]> granicus.if.org Git - php/commitdiff
@- Updated the browscap module to work with PHP 4.0 (Zeev)
authorZeev Suraski <zeev@php.net>
Wed, 16 Feb 2000 17:46:14 +0000 (17:46 +0000)
committerZeev Suraski <zeev@php.net>
Wed, 16 Feb 2000 17:46:14 +0000 (17:46 +0000)
build/ltlib.mk
ext/standard/browscap.c
main/configuration-parser.y
sapi/apache/mod_php4.c
sapi/apache/php_apache.c
sapi/apache/sapi_apache.c

index 1474621afa64a7389c20efe023cd2476b6e0addb..0354198c745b8cc37607696a159f7f81a87d2985 100644 (file)
@@ -29,3 +29,5 @@ targets = $(LTLIBRARY_NAME)
 include $(topsrcdir)/build/rules.mk
 include $(topsrcdir)/build/library.mk
 
+# CC = insure
+CC = gcc
index f29429e2d4c991c6d49348700bdc5467c744c683..5e5e346ab5651a78607d7bd6bb75a435bbfaec3a 100644 (file)
@@ -48,7 +48,7 @@ static int browser_reg_compare(pval *browser)
        if (found_browser_entry) { /* already found */
                return 0;
        }
-       zend_hash_find(browser->value.ht,"browser_name_pattern",sizeof("browser_name_pattern"),(void **) &browser_name);
+       zend_hash_find(browser->value.obj.properties, "browser_name_pattern",sizeof("browser_name_pattern"),(void **) &browser_name);
        if (!strchr(browser_name->value.str.val,'*')) {
                return 0;
        }
@@ -64,7 +64,7 @@ static int browser_reg_compare(pval *browser)
 
 PHP_FUNCTION(get_browser)
 {
-       pval **agent_name,**agent,tmp;
+       pval **agent_name,**agent, tmp;
 
        if (!INI_STR("browscap")) {
                RETURN_FALSE;
@@ -104,13 +104,15 @@ PHP_FUNCTION(get_browser)
        *return_value = **agent;
        return_value->type = IS_OBJECT;
        pval_copy_constructor(return_value);
-       return_value->value.ht->pDestructor = ZVAL_DESTRUCTOR;
+       return_value->value.obj.properties->pDestructor = ZVAL_DESTRUCTOR;
+
+       while (zend_hash_find((*agent)->value.obj.properties, "parent",sizeof("parent"), (void **) &agent_name)==SUCCESS) {
+               zval *tmp_copy;
 
-       while (zend_hash_find((*agent)->value.ht, "parent",sizeof("parent"), (void **) &agent_name)==SUCCESS) {
                if (zend_hash_find(&browser_hash,(*agent_name)->value.str.val, (*agent_name)->value.str.len+1, (void **)&agent)==FAILURE) {
                        break;
                }
-               zend_hash_merge(return_value->value.ht,(*agent)->value.ht, ZVAL_COPY_CTOR, (void *) &tmp, sizeof(pval), 0);
+               zend_hash_merge(return_value->value.obj.properties,(*agent)->value.obj.properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(pval *), 0);
        }
 }
 
index 0991c1e5699574751cab0b9e7f6fd5370167680d..64de73d2a80adcf127b0351ebaf92118086b26f5 100644 (file)
@@ -38,7 +38,7 @@
 #include "win32/wfile.h"
 #endif
 
-#define YYSTYPE pval
+#define YYSTYPE zval
 
 #define PARSING_MODE_CFG 0
 #define PARSING_MODE_BROWSCAP 1
@@ -49,21 +49,21 @@ extern HashTable browser_hash;
 PHPAPI extern char *php_ini_path;
 #endif
 static HashTable *active_hash_table;
-static pval *current_section;
+static zval *current_section;
 static char *currently_parsed_filename;
 
 static int parsing_mode;
 
-pval yylval;
+zval yylval;
 
-extern int cfglex(pval *cfglval);
+extern int cfglex(zval *cfglval);
 extern FILE *cfgin;
 extern int cfglineno;
 extern void init_cfg_scanner(void);
 
-pval *cfg_get_entry(char *name, uint name_length)
+zval *cfg_get_entry(char *name, uint name_length)
 {
-       pval *tmp;
+       zval *tmp;
 
        if (zend_hash_find(&configuration_hash, name, name_length, (void **) &tmp)==SUCCESS) {
                return tmp;
@@ -75,14 +75,14 @@ pval *cfg_get_entry(char *name, uint name_length)
 
 PHPAPI int cfg_get_long(char *varname,long *result)
 {
-       pval *tmp,var;
+       zval *tmp,var;
        
        if (zend_hash_find(&configuration_hash,varname,strlen(varname)+1,(void **) &tmp)==FAILURE) {
                *result=(long)NULL;
                return FAILURE;
        }
        var = *tmp;
-       pval_copy_constructor(&var);
+       zval_copy_ctor(&var);
        convert_to_long(&var);
        *result = var.value.lval;
        return SUCCESS;
@@ -91,14 +91,14 @@ PHPAPI int cfg_get_long(char *varname,long *result)
 
 PHPAPI int cfg_get_double(char *varname,double *result)
 {
-       pval *tmp,var;
+       zval *tmp,var;
        
        if (zend_hash_find(&configuration_hash,varname,strlen(varname)+1,(void **) &tmp)==FAILURE) {
                *result=(double)0;
                return FAILURE;
        }
        var = *tmp;
-       pval_copy_constructor(&var);
+       zval_copy_ctor(&var);
        convert_to_double(&var);
        *result = var.value.dval;
        return SUCCESS;
@@ -107,7 +107,7 @@ PHPAPI int cfg_get_double(char *varname,double *result)
 
 PHPAPI int cfg_get_string(char *varname, char **result)
 {
-       pval *tmp;
+       zval *tmp;
 
        if (zend_hash_find(&configuration_hash,varname,strlen(varname)+1,(void **) &tmp)==FAILURE) {
                *result=NULL;
@@ -124,19 +124,20 @@ static void yyerror(char *str)
 }
 
 
-static void pvalue_config_destructor(pval *pvalue)
+static void pvalue_config_destructor(zval **pvalue)
 {
-       if (pvalue->type == IS_STRING && pvalue->value.str.val != empty_string) {
-               free(pvalue->value.str.val);
+       if ((*pvalue)->type == IS_STRING && (*pvalue)->value.str.val != empty_string) {
+               free((*pvalue)->value.str.val);
        }
+       free(*pvalue);
 }
 
 
-static void pvalue_browscap_destructor(pval *pvalue)
+static void pvalue_browscap_destructor(zval *pvalue)
 {
        if (pvalue->type == IS_OBJECT || pvalue->type == IS_ARRAY) {
-               zend_hash_destroy(pvalue->value.ht);
-               free(pvalue->value.ht);
+               zend_hash_destroy(pvalue->value.obj.properties);
+               free(pvalue->value.obj.properties);
        }
 }
 
@@ -145,7 +146,7 @@ int php_init_config(void)
 {
        PLS_FETCH();
 
-       if (zend_hash_init(&configuration_hash, 0, NULL, (void (*)(void *))pvalue_config_destructor, 1)==FAILURE) {
+       if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1)==FAILURE) {
                return FAILURE;
        }
 
@@ -214,12 +215,12 @@ int php_init_config(void)
                }
 
                if (opened_path) {
-                       pval tmp;
+                       zval tmp;
                        
                        tmp.value.str.val = opened_path;
                        tmp.value.str.len = strlen(opened_path);
                        tmp.type = IS_STRING;
-                       zend_hash_update(&configuration_hash,"cfg_file_path",sizeof("cfg_file_path"),(void *) &tmp,sizeof(pval),NULL);
+                       zend_hash_update(&configuration_hash,"cfg_file_path",sizeof("cfg_file_path"),(void *) &tmp,sizeof(zval),NULL);
 #if DEBUG_CFG_PARSER
                        php_printf("INI file opened at '%s'\n",opened_path);
 #endif
@@ -244,7 +245,7 @@ PHP_MINIT_FUNCTION(browscap)
        char *browscap = INI_STR("browscap");
 
        if (browscap) {
-               if (zend_hash_init(&browser_hash, 0, NULL, (void (*)(void *))pvalue_browscap_destructor, 1)==FAILURE) {
+               if (zend_hash_init(&browser_hash, 0, NULL, (dtor_func_t) pvalue_browscap_destructor, 1)==FAILURE) {
                        return FAILURE;
                }
 
@@ -281,7 +282,7 @@ PHP_MSHUTDOWN_FUNCTION(browscap)
 }
 
 
-static void convert_browscap_pattern(pval *pattern)
+static void convert_browscap_pattern(zval *pattern)
 {
        register int i,j;
        char *t;
@@ -293,7 +294,7 @@ static void convert_browscap_pattern(pval *pattern)
        }
 
        if (i==pattern->value.str.len) { /* no wildcards */
-               return;
+               pattern->value.str.val = zend_strndup(pattern->value.str.val, pattern->value.str.len);
        }
 
        t = (char *) malloc(pattern->value.str.len*2);
@@ -317,10 +318,8 @@ static void convert_browscap_pattern(pval *pattern)
                }
        }
        t[j]=0;
-       free(pattern->value.str.val);
        pattern->value.str.val = t;
        pattern->value.str.len = j;
-       return;
 }
 
 
@@ -410,19 +409,28 @@ statement:
 #endif
                        $3.type = IS_STRING;
                        if (parsing_mode==PARSING_MODE_CFG) {
-                               zend_hash_update(active_hash_table, $1.value.str.val, $1.value.str.len+1, &$3, sizeof(pval), NULL);
+                               zend_hash_update(active_hash_table, $1.value.str.val, $1.value.str.len+1, &$3, sizeof(zval), NULL);
                                if (active_hash_table == &configuration_hash) {
                                php_alter_ini_entry($1.value.str.val, $1.value.str.len+1, $3.value.str.val, $3.value.str.len+1, PHP_INI_SYSTEM);
                                }
                        } else if (parsing_mode==PARSING_MODE_BROWSCAP) {
-                               zend_str_tolower($1.value.str.val,$1.value.str.len);
-                               zend_hash_update(current_section->value.ht, $1.value.str.val, $1.value.str.len+1, &$3, sizeof(pval), NULL);
+                               if (current_section) {
+                                       zval *new_property;
+
+                                       new_property = (zval *) malloc(sizeof(zval));
+                                       INIT_PZVAL(new_property);
+                                       new_property->value.str.val = $3.value.str.val;
+                                       new_property->value.str.len = $3.value.str.len;
+                                       new_property->type = IS_STRING;
+                                       zend_str_tolower(new_property->value.str.val, new_property->value.str.len);
+                                       zend_hash_update(current_section->value.obj.properties, $1.value.str.val, $1.value.str.len+1, &new_property, sizeof(zval *), NULL);
+                               }
                        }
                        free($1.value.str.val);
                }
        |       TC_STRING { free($1.value.str.val); }
        |       EXTENSION '=' string_foo {
-                       pval dummy;
+                       zval dummy;
 #if DEBUG_CFG_PARSER
                        printf("Loading '%s'\n",$3.value.str.val);
 #endif
@@ -455,18 +463,25 @@ statement:
                }
        |       SECTION { 
                        if (parsing_mode==PARSING_MODE_BROWSCAP) {
-                               pval tmp;
+                               zval *processed;
 
                                /*printf("'%s' (%d)\n",$1.value.str.val,$1.value.str.len+1);*/
-                               tmp.value.ht = (HashTable *) malloc(sizeof(HashTable));
-                               zend_hash_init(tmp.value.ht, 0, NULL, (void (*)(void *))pvalue_config_destructor, 1);
-                               tmp.type = IS_OBJECT;
-                               zend_hash_update(active_hash_table, $1.value.str.val, $1.value.str.len+1, (void *) &tmp, sizeof(pval), (void **) &current_section);
-                               tmp.value.str.val = zend_strndup($1.value.str.val,$1.value.str.len);
-                               tmp.value.str.len = $1.value.str.len;
-                               tmp.type = IS_STRING;
-                               convert_browscap_pattern(&tmp);
-                               zend_hash_update(current_section->value.ht,"browser_name_pattern",sizeof("browser_name_pattern"),(void *) &tmp, sizeof(pval), NULL);
+                               current_section = (zval *) malloc(sizeof(zval));
+                               INIT_PZVAL(current_section);
+                               processed = (zval *) malloc(sizeof(zval));
+                               INIT_PZVAL(processed);
+
+                               current_section->value.obj.ce = &zend_standard_class_def;
+                               current_section->value.obj.properties = (HashTable *) malloc(sizeof(HashTable));
+                               current_section->type = IS_OBJECT;
+                               zend_hash_init(current_section->value.obj.properties, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1);
+                               zend_hash_update(active_hash_table, $1.value.str.val, $1.value.str.len+1, (void *) &current_section, sizeof(zval *), NULL);
+
+                               processed->value.str.val = $1.value.str.val;
+                               processed->value.str.len = $1.value.str.len;
+                               processed->type = IS_STRING;
+                               convert_browscap_pattern(processed);
+                               zend_hash_update(current_section->value.obj.properties, "browser_name_pattern", sizeof("browser_name_pattern"), (void *) &processed, sizeof(zval *), NULL);
                        }
                        free($1.value.str.val);
                }
index 5d23a64ab627a3949d52f7d8b772df7549d568e3..08591fbb3101a39fa0c064bd5a7d2b2867e3db31 100644 (file)
@@ -19,6 +19,8 @@
  */
 /* $Id$ */
 
+#define _PHP_REGEX_H 1
+
 #include "zend.h"
 #include "php.h"
 #include "php_variables.h"
index 7480c250e79f57f72682825c7fa374a86e64bf54..b1d7a3e34095f96be93c146665d220f587b04b5a 100644 (file)
    |          David Sklar <sklar@student.net>                             |
    +----------------------------------------------------------------------+
  */
-
 /* $Id$ */
+
+#define _PHP_REGEX_H 1
+
 #include "php.h"
 #include "ext/standard/head.h"
 #include "php_globals.h"
index 5beacc18d1246500d77e57503d8dde2a6bbf046e..48c72bfa2cc154fdbf33cd65d97f5ff01e2afd4a 100644 (file)
@@ -21,6 +21,8 @@
  */
 /* $Id$ */
 
+#define _PHP_REGEX_H 1
+
 #include "php.h"
 
 #include "httpd.h"