]> granicus.if.org Git - php/commitdiff
- Make ISAPI hook in as an extension too.
authorAndi Gutmans <andi@php.net>
Sun, 2 May 1999 18:07:41 +0000 (18:07 +0000)
committerAndi Gutmans <andi@php.net>
Sun, 2 May 1999 18:07:41 +0000 (18:07 +0000)
- Some work on moving stuff to SAPI.

cgi_main.c
ext/hyperwave/hw.c
ext/standard/post.c
main.h
main/SAPI.c
main/SAPI.h
main/main.c
mod_php3.c
output.c
request_info.c
request_info.h

index 190d930ff9f9d5451e0eba4dca2ccd7205f88ac2..db3ecaac5753138b0d85617b79e71e434d5284f1 100644 (file)
@@ -76,8 +76,13 @@ static int zend_cgibin_ub_write(const char *str, uint str_length)
 }
 
 
-static sapi_functions_struct sapi_functions = {
-       zend_cgibin_ub_write
+static sapi_module_struct sapi_module = {
+       "PHP Language",                                 /* name */
+                                                                       
+       php_module_startup,                             /* startup */
+       php_module_shutdown_wrapper,    /* shutdown */
+
+       zend_cgibin_ub_write,                   /* unbuffered write */
 };
 
 
@@ -127,6 +132,7 @@ int main(int argc, char *argv[])
        zend_compiler_globals *compiler_globals;
        zend_executor_globals *executor_globals;
        php_core_globals *core_globals;
+       sapi_globals_struct *sapi_globals;
 #endif
 
 
@@ -135,7 +141,10 @@ int main(int argc, char *argv[])
                return -1;
        }
 #endif
-               
+
+       tsrm_startup(1,1,0);
+       sapi_startup(&sapi_module);
+
 #if WIN32|WINNT
        _fmode = _O_BINARY;                     /*sets default for file streams to binary */
        setmode(_fileno(stdin), O_BINARY);              /* make the stdio mode be binary */
@@ -178,13 +187,14 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
 #endif                                                 /* FORCE_CGI_REDIRECT */
        }
 
-       if (php_module_startup(&sapi_functions)==FAILURE) {
+       if (php_module_startup(&sapi_module)==FAILURE) {
                return FAILURE;
        }
 #ifdef ZTS
        compiler_globals = ts_resource(compiler_globals_id);
        executor_globals = ts_resource(executor_globals_id);
        core_globals = ts_resource(core_globals_id);
+       sapi_globals = ts_resource(sapi_globals_id);
 #endif
 
        CG(extended_info) = 0;
@@ -280,8 +290,10 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
 
        php3_TreatHeaders();
 
+       SG(request_info).query_string = getenv("QUERY_STRING");
+
        if (!cgi) {
-               if (!request_info.query_string) {
+               if (!SG(request_info).query_string) {
                        for (i = optind, len = 0; i < argc; i++)
                                len += strlen(argv[i]) + 1;
 
@@ -292,7 +304,7 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
                                if (i < (argc - 1))
                                        strcat(s, "+");
                        }
-                       request_info.query_string = s;
+                       SG(request_info).query_string = s;
                }
                if (!request_info.filename && argc > optind)
                        request_info.filename = argv[optind];
index 8ac6dbd0700017b3a84c6c1c3f532c44e8ef6332..8a813dde86b8ea06793f84578e72730f00327d78 100644 (file)
@@ -1533,7 +1533,7 @@ void php3_hw_getcgi(INTERNAL_FUNCTION_PARAMETERS) {
        sprintf(cgi_env_str, "CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s",
                             request_info.request_method,
                             request_info.path_info,
-                            request_info.query_string);
+                            SG(request_info).query_string);
 #endif
        /* !!!! memory for object and attributes is allocated with malloc !!!! */
        if (0 != (ptr->lasterror = send_getcgi(ptr->socket, id, cgi_env_str, &attributes, &object, &count)))
@@ -1785,7 +1785,7 @@ void php3_hw_pipecgi(INTERNAL_FUNCTION_PARAMETERS) {
        sprintf(cgi_env_str, "CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s",
                             request_info.request_method,
                             request_info.path_info,
-                            request_info.query_string);
+                            SG(request_info).query_string);
 #endif
        /* !!!! memory for object, bodytag and attributes is allocated with malloc !!!! */
        if (0 != (ptr->lasterror =  send_pipecgi(ptr->socket,
index 166c6799e7dcc525a876d83d8a4392dc3548bf23..009f37f08a96b9684c71bc681717a158e3aeaad2 100644 (file)
@@ -317,6 +317,7 @@ void php3_treat_data(int arg, char *str)
        pval *array_ptr;
        ELS_FETCH();
        PLS_FETCH();
+       SLS_FETCH();
        
        switch (arg) {
                case PARSE_POST:
@@ -350,7 +351,7 @@ void php3_treat_data(int arg, char *str)
        if (arg == PARSE_POST) {
                res = php3_getpost(array_ptr PLS_CC);
        } else if (arg == PARSE_GET) {          /* Get data */
-               var = request_info.query_string;
+               var = SG(request_info).query_string;
                if (var && *var) {
                        res = (char *) estrdup(var);
                }
diff --git a/main.h b/main.h
index d450ac598624f41c9660acd403559aceb12192d1..df3455c9c9b5904c8dce96c311d06755b32805e0 100644 (file)
--- a/main.h
+++ b/main.h
 PHPAPI int php_request_startup(CLS_D ELS_DC PLS_DC);
 PHPAPI void php_request_shutdown(void *dummy);
 PHPAPI void php_request_shutdown_for_exec(void *dummy);
-PHPAPI int php_module_startup(sapi_functions_struct *sf);
+PHPAPI int php_module_startup(sapi_module_struct *sf);
 PHPAPI void php_module_shutdown();
 PHPAPI void php_module_shutdown_for_exec(void);
+PHPAPI int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals);
 
 PHPAPI void php_execute_script(zend_file_handle *primary_file CLS_DC ELS_DC PLS_DC);
 
index 827bd2553f7742259edf6ea588e32bc001e3a032..bdb58baed4448400f0c084345e6ff5ab79411888 100644 (file)
@@ -11,11 +11,11 @@ sapi_globals_struct sapi_globals;
 #endif
 
 /* A true global (no need for thread safety) */
-sapi_functions_struct sapi_functions;
+sapi_module_struct sapi_module;
 
-void sapi_startup(sapi_functions_struct *sf)
+SAPI_API void sapi_startup(sapi_module_struct *sf)
 {
-       sapi_functions = *sf;
+       sapi_module = *sf;
 #ifdef ZTS
        sapi_globals_id = ts_allocate_id(sizeof(sapi_globals_struct), NULL, NULL);
 #endif
index bd62eaed76e24cf416d6e51709fea65b609e60fb..feddbc3bbc6f2bdc1168eee334dc77e43fce813a 100644 (file)
 #endif
 
 
-typedef struct {
+typedef struct _sapi_module_struct {
+       char *name;
+
+       int (*startup)(struct _sapi_module_struct *sapi_module);
+       int (*shutdown)(struct _sapi_module_struct *sapi_module);
+
        int (*ub_write)(const char *str, unsigned int str_length);
-} sapi_functions_struct;
+} sapi_module_struct;
+
 
-extern sapi_functions_struct sapi_functions;  /* true global */
+extern sapi_module_struct sapi_module;  /* true global */
+
+
+typedef struct {
+       char *path_translated;
+       char *query_string;
+} sapi_request_info;
 
 
 typedef struct {
        void *server_context;
+       sapi_request_info request_info;
 } sapi_globals_struct;
 
 
-void sapi_startup(sapi_functions_struct *sf);
+SAPI_API void sapi_startup(sapi_module_struct *sf);
 
 #ifdef ZTS
 # define SLS_D sapi_globals_struct *sapi_globals
index a4da4b9851580c67cd65721d1fd0c5b2bd468508..7bef2e8af1e537cbc13e4a3bae67aae265bf92ce 100644 (file)
@@ -755,7 +755,7 @@ static core_globals_ctor(php_core_globals *core_globals)
 #endif
 
 
-int php_module_startup(sapi_functions_struct *sf)
+int php_module_startup(sapi_module_struct *sf)
 {
        zend_utility_functions zuf;
        zend_utility_values zuv;
@@ -775,7 +775,7 @@ int php_module_startup(sapi_functions_struct *sf)
                return SUCCESS;
        }
 
-       sapi_functions = *sf;
+       sapi_module = *sf;
 
        zend_output_startup();
 
@@ -796,7 +796,6 @@ int php_module_startup(sapi_functions_struct *sf)
 #endif
 
        PG(header_is_being_sent) = 0;
-       sapi_startup(sf);
 
 #if HAVE_SETLOCALE
        setlocale(LC_CTYPE, "");
@@ -840,6 +839,14 @@ void php_module_shutdown_for_exec(void)
        /* used to close fd's in the range 3.255 here, but it's problematic */
 }
 
+
+int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals)
+{
+       php_module_shutdown();
+       return SUCCESS;
+}
+
+
 void php_module_shutdown()
 {
        int module_number=0;    /* for UNREGISTER_INI_ENTRIES() */
@@ -875,12 +882,12 @@ void php_module_shutdown()
 
 
 /* in 3.1 some of this should move into sapi */
-int _php3_hash_environment(PLS_D)
+int _php3_hash_environment(PLS_D ELS_DC)
 {
        char **env, *p, *t;
        unsigned char _gpc_flags[3] = {0,0,0};
        pval *tmp;
-       ELS_FETCH();
+       SLS_FETCH();
        
        p = PG(gpc_order);
        while(*p) {
@@ -1050,7 +1057,7 @@ int _php3_hash_environment(PLS_D)
 
 
        /* need argc/argv support as well */
-       _php3_build_argv(request_info.query_string ELS_CC);
+       _php3_build_argv(SG(request_info).query_string ELS_CC);
 
        return SUCCESS;
 }
@@ -1113,16 +1120,17 @@ PHPAPI void php_execute_script(zend_file_handle *primary_file CLS_DC ELS_DC PLS_
 {
        zend_file_handle *prepend_file_p, *append_file_p;
        zend_file_handle prepend_file, append_file;
+       SLS_FETCH();
 
-       if (request_info.query_string && request_info.query_string[0]=='=') {
-               if (!strcmp(request_info.query_string+1, "PHPE9568F34-D428-11d2-A769-00AA001ACF42")) {
+       if (SG(request_info).query_string && SG(request_info).query_string[0]=='=') {
+               if (!strcmp(SG(request_info).query_string+1, "PHPE9568F34-D428-11d2-A769-00AA001ACF42")) {
                        char *header_line = estrndup("Content-type:  image/gif", sizeof("Content-type:  image/gif")-1);
 
                        php4i_add_header_information(header_line);
                        PHPWRITE(php4_logo, sizeof(php4_logo));
                        efree(header_line);
                        return;
-               } else if (!strcmp(request_info.query_string+1, "PHPE9568F35-D428-11d2-A769-00AA001ACF42")) {
+               } else if (!strcmp(SG(request_info).query_string+1, "PHPE9568F35-D428-11d2-A769-00AA001ACF42")) {
                        char *header_line = estrndup("Content-type:  image/gif", sizeof("Content-type:  image/gif")-1);
 
                        php4i_add_header_information(header_line);
@@ -1136,7 +1144,7 @@ PHPAPI void php_execute_script(zend_file_handle *primary_file CLS_DC ELS_DC PLS_
                PG(unclean_shutdown) = 1;
                return;
        }
-       _php3_hash_environment(PLS_C);
+       _php3_hash_environment(PLS_C ELS_CC);
 
 #if WIN32||WINNT
        UpdateIniFromRegistry(primary_file->filename);
index 07641c7d37addd4e7b2e37b248d6eaef1918bc0b..7adfa2c8a240823de6d0811ae268941c52e950b4 100644 (file)
@@ -88,7 +88,7 @@ int saved_umask;
 php_apache_info_struct php_apache_info;                /* active config */
 
 int apache_php3_module_main(request_rec * r, int fd, int display_source_mode);
-int php_module_startup(sapi_functions_struct *sf);
+int php_module_startup(sapi_module_struct *sf);
 void php_module_shutdown();
 void php_module_shutdown_for_exec();
 
@@ -112,7 +112,7 @@ static int zend_apache_ub_write(const char *str, uint str_length)
 }
 
 
-sapi_functions_struct sapi_functions = {
+sapi_module_struct sapi_module = {
        zend_apache_ub_write
 };
 
@@ -268,7 +268,7 @@ int php3_xbithack_handler(request_rec * r)
 void php3_init_handler(server_rec *s, pool *p)
 {
        register_cleanup(p, NULL, php_module_shutdown, php_module_shutdown_for_exec);
-       php_module_startup(&sapi_functions);
+       php_module_startup(&sapi_module);
 #if MODULE_MAGIC_NUMBER >= 19980527
        ap_add_version_component("PHP/" PHP_VERSION);
 #endif
index e1bf28b40949a93d842b52487bbd7246048c59ad..fdf55945dcf11b4df362b1f001a1e65d711f4d1d 100644 (file)
--- a/output.c
+++ b/output.c
@@ -48,7 +48,7 @@ PHPAPI void zend_output_startup()
        ob_buffer = NULL;
        zend_body_write = zend_ub_body_write;
        header_request=0;
-       zend_header_write = sapi_functions.ub_write;
+       zend_header_write = sapi_module.ub_write;
 }
 
 
index 0ca88fb3f623922c7589606976843145004a0dab..5b3958175b866e7f3aa090bdea4005cf119c0f59 100644 (file)
@@ -38,10 +38,10 @@ PHPAPI php3_request_info request_info;
 int php3_init_request_info(void *conf)
 {
        char *buf;      /* temporary buffers */
+       SLS_FETCH();
 
        request_info.path_info = getenv("PATH_INFO");
        request_info.path_translated = getenv("PATH_TRANSLATED");
-       request_info.query_string = getenv("QUERY_STRING");
        request_info.current_user = NULL;
        request_info.current_user_length = 0;
        request_info.request_method = getenv("REQUEST_METHOD");
@@ -199,12 +199,12 @@ int php3_init_request_info(void *conf)
        SLS_FETCH();
 
        r = ((request_rec *) SG(server_context));
+       SG(request_info).query_string = r->args;
        request_info.current_user = NULL;
        request_info.current_user_length = 0;
 
        request_info.filename = r->filename;
        request_info.request_method = r->method;
-       request_info.query_string = r->args;
        request_info.content_type = table_get(r->subprocess_env, "CONTENT_TYPE");
 
        buf = table_get(r->subprocess_env, "CONTENT_LENGTH");
@@ -227,7 +227,6 @@ int php3_init_request_info(void *conf)
                request_info.filename = NULL;
        request_info.path_info = sapi_rqst->path_info;
        request_info.path_translated = sapi_rqst->path_translated;
-       request_info.query_string = sapi_rqst->query_string;
        request_info.current_user = sapi_rqst->current_user;
        request_info.current_user_length = sapi_rqst->current_user_length;
        request_info.request_method = sapi_rqst->request_method;
index 71c50cc698d8e6d16bd826d91e84c45a216f21a4..07cc873e38acd0e6781974d50792cf79b6442c79 100644 (file)
@@ -34,7 +34,6 @@ typedef struct {
        char *filename;
        char *path_info;
        const char *path_translated;
-       char *query_string;
        const char *request_method;
        char *script_name;
        char *current_user;