summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/standard/info.c89
-rw-r--r--main/SAPI.h3
-rw-r--r--main/main.c27
-rw-r--r--main/php_ini.c109
-rw-r--r--sapi/cli/TODO5
-rw-r--r--sapi/cli/php_cli.c33
6 files changed, 134 insertions, 132 deletions
diff --git a/ext/standard/info.c b/ext/standard/info.c
index 18e674dbf1..dbc043df04 100644
--- a/ext/standard/info.c
+++ b/ext/standard/info.c
@@ -48,7 +48,7 @@ ZEND_EXTERN_MODULE_GLOBALS(mbstring)
ZEND_EXTERN_MODULE_GLOBALS(iconv)
#endif
-#define SECTION(name) if (PG(html_errors)) { \
+#define SECTION(name) if (!sapi_module.phpinfo_as_text) { \
PUTS("<h2>" name "</h2>\n"); \
} else { \
php_info_print_table_start(); \
@@ -66,7 +66,7 @@ static int _display_module_info(zend_module_entry *module, void *arg TSRMLS_DC)
int show_info_func = *((int *) arg);
if (show_info_func && module->info_func) {
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_printf("<h2><a name=\"module_%s\">%s</a></h2>\n", module->name, module->name);
} else {
php_info_print_table_start();
@@ -75,7 +75,7 @@ static int _display_module_info(zend_module_entry *module, void *arg TSRMLS_DC)
}
module->info_func(module TSRMLS_CC);
} else if (!show_info_func && !module->info_func) {
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_printf("<tr>");
php_printf("<td>");
php_printf("%s", module->name);
@@ -103,7 +103,7 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC)
&& (Z_TYPE_PP(data)==IS_ARRAY)) {
zend_hash_internal_pointer_reset(Z_ARRVAL_PP(data));
while (zend_hash_get_current_data(Z_ARRVAL_PP(data), (void **) &tmp) == SUCCESS) {
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
PUTS("<tr>");
PUTS("<td class=\"e\">");
@@ -114,7 +114,7 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC)
switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(data), &string_key, &string_len, &num_key, 0, NULL)) {
case HASH_KEY_IS_STRING:
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
elem_esc = php_info_html_esc(string_key TSRMLS_CC);
PUTS(elem_esc);
efree(elem_esc);
@@ -127,24 +127,24 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC)
break;
}
PUTS("\"]");
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
PUTS("</td><td class=\"v\">");
} else {
PUTS(" => ");
}
if (Z_TYPE_PP(tmp) == IS_ARRAY) {
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
PUTS("<pre>");
}
zend_print_zval_r(*tmp, 0);
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
PUTS("</pre>");
}
} else if (Z_TYPE_PP(tmp) != IS_STRING) {
tmp2 = **tmp;
zval_copy_ctor(&tmp2);
convert_to_string(&tmp2);
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
if (Z_STRLEN(tmp2) == 0) {
PUTS("<i>no value</i>");
} else {
@@ -157,7 +157,7 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC)
}
zval_dtor(&tmp2);
} else {
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
if (Z_STRLEN_PP(tmp) == 0) {
PUTS("<i>no value</i>");
} else {
@@ -169,7 +169,7 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC)
PUTS(Z_STRVAL_PP(tmp));
}
}
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
PUTS("</td></tr>\n");
} else {
PUTS("\n");
@@ -182,7 +182,7 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC)
/* {{{ php_info_print_style
*/
-void php_info_print_style(void)
+void php_info_print_style()
{
php_printf("<style type=\"text/css\"><!--\n");
php_info_print_css();
@@ -389,7 +389,7 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
the_time = time(NULL);
ta = php_localtime_r(&the_time, &tmbuf);
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_print_info_htmlhead(TSRMLS_C);
} else {
PUTS("phpinfo()\n");
@@ -401,11 +401,11 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
php_uname = php_get_uname('a');
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_info_print_box_start(1);
}
- if (expose_php && PG(html_errors)) {
+ if (expose_php && !sapi_module.phpinfo_as_text) {
PUTS("<a href=\"http://www.php.net/\"><img border=\"0\" src=\"");
if (SG(request_info).request_uri) {
PUTS(SG(request_info).request_uri);
@@ -417,7 +417,7 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
}
}
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_printf("<h1 class=\"p\">PHP Version %s</h1>\n", PHP_VERSION);
} else {
php_info_print_table_row(2, "PHP Version", PHP_VERSION);
@@ -506,7 +506,7 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
/* Zend Engine */
php_info_print_box_start(0);
- if (expose_php && PG(html_errors)) {
+ if (expose_php && !sapi_module.phpinfo_as_text) {
PUTS("<a href=\"http://www.zend.com/\"><img border=\"0\" src=\"");
if (SG(request_info).request_uri) {
PUTS(SG(request_info).request_uri);
@@ -514,7 +514,7 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
PUTS("?="ZEND_LOGO_GUID"\" alt=\"Zend logo\" /></a>\n");
}
PUTS("This program makes use of the Zend Scripting Language Engine:");
- PUTS(PG(html_errors)?"<br />":"\n");
+ PUTS(!sapi_module.phpinfo_as_text?"<br />":"\n");
if (PG(html_errors)) {
zend_html_puts(zend_version, strlen(zend_version) TSRMLS_CC);
} else {
@@ -524,7 +524,7 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
efree(php_uname);
}
- if ((flag & PHP_INFO_CREDITS) && expose_php && PG(html_errors)) {
+ if ((flag & PHP_INFO_CREDITS) && expose_php && !sapi_module.phpinfo_as_text) {
php_info_print_hr();
PUTS("<h1><a href=\"");
if (SG(request_info).request_uri) {
@@ -539,7 +539,7 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
if (flag & PHP_INFO_CONFIGURATION) {
php_info_print_hr();
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
PUTS("<h1>Configuration</h1>\n");
} else {
SECTION("Configuration");
@@ -618,7 +618,7 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
}
if (flag & PHP_INFO_LICENSE) {
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
SECTION("PHP License");
php_info_print_box_start(0);
PUTS("<p>\n");
@@ -650,7 +650,7 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
PUTS("questions about PHP licensing, please contact license@php.net.\n");
}
}
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
PUTS("</div></body></html>");
}
}
@@ -659,9 +659,7 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
PHPAPI void php_info_print_table_start()
{
- TSRMLS_FETCH();
-
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_printf("<table border=\"0\" cellpadding=\"3\" width=\"600\">\n");
} else {
php_printf("\n");
@@ -670,9 +668,7 @@ PHPAPI void php_info_print_table_start()
PHPAPI void php_info_print_table_end()
{
- TSRMLS_FETCH();
-
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_printf("</table><br />\n");
}
@@ -680,15 +676,13 @@ PHPAPI void php_info_print_table_end()
PHPAPI void php_info_print_box_start(int flag)
{
- TSRMLS_FETCH();
-
php_info_print_table_start();
if (flag) {
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_printf("<tr class=\"h\"><td>\n");
}
} else {
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_printf("<tr class=\"v\"><td>\n");
} else {
php_printf("\n");
@@ -698,9 +692,7 @@ PHPAPI void php_info_print_box_start(int flag)
PHPAPI void php_info_print_box_end()
{
- TSRMLS_FETCH();
-
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_printf("</td></tr>\n");
}
php_info_print_table_end();
@@ -708,9 +700,7 @@ PHPAPI void php_info_print_box_end()
PHPAPI void php_info_print_hr()
{
- TSRMLS_FETCH();
-
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_printf("<hr />\n");
} else {
php_printf("\n\n _______________________________________________________________________\n\n");
@@ -721,9 +711,7 @@ PHPAPI void php_info_print_table_colspan_header(int num_cols, char *header)
{
int spaces;
- TSRMLS_FETCH();
-
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_printf("<tr class=\"h\"><th colspan=\"%d\">%s</th></tr>\n", num_cols, header );
} else {
spaces = (74 - strlen(header));
@@ -742,7 +730,7 @@ PHPAPI void php_info_print_table_header(int num_cols, ...)
TSRMLS_FETCH();
va_start(row_elements, num_cols);
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_printf("<tr class=\"h\">");
}
for (i=0; i<num_cols; i++) {
@@ -750,7 +738,7 @@ PHPAPI void php_info_print_table_header(int num_cols, ...)
if (!row_element || !*row_element) {
row_element = " ";
}
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
PUTS("<th>");
PUTS(row_element);
PUTS("</th>");
@@ -763,7 +751,7 @@ PHPAPI void php_info_print_table_header(int num_cols, ...)
}
}
}
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_printf("</tr>\n");
}
@@ -786,24 +774,24 @@ PHPAPI void php_info_print_table_row(int num_cols, ...)
TSRMLS_FETCH();
va_start(row_elements, num_cols);
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_printf("<tr>");
}
for (i=0; i<num_cols; i++) {
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_printf("<td class=\"%s\">",
(i==0 ? "e" : "v" )
);
}
row_element = va_arg(row_elements, char *);
if (!row_element || !*row_element) {
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
PUTS( "<i>no value</i>" );
} else {
PUTS( " " );
}
} else {
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
elem_esc = php_info_html_esc(row_element TSRMLS_CC);
PUTS(elem_esc);
efree(elem_esc);
@@ -814,13 +802,13 @@ PHPAPI void php_info_print_table_row(int num_cols, ...)
}
}
}
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_printf(" </td>");
} else if (i == (num_cols - 1)) {
PUTS("\n");
}
}
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
php_printf("</tr>\n");
}
@@ -1003,3 +991,4 @@ PHP_FUNCTION(php_ini_scanned_files) {
* vim600: sw=4 ts=4 fdm=marker
* vim<600: sw=4 ts=4
*/
+
diff --git a/main/SAPI.h b/main/SAPI.h
index 75c80fae41..126776f34b 100644
--- a/main/SAPI.h
+++ b/main/SAPI.h
@@ -237,6 +237,9 @@ struct _sapi_module_struct {
int (*get_target_uid)(uid_t * TSRMLS_DC);
int (*get_target_gid)(gid_t * TSRMLS_DC);
+
+ void (*ini_defaults)(HashTable *configuration_hash);
+ int phpinfo_as_text;
};
diff --git a/main/main.c b/main/main.c
index 4e19a144b9..a0a6f3d66c 100644
--- a/main/main.c
+++ b/main/main.c
@@ -663,27 +663,10 @@ static void php_error_cb(int type, const char *error_filename, const uint error_
&& (!PG(during_request_startup) || PG(display_startup_errors))) {
char *prepend_string = INI_STR("error_prepend_string");
char *append_string = INI_STR("error_append_string");
- char *error_format;
-
- error_format = PG(html_errors) ?
- "<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n"
- : "\n%s: %s in %s on line %d\n";
- if (PG(xmlrpc_errors)) {
- error_format = do_alloca(ERROR_BUF_LEN);
- snprintf(error_format, ERROR_BUF_LEN-1, "<?xml version=\"1.0\"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>%ld</int></value></member><member><name>faultString</name><value><string>%%s:%%s in %%s on line %%d</string></value></member></struct></value></fault></methodResponse>", PG(xmlrpc_error_number));
- }
-
- if (prepend_string) {
- PUTS(prepend_string);
- }
- php_printf(error_format, error_type_str, buffer, error_filename, error_lineno);
- if (PG(xmlrpc_errors)) {
- free_alloca(error_format);
- }
-
- if (append_string) {
- PUTS(append_string);
- }
+ char *error_format = PG(html_errors) ?
+ "%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n%s"
+ : "%s\n%s: %s in %s on line %d\n%s";
+ php_printf(error_format, STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string));
}
#if ZEND_DEBUG
{
@@ -700,7 +683,7 @@ static void php_error_cb(int type, const char *error_filename, const uint error_
trigger_break=0;
break;
}
- zend_output_debug_string(trigger_break, "%s(%d) : %s - %s", error_filename, error_lineno, error_type_str, buffer);
+// zend_output_debug_string(trigger_break, "%s(%d) : %s - %s", error_filename, error_lineno, error_type_str, buffer);
}
#endif
}
diff --git a/main/php_ini.c b/main/php_ini.c
index dc15049944..2be3459577 100644
--- a/main/php_ini.c
+++ b/main/php_ini.c
@@ -63,34 +63,35 @@ static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type)
uint display_string_length, esc_html=0;
TSRMLS_FETCH();
- if (type==ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
+ if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
if (ini_entry->orig_value && ini_entry->orig_value[0]) {
display_string = ini_entry->orig_value;
display_string_length = ini_entry->orig_value_length;
- esc_html=1;
+ esc_html = !sapi_module.phpinfo_as_text;
} else {
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
display_string = "<i>no value</i>";
- display_string_length = sizeof("<i>no value</i>")-1;
+ display_string_length = sizeof("<i>no value</i>") - 1;
} else {
display_string = "no value";
- display_string_length = sizeof("no value")-1;
+ display_string_length = sizeof("no value") - 1;
}
}
} else if (ini_entry->value && ini_entry->value[0]) {
display_string = ini_entry->value;
display_string_length = ini_entry->value_length;
- esc_html=1;
+ esc_html = !sapi_module.phpinfo_as_text;
} else {
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
display_string = "<i>no value</i>";
- display_string_length = sizeof("<i>no value</i>")-1;
+ display_string_length = sizeof("<i>no value</i>") - 1;
} else {
display_string = "no value";
- display_string_length = sizeof("no value")-1;
+ display_string_length = sizeof("no value") - 1;
}
}
- if(esc_html) {
+
+ if (esc_html) {
php_html_puts(display_string, display_string_length TSRMLS_CC);
} else {
PHPWRITE(display_string, display_string_length);
@@ -106,17 +107,17 @@ static int php_ini_displayer(zend_ini_entry *ini_entry, int module_number TSRMLS
if (ini_entry->module_number != module_number) {
return 0;
}
- if (PG(html_errors)) {
+ if (!sapi_module.phpinfo_as_text) {
PUTS("<tr>");
PUTS("<td class=\"e\">");
- PHPWRITE(ini_entry->name, ini_entry->name_length-1);
+ PHPWRITE(ini_entry->name, ini_entry->name_length - 1);
PUTS("</td><td class=\"v\">");
php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE);
PUTS("</td><td class=\"v\">");
php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG);
PUTS("</td></tr>\n");
} else {
- PHPWRITE(ini_entry->name, ini_entry->name_length-1);
+ PHPWRITE(ini_entry->name, ini_entry->name_length - 1);
PUTS(" => ");
php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE);
PUTS(" => ");
@@ -166,9 +167,9 @@ PHPAPI void display_ini_entries(zend_module_entry *module)
*/
static void pvalue_config_destructor(zval *pvalue)
{
- if (Z_TYPE_P(pvalue) == IS_STRING && Z_STRVAL_P(pvalue) != empty_string) {
- free(Z_STRVAL_P(pvalue));
- }
+ if (Z_TYPE_P(pvalue) == IS_STRING && Z_STRVAL_P(pvalue) != empty_string) {
+ free(Z_STRVAL_P(pvalue));
+ }
}
/* }}} */
@@ -195,11 +196,12 @@ static void php_config_ini_parser_cb(zval *arg1, zval *arg2, int callback_type,
zend_llist_add_element(&extension_lists.engine, &extension_name);
} else {
- zend_hash_update(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, arg2, sizeof(zval), (void **) &entry);
+ zend_hash_update(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, arg2, sizeof(zval), (void **) &entry);
Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry));
}
}
break;
+
case ZEND_INI_PARSER_SECTION:
break;
}
@@ -243,10 +245,14 @@ int php_init_config()
zend_llist_element *element;
TSRMLS_FETCH();
- if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1)==FAILURE) {
+ if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1) == FAILURE) {
return FAILURE;
}
+ if (sapi_module.ini_defaults) {
+ sapi_module.ini_defaults(&configuration_hash);
+ }
+
zend_llist_init(&extension_lists.engine, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
zend_llist_init(&extension_lists.functions, sizeof(zval), (llist_dtor_func_t) ZVAL_DESTRUCTOR, 1);
zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
@@ -256,7 +262,7 @@ int php_init_config()
env_location = getenv("PHPRC");
if (!env_location) {
- env_location="";
+ env_location = "";
}
if (sapi_module.php_ini_path_override) {
php_ini_search_path = sapi_module.php_ini_path_override;
@@ -265,7 +271,7 @@ int php_init_config()
char *default_location;
static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 };
- php_ini_search_path = (char *) emalloc(MAXPATHLEN*3+strlen(env_location)+3+1);
+ php_ini_search_path = (char *) emalloc(MAXPATHLEN * 3 + strlen(env_location) + 3 + 1);
free_ini_search_path = 1;
php_ini_search_path[0] = 0;
@@ -283,7 +289,7 @@ int php_init_config()
/* Add cwd */
#ifdef INI_CHECK_CWD
- if (strcmp(sapi_module.name, "cli")!=0) {
+ if (strcmp(sapi_module.name, "cli") != 0) {
if (*php_ini_search_path) {
strcat(php_ini_search_path, paths_separator);
}
@@ -294,7 +300,7 @@ int php_init_config()
/* Add binary directory */
#ifdef PHP_WIN32
binary_location = (char *) emalloc(MAXPATHLEN);
- if (GetModuleFileName(0, binary_location, MAXPATHLEN)==0) {
+ if (GetModuleFileName(0, binary_location, MAXPATHLEN) == 0) {
efree(binary_location);
binary_location = NULL;
}
@@ -320,7 +326,7 @@ int php_init_config()
/* Add default location */
#ifdef PHP_WIN32
- default_location = (char *) emalloc(MAXPATHLEN+1);
+ default_location = (char *) emalloc(MAXPATHLEN + 1);
if (0 < GetWindowsDirectory(default_location, MAXPATHLEN)) {
if (*php_ini_search_path) {
@@ -341,7 +347,7 @@ int php_init_config()
PG(safe_mode) = 0;
PG(open_basedir) = NULL;
- fh.handle.fp = NULL;
+ memset(&fh, 0, sizeof(fh));
/* Check if php_ini_path_override is a file */
if (!sapi_module.php_ini_ignore) {
if (sapi_module.php_ini_path_override && sapi_module.php_ini_path_override[0]) {
@@ -357,7 +363,7 @@ int php_init_config()
/* Search php-%sapi-module-name%.ini file in search path */
if (!fh.handle.fp) {
const char *fmt = "php-%s.ini";
- char *ini_fname=emalloc(strlen(fmt)+strlen(sapi_module.name));
+ char *ini_fname = emalloc(strlen(fmt) + strlen(sapi_module.name));
sprintf(ini_fname, fmt, sapi_module.name);
fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
efree(ini_fname);
@@ -373,9 +379,11 @@ int php_init_config()
}
}
}
+
if (free_ini_search_path) {
efree(php_ini_search_path);
}
+
PG(safe_mode) = safe_mode_state;
PG(open_basedir) = open_basedir;
@@ -391,8 +399,9 @@ int php_init_config()
Z_STRVAL(tmp) = zend_strndup(fh.filename, Z_STRLEN(tmp));
Z_TYPE(tmp) = IS_STRING;
zend_hash_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path"), (void *) &tmp, sizeof(zval), NULL);
- if(php_ini_opened_path)
+ if (php_ini_opened_path) {
efree(php_ini_opened_path);
+ }
php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
}
}
@@ -400,17 +409,17 @@ int php_init_config()
/* If the config_file_scan_dir is set at compile-time, go and scan this directory and
* parse any .ini files found in this directory. */
if (!sapi_module.php_ini_ignore && strlen(PHP_CONFIG_FILE_SCAN_DIR)) {
- struct dirent **namelist;
- int ndir, i;
-
- if ((ndir = php_scandir(PHP_CONFIG_FILE_SCAN_DIR, &namelist, 0, php_alphasort)) > 0) {
- for (i = 0; i < ndir; i++) {
- /* check for a .ini extension */
- if (!(p = strrchr(namelist[i]->d_name, '.')) || (p && strcmp(p, ".ini"))) {
- free(namelist[i]);
- continue;
- }
- snprintf(ini_file, MAXPATHLEN, "%s%c%s", PHP_CONFIG_FILE_SCAN_DIR, DEFAULT_SLASH, namelist[i]->d_name);
+ struct dirent **namelist;
+ int ndir, i;
+
+ if ((ndir = php_scandir(PHP_CONFIG_FILE_SCAN_DIR, &namelist, 0, php_alphasort)) > 0) {
+ for (i = 0; i < ndir; i++) {
+ /* check for a .ini extension */
+ if (!(p = strrchr(namelist[i]->d_name, '.')) || (p && strcmp(p, ".ini"))) {
+ free(namelist[i]);
+ continue;
+ }
+ snprintf(ini_file, MAXPATHLEN, "%s%c%s", PHP_CONFIG_FILE_SCAN_DIR, DEFAULT_SLASH, namelist[i]->d_name);
if (VCWD_STAT(ini_file, &sb) == 0) {
if (S_ISREG(sb.st_mode)) {
if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
@@ -419,8 +428,8 @@ int php_init_config()
zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists);
/* Here, add it to the list of ini files read */
l = strlen(ini_file);
- total_l += l+2;
- p = estrndup(ini_file,l);
+ total_l += l + 2;
+ p = estrndup(ini_file, l);
zend_llist_add_element(&scanned_ini_list, &p);
}
}
@@ -433,11 +442,11 @@ int php_init_config()
* Don't need an extra byte for the \0 in this malloc as the last
* element will not get a trailing , which gives us the byte for the \0
*/
- php_ini_scanned_files = (char *)malloc(total_l);
+ php_ini_scanned_files = (char *) malloc(total_l);
*php_ini_scanned_files = '\0';
- for (element=scanned_ini_list.head; element; element=element->next) {
- strcat(php_ini_scanned_files,*(char **)element->data);
- strcat(php_ini_scanned_files,element->next ? ",\n":"\n");
+ for (element = scanned_ini_list.head; element; element = element->next) {
+ strcat(php_ini_scanned_files, *(char **)element->data);
+ strcat(php_ini_scanned_files, element->next ? ",\n" : "\n");
}
zend_llist_destroy(&scanned_ini_list);
}
@@ -479,7 +488,7 @@ zval *cfg_get_entry(char *name, uint name_length)
{
zval *tmp;
- if (zend_hash_find(&configuration_hash, name, name_length, (void **) &tmp)==SUCCESS) {
+ if (zend_hash_find(&configuration_hash, name, name_length, (void **) &tmp) == SUCCESS) {
return tmp;
} else {
return NULL;
@@ -493,8 +502,8 @@ PHPAPI int cfg_get_long(char *varname, long *result)
{
zval *tmp, var;
- if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp)==FAILURE) {
- *result=(long)NULL;
+ if (zend_hash_find(&configuration_hash, varname, strlen(varname) + 1, (void **) &tmp) == FAILURE) {
+ *result = (long) NULL;
return FAILURE;
}
var = *tmp;
@@ -511,8 +520,8 @@ PHPAPI int cfg_get_double(char *varname, double *result)
{
zval *tmp, var;
- if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp)==FAILURE) {
- *result=(double)0;
+ if (zend_hash_find(&configuration_hash, varname, strlen(varname) + 1, (void **) &tmp) == FAILURE) {
+ *result = (double) 0;
return FAILURE;
}
var = *tmp;
@@ -529,8 +538,8 @@ PHPAPI int cfg_get_string(char *varname, char **result)
{
zval *tmp;
- if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp)==FAILURE) {
- *result=NULL;
+ if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp) == FAILURE) {
+ *result = NULL;
return FAILURE;
}
*result = Z_STRVAL_P(tmp);
diff --git a/sapi/cli/TODO b/sapi/cli/TODO
index ccb980f459..bc60bf4b01 100644
--- a/sapi/cli/TODO
+++ b/sapi/cli/TODO
@@ -1,6 +1 @@
TODO:
-
-- plain text "php -i" and phpinfo()
-- fix the so called CLI defaults set by zend_alter_ini_entry() in php_ini.c.
- They currently cannot be set within the PHP.INI file but can be with the -d
- command line switch and during runtime.
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
index 5c4f4e83af..deb5ddba91 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -248,6 +248,29 @@ static int php_cli_startup(sapi_module_struct *sapi_module)
}
+/* {{{ sapi_cli_ini_defaults */
+
+#define INI_DEFAULT(name,value)\
+ ZVAL_STRING(tmp, value, 0);\
+ zend_hash_update(configuration_hash, name, sizeof(name), tmp, sizeof(zval), (void**)&entry);\
+ Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry))
+
+static void sapi_cli_ini_defaults(HashTable *configuration_hash)
+{
+ zval *tmp, *entry;
+
+ MAKE_STD_ZVAL(tmp);
+
+ INI_DEFAULT("register_argc_argv", "1");
+ INI_DEFAULT("html_errors", "0");
+ INI_DEFAULT("display_errors", "1");
+ INI_DEFAULT("implicit_flush", "1");
+ INI_DEFAULT("max_execution_time", "0");
+
+ FREE_ZVAL(tmp);
+}
+/* }}} */
+
/* {{{ sapi_module_struct cli_sapi_module
*/
static sapi_module_struct cli_sapi_module = {
@@ -444,6 +467,8 @@ int main(int argc, char *argv[])
tsrm_startup(1, 1, 0, NULL);
#endif
+ cli_sapi_module.ini_defaults = sapi_cli_ini_defaults;
+ cli_sapi_module.phpinfo_as_text = 1;
sapi_startup(&cli_sapi_module);
#ifdef PHP_WIN32
@@ -510,10 +535,8 @@ int main(int argc, char *argv[])
/* Set some CLI defaults */
SG(options) |= SAPI_OPTION_NO_CHDIR;
- zend_alter_ini_entry("register_argc_argv", 19, "1", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
- zend_alter_ini_entry("html_errors", 12, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
- zend_alter_ini_entry("implicit_flush", 15, "1", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
- zend_alter_ini_entry("max_execution_time", 19, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
+ /* here is the place for hard coded defaults which cannot be overwritten in the ini file */
+ /*zend_alter_ini_entry("<name>", len, "<value>", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);*/
zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */
@@ -745,6 +768,7 @@ int main(int argc, char *argv[])
zend_llist_apply(&global_vars, (llist_apply_func_t) php_register_command_line_global_vars TSRMLS_CC);
zend_llist_destroy(&global_vars);
+ PG(during_request_startup) = 0;
switch (behavior) {
case PHP_MODE_STANDARD:
if (strcmp(file_handle.filename, "-")) {
@@ -754,7 +778,6 @@ int main(int argc, char *argv[])
exit_status = EG(exit_status);
break;
case PHP_MODE_LINT:
- PG(during_request_startup) = 0;
exit_status = php_lint_script(&file_handle TSRMLS_CC);
if (exit_status==SUCCESS) {
zend_printf("No syntax errors detected in %s\n", file_handle.filename);