/* {{{ dba_close_pe_rsrc */ static void dba_close_pe_rsrc(zend_resource *rsrc) { dba_info *info = (dba_info *)rsrc->ptr; /* closes the resource by calling dba_close_rsrc() */ zend_hash_apply_with_argument(&EG(persistent_list), dba_close_pe_rsrc_deleter, info); }
/* {{{ display_ini_entries */ PHPAPI void display_ini_entries(zend_module_entry *module) { int module_number, module_number_available; if (module) { module_number = module->module_number; } else { module_number = 0; } module_number_available = module_number; zend_hash_apply_with_argument(EG(ini_directives), php_ini_available, &module_number_available); if (module_number_available == -1) { php_info_print_table_start(); php_info_print_table_header(3, "Directive", "Local Value", "Master Value"); zend_hash_apply_with_argument(EG(ini_directives), php_ini_displayer, (void *)&module_number); php_info_print_table_end(); } }
/* {{{ _php_regcomp */ static int _php_regcomp(regex_t *preg, const char *pattern, int cflags) { int r = 0; int patlen = strlen(pattern); reg_cache *rc = NULL; if (zend_hash_num_elements(&EREG(ht_rc)) >= EREG_CACHE_SIZE) { /* easier than dealing with overflow as it happens */ if (EREG(lru_counter) >= (1 << 31) || zend_hash_sort(&EREG(ht_rc), zend_qsort, ereg_lru_cmp, 0) == FAILURE) { zend_hash_clean(&EREG(ht_rc)); EREG(lru_counter) = 0; } else { int num_clean = EREG_CACHE_SIZE / 4; zend_hash_apply_with_argument(&EREG(ht_rc), ereg_clean_cache, &num_clean); } } rc = zend_hash_str_find_ptr(&EREG(ht_rc), pattern, patlen); if (rc && rc->cflags == cflags) { #ifdef HAVE_REGEX_T_RE_MAGIC /* * We use a saved magic number to see whether cache is corrupted, and if it * is, we flush it and compile the pattern from scratch. */ if (rc->preg.re_magic != reg_magic) { zend_hash_clean(&EREG(ht_rc)); EREG(lru_counter) = 0; } else { memcpy(preg, &rc->preg, sizeof(*preg)); return r; } } r = regcomp(preg, pattern, cflags); if(!r) { reg_cache rcp; rcp.cflags = cflags; rcp.lastuse = ++(EREG(lru_counter)); memcpy(&rcp.preg, preg, sizeof(*preg)); /* * Since we don't have access to the actual MAGIC1 definition in the private * header file, we save the magic value immediately after compilation. Hopefully, * it's good. */ if (!reg_magic) reg_magic = preg->re_magic; zend_hash_str_update_mem(&EREG(ht_rc), pattern, patlen, &rcp, sizeof(rcp)); } #else memcpy(preg, &rc->preg, sizeof(*preg)); } else {
PHPAPI void display_ini_entries(zend_module_entry *module) { int module_number; ELS_FETCH(); if (module) { module_number = module->module_number; } else { module_number = 0; } php_info_print_table_start(); php_info_print_table_header(3, "Directive", "Local Value", "Master Value"); zend_hash_apply_with_argument(&EG(ini_directives), (apply_func_arg_t) php_ini_displayer, (void *) (long) module_number); php_info_print_table_end(); }
void clean_module_constants(int module_number) { zend_hash_apply_with_argument(EG(zend_constants), clean_module_constant, (void *) &module_number); }
void zend_accel_copy_internal_functions(void) { zend_hash_apply_with_argument(CG(function_table), (apply_func_arg_t)copy_internal_function, &ZCG(function_table)); ZCG(internal_functions_count) = zend_hash_num_elements(&ZCG(function_table)); }
ZEND_API void zend_ts_hash_apply_with_argument(TsHashTable *ht, apply_func_arg_t apply_func, void *argument) { begin_write(ht); zend_hash_apply_with_argument(TS_HASH(ht), apply_func, argument); end_write(ht); }
//PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_len TSRMLS_DC) pcre *compileRegex( char *regex , int regex_len , char *msg , int msglen ) { pcre *re = NULL; pcre_extra *extra; int coptions = 0; int soptions = 0; const char *error; int erroffset; char delimiter; char start_delimiter; char end_delimiter; char *p, *pp; char *pattern; int do_study = 0; int poptions = 0; unsigned const char *tables = NULL; char buf[ 1024 ] ; #if HAVE_SETLOCALE char *locale = setlocale(LC_CTYPE, NULL); #endif //R.A.W. //pcre_cache_entry *pce; //pcre_cache_entry new_entry; if( msglen ) { *msg = '\0'; } /* Try to lookup the cached regex entry, and if successful, just pass back the compiled pattern, otherwise go on and compile it. */ regex_len = strlen(regex); //R.A.W. #if 0 if (zend_hash_find(&PCRE_G(pcre_cache), regex, regex_len+1, (void **)&pce) == SUCCESS) { /* * We use a quick pcre_info() check to see whether cache is corrupted, and if it * is, we flush it and compile the pattern from scratch. */ if (pcre_info(pce->re, NULL, NULL) == PCRE_ERROR_BADMAGIC) { zend_hash_clean(&PCRE_G(pcre_cache)); } else { #if HAVE_SETLOCALE if (!strcmp(pce->locale, locale)) { #endif return pce; #if HAVE_SETLOCALE } #endif } } #endif p = regex; /* Parse through the leading whitespace, and display a warning if we get to the end without encountering a delimiter. */ while (isspace((int)*(unsigned char *)p)) p++; if (*p == 0) { // R.A.W. //php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty regular expression"); strncpy(msg, "Empty regular expression" , msglen ); return NULL; } /* Get the delimiter and display a warning if it is alphanumeric or a backslash. */ delimiter = *p++; if (isalnum((int)*(unsigned char *)&delimiter) || delimiter == '\\') { //php_error_docref(NULL TSRMLS_CC,E_WARNING, "Delimiter must not be alphanumeric or backslash"); strncpy( msg, "Delimiter must not be alphanumeric or backslash",msglen); return NULL; } start_delimiter = delimiter; if ((pp = strchr("([{< )]}> )]}>", delimiter))) delimiter = pp[5]; end_delimiter = delimiter; if (start_delimiter == end_delimiter) { /* We need to iterate through the pattern, searching for the ending delimiter, but skipping the backslashed delimiters. If the ending delimiter is not found, display a warning. */ pp = p; while (*pp != 0) { if (*pp == '\\' && pp[1] != 0) pp++; else if (*pp == delimiter) break; pp++; } if (*pp == 0) { //php_error_docref(NULL TSRMLS_CC,E_WARNING, "No ending delimiter '%c' found", delimiter); //R.A.W. strncpy( msg, "No ending delimiter found" ,msglen ) ; return NULL; } } else { /* We iterate through the pattern, searching for the matching ending * delimiter. For each matching starting delimiter, we increment nesting * level, and decrement it for each matching ending delimiter. If we * reach the end of the pattern without matching, display a warning. */ int brackets = 1; /* brackets nesting level */ pp = p; while (*pp != 0) { if (*pp == '\\' && pp[1] != 0) pp++; else if (*pp == end_delimiter && --brackets <= 0) break; else if (*pp == start_delimiter) brackets++; pp++; } if (*pp == 0) { //php_error_docref(NULL TSRMLS_CC,E_WARNING, "No ending matching delimiter '%c' found", end_delimiter); strncpy( msg,"No ending matching delimiter found",msglen ) ; return NULL; } } /* Make a copy of the actual pattern. */ // R.A.W. //pattern = strndup(p, pp-p); // osx compile is complaining about strndup and since I have te // other function anyway and since I'll someday rewrite this fn, just // call that other function now :>) pattern = ghstrndup( p,pp-p) ; /* Move on to the options */ pp++; /* Parse through the options, setting appropriate flags. Display a warning if we encounter an unknown modifier. */ while (*pp != 0) { switch (*pp++) { /* Perl compatible options */ case 'i': coptions |= PCRE_CASELESS; break; case 'm': coptions |= PCRE_MULTILINE; break; case 's': coptions |= PCRE_DOTALL; break; case 'x': coptions |= PCRE_EXTENDED; break; /* PCRE specific options */ case 'A': coptions |= PCRE_ANCHORED; break; case 'D': coptions |= PCRE_DOLLAR_ENDONLY;break; case 'S': do_study = 1; break; case 'U': coptions |= PCRE_UNGREEDY; break; case 'X': coptions |= PCRE_EXTRA; break; case 'u': coptions |= PCRE_UTF8; break; // R.A.W. /* Custom preg options */ //case 'e': poptions |= PREG_REPLACE_EVAL; break; case ' ': case '\n': break; default: //php_error_docref(NULL TSRMLS_CC,E_WARNING, "Unknown modifier '%c'", pp[-1]); strncpy( msg,"Unknown modifier",msglen ) ; free(pattern); return NULL; } } //R.A.W. tables = NULL ; #if 0 #if HAVE_SETLOCALE if (strcmp(locale, "C")) tables = pcre_maketables(); #endif #endif /* Compile pattern and display a warning if compilation failed. */ re = pcre_compile(pattern, coptions, &error, &erroffset, tables); if (re == NULL) { //php_error_docref(NULL TSRMLS_CC,E_WARNING, "Compilation failed: %s at offset %d", error, erroffset); // R.A.W. sprintf(buf, "Compilation of /%s/ failed: %s at offset %d",pattern, error, erroffset); //sprintf(buf, "Compilation failed: %s at offset %d",error, erroffset); strncpy( msg, buf , msglen ) ; free(pattern); // R.A.W. //if (tables) { //pefree((void*)tables, 1); //} return NULL; } /* If study option was specified, study the pattern and store the result in extra for passing to pcre_exec. */ if (do_study) { extra = pcre_study(re, soptions, &error); if (extra) { extra->flags |= PCRE_EXTRA_MATCH_LIMIT | PCRE_EXTRA_MATCH_LIMIT_RECURSION; } if (error != NULL) { strncpy( msg, "Error while studying pattern",msglen); } } else { extra = NULL; } free(pattern); //R.A.W. #if 0 /* * If we reached cache limit, clean out the items from the head of the list; * these are supposedly the oldest ones (but not necessarily the least used * ones). */ if (zend_hash_num_elements(&PCRE_G(pcre_cache)) == PCRE_CACHE_SIZE) { int num_clean = PCRE_CACHE_SIZE / 8; zend_hash_apply_with_argument(&PCRE_G(pcre_cache), pcre_clean_cache, &num_clean TSRMLS_CC); } /* Store the compiled pattern and extra info in the cache. */ new_entry.re = re; new_entry.extra = extra; new_entry.preg_options = poptions; new_entry.compile_options = coptions; #if HAVE_SETLOCALE new_entry.locale = pestrdup(locale, 1); new_entry.tables = tables; #endif zend_hash_update(&PCRE_G(pcre_cache), regex, regex_len+1, (void *)&new_entry, sizeof(pcre_cache_entry), (void**)&pce); #endif // return pce; //R.A.W. return re ; }
PHPAPI void php_print_info(int flag) { char **env,*tmp1,*tmp2; char *php_uname; int expose_php = INI_INT("expose_php"); time_t the_time; struct tm *ta, tmbuf; ELS_FETCH(); SLS_FETCH(); the_time = time(NULL); ta = php_localtime_r(&the_time, &tmbuf); PUTS("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n<html>\n"); if (flag & PHP_INFO_GENERAL) { char *zend_version = get_zend_version(); php_uname = php_get_uname(); PUTS("<head>"); php_info_print_style(); PUTS("<title>phpinfo()</title></head><body>"); php_info_print_box_start(1); if (expose_php) { PUTS("<a href=\"http://www.php.net/\"><img src=\""); if (SG(request_info).request_uri) { PUTS(SG(request_info).request_uri); } if ((ta->tm_mon==3) && (ta->tm_mday==1)) { PUTS("?="PHP_EGG_LOGO_GUID"\" border=0 align=\"right\" alt=\"Thies!\"></a>"); } else { PUTS("?="PHP_LOGO_GUID"\" border=0 align=\"right\" alt=\"PHP Logo\"></a>"); } } php_printf("<H1>PHP Version %s</H1>\n", PHP_VERSION); php_info_print_box_end(); php_info_print_table_start(); php_info_print_table_row(2, "System", php_uname ); php_info_print_table_row(2, "Build Date", __DATE__ ); #ifdef CONFIGURE_COMMAND php_info_print_table_row(2, "Configure Command", CONFIGURE_COMMAND ); #endif if (sapi_module.pretty_name) { php_info_print_table_row(2, "Server API", sapi_module.pretty_name ); } #ifdef VIRTUAL_DIR php_info_print_table_row(2, "Virtual Directory Support", "enabled" ); #else php_info_print_table_row(2, "Virtual Directory Support", "disabled" ); #endif php_info_print_table_row(2, "Configuration File (php.ini) Path", php_ini_opened_path?php_ini_opened_path:PHP_CONFIG_FILE_PATH); #if ZEND_DEBUG php_info_print_table_row(2, "ZEND_DEBUG", "enabled" ); #else php_info_print_table_row(2, "ZEND_DEBUG", "disabled" ); #endif #ifdef ZTS php_info_print_table_row(2, "Thread Safety", "enabled" ); #else php_info_print_table_row(2, "Thread Safety", "disabled" ); #endif #if HAVE_PHP_STREAM php_info_print_table_row(2, "Experimental PHP Streams", "enabled"); #endif php_info_print_table_end(); /* Zend Engine */ php_info_print_box_start(0); if (expose_php) { PUTS("<a href=\"http://www.zend.com/\"><img src=\""); if (SG(request_info).request_uri) { PUTS(SG(request_info).request_uri); } PUTS("?="ZEND_LOGO_GUID"\" border=\"0\" align=\"right\" alt=\"Zend logo\"></a>\n"); } php_printf("This program makes use of the Zend scripting language engine:<BR>"); zend_html_puts(zend_version, strlen(zend_version)); php_printf("</BR>\n"); php_info_print_box_end(); efree(php_uname); } if ((flag & PHP_INFO_CREDITS) && expose_php) { php_info_print_hr(); PUTS("<h1 align=\"center\"><a href=\""); if (SG(request_info).request_uri) { PUTS(SG(request_info).request_uri); } PUTS("?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000\">"); PUTS("PHP 4.0 Credits"); PUTS("</a></h1>\n"); } zend_ini_sort_entries(ELS_C); if (flag & PHP_INFO_CONFIGURATION) { php_info_print_hr(); PUTS("<h1 align=\"center\">Configuration</h1>\n"); SECTION("PHP Core\n"); display_ini_entries(NULL); } if (flag & PHP_INFO_MODULES) { int show_info_func; show_info_func = 1; zend_hash_apply_with_argument(&module_registry, (int (*)(void *, void *)) _display_module_info, &show_info_func); SECTION("Additional Modules"); php_info_print_table_start(); show_info_func = 0; zend_hash_apply_with_argument(&module_registry, (int (*)(void *, void *)) _display_module_info, &show_info_func); php_info_print_table_end(); } if (flag & PHP_INFO_ENVIRONMENT) { SECTION("Environment"); php_info_print_table_start(); php_info_print_table_header(2, "Variable", "Value"); for (env=environ; env!=NULL && *env !=NULL; env++) { tmp1 = estrdup(*env); if (!(tmp2=strchr(tmp1,'='))) { /* malformed entry? */ efree(tmp1); continue; } *tmp2 = 0; tmp2++; php_info_print_table_row(2, tmp1, tmp2); efree(tmp1); } php_info_print_table_end(); } if (flag & PHP_INFO_VARIABLES) { pval **data; SECTION("PHP Variables"); php_info_print_table_start(); php_info_print_table_header(2, "Variable", "Value"); if (zend_hash_find(&EG(symbol_table), "PHP_SELF", sizeof("PHP_SELF"), (void **) &data) != FAILURE) { php_info_print_table_row(2, "PHP_SELF", (*data)->value.str.val); } if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_TYPE", sizeof("PHP_AUTH_TYPE"), (void **) &data) != FAILURE) { php_info_print_table_row(2, "PHP_AUTH_TYPE", (*data)->value.str.val); } if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_USER", sizeof("PHP_AUTH_USER"), (void **) &data) != FAILURE) { php_info_print_table_row(2, "PHP_AUTH_USER", (*data)->value.str.val); } if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_PW", sizeof("PHP_AUTH_PW"), (void **) &data) != FAILURE) { php_info_print_table_row(2, "PHP_AUTH_PW", (*data)->value.str.val); } php_print_gpcse_array("HTTP_GET_VARS", sizeof("HTTP_GET_VARS")-1 ELS_CC); php_print_gpcse_array("HTTP_POST_VARS", sizeof("HTTP_POST_VARS")-1 ELS_CC); php_print_gpcse_array("HTTP_POST_FILES", sizeof("HTTP_POST_FILES")-1 ELS_CC); php_print_gpcse_array("HTTP_COOKIE_VARS", sizeof("HTTP_COOKIE_VARS")-1 ELS_CC); php_print_gpcse_array("HTTP_SERVER_VARS", sizeof("HTTP_SERVER_VARS")-1 ELS_CC); php_print_gpcse_array("HTTP_ENV_VARS", sizeof("HTTP_ENV_VARS")-1 ELS_CC); php_info_print_table_end(); } if (flag & PHP_INFO_LICENSE) { SECTION("PHP License"); php_info_print_box_start(0); PUTS("<P>\n"); PUTS("This program is free software; you can redistribute it and/or modify "); PUTS("it under the terms of the PHP License as published by the PHP Group "); PUTS("and included in the distribution in the file: LICENSE\n"); PUTS("</P>\n"); PUTS("<P>"); PUTS("This program is distributed in the hope that it will be useful, "); PUTS("but WITHOUT ANY WARRANTY; without even the implied warranty of "); PUTS("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); PUTS("</P>\n"); PUTS("<P>"); PUTS("If you did not receive a copy of the PHP license, or have any questions about "); PUTS("PHP licensing, please contact [email protected].\n"); PUTS("</P>\n"); php_info_print_box_end(); } PUTS("</BODY></HTML>"); }