diff options
| author | Andi Gutmans <andi@php.net> | 1999-08-25 16:24:14 +0000 |
|---|---|---|
| committer | Andi Gutmans <andi@php.net> | 1999-08-25 16:24:14 +0000 |
| commit | 7a9ad9d0c81ef11fa05a69c1819c4377c4b93cd0 (patch) | |
| tree | cc331dbc4a72610fc52f79398c11daa349525dab | |
| parent | c5d640d8af3b16cebbb756a6c39b19d3bf7d7676 (diff) | |
| download | php-git-7a9ad9d0c81ef11fa05a69c1819c4377c4b93cd0.tar.gz | |
Make fopen() work with URL's in Win32
| -rw-r--r-- | ChangeLog | 1 | ||||
| -rw-r--r-- | ext/standard/fsock.c | 27 | ||||
| -rw-r--r-- | ext/standard/fsock.h | 19 | ||||
| -rw-r--r-- | main/fopen_wrappers.c | 8 | ||||
| -rw-r--r-- | main/main.c | 18 |
5 files changed, 47 insertions, 26 deletions
@@ -2,6 +2,7 @@ PHP 4.0 CHANGE LOG ChangeLog ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ?? 1999, Version 4.0 Beta 3 +- Make fopen() work with URL's in Win32 (Andi & Zeev) - Fix for include_path for Win32 (Andi, Zend library) - Fixed bug in ISAPI header sending function (Charles) - Fixed memory leak when using undefined values (Andi & Zeev, Zend library) diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c index c23ae5eef9..3a653af83f 100644 --- a/ext/standard/fsock.c +++ b/ext/standard/fsock.c @@ -74,8 +74,8 @@ extern int le_fp; #define FREE_SOCK if(socketd >= 0) close(socketd); efree(sock); if (key) efree(key) -#define SEARCHCR \ - p = memchr(READPTR(sock), '\n', MIN(TOREAD(sock), maxlen - 1)); +#define SEARCHCR() \ + p = memchr(READPTR(sock), '\n', MIN(TOREAD(sock), maxlen)); #if WIN32|WINNT #define EWOULDBLOCK WSAEWOULDBLOCK @@ -598,17 +598,22 @@ char *_php3_sock_fgets(char *buf, size_t maxlen, int socket) size_t amount = 0; SOCK_FIND(sock, socket); - SEARCHCR; + if (maxlen==0) { + buf[0] = 0; + return buf; + } + + SEARCHCR(); if(!p) { if(sock->is_blocked) { - while(!p && !sock->eof && TOREAD(sock) < maxlen - 1) { + while(!p && !sock->eof && TOREAD(sock) < maxlen) { _php3_sock_read_internal(sock); - SEARCHCR; + SEARCHCR(); } } else { _php3_sock_read(sock); - SEARCHCR; + SEARCHCR(); } } @@ -619,7 +624,7 @@ char *_php3_sock_fgets(char *buf, size_t maxlen, int socket) amount = TOREAD(sock); } - amount = MIN(amount, maxlen - 1); + amount = MIN(amount, maxlen); if(amount > 0) { memcpy(buf, READPTR(sock), amount); @@ -693,14 +698,12 @@ size_t _php3_sock_fread(char *ptr, size_t size, int socket) /* }}} */ /* {{{ module start/shutdown functions */ - /* {{{ _php3_sock_destroy */ -#ifndef ZTS -static int _php3_msock_destroy(int *data) + /* {{{ php_msock_destroy */ +int php_msock_destroy(int *data) { close(*data); return 1; } -#endif /* }}} */ /* {{{ php3_minit_fsock */ @@ -708,7 +711,7 @@ PHP_MINIT_FUNCTION(fsock) { #ifndef ZTS zend_hash_init(&PG(ht_fsock_keys), 0, NULL, NULL, 1); - zend_hash_init(&PG(ht_fsock_socks), 0, NULL, (int (*)(void *))_php3_msock_destroy, 1); + zend_hash_init(&PG(ht_fsock_socks), 0, NULL, (int (*)(void *))php_msock_destroy, 1); #endif return SUCCESS; } diff --git a/ext/standard/fsock.h b/ext/standard/fsock.h index 5b1a7047d5..aaa8be6a21 100644 --- a/ext/standard/fsock.h +++ b/ext/standard/fsock.h @@ -59,16 +59,17 @@ extern php3_module_entry fsock_module_entry; PHP_FUNCTION(fsockopen); PHP_FUNCTION(pfsockopen); -extern int lookup_hostname(const char *addr, struct in_addr *in); -extern char *_php3_sock_fgets(char *buf, size_t maxlen, int socket); -extern size_t _php3_sock_fread(char *buf, size_t maxlen, int socket); -extern int _php3_sock_feof(int socket); -extern int _php3_sock_fgetc(int socket); -extern int _php3_is_persistent_sock(int); -extern int _php3_sock_set_blocking(int socket, int mode); -extern int _php3_sock_destroy(int socket); -extern int _php3_sock_close(int socket); +int lookup_hostname(const char *addr, struct in_addr *in); +char *_php3_sock_fgets(char *buf, size_t maxlen, int socket); +size_t _php3_sock_fread(char *buf, size_t maxlen, int socket); +int _php3_sock_feof(int socket); +int _php3_sock_fgetc(int socket); +int _php3_is_persistent_sock(int); +int _php3_sock_set_blocking(int socket, int mode); +int _php3_sock_destroy(int socket); +int _php3_sock_close(int socket); size_t _php3_sock_set_def_chunk_size(size_t size); +int php_msock_destroy(int *data); PHPAPI int connect_nonb(int sockfd, struct sockaddr *addr, int addrlen, struct timeval *timeout); diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index b9cf243792..badbce3f60 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -561,7 +561,7 @@ static FILE *php3_fopen_url_wrapper(const char *path, char *mode, int options, i location[0] = '\0'; if (!SOCK_FEOF(*socketd)) { /* get response header */ - if (SOCK_FGETS(tmp_line, sizeof(tmp_line), *socketd) != NULL) { + if (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, *socketd) != NULL) { if (strncmp(tmp_line + 8, " 200 ", 5) == 0) { reqok = 1; } @@ -569,7 +569,7 @@ static FILE *php3_fopen_url_wrapper(const char *path, char *mode, int options, i } /* Read past HTTP headers */ while (!body && !SOCK_FEOF(*socketd)) { - if (SOCK_FGETS(tmp_line, sizeof(tmp_line), *socketd) != NULL) { + if (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, *socketd) != NULL) { char *p = tmp_line; tmp_line[sizeof(tmp_line)-1] = '\0'; @@ -760,7 +760,7 @@ static FILE *php3_fopen_url_wrapper(const char *path, char *mode, int options, i /* set up the passive connection */ SOCK_WRITE("PASV\n", *socketd); - while (SOCK_FGETS(tmp_line, sizeof(tmp_line), *socketd) && + while (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, *socketd) && !(isdigit((int) tmp_line[0]) && isdigit((int) tmp_line[1]) && isdigit((int) tmp_line[2]) && tmp_line[3] == ' ')); @@ -923,7 +923,7 @@ int _php3_getftpresult(int socketd) { char tmp_line[513]; - while (SOCK_FGETS(tmp_line, sizeof(tmp_line), socketd) && + while (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, socketd) && !(isdigit((int) tmp_line[0]) && isdigit((int) tmp_line[1]) && isdigit((int) tmp_line[2]) && tmp_line[3] == ' ')); diff --git a/main/main.c b/main/main.c index 8bd3ef9a2d..f7043c07cd 100644 --- a/main/main.c +++ b/main/main.c @@ -769,6 +769,22 @@ static void php_new_thread_end_handler(THREAD_T thread_id) #endif +#ifdef ZTS +static void core_globals_ctor(php_core_globals *core_globals) +{ + zend_hash_init(&core_globals->ht_fsock_keys, 0, NULL, NULL, 1); + zend_hash_init(&core_globals->ht_fsock_socks, 0, NULL, (int (*)(void *))php_msock_destroy, 1); +} + + +static void core_globals_dtor(php_core_globals *core_globals) +{ + zend_hash_destroy(&core_globals->ht_fsock_keys); + zend_hash_destroy(&core_globals->ht_fsock_socks); +} +#endif + + int php_module_startup(sapi_module_struct *sf) { zend_utility_functions zuf; @@ -809,7 +825,7 @@ int php_module_startup(sapi_module_struct *sf) #ifdef ZTS tsrm_set_new_thread_end_handler(php_new_thread_end_handler); executor_globals = ts_resource(executor_globals_id); - core_globals_id = ts_allocate_id(sizeof(php_core_globals), NULL, NULL); + core_globals_id = ts_allocate_id(sizeof(php_core_globals), core_globals_ctor, core_globals_dtor); core_globals = ts_resource(core_globals_id); #endif EG(error_reporting) = E_ALL & ~E_NOTICE; |
