X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_message_object.c;h=18d3793dea0d90a55216af845a9eefdff253f168;hp=8cf6969a885bf9003f610353baa1b764df852a60;hb=76d019d55561c397209d49f7d594f2cfe022cdf9;hpb=19cad54672b6babfac2b7c9c64c415c9a24b888a diff --git a/http_message_object.c b/http_message_object.c index 8cf6969..18d3793 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -30,6 +30,9 @@ #include "php_http_exception_object.h" #include "phpstr/phpstr.h" +#include "missing.h" + +ZEND_EXTERN_MODULE_GLOBALS(http); #define HTTP_BEGIN_ARGS(method, ret_ref, req_args) HTTP_BEGIN_ARGS_EX(HttpMessage, method, ret_ref, req_args) #define HTTP_EMPTY_ARGS(method, ret_ref) HTTP_EMPTY_ARGS_EX(HttpMessage, method, ret_ref) @@ -165,7 +168,7 @@ zend_object_value _http_message_object_new_ex(zend_class_entry *ce, http_message ALLOC_HASHTABLE(OBJ_PROP(o)); zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0); - ov.handle = zend_objects_store_put(o, (zend_objects_store_dtor_t) zend_objects_destroy_object, http_message_object_free, NULL TSRMLS_CC); + ov.handle = putObject(http_message_object, o); ov.handlers = &http_message_object_handlers; return ov; @@ -180,6 +183,10 @@ static inline void _http_message_object_declare_default_properties(TSRMLS_D) { zend_class_entry *ce = http_message_object_ce; + DCL_CONST(long, "NONE", HTTP_MSG_NONE); + DCL_CONST(long, "REQUEST", HTTP_MSG_REQUEST); + DCL_CONST(long, "RESPONSE", HTTP_MSG_RESPONSE); + DCL_PROP(PROTECTED, long, type, HTTP_MSG_NONE); DCL_PROP(PROTECTED, string, body, ""); DCL_PROP(PROTECTED, string, requestMethod, ""); @@ -225,7 +232,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(E_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); + zend_error(HE_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); return EG(uninitialized_zval_ptr); } @@ -325,14 +332,14 @@ 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(E_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); + zend_error(HE_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)) { case HTTP_MSG_PROPHASH_TYPE: convert_to_long_ex(&value); - if (Z_LVAL_P(value) != msg->type) { + if ((http_message_type) Z_LVAL_P(value) != msg->type) { if (HTTP_MSG_TYPE(REQUEST, msg)) { if (msg->info.request.method) { efree(msg->info.request.method); @@ -648,7 +655,7 @@ PHP_METHOD(HttpMessage, getResponseCode) getObject(http_message_object, obj); if (!HTTP_MSG_TYPE(RESPONSE, obj->message)) { - http_error(E_NOTICE, HTTP_E_MSG, "HttpMessage is not of type HTTP_MSG_RESPONSE"); + http_error(HE_NOTICE, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_RESPONSE"); RETURN_NULL(); } @@ -669,7 +676,7 @@ PHP_METHOD(HttpMessage, setResponseCode) getObject(http_message_object, obj); if (!HTTP_MSG_TYPE(RESPONSE, obj->message)) { - http_error(E_WARNING, HTTP_E_MSG, "HttpMessage is not of type HTTP_MSG_RESPONSE"); + http_error(HE_WARNING, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_RESPONSE"); RETURN_FALSE; } @@ -677,7 +684,7 @@ PHP_METHOD(HttpMessage, setResponseCode) RETURN_FALSE; } if (code < 100 || code > 510) { - http_error_ex(E_WARNING, HTTP_E_PARAM, "Invalid response code (100-510): %ld", code); + http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid response code (100-510): %ld", code); RETURN_FALSE; } @@ -699,7 +706,7 @@ PHP_METHOD(HttpMessage, getRequestMethod) getObject(http_message_object, obj); if (!HTTP_MSG_TYPE(REQUEST, obj->message)) { - http_error(E_NOTICE, HTTP_E_MSG, "HttpMessage is not of type HTTP_MSG_REQUEST"); + http_error(HE_NOTICE, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_REQUEST"); RETURN_NULL(); } @@ -720,7 +727,7 @@ PHP_METHOD(HttpMessage, setRequestMethod) getObject(http_message_object, obj); if (!HTTP_MSG_TYPE(REQUEST, obj->message)) { - http_error(E_WARNING, HTTP_E_MSG, "HttpMessage is not of type HTTP_MSG_REQUEST"); + http_error(HE_WARNING, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_REQUEST"); RETURN_FALSE; } @@ -728,11 +735,11 @@ PHP_METHOD(HttpMessage, setRequestMethod) RETURN_FALSE; } if (method_len < 1) { - http_error(E_WARNING, HTTP_E_PARAM, "Cannot set HttpMessage::requestMethod to an empty string"); + http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Cannot set HttpMessage::requestMethod to an empty string"); RETURN_FALSE; } if (SUCCESS != http_check_method(method)) { - http_error_ex(E_WARNING, HTTP_E_PARAM, "Unkown request method: %s", method); + http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Unkown request method: %s", method); RETURN_FALSE; } @@ -753,7 +760,7 @@ PHP_METHOD(HttpMessage, getRequestUri) getObject(http_message_object, obj); if (!HTTP_MSG_TYPE(REQUEST, obj->message)) { - http_error(E_WARNING, HTTP_E_MSG, "HttpMessage is not of type HTTP_MSG_REQUEST"); + http_error(HE_WARNING, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_REQUEST"); RETURN_NULL(); } @@ -775,14 +782,14 @@ PHP_METHOD(HttpMessage, setRequestUri) getObject(http_message_object, obj); if (!HTTP_MSG_TYPE(REQUEST, obj->message)) { - http_error(E_WARNING, HTTP_E_MSG, "HttpMessage is not of type HTTP_MSG_REQUEST"); + http_error(HE_WARNING, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_REQUEST"); RETURN_FALSE; } if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &URI, &URIlen)) { RETURN_FALSE; } if (URIlen < 1) { - http_error(E_WARNING, HTTP_E_PARAM, "Cannot set HttpMessage::requestUri to an empty string"); + http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Cannot set HttpMessage::requestUri to an empty string"); RETURN_FALSE; } @@ -840,14 +847,14 @@ PHP_METHOD(HttpMessage, setHttpVersion) } if (HTTP_MSG_TYPE(NONE, obj->message)) { - http_error(E_WARNING, HTTP_E_MSG, "Message is neither of type HTTP_MSG_RESPONSE nor HTTP_MSG_REQUEST"); + http_error(HE_WARNING, HTTP_E_MESSAGE_TYPE, "Message is neither of type HTTP_MSG_RESPONSE nor HTTP_MSG_REQUEST"); RETURN_FALSE; } convert_to_double(zv); sprintf(v, "%1.1lf", Z_DVAL_P(zv)); if (strcmp(v, "1.0") && strcmp(v, "1.1")) { - http_error_ex(E_WARNING, HTTP_E_PARAM, "Invalid HTTP protocol version (1.0 or 1.1): %s", v); + http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid HTTP protocol version (1.0 or 1.1): %s", v); RETURN_FALSE; }