X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_message_object.c;h=cd64d31a4f0bd87f788b5087736f56a6f559ef10;hp=3161b01f0652e8eae925f60a295b0173cf6ebb72;hb=bb1f32fd5d06b9b9ace6517c177b0fe58c9ff57c;hpb=6321af281c171d1a62e2377cef9d251ba03feafc diff --git a/http_message_object.c b/http_message_object.c index 3161b01..cd64d31 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -47,6 +47,10 @@ HTTP_BEGIN_ARGS(fromString, 1, 1) HTTP_END_ARGS; HTTP_EMPTY_ARGS(getBody, 0); +HTTP_BEGIN_ARGS(setBody, 0, 1) + HTTP_ARG_VAL(body, 0) +HTTP_END_ARGS; + HTTP_EMPTY_ARGS(getHeaders, 0); HTTP_BEGIN_ARGS(setHeaders, 0, 1) HTTP_ARG_VAL(headers, 0) @@ -103,6 +107,7 @@ zend_class_entry *http_message_object_ce; zend_function_entry http_message_object_fe[] = { HTTP_MESSAGE_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) HTTP_MESSAGE_ME(getBody, ZEND_ACC_PUBLIC) + HTTP_MESSAGE_ME(setBody, ZEND_ACC_PUBLIC) HTTP_MESSAGE_ME(getHeaders, ZEND_ACC_PUBLIC) HTTP_MESSAGE_ME(setHeaders, ZEND_ACC_PUBLIC) HTTP_MESSAGE_ME(addHeaders, ZEND_ACC_PUBLIC) @@ -123,7 +128,8 @@ zend_function_entry http_message_object_fe[] = { ZEND_MALIAS(HttpMessage, __toString, toString, HTTP_ARGS(HttpMessage, toString), ZEND_ACC_PUBLIC) HTTP_MESSAGE_ME(fromString, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - {NULL, NULL, NULL} + + EMPTY_FUNCTION_ENTRY }; static zend_object_handlers http_message_object_handlers; @@ -184,9 +190,9 @@ static inline void _http_message_object_declare_default_properties(TSRMLS_D) zend_class_entry *ce = http_message_object_ce; #ifndef WONKY - DCL_CONST(long, "NONE", HTTP_MSG_NONE); - DCL_CONST(long, "REQUEST", HTTP_MSG_REQUEST); - DCL_CONST(long, "RESPONSE", HTTP_MSG_RESPONSE); + DCL_CONST(long, "TYPE_NONE", HTTP_MSG_NONE); + DCL_CONST(long, "TYPE_REQUEST", HTTP_MSG_REQUEST); + DCL_CONST(long, "TYPE_RESPONSE", HTTP_MSG_RESPONSE); #endif DCL_PROP(PROTECTED, long, type, HTTP_MSG_NONE); @@ -234,7 +240,7 @@ static zval *_http_message_object_read_prop(zval *object, zval *member, int type fprintf(stderr, "Read HttpMessage::$%s\n", Z_STRVAL_P(member)); #endif if (!EG(scope) || !instanceof_function(EG(scope), obj->zo.ce TSRMLS_CC)) { - zend_error(HE_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); + zend_error(E_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); return EG(uninitialized_zval_ptr); } @@ -325,7 +331,7 @@ static void _http_message_object_write_prop(zval *object, zval *member, zval *va fprintf(stderr, "Write HttpMessage::$%s\n", Z_STRVAL_P(member)); #endif if (!EG(scope) || !instanceof_function(EG(scope), obj->zo.ce TSRMLS_CC)) { - zend_error(HE_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); + zend_error(E_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); } switch (zend_get_hash_value(Z_STRVAL_P(member), Z_STRLEN_P(member) + 1)) @@ -403,7 +409,7 @@ static HashTable *_http_message_object_get_props(zval *object TSRMLS_DC) zval array; \ char *m_prop_name; \ int m_prop_len; \ - Z_ARRVAL(array) = OBJ_PROP(obj); \ + INIT_ZARR(array, OBJ_PROP(obj)); \ zend_mangle_property_name(&m_prop_name, &m_prop_len, "*", 1, name, lenof(name), 1); \ add_assoc_ ##ptype## _ex(&array, m_prop_name, sizeof(name)+4, val); \ } @@ -413,7 +419,7 @@ static HashTable *_http_message_object_get_props(zval *object TSRMLS_DC) zval array; \ char *m_prop_name; \ int m_prop_len; \ - Z_ARRVAL(array) = OBJ_PROP(obj); \ + INIT_ZARR(array, OBJ_PROP(obj)); \ zend_mangle_property_name(&m_prop_name, &m_prop_len, "*", 1, name, lenof(name), 1); \ add_assoc_stringl_ex(&array, m_prop_name, sizeof(name)+4, val, len, 1); \ } @@ -521,6 +527,24 @@ PHP_METHOD(HttpMessage, getBody) } /* }}} */ +/* {{{ proto void HttpMessage::setBody(string body) + * + * Set the body of the HttpMessage. + * NOTE: Don't forget to update any headers accordingly. + */ +PHP_METHOD(HttpMessage, setBody) +{ + char *body; + int len; + getObject(http_message_object, obj); + + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &body, &len)) { + phpstr_dtor(PHPSTR(obj->message)); + phpstr_from_string_ex(PHPSTR(obj->message), body, len); + } +} +/* }}} */ + /* {{{ proto array HttpMessage::getHeaders() * * Get Message Headers. @@ -533,7 +557,7 @@ PHP_METHOD(HttpMessage, getHeaders) zval headers; getObject(http_message_object, obj); - Z_ARRVAL(headers) = &obj->message->hdrs; + INIT_ZARR(headers, &obj->message->hdrs); array_init(return_value); array_copy(&headers, return_value); } @@ -554,7 +578,7 @@ PHP_METHOD(HttpMessage, setHeaders) } zend_hash_clean(&obj->message->hdrs); - Z_ARRVAL(old_headers) = &obj->message->hdrs; + INIT_ZARR(old_headers, &obj->message->hdrs); array_copy(new_headers, &old_headers); } /* }}} */ @@ -573,7 +597,7 @@ PHP_METHOD(HttpMessage, addHeaders) return; } - Z_ARRVAL(old_headers) = &obj->message->hdrs; + INIT_ZARR(old_headers, &obj->message->hdrs); if (append) { array_append(new_headers, &old_headers); } else {