X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=php_http_env.c;h=f8485f57875a72eab436ac3c15718de70d65f332;hb=a5bf469d59f8b88f00a8497599fd6388165af735;hp=511b878efbe134543e7791ea13c616c0d74447d5;hpb=4d708279b6956fc95b253ddc88671fb2f0e5aa39;p=m6w6%2Fext-http diff --git a/php_http_env.c b/php_http_env.c index 511b878..f8485f5 100644 --- a/php_http_env.c +++ b/php_http_env.c @@ -6,12 +6,10 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2010, Michael Wallner | + | Copyright (c) 2004-2011, Michael Wallner | +--------------------------------------------------------------------+ */ -/* $Id $ */ - #include "php_http.h" #include
@@ -62,7 +60,7 @@ PHP_HTTP_API void php_http_env_get_request_headers(HashTable *headers TSRMLS_DC) zend_hash_get_current_data_ex(Z_ARRVAL_PP(hsv), (void *) &header, &pos); Z_ADDREF_P(*header); - zend_hash_add(PHP_HTTP_G->env.request.headers, key.str, key.len, (void *) header, sizeof(zval *), NULL); + zend_symtable_update(PHP_HTTP_G->env.request.headers, key.str, key.len, (void *) header, sizeof(zval *), NULL); efree(key.str); } @@ -75,17 +73,20 @@ PHP_HTTP_API void php_http_env_get_request_headers(HashTable *headers TSRMLS_DC) } } -PHP_HTTP_API char *php_http_env_get_request_header(const char *name_str, size_t name_len TSRMLS_DC) +PHP_HTTP_API char *php_http_env_get_request_header(const char *name_str, size_t name_len, size_t *len TSRMLS_DC) { zval **zvalue; char *val = NULL, *key = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1); php_http_env_get_request_headers(NULL TSRMLS_CC); - if (SUCCESS == zend_hash_find(PHP_HTTP_G->env.request.headers, key, name_len + 1, (void *) &zvalue)) { + if (SUCCESS == zend_symtable_find(PHP_HTTP_G->env.request.headers, key, name_len + 1, (void *) &zvalue)) { zval *zcopy = php_http_ztyp(IS_STRING, *zvalue); val = estrndup(Z_STRVAL_P(zcopy), Z_STRLEN_P(zcopy)); + if (len) { + *len = Z_STRLEN_P(zcopy); + } zval_ptr_dtor(&zcopy); } @@ -100,7 +101,7 @@ PHP_HTTP_API int php_http_env_got_request_header(const char *name_str, size_t na int got; php_http_env_get_request_headers(NULL TSRMLS_CC); - got = zend_hash_exists(PHP_HTTP_G->env.request.headers, key, name_len + 1); + got = zend_symtable_exists(PHP_HTTP_G->env.request.headers, key, name_len + 1); efree(key); return got; @@ -129,7 +130,7 @@ PHP_HTTP_API zval *php_http_env_get_server_var(const char *key, size_t key_len, if ((SUCCESS != zend_hash_find(&EG(symbol_table), ZEND_STRS("_SERVER"), (void *) &hsv)) || (Z_TYPE_PP(hsv) != IS_ARRAY)) { return NULL; } - if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(hsv), key, key_len + 1, (void *) &var))) { + if ((SUCCESS != zend_symtable_find(Z_ARRVAL_PP(hsv), key, key_len + 1, (void *) &var))) { return NULL; } if (check && !((Z_TYPE_PP(var) == IS_STRING) && Z_STRVAL_PP(var) && Z_STRLEN_PP(var))) { @@ -183,7 +184,7 @@ PHP_HTTP_API php_http_range_status_t php_http_env_get_request_ranges(HashTable * char *range, *rp, c; long begin = -1, end = -1, *ptr; - if (!(range = php_http_env_get_request_header(ZEND_STRL("Range") TSRMLS_CC))) { + if (!(range = php_http_env_get_request_header(ZEND_STRL("Range"), NULL TSRMLS_CC))) { return PHP_HTTP_RANGE_NO; } if (strncmp(range, "bytes=", lenof("bytes="))) { @@ -355,7 +356,7 @@ PHP_HTTP_API char *php_http_env_get_response_header(const char *name_str, size_t zval **zvalue; char *key = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1); - if (SUCCESS == zend_hash_find(&headers, key, name_len + 1, (void *) &zvalue)) { + if (SUCCESS == zend_symtable_find(&headers, key, name_len + 1, (void *) &zvalue)) { zval *zcopy = php_http_ztyp(IS_STRING, *zvalue); val = estrndup(Z_STRVAL_P(zcopy), Z_STRLEN_P(zcopy)); @@ -579,6 +580,7 @@ PHP_HTTP_END_ARGS; PHP_HTTP_BEGIN_ARGS(negotiate, 2) PHP_HTTP_ARG_VAL(value, 0) PHP_HTTP_ARG_VAL(supported, 0) + PHP_HTTP_ARG_VAL(primary_type_separator, 0) PHP_HTTP_ARG_VAL(result_array, 1) PHP_HTTP_END_ARGS; @@ -589,10 +591,6 @@ PHP_HTTP_BEGIN_ARGS(persistentHandlesClean, 0) PHP_HTTP_ARG_VAL(ident, 0) PHP_HTTP_END_ARGS; -PHP_HTTP_BEGIN_ARGS(persistentHandlesIdent, 0) - PHP_HTTP_ARG_VAL(name, 0) -PHP_HTTP_END_ARGS; - zend_function_entry php_http_env_method_entry[] = { PHP_HTTP_ENV_ME(getRequestHeader) PHP_HTTP_ENV_ME(getRequestBody) @@ -622,10 +620,11 @@ PHP_METHOD(HttpEnv, getRequestHeader) if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) { if (header_name_str && header_name_len) { - char *header_value = php_http_env_get_request_header(header_name_str, header_name_len TSRMLS_CC); + size_t header_length; + char *header_value = php_http_env_get_request_header(header_name_str, header_name_len, &header_length TSRMLS_CC); if (header_value) { - RETURN_STRING(header_value, 0); + RETURN_STRINGL(header_value, header_length, 0); } RETURN_NULL(); } else { @@ -766,7 +765,7 @@ PHP_METHOD(HttpEnv, setResponseCode) #define PHP_HTTP_DO_NEGOTIATE(type, supported, rs_array) \ { \ HashTable *result; \ - if ((result = php_http_negotiate_ ##type(supported))) { \ + if ((result = php_http_negotiate_ ##type(supported TSRMLS_CC))) { \ PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(result, supported, rs_array); \ } else { \ PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array); \ @@ -785,8 +784,9 @@ PHP_METHOD(HttpEnv, negotiateLanguage) } PHP_HTTP_DO_NEGOTIATE(language, supported, rs_array); + } else { + RETURN_FALSE; } - RETURN_FALSE; } PHP_METHOD(HttpEnv, negotiateCharset) @@ -800,8 +800,9 @@ PHP_METHOD(HttpEnv, negotiateCharset) array_init(rs_array); } PHP_HTTP_DO_NEGOTIATE(charset, supported, rs_array); + } else { + RETURN_FALSE; } - RETURN_FALSE; } PHP_METHOD(HttpEnv, negotiateContentType) @@ -815,18 +816,19 @@ PHP_METHOD(HttpEnv, negotiateContentType) array_init(rs_array); } PHP_HTTP_DO_NEGOTIATE(content_type, supported, rs_array); + } else { + RETURN_FALSE; } - RETURN_FALSE; } PHP_METHOD(HttpEnv, negotiate) { HashTable *supported; zval *rs_array = NULL; - char *value_str; - int value_len; + char *value_str, *sep_str = NULL; + int value_len, sep_len = 0; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sH|z", &value_str, &value_len, &supported, &rs_array)) { + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sH|s!z", &value_str, &value_len, &supported, &sep_str, &sep_len, &rs_array)) { HashTable *rs; if (rs_array) { @@ -834,20 +836,21 @@ PHP_METHOD(HttpEnv, negotiate) array_init(rs_array); } - if ((rs = php_http_negotiate(value_str, supported, php_http_negotiate_default_func))) { + if ((rs = php_http_negotiate(value_str, value_len, supported, sep_str, sep_len TSRMLS_CC))) { PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array); } else { PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array); } + } else { + RETURN_FALSE; } - RETURN_FALSE; } PHP_METHOD(HttpEnv, persistentHandlesStat) { if (SUCCESS == zend_parse_parameters_none()) { object_init(return_value); - if (php_http_persistent_handle_statall(HASH_OF(return_value))) { + if (php_http_persistent_handle_statall(HASH_OF(return_value) TSRMLS_CC)) { return; } zval_dtor(return_value); @@ -897,7 +900,8 @@ PHP_METHOD(HttpEnvRequest, __construct) PHP_MINIT_FUNCTION(http_env) { PHP_HTTP_REGISTER_CLASS(http, Env, http_env, NULL, 0); - PHP_HTTP_REGISTER_CLASS(http\\env, Request, http_env_request, php_http_message_class_entry, 0); + + PHP_HTTP_REGISTER_CLASS(http\\Env, Request, http_env_request, php_http_message_class_entry, 0); return SUCCESS; }