]> granicus.if.org Git - php/commitdiff
* Finally commit that -q patch
authorZeev Suraski <zeev@php.net>
Tue, 11 May 1999 20:38:16 +0000 (20:38 +0000)
committerZeev Suraski <zeev@php.net>
Tue, 11 May 1999 20:38:16 +0000 (20:38 +0000)
* Refine SAPI built in header support
* Use DllMain() in ISAPI to clean after threads and initialize tsrm/sapi as soon as possible.

cgi_main.c
ext/standard/head.c
ext/standard/head.h
main/SAPI.c
main/SAPI.h
php4dllts.dsp

index a73b427e01c2f029d5e5c74a1d92b33f49ad1a5a..a2e37a4f0318c9b76519bafa1dce498914a177d9 100644 (file)
@@ -170,6 +170,10 @@ static void init_request_info(SLS_D)
        }
        SG(request_info).content_type = getenv("CONTENT_TYPE");
        SG(request_info).content_length = (content_length?atoi(content_length):0);
+
+       /* CGI does not support HTTP authentication */
+       SG(request_info).auth_user = NULL;
+       SG(request_info).auth_password = NULL;
 }
 
 
@@ -182,6 +186,7 @@ int main(int argc, char *argv[])
        char *_cgi_filename=NULL;
        int _cgi_started=0;
        int behavior=PHP_MODE_STANDARD;
+       int no_headers=0;
 #if SUPPORT_INTERACTIVE
        int interactive=0;
 #endif
@@ -273,11 +278,14 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
                                                        return FAILURE;
                                                }
                                        }
+                                       if (no_headers) {
+                                               SG(headers_sent) = 1;
+                                       }
                                        _cgi_started=1;
                                        _cgi_filename = estrdup(optarg);
                                        /* break missing intentionally */
                                case 'q':
-                                       php3_noheader();
+                                       no_headers = 1;
                                        break;
                                case 'v':
                                        if (!_cgi_started) {
@@ -286,6 +294,9 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
                                                        return FAILURE;
                                                }
                                        }
+                                       if (no_headers) {
+                                               SG(headers_sent) = 1;
+                                       }
                                        php3_printf("%s\n", PHP_VERSION);
                                        exit(1);
                                        break;
@@ -296,6 +307,9 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
                                                        return FAILURE;
                                                }
                                        }
+                                       if (no_headers) {
+                                               SG(headers_sent) = 1;
+                                       }
                                        _cgi_started=1;
                                        php3_TreatHeaders();
                                        _php3_info();
@@ -323,8 +337,8 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
                                        break;
                                case 'h':
                                case '?':
-                                       php3_noheader();
                                        zend_output_startup();
+                                       SG(headers_sent) = 1;
                                        php_cgi_usage(argv[0]);
                                        exit(1);
                                        break;
@@ -344,6 +358,9 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
                        return FAILURE;
                }
        }
+       if (no_headers) {
+               SG(headers_sent) = 1;
+       }
        file_handle.filename = "-";
        file_handle.type = ZEND_HANDLE_FP;
        file_handle.handle.fp = stdin;
index 86e3a7d835da4d68addcf343beae0d3dd24f6c1c..4d8b586f232048c6fd6d9c7b98b7a3168eed8d56 100644 (file)
@@ -69,13 +69,6 @@ int php3_init_head(INIT_FUNC_ARGS)
 }
 
 
-PHPAPI void php3_noheader(void)
-{
-       php3_PrintHeader = 0;
-       header_called = 1;
-}
-
-
 #if 0
 /* Adds header information */
 void php4i_add_header_information(char *header_information, uint header_length)
index 3ab12d0d84ef8454d5a523ccc4539822a5137638..37db395e2cc899706d7b3f7594a789b78c622cc3 100644 (file)
@@ -58,7 +58,6 @@ extern void php3_SetCookie(INTERNAL_FUNCTION_PARAMETERS);
 
 void php4i_add_header_information(char *header_information, uint header_length);
 
-PHPAPI void php3_noheader(void);
 PHPAPI int php3_header(void);
 int php3_headers_unsent(void);
 
index b0315f28b9f752a08955e5f0fd997632eecd6a53..87be2e3fe8684480d06f4dbba5b3b11324894de5 100644 (file)
@@ -91,14 +91,14 @@ SAPI_API void sapi_activate(SLS_D)
        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_status_line = NULL;
        SG(headers_sent) = 0;
        SG(read_post_bytes) = 0;
+       SG(request_info).post_data = NULL;
        if (SG(server_context)) {
                if (SG(request_info).request_method 
                        && !strcmp(SG(request_info).request_method, "POST")) {
                        sapi_read_post_data(SLS_C);
-               } else {
-                       SG(request_info).post_data = NULL;
                }
                SG(request_info).cookie_data = sapi_module.read_cookies(SLS_C);
        }
@@ -108,9 +108,17 @@ SAPI_API void sapi_activate(SLS_D)
 SAPI_API void sapi_deactivate(SLS_D)
 {
        zend_llist_destroy(&SG(sapi_headers).headers);
-       if (SG(server_context) && SG(request_info).post_data) {
+       if (SG(request_info).post_data) {
                efree(SG(request_info).post_data);
        }
+       if (SG(server_context)) {
+               if (SG(request_info).auth_user) {
+                       efree(SG(request_info).auth_user);
+               }
+               if (SG(request_info).auth_password) {
+                       efree(SG(request_info).auth_password);
+               }
+       }
 }
 
 
@@ -133,15 +141,22 @@ SAPI_API int sapi_add_header(char *header_line, uint header_line_len)
        sapi_header.header = header_line;
        sapi_header.header_len = header_line_len;
 
-       colon_offset = strchr(header_line, ':');
-       if (colon_offset) {
-               *colon_offset = 0;
-               if (!STRCASECMP(header_line, "Content-Type")) {
-                       SG(sapi_headers).send_default_content_type = 0;
-               } else if (!STRCASECMP(header_line, "Location")) {
-                       SG(sapi_headers).http_response_code = 302; /* redirect */
+       /* Check the header for a few cases that we have special support for in SAPI */
+       if (!memcmp(header_line, "HTTP/", 5)) {
+               SG(sapi_headers).http_status_line = header_line;
+       } else {
+               colon_offset = strchr(header_line, ':');
+               if (colon_offset) {
+                       *colon_offset = 0;
+                       if (!STRCASECMP(header_line, "Content-Type")) {
+                               SG(sapi_headers).send_default_content_type = 0;
+                       } else if (!STRCASECMP(header_line, "Location")) {
+                               SG(sapi_headers).http_response_code = 302; /* redirect */
+                       } else if (!STRCASECMP(header_line, "WWW-Authenticate")) { /* HTTP Authentication */
+                               SG(sapi_headers).http_response_code = 401; /* authentication-required */
+                       }
+                       *colon_offset = ':';
                }
-               *colon_offset = ':';
        }
 
        if (sapi_module.header_handler) {
@@ -182,6 +197,14 @@ SAPI_API int sapi_send_headers()
                        return SUCCESS;
                        break;
                case SAPI_HEADER_DO_SEND:
+                       if (SG(sapi_headers).http_status_line) {
+                               sapi_header_struct http_status_line;
+
+                               http_status_line.header = SG(sapi_headers).http_status_line;
+                               http_status_line.header_len = strlen(SG(sapi_headers).http_status_line);
+                               sapi_module.send_header(&http_status_line, SG(server_context));
+                               efree(SG(sapi_headers).http_status_line);
+                       }
                        if (SG(sapi_headers).send_default_content_type) {
                                sapi_module.send_header(&default_header, SG(server_context));
                        }
index 0ea9b8d8c730d1a85e962ff8cd2676e58dcf4fba..6b460c1ac22e32add7b5c4a7fe81b6b5f0ac574a 100644 (file)
@@ -27,6 +27,7 @@ typedef struct {
        zend_llist headers;
        int http_response_code;
        unsigned char send_default_content_type;
+       char *http_status_line;
 } sapi_headers_struct;
 
 
@@ -49,6 +50,10 @@ typedef struct {
        char *content_type;
 
        unsigned char headers_only;
+
+       /* for HTTP authentication */
+       char *auth_user;
+       char *auth_password;
 } sapi_request_info;
 
 
index e4a7558381f849e283f4ccc848c3ba1d956f6a27..e770189ba60f7b97c64f6ce78fbd8928744a28d8 100644 (file)
@@ -211,6 +211,10 @@ SOURCE=.\php_ini.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\php_regex.h\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\ext\standard\quot_print.h\r
 # End Source File\r
 # Begin Source File\r