X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=src%2Fphp_http_header.c;h=76b2f68a374e197cab53b4a4cb0414bbc39e3d7e;hp=4c9a7025684051ade431db1f730cff99083bbd11;hb=refs%2Fheads%2Fmaster;hpb=d5d03014cff8c8ca80ee7866af100d3ceae1bd8f diff --git a/src/php_http_header.c b/src/php_http_header.c index 4c9a702..c475a81 100644 --- a/src/php_http_header.c +++ b/src/php_http_header.c @@ -17,18 +17,18 @@ ZEND_RESULT_CODE php_http_header_parse(const char *header, size_t length, HashTa php_http_header_parser_t ctx; php_http_buffer_t buf; php_http_header_parser_state_t rs; - + if (!php_http_buffer_from_string_ex(&buf, header, length)) { php_error_docref(NULL, E_WARNING, "Could not allocate buffer"); return FAILURE; } - + if (!php_http_header_parser_init(&ctx)) { php_http_buffer_dtor(&buf); php_error_docref(NULL, E_WARNING, "Could not initialize header parser"); return FAILURE; } - + rs = php_http_header_parser_parse(&ctx, &buf, PHP_HTTP_HEADER_PARSER_CLEANUP, headers, callback_func, callback_data); php_http_header_parser_dtor(&ctx); php_http_buffer_dtor(&buf); @@ -183,11 +183,46 @@ PHP_METHOD(HttpHeader, __construct) if (name_str && name_len) { char *pretty_str = estrndup(name_str, name_len); - zend_update_property_stringl(php_http_header_class_entry, getThis(), ZEND_STRL("name"), php_http_pretty_key(pretty_str, name_len, 1, 1), name_len); + zend_update_property_stringl(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("name"), php_http_pretty_key(pretty_str, name_len, 1, 1), name_len); efree(pretty_str); } if (value_str && value_len) { - zend_update_property_stringl(php_http_header_class_entry, getThis(), ZEND_STRL("value"), value_str, value_len); + zend_update_property_stringl(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("value"), value_str, value_len); + } +} + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpHeader___serialize, 0, 0, IS_ARRAY, 0) +ZEND_END_ARG_INFO(); +PHP_METHOD(HttpHeader, __serialize) +{ + zval name, value, *ptr; + + zend_parse_parameters_none(); + + array_init(return_value); + ptr = zend_read_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("name"), 0, &name); + Z_TRY_ADDREF_P(ptr); + add_next_index_zval(return_value, ptr); + ptr = zend_read_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("value"), 0, &value); + Z_TRY_ADDREF_P(ptr); + add_next_index_zval(return_value, ptr); +} + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpHeader___unserialize, 0, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0) +ZEND_END_ARG_INFO(); +PHP_METHOD(HttpHeader, __unserialize) +{ + HashTable *ha; + zval *name, *value; + + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "h", &ha), invalid_arg, return); + name = zend_hash_index_find(ha, 0); + value = zend_hash_index_find(ha, 1); + + if (name && value) { + zend_update_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("name"), name); + zend_update_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("value"), value); } } @@ -201,11 +236,11 @@ PHP_METHOD(HttpHeader, serialize) zval name_tmp, value_tmp; php_http_buffer_init(&buf); - zs = zval_get_string(zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("name"), 0, &name_tmp)); + zs = zval_get_string(zend_read_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("name"), 0, &name_tmp)); php_http_buffer_appendz(&buf, zs); zend_string_release(zs); - zs = zval_get_string(zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0, &value_tmp)); + zs = zval_get_string(zend_read_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("value"), 0, &value_tmp)); if (zs->len) { php_http_buffer_appends(&buf, ": "); php_http_buffer_appendz(&buf, zs); @@ -239,16 +274,16 @@ PHP_METHOD(HttpHeader, unserialize) zend_hash_internal_pointer_reset(&ht); switch (zend_hash_get_current_key(&ht, &key, &idx)) { case HASH_KEY_IS_STRING: - zend_update_property_str(php_http_header_class_entry, getThis(), ZEND_STRL("name"), key); + zend_update_property_str(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("name"), key); break; case HASH_KEY_IS_LONG: - zend_update_property_long(php_http_header_class_entry, getThis(), ZEND_STRL("name"), idx); + zend_update_property_long(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("name"), idx); break; default: break; } zs = zval_get_string(zend_hash_get_current_data(&ht)); - zend_update_property_str(php_http_header_class_entry, getThis(), ZEND_STRL("value"), zs); + zend_update_property_str(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("value"), zs); zend_string_release(zs); } } @@ -273,7 +308,7 @@ PHP_METHOD(HttpHeader, match) return; } - zs = zval_get_string(zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0, &value_tmp)); + zs = zval_get_string(zend_read_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("value"), 0, &value_tmp)); RETVAL_BOOL(php_http_match(zs->val, val_str, flags)); zend_string_release(zs); } @@ -299,7 +334,7 @@ PHP_METHOD(HttpHeader, negotiate) array_init(rs_array); } - zs = zval_get_string(zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("name"), 0, &name_tmp)); + zs = zval_get_string(zend_read_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("name"), 0, &name_tmp)); if (zend_string_equals_literal(zs, "Accept")) { sep_str = "/"; sep_len = 1; @@ -309,7 +344,7 @@ PHP_METHOD(HttpHeader, negotiate) } zend_string_release(zs); - zs = zval_get_string(zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0, &value_tmp)); + zs = zval_get_string(zend_read_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("value"), 0, &value_tmp)); if ((rs = php_http_negotiate(zs->val, zs->len, supported, sep_str, sep_len))) { PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array); } else { @@ -327,21 +362,21 @@ ZEND_END_ARG_INFO(); PHP_METHOD(HttpHeader, getParams) { zval value_tmp, zctor, zparams_obj, *zargs = NULL; - + ZVAL_STRINGL(&zctor, "__construct", lenof("__construct")); - + object_init_ex(&zparams_obj, php_http_params_get_class_entry()); - + zargs = (zval *) ecalloc(ZEND_NUM_ARGS()+1, sizeof(zval)); - ZVAL_COPY_VALUE(&zargs[0], zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0, &value_tmp)); + ZVAL_COPY_VALUE(&zargs[0], zend_read_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("value"), 0, &value_tmp)); if (ZEND_NUM_ARGS()) { zend_get_parameters_array(ZEND_NUM_ARGS(), ZEND_NUM_ARGS(), &zargs[1]); } - + if (SUCCESS == call_user_function(NULL, &zparams_obj, &zctor, return_value, ZEND_NUM_ARGS()+1, zargs)) { RETVAL_ZVAL(&zparams_obj, 0, 1); } - + zval_ptr_dtor(&zctor); if (zargs) { efree(zargs); @@ -381,7 +416,7 @@ PHP_METHOD(HttpHeader, parse) object_init_ex(&zho, ce); Z_TRY_ADDREF_P(val); - zend_call_method_with_2_params(&zho, ce, NULL, "__construct", NULL, &zkey, val); + zend_call_method_with_2_params(Z_OBJ(zho), ce, NULL, "__construct", NULL, &zkey, val); zval_ptr_dtor(val); zval_ptr_dtor(&zkey); @@ -397,12 +432,17 @@ PHP_METHOD(HttpHeader, parse) } } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpHeader___toString, 0, 0, IS_STRING, 0) +ZEND_END_ARG_INFO(); + static zend_function_entry php_http_header_methods[] = { PHP_ME(HttpHeader, __construct, ai_HttpHeader___construct, ZEND_ACC_PUBLIC) + PHP_ME(HttpHeader, __unserialize, ai_HttpHeader___unserialize, ZEND_ACC_PUBLIC) + PHP_ME(HttpHeader, __serialize, ai_HttpHeader___serialize, ZEND_ACC_PUBLIC) + PHP_ME(HttpHeader, unserialize, ai_HttpHeader_unserialize, ZEND_ACC_PUBLIC) PHP_ME(HttpHeader, serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC) - ZEND_MALIAS(HttpHeader, __toString, serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC) ZEND_MALIAS(HttpHeader, toString, serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC) - PHP_ME(HttpHeader, unserialize, ai_HttpHeader_unserialize, ZEND_ACC_PUBLIC) + ZEND_MALIAS(HttpHeader, __toString, serialize, ai_HttpHeader___toString, ZEND_ACC_PUBLIC) PHP_ME(HttpHeader, match, ai_HttpHeader_match, ZEND_ACC_PUBLIC) PHP_ME(HttpHeader, negotiate, ai_HttpHeader_negotiate, ZEND_ACC_PUBLIC) PHP_ME(HttpHeader, getParams, ai_HttpHeader_getParams, ZEND_ACC_PUBLIC) @@ -436,4 +476,3 @@ PHP_MINIT_FUNCTION(http_header) * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ -