2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
19 typedef struct php_http_message_parser_state_spec
{
20 php_http_message_parser_state_t state
;
22 } php_http_message_parser_state_spec_t
;
24 static const php_http_message_parser_state_spec_t php_http_message_parser_states
[] = {
25 {PHP_HTTP_MESSAGE_PARSER_STATE_START
, 1},
26 {PHP_HTTP_MESSAGE_PARSER_STATE_HEADER
, 1},
27 {PHP_HTTP_MESSAGE_PARSER_STATE_HEADER_DONE
, 0},
28 {PHP_HTTP_MESSAGE_PARSER_STATE_BODY
, 0},
29 {PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DUMB
, 1},
30 {PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH
, 1},
31 {PHP_HTTP_MESSAGE_PARSER_STATE_BODY_CHUNKED
, 1},
32 {PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE
, 0},
33 {PHP_HTTP_MESSAGE_PARSER_STATE_DONE
, 0}
37 const char *php_http_message_parser_state_name(php_http_message_parser_state_t state
) {
38 const char *states
[] = {"START", "HEADER", "HEADER_DONE", "BODY", "BODY_DUMB", "BODY_LENGTH", "BODY_CHUNK", "BODY_DONE", "DONE"};
40 if (state
< 0 || state
> (sizeof(states
)/sizeof(char*))-1) {
47 php_http_message_parser_t
*php_http_message_parser_init(php_http_message_parser_t
*parser TSRMLS_DC
)
50 parser
= emalloc(sizeof(*parser
));
52 memset(parser
, 0, sizeof(*parser
));
54 TSRMLS_SET_CTX(parser
->ts
);
56 php_http_header_parser_init(&parser
->header TSRMLS_CC
);
61 php_http_message_parser_state_t
php_http_message_parser_state_push(php_http_message_parser_t
*parser
, unsigned argc
, ...)
63 php_http_message_parser_state_t state
;
68 ZEND_PTR_STACK_RESIZE_IF_NEEDED((&parser
->stack
), argc
);
70 va_start(va_args
, argc
);
71 for (i
= 0; i
< argc
; ++i
) {
72 state
= va_arg(va_args
, php_http_message_parser_state_t
);
73 zend_ptr_stack_push(&parser
->stack
, (void *) state
);
80 php_http_message_parser_state_t
php_http_message_parser_state_is(php_http_message_parser_t
*parser
)
82 if (parser
->stack
.top
) {
83 return (php_http_message_parser_state_t
) parser
->stack
.elements
[parser
->stack
.top
- 1];
85 return PHP_HTTP_MESSAGE_PARSER_STATE_START
;
88 php_http_message_parser_state_t
php_http_message_parser_state_pop(php_http_message_parser_t
*parser
)
90 if (parser
->stack
.top
) {
91 return (php_http_message_parser_state_t
) zend_ptr_stack_pop(&parser
->stack
);
93 return PHP_HTTP_MESSAGE_PARSER_STATE_START
;
96 void php_http_message_parser_dtor(php_http_message_parser_t
*parser
)
98 php_http_header_parser_dtor(&parser
->header
);
99 zend_ptr_stack_destroy(&parser
->stack
);
100 php_http_message_free(&parser
->message
);
101 if (parser
->dechunk
) {
102 php_http_encoding_stream_free(&parser
->dechunk
);
104 if (parser
->inflate
) {
105 php_http_encoding_stream_free(&parser
->inflate
);
109 void php_http_message_parser_free(php_http_message_parser_t
**parser
)
112 php_http_message_parser_dtor(*parser
);
118 php_http_message_parser_state_t
php_http_message_parser_parse_stream(php_http_message_parser_t
*parser
, php_http_buffer_t
*buf
, php_stream
*s
, unsigned flags
, php_http_message_t
**message
)
120 php_http_message_parser_state_t state
= PHP_HTTP_MESSAGE_PARSER_STATE_START
;
121 TSRMLS_FETCH_FROM_CTX(parser
->ts
);
124 php_http_buffer_resize_ex(buf
, 0x1000, 1, 0);
126 while (!php_stream_eof(s
)) {
129 fprintf(stderr
, "#SP: %s (f:%u)\n", php_http_message_parser_state_name(state
), flags
);
132 case PHP_HTTP_MESSAGE_PARSER_STATE_START
:
133 case PHP_HTTP_MESSAGE_PARSER_STATE_HEADER
:
134 case PHP_HTTP_MESSAGE_PARSER_STATE_HEADER_DONE
:
136 php_stream_get_line(s
, buf
->data
+ buf
->used
, buf
->free
, &justread
);
137 php_http_buffer_account(buf
, justread
);
140 case PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DUMB
:
142 justread
= php_stream_read(s
, buf
->data
+ buf
->used
, buf
->free
);
143 php_http_buffer_account(buf
, justread
);
146 case PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH
:
147 /* read body_length */
148 justread
= php_stream_read(s
, buf
->data
+ buf
->used
, MIN(buf
->free
, parser
->body_length
));
149 php_http_buffer_account(buf
, justread
);
152 case PHP_HTTP_MESSAGE_PARSER_STATE_BODY_CHUNKED
:
153 /* duh, this is very naive */
154 if (parser
->body_length
) {
155 justread
= php_stream_read(s
, buf
->data
+ buf
->used
, MIN(parser
->body_length
, buf
->free
));
157 php_http_buffer_account(buf
, justread
);
159 parser
->body_length
-= justread
;
161 php_http_buffer_resize(buf
, 24);
162 php_stream_get_line(s
, buf
->data
, buf
->free
, &justread
);
163 php_http_buffer_account(buf
, justread
);
165 parser
->body_length
= strtoul(buf
->data
+ buf
->used
- justread
, NULL
, 16);
169 case PHP_HTTP_MESSAGE_PARSER_STATE_BODY
:
170 case PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE
:
171 /* should not occur */
175 case PHP_HTTP_MESSAGE_PARSER_STATE_DONE
:
176 case PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE
:
177 return php_http_message_parser_state_is(parser
);
181 state
= php_http_message_parser_parse(parser
, buf
, flags
, message
);
187 return PHP_HTTP_MESSAGE_PARSER_STATE_DONE
;
191 php_http_message_parser_state_t
php_http_message_parser_parse(php_http_message_parser_t
*parser
, php_http_buffer_t
*buffer
, unsigned flags
, php_http_message_t
**message
)
196 TSRMLS_FETCH_FROM_CTX(parser
->ts
);
198 while (buffer
->used
|| !php_http_message_parser_states
[php_http_message_parser_state_is(parser
)].need_data
) {
200 fprintf(stderr
, "#MP: %s (f: %u, t:%d, l:%zu)\n",
201 php_http_message_parser_state_name(php_http_message_parser_state_is(parser
)),
203 message
&& *message
? (*message
)->type
: -1,
206 _dpf(0, buffer
->data
, buffer
->used
);
209 switch (php_http_message_parser_state_pop(parser
))
211 case PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE
:
212 return php_http_message_parser_state_push(parser
, 1, PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE
);
214 case PHP_HTTP_MESSAGE_PARSER_STATE_START
:
216 char *ptr
= buffer
->data
;
218 while (ptr
- buffer
->data
< buffer
->used
&& PHP_HTTP_IS_CTYPE(space
, *ptr
)) {
222 php_http_buffer_cut(buffer
, 0, ptr
- buffer
->data
);
225 php_http_message_parser_state_push(parser
, 1, PHP_HTTP_MESSAGE_PARSER_STATE_HEADER
);
230 case PHP_HTTP_MESSAGE_PARSER_STATE_HEADER
:
232 unsigned header_parser_flags
= (flags
& PHP_HTTP_MESSAGE_PARSER_CLEANUP
) ? PHP_HTTP_HEADER_PARSER_CLEANUP
: 0;
234 switch (php_http_header_parser_parse(&parser
->header
, buffer
, header_parser_flags
, *message
? &(*message
)->hdrs
: NULL
, (php_http_info_callback_t
) php_http_message_info_callback
, message
)) {
235 case PHP_HTTP_HEADER_PARSER_STATE_FAILURE
:
236 return PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE
;
238 case PHP_HTTP_HEADER_PARSER_STATE_DONE
:
239 php_http_message_parser_state_push(parser
, 1, PHP_HTTP_MESSAGE_PARSER_STATE_HEADER_DONE
);
243 php_http_message_parser_state_push(parser
, 1, PHP_HTTP_MESSAGE_PARSER_STATE_HEADER
);
245 return PHP_HTTP_MESSAGE_PARSER_STATE_HEADER
;
251 case PHP_HTTP_MESSAGE_PARSER_STATE_HEADER_DONE
:
253 zval
*h
, *h_loc
= NULL
, *h_con
= NULL
, **h_cl
= NULL
, **h_cr
= NULL
, **h_te
= NULL
;
255 if ((h
= php_http_message_header(*message
, ZEND_STRL("Transfer-Encoding"), 1))) {
256 zend_hash_update(&(*message
)->hdrs
, "X-Original-Transfer-Encoding", sizeof("X-Original-Transfer-Encoding"), &h
, sizeof(zval
*), (void *) &h_te
);
257 zend_hash_del(&(*message
)->hdrs
, "Transfer-Encoding", sizeof("Transfer-Encoding"));
259 if ((h
= php_http_message_header(*message
, ZEND_STRL("Content-Length"), 1))) {
260 zend_hash_update(&(*message
)->hdrs
, "X-Original-Content-Length", sizeof("X-Original-Content-Length"), &h
, sizeof(zval
*), (void *) &h_cl
);
262 if ((h
= php_http_message_header(*message
, ZEND_STRL("Content-Range"), 1))) {
263 zend_hash_update(&(*message
)->hdrs
, "X-Original-Content-Range", sizeof("X-Original-Content-Range"), &h
, sizeof(zval
*), (void *) &h_cr
);
264 zend_hash_del(&(*message
)->hdrs
, "Content-Range", sizeof("Content-Range"));
270 zend_hash_update(&(*message
)->hdrs
, "Content-Length", sizeof("Content-Length"), &h
, sizeof(zval
*), NULL
);
272 /* so, if curl sees a 3xx code, a Location header and a Connection:close header
273 * it decides not to read the response body.
275 if ((flags
& PHP_HTTP_MESSAGE_PARSER_EMPTY_REDIRECTS
)
276 && (*message
)->type
== PHP_HTTP_RESPONSE
277 && (*message
)->http
.info
.response
.code
/100 == 3
278 && (h_loc
= php_http_message_header(*message
, ZEND_STRL("Location"), 1))
279 && (h_con
= php_http_message_header(*message
, ZEND_STRL("Connection"), 1))
281 if (php_http_match(Z_STRVAL_P(h_con
), "close", PHP_HTTP_MATCH_WORD
)) {
282 php_http_message_parser_state_push(parser
, 1, PHP_HTTP_MESSAGE_PARSER_STATE_DONE
);
283 zval_ptr_dtor(&h_loc
);
284 zval_ptr_dtor(&h_con
);
289 zval_ptr_dtor(&h_loc
);
292 zval_ptr_dtor(&h_con
);
295 if ((h
= php_http_message_header(*message
, ZEND_STRL("Content-Encoding"), 1))) {
296 if (php_http_match(Z_STRVAL_P(h
), "gzip", PHP_HTTP_MATCH_WORD
)
297 || php_http_match(Z_STRVAL_P(h
), "x-gzip", PHP_HTTP_MATCH_WORD
)
298 || php_http_match(Z_STRVAL_P(h
), "deflate", PHP_HTTP_MATCH_WORD
)
300 if (parser
->inflate
) {
301 php_http_encoding_stream_reset(&parser
->inflate
);
303 parser
->inflate
= php_http_encoding_stream_init(NULL
, php_http_encoding_stream_get_inflate_ops(), 0 TSRMLS_CC
);
305 zend_hash_update(&(*message
)->hdrs
, "X-Original-Content-Encoding", sizeof("X-Original-Content-Encoding"), &h
, sizeof(zval
*), NULL
);
306 zend_hash_del(&(*message
)->hdrs
, "Content-Encoding", sizeof("Content-Encoding"));
312 if ((flags
& PHP_HTTP_MESSAGE_PARSER_DUMB_BODIES
)) {
313 php_http_message_parser_state_push(parser
, 1, PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DUMB
);
316 if (strstr(Z_STRVAL_PP(h_te
), "chunked")) {
317 parser
->dechunk
= php_http_encoding_stream_init(parser
->dechunk
, php_http_encoding_stream_get_dechunk_ops(), 0 TSRMLS_CC
);
318 php_http_message_parser_state_push(parser
, 1, PHP_HTTP_MESSAGE_PARSER_STATE_BODY_CHUNKED
);
326 if (Z_TYPE_PP(h_cl
) == IS_STRING
) {
327 parser
->body_length
= strtoul(Z_STRVAL_PP(h_cl
), &stop
, 10);
329 if (stop
!= Z_STRVAL_PP(h_cl
)) {
330 php_http_message_parser_state_push(parser
, 1, !parser
->body_length
?PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE
:PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH
);
333 } else if (Z_TYPE_PP(h_cl
) == IS_LONG
) {
334 parser
->body_length
= Z_LVAL_PP(h_cl
);
335 php_http_message_parser_state_push(parser
, 1, !parser
->body_length
?PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE
:PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH
);
341 ulong total
= 0, start
= 0, end
= 0;
343 if (!strncasecmp(Z_STRVAL_PP(h_cr
), "bytes", lenof("bytes"))
344 && ( Z_STRVAL_P(h
)[lenof("bytes")] == ':'
345 || Z_STRVAL_P(h
)[lenof("bytes")] == ' '
346 || Z_STRVAL_P(h
)[lenof("bytes")] == '='
349 char *total_at
= NULL
, *end_at
= NULL
;
350 char *start_at
= Z_STRVAL_PP(h_cr
) + sizeof("bytes");
352 start
= strtoul(start_at
, &end_at
, 10);
354 end
= strtoul(end_at
+ 1, &total_at
, 10);
355 if (total_at
&& strncmp(total_at
+ 1, "*", 1)) {
356 total
= strtoul(total_at
+ 1, NULL
, 10);
359 if (end
>= start
&& (!total
|| end
< total
)) {
360 parser
->body_length
= end
+ 1 - start
;
361 php_http_message_parser_state_push(parser
, 1, !parser
->body_length
?PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE
:PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH
);
369 if ((*message
)->type
== PHP_HTTP_REQUEST
) {
370 php_http_message_parser_state_push(parser
, 1, PHP_HTTP_MESSAGE_PARSER_STATE_DONE
);
372 php_http_message_parser_state_push(parser
, 1, PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DUMB
);
378 case PHP_HTTP_MESSAGE_PARSER_STATE_BODY
:
383 if (parser
->inflate
) {
384 char *dec_str
= NULL
;
387 if (SUCCESS
!= php_http_encoding_stream_update(parser
->inflate
, str
, len
, &dec_str
, &dec_len
)) {
388 return php_http_message_parser_state_push(parser
, 1, PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE
);
391 if (str
!= buffer
->data
) {
398 php_stream_write(php_http_message_body_stream((*message
)->body
), str
, len
);
402 ZVAL_LONG(zcl
, php_http_message_body_size((*message
)->body
));
403 zend_hash_update(&(*message
)->hdrs
, "Content-Length", sizeof("Content-Length"), &zcl
, sizeof(zval
*), NULL
);
407 php_http_buffer_cut(buffer
, 0, cut
);
410 if (str
!= buffer
->data
) {
420 case PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DUMB
:
426 php_http_message_parser_state_push(parser
, 2, PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE
, PHP_HTTP_MESSAGE_PARSER_STATE_BODY
);
430 case PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH
:
432 len
= MIN(parser
->body_length
, buffer
->used
);
436 parser
->body_length
-= len
;
438 php_http_message_parser_state_push(parser
, 2, !parser
->body_length
?PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE
:PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH
, PHP_HTTP_MESSAGE_PARSER_STATE_BODY
);
442 case PHP_HTTP_MESSAGE_PARSER_STATE_BODY_CHUNKED
:
445 * - pass available data through the dechunk stream
446 * - pass decoded data along
447 * - if stream zeroed:
448 * Y: - cut processed string out of buffer, but leave length of unprocessed dechunk stream data untouched
452 char *dec_str
= NULL
;
455 if (SUCCESS
!= php_http_encoding_stream_update(parser
->dechunk
, buffer
->data
, buffer
->used
, &dec_str
, &dec_len
)) {
456 return PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE
;
462 if (php_http_encoding_stream_done(parser
->dechunk
)) {
463 cut
= buffer
->used
- PHP_HTTP_BUFFER(parser
->dechunk
->ctx
)->used
;
464 php_http_message_parser_state_push(parser
, 2, PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE
, PHP_HTTP_MESSAGE_PARSER_STATE_BODY
);
467 php_http_message_parser_state_push(parser
, 2, PHP_HTTP_MESSAGE_PARSER_STATE_BODY_CHUNKED
, PHP_HTTP_MESSAGE_PARSER_STATE_BODY
);
472 case PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE
:
474 php_http_message_parser_state_push(parser
, 1, PHP_HTTP_MESSAGE_PARSER_STATE_DONE
);
476 if (parser
->dechunk
) {
477 char *dec_str
= NULL
;
480 if (SUCCESS
!= php_http_encoding_stream_finish(parser
->dechunk
, &dec_str
, &dec_len
)) {
481 return php_http_message_parser_state_push(parser
, 1, PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE
);
483 php_http_encoding_stream_dtor(parser
->dechunk
);
485 if (dec_str
&& dec_len
) {
489 php_http_message_parser_state_push(parser
, 1, PHP_HTTP_MESSAGE_PARSER_STATE_BODY
);
496 case PHP_HTTP_MESSAGE_PARSER_STATE_DONE
: {
497 char *ptr
= buffer
->data
;
499 while (ptr
- buffer
->data
< buffer
->used
&& PHP_HTTP_IS_CTYPE(space
, *ptr
)) {
503 php_http_buffer_cut(buffer
, 0, ptr
- buffer
->data
);
505 if (!(flags
& PHP_HTTP_MESSAGE_PARSER_GREEDY
)) {
506 return PHP_HTTP_MESSAGE_PARSER_STATE_DONE
;
513 return php_http_message_parser_state_is(parser
);
516 zend_class_entry
*php_http_message_parser_class_entry
;
517 static zend_object_handlers php_http_message_parser_object_handlers
;
519 zend_object_value
php_http_message_parser_object_new(zend_class_entry
*ce TSRMLS_DC
)
521 return php_http_message_parser_object_new_ex(ce
, NULL
, NULL TSRMLS_CC
);
524 zend_object_value
php_http_message_parser_object_new_ex(zend_class_entry
*ce
, php_http_message_parser_t
*parser
, php_http_message_parser_object_t
**ptr TSRMLS_DC
)
526 php_http_message_parser_object_t
*o
;
528 o
= ecalloc(1, sizeof(php_http_message_parser_object_t
));
529 zend_object_std_init((zend_object
*) o
, ce TSRMLS_CC
);
530 object_properties_init((zend_object
*) o
, ce
);
539 o
->parser
= php_http_message_parser_init(NULL TSRMLS_CC
);
541 o
->buffer
= php_http_buffer_new();
543 o
->zv
.handle
= zend_objects_store_put((zend_object
*) o
, NULL
, php_http_message_parser_object_free
, NULL TSRMLS_CC
);
544 o
->zv
.handlers
= &php_http_message_parser_object_handlers
;
549 void php_http_message_parser_object_free(void *object TSRMLS_DC
)
551 php_http_message_parser_object_t
*o
= (php_http_message_parser_object_t
*) object
;
554 php_http_message_parser_free(&o
->parser
);
557 php_http_buffer_free(&o
->buffer
);
559 zend_object_std_dtor((zend_object
*) o TSRMLS_CC
);
563 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageParser_getState
, 0, 0, 0)
565 static PHP_METHOD(HttpMessageParser
, getState
)
567 php_http_message_parser_object_t
*parser_obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
569 zend_parse_parameters_none();
570 /* always return the real state */
571 RETVAL_LONG(php_http_message_parser_state_is(parser_obj
->parser
));
574 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageParser_parse
, 0, 0, 3)
575 ZEND_ARG_INFO(0, data
)
576 ZEND_ARG_INFO(0, flags
)
577 ZEND_ARG_INFO(1, message
)
579 static PHP_METHOD(HttpMessageParser
, parse
)
581 php_http_message_parser_object_t
*parser_obj
;
587 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "slz", &data_str
, &data_len
, &flags
, &zmsg
), invalid_arg
, return);
589 parser_obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
590 php_http_buffer_append(parser_obj
->buffer
, data_str
, data_len
);
591 RETVAL_LONG(php_http_message_parser_parse(parser_obj
->parser
, parser_obj
->buffer
, flags
, &parser_obj
->parser
->message
));
594 if (parser_obj
->parser
->message
) {
595 ZVAL_OBJVAL(zmsg
, php_http_message_object_new_ex(php_http_message_class_entry
, php_http_message_copy(parser_obj
->parser
->message
, NULL
), NULL TSRMLS_CC
), 0);
599 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageParser_stream
, 0, 0, 3)
600 ZEND_ARG_INFO(0, stream
)
601 ZEND_ARG_INFO(0, flags
)
602 ZEND_ARG_INFO(1, message
)
604 static PHP_METHOD(HttpMessageParser
, stream
)
606 php_http_message_parser_object_t
*parser_obj
;
607 zend_error_handling zeh
;
608 zval
*zmsg
, *zstream
;
612 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "rlz", &zstream
, &flags
, &zmsg
), invalid_arg
, return);
614 zend_replace_error_handling(EH_THROW
, php_http_exception_unexpected_val_class_entry
, &zeh TSRMLS_CC
);
615 php_stream_from_zval(s
, &zstream
);
616 zend_restore_error_handling(&zeh TSRMLS_CC
);
618 parser_obj
= zend_object_store_get_object(getThis() TSRMLS_CC
);
619 RETVAL_LONG(php_http_message_parser_parse_stream(parser_obj
->parser
, parser_obj
->buffer
, s
, flags
, &parser_obj
->parser
->message
));
622 if (parser_obj
->parser
->message
) {
623 ZVAL_OBJVAL(zmsg
, php_http_message_object_new_ex(php_http_message_class_entry
, php_http_message_copy(parser_obj
->parser
->message
, NULL
), NULL TSRMLS_CC
), 0);
627 static zend_function_entry php_http_message_parser_methods
[] = {
628 PHP_ME(HttpMessageParser
, getState
, ai_HttpMessageParser_getState
, ZEND_ACC_PUBLIC
)
629 PHP_ME(HttpMessageParser
, parse
, ai_HttpMessageParser_parse
, ZEND_ACC_PUBLIC
)
630 PHP_ME(HttpMessageParser
, stream
, ai_HttpMessageParser_stream
, ZEND_ACC_PUBLIC
)
634 PHP_MINIT_FUNCTION(http_message_parser
)
638 INIT_NS_CLASS_ENTRY(ce
, "http\\Message", "Parser", php_http_message_parser_methods
);
639 php_http_message_parser_class_entry
= zend_register_internal_class(&ce TSRMLS_CC
);
640 memcpy(&php_http_message_parser_object_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
641 php_http_message_parser_class_entry
->create_object
= php_http_message_parser_object_new
;
642 php_http_message_parser_object_handlers
.clone_obj
= NULL
;
644 zend_declare_class_constant_long(php_http_message_parser_class_entry
, ZEND_STRL("CLEANUP"), PHP_HTTP_MESSAGE_PARSER_CLEANUP TSRMLS_CC
);
645 zend_declare_class_constant_long(php_http_message_parser_class_entry
, ZEND_STRL("DUMB_BODIES"), PHP_HTTP_MESSAGE_PARSER_DUMB_BODIES TSRMLS_CC
);
646 zend_declare_class_constant_long(php_http_message_parser_class_entry
, ZEND_STRL("EMPTY_REDIRECTS"), PHP_HTTP_MESSAGE_PARSER_EMPTY_REDIRECTS TSRMLS_CC
);
647 zend_declare_class_constant_long(php_http_message_parser_class_entry
, ZEND_STRL("GREEDY"), PHP_HTTP_MESSAGE_PARSER_GREEDY TSRMLS_CC
);
649 zend_declare_class_constant_long(php_http_message_parser_class_entry
, ZEND_STRL("STATE_FAILURE"), PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE TSRMLS_CC
);
650 zend_declare_class_constant_long(php_http_message_parser_class_entry
, ZEND_STRL("STATE_START"), PHP_HTTP_MESSAGE_PARSER_STATE_START TSRMLS_CC
);
651 zend_declare_class_constant_long(php_http_message_parser_class_entry
, ZEND_STRL("STATE_HEADER"), PHP_HTTP_MESSAGE_PARSER_STATE_HEADER TSRMLS_CC
);
652 zend_declare_class_constant_long(php_http_message_parser_class_entry
, ZEND_STRL("STATE_HEADER_DONE"), PHP_HTTP_MESSAGE_PARSER_STATE_HEADER_DONE TSRMLS_CC
);
653 zend_declare_class_constant_long(php_http_message_parser_class_entry
, ZEND_STRL("STATE_BODY"), PHP_HTTP_MESSAGE_PARSER_STATE_BODY TSRMLS_CC
);
654 zend_declare_class_constant_long(php_http_message_parser_class_entry
, ZEND_STRL("STATE_BODY_DUMB"), PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DUMB TSRMLS_CC
);
655 zend_declare_class_constant_long(php_http_message_parser_class_entry
, ZEND_STRL("STATE_BODY_LENGTH"), PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH TSRMLS_CC
);
656 zend_declare_class_constant_long(php_http_message_parser_class_entry
, ZEND_STRL("STATE_BODY_CHUNKED"), PHP_HTTP_MESSAGE_PARSER_STATE_BODY_CHUNKED TSRMLS_CC
);
657 zend_declare_class_constant_long(php_http_message_parser_class_entry
, ZEND_STRL("STATE_BODY_DONE"), PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE TSRMLS_CC
);
658 zend_declare_class_constant_long(php_http_message_parser_class_entry
, ZEND_STRL("STATE_DONE"), PHP_HTTP_MESSAGE_PARSER_STATE_DONE TSRMLS_CC
);
668 * vim600: noet sw=4 ts=4 fdm=marker
669 * vim<600: noet sw=4 ts=4