separate http_env_request; add getQuer(), getPost(), getFiles()
[m6w6/ext-http] / php_http_params.c
index 4b0e3f4b72cd20cc4cb6e4b99c4789becb875849..49d0538776dcd69a4304c0a6efc8534e754bd748 100644 (file)
@@ -12,9 +12,6 @@
 
 #include "php_http_api.h"
 
-#include <ext/standard/php_string.h>
-#include <zend_interfaces.h>
-
 static php_http_params_token_t def_param_sep = {",", 1}, *def_param_sep_ptr[] = {&def_param_sep, NULL};
 static php_http_params_token_t def_arg_sep = {";", 1}, *def_arg_sep_ptr[] = {&def_arg_sep, NULL};
 static php_http_params_token_t def_val_sep = {"=", 1}, *def_val_sep_ptr[] = {&def_val_sep, NULL};
@@ -59,30 +56,32 @@ static void push_param(HashTable *params, php_http_params_state_t *state, const
 
                        INIT_PZVAL(&key);
                        php_trim(state->arg.str, state->arg.len, NULL, 0, &key, 3 TSRMLS_CC);
-                       MAKE_STD_ZVAL(val);
-                       ZVAL_TRUE(val);
-                       zend_symtable_update(Z_ARRVAL_PP(state->current.args), Z_STRVAL(key), Z_STRLEN(key) + 1, (void *) &val, sizeof(zval *), (void *) &state->current.val);
-
+                       if (Z_STRLEN(key)) {
+                               MAKE_STD_ZVAL(val);
+                               ZVAL_TRUE(val);
+                               zend_symtable_update(Z_ARRVAL_PP(state->current.args), Z_STRVAL(key), Z_STRLEN(key) + 1, (void *) &val, sizeof(zval *), (void *) &state->current.val);
+                       }
                        zval_dtor(&key);
                }
        } else if (state->param.str) {
                if (0 < (state->param.len = state->input.str - state->param.str)) {
                        zval *prm, *arg, *val, key;
 
-                       MAKE_STD_ZVAL(prm);
-                       array_init(prm);
-                       MAKE_STD_ZVAL(val);
-                       ZVAL_TRUE(val);
-                       zend_hash_update(Z_ARRVAL_P(prm), "value", sizeof("value"), (void *) &val, sizeof(zval *), (void *) &state->current.val);
-
-                       MAKE_STD_ZVAL(arg);
-                       array_init(arg);
-                       zend_hash_update(Z_ARRVAL_P(prm), "arguments", sizeof("arguments"), (void *) &arg, sizeof(zval *), (void *) &state->current.args);
-
                        INIT_PZVAL(&key);
                        php_trim(state->param.str, state->param.len, NULL, 0, &key, 3 TSRMLS_CC);
-                       zend_symtable_update(params, Z_STRVAL(key), Z_STRLEN(key) + 1, (void *) &prm, sizeof(zval *), (void *) &state->current.param);
-
+                       if (Z_STRLEN(key)) {
+                               MAKE_STD_ZVAL(prm);
+                               array_init(prm);
+                               MAKE_STD_ZVAL(val);
+                               ZVAL_TRUE(val);
+                               zend_hash_update(Z_ARRVAL_P(prm), "value", sizeof("value"), (void *) &val, sizeof(zval *), (void *) &state->current.val);
+
+                               MAKE_STD_ZVAL(arg);
+                               array_init(arg);
+                               zend_hash_update(Z_ARRVAL_P(prm), "arguments", sizeof("arguments"), (void *) &arg, sizeof(zval *), (void *) &state->current.args);
+
+                               zend_symtable_update(params, Z_STRVAL(key), Z_STRLEN(key) + 1, (void *) &prm, sizeof(zval *), (void *) &state->current.param);
+                       }
                        zval_dtor(&key);
                }
        }
@@ -179,7 +178,9 @@ PHP_HTTP_API HashTable *php_http_params_parse(HashTable *params, const php_http_
 
 PHP_HTTP_BEGIN_ARGS(__construct, 0)
        PHP_HTTP_ARG_VAL(params, 0)
-       PHP_HTTP_ARG_VAL(flags, 0)
+       PHP_HTTP_ARG_VAL(param_sep, 0)
+       PHP_HTTP_ARG_VAL(arg_sep, 0)
+       PHP_HTTP_ARG_VAL(val_sep, 0)
 PHP_HTTP_END_ARGS;
 
 PHP_HTTP_EMPTY_ARGS(toArray);
@@ -287,11 +288,14 @@ PHP_METHOD(HttpParams, __construct)
                if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!/z/z/z/", &zparams, &param_sep, &arg_sep, &val_sep)) {
                        switch (ZEND_NUM_ARGS()) {
                                case 4:
-                                       zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), param_sep TSRMLS_CC);
+                                       zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), val_sep TSRMLS_CC);
+                                       /* no break */
                                case 3:
                                        zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), arg_sep TSRMLS_CC);
+                                       /* no break */
                                case 2:
-                                       zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), val_sep TSRMLS_CC);
+                                       zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), param_sep TSRMLS_CC);
+                                       /* no break */
                        }
 
                        if (zparams) {