-PHP_HTTP_API void php_http_message_to_struct(php_http_message_t *msg, zval *obj)
-{
- zval strct;
- zval *headers;
- char *version;
- TSRMLS_FETCH_FROM_CTX(msg->ts);
-
- INIT_PZVAL_ARRAY(&strct, HASH_OF(obj));
-
- add_assoc_long(&strct, "type", msg->type);
- spprintf(&version, 0 ,"%u.%u", msg->http.version.major, msg->http.version.minor);
- add_assoc_string_ex(&strct, ZEND_STRL("httpVersion"), version, 0);
- switch (msg->type)
- {
- case PHP_HTTP_RESPONSE:
- add_assoc_long(&strct, "responseCode", msg->http.info.response.code);
- add_assoc_string(&strct, "responseStatus", STR_PTR(msg->http.info.response.status), 1);
- break;
-
- case PHP_HTTP_REQUEST:
- add_assoc_string(&strct, "requestMethod", STR_PTR(msg->http.info.request.method), 1);
- add_assoc_string(&strct, "requestUrl", STR_PTR(msg->http.info.request.url), 1);
- break;
-
- case PHP_HTTP_NONE:
- /* avoid compiler warning */
- break;
- }
-
- MAKE_STD_ZVAL(headers);
- array_init(headers);
- zend_hash_copy(Z_ARRVAL_P(headers), &msg->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
- add_assoc_zval(&strct, "headers", headers);
-
- add_assoc_stringl(&strct, "body", PHP_HTTP_BUFFER_VAL(msg), PHP_HTTP_BUFFER_LEN(msg), 1);
-
- if (msg->parent) {
- zval *parent;
-
- MAKE_STD_ZVAL(parent);
- if (Z_TYPE_P(obj) == IS_ARRAY) {
- array_init(parent);
- } else {
- object_init(parent);