cvs: php3 / fopen-wrappers.h /functions fsock.c

From: Date: Thu, 19 Jul 2001 14:03:13 +0000
Subject: cvs: php3 / fopen-wrappers.h /functions fsock.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-6266@lists.php.net to get a copy of this message
martin Thu Jul 19 10:03:13 2001 EDT Modified files: /php3/functions fsock.c /php3 fopen-wrappers.h Log: Enable "fopen wrappers" for EBCDIC based machines. This used to fail because no conversion at all was applied to the sockets, so a call to fopen("http://some.url/",...) would send an HTTP request in EBCDIC :-( Restrictions for current hack: a) Only "text" requests work, and only if you retrieve the file from the open socket using fgets(). I.e., you cannot use fpassthru(), and you cannot fopen("http://some/file.gif",...) b) ftp requests may work, but I was unable to test it. The code lacks decent error messages for the zillions of possible errors which can occur during connection opening. c) Not only are fopen(URL) calls affected, but all socket calls which try to use fgets() to read from a socket opened by fsockopen(). AFAIK nobody used socket calls from ebcdic-php yet.... A cleaner solution which tracks the conversion state for all access function can be implemented in php4 - hopefully soon?!? Index: php3/functions/fsock.c diff -u php3/functions/fsock.c:1.135 php3/functions/fsock.c:1.136 --- php3/functions/fsock.c:1.135 Fri Dec 31 23:31:15 1999 +++ php3/functions/fsock.c Thu Jul 19 10:03:12 2001 @@ -27,7 +27,7 @@ | Jim Winstead (jimw@php.net) | +----------------------------------------------------------------------+ */ -/* $Id: fsock.c,v 1.135 2000/01/01 04:31:15 sas Exp $ */ +/* $Id: fsock.c,v 1.136 2001/07/19 14:03:12 martin Exp $ */ #include "php.h" #include "php3_list.h" #include "internal_functions.h" @@ -103,6 +103,9 @@ char persistent; char is_blocked; size_t chunk_size; +#ifdef CHARSET_EBCDIC + int binary; /* (Currently unused) Future enhancement: mark sockets as "binary" vs. "text". */ +#endif }; static struct php3i_sockbuf *phpsockbuf; @@ -602,7 +605,14 @@ if(!p) { if(sock->is_blocked) { while(!p && !sock->eof && TOREAD(sock) < maxlen - 1) { +#ifndef CHARSET_EBCDIC + _php3_sock_read_internal(sock); +#else + size_t wpos = sock->writepos; /* remember current writepos */ _php3_sock_read_internal(sock); + /* Translate newly read data */ + ascii2ebcdic(&sock->readbuf[wpos],&sock->readbuf[wpos],sock->writepos - wpos); +#endif SEARCHCR; } } else { @@ -684,6 +694,25 @@ return ret; } + +#ifdef CHARSET_EBCDIC +int _php3_sock_fputs(char *buf, int socket) +{ + size_t amount = strlen(buf), len; + int ret = 0; + char ebuf[CHUNK_SIZE]; + + while (amount && ret >= 0) + { + len = (amount > sizeof(ebuf)) ? sizeof(ebuf) : amount; + ebcdic2ascii(ebuf, buf, len); + ret = send(socket, ebuf, len, 0); + amount -= len; + buf += len; + } + return ret; +} +#endif /* EBCDIC */ /* {{{ module start/shutdown functions */ Index: php3/fopen-wrappers.h diff -u php3/fopen-wrappers.h:1.27 php3/fopen-wrappers.h:1.28 --- php3/fopen-wrappers.h:1.27 Fri Dec 31 23:44:07 1999 +++ php3/fopen-wrappers.h Thu Jul 19 10:03:13 2001 @@ -26,7 +26,7 @@ | Authors: Jim Winstead <jimw@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: fopen-wrappers.h,v 1.27 2000/01/01 04:44:07 sas Exp $ */ +/* $Id: fopen-wrappers.h,v 1.28 2001/07/19 14:03:13 martin Exp $ */ #ifndef _FOPEN_WRAPPERS_H #define _FOPEN_WRAPPERS_H @@ -58,6 +58,11 @@ #define SOCK_FEOF(sock) _php3_sock_feof((sock)) #define SOCK_FREAD(ptr,size,sock) _php3_sock_fread((ptr),(size),(sock)) #define SOCK_FCLOSE(s) _php3_sock_close(s) + +#ifdef CHARSET_EBCDIC +#undef SOCK_WRITE +#define SOCK_WRITE(d,s) _php3_sock_fputs(d,s) /* This function is used for TEXT connections only (not binary) */ +#endif /* values for issock */ #define IS_NOT_SOCKET 0

« previous php.cvs (#6266) next »