cvs: php4 / NEWS /ext/standard basic_functions.c fsock.c http_fopen_wrapper.c /main fopen-wrappers.c

From: Date: Sat, 28 Oct 2000 01:31:57 +0000
Subject: cvs: php4 / NEWS /ext/standard basic_functions.c fsock.c http_fopen_wrapper.c /main fopen-wrappers.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-2324@lists.php.net to get a copy of this message
zeev Fri Oct 27 18:31:57 2000 EDT Modified files: /php4 NEWS /php4/ext/standard basic_functions.c fsock.c http_fopen_wrapper.c /php4/main fopen-wrappers.c Log: - URL-opened files now store the HTTP response header in $http_response_header - Some layout updates

Index: php4/NEWS diff -u php4/NEWS:1.494 php4/NEWS:1.495 --- php4/NEWS:1.494 Fri Oct 27 18:09:08 2000 +++ php4/NEWS Fri Oct 27 18:31:56 2000 @@ -3,6 +3,8 @@ ?? ??? 2000, Version 4.0.4 +- URL-opened files now store the HTTP response header in $http_response_header + (Zeev) - Fixed array_rand() to shuffle results when the number of requested elements is the same as the number of elements in the array. (Andrei) - Added replace parameter to header() (Sascha) Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.269 php4/ext/standard/basic_functions.c:1.270 --- php4/ext/standard/basic_functions.c:1.269 Wed Oct 25 10:40:10 2000 +++ php4/ext/standard/basic_functions.c Fri Oct 27 18:31:56 2000 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.269 2000/10/25 17:40:10 andrei Exp $ */ +/* $Id: basic_functions.c,v 1.270 2000/10/28 01:31:56 zeev Exp $ */ #include "php.h" #include "php_main.h" @@ -724,14 +724,14 @@ #endif if(PG(allow_url_fopen)) { - if(FAILURE==php_register_url_wrapper("http",php_fopen_url_wrap_http)) { + if (FAILURE==php_register_url_wrapper("http", php_fopen_url_wrap_http)) { return FAILURE; } - if(FAILURE==php_register_url_wrapper("ftp",php_fopen_url_wrap_ftp)) { - return FAILURE; + if (FAILURE==php_register_url_wrapper("ftp", php_fopen_url_wrap_ftp)) { + return FAILURE; } - if(FAILURE==php_register_url_wrapper("php",php_fopen_url_wrap_php)) { - return FAILURE; + if (FAILURE==php_register_url_wrapper("php", php_fopen_url_wrap_php)) { + return FAILURE; } } Index: php4/ext/standard/fsock.c diff -u php4/ext/standard/fsock.c:1.54 php4/ext/standard/fsock.c:1.55 --- php4/ext/standard/fsock.c:1.54 Wed Oct 18 06:41:42 2000 +++ php4/ext/standard/fsock.c Fri Oct 27 18:31:56 2000 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: fsock.c,v 1.54 2000/10/18 13:41:42 venaas Exp $ */ +/* $Id: fsock.c,v 1.55 2000/10/28 01:31:56 zeev Exp $ */ /* Synced with php 3.0 revision 1.121 1999-06-18 [ssb] */ /* Synced with php 3.0 revision 1.133 1999-07-21 [sas] */ @@ -649,8 +649,9 @@ /* signal error only, if we don't return data from this call and if there is no data to read and if the eof flag is set */ - if(amount || TOREAD(sock) || !sock->eof) + if(amount || TOREAD(sock) || !sock->eof) { ret = buf; + } return ret; } Index: php4/ext/standard/http_fopen_wrapper.c diff -u php4/ext/standard/http_fopen_wrapper.c:1.2 php4/ext/standard/http_fopen_wrapper.c:1.3 --- php4/ext/standard/http_fopen_wrapper.c:1.2 Fri Oct 13 02:13:00 2000 +++ php4/ext/standard/http_fopen_wrapper.c Fri Oct 27 18:31:56 2000 @@ -17,7 +17,7 @@ | Hartmut Holzgraefe <hholzgra@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: http_fopen_wrapper.c,v 1.2 2000/10/13 09:13:00 dbeu Exp $ */ +/* $Id: http_fopen_wrapper.c,v 1.3 2000/10/28 01:31:56 zeev Exp $ */ #include "php.h" #include "php_globals.h" @@ -64,11 +64,13 @@ #include "php_fopen_wrappers.h" +#define HTTP_HEADER_BLOCK_SIZE 128 + FILE *php_fopen_url_wrap_http(char *path, char *mode, int options, int *issock, int *socketd, char **opened_path) { FILE *fp=NULL; php_url *resource=NULL; - char tmp_line[512]; + char tmp_line[128]; char location[512]; char hdr_line[8192]; int body = 0; @@ -76,6 +78,9 @@ unsigned char *tmp; int len; int reqok = 0; + zval *response_header; + char *http_header_line; + int http_header_line_length, http_header_line_size; resource = url_parse((char *) path); if (resource == NULL) { @@ -84,8 +89,9 @@ return NULL; } /* use port 80 if one wasn't specified */ - if (resource->port == 0) + if (resource->port == 0) { resource->port = 80; + } *socketd = php_hostconnect(resource->host, resource->port, SOCK_STREAM, 0); if (*socketd == -1) { @@ -171,36 +177,96 @@ body = 0; location[0] = '\0'; + + MAKE_STD_ZVAL(response_header); + array_init(response_header); + if (!SOCK_FEOF(*socketd)) { /* get response header */ if (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, *socketd) != NULL) { + zval *http_response; + + MAKE_STD_ZVAL(http_response); if (strncmp(tmp_line + 8, " 200 ", 5) == 0) { reqok = 1; } + Z_STRLEN_P(http_response) = strlen(tmp_line); + Z_STRVAL_P(http_response) = estrndup(tmp_line, Z_STRLEN_P(http_response)); + if (Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=='\n') { + Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=0; + Z_STRLEN_P(http_response)--; + if (Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=='\r') { + Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=0; + Z_STRLEN_P(http_response)--; + } + } + Z_TYPE_P(http_response) = IS_STRING; + zend_hash_next_index_insert(Z_ARRVAL_P(response_header), &http_response, sizeof(zval *), NULL); } } + + /* Read past HTTP headers */ while (!body && !SOCK_FEOF(*socketd)) { - if (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, *socketd) != NULL) { - char *p = tmp_line; + http_header_line = emalloc(HTTP_HEADER_BLOCK_SIZE); + http_header_line_size = HTTP_HEADER_BLOCK_SIZE; + http_header_line_length = 0; + if (SOCK_FGETS(http_header_line, HTTP_HEADER_BLOCK_SIZE-1, *socketd) != NULL) { + char *p; + zend_bool found_eol=0; + zval *http_header; - tmp_line[sizeof(tmp_line)-1] = '\0'; + http_header_line[HTTP_HEADER_BLOCK_SIZE-1] = '\0'; - while (*p) { - if (*p == '\n' || *p == '\r') { - *p = '\0'; + do { + p = http_header_line+http_header_line_length; + while (*p) { + while (*p == '\n' || *p == '\r') { + *p = '\0'; + p--; + found_eol=1; + } + if (found_eol) { + break; + } + p++; } - p++; - } + if (!found_eol) { + http_header_line_size += HTTP_HEADER_BLOCK_SIZE; + http_header_line_length += HTTP_HEADER_BLOCK_SIZE-1; + http_header_line = erealloc(http_header_line, http_header_line_size); + if (SOCK_FGETS(http_header_line+http_header_line_length, HTTP_HEADER_BLOCK_SIZE-1, *socketd)==NULL) { + http_header_line[http_header_line_length] = 0; + break; + } + } else { + http_header_line_length = p-http_header_line+1; + } + } while (!found_eol); - if (!strncasecmp(tmp_line, "Location: ", 10)) { - strlcpy(location, tmp_line + 10, sizeof(location)); + if (!strncasecmp(http_header_line, "Location: ", 10)) { + strlcpy(location, http_header_line + 10, sizeof(location)); } - if (tmp_line[0] == '\0') { - body = 1; + if (http_header_line[0] == '\0') { + body = 1; } + + if (http_header_line_length>0) { + MAKE_STD_ZVAL(http_header); + Z_STRVAL_P(http_header) = http_header_line; + Z_STRLEN_P(http_header) = http_header_line_length; + Z_TYPE_P(http_header) = IS_STRING; + zend_hash_next_index_insert(Z_ARRVAL_P(response_header), &http_header, sizeof(zval *), NULL); + } else { + efree(http_header_line); + } } + } + { + ELS_FETCH(); + + zend_hash_update(EG(active_symbol_table), "http_response_header", sizeof("http_response_header"), (void **) &response_header, sizeof(zval *), NULL); } if (!reqok) { SOCK_FCLOSE(*socketd); Index: php4/main/fopen-wrappers.c diff -u php4/main/fopen-wrappers.c:1.101 php4/main/fopen-wrappers.c:1.102 --- php4/main/fopen-wrappers.c:1.101 Fri Oct 27 09:16:55 2000 +++ php4/main/fopen-wrappers.c Fri Oct 27 18:31:56 2000 @@ -16,7 +16,7 @@ | Jim Winstead <jimw@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: fopen-wrappers.c,v 1.101 2000/10/27 16:16:55 fmk Exp $ */ +/* $Id: fopen-wrappers.c,v 1.102 2000/10/28 01:31:56 zeev Exp $ */ #include "php.h" #include "php_globals.h" @@ -431,24 +431,26 @@ int n=0; - for(p=path;isalnum((int)*p);p++) + for (p=path; isalnum((int)*p); p++) { n++; - if((*p==':')&&(n>1)) { + } + if ((*p==':')&&(n>1)) { protocol=path; } - if(protocol) { + if (protocol) { php_fopen_url_wrapper_t *wrapper=NULL; - if(FAILURE==zend_hash_find(&fopen_url_wrappers_hash, (char *)protocol, n, (void **)&wrapper)) { + if (FAILURE==zend_hash_find(&fopen_url_wrappers_hash, (char *) protocol, n, (void **)&wrapper)) { wrapper=NULL; protocol=NULL; } - if(wrapper) + if (wrapper) { return (*wrapper)(path, mode, options, issock, socketd, opened_path); + } } - if( !protocol || !strncasecmp(protocol, "file",n)){ + if (!protocol || !strncasecmp(protocol, "file",n)){ PLS_FETCH(); *issock = 0;
« previous php.cvs (#2324) next »