fat                                      Fri, 23 Apr 2010 16:05:52 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=298383

Log:
Add PHP_VALUE and PHP_ADMIN_VALUE interpretation from fastcgi headers.
It works as php_value and php_admin_value from the main conf file or apache 
sapi.

See bug (request) #51595

Bug: http://bugs.php.net/51595 (Open) passing ini settings via FASTCGI 
parameters
      
Changed paths:
    U   php/php-src/trunk/sapi/fpm/fpm/fpm_main.c

Modified: php/php-src/trunk/sapi/fpm/fpm/fpm_main.c
===================================================================
--- php/php-src/trunk/sapi/fpm/fpm/fpm_main.c   2010-04-23 15:52:45 UTC (rev 
298382)
+++ php/php-src/trunk/sapi/fpm/fpm/fpm_main.c   2010-04-23 16:05:52 UTC (rev 
298383)
@@ -27,6 +27,10 @@
 #include "php_globals.h"
 #include "php_variables.h"
 #include "zend_modules.h"
+#include "php.h"
+#include "zend_ini_scanner.h"
+#include "zend_globals.h"
+#include "zend_stream.h"

 #include "SAPI.h"

@@ -103,6 +107,8 @@
 #include <fpm/fpm.h>
 #include <fpm/fpm_request.h>
 #include <fpm/fpm_status.h>
+#include <fpm/fpm_conf.h>
+#include <fpm/fpm_php.h>

 #ifndef PHP_WIN32
 /* XXX this will need to change later when threaded fastcgi is implemented.  
shane */
@@ -123,6 +129,7 @@
 static int request_body_fd;

 static char *sapi_cgibin_getenv(char *name, size_t name_len TSRMLS_DC);
+static void fastcgi_ini_parser(zval *arg1, zval *arg2, zval *arg3, int 
callback_type, void *arg TSRMLS_DC);

 #define PHP_MODE_STANDARD      1
 #define PHP_MODE_HIGHLIGHT     2
@@ -1070,6 +1077,7 @@
        char *env_script_filename = sapi_cgibin_getenv("SCRIPT_FILENAME", 
sizeof("SCRIPT_FILENAME")-1 TSRMLS_CC);
        char *env_path_translated = sapi_cgibin_getenv("PATH_TRANSLATED", 
sizeof("PATH_TRANSLATED")-1 TSRMLS_CC);
        char *script_path_translated = env_script_filename;
+       char *ini;

        /* some broken servers do not have script_filename or argv0
         * an example, IIS configured in some ways.  then they do more
@@ -1354,9 +1362,61 @@
                auth = sapi_cgibin_getenv("HTTP_AUTHORIZATION", 
sizeof("HTTP_AUTHORIZATION")-1 TSRMLS_CC);
                php_handle_auth_data(auth TSRMLS_CC);
        }
+
+       /* INI stuff */
+       ini = sapi_cgibin_getenv("PHP_VALUE", sizeof("PHP_VALUE")-1 TSRMLS_CC);
+       if (ini) {
+               int mode = ZEND_INI_USER;
+               char *tmp;
+               spprintf(&tmp, 0, "%s\n", ini);
+               zend_parse_ini_string(tmp, 1, ZEND_INI_SCANNER_RAW, 
(zend_ini_parser_cb_t)fastcgi_ini_parser, &mode TSRMLS_CC);
+               efree(tmp);
+       }
+
+       ini = sapi_cgibin_getenv("PHP_ADMIN_VALUE", sizeof("PHP_ADMIN_VALUE")-1 
TSRMLS_CC);
+       if (ini) {
+               int mode = ZEND_INI_SYSTEM;
+               char *tmp;
+               spprintf(&tmp, 0, "%s\n", ini);
+               zend_parse_ini_string(tmp, 1, ZEND_INI_SCANNER_RAW, 
(zend_ini_parser_cb_t)fastcgi_ini_parser, &mode TSRMLS_CC);
+               efree(tmp);
+       }
 }
 /* }}} */

+static void fastcgi_ini_parser(zval *arg1, zval *arg2, zval *arg3, int 
callback_type, void *arg TSRMLS_DC) /* {{{ */
+{
+       int *mode = (int *)arg;
+       char *key = Z_STRVAL_P(arg1);
+       char *value = Z_STRVAL_P(arg2);
+       struct key_value_s kv;
+
+       if (!mode) return;
+
+       if (callback_type != ZEND_INI_PARSER_ENTRY) {
+               fprintf(stderr, "Passing INI directive through FastCGI: only 
classic entries are allowed\n");
+               return;
+       }
+
+       if (!key || strlen(key) < 1) {
+               fprintf(stderr, "Passing INI directive through FastCGI: empty 
key\n");
+               return;
+       }
+
+       if (!value || strlen(value) < 1) {
+               fprintf(stderr, "Passing INI directive through FastCGI: empty 
value for key '%s'\n", key);
+               return;
+       }
+
+       kv.key = key;
+       kv.value = value;
+       kv.next = NULL;
+       if (fpm_php_apply_defines_ex(&kv, *mode) == -1) {
+               fprintf(stderr, "Passing INI directive through FastCGI: unable 
to set '%s'\n", key);
+       }
+}
+/* }}} */
+
 PHP_INI_BEGIN()
        STD_PHP_INI_ENTRY("cgi.rfc2616_headers",     "0",  PHP_INI_ALL,    
OnUpdateBool,   rfc2616_headers, php_cgi_globals_struct, php_cgi_globals)
        STD_PHP_INI_ENTRY("cgi.nph",                 "0",  PHP_INI_ALL,    
OnUpdateBool,   nph, php_cgi_globals_struct, php_cgi_globals)

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

Reply via email to