Re: new networking code, filenames/locations okay?
| From: | Stig Venaas | Date: | Tue, 29 Aug 2000 22:35:52 +0000 |
| Subject: | Re: new networking code, filenames/locations okay? | ||
| References: | 1 2 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-31144@lists.php.net to get a copy of this message | ||
On Tue, Aug 29, 2000 at 09:49:53PM +0200, Hartmut Holzgraefe wrote:
> Stig Venaas wrote:
> > So far I've rewritten php_fopen_url_wrap_http and php_fopen_url_wrap_ftp
> > to use hostconnect.
> >
> > I'm going to add this soon, now that 4.0.2 finally is out.
>
> i already have moverd theese out of fopen_wrappers.c to seperate files
> and want to check them in as soon as ...
>
> maybe you can send me the diffs for php_fopen_url_wrap_http and
> php_fopen_url_wrap_ftp and i put it in alltogether ... ?
I'll wait a few days, if you want to add them before I add hostconnect,
just do it, and I'll update yours, okay?
But well, here's an old diff of the new not so well tested version (just to
give you an impression of what happens):
--- fopen-wrappers.c Sun Aug 13 17:56:26 2000
+++ /src/php4-network/fopen-wrappers.c Sat Aug 12 14:45:11 2000
@@ -40,6 +40,7 @@
#include "safe_mode.h"
#include "php_realpath.h"
+#include "php_network.h"
#include "ext/standard/head.h"
#include "ext/standard/php_standard.h"
#include "zend_compile.h"
@@ -514,7 +515,6 @@
{
FILE *fp=NULL;
php_url *resource=NULL;
- struct sockaddr_in server;
char tmp_line[512];
char location[512];
char hdr_line[8192];
@@ -534,29 +534,15 @@
if (resource->port == 0)
resource->port = 80;
- *socketd = socket(AF_INET, SOCK_STREAM, 0);
- if (*socketd == SOCK_ERR) {
- SOCK_FCLOSE(*socketd);
- *socketd = 0;
- free_url(resource);
- return NULL;
- }
- server.sin_family = AF_INET;
-
- if (lookup_hostname(resource->host, &server.sin_addr)) {
+ *socketd = hostconnect(resource->host, resource->port, SOCK_STREAM);
+
+ if (*socketd == -1) {
SOCK_FCLOSE(*socketd);
*socketd = 0;
free_url(resource);
return NULL;
}
- server.sin_port = htons(resource->port);
- if (connect(*socketd, (struct sockaddr *) &server, sizeof(server)) == SOCK_CONN_ERR) {
- SOCK_FCLOSE(*socketd);
- *socketd = 0;
- free_url(resource);
- return NULL;
- }
#if 0
if ((fp = fdopen(*socketd, "r+")) == NULL) {
free_url(resource);
@@ -681,7 +667,6 @@
{
FILE *fp=NULL;
php_url *resource=NULL;
- struct sockaddr_in server;
char tmp_line[512];
unsigned short portno;
char *scratch;
@@ -704,29 +689,15 @@
if (resource->port == 0)
resource->port = 21;
- *socketd = socket(AF_INET, SOCK_STREAM, 0);
- if (*socketd == SOCK_ERR) {
- SOCK_FCLOSE(*socketd);
- *socketd = 0;
- free_url(resource);
- return NULL;
- }
- server.sin_family = AF_INET;
-
- if (lookup_hostname(resource->host, &server.sin_addr)) {
- SOCK_FCLOSE(*socketd);
- *socketd = 0;
- free_url(resource);
- return NULL;
- }
- server.sin_port = htons(resource->port);
-
- if (connect(*socketd, (struct sockaddr *) &server, sizeof(server)) == SOCK_CONN_ERR) {
+ *socketd = hostconnect(resource->host, resource->port, SOCK_STREAM);
+
+ if (*socketd == -1) {
SOCK_FCLOSE(*socketd);
*socketd = 0;
free_url(resource);
return NULL;
}
+
#if 0
if ((fpc = fdopen(*socketd, "r+")) == NULL) {
free_url(resource);
@@ -917,27 +888,11 @@
SOCK_FCLOSE(*socketd);
/* open the data channel */
- *socketd = socket(AF_INET, SOCK_STREAM, 0);
- if (*socketd == SOCK_ERR) {
+ *socketd = hostconnect(resource->host, portno, SOCK_STREAM);
+ if (*socketd == -1) {
SOCK_FCLOSE(*socketd);
*socketd = 0;
free_url(resource);
- return NULL;
- }
- server.sin_family = AF_INET;
-
- if (lookup_hostname(resource->host, &server.sin_addr)) {
- free_url(resource);
- SOCK_FCLOSE(*socketd);
- *socketd = 0;
- return NULL;
- }
- server.sin_port = htons(portno);
-
- if (connect(*socketd, (struct sockaddr *) &server, sizeof(server)) == SOCK_CONN_ERR) {
- free_url(resource);
- SOCK_FCLOSE(*socketd);
- *socketd = 0;
return NULL;
}
#if 0