summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnantha Kesari H Y <hyanantha@php.net>2002-09-05 10:13:27 +0000
committerAnantha Kesari H Y <hyanantha@php.net>2002-09-05 10:13:27 +0000
commit77e2ed48346e8ed424c38a49b7ab006e45ecffb2 (patch)
tree9d44055ae295a91e5fd30a0acc194cce64146e1c
parent6c51af03e5f39af3dcb67ad25167d2c44ded6d88 (diff)
downloadphp-git-77e2ed48346e8ed424c38a49b7ab006e45ecffb2.tar.gz
NetWare related additions/modifications into FTP files
-rw-r--r--ext/ftp/ftp.c118
-rw-r--r--ext/ftp/php_ftp.c10
2 files changed, 124 insertions, 4 deletions
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c
index 6c7644f243..73675553c1 100644
--- a/ext/ftp/ftp.c
+++ b/ext/ftp/ftp.c
@@ -34,6 +34,23 @@
#include <time.h>
#ifdef PHP_WIN32
#include <winsock.h>
+#elif defined(NETWARE)
+#ifdef USE_WINSOCK /* Modified to use Winsock (NOVSOCK2.H), atleast for now */
+#include <novsock2.h>
+#else
+#ifdef NEW_LIBC
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#else
+#include <sys/socket.h>
+#endif
+#endif
+
+/* Below stuff to introduce delay so that sockets are freed */
+#define THREAD_SWITCH_DELAY 1000
+#define THREAD_SWITCH_WITH_DELAY NXThreadDelay(THREAD_SWITCH_DELAY)
+
#else
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
@@ -130,7 +147,11 @@ ftp_open(const char *host, short port, long timeout_sec TSRMLS_DC)
size = sizeof(ftp->localaddr);
memset(&ftp->localaddr, 0, size);
+#if defined(NETWARE) && !defined(USE_WINSOCK)
+ if (getsockname(ftp->fd, (struct sockaddr*) &ftp->localaddr, (unsigned int*)&size) == -1) {
+#else
if (getsockname(ftp->fd, (struct sockaddr*) &ftp->localaddr, &size) == -1) {
+#endif
perror("getsockname");
goto bail;
}
@@ -213,12 +234,30 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass)
return 0;
if (!ftp_getresp(ftp))
return 0;
+
+#if defined(NETWARE) && defined(USE_WINSOCK) /* Atleast for now, to allow sockets to be freed */
+ /*THREAD_SWITCH_WITH_DELAY;*/
+ printf ("PHP | ftp_login: response = %d\n", ftp->resp);
+#endif
+
if (ftp->resp == 230)
return 1;
if (ftp->resp != 331)
return 0;
+
+#if defined(NETWARE) && defined(USE_WINSOCK) /* Atleast for now, to allow sockets to be freed */
+ /*THREAD_SWITCH_WITH_DELAY;*/
+ printf ("PHP | ftp_login: sending password...\n");
+#endif
+
if (!ftp_putcmd(ftp, "PASS", pass))
return 0;
+
+#if defined(NETWARE) && defined(USE_WINSOCK) /* Atleast for now, to allow sockets to be freed */
+ /*THREAD_SWITCH_WITH_DELAY;*/
+ printf ("PHP | ftp_login: getting response...\n");
+#endif
+
if (!ftp_getresp(ftp))
return 0;
return (ftp->resp == 230);
@@ -833,6 +872,11 @@ ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const char *args)
int size;
char *data;
+#if defined(NETWARE) && defined(USE_WINSOCK) /* Atleast for now, to allow sockets to be freed */
+ /*THREAD_SWITCH_WITH_DELAY;*/
+ printf ("PHP | ftp_putcmd: building output buffer...\n");
+#endif
+
/* build the output buffer */
if (args && args[0]) {
/* "cmd args\r\n\0" */
@@ -848,6 +892,12 @@ ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const char *args)
}
data = ftp->outbuf;
+
+#if defined(NETWARE) && defined(USE_WINSOCK) /* Atleast for now, to allow sockets to be freed */
+ /*THREAD_SWITCH_WITH_DELAY;*/
+ printf ("PHP | ftp_putcmd: sending data...\n");
+#endif
+
if (my_send(ftp, ftp->fd, data, size) != size)
return 0;
@@ -896,6 +946,11 @@ ftp_readline(ftpbuf_t *ftp)
}
}
+#if defined(NETWARE) && defined(USE_WINSOCK) /* Atleast for now, to allow sockets to be freed */
+ /*THREAD_SWITCH_WITH_DELAY;*/
+ printf ("PHP | ftp_readline: receiving data...\n");
+#endif
+
data = eol;
if ((rcvd = my_recv(ftp, ftp->fd, data, size)) < 1) {
return 0;
@@ -917,6 +972,11 @@ ftp_getresp(ftpbuf_t *ftp)
buf = ftp->inbuf;
ftp->resp = 0;
+#if defined(NETWARE) && defined(USE_WINSOCK) /* Atleast for now, to allow sockets to be freed */
+ /*THREAD_SWITCH_WITH_DELAY;*/
+ printf ("PHP | ftp_getresp: getting response...\n");
+#endif
+
while (1) {
if (!ftp_readline(ftp)) {
@@ -944,6 +1004,11 @@ ftp_getresp(ftpbuf_t *ftp)
10 * (ftp->inbuf[1] - '0') +
(ftp->inbuf[2] - '0');
+#if defined(NETWARE) && defined(USE_WINSOCK) /* Atleast for now, to allow sockets to be freed */
+ /*THREAD_SWITCH_WITH_DELAY;*/
+ printf ("PHP | ftp_getresp: response = %c%c%c\n", ftp->inbuf[0], ftp->inbuf[1], ftp->inbuf[2]);
+#endif
+
memmove(ftp->inbuf, ftp->inbuf + 4, FTP_BUFSIZE - 4);
if (ftp->extra)
@@ -969,15 +1034,38 @@ my_send(ftpbuf_t *ftp, int s, void *buf, size_t len)
FD_ZERO(&write_set);
FD_SET(s, &write_set);
+
+#if defined(NETWARE) && defined(USE_WINSOCK) /* Atleast for now, to allow sockets to be freed */
+ /*THREAD_SWITCH_WITH_DELAY;*/
+ printf ("PHP | my_send: calling select()...\n");
+#endif
+
n = select(s + 1, NULL, &write_set, NULL, &tv);
+
+#if defined(NETWARE) && defined(USE_WINSOCK) /* Atleast for now, to allow sockets to be freed */
+ /*THREAD_SWITCH_WITH_DELAY;*/
+ printf ("PHP | my_send: select() returned %d\n", n);
+#endif
+
if (n < 1) {
-#ifndef PHP_WIN32
+#if defined(NETWARE) && defined(USE_WINSOCK) /* Atleast for now, to allow sockets to be freed */
+ /*THREAD_SWITCH_WITH_DELAY;*/
+ printf ("PHP | my_send: error = %d\n", errno);
+#endif
+
+/*#ifndef PHP_WIN32*/
+#if !defined(PHP_WIN32) && !(defined(NETWARE) && defined(USE_WINSOCK))
if (n == 0)
errno = ETIMEDOUT;
#endif
return -1;
}
+#if defined(NETWARE) && defined(USE_WINSOCK) /* Atleast for now, to allow sockets to be freed */
+ /*THREAD_SWITCH_WITH_DELAY;*/
+ printf ("PHP | my_send: FTP request **%s**\n", buf);
+#endif
+
sent = send(s, buf, size, 0);
if (sent == -1)
return -1;
@@ -1004,9 +1092,16 @@ my_recv(ftpbuf_t *ftp, int s, void *buf, size_t len)
FD_ZERO(&read_set);
FD_SET(s, &read_set);
+
+#if defined(NETWARE) && defined(USE_WINSOCK) /* Atleast for now, to allow sockets to be freed */
+ /*THREAD_SWITCH_WITH_DELAY;*/
+ printf ("PHP | my_recv: calling select()...\n");
+#endif
+
n = select(s + 1, &read_set, NULL, NULL, &tv);
if (n < 1) {
-#ifndef PHP_WIN32
+/*#ifndef PHP_WIN32*/
+#if !defined(PHP_WIN32) && !(defined(NETWARE) && defined(USE_WINSOCK))
if (n == 0)
errno = ETIMEDOUT;
#endif
@@ -1033,7 +1128,8 @@ data_available(ftpbuf_t *ftp, int s)
FD_SET(s, &read_set);
n = select(s + 1, &read_set, NULL, NULL, &tv);
if (n < 1) {
-#ifndef PHP_WIN32
+/*#ifndef PHP_WIN32*/
+#if !defined(PHP_WIN32) && !(defined(NETWARE) && defined(USE_WINSOCK))
if (n == 0)
errno = ETIMEDOUT;
#endif
@@ -1084,16 +1180,26 @@ my_accept(ftpbuf_t *ftp, int s, struct sockaddr *addr, int *addrlen)
FD_ZERO(&accept_set);
FD_SET(s, &accept_set);
+#if defined(NETWARE) && defined(USE_WINSOCK) /* Atleast for now, to allow sockets to be freed */
+ /*THREAD_SWITCH_WITH_DELAY;*/
+ printf ("PHP | FTP: calling select()...\n");
+#endif
+
n = select(s + 1, &accept_set, NULL, NULL, &tv);
if (n < 1) {
-#ifndef PHP_WIN32
+/*#ifndef PHP_WIN32*/
+#if !defined(PHP_WIN32) && !(defined(NETWARE) && defined(USE_WINSOCK))
if (n == 0)
errno = ETIMEDOUT;
#endif
return -1;
}
+#if defined(NETWARE) && !defined(USE_WINSOCK)
+ return accept(s, addr, (unsigned int*)addrlen);
+#else
return accept(s, addr, addrlen);
+#endif
}
/* }}} */
@@ -1165,7 +1271,11 @@ ftp_getdata(ftpbuf_t *ftp)
goto bail;
}
+#if defined(NETWARE) && !defined(USE_WINSOCK)
+ if (getsockname(fd, (struct sockaddr*) &addr, (unsigned int*)&size) == -1) {
+#else
if (getsockname(fd, (struct sockaddr*) &addr, &size) == -1) {
+#endif
perror("getsockname");
goto bail;
}
diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c
index 5aeaa9cca5..d1aa51b45f 100644
--- a/ext/ftp/php_ftp.c
+++ b/ext/ftp/php_ftp.c
@@ -25,6 +25,16 @@
#include "php.h"
+#ifdef NETWARE
+#ifdef USE_WINSOCK
+#include <novsock2.h>
+#else
+#ifndef NEW_LIBC
+#include <sys/socket.h>
+#endif
+#endif
+#endif
+
#if HAVE_FTP
#include "ext/standard/info.h"