CVS update: php4

From: Date: Fri, 18 Jun 1999 14:23:01 +0000
Subject: CVS update: php4
Groups: php.version4 
Request: Send a blank email to php-version4+get-1594@lists.php.net to get a copy of this message
Date: Friday June 18, 1999 @ 10:23 Author: ssb Update of /repository/php4 In directory php:/tmp/cvs-serv28749 Modified Files: fopen-wrappers.c Log Message: optimize php3_fopen_url_wrapper() a bit (fewer recv() and send() calls) Index: php4/fopen-wrappers.c diff -u php4/fopen-wrappers.c:1.17 php4/fopen-wrappers.c:1.18 --- php4/fopen-wrappers.c:1.17 Fri Jun 18 09:02:34 1999 +++ php4/fopen-wrappers.c Fri Jun 18 10:22:59 1999 @@ -27,7 +27,7 @@ | Jim Winstead <jimw@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: fopen-wrappers.c,v 1.17 1999/06/18 13:02:34 ssb Exp $ */ +/* $Id: fopen-wrappers.c,v 1.18 1999/06/18 14:22:59 ssb Exp $ */ /* Synced with php3 revision 1.62 1999-06-16 [ssb] */ @@ -442,22 +442,14 @@ char *scratch; unsigned char *tmp; - char tmp_line[513]; - char location[513]; - int chptr = 0; + char tmp_line[512]; + char location[512]; + char hdr_line[8192]; char *tpath, *ttpath; int body = 0; int reqok = 0; - int lineone = 1; int i; - char buf[2]; - char oldch1 = 0; - char oldch2 = 0; - char oldch3 = 0; - char oldch4 = 0; - char oldch5 = 0; - FILE *fp = NULL; struct sockaddr_in server; unsigned short portno; @@ -509,20 +501,22 @@ #endif #endif /*win32 */ + strcpy(hdr_line, "GET "); /* tell remote http which file to get */ - SOCK_WRITE("GET ", *socketd); if (resource->path != NULL) { - SOCK_WRITE(resource->path, *socketd); + strncat(hdr_line, resource->path, sizeof(hdr_line)); } else { - SOCK_WRITE("/", *socketd); + strncat(hdr_line, "/", sizeof(hdr_line)); } /* append the query string, if any */ if (resource->query != NULL) { - SOCK_WRITE("?", *socketd); - SOCK_WRITE(resource->query, *socketd); + strncat(hdr_line, "?", sizeof(hdr_line)); + strncat(hdr_line, resource->query, sizeof(hdr_line)); } - SOCK_WRITE(" HTTP/1.0\n", *socketd); + strncat(hdr_line, " HTTP/1.0\r\n", sizeof(hdr_line)); + hdr_line[sizeof(hdr_line)-1] = '\0'; + SOCK_WRITE(hdr_line, *socketd); /* send authorization header if we have user/pass */ if (resource->user != NULL && resource->pass != NULL) { @@ -536,77 +530,74 @@ strcat(scratch, resource->pass); tmp = _php3_base64_encode((unsigned char *)scratch, strlen(scratch), NULL); - SOCK_WRITE("Authorization: Basic ", *socketd); + strcpy(hdr_line, "Authorization: Basic "); /* output "user:pass" as base64-encoded string */ - SOCK_WRITE((char *)tmp, *socketd); - SOCK_WRITE("\n", *socketd); + strncat(hdr_line, (char *)tmp, sizeof(hdr_line)); + strncat(hdr_line, "\r\n", sizeof(hdr_line)); + hdr_line[sizeof(hdr_line)-1] = '\0'; + SOCK_WRITE(hdr_line, *socketd); efree(scratch); efree(tmp); } /* if the user has configured who they are, send a From: line */ if (cfg_get_string("from", &scratch) == SUCCESS) { - SOCK_WRITE("From: ", *socketd); - SOCK_WRITE(scratch, *socketd); - SOCK_WRITE("\n", *socketd); + strcpy(hdr_line, "From: "); + strncat(hdr_line, scratch, sizeof(hdr_line)); + strncat(hdr_line, "\r\n", sizeof(hdr_line)); + hdr_line[sizeof(hdr_line)-1] = '\0'; + SOCK_WRITE(hdr_line, *socketd); + } /* send a Host: header so name-based virtual hosts work */ - SOCK_WRITE("Host: ", *socketd); - SOCK_WRITE(resource->host, *socketd); - if(resource->port!=80) { - sprintf(tmp_line,"%i",resource->port); - SOCK_WRITE(":", *socketd); - SOCK_WRITE(tmp_line, *socketd); - } - SOCK_WRITE("\n", *socketd); - - /* identify ourselves */ - SOCK_WRITE("User-Agent: PHP/", *socketd); - SOCK_WRITE(PHP_VERSION, *socketd); - SOCK_WRITE("\n", *socketd); - - /* end the headers */ - SOCK_WRITE("\n", *socketd); + strcpy(hdr_line, "Host: "); + strncat(hdr_line, resource->host, sizeof(hdr_line)); + if (resource->port != 80) { + sprintf(tmp_line, "%i", resource->port); + strncat(hdr_line, ":", sizeof(hdr_line)); + strncat(hdr_line, tmp_line, sizeof(hdr_line)); + } + strncat(hdr_line, "\r\n", sizeof(hdr_line)); + hdr_line[sizeof(hdr_line)-1] = '\0'; + SOCK_WRITE(hdr_line, *socketd); + + /* identify ourselves and end the headers */ + strcpy(hdr_line, "User-Agent: PHP/"); + strncat(hdr_line, PHP_VERSION, sizeof(hdr_line)); + strncat(hdr_line, "\r\n\r\n", sizeof(hdr_line)); + hdr_line[sizeof(hdr_line)-1] = '\0'; + SOCK_WRITE(hdr_line, *socketd); - /* Read past http header */ body = 0; location[0] = '\0'; - while (!body && !SOCK_FEOF(*socketd)) { - if ((buf[0] = SOCK_FGETC(*socketd)) == EOF) { - SOCK_FCLOSE(*socketd); - *socketd = 0; - free_url(resource); - return NULL; + if (!SOCK_FEOF(*socketd)) { + /* get response header */ + if (SOCK_FGETS(tmp_line, sizeof(tmp_line), *socketd) != NULL) { + if (!strncmp(tmp_line + 8, " 200 ", 4)) { + reqok = 1; + } } - oldch5 = oldch4; - oldch4 = oldch3; - oldch3 = oldch2; - oldch2 = oldch1; - oldch1 = *buf; - - tmp_line[chptr++] = *buf; - if (*buf == 10 || *buf == 13) { - tmp_line[chptr] = '\0'; - chptr = 0; + } + /* Read past HTTP headers */ + while (!body && !SOCK_FEOF(*socketd)) { + if (SOCK_FGETS(tmp_line, sizeof(tmp_line), *socketd) != NULL) { + char *p = tmp_line; + + tmp_line[sizeof(tmp_line)-1] = '\0'; + + while (*p) { + if (*p == '\n' || *p == '\r') { + *p = '\0'; + } + p++; + } + if (!strncasecmp(tmp_line, "Location: ", 10)) { - tpath = tmp_line + 10; - strcpy(location, tpath); + strcpy(location, tmp_line + 10); } - } - if (lineone && (*buf == 10 || *buf == 13)) { - lineone = 0; - } - if (lineone && oldch5 == ' ' && oldch4 == '2' && oldch3 == '0' && - oldch2 == '0' && oldch1 == ' ') { - reqok = 1; - } - if (oldch4 == 13 && oldch3 == 10 && oldch2 == 13 && oldch1 == 10) { - body = 1; - } - if (oldch2 == 10 && oldch1 == 10) { - body = 1; - } - if (oldch2 == 13 && oldch1 == 13) { - body = 1; + + if (tmp_line[0] == '\0') { + body = 1; + } } } if (!reqok) {

« previous php.version4 (#1594) next »