mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-30 22:43:14 +03:00
Another patch from Wayne Davison:
- nanoftp.c nanohttp.c xmlIO.c: Win32 patch nanoftp code work now Daniel
This commit is contained in:
@ -1,4 +1,9 @@
|
|||||||
Fri Oct 13 02:54:37 CEST 2000 Daniel Veillard <Daniel.Veillard@w3.org>
|
Fri Oct 13 01:23:48 CEST 2000 Daniel Veillard <Daniel.Veillard@w3.org>
|
||||||
|
|
||||||
|
* nanoftp.c nanohttp.c xmlIO.c: Wayne Davison Win32 patch
|
||||||
|
nanoftp code work on Windows too now
|
||||||
|
|
||||||
|
Fri Oct 13 00:54:37 CEST 2000 Daniel Veillard <Daniel.Veillard@w3.org>
|
||||||
|
|
||||||
* testXPath.c xpath.[ch]: moved some debug functions to xpath core
|
* testXPath.c xpath.[ch]: moved some debug functions to xpath core
|
||||||
* xpointer.c: implemented string-range() at least a good first version
|
* xpointer.c: implemented string-range() at least a good first version
|
||||||
|
129
nanoftp.c
129
nanoftp.c
@ -71,6 +71,14 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A couple portability macros
|
||||||
|
*/
|
||||||
|
#ifndef _WINSOCKAPI_
|
||||||
|
#define closesocket(s) close(s)
|
||||||
|
#define SOCKET int
|
||||||
|
#endif
|
||||||
|
|
||||||
static char hostname[100];
|
static char hostname[100];
|
||||||
|
|
||||||
#define FTP_COMMAND_OK 200
|
#define FTP_COMMAND_OK 200
|
||||||
@ -87,8 +95,8 @@ typedef struct xmlNanoFTPCtxt {
|
|||||||
char *passwd; /* passwd string */
|
char *passwd; /* passwd string */
|
||||||
struct sockaddr_in ftpAddr; /* the socket address struct */
|
struct sockaddr_in ftpAddr; /* the socket address struct */
|
||||||
int passive; /* currently we support only passive !!! */
|
int passive; /* currently we support only passive !!! */
|
||||||
int controlFd; /* the file descriptor for the control socket */
|
SOCKET controlFd; /* the file descriptor for the control socket */
|
||||||
int dataFd; /* the file descriptor for the data socket */
|
SOCKET dataFd; /* the file descriptor for the data socket */
|
||||||
int state; /* WRITE / READ / CLOSED */
|
int state; /* WRITE / READ / CLOSED */
|
||||||
int returnValue; /* the protocol return value */
|
int returnValue; /* the protocol return value */
|
||||||
/* buffer for data received from the control connection */
|
/* buffer for data received from the control connection */
|
||||||
@ -116,10 +124,18 @@ static int proxyType = 0; /* uses TYPE or a@b ? */
|
|||||||
void
|
void
|
||||||
xmlNanoFTPInit(void) {
|
xmlNanoFTPInit(void) {
|
||||||
const char *env;
|
const char *env;
|
||||||
|
#ifdef _WINSOCKAPI_
|
||||||
|
WSADATA wsaData;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (initialized)
|
if (initialized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#ifdef _WINSOCKAPI_
|
||||||
|
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0)
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
gethostname(hostname, sizeof(hostname));
|
gethostname(hostname, sizeof(hostname));
|
||||||
|
|
||||||
proxyPort = 21;
|
proxyPort = 21;
|
||||||
@ -167,6 +183,10 @@ xmlNanoFTPCleanup(void) {
|
|||||||
proxyPasswd = NULL;
|
proxyPasswd = NULL;
|
||||||
}
|
}
|
||||||
hostname[0] = 0;
|
hostname[0] = 0;
|
||||||
|
#ifdef _WINSOCKAPI_
|
||||||
|
if (initialized)
|
||||||
|
WSACleanup();
|
||||||
|
#endif
|
||||||
initialized = 0;
|
initialized = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -488,7 +508,7 @@ xmlNanoFTPFreeCtxt(void * ctx) {
|
|||||||
if (ctxt->protocol != NULL) xmlFree(ctxt->protocol);
|
if (ctxt->protocol != NULL) xmlFree(ctxt->protocol);
|
||||||
if (ctxt->path != NULL) xmlFree(ctxt->path);
|
if (ctxt->path != NULL) xmlFree(ctxt->path);
|
||||||
ctxt->passive = 1;
|
ctxt->passive = 1;
|
||||||
if (ctxt->controlFd >= 0) close(ctxt->controlFd);
|
if (ctxt->controlFd >= 0) closesocket(ctxt->controlFd);
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
ctxt->controlBufIndex = -1;
|
ctxt->controlBufIndex = -1;
|
||||||
ctxt->controlBufUsed = -1;
|
ctxt->controlBufUsed = -1;
|
||||||
@ -590,7 +610,7 @@ xmlNanoFTPGetMore(void *ctx) {
|
|||||||
*/
|
*/
|
||||||
if ((len = recv(ctxt->controlFd, &ctxt->controlBuf[ctxt->controlBufIndex],
|
if ((len = recv(ctxt->controlFd, &ctxt->controlBuf[ctxt->controlBufIndex],
|
||||||
size, 0)) < 0) {
|
size, 0)) < 0) {
|
||||||
close(ctxt->controlFd); ctxt->controlFd = -1;
|
closesocket(ctxt->controlFd); ctxt->controlFd = -1;
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
@ -861,7 +881,7 @@ xmlNanoFTPConnect(void *ctx) {
|
|||||||
*/
|
*/
|
||||||
if (connect(ctxt->controlFd, (struct sockaddr *) &ctxt->ftpAddr,
|
if (connect(ctxt->controlFd, (struct sockaddr *) &ctxt->ftpAddr,
|
||||||
sizeof(struct sockaddr_in)) < 0) {
|
sizeof(struct sockaddr_in)) < 0) {
|
||||||
close(ctxt->controlFd); ctxt->controlFd = -1;
|
closesocket(ctxt->controlFd); ctxt->controlFd = -1;
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
@ -871,7 +891,7 @@ xmlNanoFTPConnect(void *ctx) {
|
|||||||
*/
|
*/
|
||||||
res = xmlNanoFTPGetResponse(ctxt);
|
res = xmlNanoFTPGetResponse(ctxt);
|
||||||
if (res != 2) {
|
if (res != 2) {
|
||||||
close(ctxt->controlFd); ctxt->controlFd = -1;
|
closesocket(ctxt->controlFd); ctxt->controlFd = -1;
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
@ -931,7 +951,7 @@ xmlNanoFTPConnect(void *ctx) {
|
|||||||
#endif
|
#endif
|
||||||
res = send(ctxt->controlFd, buf, len, 0);
|
res = send(ctxt->controlFd, buf, len, 0);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
close(ctxt->controlFd);
|
closesocket(ctxt->controlFd);
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
@ -961,13 +981,13 @@ xmlNanoFTPConnect(void *ctx) {
|
|||||||
#endif
|
#endif
|
||||||
res = send(ctxt->controlFd, buf, len, 0);
|
res = send(ctxt->controlFd, buf, len, 0);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
close(ctxt->controlFd);
|
closesocket(ctxt->controlFd);
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
res = xmlNanoFTPGetResponse(ctxt);
|
res = xmlNanoFTPGetResponse(ctxt);
|
||||||
if (res > 3) {
|
if (res > 3) {
|
||||||
close(ctxt->controlFd);
|
closesocket(ctxt->controlFd);
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
@ -978,7 +998,7 @@ xmlNanoFTPConnect(void *ctx) {
|
|||||||
case 5:
|
case 5:
|
||||||
case -1:
|
case -1:
|
||||||
default:
|
default:
|
||||||
close(ctxt->controlFd);
|
closesocket(ctxt->controlFd);
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
@ -1005,7 +1025,7 @@ xmlNanoFTPConnect(void *ctx) {
|
|||||||
#endif
|
#endif
|
||||||
res = send(ctxt->controlFd, buf, len, 0);
|
res = send(ctxt->controlFd, buf, len, 0);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
close(ctxt->controlFd); ctxt->controlFd = -1;
|
closesocket(ctxt->controlFd); ctxt->controlFd = -1;
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
@ -1016,7 +1036,7 @@ xmlNanoFTPConnect(void *ctx) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (proxyType == 1) {
|
if (proxyType == 1) {
|
||||||
close(ctxt->controlFd); ctxt->controlFd = -1;
|
closesocket(ctxt->controlFd); ctxt->controlFd = -1;
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
@ -1044,7 +1064,7 @@ xmlNanoFTPConnect(void *ctx) {
|
|||||||
#endif
|
#endif
|
||||||
res = send(ctxt->controlFd, buf, len, 0);
|
res = send(ctxt->controlFd, buf, len, 0);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
close(ctxt->controlFd); ctxt->controlFd = -1;
|
closesocket(ctxt->controlFd); ctxt->controlFd = -1;
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
@ -1073,7 +1093,7 @@ xmlNanoFTPConnect(void *ctx) {
|
|||||||
#endif
|
#endif
|
||||||
res = send(ctxt->controlFd, buf, len, 0);
|
res = send(ctxt->controlFd, buf, len, 0);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
close(ctxt->controlFd); ctxt->controlFd = -1;
|
closesocket(ctxt->controlFd); ctxt->controlFd = -1;
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
@ -1084,7 +1104,7 @@ xmlNanoFTPConnect(void *ctx) {
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
if (proxyType == 2) {
|
if (proxyType == 2) {
|
||||||
close(ctxt->controlFd); ctxt->controlFd = -1;
|
closesocket(ctxt->controlFd); ctxt->controlFd = -1;
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
@ -1094,7 +1114,7 @@ xmlNanoFTPConnect(void *ctx) {
|
|||||||
* send the code or at least the sequence in use.
|
* send the code or at least the sequence in use.
|
||||||
*/
|
*/
|
||||||
default:
|
default:
|
||||||
close(ctxt->controlFd); ctxt->controlFd = -1;
|
closesocket(ctxt->controlFd); ctxt->controlFd = -1;
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
@ -1104,7 +1124,7 @@ xmlNanoFTPConnect(void *ctx) {
|
|||||||
*/
|
*/
|
||||||
res = xmlNanoFTPSendUser(ctxt);
|
res = xmlNanoFTPSendUser(ctxt);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
close(ctxt->controlFd); ctxt->controlFd = -1;
|
closesocket(ctxt->controlFd); ctxt->controlFd = -1;
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
@ -1119,13 +1139,13 @@ xmlNanoFTPConnect(void *ctx) {
|
|||||||
case 5:
|
case 5:
|
||||||
case -1:
|
case -1:
|
||||||
default:
|
default:
|
||||||
close(ctxt->controlFd); ctxt->controlFd = -1;
|
closesocket(ctxt->controlFd); ctxt->controlFd = -1;
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
res = xmlNanoFTPSendPasswd(ctxt);
|
res = xmlNanoFTPSendPasswd(ctxt);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
close(ctxt->controlFd); ctxt->controlFd = -1;
|
closesocket(ctxt->controlFd); ctxt->controlFd = -1;
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
@ -1140,7 +1160,7 @@ xmlNanoFTPConnect(void *ctx) {
|
|||||||
case 5:
|
case 5:
|
||||||
case -1:
|
case -1:
|
||||||
default:
|
default:
|
||||||
close(ctxt->controlFd); ctxt->controlFd = -1;
|
closesocket(ctxt->controlFd); ctxt->controlFd = -1;
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
@ -1249,6 +1269,7 @@ xmlNanoFTPGetConnection(void *ctx) {
|
|||||||
ctxt->dataFd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
ctxt->dataFd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
if (ctxt->dataFd < 0) {
|
if (ctxt->dataFd < 0) {
|
||||||
fprintf(stderr, "xmlNanoFTPGetConnection: failed to create socket\n");
|
fprintf(stderr, "xmlNanoFTPGetConnection: failed to create socket\n");
|
||||||
|
return(-1);
|
||||||
}
|
}
|
||||||
dataAddrLen = sizeof(dataAddr);
|
dataAddrLen = sizeof(dataAddr);
|
||||||
memset(&dataAddr, 0, dataAddrLen);
|
memset(&dataAddr, 0, dataAddrLen);
|
||||||
@ -1262,19 +1283,19 @@ xmlNanoFTPGetConnection(void *ctx) {
|
|||||||
#endif
|
#endif
|
||||||
res = send(ctxt->controlFd, buf, len, 0);
|
res = send(ctxt->controlFd, buf, len, 0);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
res = xmlNanoFTPReadResponse(ctx);
|
res = xmlNanoFTPReadResponse(ctx);
|
||||||
if (res != 2) {
|
if (res != 2) {
|
||||||
if (res == 5) {
|
if (res == 5) {
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* retry with an active connection
|
* retry with an active connection
|
||||||
*/
|
*/
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
ctxt->passive = 0;
|
ctxt->passive = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1284,7 +1305,7 @@ xmlNanoFTPGetConnection(void *ctx) {
|
|||||||
&temp[3], &temp[4], &temp[5]) != 6) {
|
&temp[3], &temp[4], &temp[5]) != 6) {
|
||||||
fprintf(stderr, "Invalid answer to PASV\n");
|
fprintf(stderr, "Invalid answer to PASV\n");
|
||||||
if (ctxt->dataFd != -1) {
|
if (ctxt->dataFd != -1) {
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
}
|
}
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
@ -1293,7 +1314,7 @@ xmlNanoFTPGetConnection(void *ctx) {
|
|||||||
memcpy(&dataAddr.sin_port, &ad[4], 2);
|
memcpy(&dataAddr.sin_port, &ad[4], 2);
|
||||||
if (connect(ctxt->dataFd, (struct sockaddr *) &dataAddr, dataAddrLen) < 0) {
|
if (connect(ctxt->dataFd, (struct sockaddr *) &dataAddr, dataAddrLen) < 0) {
|
||||||
fprintf(stderr, "Failed to create a data connection\n");
|
fprintf(stderr, "Failed to create a data connection\n");
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1301,7 +1322,7 @@ xmlNanoFTPGetConnection(void *ctx) {
|
|||||||
dataAddr.sin_port = 0;
|
dataAddr.sin_port = 0;
|
||||||
if (bind(ctxt->dataFd, (struct sockaddr *) &dataAddr, dataAddrLen) < 0) {
|
if (bind(ctxt->dataFd, (struct sockaddr *) &dataAddr, dataAddrLen) < 0) {
|
||||||
fprintf(stderr, "Failed to bind a port\n");
|
fprintf(stderr, "Failed to bind a port\n");
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
getsockname(ctxt->dataFd, (struct sockaddr *) &dataAddr, &dataAddrLen);
|
getsockname(ctxt->dataFd, (struct sockaddr *) &dataAddr, &dataAddrLen);
|
||||||
@ -1309,7 +1330,7 @@ xmlNanoFTPGetConnection(void *ctx) {
|
|||||||
if (listen(ctxt->dataFd, 1) < 0) {
|
if (listen(ctxt->dataFd, 1) < 0) {
|
||||||
fprintf(stderr, "Could not listen on port %d\n",
|
fprintf(stderr, "Could not listen on port %d\n",
|
||||||
ntohs(dataAddr.sin_port));
|
ntohs(dataAddr.sin_port));
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
adp = (unsigned char *) &dataAddr.sin_addr;
|
adp = (unsigned char *) &dataAddr.sin_addr;
|
||||||
@ -1331,12 +1352,12 @@ xmlNanoFTPGetConnection(void *ctx) {
|
|||||||
|
|
||||||
res = send(ctxt->controlFd, buf, len, 0);
|
res = send(ctxt->controlFd, buf, len, 0);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
res = xmlNanoFTPGetResponse(ctxt);
|
res = xmlNanoFTPGetResponse(ctxt);
|
||||||
if (res != 2) {
|
if (res != 2) {
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1360,7 +1381,7 @@ xmlNanoFTPCloseConnection(void *ctx) {
|
|||||||
fd_set rfd, efd;
|
fd_set rfd, efd;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
tv.tv_sec = 15;
|
tv.tv_sec = 15;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
FD_ZERO(&rfd);
|
FD_ZERO(&rfd);
|
||||||
@ -1372,18 +1393,18 @@ xmlNanoFTPCloseConnection(void *ctx) {
|
|||||||
#ifdef DEBUG_FTP
|
#ifdef DEBUG_FTP
|
||||||
perror("select");
|
perror("select");
|
||||||
#endif
|
#endif
|
||||||
close(ctxt->controlFd); ctxt->controlFd = -1;
|
closesocket(ctxt->controlFd); ctxt->controlFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
#ifdef DEBUG_FTP
|
#ifdef DEBUG_FTP
|
||||||
fprintf(stderr, "xmlNanoFTPCloseConnection: timeout\n");
|
fprintf(stderr, "xmlNanoFTPCloseConnection: timeout\n");
|
||||||
#endif
|
#endif
|
||||||
close(ctxt->controlFd); ctxt->controlFd = -1;
|
closesocket(ctxt->controlFd); ctxt->controlFd = -1;
|
||||||
} else {
|
} else {
|
||||||
res = xmlNanoFTPGetResponse(ctxt);
|
res = xmlNanoFTPGetResponse(ctxt);
|
||||||
if (res != 2) {
|
if (res != 2) {
|
||||||
close(ctxt->controlFd); ctxt->controlFd = -1;
|
closesocket(ctxt->controlFd); ctxt->controlFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1567,12 +1588,12 @@ xmlNanoFTPList(void *ctx, ftpListCallback callback, void *userData,
|
|||||||
#endif
|
#endif
|
||||||
res = send(ctxt->controlFd, buf, len, 0);
|
res = send(ctxt->controlFd, buf, len, 0);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
res = xmlNanoFTPReadResponse(ctxt);
|
res = xmlNanoFTPReadResponse(ctxt);
|
||||||
if (res != 1) {
|
if (res != 1) {
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return(-res);
|
return(-res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1588,29 +1609,29 @@ xmlNanoFTPList(void *ctx, ftpListCallback callback, void *userData,
|
|||||||
#ifdef DEBUG_FTP
|
#ifdef DEBUG_FTP
|
||||||
perror("select");
|
perror("select");
|
||||||
#endif
|
#endif
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
res = xmlNanoFTPCheckResponse(ctxt);
|
res = xmlNanoFTPCheckResponse(ctxt);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
ctxt->dataFd = -1;
|
ctxt->dataFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
if (res == 2) {
|
if (res == 2) {
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((len = read(ctxt->dataFd, &buf[index], sizeof(buf) - (index + 1))) < 0) {
|
if ((len = recv(ctxt->dataFd, &buf[index], sizeof(buf) - (index + 1), 0)) < 0) {
|
||||||
#ifdef DEBUG_FTP
|
#ifdef DEBUG_FTP
|
||||||
perror("read");
|
perror("recv");
|
||||||
#endif
|
#endif
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
ctxt->dataFd = -1;
|
ctxt->dataFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
@ -1661,12 +1682,12 @@ xmlNanoFTPGetSocket(void *ctx, const char *filename) {
|
|||||||
#endif
|
#endif
|
||||||
res = send(ctxt->controlFd, buf, len, 0);
|
res = send(ctxt->controlFd, buf, len, 0);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
res = xmlNanoFTPReadResponse(ctxt);
|
res = xmlNanoFTPReadResponse(ctxt);
|
||||||
if (res != 2) {
|
if (res != 2) {
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return(-res);
|
return(-res);
|
||||||
}
|
}
|
||||||
if (filename == NULL)
|
if (filename == NULL)
|
||||||
@ -1688,12 +1709,12 @@ xmlNanoFTPGetSocket(void *ctx, const char *filename) {
|
|||||||
#endif
|
#endif
|
||||||
res = send(ctxt->controlFd, buf, len, 0);
|
res = send(ctxt->controlFd, buf, len, 0);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
res = xmlNanoFTPReadResponse(ctxt);
|
res = xmlNanoFTPReadResponse(ctxt);
|
||||||
if (res != 1) {
|
if (res != 1) {
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return(-res);
|
return(-res);
|
||||||
}
|
}
|
||||||
return(ctxt->dataFd);
|
return(ctxt->dataFd);
|
||||||
@ -1738,26 +1759,26 @@ xmlNanoFTPGet(void *ctx, ftpDataCallback callback, void *userData,
|
|||||||
#ifdef DEBUG_FTP
|
#ifdef DEBUG_FTP
|
||||||
perror("select");
|
perror("select");
|
||||||
#endif
|
#endif
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
res = xmlNanoFTPCheckResponse(ctxt);
|
res = xmlNanoFTPCheckResponse(ctxt);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
ctxt->dataFd = -1;
|
ctxt->dataFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
if (res == 2) {
|
if (res == 2) {
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((len = read(ctxt->dataFd, &buf, sizeof(buf))) < 0) {
|
if ((len = recv(ctxt->dataFd, buf, sizeof(buf), 0)) < 0) {
|
||||||
callback(userData, buf, len);
|
callback(userData, buf, len);
|
||||||
close(ctxt->dataFd); ctxt->dataFd = -1;
|
closesocket(ctxt->dataFd); ctxt->dataFd = -1;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
callback(userData, buf, len);
|
callback(userData, buf, len);
|
||||||
@ -1787,9 +1808,9 @@ xmlNanoFTPRead(void *ctx, void *dest, int len) {
|
|||||||
if (dest == NULL) return(-1);
|
if (dest == NULL) return(-1);
|
||||||
if (len <= 0) return(0);
|
if (len <= 0) return(0);
|
||||||
|
|
||||||
len = read(ctxt->dataFd, dest, len);
|
len = recv(ctxt->dataFd, dest, len, 0);
|
||||||
#ifdef DEBUG_FTP
|
#ifdef DEBUG_FTP
|
||||||
printf("Read %d bytes\n", len);
|
printf("Recvd %d bytes\n", len);
|
||||||
#endif
|
#endif
|
||||||
if (len <= 0) {
|
if (len <= 0) {
|
||||||
xmlNanoFTPCloseConnection(ctxt);
|
xmlNanoFTPCloseConnection(ctxt);
|
||||||
@ -1846,12 +1867,12 @@ xmlNanoFTPClose(void *ctx) {
|
|||||||
return(-1);
|
return(-1);
|
||||||
|
|
||||||
if (ctxt->dataFd >= 0) {
|
if (ctxt->dataFd >= 0) {
|
||||||
close(ctxt->dataFd);
|
closesocket(ctxt->dataFd);
|
||||||
ctxt->dataFd = -1;
|
ctxt->dataFd = -1;
|
||||||
}
|
}
|
||||||
if (ctxt->controlFd >= 0) {
|
if (ctxt->controlFd >= 0) {
|
||||||
xmlNanoFTPQuit(ctxt);
|
xmlNanoFTPQuit(ctxt);
|
||||||
close(ctxt->controlFd);
|
closesocket(ctxt->controlFd);
|
||||||
ctxt->controlFd = -1;
|
ctxt->controlFd = -1;
|
||||||
}
|
}
|
||||||
xmlNanoFTPFreeCtxt(ctxt);
|
xmlNanoFTPFreeCtxt(ctxt);
|
||||||
|
53
nanohttp.c
53
nanohttp.c
@ -65,6 +65,14 @@
|
|||||||
#include <libxml/parser.h> /* for xmlStr(n)casecmp() */
|
#include <libxml/parser.h> /* for xmlStr(n)casecmp() */
|
||||||
#include <libxml/nanohttp.h>
|
#include <libxml/nanohttp.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A couple portability macros
|
||||||
|
*/
|
||||||
|
#ifndef _WINSOCKAPI_
|
||||||
|
#define closesocket(s) close(s)
|
||||||
|
#define SOCKET int
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef STANDALONE
|
#ifdef STANDALONE
|
||||||
#define DEBUG_HTTP
|
#define DEBUG_HTTP
|
||||||
#define xmlStrncasecmp(a, b, n) strncasecmp((char *)a, (char *)b, n)
|
#define xmlStrncasecmp(a, b, n) strncasecmp((char *)a, (char *)b, n)
|
||||||
@ -85,7 +93,7 @@ typedef struct xmlNanoHTTPCtxt {
|
|||||||
char *hostname; /* the host name */
|
char *hostname; /* the host name */
|
||||||
int port; /* the port */
|
int port; /* the port */
|
||||||
char *path; /* the path within the URL */
|
char *path; /* the path within the URL */
|
||||||
int fd; /* the file descriptor for the socket */
|
SOCKET fd; /* the file descriptor for the socket */
|
||||||
int state; /* WRITE / READ / CLOSED */
|
int state; /* WRITE / READ / CLOSED */
|
||||||
char *out; /* buffer sent (zero terminated) */
|
char *out; /* buffer sent (zero terminated) */
|
||||||
char *outptr; /* index within the buffer sent */
|
char *outptr; /* index within the buffer sent */
|
||||||
@ -106,18 +114,8 @@ static int proxyPort; /* the proxy port if any */
|
|||||||
static unsigned int timeout = 60;/* the select() timeout in seconds */
|
static unsigned int timeout = 60;/* the select() timeout in seconds */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A bit of portability macros and functions
|
* A portability function
|
||||||
*/
|
*/
|
||||||
#ifdef _WINSOCKAPI_
|
|
||||||
|
|
||||||
WSADATA wsaData;
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define closesocket(s) close(s)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int socket_errno(void) {
|
int socket_errno(void) {
|
||||||
#ifdef _WINSOCKAPI_
|
#ifdef _WINSOCKAPI_
|
||||||
return(WSAGetLastError());
|
return(WSAGetLastError());
|
||||||
@ -136,13 +134,16 @@ int socket_errno(void) {
|
|||||||
void
|
void
|
||||||
xmlNanoHTTPInit(void) {
|
xmlNanoHTTPInit(void) {
|
||||||
const char *env;
|
const char *env;
|
||||||
|
#ifdef _WINSOCKAPI_
|
||||||
|
WSADATA wsaData;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (initialized)
|
if (initialized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef _WINSOCKAPI_
|
#ifdef _WINSOCKAPI_
|
||||||
if (WSAStartup(0x0101, &wsaData) != 0)
|
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0)
|
||||||
WSACleanup();
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (proxy == NULL) {
|
if (proxy == NULL) {
|
||||||
@ -175,10 +176,11 @@ void
|
|||||||
xmlNanoHTTPCleanup(void) {
|
xmlNanoHTTPCleanup(void) {
|
||||||
if (proxy != NULL)
|
if (proxy != NULL)
|
||||||
xmlFree(proxy);
|
xmlFree(proxy);
|
||||||
initialized = 0;
|
|
||||||
#ifdef _WINSOCKAPI_
|
#ifdef _WINSOCKAPI_
|
||||||
WSACleanup();
|
if (initialized)
|
||||||
|
WSACleanup();
|
||||||
#endif
|
#endif
|
||||||
|
initialized = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,7 +614,7 @@ xmlNanoHTTPScanAnswer(xmlNanoHTTPCtxtPtr ctxt, const char *line) {
|
|||||||
static int
|
static int
|
||||||
xmlNanoHTTPConnectAttempt(struct in_addr ia, int port)
|
xmlNanoHTTPConnectAttempt(struct in_addr ia, int port)
|
||||||
{
|
{
|
||||||
int s=socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
|
SOCKET s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
fd_set wfd;
|
fd_set wfd;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
@ -663,11 +665,16 @@ xmlNanoHTTPConnectAttempt(struct in_addr ia, int port)
|
|||||||
sin.sin_addr = ia;
|
sin.sin_addr = ia;
|
||||||
sin.sin_port = htons(port);
|
sin.sin_port = htons(port);
|
||||||
|
|
||||||
if ((connect(s, (struct sockaddr *)&sin, sizeof(sin))==-1) &&
|
if ((connect(s, (struct sockaddr *)&sin, sizeof(sin))==-1)) {
|
||||||
(socket_errno() != EINPROGRESS) && (socket_errno() != EWOULDBLOCK)) {
|
switch (socket_errno()) {
|
||||||
perror("connect");
|
case EINPROGRESS:
|
||||||
closesocket(s);
|
case EWOULDBLOCK:
|
||||||
return(-1);
|
break;
|
||||||
|
default:
|
||||||
|
perror("connect");
|
||||||
|
closesocket(s);
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tv.tv_sec = timeout;
|
tv.tv_sec = timeout;
|
||||||
@ -694,7 +701,7 @@ xmlNanoHTTPConnectAttempt(struct in_addr ia, int port)
|
|||||||
if ( FD_ISSET(s, &wfd) ) {
|
if ( FD_ISSET(s, &wfd) ) {
|
||||||
SOCKLEN_T len;
|
SOCKLEN_T len;
|
||||||
len = sizeof(status);
|
len = sizeof(status);
|
||||||
if (getsockopt(s, SOL_SOCKET, SO_ERROR, &status, &len) < 0 ) {
|
if (getsockopt(s, SOL_SOCKET, SO_ERROR, (char*)&status, &len) < 0 ) {
|
||||||
/* Solaris error code */
|
/* Solaris error code */
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
6
xmlIO.c
6
xmlIO.c
@ -374,7 +374,7 @@ xmlGzfileOpen (const char *filename) {
|
|||||||
gzFile fd;
|
gzFile fd;
|
||||||
|
|
||||||
if (!strcmp(filename, "-")) {
|
if (!strcmp(filename, "-")) {
|
||||||
fd = gzdopen (fileno(stdin), "r");
|
fd = gzdopen(fileno(stdin), "rb");
|
||||||
return((void *) fd);
|
return((void *) fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,7 +385,7 @@ xmlGzfileOpen (const char *filename) {
|
|||||||
else
|
else
|
||||||
path = filename;
|
path = filename;
|
||||||
|
|
||||||
fd = gzopen(filename, "r");
|
fd = gzopen(filename, "rb");
|
||||||
return((void *) fd);
|
return((void *) fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,7 +405,7 @@ xmlGzfileOpenW (const char *filename, int compression) {
|
|||||||
char mode[15];
|
char mode[15];
|
||||||
gzFile fd;
|
gzFile fd;
|
||||||
|
|
||||||
sprintf(mode, "w%d", compression);
|
sprintf(mode, "wb%d", compression);
|
||||||
if (!strcmp(filename, "-")) {
|
if (!strcmp(filename, "-")) {
|
||||||
fd = gzdopen(1, mode);
|
fd = gzdopen(1, mode);
|
||||||
return((void *) fd);
|
return((void *) fd);
|
||||||
|
Reference in New Issue
Block a user