diff options
Diffstat (limited to 'main')
| -rw-r--r-- | main/SAPI.c | 12 | ||||
| -rw-r--r-- | main/SAPI.h | 18 | ||||
| -rw-r--r-- | main/configuration-parser.y | 2 | ||||
| -rw-r--r-- | main/fopen_wrappers.c | 2 | ||||
| -rw-r--r-- | main/fopen_wrappers.h | 2 | ||||
| -rw-r--r-- | main/main.c | 363 | ||||
| -rw-r--r-- | main/php.h | 21 | ||||
| -rw-r--r-- | main/php_globals.h | 2 |
8 files changed, 59 insertions, 363 deletions
diff --git a/main/SAPI.c b/main/SAPI.c index d04c051727..2456662401 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -1,16 +1,20 @@ #include "SAPI.h" +#ifdef ZTS #include "TSRM.h" +#endif #ifdef ZTS -int sapi_globals_id; +SAPI_API int sapi_globals_id; #endif +/* A true global (no need for thread safety) */ +sapi_functions_struct sapi_functions; -void sapi_startup() +void sapi_startup(sapi_functions_struct *sf) { + sapi_functions = *sf; #ifdef ZTS sapi_globals_id = ts_allocate_id(sizeof(sapi_globals_struct), NULL, NULL); #endif -} - +}
\ No newline at end of file diff --git a/main/SAPI.h b/main/SAPI.h index de6af839d1..bd62eaed76 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -1,6 +1,18 @@ #ifndef _NEW_SAPI_H #define _NEW_SAPI_H + +#if WIN32||WINNT +# ifdef SAPI_EXPORTS +# define SAPI_API __declspec(dllexport) +# else +# define SAPI_API __declspec(dllimport) +# endif +#else +#define SAPI_API +#endif + + typedef struct { int (*ub_write)(const char *str, unsigned int str_length); } sapi_functions_struct; @@ -13,7 +25,7 @@ typedef struct { } sapi_globals_struct; -void sapi_startup(); +void sapi_startup(sapi_functions_struct *sf); #ifdef ZTS # define SLS_D sapi_globals_struct *sapi_globals @@ -22,7 +34,7 @@ void sapi_startup(); # define SLS_CC , SLS_C # define SG(v) (sapi_globals->v) # define SLS_FETCH() sapi_globals_struct *sapi_globals = ts_resource(sapi_globals_id) -extern int sapi_globals_id; +SAPI_API extern int sapi_globals_id; #else # define SLS_D # define SLS_DC @@ -30,7 +42,7 @@ extern int sapi_globals_id; # define SLS_CC # define SG(v) (sapi_globals.v) # define SLS_FETCH() -extern ZEND_API sapi_globals_struct sapi_globals; +extern SAPI_API sapi_globals_struct sapi_globals; #endif diff --git a/main/configuration-parser.y b/main/configuration-parser.y index 19bbb0d62d..79153c10ee 100644 --- a/main/configuration-parser.y +++ b/main/configuration-parser.y @@ -60,7 +60,7 @@ static HashTable configuration_hash; #ifndef THREAD_SAFE extern HashTable browser_hash; -extern char *php3_ini_path; +PHPAPI extern char *php3_ini_path; #endif static HashTable *active__php3_hash_table; static pval *current_section; diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index 6128750bf4..8b2814bf88 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -198,7 +198,7 @@ PHPAPI FILE *php3_fopen_wrapper(char *path, char *mode, int options, int *issock #if CGI_BINARY || FHTTPD || USE_SAPI -FILE *php3_fopen_for_parser(void) +PHPAPI FILE *php3_fopen_for_parser(void) { FILE *fp; struct stat st; diff --git a/main/fopen_wrappers.h b/main/fopen_wrappers.h index 0b3834a1e3..c1e1420b3c 100644 --- a/main/fopen_wrappers.h +++ b/main/fopen_wrappers.h @@ -69,7 +69,7 @@ extern int wsa_fp; /* a list for open sockets */ extern PHPAPI FILE *php3_fopen_wrapper(char *filename, char *mode, int options, int *issock, int *socketd); -extern FILE *php3_fopen_for_parser(void); +PHPAPI FILE *php3_fopen_for_parser(void); extern PHPAPI int _php3_check_open_basedir(char *path); diff --git a/main/main.c b/main/main.c index 236209a41c..0df2c4049e 100644 --- a/main/main.c +++ b/main/main.c @@ -93,7 +93,7 @@ struct sapi_request_info *sapi_rqst; #ifndef ZTS php_core_globals core_globals; #else -int core_globals_id; +PHPAPI int core_globals_id; #endif void _php3_build_argv(char * ELS_DC); @@ -109,7 +109,7 @@ void *gLock; /*mutex variable */ /* True globals (no need for thread safety) */ HashTable configuration_hash; -char *php3_ini_path = NULL; +PHPAPI char *php3_ini_path = NULL; #ifdef ZTS php_core_globals *main_core_globals=NULL; #endif @@ -606,36 +606,7 @@ static void php_message_handler_for_zend(long message, void *data) -#ifndef NEW_SAPI -# if APACHE -static int zend_apache_ub_write(const char *str, uint str_length) -{ - if (php3_rqst) { - return rwrite(str, str_length, php3_rqst); - } else { - return fwrite(str, 1, str_length, stdout); - } -} - -sapi_functions_struct sapi_functions = { - zend_apache_ub_write -}; - -# elif CGI_BINARY - -static int zend_cgibin_ub_write(const char *str, uint str_length) -{ - return fwrite(str, 1, str_length, stdout); -} - -sapi_functions_struct sapi_functions = { - zend_cgibin_ub_write -}; -# endif -#endif - - -int php3_request_startup(CLS_D ELS_DC PLS_DC) +int php_request_startup(CLS_D ELS_DC PLS_DC) { zend_output_startup(); @@ -651,7 +622,7 @@ int php3_request_startup(CLS_D ELS_DC PLS_DC) * memory. */ block_alarms(); - register_cleanup(php3_rqst->pool, NULL, php3_request_shutdown, php3_request_shutdown_for_exec); + register_cleanup(php3_rqst->pool, NULL, php_request_shutdown, php_request_shutdown_for_exec); unblock_alarms(); #endif @@ -675,7 +646,7 @@ int php3_request_startup(CLS_D ELS_DC PLS_DC) } -void php3_request_shutdown_for_exec(void *dummy) +void php_request_shutdown_for_exec(void *dummy) { /* used to close fd's in the 3..255 range here, but it's problematic */ @@ -689,7 +660,7 @@ int return_one(void *p) } -void php3_request_shutdown(void *dummy) +void php_request_shutdown(void *dummy) { #if FHTTPD char tmpline[128]; @@ -791,7 +762,7 @@ static core_globals_ctor(php_core_globals *core_globals) #endif -int php3_module_startup() +int php_module_startup(sapi_functions_struct *sf) { zend_utility_functions zuf; zend_utility_values zuv; @@ -829,9 +800,7 @@ int php3_module_startup() main_core_globals = core_globals; #endif -#ifdef NEW_SAPI - sapi_startup(); -#endif + sapi_startup(sf); #if HAVE_SETLOCALE setlocale(LC_CTYPE, ""); @@ -870,12 +839,12 @@ int php3_module_startup() -void php3_module_shutdown_for_exec(void) +void php_module_shutdown_for_exec(void) { /* used to close fd's in the range 3.255 here, but it's problematic */ } -void php3_module_shutdown() +void php_module_shutdown() { int module_number=0; /* for UNREGISTER_INI_ENTRIES() */ CLS_FETCH(); @@ -1144,7 +1113,7 @@ void _php3_build_argv(char *s ELS_DC) #include "logos.h" -void php3_parse(zend_file_handle *primary_file CLS_DC ELS_DC PLS_DC) +PHPAPI void php_execute_script(zend_file_handle *primary_file CLS_DC ELS_DC PLS_DC) { zend_file_handle *prepend_file_p, *append_file_p; zend_file_handle prepend_file, append_file; @@ -1199,304 +1168,7 @@ void php3_parse(zend_file_handle *primary_file CLS_DC ELS_DC PLS_DC) -#if CGI_BINARY - -void _php3_usage(char *argv0) -{ - char *prog; - - prog = strrchr(argv0, '/'); - if (prog) { - prog++; - } else { - prog = "php"; - } - - php3_printf("Usage: %s [-q] [-h]" - " [-s]" - " [-v] [-i] [-f <file>] | " - "{<file> [args...]}\n" - " -q Quiet-mode. Suppress HTTP Header output.\n" - " -s Display colour syntax highlighted source.\n" - " -f<file> Parse <file>. Implies `-q'\n" - " -v Version number\n" - " -c<path> Look for php3.ini file in this directory\n" -#if SUPPORT_INTERACTIVE - " -a Run interactively\n" -#endif - " -e Generate extended information for debugger/profiler\n" - " -i PHP information\n" - " -h This help\n", prog); -} - /* some systems are missing these from their header files */ -extern char *optarg; -extern int optind; - -#if THREAD_SAFE -extern flex_globals *yy_init_tls(void); -extern void yy_destroy_tls(void); -#endif - -#ifndef ZTS -int main(int argc, char *argv[]) -{ - int cgi = 0, c, i, len; - zend_file_handle file_handle; - char *s; -/* temporary locals */ - char *_cgi_filename=NULL; - int _cgi_started=0; - int behavior=PHP_MODE_STANDARD; -#if SUPPORT_INTERACTIVE - int interactive=0; -#endif -/* end of temporary locals */ -#ifdef ZTS - zend_compiler_globals *compiler_globals; - zend_executor_globals *executor_globals; - php_core_globals *core_globals; -#endif - - -#ifndef ZTS - if (setjmp(EG(bailout))!=0) { - return -1; - } -#endif - -#if WIN32|WINNT - _fmode = _O_BINARY; /*sets default for file streams to binary */ - setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */ - setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */ - setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */ -#endif - - - /* Make sure we detect we are a cgi - a bit redundancy here, - but the default case is that we have to check only the first one. */ - if (getenv("SERVER_SOFTWARE") - || getenv("SERVER_NAME") - || getenv("GATEWAY_INTERFACE") - || getenv("REQUEST_METHOD")) { - cgi = 1; - if (argc > 1) - request_info.php_argv0 = strdup(argv[1]); - else request_info.php_argv0 = NULL; -#if FORCE_CGI_REDIRECT - if (!getenv("REDIRECT_STATUS")) { - PUTS("<b>Security Alert!</b> PHP CGI cannot be accessed directly.\n\ -\n\ -<P>This PHP CGI binary was compiled with force-cgi-redirect enabled. This\n\ -means that a page will only be served up if the REDIRECT_STATUS CGI variable is\n\ -set. This variable is set, for example, by Apache's Action directive redirect.\n\ -<P>You may disable this restriction by recompiling the PHP binary with the\n\ ---disable-force-cgi-redirect switch. If you do this and you have your PHP CGI\n\ -binary accessible somewhere in your web tree, people will be able to circumvent\n\ -.htaccess security by loading files through the PHP parser. A good way around\n\ -this is to define doc_root in your php3.ini file to something other than your\n\ -top-level DOCUMENT_ROOT. This way you can separate the part of your web space\n\n\ -which uses PHP from the normal part using .htaccess security. If you do not have\n\ -any .htaccess restrictions anywhere on your site you can leave doc_root undefined.\n\ -\n"); - - /* remove that detailed explanation some time */ - - return FAILURE; - } -#endif /* FORCE_CGI_REDIRECT */ - } - - if (php3_module_startup()==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); -#endif - - CG(extended_info) = 0; - - if (!cgi) { /* never execute the arguments if you are a CGI */ - request_info.php_argv0 = NULL; - while ((c = getopt(argc, argv, "c:qvisnaeh?vf:")) != -1) { - switch (c) { - case 'f': - if (!_cgi_started){ - if (php3_request_startup(CLS_C ELS_CC PLS_CC)==FAILURE) { - php3_module_shutdown(); - return FAILURE; - } - } - _cgi_started=1; - _cgi_filename = estrdup(optarg); - /* break missing intentionally */ - case 'q': - php3_noheader(); - break; - case 'v': - if (!_cgi_started) { - if (php3_request_startup(CLS_C ELS_CC PLS_CC)==FAILURE) { - php3_module_shutdown(); - return FAILURE; - } - } - php3_printf("%s\n", PHP_VERSION); - exit(1); - break; - case 'i': - if (!_cgi_started) { - if (php3_request_startup(CLS_C ELS_CC PLS_CC)==FAILURE) { - php3_module_shutdown(); - return FAILURE; - } - } - _cgi_started=1; - php3_TreatHeaders(); - _php3_info(); - exit(1); - break; - case 's': - behavior=PHP_MODE_HIGHLIGHT; - break; - case 'n': - behavior=PHP_MODE_INDENT; - break; - case 'c': - php3_ini_path = strdup(optarg); /* intentional leak */ - break; - case 'a': -#if SUPPORT_INTERACTIVE - printf("Interactive mode enabled\n\n"); - interactive=1; -#else - printf("Interactive mode not supported!\n\n"); -#endif - break; - case 'e': - CG(extended_info) = 1; - break; - case 'h': - case '?': - php3_noheader(); - zend_output_startup(); - _php3_usage(argv[0]); - exit(1); - break; - default: - break; - } - } - } /* not cgi */ - -#if SUPPORT_INTERACTIVE - EG(interactive) = interactive; -#endif - - if (!_cgi_started) { - if (php3_request_startup(CLS_C ELS_CC PLS_CC)==FAILURE) { - php3_module_shutdown(); - return FAILURE; - } - } - file_handle.filename = "-"; - file_handle.type = ZEND_HANDLE_FP; - file_handle.handle.fp = stdin; - if (_cgi_filename) { - request_info.filename = _cgi_filename; - } - - php3_TreatHeaders(); - - if (!cgi) { - if (!request_info.query_string) { - for (i = optind, len = 0; i < argc; i++) - len += strlen(argv[i]) + 1; - - s = malloc(len + 1); /* leak - but only for command line version, so ok */ - *s = '\0'; /* we are pretending it came from the environment */ - for (i = optind, len = 0; i < argc; i++) { - strcat(s, argv[i]); - if (i < (argc - 1)) - strcat(s, "+"); - } - request_info.query_string = s; - } - if (!request_info.filename && argc > optind) - request_info.filename = argv[optind]; - } - /* If for some reason the CGI interface is not setting the - PATH_TRANSLATED correctly, request_info.filename is NULL. - We still call php3_fopen_for_parser, because if you set doc_root - or user_dir configuration directives, PATH_INFO is used to construct - the filename as a side effect of php3_fopen_for_parser. - */ - if (cgi || request_info.filename) { - file_handle.filename = request_info.filename; - file_handle.handle.fp = php3_fopen_for_parser(); - } - - if (cgi && !file_handle.handle.fp) { - PUTS("No input file specified.\n"); -#if 0 /* this is here for debuging under windows */ - if (argc) { - i = 0; - php3_printf("\nargc %d\n",argc); - while (i <= argc) { - php3_printf("%s\n",argv[i]); - i++; - } - } -#endif - php3_request_shutdown((void *) 0); - php3_module_shutdown(); - return FAILURE; - } else if (file_handle.handle.fp && file_handle.handle.fp!=stdin) { - /* #!php support */ - c = fgetc(file_handle.handle.fp); - if (c == '#') { - while (c != 10 && c != 13) { - c = fgetc(file_handle.handle.fp); /* skip to end of line */ - } - CG(zend_lineno)++; - } else { - rewind(file_handle.handle.fp); - } - } - - switch (behavior) { - case PHP_MODE_STANDARD: - php3_parse(&file_handle CLS_CC ELS_CC PLS_CC); - break; - case PHP_MODE_HIGHLIGHT: { - zend_syntax_highlighter_ini syntax_highlighter_ini; - - if (open_file_for_scanning(&file_handle CLS_CC)==SUCCESS) { - php_get_highlight_struct(&syntax_highlighter_ini); - zend_highlight(&syntax_highlighter_ini); - fclose(file_handle.handle.fp); - } - return 0; - } - break; - case PHP_MODE_INDENT: - open_file_for_scanning(&file_handle CLS_CC); - zend_indent(); - fclose(file_handle.handle.fp); - return 0; - break; - } - - php3_header(); /* Make sure headers have been sent */ - php3_request_shutdown((void *) 0); - php3_module_shutdown(); - return SUCCESS; -} -#endif /* CGI_BINARY */ - -#endif /* ZTS */ - #if APACHE PHPAPI int apache_php3_module_main(request_rec * r, int fd, int display_source_mode) @@ -1513,14 +1185,14 @@ PHPAPI int apache_php3_module_main(request_rec * r, int fd, int display_source_m php3_rqst = r; - if (php3_request_startup(CLS_C ELS_CC PLS_CC) == FAILURE) { + if (php_request_startup(CLS_C ELS_CC PLS_CC) == FAILURE) { return FAILURE; } php3_TreatHeaders(); file_handle.type = ZEND_HANDLE_FD; file_handle.handle.fd = fd; file_handle.filename = request_info.filename; - (void) php3_parse(&file_handle CLS_CC ELS_CC); + (void) php_execute_script(&file_handle CLS_CC ELS_CC); php3_header(); /* Make sure headers have been sent */ zend_end_ob_buffering(1); @@ -1528,6 +1200,15 @@ PHPAPI int apache_php3_module_main(request_rec * r, int fd, int display_source_m } #endif /* APACHE */ + +#if WIN32||WINNT +/* just so that this symbol gets exported... */ +PHPAPI void dummy_indent() +{ + zend_indent(); +} +#endif + /* * Local variables: * tab-width: 4 diff --git a/main/php.h b/main/php.h index d66976e58b..ab4a159069 100644 --- a/main/php.h +++ b/main/php.h @@ -69,15 +69,15 @@ extern unsigned char second_arg_allow_ref[]; #if WIN32 #include "config.w32.h" #include "win95nt.h" -# if defined(COMPILE_DL) -# define PHPAPI __declspec(dllimport) -# else -# define PHPAPI __declspec(dllexport) -# endif +# ifdef PHP_EXPORTS +# define PHPAPI __declspec(dllexport) +# else +# define PHPAPI __declspec(dllimport) +# endif #else -# include "config.h" -# define PHPAPI -# define THREAD_LS +#include "config.h" +#define PHPAPI +#define THREAD_LS #endif @@ -314,12 +314,11 @@ extern PHPAPI int php3_fhttpd_write(char *a,int n); /* global variables */ -#ifndef THREAD_SAFE extern pval *data; -#if (!PHP_ISAPI) +#if !(WIN32||WINNT) extern char **environ; #endif -#endif + extern PHPAPI int le_index_ptr; /* list entry type for index pointers */ extern void phperror(char *error); diff --git a/main/php_globals.h b/main/php_globals.h index 969d7cab66..ce5405c930 100644 --- a/main/php_globals.h +++ b/main/php_globals.h @@ -12,7 +12,7 @@ typedef struct _php_core_globals php_core_globals; # define PLS_CC , PLS_C # define PG(v) (core_globals->v) # define PLS_FETCH() php_core_globals *core_globals = ts_resource(core_globals_id) -extern int core_globals_id; +PHPAPI extern int core_globals_id; #else # define PLS_D # define PLS_DC |
