jani Sat May 23 18:19:11 2009 UTC Modified files: /php-src/main SAPI.c Log: ws + cs
http://cvs.php.net/viewvc.cgi/php-src/main/SAPI.c?r1=1.237&r2=1.238&diff_format=u Index: php-src/main/SAPI.c diff -u php-src/main/SAPI.c:1.237 php-src/main/SAPI.c:1.238 --- php-src/main/SAPI.c:1.237 Sat May 23 18:10:13 2009 +++ php-src/main/SAPI.c Sat May 23 18:19:11 2009 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: SAPI.c,v 1.237 2009/05/23 18:10:13 jani Exp $ */ +/* $Id: SAPI.c,v 1.238 2009/05/23 18:19:11 jani Exp $ */ #include <ctype.h> #include <sys/stat.h> @@ -70,7 +70,6 @@ /* True globals (no need for thread safety) */ SAPI_API sapi_module_struct sapi_module; - SAPI_API void sapi_startup(sapi_module_struct *sf) { sf->ini_entries = NULL; @@ -108,13 +107,11 @@ #endif } - SAPI_API void sapi_free_header(sapi_header_struct *sapi_header) { efree(sapi_header->header); } - SAPI_API void sapi_handle_post(void *arg TSRMLS_DC) { if (SG(request_info).post_entry && SG(request_info).content_type_dup) { @@ -146,7 +143,6 @@ char oldchar=0; void (*post_reader_func)(TSRMLS_D) = NULL; - /* dedicated implementation for increased performance: * - Make the content type lowercase * - Trim descriptive data, stay with the content-type only @@ -167,8 +163,7 @@ } /* now try to find an appropriate POST content handler */ - if (zend_hash_find(&SG(known_post_content_types), content_type, - content_type_length+1, (void **) &post_entry) == SUCCESS) { + if (zend_hash_find(&SG(known_post_content_types), content_type, content_type_length + 1, (void **) &post_entry) == SUCCESS) { /* found one, register it for use */ SG(request_info).post_entry = post_entry; post_reader_func = post_entry->post_reader; @@ -188,24 +183,22 @@ SG(request_info).content_type_dup = content_type; - if(post_reader_func) { + if (post_reader_func) { post_reader_func(TSRMLS_C); } - if(sapi_module.default_post_reader) { + if (sapi_module.default_post_reader) { sapi_module.default_post_reader(TSRMLS_C); } } - SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data) { int read_bytes; int allocated_bytes=SAPI_POST_BLOCK_SIZE+1; if (SG(request_info).content_length > SG(post_max_size)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes", - SG(request_info).content_length, SG(post_max_size)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes", SG(request_info).content_length, SG(post_max_size)); return; } SG(request_info).post_data = emalloc(allocated_bytes); @@ -228,11 +221,10 @@ SG(request_info).post_data = erealloc(SG(request_info).post_data, allocated_bytes); } } - SG(request_info).post_data[SG(read_post_bytes)] = 0; /* terminating NULL */ + SG(request_info).post_data[SG(read_post_bytes)] = 0; /* terminating NULL */ SG(request_info).post_data_length = SG(read_post_bytes); } - /* {{{ sapi_update_default_charset */ SAPI_API void sapi_update_default_charset(TSRMLS_D) { @@ -248,7 +240,6 @@ } /* }}} */ - SAPI_API char *sapi_get_default_content_type(TSRMLS_D) { char *mimetype, *charset, *content_type; @@ -271,7 +262,6 @@ return content_type; } - SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header TSRMLS_DC) { char *default_content_type = sapi_get_default_content_type(TSRMLS_C); @@ -291,8 +281,8 @@ * there is not already a charset option in there. * * If "mimetype" is non-NULL, it should point to a pointer allocated - * with emalloc(). If a charset is added, the string will be - * re-allocated and the new length is returned. If mimetype is + * with emalloc(). If a charset is added, the string will be + * re-allocated and the new length is returned. If mimetype is * unchanged, 0 is returned. * */ @@ -307,7 +297,7 @@ if (*charset && strncmp(*mimetype, "text/", 5) == 0 && strstr(*mimetype, "charset=") == NULL) { newlen = len + (sizeof(";charset=")-1) + strlen(charset); newtype = emalloc(newlen + 1); - PHP_STRLCPY(newtype, *mimetype, newlen + 1, len); + PHP_STRLCPY(newtype, *mimetype, newlen + 1, len); strlcat(newtype, ";charset=", newlen + 1); strlcat(newtype, charset, newlen + 1); efree(*mimetype); @@ -320,14 +310,14 @@ SAPI_API void sapi_activate_headers_only(TSRMLS_D) { - if (SG(request_info).headers_read == 1) + if (SG(request_info).headers_read == 1) { return; + } SG(request_info).headers_read = 1; - zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct), - (void (*)(void *)) sapi_free_header, 0); + zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct), (void (*)(void *)) sapi_free_header, 0); SG(sapi_headers).send_default_content_type = 1; - /* SG(sapi_headers).http_response_code = 200; */ + /* SG(sapi_headers).http_response_code = 200; */ SG(sapi_headers).http_status_line = NULL; SG(sapi_headers).mimetype = NULL; SG(read_post_bytes) = 0; @@ -340,7 +330,7 @@ SG(global_request_time) = 0; /* - * It's possible to override this general case in the activate() callback, + * It's possible to override this general case in the activate() callback, * if necessary. */ if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) { @@ -398,20 +388,19 @@ /* handle request mehtod */ if (SG(server_context)) { - if ( SG(request_info).request_method) { - if(!strcmp(SG(request_info).request_method, "POST") - && (SG(request_info).content_type)) { + if (SG(request_info).request_method) { + if (!strcmp(SG(request_info).request_method, "POST") && + (SG(request_info).content_type) + ) { /* HTTP POST -> may contain form data to be read into variables - depending on content type given - */ + * depending on content type given */ sapi_read_post_data(TSRMLS_C); } else { - /* any other method with content payload will fill - $HTTP_RAW_POST_DATA if enabled by always_populate_raw_post_data - it is up to the webserver to decide whether to allow a method or not - */ + /* Any other method with content payload will fill + * $HTTP_RAW_POST_DATA if enabled by always_populate_raw_post_data + * it is up to the webserver to decide whether to allow a method or not */ SG(request_info).content_type_dup = NULL; - if(sapi_module.default_post_reader) { + if (sapi_module.default_post_reader) { sapi_module.default_post_reader(TSRMLS_C); } } @@ -430,7 +419,6 @@ } } - static void sapi_send_headers_free(TSRMLS_D) { if (SG(sapi_headers).http_status_line) { @@ -438,14 +426,14 @@ SG(sapi_headers).http_status_line = NULL; } } - + SAPI_API void sapi_deactivate(TSRMLS_D) { zend_llist_destroy(&SG(sapi_headers).headers); if (SG(request_info).post_data) { efree(SG(request_info).post_data); - } else if (SG(server_context)) { - if(sapi_module.read_post) { + } else if (SG(server_context)) { + if (sapi_module.read_post) { /* make sure we've consumed all request input data */ char dummy[SAPI_POST_BLOCK_SIZE]; int read_bytes; @@ -457,7 +445,7 @@ } if (SG(request_info).raw_post_data) { efree(SG(request_info).raw_post_data); - } + } if (SG(request_info).auth_user) { efree(SG(request_info).auth_user); } @@ -498,7 +486,6 @@ SG(global_request_time) = 0; } - SAPI_API void sapi_initialize_empty_request(TSRMLS_D) { SG(server_context) = NULL; @@ -507,7 +494,6 @@ SG(request_info).content_type_dup = NULL; } - static int sapi_extract_response_code(const char *header_line) { int code = 200; @@ -519,15 +505,14 @@ break; } } - + return code; } - static void sapi_update_response_code(int ncode TSRMLS_DC) { /* if the status code did not change, we do not want - to change the status line, and no need to change the code */ + * to change the status line, and no need to change the code */ if (SG(sapi_headers).http_response_code == ncode) { return; } @@ -549,16 +534,15 @@ { sapi_header_line ctr = {0}; int r; - + ctr.line = header_line; ctr.line_len = header_line_len; - r = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, - &ctr TSRMLS_CC); + r = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, &ctr TSRMLS_CC); - if (!duplicate) + if (!duplicate) { efree(header_line); - + } return r; } @@ -571,14 +555,13 @@ char *header_line; uint header_line_len; int http_response_code; - + if (SG(headers_sent) && !SG(request_info).no_headers) { char *output_start_filename = php_output_get_start_filename(TSRMLS_C); int output_start_lineno = php_output_get_start_lineno(TSRMLS_C); if (output_start_filename) { - sapi_module.sapi_error(E_WARNING, "Cannot modify header information - headers already sent by (output started at %s:%d)", - output_start_filename, output_start_lineno); + sapi_module.sapi_error(E_WARNING, "Cannot modify header information - headers already sent by (output started at %s:%d)", output_start_filename, output_start_lineno); } else { sapi_module.sapi_error(E_WARNING, "Cannot modify header information - headers already sent"); } @@ -594,7 +577,7 @@ case SAPI_HEADER_REPLACE: case SAPI_HEADER_DELETE: { sapi_header_line *p = arg; - + if (!p->line || !p->line_len) { return FAILURE; } @@ -602,7 +585,7 @@ header_line_len = p->line_len; http_response_code = p->response_code; break; - } + } case SAPI_HEADER_DELETE_ALL: if (sapi_module.header_handler) { @@ -610,7 +593,7 @@ } zend_llist_clean(&SG(sapi_headers).headers); return SUCCESS; - + default: return FAILURE; } @@ -618,9 +601,9 @@ header_line = estrndup(header_line, header_line_len); /* cut of trailing spaces, linefeeds and carriage-returns */ - while(header_line_len && isspace(header_line[header_line_len-1])) - header_line[--header_line_len]='\0'; - + while(header_line_len && isspace(header_line[header_line_len-1])) { + header_line[--header_line_len] = '\0'; + } if (op == SAPI_HEADER_DELETE) { if (strchr(header_line, ':')) { efree(header_line); @@ -654,8 +637,7 @@ } /* Check the header for a few cases that we have special support for in SAPI */ - if (header_line_len>=5 - && !strncasecmp(header_line, "HTTP/", 5)) { + if (header_line_len >= 5 && !strncasecmp(header_line, "HTTP/", 5)) { /* filter out the response code */ sapi_update_response_code(sapi_extract_response_code(header_line) TSRMLS_CC); /* sapi_update_response_code doesn't free the status line if the code didn't change */ @@ -676,7 +658,7 @@ len--; } #if HAVE_ZLIB - if(!strncmp(ptr, "image/", sizeof("image/")-1)) { + if (!strncmp(ptr, "image/", sizeof("image/")-1)) { zend_alter_ini_entry("zlib.output_compression", sizeof("zlib.output_compression"), "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); } #endif @@ -704,10 +686,11 @@ /* Return a Found Redirect if one is not already specified */ if (http_response_code) { /* user specified redirect code */ sapi_update_response_code(http_response_code TSRMLS_CC); - } else if (SG(request_info).proto_num > 1000 && - SG(request_info).request_method && - strcmp(SG(request_info).request_method, "HEAD") && - strcmp(SG(request_info).request_method, "GET")) { + } else if (SG(request_info).proto_num > 1000 && + SG(request_info).request_method && + strcmp(SG(request_info).request_method, "HEAD") && + strcmp(SG(request_info).request_method, "GET") + ) { sapi_update_response_code(303 TSRMLS_CC); } else { sapi_update_response_code(302 TSRMLS_CC); @@ -754,7 +737,6 @@ return SUCCESS; } - SAPI_API int sapi_send_headers(TSRMLS_D) { int retval; @@ -764,9 +746,8 @@ return SUCCESS; } - /* Success-oriented. We set headers_sent to 1 here to avoid an infinite loop - * in case of an error situation. - */ + /* Success-oriented. We set headers_sent to 1 here to avoid an infinite loop + * in case of an error situation. */ if (SG(sapi_headers).send_default_content_type && sapi_module.send_headers) { sapi_header_struct default_header; sapi_get_default_content_type_header(&default_header TSRMLS_CC); @@ -799,7 +780,7 @@ sapi_module.send_header(&http_status_line, SG(server_context) TSRMLS_CC); } zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) sapi_module.send_header, SG(server_context) TSRMLS_CC); - if(SG(sapi_headers).send_default_content_type) { + if (SG(sapi_headers).send_default_content_type) { sapi_header_struct default_header; sapi_get_default_content_type_header(&default_header TSRMLS_CC); @@ -814,13 +795,11 @@ ret = FAILURE; break; } - sapi_send_headers_free(TSRMLS_C); return ret; } - SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entries TSRMLS_DC) { sapi_post_entry *p=post_entries; @@ -834,16 +813,13 @@ return SUCCESS; } - SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry TSRMLS_DC) { if (SG(sapi_started) && EG(in_execution)) { return FAILURE; } - return zend_hash_add(&SG(known_post_content_types), - post_entry->content_type, post_entry->content_type_len+1, - (void *) post_entry, sizeof(sapi_post_entry), NULL); + return zend_hash_add(&SG(known_post_content_types), post_entry->content_type, post_entry->content_type_len + 1, (void *) post_entry, sizeof(sapi_post_entry), NULL); } SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry TSRMLS_DC) @@ -851,11 +827,9 @@ if (SG(sapi_started) && EG(in_execution)) { return; } - zend_hash_del(&SG(known_post_content_types), post_entry->content_type, - post_entry->content_type_len+1); + zend_hash_del(&SG(known_post_content_types), post_entry->content_type, post_entry->content_type_len+1); } - SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRMLS_D)) { TSRMLS_FETCH(); @@ -866,7 +840,6 @@ return SUCCESS; } - SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC)) { TSRMLS_FETCH(); @@ -912,8 +885,9 @@ SAPI_API char *sapi_getenv(char *name, size_t name_len TSRMLS_DC) { - if (sapi_module.getenv) { + if (sapi_module.getenv) { char *value, *tmp = sapi_module.getenv(name, name_len TSRMLS_CC); + if (tmp) { value = estrdup(tmp); } else { @@ -922,7 +896,7 @@ sapi_module.input_filter(PARSE_ENV, name, &value, strlen(value), NULL TSRMLS_CC); return value; } - return NULL; + return NULL; } SAPI_API int sapi_get_fd(int *fd TSRMLS_DC) @@ -943,7 +917,6 @@ } } - SAPI_API int sapi_get_target_uid(uid_t *obj TSRMLS_DC) { if (sapi_module.get_target_uid) { @@ -964,8 +937,9 @@ SAPI_API time_t sapi_get_request_time(TSRMLS_D) { - if(SG(global_request_time)) return SG(global_request_time); - + if (SG(global_request_time)) { + return SG(global_request_time); + } if (sapi_module.get_request_time && SG(server_context)) { SG(global_request_time) = sapi_module.get_request_time(TSRMLS_C); } else { @@ -974,7 +948,8 @@ return SG(global_request_time); } -SAPI_API void sapi_terminate_process(TSRMLS_D) { +SAPI_API void sapi_terminate_process(TSRMLS_D) +{ if (sapi_module.terminate_process) { sapi_module.terminate_process(TSRMLS_C); }
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php