1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
|
%{
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2000 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
/* $Id: configuration-parser.y,v 1.81 2000/02/07 23:54:49 zeev Exp $ */
#define DEBUG_CFG_PARSER 1
#include "php.h"
#include "modules.h"
#include "functions/dl.h"
#include "functions/file.h"
#include "functions/php3_browscap.h"
#if WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winbase.h>
#include "win32/wfile.h"
#endif
#define PARSING_MODE_CFG 0
#define PARSING_MODE_BROWSCAP 1
static HashTable configuration_hash;
extern HashTable browser_hash;
extern char *php3_ini_path;
static HashTable *active__php3_hash_table;
static pval *current_section;
static char *currently_parsed_filename;
static int parsing_mode;
pval yylval;
extern int cfglex(pval *cfglval);
extern FILE *cfgin;
extern int cfglineno;
extern void init_cfg_scanner(void);
PHPAPI int cfg_get_long(char *varname,long *result)
{
pval *tmp,var;
if (_php3_hash_find(&configuration_hash,varname,strlen(varname)+1,(void **) &tmp)==FAILURE) {
*result=(long)NULL;
return FAILURE;
}
var = *tmp;
pval_copy_constructor(&var);
convert_to_long(&var);
*result = var.value.lval;
return SUCCESS;
}
PHPAPI int cfg_get_double(char *varname,double *result)
{
pval *tmp,var;
if (_php3_hash_find(&configuration_hash,varname,strlen(varname)+1,(void **) &tmp)==FAILURE) {
*result=(double)0;
return FAILURE;
}
var = *tmp;
pval_copy_constructor(&var);
convert_to_double(&var);
*result = var.value.dval;
return SUCCESS;
}
PHPAPI int cfg_get_string(char *varname, char **result)
{
pval *tmp;
if (_php3_hash_find(&configuration_hash,varname,strlen(varname)+1,(void **) &tmp)==FAILURE) {
*result=NULL;
return FAILURE;
}
*result = tmp->value.str.val;
return SUCCESS;
}
static void yyerror(char *str)
{
fprintf(stderr,"PHP: Error parsing %s on line %d\n",currently_parsed_filename,cfglineno);
}
static void pvalue_config_destructor(pval *pvalue)
{
if (pvalue->type == IS_STRING && pvalue->value.str.val != empty_string) {
free(pvalue->value.str.val);
}
}
static void pvalue_browscap_destructor(pval *pvalue)
{
if (pvalue->type == IS_OBJECT || pvalue->type == IS_ARRAY) {
_php3_hash_destroy(pvalue->value.ht);
free(pvalue->value.ht);
}
}
int php3_init_config(void)
{
TLS_VARS;
if (_php3_hash_init(&configuration_hash, 0, NULL, (void (*)(void *))pvalue_config_destructor, 1)==FAILURE) {
return FAILURE;
}
#if USE_CONFIG_FILE
{
char *env_location,*default_location,*php_ini_path;
int safe_mode_state = php3_ini.safe_mode;
char *opened_path;
env_location = getenv("PHPRC");
if (!env_location) {
env_location="";
}
#if WIN32|WINNT
{
if (GLOBAL(php3_ini_path)) {
default_location = GLOBAL(php3_ini_path);
} else {
default_location = (char *) malloc(512);
if (!GetWindowsDirectory(default_location,255)) {
default_location[0]=0;
}
}
}
#elif OS2
if (GLOBAL(php3_ini_path)) {
default_location = GLOBAL(php3_ini_path);
} else {
default_location = getenv("ETC");
if (!default_location) {
default_location = CONFIGURATION_FILE_PATH;
}
}
#else
if (!GLOBAL(php3_ini_path)) {
default_location = CONFIGURATION_FILE_PATH;
} else {
default_location = GLOBAL(php3_ini_path);
}
#endif
/* build a path */
php_ini_path = (char *) malloc(sizeof(".")+strlen(env_location)+strlen(default_location)+2+1);
if (!GLOBAL(php3_ini_path)) {
#if WIN32|WINNT|OS2
sprintf(php_ini_path,".;%s;%s",env_location,default_location);
#else
sprintf(php_ini_path,".:%s:%s",env_location,default_location);
#endif
} else {
/* if path was set via -c flag, only look there */
strcpy(php_ini_path,default_location);
}
php3_ini.safe_mode = 0;
cfgin = php3_fopen_with_path("php3.ini","r",php_ini_path,&opened_path);
free(php_ini_path);
php3_ini.safe_mode = safe_mode_state;
if (!cfgin) {
# if WIN32|WINNT
return FAILURE;
# else
return SUCCESS; /* having no configuration file is ok */
# endif
}
if (opened_path) {
pval tmp;
tmp.value.str.val = opened_path;
tmp.value.str.len = strlen(opened_path);
tmp.type = IS_STRING;
_php3_hash_update(&configuration_hash,"cfg_file_path",sizeof("cfg_file_path"),(void *) &tmp,sizeof(pval),NULL);
#if 0
php3_printf("INI file opened at '%s'\n",opened_path);
#endif
}
init_cfg_scanner();
active__php3_hash_table = &configuration_hash;
parsing_mode = PARSING_MODE_CFG;
currently_parsed_filename = "php3.ini";
yyparse();
fclose(cfgin);
}
#endif
return SUCCESS;
}
int php3_minit_browscap(INIT_FUNC_ARGS)
{
TLS_VARS;
if (php3_ini.browscap) {
if (_php3_hash_init(&GLOBAL(browser_hash), 0, NULL, (void (*)(void *))pvalue_browscap_destructor, 1)==FAILURE) {
return FAILURE;
}
cfgin = fopen(php3_ini.browscap,"r");
if (!cfgin) {
php3_error(E_WARNING,"Cannot open '%s' for reading",php3_ini.browscap);
return FAILURE;
}
init_cfg_scanner();
active__php3_hash_table = &GLOBAL(browser_hash);
parsing_mode = PARSING_MODE_BROWSCAP;
currently_parsed_filename = php3_ini.browscap;
yyparse();
fclose(cfgin);
}
return SUCCESS;
}
int php3_shutdown_config(void)
{
_php3_hash_destroy(&configuration_hash);
return SUCCESS;
}
int php3_mshutdown_browscap(void)
{
TLS_VARS;
if (php3_ini.browscap) {
_php3_hash_destroy(&GLOBAL(browser_hash));
}
return SUCCESS;
}
static void convert_browscap_pattern(pval *pattern)
{
register int i,j;
char *t;
for (i=0; i<pattern->value.str.len; i++) {
if (pattern->value.str.val[i]=='*' || pattern->value.str.val[i]=='?') {
break;
}
}
if (i==pattern->value.str.len) { /* no wildcards */
return;
}
t = (char *) malloc(pattern->value.str.len*2);
for (i=0,j=0; i<pattern->value.str.len; i++,j++) {
switch (pattern->value.str.val[i]) {
case '?':
t[j] = '.';
break;
case '*':
t[j++] = '.';
t[j] = '*';
break;
case '.':
t[j++] = '\\';
t[j] = '.';
break;
default:
t[j] = pattern->value.str.val[i];
break;
}
}
t[j]=0;
free(pattern->value.str.val);
pattern->value.str.val = t;
pattern->value.str.len = j;
return;
}
%}
%pure_parser
%token STRING
%token ENCAPSULATED_STRING
%token SECTION
%token CFG_TRUE
%token CFG_FALSE
%token EXTENSION
%%
statement_list:
statement_list statement
| /* empty */
;
statement:
string '=' string_or_value {
#if 0
printf("'%s' = '%s'\n",$1.value.str.val,$3.value.str.val);
#endif
$3.type = IS_STRING;
if (parsing_mode==PARSING_MODE_CFG) {
_php3_hash_update(active__php3_hash_table, $1.value.str.val, $1.value.str.len+1, &$3, sizeof(pval), NULL);
} else if (parsing_mode==PARSING_MODE_BROWSCAP) {
php3_str_tolower($1.value.str.val,$1.value.str.len);
_php3_hash_update(current_section->value.ht, $1.value.str.val, $1.value.str.len+1, &$3, sizeof(pval), NULL);
}
free($1.value.str.val);
}
| string { free($1.value.str.val); }
| EXTENSION '=' string {
pval dummy;
#if 0
printf("Loading '%s'\n",$3.value.str.val);
#endif
php3_dl(&$3,MODULE_PERSISTENT,&dummy);
}
| SECTION {
if (parsing_mode==PARSING_MODE_BROWSCAP) {
pval tmp;
/*printf("'%s' (%d)\n",$1.value.str.val,$1.value.str.len+1);*/
tmp.value.ht = (HashTable *) malloc(sizeof(HashTable));
_php3_hash_init(tmp.value.ht, 0, NULL, (void (*)(void *))pvalue_config_destructor, 1);
tmp.type = IS_OBJECT;
_php3_hash_update(active__php3_hash_table, $1.value.str.val, $1.value.str.len+1, (void *) &tmp, sizeof(pval), (void **) ¤t_section);
tmp.value.str.val = php3_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);
_php3_hash_update(current_section->value.ht,"browser_name_pattern",sizeof("browser_name_pattern"),(void *) &tmp, sizeof(pval), NULL);
}
free($1.value.str.val);
}
| '\n'
;
string:
STRING { $$ = $1; }
| ENCAPSULATED_STRING { $$ = $1; }
;
string_or_value:
string { $$ = $1; }
| CFG_TRUE { $$ = $1; }
| CFG_FALSE { $$ = $1; }
| '\n' { $$.value.str.val = strdup(""); $$.value.str.len=0; $$.type = IS_STRING; }
;
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/
|