From: Sascha Schumann Date: Sat, 11 Nov 2000 18:24:27 +0000 (+0000) Subject: Update README X-Git-Tag: php-4.0.4RC3~240 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=802d716c0d4129ca6bd513570b6d03ad465ce524;p=php Update README Make Apache-related functions build Add get_all_headers() Fix segfault when SAPI outputs strings of length 0 Move request ctor/dtor into their own functions --- diff --git a/sapi/apache2filter/Makefile.in b/sapi/apache2filter/Makefile.in index d3b4abbd5e..e4e876c904 100644 --- a/sapi/apache2filter/Makefile.in +++ b/sapi/apache2filter/Makefile.in @@ -1,6 +1,6 @@ LTLIBRARY_NAME = libsapi.la -LTLIBRARY_SOURCES = sapi_apache2.c apache_config.c +LTLIBRARY_SOURCES = sapi_apache2.c apache_config.c php_functions.c EXTRA_INCLUDES = $(APACHE_INCLUDE) diff --git a/sapi/apache2filter/README b/sapi/apache2filter/README index 16d32048d9..1f227fac32 100644 --- a/sapi/apache2filter/README +++ b/sapi/apache2filter/README @@ -33,9 +33,6 @@ HOW TO INSTALL $ ./configure --with-apxs2=/path/to/apache-2.0/bin/apxs $ make install - APXS is currently still flaky, so edit conf/httpd.conf and change - the LoadModule entry from libphp4.la to libphp4.so. - At the end of conf/httpd.conf, add: @@ -45,13 +42,21 @@ HOW TO INSTALL That's it. Now start bin/httpd. - If you want to debug Apache, set ONE_PROCESS in your environment - (comparable to -X in Apache 1.3). We recommened the prefork MPM - for debugging purposes. - +DEBUGGING APACHE AND PHP + + To debug Apache, we recommened: + + 1. Use the Prefork MPM (Apache 1.3-like process model) by + configuring Apache with '--with-mpm=prefork'. + 2. Set the variable "ONE_PROCESS" to 1 and export it before + starting Apache/a debugger. + + If you want to debug a part of the PHP startup procedure, set a + breakpoint on 'load_module'. Step through it until apr_dso_load() is + done. Then you can set a breakpoint on any PHP-related symbol. + TODO - php_*flag config directives PHP functions like apache_sub_req (see php_functions.c) Protocol handlers Passing script data to engine without temporary file diff --git a/sapi/apache2filter/php_apache.h b/sapi/apache2filter/php_apache.h index 6320ffd90b..e745fc17d9 100644 --- a/sapi/apache2filter/php_apache.h +++ b/sapi/apache2filter/php_apache.h @@ -31,9 +31,21 @@ typedef struct php_struct { char *post_data; } php_struct; +int php_apache_register_module(void); void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf); void *create_php_config(apr_pool_t *p, char *dummy); void apply_config(void *); extern const command_rec php_dir_cmds[]; +#define APR_ARRAY_FOREACH_OPEN(arr, key, val) \ +{ \ + apr_table_entry_t *elts; \ + int i; \ + elts = (apr_table_entry_t *) arr->elts; \ + for (i = 0; i < arr->nelts; i++) { \ + key = elts[i].key; \ + val = elts[i].val; + +#define APR_ARRAY_FOREACH_CLOSE() }} + #endif /* PHP_APACHE_H */ diff --git a/sapi/apache2filter/php_functions.c b/sapi/apache2filter/php_functions.c index f2265cc4da..fd17d17999 100644 --- a/sapi/apache2filter/php_functions.c +++ b/sapi/apache2filter/php_functions.c @@ -16,9 +16,25 @@ +----------------------------------------------------------------------+ */ +#include "php.h" +#include "SAPI.h" + +#include "apr_strings.h" +#include "ap_config.h" +#include "util_filter.h" +#include "httpd.h" +#include "http_config.h" +#include "http_request.h" +#include "http_core.h" +#include "http_protocol.h" +#include "http_log.h" +#include "http_main.h" +#include "util_script.h" +#include "http_core.h" + #include "php_apache.h" -static request_rec *php_lookup_uri(INTERNAL_FUNCTION_PARAMETERS) +static request_rec *php_apache_lookup_uri(INTERNAL_FUNCTION_PARAMETERS) { zval **p1; php_struct *ctx; @@ -37,10 +53,10 @@ PHP_FUNCTION(apache_sub_req) { request_rec *rr; - rr = php_lookup_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU); + rr = php_apache_lookup_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU); if (!rr) - WRONG_NUM_ARGS; + WRONG_PARAM_COUNT; if (rr->status == HTTP_OK) { ap_run_sub_req(rr); @@ -52,7 +68,7 @@ PHP_FUNCTION(apache_sub_req) #define ADD_LONG(name) \ add_assoc_long(return_value, #name, rr->name) #define ADD_STRING(name) \ - add_assoc_string(return_value, #name, rr->name, 1) + if (rr->name) add_assoc_string(return_value, #name, (char *) rr->name, 1) PHP_FUNCTION(apache_lookup_uri) { @@ -60,7 +76,7 @@ PHP_FUNCTION(apache_lookup_uri) rr = php_apache_lookup_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU); if (!rr) - WRONG_NUM_ARGS; + WRONG_PARAM_COUNT; if (rr->status == HTTP_OK) { array_init(return_value); @@ -73,7 +89,6 @@ PHP_FUNCTION(apache_lookup_uri) ADD_LONG(clength); ADD_STRING(boundary); ADD_STRING(range); - ADD_LONG(byterange); ADD_LONG(chunked); ADD_STRING(content_type); ADD_STRING(handler); @@ -89,3 +104,50 @@ PHP_FUNCTION(apache_lookup_uri) } RETURN_FALSE; } + +PHP_FUNCTION(get_all_headers) +{ + php_struct *ctx; + apr_array_header_t *arr; + char *key, *val; + SLS_FETCH(); + + if (array_init(return_value) == FAILURE) { + RETURN_FALSE; + } + + ctx = SG(server_context); + arr = apr_table_elts(ctx->f->r->headers_in); + + APR_ARRAY_FOREACH_OPEN(arr, key, val) + if (!val) val = empty_string; + add_assoc_string(return_value, key, val, 1); + APR_ARRAY_FOREACH_CLOSE() +} + +PHP_MINFO_FUNCTION(apache) +{ +} + +static function_entry apache_functions[] = { + PHP_FE(apache_lookup_uri, NULL) + PHP_FE(apache_sub_req, NULL) + PHP_FE(get_all_headers, NULL) + {0} +}; + +static zend_module_entry php_apache_module = { + "Apache 2.0", + apache_functions, + NULL, + NULL, + NULL, + NULL, + PHP_MINFO(apache), + STANDARD_MODULE_PROPERTIES +}; + +int php_apache_register_module(void) +{ + return zend_startup_module(&php_apache_module); +} diff --git a/sapi/apache2filter/sapi_apache2.c b/sapi/apache2filter/sapi_apache2.c index 9a5c0e1894..3f363b94e9 100644 --- a/sapi/apache2filter/sapi_apache2.c +++ b/sapi/apache2filter/sapi_apache2.c @@ -54,6 +54,8 @@ php_apache_sapi_ub_write(const char *str, uint str_length) ctx = SG(server_context); + if (!str_length) return 0; + bb = ap_brigade_create(ctx->f->r->pool); while (str_length > 0) { now = MIN(str_length, 4096); @@ -145,17 +147,13 @@ php_apache_sapi_register_variables(zval *track_vars_array ELS_DC SLS_DC PLS_DC) { php_struct *ctx = SG(server_context); apr_array_header_t *arr = apr_table_elts(ctx->f->r->subprocess_env); - apr_table_entry_t *elts = (apr_table_entry_t *) arr->elts; - int i; - char *val; - - for (i = 0; i < arr->nelts; i++) { - if (!(val = elts[i].val)) - val = empty_string; - - php_register_variable(elts[i].key, val, track_vars_array ELS_CC PLS_CC); - } + char *key, *val; + APR_ARRAY_FOREACH_OPEN(arr, key, val) + if (!val) val = empty_string; + php_register_variable(key, val, track_vars_array ELS_CC PLS_CC); + APR_ARRAY_FOREACH_CLOSE() + php_register_variable("PHP_SELF", ctx->f->r->uri, track_vars_array ELS_CC PLS_CC); } @@ -263,6 +261,49 @@ static int php_input_filter(ap_filter_t *f, ap_bucket_brigade *bb, return APR_SUCCESS; } +static void php_apache_request_ctor(ap_filter_t *f, php_struct *ctx SLS_DC) +{ + char *content_type; + const char *auth; + CLS_FETCH(); + ELS_FETCH(); + PLS_FETCH(); + + PG(during_request_startup) = 0; + SG(sapi_headers).http_response_code = 200; + SG(request_info).content_type = apr_table_get(f->r->headers_in, "Content-Type"); +#undef safe_strdup +#define safe_strdup(x) ((x)?strdup((x)):NULL) + SG(request_info).query_string = safe_strdup(f->r->args); + SG(request_info).request_method = f->r->method; + SG(request_info).request_uri = safe_strdup(f->r->uri); + f->r->no_local_copy = 1; + content_type = sapi_get_default_content_type(SLS_C); + f->r->content_type = apr_pstrdup(f->r->pool, content_type); + SG(request_info).post_data = ctx->post_data; + SG(request_info).post_data_length = ctx->post_len; + efree(content_type); + apr_table_unset(f->r->headers_out, "Content-Length"); + apr_table_unset(f->r->headers_out, "Last-Modified"); + apr_table_unset(f->r->headers_out, "Expires"); + apr_table_unset(f->r->headers_out, "ETag"); + apr_table_unset(f->r->headers_in, "Connection"); + auth = apr_table_get(f->r->headers_in, "Authorization"); + php_handle_auth_data(auth SLS_CC); + + php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC); +} + +static void php_apache_request_dtor(ap_filter_t *f SLS_DC) +{ + php_request_shutdown(NULL); + +#undef safe_free +#define safe_free(x) ((x)?free((x)):0) + safe_free(SG(request_info).query_string); + safe_free(SG(request_info).request_uri); +} + static int php_output_filter(ap_filter_t *f, ap_bucket_brigade *bb) { php_struct *ctx; @@ -284,37 +325,12 @@ static int php_output_filter(ap_filter_t *f, ap_bucket_brigade *bb) * 2: script execution and request shutdown */ if (ctx->state == 0) { - char *content_type; - const char *auth; - CLS_FETCH(); - ELS_FETCH(); - PLS_FETCH(); - SLS_FETCH(); apply_config(conf); ctx->state++; - /* XXX: Lots of startup crap. Should be moved into its own func */ - PG(during_request_startup) = 0; - SG(sapi_headers).http_response_code = 200; - SG(request_info).content_type = apr_table_get(f->r->headers_in, "Content-Type"); - SG(request_info).query_string = f->r->args; - SG(request_info).request_method = f->r->method; - SG(request_info).request_uri = f->r->uri; - f->r->no_local_copy = 1; - content_type = sapi_get_default_content_type(SLS_C); - f->r->content_type = apr_pstrdup(f->r->pool, content_type); - efree(content_type); - apr_table_unset(f->r->headers_out, "Content-Length"); - apr_table_unset(f->r->headers_out, "Last-Modified"); - apr_table_unset(f->r->headers_out, "Expires"); - apr_table_unset(f->r->headers_out, "ETag"); - apr_table_unset(f->r->headers_in, "Connection"); - auth = apr_table_get(f->r->headers_in, "Authorization"); - php_handle_auth_data(auth SLS_CC); - - php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC); + php_apache_request_ctor(f, ctx SLS_CC); } /* moves all buckets from bb to ctx->bb */ @@ -387,7 +403,7 @@ skip_execution: eos = ap_bucket_create_transient(NO_DATA, sizeof(NO_DATA)-1); AP_BRIGADE_INSERT_HEAD(bb, eos); ok: - php_request_shutdown(NULL); + php_apache_request_dtor(f SLS_CC); SG(server_context) = 0; /* Pass EOS bucket to next filter to signal end of request */ @@ -417,6 +433,7 @@ php_apache_server_startup(apr_pool_t *pchild, server_rec *s) sapi_startup(&sapi_module); sapi_module.startup(&sapi_module); apr_register_cleanup(pchild, NULL, php_apache_server_shutdown, NULL); + php_apache_register_module(); } static void php_register_hook(void)