X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=php_http_env.c;h=5df1e5bb8edb4ae29d626d8724e2826bcfc8fa79;hb=a2694ec713f44e2a07003e045c6adf76e327aecc;hp=96c757be07463be4fa3a3ec9d4b390e5ea3fed42;hpb=61067d19cf03ad876954c2644ff9e37942b2ad67;p=m6w6%2Fext-http diff --git a/php_http_env.c b/php_http_env.c index 96c757b..5df1e5b 100644 --- a/php_http_env.c +++ b/php_http_env.c @@ -11,11 +11,71 @@ */ #include "php_http_api.h" +#include "php_variables.h" PHP_RINIT_FUNCTION(http_env) { PHP_HTTP_G->env.request.time = sapi_get_request_time(TSRMLS_C); + /* populate form data on non-POST requests */ + if (SG(request_info).request_method && strcasecmp(SG(request_info).request_method, "POST") && SG(request_info).content_type && *SG(request_info).content_type) { + uint ct_len = strlen(SG(request_info).content_type); + char *ct_str = estrndup(SG(request_info).content_type, ct_len); + php_http_params_opts_t opts; + HashTable params; + + php_http_params_opts_default_get(&opts); + opts.input.str = ct_str; + opts.input.len = ct_len; + + SG(request_info).content_type_dup = ct_str; + + ZEND_INIT_SYMTABLE(¶ms); + if (php_http_params_parse(¶ms, &opts TSRMLS_CC)) { + char *key_str; + uint key_len; + ulong key_num; + + if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(¶ms, &key_str, &key_len, &key_num, 0, NULL)) { + sapi_post_entry *post_entry = NULL; + + if (SUCCESS == zend_hash_find(&SG(known_post_content_types), key_str, key_len, (void *) &post_entry)) { + zval *files = PG(http_globals)[TRACK_VARS_FILES]; + + zend_is_auto_global(ZEND_STRL("_POST") TSRMLS_CC); + + if (post_entry) { + SG(request_info).post_entry = post_entry; + + if (post_entry->post_reader) { + post_entry->post_reader(TSRMLS_C); + } + } + + if (sapi_module.default_post_reader) { + sapi_module.default_post_reader(TSRMLS_C); + } + + sapi_handle_post(PG(http_globals)[TRACK_VARS_POST] TSRMLS_CC); + + /* + * the rfc1867 handler is an awkward buddy + */ + if (files != PG(http_globals)[TRACK_VARS_FILES] && PG(http_globals)[TRACK_VARS_FILES]) { + Z_ADDREF_P(PG(http_globals)[TRACK_VARS_FILES]); + zend_hash_update(&EG(symbol_table), "_FILES", sizeof("_FILES"), &PG(http_globals)[TRACK_VARS_FILES], sizeof(zval *), NULL); + if (files) { + zval_ptr_dtor(&files); + } + } + } + } + zend_hash_destroy(¶ms); + } + } + + STR_SET(SG(request_info).content_type_dup, NULL); + return SUCCESS; } @@ -544,7 +604,6 @@ PHP_HTTP_API const char *php_http_env_get_response_status_for_code(unsigned code return php_http_strlist_find(php_http_env_response_status, 100, code); } -zend_class_entry *php_http_env_class_entry; #define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpEnv, method, 0, req_args) #define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpEnv, method, 0) @@ -613,7 +672,14 @@ PHP_HTTP_BEGIN_ARGS(cleanPersistentHandles, 0) PHP_HTTP_ARG_VAL(ident, 0) PHP_HTTP_END_ARGS; -zend_function_entry php_http_env_method_entry[] = { +static zend_class_entry *php_http_env_class_entry; + +zend_class_entry *php_http_env_get_class_entry(void) +{ + return php_http_env_class_entry; +} + +static zend_function_entry php_http_env_method_entry[] = { PHP_HTTP_ENV_ME(getRequestHeader) PHP_HTTP_ENV_ME(getRequestBody) @@ -661,14 +727,14 @@ PHP_METHOD(HttpEnv, getRequestHeader) PHP_METHOD(HttpEnv, getRequestBody) { - with_error_handling(EH_THROW, php_http_exception_class_entry) { - zend_class_entry *class_entry = php_http_message_body_class_entry; + with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + zend_class_entry *class_entry = php_http_message_body_get_class_entry(); if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &class_entry)) { zend_object_value ov; php_http_message_body_t *body = php_http_env_get_request_body(TSRMLS_C); - if (SUCCESS == php_http_new(&ov, class_entry, (php_http_new_t) php_http_message_body_object_new_ex, php_http_message_body_class_entry, php_http_message_body_copy(body, NULL, 0), NULL TSRMLS_CC)) { + if (SUCCESS == php_http_new(&ov, class_entry, (php_http_new_t) php_http_message_body_object_new_ex, php_http_message_body_get_class_entry(), php_http_message_body_copy(body, NULL, 0), NULL TSRMLS_CC)) { RETVAL_OBJVAL(ov, 0); } }