Make fopen() work with URL's in Win32

This commit is contained in:
Andi Gutmans 1999-08-25 16:24:14 +00:00
parent c5d640d8af
commit 7a9ad9d0c8
5 changed files with 47 additions and 26 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -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);

View File

@ -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] == ' '));

View File

@ -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;