Re: new networking code, filenames/locations okay?
| From: | Stig Venaas | Date: | Sun, 03 Sep 2000 10:14:45 +0000 |
| Subject: | Re: new networking code, filenames/locations okay? | ||
| References: | 1 2 3 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-31761@lists.php.net to get a copy of this message | ||
Hi
On Wed, Aug 30, 2000 at 12:35:52AM +0200, Stig Venaas wrote:
> On Tue, Aug 29, 2000 at 09:49:53PM +0200, Hartmut Holzgraefe wrote:
> > 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?
I've committed the hostconnect code now, hope you'll add your code
soon then. Here's what I planned to change in fopen-wrappers.c:
=========================================================================
--- /src/cvs/php4/main/fopen-wrappers.c Fri Sep 1 08:24:20 2000
+++ fopen-wrappers.c Sun Sep 3 11:21:20 2000
@@ -42,6 +42,7 @@
#include "ext/standard/head.h"
#include "ext/standard/php_standard.h"
#include "zend_compile.h"
+#include "php_network.h"
#if HAVE_PWD_H
#ifdef PHP_WIN32
@@ -476,7 +477,6 @@
{
FILE *fp=NULL;
php_url *resource=NULL;
- struct sockaddr_in server;
char tmp_line[512];
char location[512];
char hdr_line[8192];
@@ -496,29 +496,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);
@@ -643,7 +629,6 @@
{
FILE *fp=NULL;
php_url *resource=NULL;
- struct sockaddr_in server;
char tmp_line[512];
unsigned short portno;
char *scratch;
@@ -666,24 +651,9 @@
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);
@@ -879,27 +849,11 @@
SOCK_FCLOSE(*socketd);
/* open the data channel */
- *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)) {
- free_url(resource);
+ *socketd = hostconnect(resource->host, portno, SOCK_STREAM);
+ if (*socketd == -1) {
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
=========================================================================
There is a problem with the ftp wrapper. With Troll ftpd, and perhaps some
others, I don't get the entire file. I think the reason might be that we
close the control connection before opening the data connection. There
could be something else though.
For an example, try:
$fp = fopen("ftp://ftp.venaas.priv.no/pub/rfc/rfc-index.txt",
"r");
fpassthru($fp);
//while ($buf = fread($fp, 1024))
// echo $buf;
//fclose($fp);
If you replace fpassthru with the other code, same happens.
Stig