Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Make ISAPI hook in as an extension too.

- Some work on moving stuff to SAPI.
  • Loading branch information...
commit 5dbe9246609e59439ca0340aed5b2eaac1bed7d8 1 parent 7e0ee50
andigutmans andigutmans authored
24 cgi_main.c
View
@@ -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];
4 ext/hyperwave/hw.c
View
@@ -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,
3  ext/standard/post.c
View
@@ -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);
}
3  main.h
View
@@ -42,9 +42,10 @@
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);
6 main/SAPI.c
View
@@ -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
21 main/SAPI.h
View
@@ -13,19 +13,32 @@
#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
28 main/main.c
View
@@ -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);
6 mod_php3.c
View
@@ -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
2  output.c
View
@@ -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;
}
5 request_info.c
View
@@ -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;
1  request_info.h
View
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.