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-2006, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
15 #define HTTP_WANT_SAPI
16 #define HTTP_WANT_CURL
21 #include "zend_interfaces.h"
22 #include "ext/standard/url.h"
24 #include "php_http_api.h"
25 #include "php_http_send_api.h"
26 #include "php_http_url_api.h"
27 #include "php_http_message_api.h"
28 #include "php_http_message_object.h"
29 #include "php_http_exception_object.h"
30 #include "php_http_response_object.h"
31 #include "php_http_request_method_api.h"
32 #include "php_http_request_api.h"
33 #include "php_http_request_object.h"
37 /* SPL doesn't install its headers */
38 extern PHPAPI zend_class_entry
*spl_ce_Countable
;
42 #define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpMessage, method, 0, req_args)
43 #define HTTP_EMPTY_ARGS(method) HTTP_EMPTY_ARGS_EX(HttpMessage, method, 0)
44 #define HTTP_MESSAGE_ME(method, visibility) PHP_ME(HttpMessage, method, HTTP_ARGS(HttpMessage, method), visibility)
46 HTTP_BEGIN_ARGS(__construct
, 0)
47 HTTP_ARG_VAL(message
, 0)
50 HTTP_BEGIN_ARGS(fromString
, 1)
51 HTTP_ARG_VAL(message
, 0)
54 HTTP_EMPTY_ARGS(getBody
);
55 HTTP_BEGIN_ARGS(setBody
, 1)
59 HTTP_EMPTY_ARGS(getHeaders
);
60 HTTP_BEGIN_ARGS(setHeaders
, 1)
61 HTTP_ARG_VAL(headers
, 0)
64 HTTP_BEGIN_ARGS(addHeaders
, 1)
65 HTTP_ARG_VAL(headers
, 0)
66 HTTP_ARG_VAL(append
, 0)
69 HTTP_EMPTY_ARGS(getType
);
70 HTTP_BEGIN_ARGS(setType
, 1)
74 HTTP_EMPTY_ARGS(getResponseCode
);
75 HTTP_BEGIN_ARGS(setResponseCode
, 1)
76 HTTP_ARG_VAL(response_code
, 0)
79 HTTP_EMPTY_ARGS(getResponseStatus
);
80 HTTP_BEGIN_ARGS(setResponseStatus
, 1)
81 HTTP_ARG_VAL(response_status
, 0)
84 HTTP_EMPTY_ARGS(getRequestMethod
);
85 HTTP_BEGIN_ARGS(setRequestMethod
, 1)
86 HTTP_ARG_VAL(request_method
, 0)
89 HTTP_EMPTY_ARGS(getRequestUrl
);
90 HTTP_BEGIN_ARGS(setRequestUrl
, 1)
94 HTTP_EMPTY_ARGS(getHttpVersion
);
95 HTTP_BEGIN_ARGS(setHttpVersion
, 1)
96 HTTP_ARG_VAL(http_version
, 0)
99 HTTP_EMPTY_ARGS(getParentMessage
);
100 HTTP_EMPTY_ARGS(send
);
101 HTTP_BEGIN_ARGS(toString
, 0)
102 HTTP_ARG_VAL(include_parent
, 0)
105 HTTP_EMPTY_ARGS(toMessageTypeObject
);
107 HTTP_EMPTY_ARGS(count
);
109 HTTP_EMPTY_ARGS(serialize
);
110 HTTP_BEGIN_ARGS(unserialize
, 1)
111 HTTP_ARG_VAL(serialized
, 0)
114 HTTP_EMPTY_ARGS(rewind
);
115 HTTP_EMPTY_ARGS(valid
);
116 HTTP_EMPTY_ARGS(key
);
117 HTTP_EMPTY_ARGS(current
);
118 HTTP_EMPTY_ARGS(next
);
120 HTTP_EMPTY_ARGS(detach
);
121 HTTP_BEGIN_ARGS(prepend
, 1)
122 HTTP_ARG_OBJ(HttpMessage
, message
, 0)
124 HTTP_EMPTY_ARGS(reverse
);
126 #define http_message_object_read_prop _http_message_object_read_prop
127 static zval
*_http_message_object_read_prop(zval
*object
, zval
*member
, int type TSRMLS_DC
);
128 #define http_message_object_write_prop _http_message_object_write_prop
129 static void _http_message_object_write_prop(zval
*object
, zval
*member
, zval
*value TSRMLS_DC
);
130 #define http_message_object_get_props _http_message_object_get_props
131 static HashTable
*_http_message_object_get_props(zval
*object TSRMLS_DC
);
133 #define OBJ_PROP_CE http_message_object_ce
134 zend_class_entry
*http_message_object_ce
;
135 zend_function_entry http_message_object_fe
[] = {
136 HTTP_MESSAGE_ME(__construct
, ZEND_ACC_PUBLIC
|ZEND_ACC_CTOR
)
137 HTTP_MESSAGE_ME(getBody
, ZEND_ACC_PUBLIC
)
138 HTTP_MESSAGE_ME(setBody
, ZEND_ACC_PUBLIC
)
139 HTTP_MESSAGE_ME(getHeaders
, ZEND_ACC_PUBLIC
)
140 HTTP_MESSAGE_ME(setHeaders
, ZEND_ACC_PUBLIC
)
141 HTTP_MESSAGE_ME(addHeaders
, ZEND_ACC_PUBLIC
)
142 HTTP_MESSAGE_ME(getType
, ZEND_ACC_PUBLIC
)
143 HTTP_MESSAGE_ME(setType
, ZEND_ACC_PUBLIC
)
144 HTTP_MESSAGE_ME(getResponseCode
, ZEND_ACC_PUBLIC
)
145 HTTP_MESSAGE_ME(setResponseCode
, ZEND_ACC_PUBLIC
)
146 HTTP_MESSAGE_ME(getResponseStatus
, ZEND_ACC_PUBLIC
)
147 HTTP_MESSAGE_ME(setResponseStatus
, ZEND_ACC_PUBLIC
)
148 HTTP_MESSAGE_ME(getRequestMethod
, ZEND_ACC_PUBLIC
)
149 HTTP_MESSAGE_ME(setRequestMethod
, ZEND_ACC_PUBLIC
)
150 HTTP_MESSAGE_ME(getRequestUrl
, ZEND_ACC_PUBLIC
)
151 HTTP_MESSAGE_ME(setRequestUrl
, ZEND_ACC_PUBLIC
)
152 HTTP_MESSAGE_ME(getHttpVersion
, ZEND_ACC_PUBLIC
)
153 HTTP_MESSAGE_ME(setHttpVersion
, ZEND_ACC_PUBLIC
)
154 HTTP_MESSAGE_ME(getParentMessage
, ZEND_ACC_PUBLIC
)
155 HTTP_MESSAGE_ME(send
, ZEND_ACC_PUBLIC
)
156 HTTP_MESSAGE_ME(toString
, ZEND_ACC_PUBLIC
)
157 HTTP_MESSAGE_ME(toMessageTypeObject
, ZEND_ACC_PUBLIC
)
159 /* implements Countable */
160 HTTP_MESSAGE_ME(count
, ZEND_ACC_PUBLIC
)
162 /* implements Serializable */
163 HTTP_MESSAGE_ME(serialize
, ZEND_ACC_PUBLIC
)
164 HTTP_MESSAGE_ME(unserialize
, ZEND_ACC_PUBLIC
)
166 /* implements Iterator */
167 HTTP_MESSAGE_ME(rewind
, ZEND_ACC_PUBLIC
)
168 HTTP_MESSAGE_ME(valid
, ZEND_ACC_PUBLIC
)
169 HTTP_MESSAGE_ME(current
, ZEND_ACC_PUBLIC
)
170 HTTP_MESSAGE_ME(key
, ZEND_ACC_PUBLIC
)
171 HTTP_MESSAGE_ME(next
, ZEND_ACC_PUBLIC
)
173 ZEND_MALIAS(HttpMessage
, __toString
, toString
, HTTP_ARGS(HttpMessage
, toString
), ZEND_ACC_PUBLIC
)
175 HTTP_MESSAGE_ME(fromString
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
177 HTTP_MESSAGE_ME(detach
, ZEND_ACC_PUBLIC
)
178 HTTP_MESSAGE_ME(prepend
, ZEND_ACC_PUBLIC
)
179 HTTP_MESSAGE_ME(reverse
, ZEND_ACC_PUBLIC
)
183 static zend_object_handlers http_message_object_handlers
;
185 PHP_MINIT_FUNCTION(http_message_object
)
187 HTTP_REGISTER_CLASS_EX(HttpMessage
, http_message_object
, NULL
, 0);
191 zend_class_implements(http_message_object_ce TSRMLS_CC
, 3, spl_ce_Countable
, zend_ce_serializable
, zend_ce_iterator
);
193 zend_class_implements(http_message_object_ce TSRMLS_CC
, 2, zend_ce_serializable
, zend_ce_iterator
);
196 zend_class_implements(http_message_object_ce TSRMLS_CC
, 1, zend_ce_iterator
);
199 http_message_object_handlers
.clone_obj
= _http_message_object_clone_obj
;
200 http_message_object_handlers
.read_property
= http_message_object_read_prop
;
201 http_message_object_handlers
.write_property
= http_message_object_write_prop
;
202 http_message_object_handlers
.get_properties
= http_message_object_get_props
;
203 http_message_object_handlers
.get_property_ptr_ptr
= NULL
;
205 DCL_PROP(PROTECTED
, long, type
, HTTP_MSG_NONE
);
206 DCL_PROP(PROTECTED
, string
, body
, "");
207 DCL_PROP(PROTECTED
, string
, requestMethod
, "");
208 DCL_PROP(PROTECTED
, string
, requestUrl
, "");
209 DCL_PROP(PROTECTED
, string
, responseStatus
, "");
210 DCL_PROP(PROTECTED
, long, responseCode
, 0);
211 DCL_PROP_N(PROTECTED
, httpVersion
);
212 DCL_PROP_N(PROTECTED
, headers
);
213 DCL_PROP_N(PROTECTED
, parentMessage
);
216 DCL_CONST(long, "TYPE_NONE", HTTP_MSG_NONE
);
217 DCL_CONST(long, "TYPE_REQUEST", HTTP_MSG_REQUEST
);
218 DCL_CONST(long, "TYPE_RESPONSE", HTTP_MSG_RESPONSE
);
221 HTTP_LONG_CONSTANT("HTTP_MSG_NONE", HTTP_MSG_NONE
);
222 HTTP_LONG_CONSTANT("HTTP_MSG_REQUEST", HTTP_MSG_REQUEST
);
223 HTTP_LONG_CONSTANT("HTTP_MSG_RESPONSE", HTTP_MSG_RESPONSE
);
228 void _http_message_object_reverse(zval
*this_ptr
, zval
*return_value TSRMLS_DC
)
231 getObject(http_message_object
, obj
);
234 http_message_count(i
, obj
->message
);
238 zend_object_value
*ovalues
= NULL
;
239 http_message_object
**objects
= NULL
;
242 objects
= ecalloc(i
, sizeof(http_message_object
*));
243 ovalues
= ecalloc(i
, sizeof(zend_object_value
));
245 /* we are the first message */
247 ovalues
[0] = getThis()->value
.obj
;
252 for (i
= 1; obj
->parent
.handle
; ++i
) {
253 o
.value
.obj
= obj
->parent
;
254 ovalues
[i
] = o
.value
.obj
;
255 objects
[i
] = obj
= zend_object_store_get_object(&o TSRMLS_CC
);
258 /* reorder parents */
259 for (last
= --i
; i
; --i
) {
260 objects
[i
]->message
->parent
= objects
[i
-1]->message
;
261 objects
[i
]->parent
= ovalues
[i
-1];
263 objects
[0]->message
->parent
= NULL
;
264 objects
[0]->parent
.handle
= 0;
265 objects
[0]->parent
.handlers
= NULL
;
268 Z_OBJ_ADDREF_P(getThis());
269 RETVAL_OBJVAL(ovalues
[last
], 1);
274 RETURN_ZVAL(getThis(), 1, 0);
278 void _http_message_object_prepend_ex(zval
*this_ptr
, zval
*prepend
, zend_bool top TSRMLS_DC
)
281 http_message
*save_parent_msg
;
282 zend_object_value save_parent_obj
;
283 getObject(http_message_object
, obj
);
284 getObjectEx(http_message_object
, prepend_obj
, prepend
);
290 save_parent_obj
= obj
->parent
;
291 save_parent_msg
= obj
->message
->parent
;
293 /* iterate to the most parent object */
294 while (obj
->parent
.handle
) {
295 m
.value
.obj
= obj
->parent
;
296 obj
= zend_object_store_get_object(&m TSRMLS_CC
);
301 obj
->parent
= prepend
->value
.obj
;
302 obj
->message
->parent
= prepend_obj
->message
;
305 zend_objects_store_add_ref(prepend TSRMLS_CC
);
306 while (prepend_obj
->parent
.handle
) {
307 m
.value
.obj
= prepend_obj
->parent
;
308 zend_objects_store_add_ref(&m TSRMLS_CC
);
309 prepend_obj
= zend_object_store_get_object(&m TSRMLS_CC
);
313 prepend_obj
->parent
= save_parent_obj
;
314 prepend_obj
->message
->parent
= save_parent_msg
;
318 zend_object_value
_http_message_object_new(zend_class_entry
*ce TSRMLS_DC
)
320 return http_message_object_new_ex(ce
, NULL
, NULL
);
323 zend_object_value
_http_message_object_new_ex(zend_class_entry
*ce
, http_message
*msg
, http_message_object
**ptr TSRMLS_DC
)
325 zend_object_value ov
;
326 http_message_object
*o
;
328 o
= ecalloc(1, sizeof(http_message_object
));
338 o
->parent
= http_message_object_new_ex(ce
, msg
->parent
, NULL
);
342 ALLOC_HASHTABLE(OBJ_PROP(o
));
343 zend_hash_init(OBJ_PROP(o
), 0, NULL
, ZVAL_PTR_DTOR
, 0);
345 ov
.handle
= putObject(http_message_object
, o
);
346 ov
.handlers
= &http_message_object_handlers
;
351 zend_object_value
_http_message_object_clone_obj(zval
*this_ptr TSRMLS_DC
)
353 getObject(http_message_object
, obj
);
354 return http_message_object_new_ex(Z_OBJCE_P(this_ptr
), http_message_dup(obj
->message
), NULL
);
357 void _http_message_object_free(zend_object
*object TSRMLS_DC
)
359 http_message_object
*o
= (http_message_object
*) object
;
362 zend_hash_destroy(OBJ_PROP(o
));
363 FREE_HASHTABLE(OBJ_PROP(o
));
366 http_message_dtor(o
->message
);
369 if (o
->parent
.handle
) {
374 p
.value
.obj
= o
->parent
;
375 zend_objects_store_del_ref(&p TSRMLS_CC
);
380 static zval
*_http_message_object_read_prop(zval
*object
, zval
*member
, int type TSRMLS_DC
)
382 getObjectEx(http_message_object
, obj
, object
);
383 http_message
*msg
= obj
->message
;
386 ulong h
= zend_get_hash_value(Z_STRVAL_P(member
), Z_STRLEN_P(member
)+1);
388 zend_property_info
*pinfo
= zend_get_property_info(obj
->zo
.ce
, member
, 1 TSRMLS_CC
);
390 if (!pinfo
|| ACC_PROP_PUBLIC(pinfo
->flags
)) {
391 return zend_get_std_object_handlers()->read_property(object
, member
, type TSRMLS_CC
);
395 if (type
== BP_VAR_W
) {
396 zend_error(E_ERROR
, "Cannot access HttpMessage properties by reference or array key/index");
400 ALLOC_ZVAL(return_value
);
401 return_value
->refcount
= 0;
402 return_value
->is_ref
= 0;
410 case HTTP_MSG_PROPHASH_TYPE
:
411 case HTTP_MSG_CHILD_PROPHASH_TYPE
:
412 RETVAL_LONG(msg
->type
);
415 case HTTP_MSG_PROPHASH_HTTP_VERSION
:
416 case HTTP_MSG_CHILD_PROPHASH_HTTP_VERSION
:
417 RETVAL_DOUBLE(msg
->http
.version
);
420 case HTTP_MSG_PROPHASH_BODY
:
421 case HTTP_MSG_CHILD_PROPHASH_BODY
:
422 phpstr_fix(PHPSTR(msg
));
423 RETVAL_PHPSTR(PHPSTR(msg
), 0, 1);
426 case HTTP_MSG_PROPHASH_HEADERS
:
427 case HTTP_MSG_CHILD_PROPHASH_HEADERS
:
428 array_init(return_value
);
429 zend_hash_copy(Z_ARRVAL_P(return_value
), &msg
->hdrs
, (copy_ctor_func_t
) zval_add_ref
, NULL
, sizeof(zval
*));
432 case HTTP_MSG_PROPHASH_PARENT_MESSAGE
:
433 case HTTP_MSG_CHILD_PROPHASH_PARENT_MESSAGE
:
435 RETVAL_OBJVAL(obj
->parent
, 1);
441 case HTTP_MSG_PROPHASH_REQUEST_METHOD
:
442 case HTTP_MSG_CHILD_PROPHASH_REQUEST_METHOD
:
443 if (HTTP_MSG_TYPE(REQUEST
, msg
) && msg
->http
.info
.request
.method
) {
444 RETVAL_STRING(msg
->http
.info
.request
.method
, 1);
450 case HTTP_MSG_PROPHASH_REQUEST_URL
:
451 case HTTP_MSG_CHILD_PROPHASH_REQUEST_URL
:
452 if (HTTP_MSG_TYPE(REQUEST
, msg
) && msg
->http
.info
.request
.url
) {
453 RETVAL_STRING(msg
->http
.info
.request
.url
, 1);
459 case HTTP_MSG_PROPHASH_RESPONSE_CODE
:
460 case HTTP_MSG_CHILD_PROPHASH_RESPONSE_CODE
:
461 if (HTTP_MSG_TYPE(RESPONSE
, msg
)) {
462 RETVAL_LONG(msg
->http
.info
.response
.code
);
468 case HTTP_MSG_PROPHASH_RESPONSE_STATUS
:
469 case HTTP_MSG_CHILD_PROPHASH_RESPONSE_STATUS
:
470 if (HTTP_MSG_TYPE(RESPONSE
, msg
) && msg
->http
.info
.response
.status
) {
471 RETVAL_STRING(msg
->http
.info
.response
.status
, 1);
479 return zend_get_std_object_handlers()->read_property(object
, member
, type TSRMLS_CC
);
489 static void _http_message_object_write_prop(zval
*object
, zval
*member
, zval
*value TSRMLS_DC
)
491 getObjectEx(http_message_object
, obj
, object
);
492 http_message
*msg
= obj
->message
;
495 ulong h
= zend_get_hash_value(Z_STRVAL_P(member
), Z_STRLEN_P(member
) + 1);
497 zend_property_info
*pinfo
= zend_get_property_info(obj
->zo
.ce
, member
, 1 TSRMLS_CC
);
499 if (!pinfo
|| ACC_PROP_PUBLIC(pinfo
->flags
)) {
500 zend_get_std_object_handlers()->write_property(object
, member
, value TSRMLS_CC
);
505 cpy
= zval_copy(Z_TYPE_P(value
), value
);
513 case HTTP_MSG_PROPHASH_TYPE
:
514 case HTTP_MSG_CHILD_PROPHASH_TYPE
:
515 convert_to_long(cpy
);
516 http_message_set_type(msg
, Z_LVAL_P(cpy
));
519 case HTTP_MSG_PROPHASH_HTTP_VERSION
:
520 case HTTP_MSG_CHILD_PROPHASH_HTTP_VERSION
:
521 convert_to_double(cpy
);
522 msg
->http
.version
= Z_DVAL_P(cpy
);
525 case HTTP_MSG_PROPHASH_BODY
:
526 case HTTP_MSG_CHILD_PROPHASH_BODY
:
527 convert_to_string(cpy
);
528 phpstr_dtor(PHPSTR(msg
));
529 phpstr_from_string_ex(PHPSTR(msg
), Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
));
532 case HTTP_MSG_PROPHASH_HEADERS
:
533 case HTTP_MSG_CHILD_PROPHASH_HEADERS
:
534 convert_to_array(cpy
);
535 zend_hash_clean(&msg
->hdrs
);
536 zend_hash_copy(&msg
->hdrs
, Z_ARRVAL_P(cpy
), (copy_ctor_func_t
) zval_add_ref
, NULL
, sizeof(zval
*));
539 case HTTP_MSG_PROPHASH_PARENT_MESSAGE
:
540 case HTTP_MSG_CHILD_PROPHASH_PARENT_MESSAGE
:
541 if (Z_TYPE_P(value
) == IS_OBJECT
&& instanceof_function(Z_OBJCE_P(value
), http_message_object_ce TSRMLS_CC
)) {
544 tmp
.value
.obj
= obj
->parent
;
547 Z_OBJ_ADDREF_P(value
);
548 obj
->parent
= value
->value
.obj
;
552 case HTTP_MSG_PROPHASH_REQUEST_METHOD
:
553 case HTTP_MSG_CHILD_PROPHASH_REQUEST_METHOD
:
554 if (HTTP_MSG_TYPE(REQUEST
, msg
)) {
555 convert_to_string(cpy
);
556 STR_SET(msg
->http
.info
.request
.method
, estrndup(Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
)));
560 case HTTP_MSG_PROPHASH_REQUEST_URL
:
561 case HTTP_MSG_CHILD_PROPHASH_REQUEST_URL
:
562 if (HTTP_MSG_TYPE(REQUEST
, msg
)) {
563 convert_to_string(cpy
);
564 STR_SET(msg
->http
.info
.request
.url
, estrndup(Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
)));
568 case HTTP_MSG_PROPHASH_RESPONSE_CODE
:
569 case HTTP_MSG_CHILD_PROPHASH_RESPONSE_CODE
:
570 if (HTTP_MSG_TYPE(RESPONSE
, msg
)) {
571 convert_to_long(cpy
);
572 msg
->http
.info
.response
.code
= Z_LVAL_P(cpy
);
576 case HTTP_MSG_PROPHASH_RESPONSE_STATUS
:
577 case HTTP_MSG_CHILD_PROPHASH_RESPONSE_STATUS
:
578 if (HTTP_MSG_TYPE(RESPONSE
, msg
)) {
579 convert_to_string(cpy
);
580 STR_SET(msg
->http
.info
.response
.status
, estrndup(Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
)));
586 zend_get_std_object_handlers()->write_property(object
, member
, value TSRMLS_CC
);
593 static HashTable
*_http_message_object_get_props(zval
*object TSRMLS_DC
)
596 getObjectEx(http_message_object
, obj
, object
);
597 http_message
*msg
= obj
->message
;
598 HashTable
*props
= OBJ_PROP(obj
);
601 INIT_ZARR(array
, props
);
603 #define ASSOC_PROP(array, ptype, name, val) \
607 zend_mangle_property_name(&m_prop_name, &m_prop_len, "*", 1, name, lenof(name), 0); \
608 add_assoc_ ##ptype## _ex(&array, m_prop_name, sizeof(name)+3, val); \
609 efree(m_prop_name); \
611 #define ASSOC_STRING(array, name, val) ASSOC_STRINGL(array, name, val, strlen(val))
612 #define ASSOC_STRINGL(array, name, val, len) \
616 zend_mangle_property_name(&m_prop_name, &m_prop_len, "*", 1, name, lenof(name), 0); \
617 add_assoc_stringl_ex(&array, m_prop_name, sizeof(name)+3, val, len, 1); \
618 efree(m_prop_name); \
621 ASSOC_PROP(array
, long, "type", msg
->type
);
622 ASSOC_PROP(array
, double, "httpVersion", msg
->http
.version
);
626 case HTTP_MSG_REQUEST
:
627 ASSOC_PROP(array
, long, "responseCode", 0);
628 ASSOC_STRINGL(array
, "responseStatus", "", 0);
629 ASSOC_STRING(array
, "requestMethod", msg
->http
.info
.request
.method
);
630 ASSOC_STRING(array
, "requestUrl", msg
->http
.info
.request
.url
);
633 case HTTP_MSG_RESPONSE
:
634 ASSOC_PROP(array
, long, "responseCode", msg
->http
.info
.response
.code
);
635 ASSOC_STRING(array
, "responseStatus", msg
->http
.info
.response
.status
);
636 ASSOC_STRINGL(array
, "requestMethod", "", 0);
637 ASSOC_STRINGL(array
, "requestUrl", "", 0);
642 ASSOC_PROP(array
, long, "responseCode", 0);
643 ASSOC_STRINGL(array
, "responseStatus", "", 0);
644 ASSOC_STRINGL(array
, "requestMethod", "", 0);
645 ASSOC_STRINGL(array
, "requestUrl", "", 0);
649 MAKE_STD_ZVAL(headers
);
651 zend_hash_copy(Z_ARRVAL_P(headers
), &msg
->hdrs
, (copy_ctor_func_t
) zval_add_ref
, NULL
, sizeof(zval
*));
652 ASSOC_PROP(array
, zval
, "headers", headers
);
653 ASSOC_STRINGL(array
, "body", PHPSTR_VAL(msg
), PHPSTR_LEN(msg
));
655 return OBJ_PROP(obj
);
658 /* ### USERLAND ### */
660 /* {{{ proto void HttpMessage::__construct([string message])
662 * Instantiate a new HttpMessage object.
664 * Accepts an optional string parameter containing a single or several
665 * consecutive HTTP messages. The constructed object will actually
666 * represent the *last* message of the passed string. If there were
667 * prior messages, those can be accessed by HttpMessage::getParentMessage().
669 * Throws HttpMalformedHeaderException.
671 PHP_METHOD(HttpMessage
, __construct
)
674 char *message
= NULL
;
676 getObject(http_message_object
, obj
);
679 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s", &message
, &length
) && message
&& length
) {
680 http_message
*msg
= obj
->message
;
682 http_message_dtor(msg
);
683 if ((obj
->message
= http_message_parse_ex(msg
, message
, length
))) {
684 if (obj
->message
->parent
) {
685 obj
->parent
= http_message_object_new_ex(Z_OBJCE_P(getThis()), obj
->message
->parent
, NULL
);
688 obj
->message
= http_message_init(msg
);
692 obj
->message
= http_message_new();
698 /* {{{ proto static HttpMessage HttpMessage::fromString(string raw_message[, string class_name = "HttpMessage"])
700 * Create an HttpMessage object from a string. Kind of a static constructor.
702 * Expects a string parameter containing a single or several consecutive
703 * HTTP messages. Accepts an optional string parameter specifying the class to use.
705 * Returns an HttpMessage object on success or NULL on failure.
707 * Throws HttpMalformedHeadersException.
709 PHP_METHOD(HttpMessage
, fromString
)
711 char *string
= NULL
, *class_name
= NULL
;
712 int length
= 0, class_length
= 0;
713 http_message
*msg
= NULL
;
718 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|s", &string
, &length
, &class_name
, &class_length
)) {
719 if ((msg
= http_message_parse(string
, length
))) {
720 zend_class_entry
*ce
= http_message_object_ce
;
722 if (class_name
&& *class_name
) {
723 ce
= zend_fetch_class(class_name
, class_length
, ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC
);
724 if (ce
&& !instanceof_function(ce
, http_message_object_ce TSRMLS_CC
)) {
725 http_error_ex(HE_WARNING
, HTTP_E_RUNTIME
, "Class %s does not extend HttpMessage", class_name
);
730 RETVAL_OBJVAL(http_message_object_new_ex(ce
, msg
, NULL
), 0);
738 /* {{{ proto string HttpMessage::getBody()
740 * Get the body of the parsed HttpMessage.
742 * Returns the message body as string.
744 PHP_METHOD(HttpMessage
, getBody
)
749 getObject(http_message_object
, obj
);
750 RETURN_PHPSTR(&obj
->message
->body
, PHPSTR_FREE_NOT
, 1);
755 /* {{{ proto void HttpMessage::setBody(string body)
757 * Set the body of the HttpMessage.
758 * NOTE: Don't forget to update any headers accordingly.
760 * Expects a string parameter containing the new body of the message.
762 PHP_METHOD(HttpMessage
, setBody
)
766 getObject(http_message_object
, obj
);
768 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &body
, &len
)) {
769 phpstr_dtor(PHPSTR(obj
->message
));
770 phpstr_from_string_ex(PHPSTR(obj
->message
), body
, len
);
775 /* {{{ proto array HttpMessage::getHeaders()
777 * Get Message Headers.
779 * Returns an associative array containing the messages HTTP headers.
781 PHP_METHOD(HttpMessage
, getHeaders
)
787 getObject(http_message_object
, obj
);
789 INIT_ZARR(headers
, &obj
->message
->hdrs
);
790 array_init(return_value
);
791 array_copy(&headers
, return_value
);
796 /* {{{ proto void HttpMessage::setHeaders(array headers)
800 * Expects an associative array as parameter containing the new HTTP headers,
801 * which will replace *all* previous HTTP headers of the message.
803 PHP_METHOD(HttpMessage
, setHeaders
)
805 zval
*new_headers
, old_headers
;
806 getObject(http_message_object
, obj
);
808 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a/", &new_headers
)) {
812 zend_hash_clean(&obj
->message
->hdrs
);
813 INIT_ZARR(old_headers
, &obj
->message
->hdrs
);
814 array_copy(new_headers
, &old_headers
);
818 /* {{{ proto void HttpMessage::addHeaders(array headers[, bool append = false])
820 * Add headers. If append is true, headers with the same name will be separated, else overwritten.
822 * Expects an associative array as parameter containing the additional HTTP headers
823 * to add to the messages existing headers. If the optional bool parameter is true,
824 * and a header with the same name of one to add exists already, this respective
825 * header will be converted to an array containing both header values, otherwise
826 * it will be overwritten with the new header value.
828 PHP_METHOD(HttpMessage
, addHeaders
)
830 zval old_headers
, *new_headers
;
831 zend_bool append
= 0;
832 getObject(http_message_object
, obj
);
834 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a|b", &new_headers
, &append
)) {
838 INIT_ZARR(old_headers
, &obj
->message
->hdrs
);
840 array_append(new_headers
, &old_headers
);
842 array_merge(new_headers
, &old_headers
);
847 /* {{{ proto int HttpMessage::getType()
849 * Get Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE)
851 * Returns the HttpMessage::TYPE.
853 PHP_METHOD(HttpMessage
, getType
)
858 getObject(http_message_object
, obj
);
859 RETURN_LONG(obj
->message
->type
);
864 /* {{{ proto void HttpMessage::setType(int type)
866 * Set Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE)
868 * Expects an int parameter, the HttpMessage::TYPE.
870 PHP_METHOD(HttpMessage
, setType
)
873 getObject(http_message_object
, obj
);
875 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &type
)) {
878 http_message_set_type(obj
->message
, type
);
882 /* {{{ proto int HttpMessage::getResponseCode()
884 * Get the Response Code of the Message.
886 * Returns the HTTP response code if the message is of type
887 * HttpMessage::TYPE_RESPONSE, else FALSE.
889 PHP_METHOD(HttpMessage
, getResponseCode
)
894 getObject(http_message_object
, obj
);
895 HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj
->message
, RETURN_FALSE
);
896 RETURN_LONG(obj
->message
->http
.info
.response
.code
);
901 /* {{{ proto bool HttpMessage::setResponseCode(int code)
903 * Set the response code of an HTTP Response Message.
905 * Expects an int parameter with the HTTP response code.
907 * Returns TRUE on success, or FALSE if the message is not of type
908 * HttpMessage::TYPE_RESPONSE or the response code is out of range (100-510).
910 PHP_METHOD(HttpMessage
, setResponseCode
)
913 getObject(http_message_object
, obj
);
915 HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj
->message
, RETURN_FALSE
);
917 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &code
)) {
920 if (code
< 100 || code
> 510) {
921 http_error_ex(HE_WARNING
, HTTP_E_INVALID_PARAM
, "Invalid response code (100-510): %ld", code
);
925 obj
->message
->http
.info
.response
.code
= code
;
930 /* {{{ proto string HttpMessage::getResponseStatus()
932 * Get the Response Status of the message (i.e. the string following the response code).
934 * Returns the HTTP response status string if the message is of type
935 * HttpMessage::TYPE_RESPONSE, else FALSE.
937 PHP_METHOD(HttpMessage
, getResponseStatus
)
942 getObject(http_message_object
, obj
);
943 HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj
->message
, RETURN_FALSE
);
944 RETURN_STRING(obj
->message
->http
.info
.response
.status
, 1);
949 /* {{{ proto bool HttpMessage::setResponseStatus(string status)
951 * Set the Response Status of the HTTP message (i.e. the string following the response code).
953 * Expects a string parameter containing the response status text.
955 * Returns TRUE on success or FALSE if the message is not of type
956 * HttpMessage::TYPE_RESPONSE.
958 PHP_METHOD(HttpMessage
, setResponseStatus
)
962 getObject(http_message_object
, obj
);
964 HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj
->message
, RETURN_FALSE
);
966 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &status
, &status_len
)) {
969 STR_SET(obj
->message
->http
.info
.response
.status
, estrdup(status
));
974 /* {{{ proto string HttpMessage::getRequestMethod()
976 * Get the Request Method of the Message.
978 * Returns the request method name on success, or FALSE if the message is
979 * not of type HttpMessage::TYPE_REQUEST.
981 PHP_METHOD(HttpMessage
, getRequestMethod
)
986 getObject(http_message_object
, obj
);
987 HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj
->message
, RETURN_FALSE
);
988 RETURN_STRING(obj
->message
->http
.info
.request
.method
, 1);
993 /* {{{ proto bool HttpMessage::setRequestMethod(string method)
995 * Set the Request Method of the HTTP Message.
997 * Expects a string parameter containing the request method name.
999 * Returns TRUE on success, or FALSE if the message is not of type
1000 * HttpMessage::TYPE_REQUEST or an invalid request method was supplied.
1002 PHP_METHOD(HttpMessage
, setRequestMethod
)
1006 getObject(http_message_object
, obj
);
1008 HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj
->message
, RETURN_FALSE
);
1010 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &method
, &method_len
)) {
1013 if (method_len
< 1) {
1014 http_error(HE_WARNING
, HTTP_E_INVALID_PARAM
, "Cannot set HttpMessage::requestMethod to an empty string");
1017 if (SUCCESS
!= http_check_method(method
)) {
1018 http_error_ex(HE_WARNING
, HTTP_E_REQUEST_METHOD
, "Unkown request method: %s", method
);
1022 STR_SET(obj
->message
->http
.info
.request
.method
, estrndup(method
, method_len
));
1027 /* {{{ proto string HttpMessage::getRequestUrl()
1029 * Get the Request URL of the Message.
1031 * Returns the request url as string on success, or FALSE if the message
1032 * is not of type HttpMessage::TYPE_REQUEST.
1034 PHP_METHOD(HttpMessage
, getRequestUrl
)
1039 getObject(http_message_object
, obj
);
1040 HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj
->message
, RETURN_FALSE
);
1041 RETURN_STRING(obj
->message
->http
.info
.request
.url
, 1);
1046 /* {{{ proto bool HttpMessage::setRequestUrl(string url)
1048 * Set the Request URL of the HTTP Message.
1050 * Expects a string parameters containing the request url.
1052 * Returns TRUE on success, or FALSE if the message is not of type
1053 * HttpMessage::TYPE_REQUEST or supplied URL was empty.
1055 PHP_METHOD(HttpMessage
, setRequestUrl
)
1059 getObject(http_message_object
, obj
);
1061 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &URI
, &URIlen
)) {
1064 HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj
->message
, RETURN_FALSE
);
1066 http_error(HE_WARNING
, HTTP_E_INVALID_PARAM
, "Cannot set HttpMessage::requestUrl to an empty string");
1070 STR_SET(obj
->message
->http
.info
.request
.url
, estrndup(URI
, URIlen
));
1075 /* {{{ proto string HttpMessage::getHttpVersion()
1077 * Get the HTTP Protocol Version of the Message.
1079 * Returns the HTTP protocol version as string.
1081 PHP_METHOD(HttpMessage
, getHttpVersion
)
1087 getObject(http_message_object
, obj
);
1089 sprintf(ver
, "%1.1lf", obj
->message
->http
.version
);
1090 RETURN_STRINGL(ver
, 3, 1);
1095 /* {{{ proto bool HttpMessage::setHttpVersion(string version)
1097 * Set the HTTP Protocol version of the Message.
1099 * Expects a string parameter containing the HTTP protocol version.
1101 * Returns TRUE on success, or FALSE if supplied version is out of range (1.0/1.1).
1103 PHP_METHOD(HttpMessage
, setHttpVersion
)
1107 getObject(http_message_object
, obj
);
1109 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z/", &zv
)) {
1113 convert_to_double(zv
);
1114 sprintf(v
, "%1.1lf", Z_DVAL_P(zv
));
1115 if (strcmp(v
, "1.0") && strcmp(v
, "1.1")) {
1116 http_error_ex(HE_WARNING
, HTTP_E_INVALID_PARAM
, "Invalid HTTP protocol version (1.0 or 1.1): %s", v
);
1120 obj
->message
->http
.version
= Z_DVAL_P(zv
);
1125 /* {{{ proto HttpMessage HttpMessage::getParentMessage()
1127 * Get parent Message.
1129 * Returns the parent HttpMessage on success, or NULL if there's none.
1131 PHP_METHOD(HttpMessage
, getParentMessage
)
1136 getObject(http_message_object
, obj
);
1138 if (obj
->message
->parent
) {
1139 RETVAL_OBJVAL(obj
->parent
, 1);
1147 /* {{{ proto bool HttpMessage::send()
1149 * Send the Message according to its type as Response or Request.
1150 * This provides limited functionality compared to HttpRequest and HttpResponse.
1152 * Returns TRUE on success, or FALSE on failure.
1154 PHP_METHOD(HttpMessage
, send
)
1156 getObject(http_message_object
, obj
);
1160 RETURN_SUCCESS(http_message_send(obj
->message
));
1164 /* {{{ proto string HttpMessage::toString([bool include_parent = false])
1166 * Get the string representation of the Message.
1168 * Accepts a bool parameter which specifies whether the returned string
1169 * should also contain any parent messages.
1171 * Returns the full message as string.
1173 PHP_METHOD(HttpMessage
, toString
)
1178 zend_bool include_parent
= 0;
1179 getObject(http_message_object
, obj
);
1181 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|b", &include_parent
)) {
1185 if (include_parent
) {
1186 http_message_serialize(obj
->message
, &string
, &length
);
1188 http_message_tostring(obj
->message
, &string
, &length
);
1190 RETURN_STRINGL(string
, length
, 0);
1195 /* {{{ proto HttpRequest|HttpResponse HttpMessage::toMessageTypeObject(void)
1197 * Creates an object regarding to the type of the message.
1199 * Returns either an HttpRequest or HttpResponse object on success, or NULL on failure.
1201 * Throws HttpRuntimeException, HttpMessageTypeException, HttpHeaderException.
1203 PHP_METHOD(HttpMessage
, toMessageTypeObject
)
1205 SET_EH_THROW_HTTP();
1210 getObject(http_message_object
, obj
);
1212 switch (obj
->message
->type
)
1214 case HTTP_MSG_REQUEST
:
1216 #ifdef HTTP_HAVE_CURL
1219 zval tmp
, body
, *array
, *headers
, *host
= http_message_header(obj
->message
, "Host");
1220 php_url hurl
, *purl
= php_url_parse(obj
->message
->http
.info
.request
.url
);
1222 MAKE_STD_ZVAL(array
);
1225 memset(&hurl
, 0, sizeof(php_url
));
1226 hurl
.host
= host
? Z_STRVAL_P(host
) : NULL
;
1227 http_build_url(HTTP_URL_REPLACE
, purl
, &hurl
, NULL
, &url
, NULL
);
1229 add_assoc_string(array
, "url", url
, 0);
1231 if ( (method
= http_request_method_exists(1, 0, obj
->message
->http
.info
.request
.method
)) ||
1232 (method
= http_request_method_register(obj
->message
->http
.info
.request
.method
, strlen(obj
->message
->http
.info
.request
.method
)))) {
1233 add_assoc_long(array
, "method", method
);
1236 if (10 == (int) (obj
->message
->http
.version
* 10)) {
1237 add_assoc_long(array
, "protocol", CURL_HTTP_VERSION_1_0
);
1240 MAKE_STD_ZVAL(headers
);
1241 array_init(headers
);
1242 INIT_ZARR(tmp
, &obj
->message
->hdrs
);
1243 array_copy(&tmp
, headers
);
1244 add_assoc_zval(array
, "headers", headers
);
1246 object_init_ex(return_value
, http_request_object_ce
);
1247 zend_call_method_with_1_params(&return_value
, http_request_object_ce
, NULL
, "setoptions", NULL
, array
);
1248 zval_ptr_dtor(&array
);
1251 ZVAL_STRINGL(&body
, PHPSTR_VAL(obj
->message
), PHPSTR_LEN(obj
->message
), 0);
1252 zend_call_method_with_1_params(&return_value
, http_request_object_ce
, NULL
, "setrawpostdata", NULL
, &body
);
1254 http_error(HE_WARNING
, HTTP_E_RUNTIME
, "Cannot transform HttpMessage to HttpRequest (missing curl support)");
1259 case HTTP_MSG_RESPONSE
:
1262 HashPosition pos1
, pos2
;
1266 zval
**header
, **h
, *body
;
1268 if (obj
->message
->http
.info
.response
.code
) {
1269 http_send_status(obj
->message
->http
.info
.response
.code
);
1272 object_init_ex(return_value
, http_response_object_ce
);
1274 FOREACH_HASH_KEYLENVAL(pos1
, &obj
->message
->hdrs
, key
, key_len
, idx
, header
) {
1279 ZVAL_STRINGL(&zkey
, key
, key_len
, 0);
1281 switch (Z_TYPE_PP(header
))
1285 FOREACH_HASH_VAL(pos2
, HASH_OF(*header
), h
) {
1287 zend_call_method_with_2_params(&return_value
, http_response_object_ce
, NULL
, "setheader", NULL
, &zkey
, *h
);
1293 ZVAL_ADDREF(*header
);
1294 zend_call_method_with_2_params(&return_value
, http_response_object_ce
, NULL
, "setheader", NULL
, &zkey
, *header
);
1295 zval_ptr_dtor(header
);
1302 MAKE_STD_ZVAL(body
);
1303 ZVAL_STRINGL(body
, PHPSTR_VAL(obj
->message
), PHPSTR_LEN(obj
->message
), 1);
1304 zend_call_method_with_1_params(&return_value
, http_response_object_ce
, NULL
, "setdata", NULL
, body
);
1305 zval_ptr_dtor(&body
);
1307 http_error(HE_WARNING
, HTTP_E_RUNTIME
, "Cannot transform HttpMessage to HttpResponse (need PHP 5.1+)");
1313 http_error(HE_WARNING
, HTTP_E_MESSAGE_TYPE
, "HttpMessage is neither of type HttpMessage::TYPE_REQUEST nor HttpMessage::TYPE_RESPONSE");
1321 /* {{{ proto int HttpMessage::count()
1323 * Implements Countable.
1325 * Returns the number of parent messages + 1.
1327 PHP_METHOD(HttpMessage
, count
)
1331 getObject(http_message_object
, obj
);
1333 http_message_count(i
, obj
->message
);
1339 /* {{{ proto string HttpMessage::serialize()
1341 * Implements Serializable.
1343 * Returns the serialized representation of the HttpMessage.
1345 PHP_METHOD(HttpMessage
, serialize
)
1350 getObject(http_message_object
, obj
);
1352 http_message_serialize(obj
->message
, &string
, &length
);
1353 RETURN_STRINGL(string
, length
, 0);
1358 /* {{{ proto void HttpMessage::unserialize(string serialized)
1360 * Implements Serializable.
1362 * Re-constructs the HttpMessage based upon the serialized string.
1364 PHP_METHOD(HttpMessage
, unserialize
)
1368 getObject(http_message_object
, obj
);
1370 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &serialized
, &length
)) {
1371 http_message_dtor(obj
->message
);
1372 if (!http_message_parse_ex(obj
->message
, serialized
, (size_t) length
)) {
1373 http_error(HE_ERROR
, HTTP_E_RUNTIME
, "Could not unserialize HttpMessage");
1374 http_message_init(obj
->message
);
1380 /* {{{ proto HttpMessage HttpMessage::detach(void)
1382 * Returns a clone of an HttpMessage object detached from any parent messages.
1384 PHP_METHOD(HttpMessage
, detach
)
1388 getObject(http_message_object
, obj
);
1392 info
.type
= obj
->message
->type
;
1393 memcpy(&HTTP_INFO(&info
), &HTTP_INFO(obj
->message
), sizeof(struct http_info
));
1395 msg
= http_message_new();
1396 http_message_set_info(msg
, &info
);
1398 zend_hash_copy(&msg
->hdrs
, &obj
->message
->hdrs
, (copy_ctor_func_t
) zval_add_ref
, NULL
, sizeof(zval
*));
1399 phpstr_append(&msg
->body
, PHPSTR_VAL(obj
->message
), PHPSTR_LEN(obj
->message
));
1401 RETVAL_OBJVAL(http_message_object_new_ex(Z_OBJCE_P(getThis()), msg
, NULL
), 0);
1405 /* {{{ proto void HttpMessage::prepend(HttpMessage message)
1407 * Prepends message(s) to the HTTP message.
1409 * Expects an HttpMessage object as parameter.
1411 PHP_METHOD(HttpMessage
, prepend
)
1416 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "O|b", &prepend
, http_message_object_ce
, &top
)) {
1417 http_message_object_prepend_ex(getThis(), prepend
, top
);
1422 /* {{{ proto HttpMessage HttpMessage::reverse()
1424 * Reorders the message chain in reverse order.
1426 * Returns the most parent HttpMessage object.
1428 PHP_METHOD(HttpMessage
, reverse
)
1431 http_message_object_reverse(getThis(), return_value
);
1436 /* {{{ proto void HttpMessage::rewind(void)
1438 * Implements Iterator.
1440 PHP_METHOD(HttpMessage
, rewind
)
1443 getObject(http_message_object
, obj
);
1445 if (obj
->iterator
) {
1446 zval_ptr_dtor(&obj
->iterator
);
1448 ZVAL_ADDREF(getThis());
1449 obj
->iterator
= getThis();
1454 /* {{{ proto bool HttpMessage::valid(void)
1456 * Implements Iterator.
1458 PHP_METHOD(HttpMessage
, valid
)
1461 getObject(http_message_object
, obj
);
1463 RETURN_BOOL(obj
->iterator
!= NULL
);
1468 /* {{{ proto void HttpMessage::next(void)
1470 * Implements Iterator.
1472 PHP_METHOD(HttpMessage
, next
)
1475 getObject(http_message_object
, obj
);
1476 getObjectEx(http_message_object
, itr
, obj
->iterator
);
1478 if (itr
&& itr
->parent
.handle
) {
1479 zval
*old
= obj
->iterator
;
1480 MAKE_STD_ZVAL(obj
->iterator
);
1481 ZVAL_OBJVAL(obj
->iterator
, itr
->parent
, 1);
1482 zval_ptr_dtor(&old
);
1484 zval_ptr_dtor(&obj
->iterator
);
1485 obj
->iterator
= NULL
;
1491 /* {{{ proto int HttpMessage::key(void)
1493 * Implements Iterator.
1495 PHP_METHOD(HttpMessage
, key
)
1498 getObject(http_message_object
, obj
);
1500 RETURN_LONG(obj
->iterator
? obj
->iterator
->value
.obj
.handle
:0);
1505 /* {{{ proto HttpMessage HttpMessage::current(void)
1507 * Implements Iterator.
1509 PHP_METHOD(HttpMessage
, current
)
1512 getObject(http_message_object
, obj
);
1514 if (obj
->iterator
) {
1515 RETURN_ZVAL(obj
->iterator
, 1, 0);
1521 #endif /* ZEND_ENGINE_2 */
1528 * vim600: noet sw=4 ts=4 fdm=marker
1529 * vim<600: noet sw=4 ts=4