Class: MultipartParser
- Inherits:
-
Object
- Object
- MultipartParser
- Defined in:
- lib/multipart_parser.rb,
lib/multipart_parser/version.rb,
ext/multipart_parser/multipart_parser.c
Constant Summary collapse
- VERSION =
"0.0.3"
Class Attribute Summary collapse
-
.default_header_value_type ⇒ Object
Multiple headers are listed as arrays.
Instance Method Summary collapse
-
#<<(data) ⇒ Object
MultipartParser# << (data).
-
#header_value_type ⇒ Object
MultipartParser#header_value_type.
-
#header_value_type=(val) ⇒ Object
MultipartParser#header_value_type=.
-
#headers ⇒ Object
MultipartParser#headers.
-
#initialize(*args) ⇒ Object
constructor
MultipartParser#new(boundary) MultipartParser#new(boundary, callback_object) MultipartParser#new(boundary, callback_object, default_header_value_type).
-
#on_data=(callback) ⇒ Object
MultipartParser#on_data=.
-
#on_headers_complete=(callback) ⇒ Object
MultipartParser#on_headers_complete=.
-
#on_message_begin=(callback) ⇒ Object
MultipartParser#on_message_begin=.
-
#on_message_complete=(callback) ⇒ Object
MultipartParser#on_message_complete=.
-
#on_part_begin=(callback) ⇒ Object
MultipartParser#on_part_begin=.
-
#on_part_complete=(callback) ⇒ Object
MultipartParser#on_part_complete=.
Constructor Details
#initialize(*args) ⇒ Object
MultipartParser#new(boundary) MultipartParser#new(boundary, callback_object) MultipartParser#new(boundary, callback_object, default_header_value_type)
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'ext/multipart_parser/multipart_parser.c', line 256
VALUE MultipartParser_initialize(int argc, VALUE *argv, VALUE self) {
MultipartParserWrapper *wrapper = NULL;
DATA_GET(self, MultipartParserWrapper, wrapper);
VALUE boundary;
wrapper->header_value_type = rb_iv_get(CLASS_OF(self), "@default_header_value_type");
if (argc == 0 ) {
rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)");
}
if (argc == 1) {
boundary = argv[0];
}
if (argc == 2) {
boundary = argv[0];
wrapper->callback_object = argv[1];
}
if (argc == 3) {
boundary = argv[0];
wrapper->callback_object = argv[1];
wrapper->header_value_type = argv[2];
}
Check_Type(boundary, T_STRING);
char *ptr = RSTRING_PTR(boundary);
long len = RSTRING_LEN(boundary);
wrapper->parser = multipart_parser_c_init(ptr,len);
wrapper->parser->context = wrapper;
return self;
}
|
Class Attribute Details
.default_header_value_type ⇒ Object
Multiple headers are listed as arrays
9 10 11 |
# File 'lib/multipart_parser.rb', line 9 def default_header_value_type @default_header_value_type end |
Instance Method Details
#<<(data) ⇒ Object
MultipartParser# << (data)
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'ext/multipart_parser/multipart_parser.c', line 300
VALUE MultipartParser_execute(VALUE self, VALUE data) {
MultipartParserWrapper *wrapper = NULL;
Check_Type(data, T_STRING);
char *ptr = RSTRING_PTR(data);
long len = RSTRING_LEN(data);
DATA_GET(self, MultipartParserWrapper, wrapper);
size_t nparsed = multipart_parser_c_execute(wrapper->parser, &settings, ptr, len);
return INT2FIX(nparsed);
}
|
#header_value_type ⇒ Object
MultipartParser#header_value_type
427 428 429 430 431 432 |
# File 'ext/multipart_parser/multipart_parser.c', line 427
VALUE MultipartParser_header_value_type(VALUE self) {
MultipartParserWrapper *wrapper = NULL;
DATA_GET(self, MultipartParserWrapper, wrapper);
return wrapper->header_value_type;
}
|
#header_value_type=(val) ⇒ Object
MultipartParser#header_value_type=
436 437 438 439 440 441 442 443 444 445 |
# File 'ext/multipart_parser/multipart_parser.c', line 436
VALUE MultipartParser_set_header_value_type(VALUE self, VALUE val) {
if (val != Sarrays && val != Sstrings && val != Smixed) {
rb_raise(rb_eArgError, "Invalid header value type");
}
MultipartParserWrapper *wrapper = NULL;
DATA_GET(self, MultipartParserWrapper, wrapper);
wrapper->header_value_type = val;
return wrapper->header_value_type;
}
|
#headers ⇒ Object
MultipartParser#headers
417 418 419 420 421 422 |
# File 'ext/multipart_parser/multipart_parser.c', line 417
VALUE MultipartParser_headers(VALUE self) {
MultipartParserWrapper *wrapper = NULL;
DATA_GET(self, MultipartParserWrapper, wrapper);
return wrapper->headers;
}
|
#on_data=(callback) ⇒ Object
MultipartParser#on_data=
368 369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'ext/multipart_parser/multipart_parser.c', line 368
VALUE MultipartParser_set_on_data(VALUE self, VALUE callback) {
MultipartParserWrapper *wrapper = NULL;
DATA_GET(self, MultipartParserWrapper, wrapper);
if (rb_class_of(callback) != rb_cProc) {
rb_raise(rb_eTypeError, "Expected Proc callback");
}
wrapper->on_data = callback;
return callback;
}
|
#on_headers_complete=(callback) ⇒ Object
MultipartParser#on_headers_complete=
352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'ext/multipart_parser/multipart_parser.c', line 352
VALUE MultipartParser_set_on_headers_complete(VALUE self, VALUE callback) {
MultipartParserWrapper *wrapper = NULL;
DATA_GET(self, MultipartParserWrapper, wrapper);
if (rb_class_of(callback) != rb_cProc) {
rb_raise(rb_eTypeError, "Expected Proc callback");
}
wrapper->on_headers_complete = callback;
return callback;
}
|
#on_message_begin=(callback) ⇒ Object
MultipartParser#on_message_begin=
318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'ext/multipart_parser/multipart_parser.c', line 318
VALUE MultipartParser_set_on_message_begin(VALUE self, VALUE callback) {
MultipartParserWrapper *wrapper = NULL;
DATA_GET(self, MultipartParserWrapper, wrapper);
if (rb_class_of(callback) != rb_cProc) {
rb_raise(rb_eTypeError, "Expected Proc callback");
}
wrapper->on_message_begin = callback;
return callback;
}
|
#on_message_complete=(callback) ⇒ Object
MultipartParser#on_message_complete=
399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'ext/multipart_parser/multipart_parser.c', line 399
VALUE MultipartParser_set_on_message_complete(VALUE self, VALUE callback) {
MultipartParserWrapper *wrapper = NULL;
DATA_GET(self, MultipartParserWrapper, wrapper);
if (rb_class_of(callback) != rb_cProc) {
rb_raise(rb_eTypeError, "Expected Proc callback");
}
wrapper->on_message_complete = callback;
return callback;
}
|
#on_part_begin=(callback) ⇒ Object
MultipartParser#on_part_begin=
335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'ext/multipart_parser/multipart_parser.c', line 335
VALUE MultipartParser_set_on_part_begin(VALUE self, VALUE callback) {
MultipartParserWrapper *wrapper = NULL;
DATA_GET(self, MultipartParserWrapper, wrapper);
if (rb_class_of(callback) != rb_cProc) {
rb_raise(rb_eTypeError, "Expected Proc callback");
}
wrapper->on_part_begin = callback;
return callback;
}
|
#on_part_complete=(callback) ⇒ Object
MultipartParser#on_part_complete=
384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'ext/multipart_parser/multipart_parser.c', line 384
VALUE MultipartParser_set_on_part_complete(VALUE self, VALUE callback) {
MultipartParserWrapper *wrapper = NULL;
DATA_GET(self, MultipartParserWrapper, wrapper);
if (rb_class_of(callback) != rb_cProc) {
rb_raise(rb_eTypeError, "Expected Proc callback");
}
wrapper->on_part_complete = callback;
return callback;
}
|