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 ((size
= php_http_message_body_size(msg
->body
))) {
280 zend_hash_str_update(&msg
->hdrs
, "Content-Length", lenof("Content-Length"), &h
);
282 if (msg
->body
->boundary
) {
287 if (!(ct
= php_http_message_header_string(msg
, ZEND_STRL("Content-Type")))) {
288 len
= spprintf(&str
, 0, "multipart/form-data; boundary=\"%s\"", msg
->body
->boundary
);
289 ZVAL_STR(&h
, php_http_cs2zs(str
, len
));
290 zend_hash_str_update(&msg
->hdrs
, "Content-Type", lenof("Content-Type"), &h
);
291 } else if (!php_http_match(ct
->val
, "boundary=", PHP_HTTP_MATCH_WORD
)) {
292 len
= spprintf(&str
, 0, "%s; boundary=\"%s\"", ct
->val
, msg
->body
->boundary
);
293 ZVAL_STR(&h
, php_http_cs2zs(str
, len
));
294 zend_hash_str_update(&msg
->hdrs
, "Content-Type", lenof("Content-Type"), &h
);
295 zend_string_release(ct
);
297 zend_string_release(ct
);
300 } else if ((cl
= php_http_message_header_string(msg
, ZEND_STRL("Content-Length")))) {
301 if (!zend_string_equals_literal(cl
, "0")) {
302 zend_hash_str_del(&msg
->hdrs
, ZEND_STRL("Content-Length"));
304 zend_string_release(cl
);
308 static void message_headers(php_http_message_t
*msg
, php_http_buffer_t
*str
)
313 case PHP_HTTP_REQUEST
:
314 php_http_buffer_appendf(str
, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&msg
->http
, tmp
, PHP_HTTP_CRLF
));
318 case PHP_HTTP_RESPONSE
:
319 php_http_buffer_appendf(str
, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&msg
->http
, tmp
, PHP_HTTP_CRLF
));
327 php_http_message_update_headers(msg
);
328 php_http_header_to_string(str
, &msg
->hdrs
);
331 void php_http_message_to_callback(php_http_message_t
*msg
, php_http_pass_callback_t cb
, void *cb_arg
)
333 php_http_buffer_t str
;
335 php_http_buffer_init_ex(&str
, 0x1000, 0);
336 message_headers(msg
, &str
);
337 cb(cb_arg
, str
.data
, str
.used
);
338 php_http_buffer_dtor(&str
);
340 if (php_http_message_body_size(msg
->body
)) {
341 cb(cb_arg
, ZEND_STRL(PHP_HTTP_CRLF
));
342 php_http_message_body_to_callback(msg
->body
, cb
, cb_arg
, 0, 0);
346 void php_http_message_to_string(php_http_message_t
*msg
, char **string
, size_t *length
)
348 php_http_buffer_t str
;
351 php_http_buffer_init_ex(&str
, 0x1000, 0);
352 message_headers(msg
, &str
);
353 if (php_http_message_body_size(msg
->body
)) {
354 php_http_buffer_appends(&str
, PHP_HTTP_CRLF
);
355 php_http_message_body_to_callback(msg
->body
, (php_http_pass_callback_t
) php_http_buffer_append
, &str
, 0, 0);
358 data
= php_http_buffer_data(&str
, string
, length
);
363 php_http_buffer_dtor(&str
);
366 void php_http_message_serialize(php_http_message_t
*message
, char **string
, size_t *length
)
369 php_http_buffer_t str
;
370 php_http_message_t
*msg
;
372 php_http_buffer_init(&str
);
374 msg
= message
= php_http_message_reverse(message
);
376 php_http_message_to_callback(message
, (php_http_pass_callback_t
) php_http_buffer_append
, &str
);
377 php_http_buffer_appends(&str
, PHP_HTTP_CRLF
);
378 } while ((message
= message
->parent
));
379 php_http_message_reverse(msg
);
381 buf
= php_http_buffer_data(&str
, string
, length
);
386 php_http_buffer_dtor(&str
);
389 php_http_message_t
*php_http_message_reverse(php_http_message_t
*msg
)
391 size_t i
, c
= php_http_message_count(msg
);
394 php_http_message_t
*tmp
= msg
, **arr
;
396 arr
= ecalloc(c
, sizeof(**arr
));
397 for (i
= 0; i
< c
; ++i
) {
401 arr
[0]->parent
= NULL
;
402 for (i
= 0; i
< c
-1; ++i
) {
403 arr
[i
+1]->parent
= arr
[i
];
413 php_http_message_t
*php_http_message_zip(php_http_message_t
*dst
, php_http_message_t
*src
)
415 php_http_message_t
*tmp_dst
, *tmp_src
, *ret
= dst
;
418 tmp_dst
= dst
->parent
;
419 tmp_src
= src
->parent
;
422 src
->parent
= tmp_dst
;
431 php_http_message_t
*php_http_message_copy_ex(php_http_message_t
*from
, php_http_message_t
*to
, zend_bool parents
)
433 php_http_message_t
*temp
, *copy
= NULL
;
434 php_http_info_t info
;
437 info
.type
= from
->type
;
438 info
.http
= from
->http
;
440 copy
= temp
= php_http_message_init(to
, 0, php_http_message_body_copy(from
->body
, NULL
));
441 php_http_message_set_info(temp
, &info
);
442 zend_hash_copy(&temp
->hdrs
, &from
->hdrs
, (copy_ctor_func_t
) zval_add_ref
);
444 if (parents
) while (from
->parent
) {
445 info
.type
= from
->parent
->type
;
446 info
.http
= from
->parent
->http
;
448 temp
->parent
= php_http_message_init(NULL
, 0, php_http_message_body_copy(from
->parent
->body
, NULL
));
449 php_http_message_set_info(temp
->parent
, &info
);
450 array_copy(&from
->parent
->hdrs
, &temp
->parent
->hdrs
);
460 void php_http_message_dtor(php_http_message_t
*message
)
463 zend_hash_destroy(&message
->hdrs
);
464 php_http_message_body_free(&message
->body
);
466 switch (message
->type
) {
467 case PHP_HTTP_REQUEST
:
468 PTR_SET(message
->http
.info
.request
.method
, NULL
);
469 PTR_SET(message
->http
.info
.request
.url
, NULL
);
472 case PHP_HTTP_RESPONSE
:
473 PTR_SET(message
->http
.info
.response
.status
, NULL
);
482 void php_http_message_free(php_http_message_t
**message
)
485 if ((*message
)->parent
) {
486 php_http_message_free(&(*message
)->parent
);
488 php_http_message_dtor(*message
);
494 static zval
*php_http_message_object_read_prop(zval
*object
, zval
*member
, int type
, void **cache_slot
, zval
*rv
);
495 static void php_http_message_object_write_prop(zval
*object
, zval
*member
, zval
*value
, void **cache_slot
);
496 static HashTable
*php_http_message_object_get_props(zval
*object
);
498 static zend_object_handlers php_http_message_object_handlers
;
499 static HashTable php_http_message_object_prophandlers
;
501 static void php_http_message_object_prophandler_hash_dtor(zval
*pData
)
503 pefree(Z_PTR_P(pData
), 1);
506 typedef void (*php_http_message_object_prophandler_func_t
)(php_http_message_object_t
*o
, zval
*v
);
508 typedef struct php_http_message_object_prophandler
{
509 php_http_message_object_prophandler_func_t read
;
510 php_http_message_object_prophandler_func_t write
;
511 } php_http_message_object_prophandler_t
;
513 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
) {
514 php_http_message_object_prophandler_t h
= { read
, write
};
515 if (!zend_hash_str_add_mem(&php_http_message_object_prophandlers
, prop_str
, prop_len
, (void *) &h
, sizeof(h
))) {
520 static php_http_message_object_prophandler_t
*php_http_message_object_get_prophandler(zend_string
*name_str
) {
521 return zend_hash_str_find_ptr(&php_http_message_object_prophandlers
, name_str
->val
, name_str
->len
);
523 static void php_http_message_object_prophandler_get_type(php_http_message_object_t
*obj
, zval
*return_value
) {
524 RETVAL_LONG(obj
->message
->type
);
526 static void php_http_message_object_prophandler_set_type(php_http_message_object_t
*obj
, zval
*value
) {
527 php_http_message_set_type(obj
->message
, zval_get_long(value
));
529 static void php_http_message_object_prophandler_get_request_method(php_http_message_object_t
*obj
, zval
*return_value
) {
530 if (PHP_HTTP_MESSAGE_TYPE(REQUEST
, obj
->message
) && obj
->message
->http
.info
.request
.method
) {
531 RETVAL_STRING(obj
->message
->http
.info
.request
.method
);
536 static void php_http_message_object_prophandler_set_request_method(php_http_message_object_t
*obj
, zval
*value
) {
537 if (PHP_HTTP_MESSAGE_TYPE(REQUEST
, obj
->message
)) {
538 zend_string
*zs
= zval_get_string(value
);
539 PTR_SET(obj
->message
->http
.info
.request
.method
, estrndup(zs
->val
, zs
->len
));
540 zend_string_release(zs
);
543 static void php_http_message_object_prophandler_get_request_url(php_http_message_object_t
*obj
, zval
*return_value
) {
547 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)) {
548 RETVAL_STR(php_http_cs2zs(url_str
, url_len
));
553 static void php_http_message_object_prophandler_set_request_url(php_http_message_object_t
*obj
, zval
*value
) {
554 if (PHP_HTTP_MESSAGE_TYPE(REQUEST
, obj
->message
)) {
555 PTR_SET(obj
->message
->http
.info
.request
.url
, php_http_url_from_zval(value
, ~0));
558 static void php_http_message_object_prophandler_get_response_status(php_http_message_object_t
*obj
, zval
*return_value
) {
559 if (PHP_HTTP_MESSAGE_TYPE(RESPONSE
, obj
->message
) && obj
->message
->http
.info
.response
.status
) {
560 RETVAL_STRING(obj
->message
->http
.info
.response
.status
);
565 static void php_http_message_object_prophandler_set_response_status(php_http_message_object_t
*obj
, zval
*value
) {
566 if (PHP_HTTP_MESSAGE_TYPE(RESPONSE
, obj
->message
)) {
567 zend_string
*zs
= zval_get_string(value
);
568 PTR_SET(obj
->message
->http
.info
.response
.status
, estrndup(zs
->val
, zs
->len
));
569 zend_string_release(zs
);
572 static void php_http_message_object_prophandler_get_response_code(php_http_message_object_t
*obj
, zval
*return_value
) {
573 if (PHP_HTTP_MESSAGE_TYPE(RESPONSE
, obj
->message
)) {
574 RETVAL_LONG(obj
->message
->http
.info
.response
.code
);
579 static void php_http_message_object_prophandler_set_response_code(php_http_message_object_t
*obj
, zval
*value
) {
580 if (PHP_HTTP_MESSAGE_TYPE(RESPONSE
, obj
->message
)) {
581 obj
->message
->http
.info
.response
.code
= zval_get_long(value
);
582 PTR_SET(obj
->message
->http
.info
.response
.status
, estrdup(php_http_env_get_response_status_for_code(obj
->message
->http
.info
.response
.code
)));
585 static void php_http_message_object_prophandler_get_http_version(php_http_message_object_t
*obj
, zval
*return_value
) {
589 php_http_version_to_string(&obj
->message
->http
.version
, &version_str
, &version_len
, NULL
, NULL
);
590 RETVAL_STR(php_http_cs2zs(version_str
, version_len
));
592 static void php_http_message_object_prophandler_set_http_version(php_http_message_object_t
*obj
, zval
*value
) {
593 zend_string
*zs
= zval_get_string(value
);
594 php_http_version_parse(&obj
->message
->http
.version
, zs
->val
);
595 zend_string_release(zs
);
597 static void php_http_message_object_prophandler_get_headers(php_http_message_object_t
*obj
, zval
*return_value
) {
598 array_init(return_value
);
599 array_copy(&obj
->message
->hdrs
, Z_ARRVAL_P(return_value
));
601 static void php_http_message_object_prophandler_set_headers(php_http_message_object_t
*obj
, zval
*value
) {
603 zval
*orig_value
= value
;
605 if (Z_TYPE_P(value
) != IS_ARRAY
&& Z_TYPE_P(value
) != IS_OBJECT
) {
606 convert_to_array_ex(value
);
608 headers
= HASH_OF(value
);
611 zend_hash_clean(&obj
->message
->hdrs
);
612 array_copy(headers
, &obj
->message
->hdrs
);
614 if (orig_value
!= value
) {
615 zval_ptr_dtor(value
);
618 static void php_http_message_object_prophandler_get_body(php_http_message_object_t
*obj
, zval
*return_value
) {
620 RETVAL_OBJECT(&obj
->body
->zo
, 1);
625 static void php_http_message_object_prophandler_set_body(php_http_message_object_t
*obj
, zval
*value
) {
626 php_http_message_object_set_body(obj
, value
);
628 static void php_http_message_object_prophandler_get_parent_message(php_http_message_object_t
*obj
, zval
*return_value
) {
629 if (obj
->message
->parent
) {
630 RETVAL_OBJECT(&obj
->parent
->zo
, 1);
635 static void php_http_message_object_prophandler_set_parent_message(php_http_message_object_t
*obj
, zval
*value
) {
636 if (Z_TYPE_P(value
) == IS_OBJECT
&& instanceof_function(Z_OBJCE_P(value
), php_http_message_class_entry
)) {
637 php_http_message_object_t
*parent_obj
= PHP_HTTP_OBJ(NULL
, value
);
639 if (obj
->message
->parent
) {
640 zend_objects_store_del(&obj
->parent
->zo
);
643 obj
->parent
= parent_obj
;
644 obj
->message
->parent
= parent_obj
->message
;
648 #define PHP_HTTP_MESSAGE_OBJECT_INIT(obj) \
650 if (!obj->message) { \
651 obj->message = php_http_message_init(NULL, 0, NULL); \
656 void php_http_message_object_reverse(zval
*zmsg
, zval
*return_value
)
659 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, zmsg
);
661 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
664 i
= php_http_message_count(obj
->message
);
667 php_http_message_object_t
**objects
;
670 objects
= ecalloc(i
, sizeof(**objects
));
672 /* we are the first message */
676 for (i
= 1; obj
->parent
; ++i
) {
677 objects
[i
] = obj
= obj
->parent
;
680 /* reorder parents */
681 for (last
= --i
; i
; --i
) {
682 objects
[i
]->message
->parent
= objects
[i
-1]->message
;
683 objects
[i
]->parent
= objects
[i
-1];
686 objects
[0]->message
->parent
= NULL
;
687 objects
[0]->parent
= NULL
;
689 /* add ref, because we previously have not been a parent message */
691 RETVAL_OBJ(&objects
[last
]->zo
);
695 RETURN_ZVAL_FAST(zmsg
);
699 void php_http_message_object_prepend(zval
*this_ptr
, zval
*prepend
, zend_bool top
)
701 php_http_message_t
*save_parent_msg
= NULL
;
702 php_http_message_object_t
*save_parent_obj
= NULL
, *obj
= PHP_HTTP_OBJ(NULL
, this_ptr
);
703 php_http_message_object_t
*prepend_obj
= PHP_HTTP_OBJ(NULL
, prepend
);
706 save_parent_obj
= obj
->parent
;
707 save_parent_msg
= obj
->message
->parent
;
709 /* iterate to the most parent object */
710 while (obj
->parent
) {
716 obj
->parent
= prepend_obj
;
717 obj
->message
->parent
= prepend_obj
->message
;
723 prepend_obj
->parent
= save_parent_obj
;
724 prepend_obj
->message
->parent
= save_parent_msg
;
728 ZEND_RESULT_CODE
php_http_message_object_set_body(php_http_message_object_t
*msg_obj
, zval
*zbody
)
731 zend_string
*body_str
;
732 php_http_message_body_t
*body
;
733 php_http_message_body_object_t
*body_obj
;
735 switch (Z_TYPE_P(zbody
)) {
737 php_stream_from_zval_no_verify(s
, zbody
);
739 php_http_throw(unexpected_val
, "The stream is not a valid resource", NULL
);
745 body
= php_http_message_body_init(NULL
, s
);
746 if (!(body_obj
= php_http_message_body_object_new_ex(php_http_message_body_class_entry
, body
))) {
747 php_http_message_body_free(&body
);
753 if (instanceof_function(Z_OBJCE_P(zbody
), php_http_message_body_class_entry
)) {
755 body_obj
= PHP_HTTP_OBJ(NULL
, zbody
);
761 body_str
= zval_get_string(zbody
);
762 s
= php_stream_temp_new();
763 php_stream_write(s
, body_str
->val
, body_str
->len
);
764 zend_string_release(body_str
);
769 if (!body_obj
->body
) {
770 body_obj
->body
= php_http_message_body_init(NULL
, NULL
);
773 zend_objects_store_del(&msg_obj
->body
->zo
);
775 if (msg_obj
->message
) {
776 php_http_message_body_free(&msg_obj
->message
->body
);
777 msg_obj
->message
->body
= php_http_message_body_init(&body_obj
->body
, NULL
);
779 msg_obj
->message
= php_http_message_init(NULL
, 0, php_http_message_body_init(&body_obj
->body
, NULL
));
781 msg_obj
->body
= body_obj
;
786 ZEND_RESULT_CODE
php_http_message_object_init_body_object(php_http_message_object_t
*obj
)
788 php_http_message_body_addref(obj
->message
->body
);
789 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
);
792 zend_object
*php_http_message_object_new(zend_class_entry
*ce
)
794 return &php_http_message_object_new_ex(ce
, NULL
)->zo
;
797 php_http_message_object_t
*php_http_message_object_new_ex(zend_class_entry
*ce
, php_http_message_t
*msg
)
799 php_http_message_object_t
*o
;
801 o
= ecalloc(1, sizeof(php_http_message_object_t
) + (ce
->default_properties_count
- 1) * sizeof(zval
));
802 zend_object_std_init(&o
->zo
, ce
);
803 object_properties_init(&o
->zo
, ce
);
808 o
->parent
= php_http_message_object_new_ex(ce
, msg
->parent
);
810 o
->body
= php_http_message_body_object_new_ex(php_http_message_body_class_entry
, php_http_message_body_init(&msg
->body
, NULL
));
813 o
->zo
.handlers
= &php_http_message_object_handlers
;
818 zend_object
*php_http_message_object_clone(zval
*this_ptr TSRMLS_DC
)
820 php_http_message_object_t
*new_obj
= NULL
;
821 php_http_message_object_t
*old_obj
= PHP_HTTP_OBJ(NULL
, this_ptr
);
823 new_obj
= php_http_message_object_new_ex(old_obj
->zo
.ce
, php_http_message_copy(old_obj
->message
, NULL
));
824 zend_objects_clone_members(&new_obj
->zo
, &old_obj
->zo
);
829 void php_http_message_object_free(zend_object
*object
)
831 php_http_message_object_t
*o
= PHP_HTTP_OBJ(object
, NULL
);
833 if (!Z_ISUNDEF(o
->iterator
)) {
834 zval_ptr_dtor(&o
->iterator
);
835 ZVAL_UNDEF(&o
->iterator
);
838 /* do NOT free recursivly */
839 php_http_message_dtor(o
->message
);
844 zend_objects_store_del(&o
->parent
->zo
);
848 zend_objects_store_del(&o
->body
->zo
);
851 zend_object_std_dtor(object
);
854 static zval
*php_http_message_object_read_prop(zval
*object
, zval
*member
, int type
, void **cache_slot
, zval
*return_value
)
856 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, object
);
857 php_http_message_object_prophandler_t
*handler
;
858 zend_string
*member_name
= zval_get_string(member
);
860 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
862 /* supplied retun_value lives on the stack of zend_read_property! */
863 return_value
= zend_get_std_object_handlers()->read_property(object
, member
, type
, cache_slot
, return_value
);
865 if ((handler
= php_http_message_object_get_prophandler(member_name
))) {
866 zval_dtor(return_value
);
868 if (type
== BP_VAR_R
) {
869 handler
->read(obj
, return_value
);
871 php_property_proxy_t
*proxy
= php_property_proxy_init(object
, member_name
);
872 RETVAL_OBJ(&php_property_proxy_object_new_ex(php_property_proxy_get_class_entry(), proxy
)->zo
);
876 zend_string_release(member_name
);
881 static void php_http_message_object_write_prop(zval
*object
, zval
*member
, zval
*value
, void **cache_slot
)
883 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, object
);
884 php_http_message_object_prophandler_t
*handler
;
885 zend_string
*member_name
= zval_get_string(member
);
887 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
889 if ((handler
= php_http_message_object_get_prophandler(member_name
))) {
890 handler
->write(obj
, value
);
892 zend_get_std_object_handlers()->write_property(object
, member
, value
, cache_slot
);
895 zend_string_release(member_name
);
898 static HashTable
*php_http_message_object_get_props(zval
*object
)
901 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, object
);
902 HashTable
*props
= zend_get_std_object_handlers()->get_properties(object
);
903 char *ver_str
, *url_str
= NULL
;
904 size_t ver_len
, url_len
= 0;
906 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
908 #define UPDATE_PROP(name_str, action_with_tmp) \
910 zend_property_info *pi; \
911 if ((pi = zend_hash_str_find_ptr(&obj->zo.ce->properties_info, name_str, lenof(name_str)))) { \
913 zend_hash_update(props, pi->name, &tmp); \
917 UPDATE_PROP("type", ZVAL_LONG(&tmp
, obj
->message
->type
));
919 ver_len
= spprintf(&ver_str
, 0, "%u.%u", obj
->message
->http
.version
.major
, obj
->message
->http
.version
.minor
);
920 UPDATE_PROP("httpVersion", ZVAL_STR(&tmp
, php_http_cs2zs(ver_str
, ver_len
)));
922 switch (obj
->message
->type
) {
923 case PHP_HTTP_REQUEST
:
924 UPDATE_PROP("responseCode", ZVAL_LONG(&tmp
, 0));
925 UPDATE_PROP("responseStatus", ZVAL_EMPTY_STRING(&tmp
));
926 UPDATE_PROP("requestMethod", ZVAL_STRING(&tmp
, STR_PTR(obj
->message
->http
.info
.request
.method
)));
927 if (obj
->message
->http
.info
.request
.url
) {
928 php_http_url_to_string(obj
->message
->http
.info
.request
.url
, &url_str
, &url_len
, 0);
929 UPDATE_PROP("requestUrl", ZVAL_STR(&tmp
, php_http_cs2zs(url_str
, url_len
)));
931 UPDATE_PROP("requestUrl", ZVAL_EMPTY_STRING(&tmp
));
936 case PHP_HTTP_RESPONSE
:
937 UPDATE_PROP("responseCode", ZVAL_LONG(&tmp
, obj
->message
->http
.info
.response
.code
));
938 UPDATE_PROP("responseStatus", ZVAL_STRING(&tmp
, STR_PTR(obj
->message
->http
.info
.response
.status
)));
939 UPDATE_PROP("requestMethod", ZVAL_EMPTY_STRING(&tmp
));
940 UPDATE_PROP("requestUrl", ZVAL_EMPTY_STRING(&tmp
));
945 UPDATE_PROP("responseCode", ZVAL_LONG(&tmp
, 0));
946 UPDATE_PROP("responseStatus", ZVAL_EMPTY_STRING(&tmp
));
947 UPDATE_PROP("requestMethod", ZVAL_EMPTY_STRING(&tmp
));
948 UPDATE_PROP("requestUrl", ZVAL_EMPTY_STRING(&tmp
));
952 UPDATE_PROP("headers",
954 array_copy(&obj
->message
->hdrs
, Z_ARRVAL(tmp
));
959 ZVAL_OBJECT(&tmp
, &obj
->body
->zo
, 1);
965 UPDATE_PROP("parentMessage",
966 if (obj
->message
->parent
) {
967 ZVAL_OBJECT(&tmp
, &obj
->parent
->zo
, 1);
976 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage___construct
, 0, 0, 0)
977 ZEND_ARG_INFO(0, message
)
978 ZEND_ARG_INFO(0, greedy
)
980 static PHP_METHOD(HttpMessage
, __construct
)
982 zend_bool greedy
= 1;
983 zval
*zmessage
= NULL
;
984 php_http_message_t
*msg
= NULL
;
985 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
986 zend_error_handling zeh
;
988 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "|z!b", &zmessage
, &greedy
), invalid_arg
, return);
990 zend_replace_error_handling(EH_THROW
, php_http_exception_bad_message_class_entry
, &zeh
);
991 if (zmessage
&& Z_TYPE_P(zmessage
) == IS_RESOURCE
) {
993 php_http_message_parser_t p
;
994 zend_error_handling zeh
;
996 zend_replace_error_handling(EH_THROW
, php_http_exception_unexpected_val_class_entry
, &zeh
);
997 php_stream_from_zval(s
, zmessage
);
998 zend_restore_error_handling(&zeh
);
1000 if (s
&& php_http_message_parser_init(&p
)) {
1001 unsigned flags
= (greedy
? PHP_HTTP_MESSAGE_PARSER_GREEDY
: 0);
1002 php_http_buffer_t buf
;
1004 php_http_buffer_init_ex(&buf
, 0x1000, PHP_HTTP_BUFFER_INIT_PREALLOC
);
1005 if (PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE
== php_http_message_parser_parse_stream(&p
, &buf
, s
, flags
, &msg
)) {
1006 if (!EG(exception
)) {
1007 php_http_throw(bad_message
, "Could not parse message from stream", NULL
);
1010 php_http_buffer_dtor(&buf
);
1011 php_http_message_parser_dtor(&p
);
1014 if (!msg
&& !EG(exception
)) {
1015 php_http_throw(bad_message
, "Empty message received from stream", NULL
);
1017 } else if (zmessage
) {
1018 zend_string
*zs_msg
= zval_get_string(zmessage
);
1020 msg
= php_http_message_parse(NULL
, zs_msg
->val
, zs_msg
->len
, greedy
);
1022 if (!msg
&& !EG(exception
)) {
1023 php_http_throw(bad_message
, "Could not parse message: %.*s", MIN(25, zs_msg
->len
), zs_msg
->val
);
1025 zend_string_release(zs_msg
);
1029 php_http_message_dtor(obj
->message
);
1031 if (obj
->message
->parent
) {
1032 obj
->parent
= php_http_message_object_new_ex(obj
->zo
.ce
, obj
->message
->parent
);
1035 zend_restore_error_handling(&zeh
);
1036 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1039 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getBody
, 0, 0, 0)
1040 ZEND_END_ARG_INFO();
1041 static PHP_METHOD(HttpMessage
, getBody
)
1043 php_http_message_object_t
*obj
;
1045 php_http_expect(SUCCESS
== zend_parse_parameters_none(), invalid_arg
, return);
1047 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1048 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1051 php_http_message_object_init_body_object(obj
);
1055 RETVAL_OBJECT(&obj
->body
->zo
, 1);
1059 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setBody
, 0, 0, 1)
1060 ZEND_ARG_OBJ_INFO(0, body
, http
\\Message
\\Body
, 0)
1061 ZEND_END_ARG_INFO();
1062 static PHP_METHOD(HttpMessage
, setBody
)
1066 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zbody
, php_http_message_body_class_entry
)) {
1067 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1069 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1070 php_http_message_object_prophandler_set_body(obj
, zbody
);
1072 RETVAL_ZVAL_FAST(getThis());
1075 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_addBody
, 0, 0, 1)
1076 ZEND_ARG_OBJ_INFO(0, body
, http
\\Message
\\Body
, 0)
1077 ZEND_END_ARG_INFO();
1078 static PHP_METHOD(HttpMessage
, addBody
)
1082 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "O", &new_body
, php_http_message_body_class_entry
)) {
1083 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1084 php_http_message_body_object_t
*new_obj
= PHP_HTTP_OBJ(NULL
, new_body
);
1086 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1087 php_http_message_body_to_callback(new_obj
->body
, (php_http_pass_callback_t
) php_http_message_body_append
, obj
->message
->body
, 0, 0);
1089 RETVAL_ZVAL_FAST(getThis());
1092 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getHeader
, 0, 0, 1)
1093 ZEND_ARG_INFO(0, header
)
1094 ZEND_ARG_INFO(0, into_class
)
1095 ZEND_END_ARG_INFO();
1096 static PHP_METHOD(HttpMessage
, getHeader
)
1100 zend_class_entry
*header_ce
= NULL
;
1102 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "s|C!", &header_str
, &header_len
, &header_ce
)) {
1103 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1106 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1108 if ((header
= php_http_message_header(obj
->message
, header_str
, header_len
))) {
1110 RETURN_ZVAL(header
, 1, 1);
1111 } else if (instanceof_function(header_ce
, php_http_header_class_entry
)) {
1114 ZVAL_STRINGL(&argv
[0], header_str
, header_len
);
1115 ZVAL_COPY(&argv
[1], header
);
1117 object_init_ex(return_value
, header_ce
);
1118 php_http_method_call(return_value
, ZEND_STRL("__construct"), 2, argv
, NULL
);
1120 zval_ptr_dtor(&argv
[0]);
1121 zval_ptr_dtor(&argv
[1]);
1125 php_error_docref(NULL
, E_WARNING
, "Class '%s' is not as descendant of http\\Header", header_ce
->name
->val
);
1132 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getHeaders
, 0, 0, 0)
1133 ZEND_END_ARG_INFO();
1134 static PHP_METHOD(HttpMessage
, getHeaders
)
1136 if (SUCCESS
== zend_parse_parameters_none()) {
1137 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1139 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1141 array_init(return_value
);
1142 array_copy(&obj
->message
->hdrs
, Z_ARRVAL_P(return_value
));
1146 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setHeader
, 0, 0, 1)
1147 ZEND_ARG_INFO(0, header
)
1148 ZEND_ARG_INFO(0, value
)
1149 ZEND_END_ARG_INFO();
1150 static PHP_METHOD(HttpMessage
, setHeader
)
1152 zval
*zvalue
= NULL
;
1156 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "s|z!", &name_str
, &name_len
, &zvalue
)) {
1157 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1158 char *name
= php_http_pretty_key(estrndup(name_str
, name_len
), name_len
, 1, 1);
1160 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1163 zend_symtable_str_del(&obj
->message
->hdrs
, name
, name_len
);
1165 Z_TRY_ADDREF_P(zvalue
);
1166 zend_symtable_str_update(&obj
->message
->hdrs
, name
, name_len
, zvalue
);
1170 RETVAL_ZVAL_FAST(getThis());
1173 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setHeaders
, 0, 0, 1)
1174 ZEND_ARG_ARRAY_INFO(0, headers
, 1)
1175 ZEND_END_ARG_INFO();
1176 static PHP_METHOD(HttpMessage
, setHeaders
)
1178 zval
*new_headers
= NULL
;
1180 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "a/!", &new_headers
)) {
1181 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1183 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1185 zend_hash_clean(&obj
->message
->hdrs
);
1187 array_join(Z_ARRVAL_P(new_headers
), &obj
->message
->hdrs
, 0, ARRAY_JOIN_PRETTIFY
|ARRAY_JOIN_STRONLY
);
1190 RETVAL_ZVAL_FAST(getThis());
1193 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_addHeader
, 0, 0, 2)
1194 ZEND_ARG_INFO(0, header
)
1195 ZEND_ARG_INFO(0, value
)
1196 ZEND_END_ARG_INFO();
1197 static PHP_METHOD(HttpMessage
, addHeader
)
1203 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &name_str
, &name_len
, &zvalue
)) {
1204 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1205 char *name
= php_http_pretty_key(estrndup(name_str
, name_len
), name_len
, 1, 1);
1208 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1210 Z_TRY_ADDREF_P(zvalue
);
1211 if ((header
= php_http_message_header(obj
->message
, name
, name_len
))) {
1212 convert_to_array(header
);
1213 zend_hash_next_index_insert(Z_ARRVAL_P(header
), zvalue
);
1215 zend_symtable_str_update(&obj
->message
->hdrs
, name
, name_len
, zvalue
);
1219 RETVAL_ZVAL_FAST(getThis());
1222 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_addHeaders
, 0, 0, 1)
1223 ZEND_ARG_ARRAY_INFO(0, headers
, 0)
1224 ZEND_ARG_INFO(0, append
)
1225 ZEND_END_ARG_INFO();
1226 static PHP_METHOD(HttpMessage
, addHeaders
)
1229 zend_bool append
= 0;
1231 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "a|b", &new_headers
, &append
)) {
1232 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1234 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1236 array_join(Z_ARRVAL_P(new_headers
), &obj
->message
->hdrs
, append
, ARRAY_JOIN_STRONLY
|ARRAY_JOIN_PRETTIFY
);
1238 RETVAL_ZVAL_FAST(getThis());
1241 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getType
, 0, 0, 0)
1242 ZEND_END_ARG_INFO();
1243 static PHP_METHOD(HttpMessage
, getType
)
1245 if (SUCCESS
== zend_parse_parameters_none()) {
1246 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1248 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1250 RETURN_LONG(obj
->message
->type
);
1254 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setType
, 0, 0, 1)
1255 ZEND_ARG_INFO(0, type
)
1256 ZEND_END_ARG_INFO();
1257 static PHP_METHOD(HttpMessage
, setType
)
1261 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "l", &type
)) {
1262 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1264 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1266 php_http_message_set_type(obj
->message
, type
);
1268 RETVAL_ZVAL_FAST(getThis());
1271 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getInfo
, 0, 0, 0)
1272 ZEND_END_ARG_INFO();
1273 static PHP_METHOD(HttpMessage
, getInfo
)
1275 if (SUCCESS
== zend_parse_parameters_none()) {
1276 char *str
, *tmp
= NULL
;
1278 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1280 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1282 switch (obj
->message
->type
) {
1283 case PHP_HTTP_REQUEST
:
1284 len
= spprintf(&str
, 0, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&obj
->message
->http
, tmp
, ""));
1287 case PHP_HTTP_RESPONSE
:
1288 len
= spprintf(&str
, 0, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&obj
->message
->http
, tmp
, ""));
1296 RETVAL_STR(php_http_cs2zs(str
, len
));
1300 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setInfo
, 0, 0, 1)
1301 ZEND_ARG_INFO(0, http_info
)
1302 ZEND_END_ARG_INFO();
1303 static PHP_METHOD(HttpMessage
, setInfo
)
1307 php_http_message_object_t
*obj
;
1308 php_http_info_t inf
;
1310 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str
, &len
), invalid_arg
, return);
1312 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1313 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1315 if (!php_http_info_parse(&inf
, str
)) {
1316 php_http_throw(bad_header
, "Could not parse message info '%s'", str
);
1320 php_http_message_set_info(obj
->message
, &inf
);
1321 php_http_info_dtor(&inf
);
1323 RETVAL_ZVAL_FAST(getThis());
1326 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getHttpVersion
, 0, 0, 0)
1327 ZEND_END_ARG_INFO();
1328 static PHP_METHOD(HttpMessage
, getHttpVersion
)
1330 if (SUCCESS
== zend_parse_parameters_none()) {
1333 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1335 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1337 php_http_version_to_string(&obj
->message
->http
.version
, &str
, &len
, NULL
, NULL
);
1338 RETURN_STR(php_http_cs2zs(str
, len
));
1342 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setHttpVersion
, 0, 0, 1)
1343 ZEND_ARG_INFO(0, http_version
)
1344 ZEND_END_ARG_INFO();
1345 static PHP_METHOD(HttpMessage
, setHttpVersion
)
1349 php_http_version_t version
;
1350 php_http_message_object_t
*obj
;
1352 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "s", &v_str
, &v_len
), invalid_arg
, return);
1354 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1355 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1357 php_http_expect(php_http_version_parse(&version
, v_str
), unexpected_val
, return);
1359 obj
->message
->http
.version
= version
;
1361 RETVAL_ZVAL_FAST(getThis());
1364 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getResponseCode
, 0, 0, 0)
1365 ZEND_END_ARG_INFO();
1366 static PHP_METHOD(HttpMessage
, getResponseCode
)
1368 if (SUCCESS
== zend_parse_parameters_none()) {
1369 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1371 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1373 if (obj
->message
->type
!= PHP_HTTP_RESPONSE
) {
1374 php_error_docref(NULL
, E_WARNING
, "http\\Message is not if type response");
1378 RETURN_LONG(obj
->message
->http
.info
.response
.code
);
1382 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setResponseCode
, 0, 0, 1)
1383 ZEND_ARG_INFO(0, response_code
)
1384 ZEND_ARG_INFO(0, strict
)
1385 ZEND_END_ARG_INFO();
1386 static PHP_METHOD(HttpMessage
, setResponseCode
)
1389 zend_bool strict
= 1;
1390 php_http_message_object_t
*obj
;
1392 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l|b", &code
, &strict
), invalid_arg
, return);
1394 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1395 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1397 if (obj
->message
->type
!= PHP_HTTP_RESPONSE
) {
1398 php_http_throw(bad_method_call
, "http\\Message is not of type response", NULL
);
1402 if (strict
&& (code
< 100 || code
> 599)) {
1403 php_http_throw(invalid_arg
, "Invalid response code (100-599): %ld", code
);
1407 obj
->message
->http
.info
.response
.code
= code
;
1408 PTR_SET(obj
->message
->http
.info
.response
.status
, estrdup(php_http_env_get_response_status_for_code(code
)));
1410 RETVAL_ZVAL_FAST(getThis());
1413 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getResponseStatus
, 0, 0, 0)
1414 ZEND_END_ARG_INFO();
1415 static PHP_METHOD(HttpMessage
, getResponseStatus
)
1417 if (SUCCESS
== zend_parse_parameters_none()) {
1418 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1420 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1422 if (obj
->message
->type
!= PHP_HTTP_RESPONSE
) {
1423 php_error_docref(NULL
, E_WARNING
, "http\\Message is not of type response");
1426 if (obj
->message
->http
.info
.response
.status
) {
1427 RETURN_STRING(obj
->message
->http
.info
.response
.status
);
1429 RETURN_EMPTY_STRING();
1434 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setResponseStatus
, 0, 0, 1)
1435 ZEND_ARG_INFO(0, response_status
)
1436 ZEND_END_ARG_INFO();
1437 static PHP_METHOD(HttpMessage
, setResponseStatus
)
1441 php_http_message_object_t
*obj
;
1443 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &status
, &status_len
), invalid_arg
, return);
1445 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1447 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1449 if (obj
->message
->type
!= PHP_HTTP_RESPONSE
) {
1450 php_http_throw(bad_method_call
, "http\\Message is not of type response", NULL
);
1453 PTR_SET(obj
->message
->http
.info
.response
.status
, estrndup(status
, status_len
));
1454 RETVAL_ZVAL_FAST(getThis());
1457 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getRequestMethod
, 0, 0, 0)
1458 ZEND_END_ARG_INFO();
1459 static PHP_METHOD(HttpMessage
, getRequestMethod
)
1461 if (SUCCESS
== zend_parse_parameters_none()) {
1462 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1464 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1466 if (obj
->message
->type
!= PHP_HTTP_REQUEST
) {
1467 php_error_docref(NULL
, E_WARNING
, "http\\Message is not of type request");
1471 if (obj
->message
->http
.info
.request
.method
) {
1472 RETURN_STRING(obj
->message
->http
.info
.request
.method
);
1474 RETURN_EMPTY_STRING();
1479 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setRequestMethod
, 0, 0, 1)
1480 ZEND_ARG_INFO(0, request_method
)
1481 ZEND_END_ARG_INFO();
1482 static PHP_METHOD(HttpMessage
, setRequestMethod
)
1486 php_http_message_object_t
*obj
;
1488 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "s", &method
, &method_len
), invalid_arg
, return);
1490 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1492 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1494 if (obj
->message
->type
!= PHP_HTTP_REQUEST
) {
1495 php_http_throw(bad_method_call
, "http\\Message is not of type request", NULL
);
1499 if (method_len
< 1) {
1500 php_http_throw(invalid_arg
, "Cannot set http\\Message's request method to an empty string", NULL
);
1504 PTR_SET(obj
->message
->http
.info
.request
.method
, estrndup(method
, method_len
));
1505 RETVAL_ZVAL_FAST(getThis());
1508 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getRequestUrl
, 0, 0, 0)
1509 ZEND_END_ARG_INFO();
1510 static PHP_METHOD(HttpMessage
, getRequestUrl
)
1512 if (SUCCESS
== zend_parse_parameters_none()) {
1513 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1515 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1517 if (obj
->message
->type
!= PHP_HTTP_REQUEST
) {
1518 php_error_docref(NULL
, E_WARNING
, "http\\Message is not of type request");
1522 if (obj
->message
->http
.info
.request
.url
) {
1526 php_http_url_to_string(obj
->message
->http
.info
.request
.url
, &url_str
, &url_len
, 0);
1527 RETURN_STR(php_http_cs2zs(url_str
, url_len
));
1529 RETURN_EMPTY_STRING();
1534 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setRequestUrl
, 0, 0, 1)
1535 ZEND_ARG_INFO(0, url
)
1536 ZEND_END_ARG_INFO();
1537 static PHP_METHOD(HttpMessage
, setRequestUrl
)
1540 php_http_url_t
*url
;
1541 php_http_message_object_t
*obj
;
1542 zend_error_handling zeh
;
1544 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zurl
), invalid_arg
, return);
1546 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1548 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1550 if (obj
->message
->type
!= PHP_HTTP_REQUEST
) {
1551 php_http_throw(bad_method_call
, "http\\Message is not of type request", NULL
);
1555 zend_replace_error_handling(EH_THROW
, php_http_exception_bad_url_class_entry
, &zeh
);
1556 url
= php_http_url_from_zval(zurl
, ~0);
1557 zend_restore_error_handling(&zeh
);
1559 if (php_http_url_is_empty(url
)) {
1560 php_http_url_free(&url
);
1561 php_http_throw(invalid_arg
, "Cannot set http\\Message's request url to an empty string", NULL
);
1563 PTR_SET(obj
->message
->http
.info
.request
.url
, url
);
1566 RETVAL_ZVAL_FAST(getThis());
1569 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getParentMessage
, 0, 0, 0)
1570 ZEND_END_ARG_INFO();
1571 static PHP_METHOD(HttpMessage
, getParentMessage
)
1573 php_http_message_object_t
*obj
;
1575 php_http_expect(SUCCESS
== zend_parse_parameters_none(), invalid_arg
, return);
1577 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1578 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1580 if (!obj
->message
->parent
) {
1581 php_http_throw(unexpected_val
, "http\\Message has not parent message", NULL
);
1585 RETVAL_OBJECT(&obj
->parent
->zo
, 1);
1588 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage___toString
, 0, 0, 0)
1589 ZEND_END_ARG_INFO();
1590 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toString
, 0, 0, 0)
1591 ZEND_ARG_INFO(0, include_parent
)
1592 ZEND_END_ARG_INFO();
1593 static PHP_METHOD(HttpMessage
, toString
)
1595 zend_bool include_parent
= 0;
1597 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &include_parent
)) {
1598 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1602 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1604 if (include_parent
) {
1605 php_http_message_serialize(obj
->message
, &string
, &length
);
1607 php_http_message_to_string(obj
->message
, &string
, &length
);
1610 RETURN_STR(php_http_cs2zs(string
, length
));
1613 RETURN_EMPTY_STRING();
1616 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toStream
, 0, 0, 1)
1617 ZEND_ARG_INFO(0, stream
)
1618 ZEND_END_ARG_INFO();
1619 static PHP_METHOD(HttpMessage
, toStream
)
1623 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zstream
)) {
1624 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1627 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1629 php_stream_from_zval(s
, zstream
);
1630 php_http_message_to_callback(obj
->message
, (php_http_pass_callback_t
) _php_stream_write
, s
);
1634 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toCallback
, 0, 0, 1)
1635 ZEND_ARG_INFO(0, callback
)
1636 ZEND_END_ARG_INFO();
1637 static PHP_METHOD(HttpMessage
, toCallback
)
1639 php_http_pass_fcall_arg_t fcd
;
1641 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "f", &fcd
.fci
, &fcd
.fcc
)) {
1642 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1644 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1646 ZVAL_COPY(&fcd
.fcz
, getThis());
1647 php_http_message_to_callback(obj
->message
, php_http_pass_fcall_callback
, &fcd
);
1648 zend_fcall_info_args_clear(&fcd
.fci
, 1);
1649 zval_ptr_dtor(&fcd
.fcz
);
1651 RETURN_ZVAL_FAST(getThis());
1655 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_serialize
, 0, 0, 0)
1656 ZEND_END_ARG_INFO();
1657 static PHP_METHOD(HttpMessage
, serialize
)
1659 if (SUCCESS
== zend_parse_parameters_none()) {
1660 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1664 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1666 php_http_message_serialize(obj
->message
, &string
, &length
);
1667 RETURN_STR(php_http_cs2zs(string
, length
));
1669 RETURN_EMPTY_STRING();
1672 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_unserialize
, 0, 0, 1)
1673 ZEND_ARG_INFO(0, serialized
)
1674 ZEND_END_ARG_INFO();
1675 static PHP_METHOD(HttpMessage
, unserialize
)
1680 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized
, &length
)) {
1681 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1682 php_http_message_t
*msg
;
1685 /* do not free recursively */
1686 php_http_message_dtor(obj
->message
);
1687 efree(obj
->message
);
1689 if ((msg
= php_http_message_parse(NULL
, serialized
, length
, 1))) {
1692 obj
->message
= php_http_message_init(NULL
, 0, NULL
);
1693 php_error_docref(NULL TSRMLS_CC
, E_ERROR
, "Could not unserialize http\\Message");
1698 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_detach
, 0, 0, 0)
1699 ZEND_END_ARG_INFO();
1700 static PHP_METHOD(HttpMessage
, detach
)
1702 php_http_message_object_t
*obj
, *new_obj
;
1703 php_http_message_t
*msg_cpy
;
1705 php_http_expect(SUCCESS
== zend_parse_parameters_none(), invalid_arg
, return);
1707 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1708 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1710 msg_cpy
= php_http_message_copy_ex(obj
->message
, NULL
, 0);
1711 new_obj
= php_http_message_object_new_ex(obj
->zo
.ce
, msg_cpy
);
1713 RETVAL_OBJ(&new_obj
->zo
);
1716 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_prepend
, 0, 0, 1)
1717 ZEND_ARG_OBJ_INFO(0, message
, http
\\Message
, 0)
1718 ZEND_ARG_INFO(0, top
)
1719 ZEND_END_ARG_INFO();
1720 static PHP_METHOD(HttpMessage
, prepend
)
1724 php_http_message_t
*msg
[2];
1725 php_http_message_object_t
*obj
, *prepend_obj
;
1727 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "O|b", &prepend
, php_http_message_class_entry
, &top
), invalid_arg
, return);
1729 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1730 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1731 prepend_obj
= PHP_HTTP_OBJ(NULL
, prepend
);
1732 PHP_HTTP_MESSAGE_OBJECT_INIT(prepend_obj
);
1735 for (msg
[0] = obj
->message
; msg
[0]; msg
[0] = msg
[0]->parent
) {
1736 for (msg
[1] = prepend_obj
->message
; msg
[1]; msg
[1] = msg
[1]->parent
) {
1737 if (msg
[0] == msg
[1]) {
1738 php_http_throw(unexpected_val
, "Cannot prepend a message located within the same message chain", NULL
);
1744 php_http_message_object_prepend(getThis(), prepend
, top
);
1745 RETURN_ZVAL_FAST(getThis());
1748 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_reverse
, 0, 0, 0)
1749 ZEND_END_ARG_INFO();
1750 static PHP_METHOD(HttpMessage
, reverse
)
1752 php_http_expect(SUCCESS
== zend_parse_parameters_none(), invalid_arg
, return);
1754 php_http_message_object_reverse(getThis(), return_value
);
1757 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_isMultipart
, 0, 0, 0)
1758 ZEND_ARG_INFO(1, boundary
)
1759 ZEND_END_ARG_INFO();
1760 static PHP_METHOD(HttpMessage
, isMultipart
)
1762 zval
*zboundary
= NULL
;
1764 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "|z!", &zboundary
)) {
1765 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1766 char *boundary
= NULL
;
1768 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1770 if (php_http_message_is_multipart(obj
->message
, zboundary
? &boundary
: NULL
)) {
1776 if (zboundary
&& boundary
) {
1777 ZVAL_DEREF(zboundary
);
1778 zval_dtor(zboundary
);
1779 ZVAL_STR(zboundary
, php_http_cs2zs(boundary
, strlen(boundary
)));
1784 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_splitMultipartBody
, 0, 0, 0)
1785 ZEND_END_ARG_INFO();
1786 static PHP_METHOD(HttpMessage
, splitMultipartBody
)
1788 php_http_message_object_t
*obj
;
1789 php_http_message_t
*msg
;
1790 char *boundary
= NULL
;
1792 php_http_expect(SUCCESS
== zend_parse_parameters_none(), invalid_arg
, return);
1794 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1795 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1797 if (!php_http_message_is_multipart(obj
->message
, &boundary
)) {
1798 php_http_throw(bad_method_call
, "http\\Message is not a multipart message", NULL
);
1802 php_http_expect(msg
= php_http_message_body_split(obj
->message
->body
, boundary
), bad_message
, return);
1806 RETURN_OBJ(&php_http_message_object_new_ex(obj
->zo
.ce
, msg
)->zo
);
1809 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_count
, 0, 0, 0)
1810 ZEND_END_ARG_INFO();
1811 static PHP_METHOD(HttpMessage
, count
)
1813 zend_long count_mode
= -1;
1815 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|l", &count_mode
)) {
1816 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1818 PHP_HTTP_MESSAGE_OBJECT_INIT(obj
);
1820 RETURN_LONG(php_http_message_count(obj
->message
));
1824 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_rewind
, 0, 0, 0)
1825 ZEND_END_ARG_INFO();
1826 static PHP_METHOD(HttpMessage
, rewind
)
1828 if (SUCCESS
== zend_parse_parameters_none()) {
1829 zval
*zobj
= getThis();
1830 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1832 if (!Z_ISUNDEF(obj
->iterator
)) {
1833 zval_ptr_dtor(&obj
->iterator
);
1835 ZVAL_COPY(&obj
->iterator
, zobj
);
1839 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_valid
, 0, 0, 0)
1840 ZEND_END_ARG_INFO();
1841 static PHP_METHOD(HttpMessage
, valid
)
1843 if (SUCCESS
== zend_parse_parameters_none()) {
1844 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1846 RETURN_BOOL(!Z_ISUNDEF(obj
->iterator
));
1850 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_next
, 0, 0, 0)
1851 ZEND_END_ARG_INFO();
1852 static PHP_METHOD(HttpMessage
, next
)
1854 if (SUCCESS
== zend_parse_parameters_none()) {
1855 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1857 if (!Z_ISUNDEF(obj
->iterator
)) {
1858 php_http_message_object_t
*itr
= PHP_HTTP_OBJ(NULL
, &obj
->iterator
);
1863 ZVAL_OBJECT(&tmp
, &itr
->parent
->zo
, 1);
1864 zval_ptr_dtor(&obj
->iterator
);
1865 obj
->iterator
= tmp
;
1867 zval_ptr_dtor(&obj
->iterator
);
1868 ZVAL_UNDEF(&obj
->iterator
);
1874 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_key
, 0, 0, 0)
1875 ZEND_END_ARG_INFO();
1876 static PHP_METHOD(HttpMessage
, key
)
1878 if (SUCCESS
== zend_parse_parameters_none()) {
1879 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1881 RETURN_LONG(Z_ISUNDEF(obj
->iterator
) ? 0 : Z_OBJ_HANDLE(obj
->iterator
));
1885 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_current
, 0, 0, 0)
1886 ZEND_END_ARG_INFO();
1887 static PHP_METHOD(HttpMessage
, current
)
1889 if (SUCCESS
== zend_parse_parameters_none()) {
1890 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1892 if (!Z_ISUNDEF(obj
->iterator
)) {
1893 RETURN_ZVAL_FAST(&obj
->iterator
);
1898 static zend_function_entry php_http_message_methods
[] = {
1899 PHP_ME(HttpMessage
, __construct
, ai_HttpMessage___construct
, ZEND_ACC_PUBLIC
|ZEND_ACC_CTOR
)
1900 PHP_ME(HttpMessage
, getBody
, ai_HttpMessage_getBody
, ZEND_ACC_PUBLIC
)
1901 PHP_ME(HttpMessage
, setBody
, ai_HttpMessage_setBody
, ZEND_ACC_PUBLIC
)
1902 PHP_ME(HttpMessage
, addBody
, ai_HttpMessage_addBody
, ZEND_ACC_PUBLIC
)
1903 PHP_ME(HttpMessage
, getHeader
, ai_HttpMessage_getHeader
, ZEND_ACC_PUBLIC
)
1904 PHP_ME(HttpMessage
, setHeader
, ai_HttpMessage_setHeader
, ZEND_ACC_PUBLIC
)
1905 PHP_ME(HttpMessage
, addHeader
, ai_HttpMessage_addHeader
, ZEND_ACC_PUBLIC
)
1906 PHP_ME(HttpMessage
, getHeaders
, ai_HttpMessage_getHeaders
, ZEND_ACC_PUBLIC
)
1907 PHP_ME(HttpMessage
, setHeaders
, ai_HttpMessage_setHeaders
, ZEND_ACC_PUBLIC
)
1908 PHP_ME(HttpMessage
, addHeaders
, ai_HttpMessage_addHeaders
, ZEND_ACC_PUBLIC
)
1909 PHP_ME(HttpMessage
, getType
, ai_HttpMessage_getType
, ZEND_ACC_PUBLIC
)
1910 PHP_ME(HttpMessage
, setType
, ai_HttpMessage_setType
, ZEND_ACC_PUBLIC
)
1911 PHP_ME(HttpMessage
, getInfo
, ai_HttpMessage_getInfo
, ZEND_ACC_PUBLIC
)
1912 PHP_ME(HttpMessage
, setInfo
, ai_HttpMessage_setInfo
, ZEND_ACC_PUBLIC
)
1913 PHP_ME(HttpMessage
, getResponseCode
, ai_HttpMessage_getResponseCode
, ZEND_ACC_PUBLIC
)
1914 PHP_ME(HttpMessage
, setResponseCode
, ai_HttpMessage_setResponseCode
, ZEND_ACC_PUBLIC
)
1915 PHP_ME(HttpMessage
, getResponseStatus
, ai_HttpMessage_getResponseStatus
, ZEND_ACC_PUBLIC
)
1916 PHP_ME(HttpMessage
, setResponseStatus
, ai_HttpMessage_setResponseStatus
, ZEND_ACC_PUBLIC
)
1917 PHP_ME(HttpMessage
, getRequestMethod
, ai_HttpMessage_getRequestMethod
, ZEND_ACC_PUBLIC
)
1918 PHP_ME(HttpMessage
, setRequestMethod
, ai_HttpMessage_setRequestMethod
, ZEND_ACC_PUBLIC
)
1919 PHP_ME(HttpMessage
, getRequestUrl
, ai_HttpMessage_getRequestUrl
, ZEND_ACC_PUBLIC
)
1920 PHP_ME(HttpMessage
, setRequestUrl
, ai_HttpMessage_setRequestUrl
, ZEND_ACC_PUBLIC
)
1921 PHP_ME(HttpMessage
, getHttpVersion
, ai_HttpMessage_getHttpVersion
, ZEND_ACC_PUBLIC
)
1922 PHP_ME(HttpMessage
, setHttpVersion
, ai_HttpMessage_setHttpVersion
, ZEND_ACC_PUBLIC
)
1923 PHP_ME(HttpMessage
, getParentMessage
, ai_HttpMessage_getParentMessage
, ZEND_ACC_PUBLIC
)
1924 PHP_ME(HttpMessage
, toString
, ai_HttpMessage_toString
, ZEND_ACC_PUBLIC
)
1925 PHP_ME(HttpMessage
, toCallback
, ai_HttpMessage_toCallback
, ZEND_ACC_PUBLIC
)
1926 PHP_ME(HttpMessage
, toStream
, ai_HttpMessage_toStream
, ZEND_ACC_PUBLIC
)
1928 /* implements Countable */
1929 PHP_ME(HttpMessage
, count
, ai_HttpMessage_count
, ZEND_ACC_PUBLIC
)
1931 /* implements Serializable */
1932 PHP_ME(HttpMessage
, serialize
, ai_HttpMessage_serialize
, ZEND_ACC_PUBLIC
)
1933 PHP_ME(HttpMessage
, unserialize
, ai_HttpMessage_unserialize
, ZEND_ACC_PUBLIC
)
1935 /* implements Iterator */
1936 PHP_ME(HttpMessage
, rewind
, ai_HttpMessage_rewind
, ZEND_ACC_PUBLIC
)
1937 PHP_ME(HttpMessage
, valid
, ai_HttpMessage_valid
, ZEND_ACC_PUBLIC
)
1938 PHP_ME(HttpMessage
, current
, ai_HttpMessage_current
, ZEND_ACC_PUBLIC
)
1939 PHP_ME(HttpMessage
, key
, ai_HttpMessage_key
, ZEND_ACC_PUBLIC
)
1940 PHP_ME(HttpMessage
, next
, ai_HttpMessage_next
, ZEND_ACC_PUBLIC
)
1942 ZEND_MALIAS(HttpMessage
, __toString
, toString
, ai_HttpMessage___toString
, ZEND_ACC_PUBLIC
)
1944 PHP_ME(HttpMessage
, detach
, ai_HttpMessage_detach
, ZEND_ACC_PUBLIC
)
1945 PHP_ME(HttpMessage
, prepend
, ai_HttpMessage_prepend
, ZEND_ACC_PUBLIC
)
1946 PHP_ME(HttpMessage
, reverse
, ai_HttpMessage_reverse
, ZEND_ACC_PUBLIC
)
1948 PHP_ME(HttpMessage
, isMultipart
, ai_HttpMessage_isMultipart
, ZEND_ACC_PUBLIC
)
1949 PHP_ME(HttpMessage
, splitMultipartBody
, ai_HttpMessage_splitMultipartBody
, ZEND_ACC_PUBLIC
)
1951 EMPTY_FUNCTION_ENTRY
1954 zend_class_entry
*php_http_message_class_entry
;
1956 PHP_MINIT_FUNCTION(http_message
)
1958 zend_class_entry ce
= {0};
1960 INIT_NS_CLASS_ENTRY(ce
, "http", "Message", php_http_message_methods
);
1961 php_http_message_class_entry
= zend_register_internal_class(&ce
);
1962 php_http_message_class_entry
->create_object
= php_http_message_object_new
;
1963 memcpy(&php_http_message_object_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
1964 php_http_message_object_handlers
.offset
= XtOffsetOf(php_http_message_object_t
, zo
);
1965 php_http_message_object_handlers
.clone_obj
= php_http_message_object_clone
;
1966 php_http_message_object_handlers
.free_obj
= php_http_message_object_free
;
1967 php_http_message_object_handlers
.read_property
= php_http_message_object_read_prop
;
1968 php_http_message_object_handlers
.write_property
= php_http_message_object_write_prop
;
1969 php_http_message_object_handlers
.get_properties
= php_http_message_object_get_props
;
1970 php_http_message_object_handlers
.get_property_ptr_ptr
= NULL
;
1972 zend_class_implements(php_http_message_class_entry
, 3, spl_ce_Countable
, zend_ce_serializable
, zend_ce_iterator
);
1974 zend_hash_init(&php_http_message_object_prophandlers
, 9, NULL
, php_http_message_object_prophandler_hash_dtor
, 1);
1975 zend_declare_property_long(php_http_message_class_entry
, ZEND_STRL("type"), PHP_HTTP_NONE
, ZEND_ACC_PROTECTED
);
1976 php_http_message_object_add_prophandler(ZEND_STRL("type"), php_http_message_object_prophandler_get_type
, php_http_message_object_prophandler_set_type
);
1977 zend_declare_property_null(php_http_message_class_entry
, ZEND_STRL("body"), ZEND_ACC_PROTECTED
);
1978 php_http_message_object_add_prophandler(ZEND_STRL("body"), php_http_message_object_prophandler_get_body
, php_http_message_object_prophandler_set_body
);
1979 zend_declare_property_string(php_http_message_class_entry
, ZEND_STRL("requestMethod"), "", ZEND_ACC_PROTECTED
);
1980 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
);
1981 zend_declare_property_string(php_http_message_class_entry
, ZEND_STRL("requestUrl"), "", ZEND_ACC_PROTECTED
);
1982 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
);
1983 zend_declare_property_string(php_http_message_class_entry
, ZEND_STRL("responseStatus"), "", ZEND_ACC_PROTECTED
);
1984 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
);
1985 zend_declare_property_long(php_http_message_class_entry
, ZEND_STRL("responseCode"), 0, ZEND_ACC_PROTECTED
);
1986 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
);
1987 zend_declare_property_null(php_http_message_class_entry
, ZEND_STRL("httpVersion"), ZEND_ACC_PROTECTED
);
1988 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
);
1989 zend_declare_property_null(php_http_message_class_entry
, ZEND_STRL("headers"), ZEND_ACC_PROTECTED
);
1990 php_http_message_object_add_prophandler(ZEND_STRL("headers"), php_http_message_object_prophandler_get_headers
, php_http_message_object_prophandler_set_headers
);
1991 zend_declare_property_null(php_http_message_class_entry
, ZEND_STRL("parentMessage"), ZEND_ACC_PROTECTED
);
1992 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
);
1994 zend_declare_class_constant_long(php_http_message_class_entry
, ZEND_STRL("TYPE_NONE"), PHP_HTTP_NONE
);
1995 zend_declare_class_constant_long(php_http_message_class_entry
, ZEND_STRL("TYPE_REQUEST"), PHP_HTTP_REQUEST
);
1996 zend_declare_class_constant_long(php_http_message_class_entry
, ZEND_STRL("TYPE_RESPONSE"), PHP_HTTP_RESPONSE
);
2001 PHP_MSHUTDOWN_FUNCTION(http_message
)
2003 zend_hash_destroy(&php_http_message_object_prophandlers
);
2013 * vim600: noet sw=4 ts=4 fdm=marker
2014 * vim<600: noet sw=4 ts=4