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"
15 static void message_headers(php_http_message_t
*msg
, php_http_buffer_t
*str
);
17 zend_bool
php_http_message_info_callback(php_http_message_t
**message
, HashTable
**headers
, php_http_info_t
*info
)
19 php_http_message_t
*old
= *message
;
22 if (!old
|| old
->type
|| zend_hash_num_elements(&old
->hdrs
)) {
23 (*message
) = php_http_message_init(NULL
, 0, NULL
);
24 (*message
)->parent
= old
;
26 (*headers
) = &((*message
)->hdrs
);
31 php_http_message_set_info(*message
, info
);
34 return old
!= *message
;
37 php_http_message_t
*php_http_message_init(php_http_message_t
*message
, php_http_message_type_t type
, php_http_message_body_t
*body
)
40 message
= emalloc(sizeof(*message
));
42 memset(message
, 0, sizeof(*message
));
44 php_http_message_set_type(message
, type
);
45 message
->http
.version
.major
= 1;
46 message
->http
.version
.minor
= 1;
47 zend_hash_init(&message
->hdrs
, 0, NULL
, ZVAL_PTR_DTOR
, 0);
48 message
->body
= body
? body
: php_http_message_body_init(NULL
, NULL
);
53 php_http_message_t
*php_http_message_init_env(php_http_message_t
*message
, php_http_message_type_t type
)
55 int free_msg
= !message
;
57 php_http_message_body_t
*mbody
;
60 case PHP_HTTP_REQUEST
:
61 mbody
= php_http_env_get_request_body();
62 php_http_message_body_addref(mbody
);
63 message
= php_http_message_init(message
, type
, mbody
);
64 if ((sval
= php_http_env_get_server_var(ZEND_STRL("SERVER_PROTOCOL"), 1)) && !strncmp(Z_STRVAL_P(sval
), "HTTP/", lenof("HTTP/"))) {
65 php_http_version_parse(&message
->http
.version
, Z_STRVAL_P(sval
));
67 if ((sval
= php_http_env_get_server_var(ZEND_STRL("REQUEST_METHOD"), 1))) {
68 message
->http
.info
.request
.method
= estrdup(Z_STRVAL_P(sval
));
70 if ((sval
= php_http_env_get_server_var(ZEND_STRL("REQUEST_URI"), 1))) {
71 message
->http
.info
.request
.url
= php_http_url_parse(Z_STRVAL_P(sval
), Z_STRLEN_P(sval
), ~0);
74 php_http_env_get_request_headers(&message
->hdrs
);
77 case PHP_HTTP_RESPONSE
:
78 message
= php_http_message_init(NULL
, type
, NULL
);
79 if (!SG(sapi_headers
).http_status_line
|| !php_http_info_parse((php_http_info_t
*) &message
->http
, SG(sapi_headers
).http_status_line
)) {
80 if (!(message
->http
.info
.response
.code
= SG(sapi_headers
).http_response_code
)) {
81 message
->http
.info
.response
.code
= 200;
83 message
->http
.info
.response
.status
= estrdup(php_http_env_get_response_status_for_code(message
->http
.info
.response
.code
));
86 php_http_env_get_response_headers(&message
->hdrs
);
87 if (php_output_get_level()) {
88 if (php_output_get_status() & PHP_OUTPUT_SENT
) {
89 php_error_docref(NULL
, E_WARNING
, "Could not fetch response body, output has already been sent at %s:%d", php_output_get_start_filename(TSRMLS_C
), php_output_get_start_lineno(TSRMLS_C
));
91 } else if (SUCCESS
!= php_output_get_contents(&tval
)) {
92 php_error_docref(NULL
, E_WARNING
, "Could not fetch response body");
95 php_http_message_body_append(message
->body
, Z_STRVAL(tval
), Z_STRLEN(tval
));
105 php_http_message_free(&message
);
116 php_http_message_t
*php_http_message_parse(php_http_message_t
*msg
, const char *str
, size_t len
, zend_bool greedy
)
118 php_http_message_parser_t p
;
119 php_http_buffer_t buf
;
120 unsigned flags
= PHP_HTTP_MESSAGE_PARSER_CLEANUP
;
123 php_http_buffer_from_string_ex(&buf
, str
, len
);
124 php_http_message_parser_init(&p
);
126 if ((free_msg
= !msg
)) {
127 msg
= php_http_message_init(NULL
, 0, NULL
);
131 flags
|= PHP_HTTP_MESSAGE_PARSER_GREEDY
;
133 if (PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE
== php_http_message_parser_parse(&p
, &buf
, flags
, &msg
)) {
135 php_http_message_free(&msg
);
140 php_http_message_parser_dtor(&p
);
141 php_http_buffer_dtor(&buf
);
146 zval
*php_http_message_header(php_http_message_t
*msg
, const char *key_str
, size_t key_len
)
150 ALLOCA_FLAG(free_key
);
152 key
= do_alloca(key_len
+ 1, free_key
);
154 memcpy(key
, key_str
, key_len
);
156 php_http_pretty_key(key
, key_len
, 1, 1);
158 ret
= zend_symtable_str_find(&msg
->hdrs
, key
, key_len
);
160 free_alloca(key
, free_key
);
165 zend_bool
php_http_message_is_multipart(php_http_message_t
*msg
, char **boundary
)
167 zend_string
*ct
= php_http_message_header_string(msg
, ZEND_STRL("Content-Type"));
168 zend_bool is_multipart
= 0;
171 php_http_params_opts_t popts
;
174 ZEND_INIT_SYMTABLE(¶ms
);
175 php_http_params_opts_default_get(&popts
);
176 popts
.input
.str
= ct
->val
;
177 popts
.input
.len
= ct
->len
;
179 if (php_http_params_parse(¶ms
, &popts
)) {
184 zend_hash_internal_pointer_reset(¶ms
);
186 if ((cur
= zend_hash_get_current_data(¶ms
))
187 && (Z_TYPE_P(cur
) == IS_ARRAY
)
188 && (HASH_KEY_IS_STRING
== zend_hash_get_current_key(¶ms
, &ct_str
, &index
))
190 if (php_http_match(ct_str
->val
, "multipart", PHP_HTTP_MATCH_WORD
)) {
195 && (arg
= zend_hash_str_find(Z_ARRVAL_P(cur
), ZEND_STRL("arguments")))
196 && Z_TYPE_P(arg
) == IS_ARRAY
199 php_http_arrkey_t key
;
201 ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(arg
), key
.h
, key
.key
, val
)
203 if (key
.key
&& key
.key
->len
== lenof("boundary") && !strcasecmp(key
.key
->val
, "boundary")) {
204 zend_string
*bnd
= zval_get_string(val
);
207 *boundary
= estrndup(bnd
->val
, bnd
->len
);
209 zend_string_release(bnd
);
212 ZEND_HASH_FOREACH_END();
217 zend_hash_destroy(¶ms
);
218 zend_string_release(ct
);
225 void php_http_message_set_type(php_http_message_t
*message
, php_http_message_type_t type
)
227 /* just act if different */
228 if (type
!= message
->type
) {
230 /* free request info */
231 switch (message
->type
) {
232 case PHP_HTTP_REQUEST
:
233 PTR_FREE(message
->http
.info
.request
.method
);
234 PTR_FREE(message
->http
.info
.request
.url
);
237 case PHP_HTTP_RESPONSE
:
238 PTR_FREE(message
->http
.info
.response
.status
);
245 message
->type
= type
;
246 memset(&message
->http
, 0, sizeof(message
->http
));
250 void php_http_message_set_info(php_http_message_t
*message
, php_http_info_t
*info
)
252 php_http_message_set_type(message
, info
->type
);
253 message
->http
.version
= info
->http
.version
;
254 switch (message
->type
) {
255 case PHP_HTTP_REQUEST
:
256 PTR_SET(PHP_HTTP_INFO(message
).request
.url
, PHP_HTTP_INFO(info
).request
.url
? php_http_url_copy(PHP_HTTP_INFO(info
).request
.url
, 0) : NULL
);
257 PTR_SET(PHP_HTTP_INFO(message
).request
.method
, PHP_HTTP_INFO(info
).request
.method
? estrdup(PHP_HTTP_INFO(info
).request
.method
) : NULL
);
260 case PHP_HTTP_RESPONSE
:
261 PHP_HTTP_INFO(message
).response
.code
= PHP_HTTP_INFO(info
).response
.code
;
262 PTR_SET(PHP_HTTP_INFO(message
).response
.status
, PHP_HTTP_INFO(info
).response
.status
? estrdup(PHP_HTTP_INFO(info
).response
.status
) : NULL
);
270 void php_http_message_update_headers(php_http_message_t
*msg
)
276 if (php_http_message_body_stream(msg
->body
)->readfilters
.head
) {
277 /* if a read stream filter is attached to the body the caller must also care for the headers */
278 } else if (php_http_message_header(msg
, ZEND_STRL("Content-Range"))) {
279 /* don't mess around with a Content-Range message */
280 } else if ((size
= php_http_message_body_size(msg
->body
))) {
282 zend_hash_str_update(&msg
->hdrs
, "Content-Length", lenof("Content-Length"), &h
);
284 if (msg
->body
->boundary
) {
289 if (!(ct
= php_http_message_header_string(msg
, ZEND_STRL("Content-Type")))) {
290 len
= spprintf(&str
, 0, "multipart/form-data; boundary=\"%s\"", msg
->body
->boundary
);
291 ZVAL_STR(&h
, php_http_cs2zs(str
, len
));
292 zend_hash_str_update(&msg
->hdrs
, "Content-Type", lenof("Content-Type"), &h
);
293 } else if (!php_http_match(ct
->val
, "boundary=", PHP_HTTP_MATCH_WORD
)) {
294 len
= spprintf(&str
, 0, "%s; boundary=\"%s\"", ct
->val
, msg
->body
->boundary
);
295 ZVAL_STR(&h
, php_http_cs2zs(str
, len
));
296 zend_hash_str_update(&msg
->hdrs
, "Content-Type", lenof("Content-Type"), &h
);
297 zend_string_release(ct
);
299 zend_string_release(ct
);
302 } else if ((cl
= php_http_message_header_string(msg
, ZEND_STRL("Content-Length")))) {
303 if (!zend_string_equals_literal(cl
, "0")) {
304 /* body->size == 0, so get rid of old Content-Length */
305 zend_hash_str_del(&msg
->hdrs
, ZEND_STRL("Content-Length"));
307 zend_string_release(cl
);
311 static void message_headers(php_http_message_t
*msg
, php_http_buffer_t
*str
)
316 case PHP_HTTP_REQUEST
:
317 php_http_buffer_appendf(str
, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&msg
->http
, tmp
, PHP_HTTP_CRLF
));
321 case PHP_HTTP_RESPONSE
:
322 php_http_buffer_appendf(str
, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&msg
->http
, tmp
, PHP_HTTP_CRLF
));
330 php_http_message_update_headers(msg
);
331 php_http_header_to_string(str
, &msg
->hdrs
);
334 void php_http_message_to_callback(php_http_message_t
*msg
, php_http_pass_callback_t cb
, void *cb_arg
)
336 php_http_buffer_t str
;
338 php_http_buffer_init_ex(&str
, 0x1000, 0);
339 message_headers(msg
, &str
);
340 cb(cb_arg
, str
.data
, str
.used
);
341 php_http_buffer_dtor(&str
);
343 if (php_http_message_body_size(msg
->body
)) {
344 cb(cb_arg
, ZEND_STRL(PHP_HTTP_CRLF
));
345 php_http_message_body_to_callback(msg
->body
, cb
, cb_arg
, 0, 0);
349 void php_http_message_to_string(php_http_message_t
*msg
, char **string
, size_t *length
)
351 php_http_buffer_t str
;
354 php_http_buffer_init_ex(&str
, 0x1000, 0);
355 message_headers(msg
, &str
);
356 if (php_http_message_body_size(msg
->body
)) {
357 php_http_buffer_appends(&str
, PHP_HTTP_CRLF
);
358 php_http_message_body_to_callback(msg
->body
, (php_http_pass_callback_t
) php_http_buffer_append
, &str
, 0, 0);
361 data
= php_http_buffer_data(&str
, string
, length
);
366 php_http_buffer_dtor(&str
);
369 void php_http_message_serialize(php_http_message_t
*message
, char **string
, size_t *length
)
372 php_http_buffer_t str
;
373 php_http_message_t
*msg
;
375 php_http_buffer_init(&str
);
377 msg
= message
= php_http_message_reverse(message
);
379 php_http_message_to_callback(message
, (php_http_pass_callback_t
) php_http_buffer_append
, &str
);
380 php_http_buffer_appends(&str
, PHP_HTTP_CRLF
);
381 } while ((message
= message
->parent
));
382 php_http_message_reverse(msg
);
384 buf
= php_http_buffer_data(&str
, string
, length
);
389 php_http_buffer_dtor(&str
);
392 php_http_message_t
*php_http_message_reverse(php_http_message_t
*msg
)
394 size_t i
, c
= php_http_message_count(msg
);
397 php_http_message_t
*tmp
= msg
, **arr
;
399 arr
= ecalloc(c
, sizeof(**arr
));
400 for (i
= 0; i
< c
; ++i
) {
404 arr
[0]->parent
= NULL
;
405 for (i
= 0; i
< c
-1; ++i
) {
406 arr
[i
+1]->parent
= arr
[i
];
416 php_http_message_t
*php_http_message_zip(php_http_message_t
*dst
, php_http_message_t
*src
)
418 php_http_message_t
*tmp_dst
, *tmp_src
, *ret
= dst
;
421 tmp_dst
= dst
->parent
;
422 tmp_src
= src
->parent
;
425 src
->parent
= tmp_dst
;
434 php_http_message_t
*php_http_message_copy_ex(php_http_message_t
*from
, php_http_message_t
*to
, zend_bool parents
)
436 php_http_message_t
*temp
, *copy
= NULL
;
437 php_http_info_t info
;
440 info
.type
= from
->type
;
441 info
.http
= from
->http
;
443 copy
= temp
= php_http_message_init(to
, 0, php_http_message_body_copy(from
->body
, NULL
));
444 php_http_message_set_info(temp
, &info
);
445 zend_hash_copy(&temp
->hdrs
, &from
->hdrs
, (copy_ctor_func_t
) zval_add_ref
);
447 if (parents
) while (from
->parent
) {
448 info
.type
= from
->parent
->type
;
449 info
.http
= from
->parent
->http
;
451 temp
->parent
= php_http_message_init(NULL
, 0, php_http_message_body_copy(from
->parent
->body
, NULL
));
452 php_http_message_set_info(temp
->parent
, &info
);
453 array_copy(&from
->parent
->hdrs
, &temp
->parent
->hdrs
);
463 void php_http_message_dtor(php_http_message_t
*message
)
466 zend_hash_destroy(&message
->hdrs
);
467 php_http_message_body_free(&message
->body
);
469 switch (message
->type
) {
470 case PHP_HTTP_REQUEST
:
471 PTR_SET(message
->http
.info
.request
.method
, NULL
);
472 PTR_SET(message
->http
.info
.request
.url
, NULL
);
475 case PHP_HTTP_RESPONSE
:
476 PTR_SET(message
->http
.info
.response
.status
, NULL
);
485 void php_http_message_free(php_http_message_t
**message
)
488 if ((*message
)->parent
) {
489 php_http_message_free(&(*message
)->parent
);
491 php_http_message_dtor(*message
);
497 static zval
*php_http_message_object_read_prop(zval
*object
, zval
*member
, int type
, void **cache_slot
, zval
*rv
);
498 static void php_http_message_object_write_prop(zval
*object
, zval
*member
, zval
*value
, void **cache_slot
);
499 static HashTable
*php_http_message_object_get_props(zval
*object
);
501 static zend_object_handlers php_http_message_object_handlers
;
502 static HashTable php_http_message_object_prophandlers
;
504 static void php_http_message_object_prophandler_hash_dtor(zval
*pData
)
506 pefree(Z_PTR_P(pData
), 1);
509 typedef void (*php_http_message_object_prophandler_func_t
)(php_http_message_object_t
*o
, zval
*v
);
511 typedef struct php_http_message_object_prophandler
{
512 php_http_message_object_prophandler_func_t read
;
513 php_http_message_object_prophandler_func_t write
;
514 } php_http_message_object_prophandler_t
;
516 static ZEND_RESULT_CODE
php_http_message_object_add_prophandler(const char *prop_str
, size_t prop_len
, php_http_message_object_prophandler_func_t read
, php_http_message_object_prophandler_func_t write
) {
517 php_http_message_object_prophandler_t h
= { read
, write
};
518 if (!zend_hash_str_add_mem(&php_http_message_object_prophandlers
, prop_str
, prop_len
, (void *) &h
, sizeof(h
))) {
523 static php_http_message_object_prophandler_t
*php_http_message_object_get_prophandler(zend_string
*name_str
) {
524 return zend_hash_str_find_ptr(&php_http_message_object_prophandlers
, name_str
->val
, name_str
->len
);
526 static void php_http_message_object_prophandler_get_type(php_http_message_object_t
*obj
, zval
*return_value
) {
527 RETVAL_LONG(obj
->message
->type
);
529 static void php_http_message_object_prophandler_set_type(php_http_message_object_t
*obj
, zval
*value
) {
530 php_http_message_set_type(obj
->message
, zval_get_long(value
));
532 static void php_http_message_object_prophandler_get_request_method(php_http_message_object_t
*obj
, zval
*return_value
) {
533 if (PHP_HTTP_MESSAGE_TYPE(REQUEST
, obj
->message
) && obj
->message
->http
.info
.request
.method
) {
534 RETVAL_STRING(obj
->message
->http
.info
.request
.method
);
539 static void php_http_message_object_prophandler_set_request_method(php_http_message_object_t
*obj
, zval
*value
) {
540 if (PHP_HTTP_MESSAGE_TYPE(REQUEST
, obj
->message
)) {
541 zend_string
*zs
= zval_get_string(value
);
542 PTR_SET(obj
->message
->http
.info
.request
.method
, estrndup(zs
->val
, zs
->len
));
543 zend_string_release(zs
);
546 static void php_http_message_object_prophandler_get_request_url(php_http_message_object_t
*obj
, zval
*return_value
) {
550 if (PHP_HTTP_MESSAGE_TYPE(REQUEST
, obj
->message
) && obj
->message
->http
.info
.request
.url
&& php_http_url_to_string(obj
->message
->http
.info
.request
.url
, &url_str
, &url_len
, 0)) {
551 RETVAL_STR(php_http_cs2zs(url_str
, url_len
));
556 static void php_http_message_object_prophandler_set_request_url(php_http_message_object_t
*obj
, zval
*value
) {
557 if (PHP_HTTP_MESSAGE_TYPE(REQUEST
, obj
->message
)) {
558 PTR_SET(obj
->message
->http
.info
.request
.url
, php_http_url_from_zval(value
, ~0));
561 static void php_http_message_object_prophandler_get_response_status(php_http_message_object_t
*obj
, zval
*return_value
) {
562 if (PHP_HTTP_MESSAGE_TYPE(RESPONSE
, obj
->message
) && obj
->message
->http
.info
.response
.status
) {
563 RETVAL_STRING(obj
->message
->http
.info
.response
.status
);
568 static void php_http_message_object_prophandler_set_response_status(php_http_message_object_t
*obj
, zval
*value
) {
569 if (PHP_HTTP_MESSAGE_TYPE(RESPONSE
, obj
->message
)) {
570 zend_string
*zs
= zval_get_string(value
);
571 PTR_SET(obj
->message
->http
.info
.response
.status
, estrndup(zs
->val
, zs
->len
));
572 zend_string_release(zs
);
575 static void php_http_message_object_prophandler_get_response_code(php_http_message_object_t
*obj
, zval
*return_value
) {
576 if (PHP_HTTP_MESSAGE_TYPE(RESPONSE
, obj
->message
)) {
577 RETVAL_LONG(obj
->message
->http
.info
.response
.code
);
582 static void php_http_message_object_prophandler_set_response_code(php_http_message_object_t
*obj
, zval
*value
) {
583 if (PHP_HTTP_MESSAGE_TYPE(RESPONSE
, obj
->message
)) {
584 obj
->message
->http
.info
.response
.code
= zval_get_long(value
);
585 PTR_SET(obj
->message
->http
.info
.response
.status
, estrdup(php_http_env_get_response_status_for_code(obj
->message
->http
.info
.response
.code
)));
588 static void php_http_message_object_prophandler_get_http_version(php_http_message_object_t
*obj
, zval
*return_value
) {
592 php_http_version_to_string(&obj
->message
->http
.version
, &version_str
, &version_len
, NULL
, NULL
);
593 RETVAL_STR(php_http_cs2zs(version_str
, version_len
));
595 static void php_http_message_object_prophandler_set_http_version(php_http_message_object_t
*obj
, zval
*value
) {
596 zend_string
*zs
= zval_get_string(value
);
597 php_http_version_parse(&obj
->message
->http
.version
, zs
->val
);
598 zend_string_release(zs
);
600 static void php_http_message_object_prophandler_get_headers(php_http_message_object_t
*obj
, zval
*return_value
) {
601 array_init(return_value
);
602 array_copy(&obj
->message
->hdrs
, Z_ARRVAL_P(return_value
));
604 static void php_http_message_object_prophandler_set_headers(php_http_message_object_t
*obj
, zval
*value
) {
606 zval
*orig_value
= value
;
608 if (Z_TYPE_P(value
) != IS_ARRAY
&& Z_TYPE_P(value
) != IS_OBJECT
) {
609 convert_to_array_ex(value
);
611 headers
= HASH_OF(value
);
613 zend_hash_clean(&obj
->message
->hdrs
);
614 array_copy(headers
, &obj
->message
->hdrs
);
616 if (orig_value
!= value
) {
617 zval_ptr_dtor(value
);
620 static void php_http_message_object_prophandler_get_body(php_http_message_object_t
*obj
, zval
*return_value
) {
622 RETVAL_OBJECT(&obj
->body
->zo
, 1);
627 static void php_http_message_object_prophandler_set_body(php_http_message_object_t
*obj
, zval
*value
) {
628 php_http_message_object_set_body(obj
, value
);
630 static void php_http_message_object_prophandler_get_parent_message(php_http_message_object_t
*obj
, zval
*return_value
) {
631 if (obj
->message
->parent
) {
632 RETVAL_OBJECT(&obj
->parent
->zo
, 1);
637 static void php_http_message_object_prophandler_set_parent_message(php_http_message_object_t
*obj
, zval
*value
) {
638 if (Z_TYPE_P(value
) == IS_OBJECT
&& instanceof_function(Z_OBJCE_P(value
), php_http_message_class_entry
)) {
639 php_http_message_object_t
*parent_obj
= PHP_HTTP_OBJ(NULL
, value
);
641 if (obj
->message
->parent
) {
642 zend_objects_store_del(&obj
->parent
->zo
);
645 obj
->parent
= parent_obj
;
646 obj
->message
->parent
= parent_obj
->message
;
650 #define PHP_HTTP_MESSAGE_OBJECT_INIT(obj) \
652 if (!obj->message) { \
653 obj->message = php_http_message_init(NULL, 0, NULL); \
658 void php_http_message_object_reverse(zval
*zmsg
, zval
*return_value
)
661 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, zmsg
);
663 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
666 i
= php_http_message_count(obj
->message
);
669 php_http_message_object_t
**objects
;
672 objects
= ecalloc(i
, sizeof(**objects
));
674 /* we are the first message */
678 for (i
= 1; obj
->parent
; ++i
) {
679 objects
[i
] = obj
= obj
->parent
;
682 /* reorder parents */
683 for (last
= --i
; i
; --i
) {
684 objects
[i
]->message
->parent
= objects
[i
-1]->message
;
685 objects
[i
]->parent
= objects
[i
-1];
688 objects
[0]->message
->parent
= NULL
;
689 objects
[0]->parent
= NULL
;
691 /* add ref, because we previously have not been a parent message */
693 RETVAL_OBJECT(&objects
[last
]->zo
, 1);
697 RETURN_ZVAL_FAST(zmsg
);
701 void php_http_message_object_prepend(zval
*this_ptr
, zval
*prepend
, zend_bool top
)
703 php_http_message_t
*save_parent_msg
= NULL
;
704 php_http_message_object_t
*save_parent_obj
= NULL
, *obj
= PHP_HTTP_OBJ(NULL
, this_ptr
);
705 php_http_message_object_t
*prepend_obj
= PHP_HTTP_OBJ(NULL
, prepend
);
708 save_parent_obj
= obj
->parent
;
709 save_parent_msg
= obj
->message
->parent
;
711 /* iterate to the most parent object */
712 while (obj
->parent
) {
718 obj
->parent
= prepend_obj
;
719 obj
->message
->parent
= prepend_obj
->message
;
725 prepend_obj
->parent
= save_parent_obj
;
726 prepend_obj
->message
->parent
= save_parent_msg
;
730 ZEND_RESULT_CODE
php_http_message_object_set_body(php_http_message_object_t
*msg_obj
, zval
*zbody
)
733 zend_string
*body_str
;
734 php_http_message_body_t
*body
;
735 php_http_message_body_object_t
*body_obj
;
737 switch (Z_TYPE_P(zbody
)) {
739 php_stream_from_zval_no_verify(s
, zbody
);
741 php_http_throw(unexpected_val
, "The stream is not a valid resource", NULL
);
747 body
= php_http_message_body_init(NULL
, s
);
748 if (!(body_obj
= php_http_message_body_object_new_ex(php_http_message_body_class_entry
, body
))) {
749 php_http_message_body_free(&body
);
755 if (instanceof_function(Z_OBJCE_P(zbody
), php_http_message_body_class_entry
)) {
757 body_obj
= PHP_HTTP_OBJ(NULL
, zbody
);
763 body_str
= zval_get_string(zbody
);
764 s
= php_stream_temp_new();
765 php_stream_write(s
, body_str
->val
, body_str
->len
);
766 zend_string_release(body_str
);
771 if (!body_obj
->body
) {
772 body_obj
->body
= php_http_message_body_init(NULL
, NULL
);
775 zend_objects_store_del(&msg_obj
->body
->zo
);
777 if (msg_obj
->message
) {
778 php_http_message_body_free(&msg_obj
->message
->body
);
779 msg_obj
->message
->body
= php_http_message_body_init(&body_obj
->body
, NULL
);
781 msg_obj
->message
= php_http_message_init(NULL
, 0, php_http_message_body_init(&body_obj
->body
, NULL
));
783 msg_obj
->body
= body_obj
;
788 ZEND_RESULT_CODE
php_http_message_object_init_body_object(php_http_message_object_t
*obj
)
790 php_http_message_body_addref(obj
->message
->body
);
791 return php_http_new((void *) &obj
->body
, php_http_message_body_class_entry
, (php_http_new_t
) php_http_message_body_object_new_ex
, NULL
, obj
->message
->body
);
794 zend_object
*php_http_message_object_new(zend_class_entry
*ce
)
796 return &php_http_message_object_new_ex(ce
, NULL
)->zo
;
799 php_http_message_object_t
*php_http_message_object_new_ex(zend_class_entry
*ce
, php_http_message_t
*msg
)
801 php_http_message_object_t
*o
;
803 o
= ecalloc(1, sizeof(*o
) + zend_object_properties_size(ce
));
804 zend_object_std_init(&o
->zo
, ce
);
805 object_properties_init(&o
->zo
, ce
);
810 o
->parent
= php_http_message_object_new_ex(ce
, msg
->parent
);
812 o
->body
= php_http_message_body_object_new_ex(php_http_message_body_class_entry
, php_http_message_body_init(&msg
->body
, NULL
));
815 o
->zo
.handlers
= &php_http_message_object_handlers
;
820 zend_object
*php_http_message_object_clone(zval
*this_ptr TSRMLS_DC
)
822 php_http_message_object_t
*new_obj
= NULL
;
823 php_http_message_object_t
*old_obj
= PHP_HTTP_OBJ(NULL
, this_ptr
);
825 new_obj
= php_http_message_object_new_ex(old_obj
->zo
.ce
, php_http_message_copy(old_obj
->message
, NULL
));
826 zend_objects_clone_members(&new_obj
->zo
, &old_obj
->zo
);
831 void php_http_message_object_free(zend_object
*object
)
833 php_http_message_object_t
*o
= PHP_HTTP_OBJ(object
, NULL
);
835 if (!Z_ISUNDEF(o
->iterator
)) {
836 zval_ptr_dtor(&o
->iterator
);
837 ZVAL_UNDEF(&o
->iterator
);
840 /* do NOT free recursivly */
841 php_http_message_dtor(o
->message
);
846 zend_objects_store_del(&o
->parent
->zo
);
850 zend_objects_store_del(&o
->body
->zo
);
853 zend_object_std_dtor(object
);
856 static zval
*php_http_message_object_read_prop(zval
*object
, zval
*member
, int type
, void **cache_slot
, zval
*tmp
)
859 zend_string
*member_name
= zval_get_string(member
);
860 php_http_message_object_prophandler_t
*handler
= php_http_message_object_get_prophandler(member_name
);
862 if (!handler
|| type
== BP_VAR_R
|| type
== BP_VAR_IS
) {
863 return_value
= zend_get_std_object_handlers()->read_property(object
, member
, type
, cache_slot
, tmp
);
866 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, object
);
868 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
869 handler
->read(obj
, tmp
);
871 zval_ptr_dtor(return_value
);
872 ZVAL_COPY_VALUE(return_value
, tmp
);
875 return_value
= php_property_proxy_zval(object
, member_name
);
878 zend_string_release(member_name
);
883 static void php_http_message_object_write_prop(zval
*object
, zval
*member
, zval
*value
, void **cache_slot
)
885 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, object
);
886 php_http_message_object_prophandler_t
*handler
;
887 zend_string
*member_name
= zval_get_string(member
);
889 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
891 if ((handler
= php_http_message_object_get_prophandler(member_name
))) {
892 handler
->write(obj
, value
);
894 zend_get_std_object_handlers()->write_property(object
, member
, value
, cache_slot
);
897 zend_string_release(member_name
);
900 static HashTable
*php_http_message_object_get_props(zval
*object
)
903 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, object
);
904 HashTable
*props
= zend_get_std_object_handlers()->get_properties(object
);
905 char *ver_str
, *url_str
= NULL
;
906 size_t ver_len
, url_len
= 0;
908 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
910 #define UPDATE_PROP(name_str, action_with_tmp) \
912 zend_property_info *pi; \
913 if ((pi = zend_hash_str_find_ptr(&obj->zo.ce->properties_info, name_str, lenof(name_str)))) { \
915 zend_hash_update(props, pi->name, &tmp); \
919 UPDATE_PROP("type", ZVAL_LONG(&tmp
, obj
->message
->type
));
921 ver_len
= spprintf(&ver_str
, 0, "%u.%u", obj
->message
->http
.version
.major
, obj
->message
->http
.version
.minor
);
922 UPDATE_PROP("httpVersion", ZVAL_STR(&tmp
, php_http_cs2zs(ver_str
, ver_len
)));
924 switch (obj
->message
->type
) {
925 case PHP_HTTP_REQUEST
:
926 UPDATE_PROP("responseCode", ZVAL_LONG(&tmp
, 0));
927 UPDATE_PROP("responseStatus", ZVAL_EMPTY_STRING(&tmp
));
928 UPDATE_PROP("requestMethod", ZVAL_STRING(&tmp
, STR_PTR(obj
->message
->http
.info
.request
.method
)));
929 if (obj
->message
->http
.info
.request
.url
) {
930 php_http_url_to_string(obj
->message
->http
.info
.request
.url
, &url_str
, &url_len
, 0);
931 UPDATE_PROP("requestUrl", ZVAL_STR(&tmp
, php_http_cs2zs(url_str
, url_len
)));
933 UPDATE_PROP("requestUrl", ZVAL_EMPTY_STRING(&tmp
));
938 case PHP_HTTP_RESPONSE
:
939 UPDATE_PROP("responseCode", ZVAL_LONG(&tmp
, obj
->message
->http
.info
.response
.code
));
940 UPDATE_PROP("responseStatus", ZVAL_STRING(&tmp
, STR_PTR(obj
->message
->http
.info
.response
.status
)));
941 UPDATE_PROP("requestMethod", ZVAL_EMPTY_STRING(&tmp
));
942 UPDATE_PROP("requestUrl", ZVAL_EMPTY_STRING(&tmp
));
947 UPDATE_PROP("responseCode", ZVAL_LONG(&tmp
, 0));
948 UPDATE_PROP("responseStatus", ZVAL_EMPTY_STRING(&tmp
));
949 UPDATE_PROP("requestMethod", ZVAL_EMPTY_STRING(&tmp
));
950 UPDATE_PROP("requestUrl", ZVAL_EMPTY_STRING(&tmp
));
954 UPDATE_PROP("headers",
956 array_copy(&obj
->message
->hdrs
, Z_ARRVAL(tmp
));
961 ZVAL_OBJECT(&tmp
, &obj
->body
->zo
, 1);
967 UPDATE_PROP("parentMessage",
968 if (obj
->message
->parent
) {
969 ZVAL_OBJECT(&tmp
, &obj
->parent
->zo
, 1);
978 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage___construct
, 0, 0, 0)
979 ZEND_ARG_INFO(0, message
)
980 ZEND_ARG_INFO(0, greedy
)
982 static PHP_METHOD(HttpMessage
, __construct
)
984 zend_bool greedy
= 1;
985 zval
*zmessage
= NULL
;
986 php_http_message_t
*msg
= NULL
;
987 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
988 zend_error_handling zeh
;
990 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "|z!b", &zmessage
, &greedy
), invalid_arg
, return);
992 zend_replace_error_handling(EH_THROW
, php_http_exception_bad_message_class_entry
, &zeh
);
993 if (zmessage
&& Z_TYPE_P(zmessage
) == IS_RESOURCE
) {
995 php_http_message_parser_t p
;
996 zend_error_handling zeh
;
998 zend_replace_error_handling(EH_THROW
, php_http_exception_unexpected_val_class_entry
, &zeh
);
999 php_stream_from_zval(s
, zmessage
);
1000 zend_restore_error_handling(&zeh
);
1002 if (s
&& php_http_message_parser_init(&p
)) {
1003 unsigned flags
= (greedy
? PHP_HTTP_MESSAGE_PARSER_GREEDY
: 0);
1004 php_http_buffer_t buf
;
1006 php_http_buffer_init_ex(&buf
, 0x1000, PHP_HTTP_BUFFER_INIT_PREALLOC
);
1007 if (PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE
== php_http_message_parser_parse_stream(&p
, &buf
, s
, flags
, &msg
)) {
1008 if (!EG(exception
)) {
1009 php_http_throw(bad_message
, "Could not parse message from stream", NULL
);
1012 php_http_buffer_dtor(&buf
);
1013 php_http_message_parser_dtor(&p
);
1016 if (!msg
&& !EG(exception
)) {
1017 php_http_throw(bad_message
, "Empty message received from stream", NULL
);
1019 } else if (zmessage
) {
1020 zend_string
*zs_msg
= zval_get_string(zmessage
);
1022 msg
= php_http_message_parse(NULL
, zs_msg
->val
, zs_msg
->len
, greedy
);
1024 if (!msg
&& !EG(exception
)) {
1025 php_http_throw(bad_message
, "Could not parse message: %.*s", MIN(25, zs_msg
->len
), zs_msg
->val
);
1027 zend_string_release(zs_msg
);
1031 php_http_message_dtor(obj
->message
);
1033 if (obj
->message
->parent
) {
1034 obj
->parent
= php_http_message_object_new_ex(obj
->zo
.ce
, obj
->message
->parent
);
1037 zend_restore_error_handling(&zeh
);
1038 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1041 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getBody
, 0, 0, 0)
1042 ZEND_END_ARG_INFO();
1043 static PHP_METHOD(HttpMessage
, getBody
)
1045 php_http_message_object_t
*obj
;
1047 php_http_expect(SUCCESS
== zend_parse_parameters_none(), invalid_arg
, return);
1049 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1050 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1053 php_http_message_object_init_body_object(obj
);
1057 RETVAL_OBJECT(&obj
->body
->zo
, 1);
1061 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setBody
, 0, 0, 1)
1062 ZEND_ARG_OBJ_INFO(0, body
, http
\\Message
\\Body
, 0)
1063 ZEND_END_ARG_INFO();
1064 static PHP_METHOD(HttpMessage
, setBody
)
1068 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zbody
, php_http_message_body_class_entry
)) {
1069 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1071 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1072 php_http_message_object_prophandler_set_body(obj
, zbody
);
1074 RETVAL_ZVAL_FAST(getThis());
1077 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_addBody
, 0, 0, 1)
1078 ZEND_ARG_OBJ_INFO(0, body
, http
\\Message
\\Body
, 0)
1079 ZEND_END_ARG_INFO();
1080 static PHP_METHOD(HttpMessage
, addBody
)
1084 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "O", &new_body
, php_http_message_body_class_entry
)) {
1085 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1086 php_http_message_body_object_t
*new_obj
= PHP_HTTP_OBJ(NULL
, new_body
);
1088 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1089 php_http_message_body_to_callback(new_obj
->body
, (php_http_pass_callback_t
) php_http_message_body_append
, obj
->message
->body
, 0, 0);
1091 RETVAL_ZVAL_FAST(getThis());
1094 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getHeader
, 0, 0, 1)
1095 ZEND_ARG_INFO(0, header
)
1096 ZEND_ARG_INFO(0, into_class
)
1097 ZEND_END_ARG_INFO();
1098 static PHP_METHOD(HttpMessage
, getHeader
)
1102 zend_class_entry
*header_ce
= NULL
;
1104 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "s|C!", &header_str
, &header_len
, &header_ce
)) {
1105 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1108 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1110 if ((header
= php_http_message_header(obj
->message
, header_str
, header_len
))) {
1112 RETURN_ZVAL_FAST(header
);
1113 } else if (instanceof_function(header_ce
, php_http_header_class_entry
)) {
1114 php_http_object_method_t cb
;
1117 ZVAL_STRINGL(&argv
[0], header_str
, header_len
);
1118 ZVAL_COPY(&argv
[1], header
);
1120 object_init_ex(return_value
, header_ce
);
1121 php_http_object_method_init(&cb
, return_value
, ZEND_STRL("__construct"));
1122 php_http_object_method_call(&cb
, return_value
, NULL
, 2, argv
);
1123 php_http_object_method_dtor(&cb
);
1125 zval_ptr_dtor(&argv
[0]);
1126 zval_ptr_dtor(&argv
[1]);
1130 php_error_docref(NULL
, E_WARNING
, "Class '%s' is not as descendant of http\\Header", header_ce
->name
->val
);
1137 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getHeaders
, 0, 0, 0)
1138 ZEND_END_ARG_INFO();
1139 static PHP_METHOD(HttpMessage
, getHeaders
)
1141 if (SUCCESS
== zend_parse_parameters_none()) {
1142 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1144 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1146 array_init(return_value
);
1147 array_copy(&obj
->message
->hdrs
, Z_ARRVAL_P(return_value
));
1151 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setHeader
, 0, 0, 1)
1152 ZEND_ARG_INFO(0, header
)
1153 ZEND_ARG_INFO(0, value
)
1154 ZEND_END_ARG_INFO();
1155 static PHP_METHOD(HttpMessage
, setHeader
)
1157 zval
*zvalue
= NULL
;
1161 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "s|z!", &name_str
, &name_len
, &zvalue
)) {
1162 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1163 char *name
= php_http_pretty_key(estrndup(name_str
, name_len
), name_len
, 1, 1);
1165 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1168 zend_symtable_str_del(&obj
->message
->hdrs
, name
, name_len
);
1170 Z_TRY_ADDREF_P(zvalue
);
1171 zend_symtable_str_update(&obj
->message
->hdrs
, name
, name_len
, zvalue
);
1175 RETVAL_ZVAL_FAST(getThis());
1178 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setHeaders
, 0, 0, 1)
1179 ZEND_ARG_ARRAY_INFO(0, headers
, 1)
1180 ZEND_END_ARG_INFO();
1181 static PHP_METHOD(HttpMessage
, setHeaders
)
1183 zval
*new_headers
= NULL
;
1185 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "a/!", &new_headers
)) {
1186 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1188 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1190 zend_hash_clean(&obj
->message
->hdrs
);
1192 array_join(Z_ARRVAL_P(new_headers
), &obj
->message
->hdrs
, 0, ARRAY_JOIN_PRETTIFY
|ARRAY_JOIN_STRONLY
);
1195 RETVAL_ZVAL_FAST(getThis());
1198 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_addHeader
, 0, 0, 2)
1199 ZEND_ARG_INFO(0, header
)
1200 ZEND_ARG_INFO(0, value
)
1201 ZEND_END_ARG_INFO();
1202 static PHP_METHOD(HttpMessage
, addHeader
)
1208 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &name_str
, &name_len
, &zvalue
)) {
1209 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1210 char *name
= php_http_pretty_key(estrndup(name_str
, name_len
), name_len
, 1, 1);
1213 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1215 Z_TRY_ADDREF_P(zvalue
);
1216 if ((header
= php_http_message_header(obj
->message
, name
, name_len
))) {
1217 convert_to_array(header
);
1218 zend_hash_next_index_insert(Z_ARRVAL_P(header
), zvalue
);
1220 zend_symtable_str_update(&obj
->message
->hdrs
, name
, name_len
, zvalue
);
1224 RETVAL_ZVAL_FAST(getThis());
1227 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_addHeaders
, 0, 0, 1)
1228 ZEND_ARG_ARRAY_INFO(0, headers
, 0)
1229 ZEND_ARG_INFO(0, append
)
1230 ZEND_END_ARG_INFO();
1231 static PHP_METHOD(HttpMessage
, addHeaders
)
1234 zend_bool append
= 0;
1236 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "a|b", &new_headers
, &append
)) {
1237 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1239 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1241 array_join(Z_ARRVAL_P(new_headers
), &obj
->message
->hdrs
, append
, ARRAY_JOIN_STRONLY
|ARRAY_JOIN_PRETTIFY
);
1243 RETVAL_ZVAL_FAST(getThis());
1246 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getType
, 0, 0, 0)
1247 ZEND_END_ARG_INFO();
1248 static PHP_METHOD(HttpMessage
, getType
)
1250 if (SUCCESS
== zend_parse_parameters_none()) {
1251 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1253 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1255 RETURN_LONG(obj
->message
->type
);
1259 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setType
, 0, 0, 1)
1260 ZEND_ARG_INFO(0, type
)
1261 ZEND_END_ARG_INFO();
1262 static PHP_METHOD(HttpMessage
, setType
)
1266 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "l", &type
)) {
1267 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1269 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1271 php_http_message_set_type(obj
->message
, type
);
1273 RETVAL_ZVAL_FAST(getThis());
1276 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getInfo
, 0, 0, 0)
1277 ZEND_END_ARG_INFO();
1278 static PHP_METHOD(HttpMessage
, getInfo
)
1280 if (SUCCESS
== zend_parse_parameters_none()) {
1281 char *str
, *tmp
= NULL
;
1283 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1285 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1287 switch (obj
->message
->type
) {
1288 case PHP_HTTP_REQUEST
:
1289 len
= spprintf(&str
, 0, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&obj
->message
->http
, tmp
, ""));
1292 case PHP_HTTP_RESPONSE
:
1293 len
= spprintf(&str
, 0, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&obj
->message
->http
, tmp
, ""));
1301 RETVAL_STR(php_http_cs2zs(str
, len
));
1305 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setInfo
, 0, 0, 1)
1306 ZEND_ARG_INFO(0, http_info
)
1307 ZEND_END_ARG_INFO();
1308 static PHP_METHOD(HttpMessage
, setInfo
)
1312 php_http_message_object_t
*obj
;
1313 php_http_info_t inf
;
1315 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str
, &len
), invalid_arg
, return);
1317 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1318 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1320 if (!php_http_info_parse(&inf
, str
)) {
1321 php_http_throw(bad_header
, "Could not parse message info '%s'", str
);
1325 php_http_message_set_info(obj
->message
, &inf
);
1326 php_http_info_dtor(&inf
);
1328 RETVAL_ZVAL_FAST(getThis());
1331 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getHttpVersion
, 0, 0, 0)
1332 ZEND_END_ARG_INFO();
1333 static PHP_METHOD(HttpMessage
, getHttpVersion
)
1335 if (SUCCESS
== zend_parse_parameters_none()) {
1338 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1340 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1342 php_http_version_to_string(&obj
->message
->http
.version
, &str
, &len
, NULL
, NULL
);
1343 RETURN_STR(php_http_cs2zs(str
, len
));
1347 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setHttpVersion
, 0, 0, 1)
1348 ZEND_ARG_INFO(0, http_version
)
1349 ZEND_END_ARG_INFO();
1350 static PHP_METHOD(HttpMessage
, setHttpVersion
)
1354 php_http_version_t version
;
1355 php_http_message_object_t
*obj
;
1357 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "s", &v_str
, &v_len
), invalid_arg
, return);
1359 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1360 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1362 php_http_expect(php_http_version_parse(&version
, v_str
), unexpected_val
, return);
1364 obj
->message
->http
.version
= version
;
1366 RETVAL_ZVAL_FAST(getThis());
1369 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getResponseCode
, 0, 0, 0)
1370 ZEND_END_ARG_INFO();
1371 static PHP_METHOD(HttpMessage
, getResponseCode
)
1373 if (SUCCESS
== zend_parse_parameters_none()) {
1374 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1376 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1378 if (obj
->message
->type
!= PHP_HTTP_RESPONSE
) {
1379 php_error_docref(NULL
, E_WARNING
, "http\\Message is not if type response");
1383 RETURN_LONG(obj
->message
->http
.info
.response
.code
);
1387 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setResponseCode
, 0, 0, 1)
1388 ZEND_ARG_INFO(0, response_code
)
1389 ZEND_ARG_INFO(0, strict
)
1390 ZEND_END_ARG_INFO();
1391 static PHP_METHOD(HttpMessage
, setResponseCode
)
1394 zend_bool strict
= 1;
1395 php_http_message_object_t
*obj
;
1397 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l|b", &code
, &strict
), invalid_arg
, return);
1399 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1400 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1402 if (obj
->message
->type
!= PHP_HTTP_RESPONSE
) {
1403 php_http_throw(bad_method_call
, "http\\Message is not of type response", NULL
);
1407 if (strict
&& (code
< 100 || code
> 599)) {
1408 php_http_throw(invalid_arg
, "Invalid response code (100-599): %ld", code
);
1412 obj
->message
->http
.info
.response
.code
= code
;
1413 PTR_SET(obj
->message
->http
.info
.response
.status
, estrdup(php_http_env_get_response_status_for_code(code
)));
1415 RETVAL_ZVAL_FAST(getThis());
1418 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getResponseStatus
, 0, 0, 0)
1419 ZEND_END_ARG_INFO();
1420 static PHP_METHOD(HttpMessage
, getResponseStatus
)
1422 if (SUCCESS
== zend_parse_parameters_none()) {
1423 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1425 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1427 if (obj
->message
->type
!= PHP_HTTP_RESPONSE
) {
1428 php_error_docref(NULL
, E_WARNING
, "http\\Message is not of type response");
1431 if (obj
->message
->http
.info
.response
.status
) {
1432 RETURN_STRING(obj
->message
->http
.info
.response
.status
);
1434 RETURN_EMPTY_STRING();
1439 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setResponseStatus
, 0, 0, 1)
1440 ZEND_ARG_INFO(0, response_status
)
1441 ZEND_END_ARG_INFO();
1442 static PHP_METHOD(HttpMessage
, setResponseStatus
)
1446 php_http_message_object_t
*obj
;
1448 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &status
, &status_len
), invalid_arg
, return);
1450 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1452 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1454 if (obj
->message
->type
!= PHP_HTTP_RESPONSE
) {
1455 php_http_throw(bad_method_call
, "http\\Message is not of type response", NULL
);
1458 PTR_SET(obj
->message
->http
.info
.response
.status
, estrndup(status
, status_len
));
1459 RETVAL_ZVAL_FAST(getThis());
1462 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getRequestMethod
, 0, 0, 0)
1463 ZEND_END_ARG_INFO();
1464 static PHP_METHOD(HttpMessage
, getRequestMethod
)
1466 if (SUCCESS
== zend_parse_parameters_none()) {
1467 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1469 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1471 if (obj
->message
->type
!= PHP_HTTP_REQUEST
) {
1472 php_error_docref(NULL
, E_WARNING
, "http\\Message is not of type request");
1476 if (obj
->message
->http
.info
.request
.method
) {
1477 RETURN_STRING(obj
->message
->http
.info
.request
.method
);
1479 RETURN_EMPTY_STRING();
1484 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setRequestMethod
, 0, 0, 1)
1485 ZEND_ARG_INFO(0, request_method
)
1486 ZEND_END_ARG_INFO();
1487 static PHP_METHOD(HttpMessage
, setRequestMethod
)
1491 php_http_message_object_t
*obj
;
1493 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "s", &method
, &method_len
), invalid_arg
, return);
1495 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1497 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1499 if (obj
->message
->type
!= PHP_HTTP_REQUEST
) {
1500 php_http_throw(bad_method_call
, "http\\Message is not of type request", NULL
);
1504 if (method_len
< 1) {
1505 php_http_throw(invalid_arg
, "Cannot set http\\Message's request method to an empty string", NULL
);
1509 PTR_SET(obj
->message
->http
.info
.request
.method
, estrndup(method
, method_len
));
1510 RETVAL_ZVAL_FAST(getThis());
1513 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getRequestUrl
, 0, 0, 0)
1514 ZEND_END_ARG_INFO();
1515 static PHP_METHOD(HttpMessage
, getRequestUrl
)
1517 if (SUCCESS
== zend_parse_parameters_none()) {
1518 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1520 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1522 if (obj
->message
->type
!= PHP_HTTP_REQUEST
) {
1523 php_error_docref(NULL
, E_WARNING
, "http\\Message is not of type request");
1527 if (obj
->message
->http
.info
.request
.url
) {
1531 php_http_url_to_string(obj
->message
->http
.info
.request
.url
, &url_str
, &url_len
, 0);
1532 RETURN_STR(php_http_cs2zs(url_str
, url_len
));
1534 RETURN_EMPTY_STRING();
1539 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setRequestUrl
, 0, 0, 1)
1540 ZEND_ARG_INFO(0, url
)
1541 ZEND_END_ARG_INFO();
1542 static PHP_METHOD(HttpMessage
, setRequestUrl
)
1545 php_http_url_t
*url
;
1546 php_http_message_object_t
*obj
;
1547 zend_error_handling zeh
;
1549 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zurl
), invalid_arg
, return);
1551 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1553 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1555 if (obj
->message
->type
!= PHP_HTTP_REQUEST
) {
1556 php_http_throw(bad_method_call
, "http\\Message is not of type request", NULL
);
1560 zend_replace_error_handling(EH_THROW
, php_http_exception_bad_url_class_entry
, &zeh
);
1561 url
= php_http_url_from_zval(zurl
, ~0);
1562 zend_restore_error_handling(&zeh
);
1564 if (php_http_url_is_empty(url
)) {
1565 php_http_url_free(&url
);
1566 php_http_throw(invalid_arg
, "Cannot set http\\Message's request url to an empty string", NULL
);
1568 PTR_SET(obj
->message
->http
.info
.request
.url
, url
);
1571 RETVAL_ZVAL_FAST(getThis());
1574 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getParentMessage
, 0, 0, 0)
1575 ZEND_END_ARG_INFO();
1576 static PHP_METHOD(HttpMessage
, getParentMessage
)
1578 php_http_message_object_t
*obj
;
1580 php_http_expect(SUCCESS
== zend_parse_parameters_none(), invalid_arg
, return);
1582 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1583 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1585 if (!obj
->message
->parent
) {
1586 php_http_throw(unexpected_val
, "http\\Message has not parent message", NULL
);
1590 RETVAL_OBJECT(&obj
->parent
->zo
, 1);
1593 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage___toString
, 0, 0, 0)
1594 ZEND_END_ARG_INFO();
1595 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toString
, 0, 0, 0)
1596 ZEND_ARG_INFO(0, include_parent
)
1597 ZEND_END_ARG_INFO();
1598 static PHP_METHOD(HttpMessage
, toString
)
1600 zend_bool include_parent
= 0;
1602 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &include_parent
)) {
1603 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1607 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1609 if (include_parent
) {
1610 php_http_message_serialize(obj
->message
, &string
, &length
);
1612 php_http_message_to_string(obj
->message
, &string
, &length
);
1615 RETURN_STR(php_http_cs2zs(string
, length
));
1618 RETURN_EMPTY_STRING();
1621 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toStream
, 0, 0, 1)
1622 ZEND_ARG_INFO(0, stream
)
1623 ZEND_END_ARG_INFO();
1624 static PHP_METHOD(HttpMessage
, toStream
)
1628 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zstream
)) {
1629 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1632 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1634 php_stream_from_zval(s
, zstream
);
1635 php_http_message_to_callback(obj
->message
, (php_http_pass_callback_t
) _php_stream_write
, s
);
1639 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toCallback
, 0, 0, 1)
1640 ZEND_ARG_INFO(0, callback
)
1641 ZEND_END_ARG_INFO();
1642 static PHP_METHOD(HttpMessage
, toCallback
)
1644 php_http_pass_fcall_arg_t fcd
;
1646 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "f", &fcd
.fci
, &fcd
.fcc
)) {
1647 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1649 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1651 ZVAL_COPY(&fcd
.fcz
, getThis());
1652 php_http_message_to_callback(obj
->message
, php_http_pass_fcall_callback
, &fcd
);
1653 zend_fcall_info_args_clear(&fcd
.fci
, 1);
1654 zval_ptr_dtor(&fcd
.fcz
);
1656 RETURN_ZVAL_FAST(getThis());
1660 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_serialize
, 0, 0, 0)
1661 ZEND_END_ARG_INFO();
1662 static PHP_METHOD(HttpMessage
, serialize
)
1664 if (SUCCESS
== zend_parse_parameters_none()) {
1665 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1669 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1671 php_http_message_serialize(obj
->message
, &string
, &length
);
1672 RETURN_STR(php_http_cs2zs(string
, length
));
1674 RETURN_EMPTY_STRING();
1677 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_unserialize
, 0, 0, 1)
1678 ZEND_ARG_INFO(0, serialized
)
1679 ZEND_END_ARG_INFO();
1680 static PHP_METHOD(HttpMessage
, unserialize
)
1685 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized
, &length
)) {
1686 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1687 php_http_message_t
*msg
;
1690 /* do not free recursively */
1691 php_http_message_dtor(obj
->message
);
1692 efree(obj
->message
);
1694 if ((msg
= php_http_message_parse(NULL
, serialized
, length
, 1))) {
1697 obj
->message
= php_http_message_init(NULL
, 0, NULL
);
1698 php_error_docref(NULL TSRMLS_CC
, E_ERROR
, "Could not unserialize http\\Message");
1703 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_detach
, 0, 0, 0)
1704 ZEND_END_ARG_INFO();
1705 static PHP_METHOD(HttpMessage
, detach
)
1707 php_http_message_object_t
*obj
, *new_obj
;
1708 php_http_message_t
*msg_cpy
;
1710 php_http_expect(SUCCESS
== zend_parse_parameters_none(), invalid_arg
, return);
1712 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1713 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1715 msg_cpy
= php_http_message_copy_ex(obj
->message
, NULL
, 0);
1716 new_obj
= php_http_message_object_new_ex(obj
->zo
.ce
, msg_cpy
);
1718 RETVAL_OBJ(&new_obj
->zo
);
1721 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_prepend
, 0, 0, 1)
1722 ZEND_ARG_OBJ_INFO(0, message
, http
\\Message
, 0)
1723 ZEND_ARG_INFO(0, top
)
1724 ZEND_END_ARG_INFO();
1725 static PHP_METHOD(HttpMessage
, prepend
)
1729 php_http_message_t
*msg
[2];
1730 php_http_message_object_t
*obj
, *prepend_obj
;
1732 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "O|b", &prepend
, php_http_message_class_entry
, &top
), invalid_arg
, return);
1734 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1735 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1736 prepend_obj
= PHP_HTTP_OBJ(NULL
, prepend
);
1737 PHP_HTTP_MESSAGE_OBJECT_INIT(prepend_obj
);
1740 for (msg
[0] = obj
->message
; msg
[0]; msg
[0] = msg
[0]->parent
) {
1741 for (msg
[1] = prepend_obj
->message
; msg
[1]; msg
[1] = msg
[1]->parent
) {
1742 if (msg
[0] == msg
[1]) {
1743 php_http_throw(unexpected_val
, "Cannot prepend a message located within the same message chain", NULL
);
1749 php_http_message_object_prepend(getThis(), prepend
, top
);
1750 RETURN_ZVAL_FAST(getThis());
1753 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_reverse
, 0, 0, 0)
1754 ZEND_END_ARG_INFO();
1755 static PHP_METHOD(HttpMessage
, reverse
)
1757 php_http_expect(SUCCESS
== zend_parse_parameters_none(), invalid_arg
, return);
1759 php_http_message_object_reverse(getThis(), return_value
);
1762 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_isMultipart
, 0, 0, 0)
1763 ZEND_ARG_INFO(1, boundary
)
1764 ZEND_END_ARG_INFO();
1765 static PHP_METHOD(HttpMessage
, isMultipart
)
1767 zval
*zboundary
= NULL
;
1769 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "|z!", &zboundary
)) {
1770 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1771 char *boundary
= NULL
;
1773 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1775 if (php_http_message_is_multipart(obj
->message
, zboundary
? &boundary
: NULL
)) {
1781 if (zboundary
&& boundary
) {
1782 ZVAL_DEREF(zboundary
);
1783 zval_dtor(zboundary
);
1784 ZVAL_STR(zboundary
, php_http_cs2zs(boundary
, strlen(boundary
)));
1789 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_splitMultipartBody
, 0, 0, 0)
1790 ZEND_END_ARG_INFO();
1791 static PHP_METHOD(HttpMessage
, splitMultipartBody
)
1793 php_http_message_object_t
*obj
;
1794 php_http_message_t
*msg
;
1795 char *boundary
= NULL
;
1797 php_http_expect(SUCCESS
== zend_parse_parameters_none(), invalid_arg
, return);
1799 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1800 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1802 if (!php_http_message_is_multipart(obj
->message
, &boundary
)) {
1803 php_http_throw(bad_method_call
, "http\\Message is not a multipart message", NULL
);
1807 php_http_expect(msg
= php_http_message_body_split(obj
->message
->body
, boundary
), bad_message
, return);
1811 RETURN_OBJ(&php_http_message_object_new_ex(obj
->zo
.ce
, msg
)->zo
);
1814 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_count
, 0, 0, 0)
1815 ZEND_END_ARG_INFO();
1816 static PHP_METHOD(HttpMessage
, count
)
1818 zend_long count_mode
= -1;
1820 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|l", &count_mode
)) {
1821 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1823 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1825 RETURN_LONG(php_http_message_count(obj
->message
));
1829 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_rewind
, 0, 0, 0)
1830 ZEND_END_ARG_INFO();
1831 static PHP_METHOD(HttpMessage
, rewind
)
1833 if (SUCCESS
== zend_parse_parameters_none()) {
1834 zval
*zobj
= getThis();
1835 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1837 if (!Z_ISUNDEF(obj
->iterator
)) {
1838 zval_ptr_dtor(&obj
->iterator
);
1840 ZVAL_COPY(&obj
->iterator
, zobj
);
1844 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_valid
, 0, 0, 0)
1845 ZEND_END_ARG_INFO();
1846 static PHP_METHOD(HttpMessage
, valid
)
1848 if (SUCCESS
== zend_parse_parameters_none()) {
1849 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1851 RETURN_BOOL(!Z_ISUNDEF(obj
->iterator
));
1855 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_next
, 0, 0, 0)
1856 ZEND_END_ARG_INFO();
1857 static PHP_METHOD(HttpMessage
, next
)
1859 if (SUCCESS
== zend_parse_parameters_none()) {
1860 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1862 if (!Z_ISUNDEF(obj
->iterator
)) {
1863 php_http_message_object_t
*itr
= PHP_HTTP_OBJ(NULL
, &obj
->iterator
);
1868 ZVAL_OBJECT(&tmp
, &itr
->parent
->zo
, 1);
1869 zval_ptr_dtor(&obj
->iterator
);
1870 obj
->iterator
= tmp
;
1872 zval_ptr_dtor(&obj
->iterator
);
1873 ZVAL_UNDEF(&obj
->iterator
);
1879 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_key
, 0, 0, 0)
1880 ZEND_END_ARG_INFO();
1881 static PHP_METHOD(HttpMessage
, key
)
1883 if (SUCCESS
== zend_parse_parameters_none()) {
1884 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1886 RETURN_LONG(Z_ISUNDEF(obj
->iterator
) ? 0 : Z_OBJ_HANDLE(obj
->iterator
));
1890 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_current
, 0, 0, 0)
1891 ZEND_END_ARG_INFO();
1892 static PHP_METHOD(HttpMessage
, current
)
1894 if (SUCCESS
== zend_parse_parameters_none()) {
1895 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1897 if (!Z_ISUNDEF(obj
->iterator
)) {
1898 RETURN_ZVAL_FAST(&obj
->iterator
);
1903 static zend_function_entry php_http_message_methods
[] = {
1904 PHP_ME(HttpMessage
, __construct
, ai_HttpMessage___construct
, ZEND_ACC_PUBLIC
|ZEND_ACC_CTOR
)
1905 PHP_ME(HttpMessage
, getBody
, ai_HttpMessage_getBody
, ZEND_ACC_PUBLIC
)
1906 PHP_ME(HttpMessage
, setBody
, ai_HttpMessage_setBody
, ZEND_ACC_PUBLIC
)
1907 PHP_ME(HttpMessage
, addBody
, ai_HttpMessage_addBody
, ZEND_ACC_PUBLIC
)
1908 PHP_ME(HttpMessage
, getHeader
, ai_HttpMessage_getHeader
, ZEND_ACC_PUBLIC
)
1909 PHP_ME(HttpMessage
, setHeader
, ai_HttpMessage_setHeader
, ZEND_ACC_PUBLIC
)
1910 PHP_ME(HttpMessage
, addHeader
, ai_HttpMessage_addHeader
, ZEND_ACC_PUBLIC
)
1911 PHP_ME(HttpMessage
, getHeaders
, ai_HttpMessage_getHeaders
, ZEND_ACC_PUBLIC
)
1912 PHP_ME(HttpMessage
, setHeaders
, ai_HttpMessage_setHeaders
, ZEND_ACC_PUBLIC
)
1913 PHP_ME(HttpMessage
, addHeaders
, ai_HttpMessage_addHeaders
, ZEND_ACC_PUBLIC
)
1914 PHP_ME(HttpMessage
, getType
, ai_HttpMessage_getType
, ZEND_ACC_PUBLIC
)
1915 PHP_ME(HttpMessage
, setType
, ai_HttpMessage_setType
, ZEND_ACC_PUBLIC
)
1916 PHP_ME(HttpMessage
, getInfo
, ai_HttpMessage_getInfo
, ZEND_ACC_PUBLIC
)
1917 PHP_ME(HttpMessage
, setInfo
, ai_HttpMessage_setInfo
, ZEND_ACC_PUBLIC
)
1918 PHP_ME(HttpMessage
, getResponseCode
, ai_HttpMessage_getResponseCode
, ZEND_ACC_PUBLIC
)
1919 PHP_ME(HttpMessage
, setResponseCode
, ai_HttpMessage_setResponseCode
, ZEND_ACC_PUBLIC
)
1920 PHP_ME(HttpMessage
, getResponseStatus
, ai_HttpMessage_getResponseStatus
, ZEND_ACC_PUBLIC
)
1921 PHP_ME(HttpMessage
, setResponseStatus
, ai_HttpMessage_setResponseStatus
, ZEND_ACC_PUBLIC
)
1922 PHP_ME(HttpMessage
, getRequestMethod
, ai_HttpMessage_getRequestMethod
, ZEND_ACC_PUBLIC
)
1923 PHP_ME(HttpMessage
, setRequestMethod
, ai_HttpMessage_setRequestMethod
, ZEND_ACC_PUBLIC
)
1924 PHP_ME(HttpMessage
, getRequestUrl
, ai_HttpMessage_getRequestUrl
, ZEND_ACC_PUBLIC
)
1925 PHP_ME(HttpMessage
, setRequestUrl
, ai_HttpMessage_setRequestUrl
, ZEND_ACC_PUBLIC
)
1926 PHP_ME(HttpMessage
, getHttpVersion
, ai_HttpMessage_getHttpVersion
, ZEND_ACC_PUBLIC
)
1927 PHP_ME(HttpMessage
, setHttpVersion
, ai_HttpMessage_setHttpVersion
, ZEND_ACC_PUBLIC
)
1928 PHP_ME(HttpMessage
, getParentMessage
, ai_HttpMessage_getParentMessage
, ZEND_ACC_PUBLIC
)
1929 PHP_ME(HttpMessage
, toString
, ai_HttpMessage_toString
, ZEND_ACC_PUBLIC
)
1930 PHP_ME(HttpMessage
, toCallback
, ai_HttpMessage_toCallback
, ZEND_ACC_PUBLIC
)
1931 PHP_ME(HttpMessage
, toStream
, ai_HttpMessage_toStream
, ZEND_ACC_PUBLIC
)
1933 /* implements Countable */
1934 PHP_ME(HttpMessage
, count
, ai_HttpMessage_count
, ZEND_ACC_PUBLIC
)
1936 /* implements Serializable */
1937 PHP_ME(HttpMessage
, serialize
, ai_HttpMessage_serialize
, ZEND_ACC_PUBLIC
)
1938 PHP_ME(HttpMessage
, unserialize
, ai_HttpMessage_unserialize
, ZEND_ACC_PUBLIC
)
1940 /* implements Iterator */
1941 PHP_ME(HttpMessage
, rewind
, ai_HttpMessage_rewind
, ZEND_ACC_PUBLIC
)
1942 PHP_ME(HttpMessage
, valid
, ai_HttpMessage_valid
, ZEND_ACC_PUBLIC
)
1943 PHP_ME(HttpMessage
, current
, ai_HttpMessage_current
, ZEND_ACC_PUBLIC
)
1944 PHP_ME(HttpMessage
, key
, ai_HttpMessage_key
, ZEND_ACC_PUBLIC
)
1945 PHP_ME(HttpMessage
, next
, ai_HttpMessage_next
, ZEND_ACC_PUBLIC
)
1947 ZEND_MALIAS(HttpMessage
, __toString
, toString
, ai_HttpMessage___toString
, ZEND_ACC_PUBLIC
)
1949 PHP_ME(HttpMessage
, detach
, ai_HttpMessage_detach
, ZEND_ACC_PUBLIC
)
1950 PHP_ME(HttpMessage
, prepend
, ai_HttpMessage_prepend
, ZEND_ACC_PUBLIC
)
1951 PHP_ME(HttpMessage
, reverse
, ai_HttpMessage_reverse
, ZEND_ACC_PUBLIC
)
1953 PHP_ME(HttpMessage
, isMultipart
, ai_HttpMessage_isMultipart
, ZEND_ACC_PUBLIC
)
1954 PHP_ME(HttpMessage
, splitMultipartBody
, ai_HttpMessage_splitMultipartBody
, ZEND_ACC_PUBLIC
)
1956 EMPTY_FUNCTION_ENTRY
1959 zend_class_entry
*php_http_message_class_entry
;
1961 PHP_MINIT_FUNCTION(http_message
)
1963 zend_class_entry ce
= {0};
1965 INIT_NS_CLASS_ENTRY(ce
, "http", "Message", php_http_message_methods
);
1966 php_http_message_class_entry
= zend_register_internal_class(&ce
);
1967 php_http_message_class_entry
->create_object
= php_http_message_object_new
;
1968 memcpy(&php_http_message_object_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
1969 php_http_message_object_handlers
.offset
= XtOffsetOf(php_http_message_object_t
, zo
);
1970 php_http_message_object_handlers
.clone_obj
= php_http_message_object_clone
;
1971 php_http_message_object_handlers
.free_obj
= php_http_message_object_free
;
1972 php_http_message_object_handlers
.read_property
= php_http_message_object_read_prop
;
1973 php_http_message_object_handlers
.write_property
= php_http_message_object_write_prop
;
1974 php_http_message_object_handlers
.get_properties
= php_http_message_object_get_props
;
1975 php_http_message_object_handlers
.get_property_ptr_ptr
= NULL
;
1977 zend_class_implements(php_http_message_class_entry
, 3, spl_ce_Countable
, zend_ce_serializable
, zend_ce_iterator
);
1979 zend_hash_init(&php_http_message_object_prophandlers
, 9, NULL
, php_http_message_object_prophandler_hash_dtor
, 1);
1980 zend_declare_property_long(php_http_message_class_entry
, ZEND_STRL("type"), PHP_HTTP_NONE
, ZEND_ACC_PROTECTED
);
1981 php_http_message_object_add_prophandler(ZEND_STRL("type"), php_http_message_object_prophandler_get_type
, php_http_message_object_prophandler_set_type
);
1982 zend_declare_property_null(php_http_message_class_entry
, ZEND_STRL("body"), ZEND_ACC_PROTECTED
);
1983 php_http_message_object_add_prophandler(ZEND_STRL("body"), php_http_message_object_prophandler_get_body
, php_http_message_object_prophandler_set_body
);
1984 zend_declare_property_string(php_http_message_class_entry
, ZEND_STRL("requestMethod"), "", ZEND_ACC_PROTECTED
);
1985 php_http_message_object_add_prophandler(ZEND_STRL("requestMethod"), php_http_message_object_prophandler_get_request_method
, php_http_message_object_prophandler_set_request_method
);
1986 zend_declare_property_string(php_http_message_class_entry
, ZEND_STRL("requestUrl"), "", ZEND_ACC_PROTECTED
);
1987 php_http_message_object_add_prophandler(ZEND_STRL("requestUrl"), php_http_message_object_prophandler_get_request_url
, php_http_message_object_prophandler_set_request_url
);
1988 zend_declare_property_string(php_http_message_class_entry
, ZEND_STRL("responseStatus"), "", ZEND_ACC_PROTECTED
);
1989 php_http_message_object_add_prophandler(ZEND_STRL("responseStatus"), php_http_message_object_prophandler_get_response_status
, php_http_message_object_prophandler_set_response_status
);
1990 zend_declare_property_long(php_http_message_class_entry
, ZEND_STRL("responseCode"), 0, ZEND_ACC_PROTECTED
);
1991 php_http_message_object_add_prophandler(ZEND_STRL("responseCode"), php_http_message_object_prophandler_get_response_code
, php_http_message_object_prophandler_set_response_code
);
1992 zend_declare_property_null(php_http_message_class_entry
, ZEND_STRL("httpVersion"), ZEND_ACC_PROTECTED
);
1993 php_http_message_object_add_prophandler(ZEND_STRL("httpVersion"), php_http_message_object_prophandler_get_http_version
, php_http_message_object_prophandler_set_http_version
);
1994 zend_declare_property_null(php_http_message_class_entry
, ZEND_STRL("headers"), ZEND_ACC_PROTECTED
);
1995 php_http_message_object_add_prophandler(ZEND_STRL("headers"), php_http_message_object_prophandler_get_headers
, php_http_message_object_prophandler_set_headers
);
1996 zend_declare_property_null(php_http_message_class_entry
, ZEND_STRL("parentMessage"), ZEND_ACC_PROTECTED
);
1997 php_http_message_object_add_prophandler(ZEND_STRL("parentMessage"), php_http_message_object_prophandler_get_parent_message
, php_http_message_object_prophandler_set_parent_message
);
1999 zend_declare_class_constant_long(php_http_message_class_entry
, ZEND_STRL("TYPE_NONE"), PHP_HTTP_NONE
);
2000 zend_declare_class_constant_long(php_http_message_class_entry
, ZEND_STRL("TYPE_REQUEST"), PHP_HTTP_REQUEST
);
2001 zend_declare_class_constant_long(php_http_message_class_entry
, ZEND_STRL("TYPE_RESPONSE"), PHP_HTTP_RESPONSE
);
2006 PHP_MSHUTDOWN_FUNCTION(http_message
)
2008 zend_hash_destroy(&php_http_message_object_prophandlers
);
2018 * vim600: noet sw=4 ts=4 fdm=marker
2019 * vim<600: noet sw=4 ts=4