]> granicus.if.org Git - php/commitdiff
- Add a function that returns whether a specific input variable exists or not.
authorDerick Rethans <derick@php.net>
Tue, 4 Oct 2005 13:42:52 +0000 (13:42 +0000)
committerDerick Rethans <derick@php.net>
Tue, 4 Oct 2005 13:42:52 +0000 (13:42 +0000)
ext/filter/filter.c
ext/filter/php_filter.h

index 539070cc91e0de9d6292ea3e9cadf92d6789caf2..9864658b0b514aed593ec4b758c79837d0871b46 100644 (file)
@@ -78,6 +78,7 @@ static unsigned int php_sapi_filter(int arg, char *var, char **val, unsigned int
 function_entry filter_functions[] = {
        PHP_FE(input_get, NULL)
        PHP_FE(input_filters_list, NULL)
+       PHP_FE(input_has_variable, NULL)
        PHP_FE(filter_data, NULL)
        {NULL, NULL, NULL}
 };
@@ -373,6 +374,50 @@ static void php_zval_filter_recursive(zval *value, long filter, long flags, zval
 }
 /* }}} */
 
+#define FIND_SOURCE(a,t)                              \
+               array_ptr = IF_G(a);                          \
+               break;
+
+/* {{{ proto mixed input_has_variable(constant type, string variable_name)
+ */
+PHP_FUNCTION(input_has_variable)
+{
+       long        arg;
+       char       *var;
+       int         var_len;
+    zval      **tmp;
+       zval       *array_ptr = NULL;
+       HashTable  *hash_ptr;
+       int         found = 0;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &arg, &var, &var_len) == FAILURE) {
+               return;
+       }
+
+       switch(arg) {
+               case PARSE_GET:     FIND_SOURCE(get_array,     TRACK_VARS_GET)
+               case PARSE_POST:    FIND_SOURCE(post_array,    TRACK_VARS_POST)
+               case PARSE_COOKIE:  FIND_SOURCE(cookie_array,  TRACK_VARS_COOKIE)
+               case PARSE_SERVER:  FIND_SOURCE(server_array,  TRACK_VARS_SERVER)
+               case PARSE_ENV:     FIND_SOURCE(env_array,     TRACK_VARS_ENV)
+       }
+
+       if (!array_ptr) {
+               RETURN_FALSE;
+       }
+
+       if (!found) {
+               hash_ptr = HASH_OF(array_ptr);
+
+               if (hash_ptr && zend_hash_find(hash_ptr, var, var_len + 1, (void **)&tmp) == SUCCESS) {
+                       RETURN_TRUE;
+               }
+       }
+
+       RETURN_FALSE;
+}
+/* }}} */
+
 /* {{{ proto mixed input_get(constant type, string variable_name [, int filter [, mixed flags [, string charset]]])
  */
 PHP_FUNCTION(input_get)
@@ -409,10 +454,6 @@ PHP_FUNCTION(input_get)
                }
        }
 
-#define FIND_SOURCE(a,t)                              \
-               array_ptr = IF_G(a);                          \
-               break;
-
        switch(arg) {
                case PARSE_GET:     FIND_SOURCE(get_array,     TRACK_VARS_GET)
                case PARSE_POST:    FIND_SOURCE(post_array,    TRACK_VARS_POST)
index 323cf22a7ececc8f370dd3a85ad3a3d9bae1f31d..5572096a9887996cf0e948e19f6388b791b79411 100644 (file)
@@ -50,6 +50,7 @@ PHP_MINFO_FUNCTION(filter);
 
 PHP_FUNCTION(input_get);
 PHP_FUNCTION(input_filters_list);
+PHP_FUNCTION(input_has_variable);
 PHP_FUNCTION(filter_data);
 
 ZEND_BEGIN_MODULE_GLOBALS(filter)