jani            Fri Nov  9 16:27:43 2007 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src    NEWS 
    /php-src/ext/standard       dl.c dl.h 
    /php-src/main       php_ini.c php_ini.h 
    /php-src/sapi/cgi   cgi_main.c 
  Log:
  MFH:- Added support for [HOST=www.example.com] special sections
  MFH:- Allowed using full path to load modules using "extension" directive
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.45&r2=1.2027.2.547.2.965.2.46&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.45 
php-src/NEWS:1.2027.2.547.2.965.2.46
--- php-src/NEWS:1.2027.2.547.2.965.2.45        Thu Nov  8 19:54:19 2007
+++ php-src/NEWS        Fri Nov  9 16:27:42 2007
@@ -25,10 +25,11 @@
 
 - Improved php.ini handling: (Jani)
   . Added ".htaccess" style user-defined php.ini files support for CGI/FastCGI
-  . Added support for special [PATH=/opt/httpd/www.example.com/] sections
-    All directives set in these sections will not be able to be overridden
-    in user-defined ini-files or during runtime in the specified path
+  . Added support for special [PATH=/opt/httpd/www.example.com/] and 
+    [HOST=www.example.com] sections. Directives set in these sections can
+    not be overridden by user-defined ini-files or during runtime.
   . Added better error reporting for php.ini syntax errors
+  . Allowed using full path to load modules using "extension" directive
   . Allowed "ini-variables" to be used almost everywhere ini php.ini files
   . Allowed using alphanumeric/variable indexes in "array" ini options
   . Added 3rd optional parameter to parse_ini_file() to specify the scanning
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/dl.c?r1=1.106.2.1.2.5.2.2&r2=1.106.2.1.2.5.2.3&diff_format=u
Index: php-src/ext/standard/dl.c
diff -u php-src/ext/standard/dl.c:1.106.2.1.2.5.2.2 
php-src/ext/standard/dl.c:1.106.2.1.2.5.2.3
--- php-src/ext/standard/dl.c:1.106.2.1.2.5.2.2 Fri Nov  9 13:49:15 2007
+++ php-src/ext/standard/dl.c   Fri Nov  9 16:27:42 2007
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dl.c,v 1.106.2.1.2.5.2.2 2007/11/09 13:49:15 jani Exp $ */
+/* $Id: dl.c,v 1.106.2.1.2.5.2.3 2007/11/09 16:27:42 jani Exp $ */
 
 #include "php.h"
 #include "dl.h"
@@ -77,10 +77,10 @@
                (strncmp(sapi_module.name, "embed", 5) != 0)
        ) {
 #ifdef ZTS
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not supported in 
multithreaded Web servers - use extension=%s in your php.ini", 
Z_STRVAL_PP(file));
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not supported in 
multithreaded Web servers - use extension=%s in your php.ini", 
Z_STRVAL_P(filename));
                RETURN_FALSE;
 #else
-               php_error_docref(NULL TSRMLS_CC, E_STRICT, "dl() is deprecated 
- use extension=%s in your php.ini", Z_STRVAL_PP(file));
+               php_error_docref(NULL TSRMLS_CC, E_STRICT, "dl() is deprecated 
- use extension=%s in your php.ini", Z_STRVAL_P(filename));
 #endif
        }
 
@@ -97,9 +97,7 @@
 #define USING_ZTS 0
 #endif
 
-/* {{{ php_dl
- */
-void php_dl(zval *file, int type, zval *return_value, int start_now TSRMLS_DC)
+PHPAPI int php_load_extension(char *filename, int type, int start_now 
TSRMLS_DC) /* {{{ */
 {
        void *handle;
        char *libpath;
@@ -107,8 +105,6 @@
        zend_module_entry *(*get_module)(void);
        int error_type;
        char *extension_dir;
-       char *filename;
-       int filename_len;
 
        if (type == MODULE_PERSISTENT) {
                extension_dir = INI_STR("extension_dir");
@@ -122,18 +118,16 @@
                error_type = E_CORE_WARNING;
        }
 
-       filename = Z_STRVAL_P(file);
-       filename_len = Z_STRLEN_P(file);
-
-       if (extension_dir && extension_dir[0]){
-               int extension_dir_len = strlen(extension_dir);
-
+       /* Check if passed filename contains directory separators */
+       if (strchr(filename, '/') != NULL || strchr(filename, DEFAULT_SLASH) != 
NULL) {
+               /* Passing modules with full path is not supported for 
dynamically loaded extensions */
                if (type == MODULE_TEMPORARY) {
-                       if (strchr(filename, '/') != NULL || strchr(filename, 
DEFAULT_SLASH) != NULL) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"Temporary module name should contain only filename");
-                               RETURN_FALSE;
-                       }
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Temporary 
module name should contain only filename");
+                       return FAILURE;
                }
+               libpath = estrdup(filename);
+       } else if (extension_dir && extension_dir[0]) {
+               int extension_dir_len = strlen(extension_dir);
 
                if (IS_SLASH(extension_dir[extension_dir_len-1])) {
                        spprintf(&libpath, 0, "%s%s", extension_dir, filename); 
/* SAFE */
@@ -141,7 +135,7 @@
                        spprintf(&libpath, 0, "%s%c%s", extension_dir, 
DEFAULT_SLASH, filename); /* SAFE */
                }
        } else {
-               libpath = estrndup(filename, filename_len);
+               return FAILURE; /* Not full path given or extension_dir is not 
set */
        }
 
        /* load dynamic symbol */
@@ -150,9 +144,8 @@
                php_error_docref(NULL TSRMLS_CC, error_type, "Unable to load 
dynamic library '%s' - %s", libpath, GET_DL_ERROR());
                GET_DL_ERROR(); /* free the buffer storing the error */
                efree(libpath);
-               RETURN_FALSE;
+               return FAILURE;
        }
-
        efree(libpath);
 
        get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, 
"get_module");
@@ -167,8 +160,8 @@
 
        if (!get_module) {
                DL_UNLOAD(handle);
-               php_error_docref(NULL TSRMLS_CC, error_type, "Invalid library 
(maybe not a PHP library) '%s' ", filename);
-               RETURN_FALSE;
+               php_error_docref(NULL TSRMLS_CC, error_type, "Invalid library 
(maybe not a PHP library) '%s'", filename);
+               return FAILURE;
        }
        module_entry = get_module();
        if ((module_entry->zend_debug != ZEND_DEBUG) ||
@@ -222,7 +215,7 @@
                                        name, zend_api, zend_debug, zts,
                                        ZEND_MODULE_API_NO, ZEND_DEBUG, 
USING_ZTS);
                        DL_UNLOAD(handle);
-                       RETURN_FALSE;
+                       return FAILURE;
        }
        module_entry->type = type;
        module_entry->module_number = zend_next_free_module();
@@ -230,22 +223,39 @@
 
        if ((module_entry = zend_register_module_ex(module_entry TSRMLS_CC)) == 
NULL) {
                DL_UNLOAD(handle);
-               RETURN_FALSE;
+               return FAILURE;
        }
 
        if ((type == MODULE_TEMPORARY || start_now) && 
zend_startup_module_ex(module_entry TSRMLS_CC) == FAILURE) {
                DL_UNLOAD(handle);
-               RETURN_FALSE;
+               return FAILURE;
        }
 
        if ((type == MODULE_TEMPORARY || start_now) && 
module_entry->request_startup_func) {
                if (module_entry->request_startup_func(type, 
module_entry->module_number TSRMLS_CC) == FAILURE) {
                        php_error_docref(NULL TSRMLS_CC, error_type, "Unable to 
initialize module '%s'", module_entry->name);
                        DL_UNLOAD(handle);
-                       RETURN_FALSE;
+                       return FAILURE;
                }
        }
-       RETURN_TRUE;
+       return SUCCESS;
+}
+/* }}} */
+
+/* {{{ php_dl
+ */
+PHPAPI void php_dl(zval *file, int type, zval *return_value, int start_now 
TSRMLS_DC)
+{
+       char *filename;
+
+       filename = Z_STRVAL_P(file);
+
+       /* Load extension */
+       if (php_load_extension(filename, type, start_now TSRMLS_CC) == FAILURE) 
{
+               RETVAL_FALSE;
+       } else {
+               RETVAL_TRUE;
+       }
 }
 /* }}} */
 
@@ -256,7 +266,7 @@
 
 #else
 
-void php_dl(zval *file, int type, zval *return_value, int start_now TSRMLS_DC)
+PHPAPI void php_dl(zval *file, int type, zval *return_value, int start_now 
TSRMLS_DC)
 {
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot dynamically load %s 
- dynamic modules are not supported", Z_STRVAL_P(file));
        RETURN_FALSE;
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/dl.h?r1=1.23.2.1.2.1&r2=1.23.2.1.2.1.2.1&diff_format=u
Index: php-src/ext/standard/dl.h
diff -u php-src/ext/standard/dl.h:1.23.2.1.2.1 
php-src/ext/standard/dl.h:1.23.2.1.2.1.2.1
--- php-src/ext/standard/dl.h:1.23.2.1.2.1      Mon Jan  1 09:36:08 2007
+++ php-src/ext/standard/dl.h   Fri Nov  9 16:27:43 2007
@@ -18,11 +18,12 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dl.h,v 1.23.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */
+/* $Id: dl.h,v 1.23.2.1.2.1.2.1 2007/11/09 16:27:43 jani Exp $ */
 
 #ifndef DL_H
 #define DL_H
 
+PHPAPI int php_load_extension(char *filename, int type, int start_now 
TSRMLS_DC);
 PHPAPI void php_dl(zval *file,int type, zval *return_value, int start_now 
TSRMLS_DC);
 
 /* dynamic loading functions */
http://cvs.php.net/viewvc.cgi/php-src/main/php_ini.c?r1=1.136.2.4.2.15.2.3&r2=1.136.2.4.2.15.2.4&diff_format=u
Index: php-src/main/php_ini.c
diff -u php-src/main/php_ini.c:1.136.2.4.2.15.2.3 
php-src/main/php_ini.c:1.136.2.4.2.15.2.4
--- php-src/main/php_ini.c:1.136.2.4.2.15.2.3   Sun Oct  7 05:22:07 2007
+++ php-src/main/php_ini.c      Fri Nov  9 16:27:43 2007
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_ini.c,v 1.136.2.4.2.15.2.3 2007/10/07 05:22:07 davidw Exp $ */
+/* $Id: php_ini.c,v 1.136.2.4.2.15.2.4 2007/11/09 16:27:43 jani Exp $ */
 
 #include "php.h"
 #include "ext/standard/info.h"
@@ -47,6 +47,7 @@
 } php_extension_lists;
 
 /* True globals */
+static int is_special_section = 0;
 static HashTable *active_ini_hash;
 static HashTable configuration_hash;
 PHPAPI char *php_ini_opened_path=NULL;
@@ -148,6 +149,7 @@
 /* }}} */
 
 /* php.ini support */
+#define PHP_EXTENSION_TOKEN            "extension"
 #ifdef ZTS
 # if (ZEND_DEBUG)
 # define ZEND_EXTENSION_TOKEN  "zend_extension_debug_ts"
@@ -185,6 +187,7 @@
 {
        zval *entry;
        HashTable *active_hash;
+       char *extension_name;
 
        if (active_ini_hash) {
                active_hash = active_ini_hash;
@@ -199,19 +202,12 @@
                                        break;
                                }
 
-/* FIXME: Should the extension loading be disabled for PATH sections? */
-
                                /* PHP and Zend extensions are not added into 
configuration hash! */
-                               if (!strcasecmp(Z_STRVAL_P(arg1), "extension")) 
{ /* load function module */
-                                       zval copy;
-
-                                       copy = *arg2;
-                                       zval_copy_ctor(&copy);
-                                       Z_SET_REFCOUNT(copy, 0);
-                                       
zend_llist_add_element(&extension_lists.functions, &copy);
-                               } else if (!strcasecmp(Z_STRVAL_P(arg1), 
ZEND_EXTENSION_TOKEN)) { /* load Zend extension */
-                                       char *extension_name = 
estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2));
-
+                               if (!is_special_section && 
!strcasecmp(Z_STRVAL_P(arg1), PHP_EXTENSION_TOKEN)) { /* load PHP extension */
+                                       extension_name = 
estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2));
+                                       
zend_llist_add_element(&extension_lists.functions, &extension_name);
+                               } else if (!is_special_section && 
!strcasecmp(Z_STRVAL_P(arg1), ZEND_EXTENSION_TOKEN)) { /* load Zend extension */
+                                       extension_name = 
estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2));
                                        
zend_llist_add_element(&extension_lists.engine, &extension_name);
 
                                /* All other entries are added into either 
configuration_hash or active ini section array */
@@ -262,18 +258,21 @@
                                char *key = NULL;
                                uint key_len;
 
-                               /* Only PATH sections are handled here! */
+                               /* PATH sections */
                                if (!strncasecmp(Z_STRVAL_P(arg1), "PATH", 
sizeof("PATH") - 1)) {
                                        key = Z_STRVAL_P(arg1);
                                        key = key + sizeof("PATH") - 1;
                                        key_len = Z_STRLEN_P(arg1) - 
sizeof("PATH") + 1;
+                                       is_special_section = 1;
 
-#if 0 /* Disable HOST sections for now. If someone can come up with some good 
usage case, then I can reconsider :) */
+                               /* HOST sections */
                                } else if (!strncasecmp(Z_STRVAL_P(arg1), 
"HOST", sizeof("HOST") - 1)) {
                                        key = Z_STRVAL_P(arg1);
                                        key = key + sizeof("HOST") - 1;
                                        key_len = Z_STRLEN_P(arg1) - 
sizeof("HOST") + 1;
-#endif
+                                       is_special_section = 1;
+                               } else {
+                                       is_special_section = 0;
                                }
 
                                if (key && key_len > 0) {
@@ -313,14 +312,11 @@
 }
 /* }}} */
 
-/* {{{ php_load_function_extension_cb
+/* {{{ php_load_php_extension_cb
  */
-static void php_load_function_extension_cb(void *arg TSRMLS_DC)
+static void php_load_php_extension_cb(void *arg TSRMLS_DC)
 {
-       zval *extension = (zval *) arg;
-       zval zval;
-
-       php_dl(extension, MODULE_PERSISTENT, &zval, 0 TSRMLS_CC);
+       php_load_extension(*((char **) arg), MODULE_PERSISTENT, 0 TSRMLS_CC);
 }
 /* }}} */
 
@@ -352,7 +348,7 @@
        }
 
        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(&extension_lists.functions, sizeof(zval), 
(llist_dtor_func_t) free_estring, 1);
 
        safe_mode_state = PG(safe_mode);
        open_basedir = PG(open_basedir);
@@ -682,7 +678,7 @@
 void php_ini_register_extensions(TSRMLS_D)
 {
        zend_llist_apply(&extension_lists.engine, php_load_zend_extension_cb 
TSRMLS_CC);
-       zend_llist_apply(&extension_lists.functions, 
php_load_function_extension_cb TSRMLS_CC);
+       zend_llist_apply(&extension_lists.functions, php_load_php_extension_cb 
TSRMLS_CC);
 
        zend_llist_destroy(&extension_lists.engine);
        zend_llist_destroy(&extension_lists.functions);
@@ -764,6 +760,21 @@
 }
 /* }}} */
 
+/* {{{ php_ini_activate_per_host_config
+ */
+PHPAPI void php_ini_activate_per_host_config(char *host, uint host_len 
TSRMLS_DC)
+{
+       zval *tmp;
+
+       if (host && host_len) {
+               /* Search for source array matching the host from 
configuration_hash */
+               if (zend_hash_find(&configuration_hash, host, host_len, (void 
**) &tmp) == SUCCESS) {
+                       php_ini_activate_config(Z_ARRVAL_P(tmp), 
PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE TSRMLS_CC);
+               }
+       }
+}
+/* }}} */
+
 /* {{{ cfg_get_entry
  */
 PHPAPI zval *cfg_get_entry(char *name, uint name_length)
http://cvs.php.net/viewvc.cgi/php-src/main/php_ini.h?r1=1.45.2.3.2.3.2.2&r2=1.45.2.3.2.3.2.3&diff_format=u
Index: php-src/main/php_ini.h
diff -u php-src/main/php_ini.h:1.45.2.3.2.3.2.2 
php-src/main/php_ini.h:1.45.2.3.2.3.2.3
--- php-src/main/php_ini.h:1.45.2.3.2.3.2.2     Fri Sep 28 10:23:38 2007
+++ php-src/main/php_ini.h      Fri Nov  9 16:27:43 2007
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_ini.h,v 1.45.2.3.2.3.2.2 2007/09/28 10:23:38 jani Exp $ */
+/* $Id: php_ini.h,v 1.45.2.3.2.3.2.3 2007/11/09 16:27:43 jani Exp $ */
 
 #ifndef PHP_INI_H
 #define PHP_INI_H
@@ -35,6 +35,7 @@
 PHPAPI int php_parse_user_ini_file(char *dirname, char *ini_filename, 
HashTable *target_hash TSRMLS_DC);
 PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, 
int stage TSRMLS_DC);
 PHPAPI void php_ini_activate_per_dir_config(char *path, uint path_len 
TSRMLS_DC);
+PHPAPI void php_ini_activate_per_host_config(char *host, uint host_len 
TSRMLS_DC);
 #if ZEND_DEBUG
 PHPAPI HashTable get_configuration_hash(void);
 #endif
http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.267.2.15.2.50.2.8&r2=1.267.2.15.2.50.2.9&diff_format=u
Index: php-src/sapi/cgi/cgi_main.c
diff -u php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.50.2.8 
php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.50.2.9
--- php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.50.2.8     Thu Nov  1 11:12:33 2007
+++ php-src/sapi/cgi/cgi_main.c Fri Nov  9 16:27:43 2007
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: cgi_main.c,v 1.267.2.15.2.50.2.8 2007/11/01 11:12:33 dmitry Exp $ */
+/* $Id: cgi_main.c,v 1.267.2.15.2.50.2.9 2007/11/09 16:27:43 jani Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -702,7 +702,7 @@
 
 static int sapi_cgi_activate(TSRMLS_D)
 {
-       char *path, *doc_root;
+       char *path, *doc_root, *server_name;
        uint path_len, doc_root_len;
 
        /* PATH_TRANSLATED should be defined at this stage but better safe than 
sorry :) */
@@ -711,9 +711,10 @@
        }
 
        doc_root = sapi_cgibin_getenv("DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT") 
- 1 TSRMLS_CC);
+       server_name = sapi_cgibin_getenv("SERVER_NAME", sizeof("SERVER_NAME") - 
1 TSRMLS_CC);
 
-       /* DOCUMENT_ROOT should also be defined at this stage..but better check 
it anyway */
-       if (!doc_root) {
+       /* DOCUMENT_ROOT and SERVER_NAME should also be defined at this 
stage..but better check it anyway */
+       if (!doc_root || !server_name) {
                return FAILURE;
        }
        doc_root_len = strlen(doc_root);
@@ -736,6 +737,9 @@
        /* Activate per-dir-system-configuration defined in php.ini and stored 
into configuration_hash during startup */
        php_ini_activate_per_dir_config(path, path_len TSRMLS_CC); /* Note: for 
global settings sake we check from root to path */
 
+       /* Activate per-host-system-configuration defined in php.ini and stored 
into configuration_hash during startup */
+       php_ini_activate_per_host_config(server_name, strlen(server_name) + 1 
TSRMLS_CC);
+
        /* Load and activate user ini files in path starting from DOCUMENT_ROOT 
*/
        if (strlen(PG(user_ini_filename))) {
                php_cgi_ini_activate_user_config(path, path_len, doc_root_len - 
1 TSRMLS_CC);

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to