Synopsis
-
int xmlNanoFTPQuit (void * ctx);
+ #define INVALID_SOCKET;
+#define SOCKET;
+int xmlNanoFTPQuit (void * ctx);
int xmlNanoFTPClose (void * ctx);
typedef void ftpListCallback (void * userData,
const char * filename,
const char * attrib,
const char * owner,
const char * group,
unsigned long size,
int links,
int year,
const char * month,
int day,
int hour,
int minute);
int xmlNanoFTPCloseConnection (void * ctx);
void xmlNanoFTPProxy (const char * host,
int port,
const char * user,
const char * passwd,
int type);
int xmlNanoFTPUpdateURL (void * ctx,
const char * URL);
-int xmlNanoFTPGetConnection (void * ctx);
+SOCKET xmlNanoFTPGetConnection (void * ctx);
int xmlNanoFTPDele (void * ctx,
const char * file);
void * xmlNanoFTPNewCtxt (const char * URL);
int xmlNanoFTPCheckResponse (void * ctx);
@@ -62,7 +64,7 @@ void * xmlNanoFTPConnectTo (const char * ser
int xmlNanoFTPList (void * ctx,
ftpListCallback callback,
void * userData,
const char * filename);
void * xmlNanoFTPOpen (const char * URL);
int xmlNanoFTPConnect (void * ctx);
-int xmlNanoFTPGetSocket (void * ctx,
const char * filename);
+SOCKET xmlNanoFTPGetSocket (void * ctx,
const char * filename);
int xmlNanoFTPGet (void * ctx,
ftpDataCallback callback,
void * userData,
const char * filename);
int xmlNanoFTPRead (void * ctx,
void * dest,
int len);
void xmlNanoFTPFreeCtxt (void * ctx);
@@ -75,6 +77,14 @@ void xmlNanoFTPCleanup (void);
Details
+
+
+
+
Function type ftpDataCallback
void ftpDataCallback (void * userData,
const char * data,
int len)
A callback for the xmlNanoFTPGet command.
| userData: | the user provided context |
| data: | the data received |
| len: | its size in bytes |
@@ -123,7 +133,7 @@ void
xmlNanoFTPCleanup (void);
Fetch the given file from the server. All data are passed back in the callbacks. The last callback has a size of 0 block.
| ctx: | an FTP context |
| callback: | the user callback |
| userData: | the user callback data |
| filename: | the file to retrieve |
| Returns: | -1 incase of error, 0 otherwise |
-
xmlNanoFTPGetConnection ()
int xmlNanoFTPGetConnection (void * ctx)
+ xmlNanoFTPGetConnection ()
SOCKET xmlNanoFTPGetConnection (void * ctx)
Try to open a data connection to the server. Currently only passive mode is supported.
| ctx: | an FTP context |
| Returns: | -1 incase of error, 0 otherwise |
@@ -131,7 +141,7 @@ void xmlNanoFTPCleanup (void);
Get the response from the FTP server after a command.
| ctx: | an FTP context |
| Returns: | the code number |
-
xmlNanoFTPGetSocket ()
int xmlNanoFTPGetSocket (void * ctx,
const char * filename)
+ xmlNanoFTPGetSocket ()
SOCKET xmlNanoFTPGetSocket (void * ctx,
const char * filename)
Initiate fetch of the given file from the server.
| ctx: | an FTP context |
| filename: | the file to retrieve (or NULL if path is in context). |
| Returns: | the socket for the data connection, or <0 in case of error |
diff --git a/doc/devhelp/libxml2-xmlsave.html b/doc/devhelp/libxml2-xmlsave.html
index 852a9068..f006e3bb 100644
--- a/doc/devhelp/libxml2-xmlsave.html
+++ b/doc/devhelp/libxml2-xmlsave.html
@@ -81,7 +81,8 @@ The content of this structure is not made public by the API.
XML_SAVE_NO_XHTML = 8 /* disable XHTML1 specific rules */
XML_SAVE_XHTML = 16 /* force XHTML1 specific rules */
XML_SAVE_AS_XML = 32 /* force XML serialization on HTML doc */
- XML_SAVE_AS_HTML = 64 /* force HTML serialization on XML doc */
+ XML_SAVE_AS_HTML = 64 /* force HTML serialization on XML doc */
+ XML_SAVE_WSNONSIG = 128 /* format with non-significant whitespace */
};
diff --git a/doc/devhelp/libxml2.devhelp b/doc/devhelp/libxml2.devhelp
index aa6fb80a..643354a0 100644
--- a/doc/devhelp/libxml2.devhelp
+++ b/doc/devhelp/libxml2.devhelp
@@ -71,6 +71,7 @@
+
@@ -133,6 +134,7 @@
+
@@ -988,6 +990,7 @@
+
diff --git a/doc/html/libxml-nanoftp.html b/doc/html/libxml-nanoftp.html
index b8915678..2b6bf8f3 100644
--- a/doc/html/libxml-nanoftp.html
+++ b/doc/html/libxml-nanoftp.html
@@ -10,7 +10,7 @@ A:link, A:visited, A:active { text-decoration: underline }
Module nanoftp from libxml2 |    | Module nanoftp from libxml2 |
|
|
| minimal FTP implementation allowing to fetch resources like external subset. Table of ContentsFunction type: ftpDataCallback
+ Module nanoftp from libxml2  |    | Module nanoftp from libxml2 |
|
|
| minimal FTP implementation allowing to fetch resources like external subset. Table of Contents#define INVALID_SOCKET #define SOCKET Function type: ftpDataCallback
void ftpDataCallback (void * userData, const char * data, int len)
Function type: ftpListCallback
@@ -26,9 +26,9 @@ void ftpListCallback (void * userData,
int xmlNanoFTPDele (void * ctx, const char * file)
void xmlNanoFTPFreeCtxt (void * ctx)
int xmlNanoFTPGet (void * ctx, ftpDataCallback callback, void * userData, const char * filename)
-int xmlNanoFTPGetConnection (void * ctx)
+SOCKET xmlNanoFTPGetConnection (void * ctx)
int xmlNanoFTPGetResponse (void * ctx)
-int xmlNanoFTPGetSocket (void * ctx, const char * filename)
+SOCKET xmlNanoFTPGetSocket (void * ctx, const char * filename)
void xmlNanoFTPInit (void)
int xmlNanoFTPList (void * ctx, ftpListCallback callback, void * userData, const char * filename)
void * xmlNanoFTPNewCtxt (const char * URL)
@@ -39,6 +39,8 @@ void ftpListCallback (void * userData,
void xmlNanoFTPScanProxy (const char * URL)
int xmlNanoFTPUpdateURL (void * ctx, const char * URL)
Description
+Macro: INVALID_SOCKET#define INVALID_SOCKET
+Macro: SOCKET#define SOCKET
Function type: ftpDataCallbackFunction type: ftpDataCallback
void ftpDataCallback (void * userData, const char * data, int len)
A callback for the xmlNanoFTPGet command. | userData: | the user provided context | | data: | the data received | | len: | its size in bytes |
@@ -65,11 +67,11 @@ void ftpListCallback (void * userData, const char * filename,
Frees the context after closing the connection.
Function: xmlNanoFTPGetint xmlNanoFTPGet (void * ctx, ftpDataCallback callback, void * userData, const char * filename)
Fetch the given file from the server. All data are passed back in the callbacks. The last callback has a size of 0 block.
-| ctx: | an FTP context | | callback: | the user callback | | userData: | the user callback data | | filename: | the file to retrieve | | Returns: | -1 incase of error, 0 otherwise |
Function: xmlNanoFTPGetConnectionint xmlNanoFTPGetConnection (void * ctx)
+| ctx: | an FTP context | | callback: | the user callback | | userData: | the user callback data | | filename: | the file to retrieve | | Returns: | -1 incase of error, 0 otherwise |
Function: xmlNanoFTPGetConnectionSOCKET xmlNanoFTPGetConnection (void * ctx)
Try to open a data connection to the server. Currently only passive mode is supported.
| ctx: | an FTP context | | Returns: | -1 incase of error, 0 otherwise |
Function: xmlNanoFTPGetResponseint xmlNanoFTPGetResponse (void * ctx)
Get the response from the FTP server after a command.
-| ctx: | an FTP context | | Returns: | the code number |
Function: xmlNanoFTPGetSocketint xmlNanoFTPGetSocket (void * ctx, const char * filename)
+| ctx: | an FTP context | | Returns: | the code number |
Function: xmlNanoFTPGetSocketSOCKET xmlNanoFTPGetSocket (void * ctx, const char * filename)
Initiate fetch of the given file from the server.
| ctx: | an FTP context | | filename: | the file to retrieve (or NULL if path is in context). | | Returns: | the socket for the data connection, or <0 in case of error |
Function: xmlNanoFTPInitvoid xmlNanoFTPInit (void)
Initialize the FTP protocol layer. Currently it just checks for proxy informations, and get the hostname
diff --git a/doc/html/libxml-xmlsave.html b/doc/html/libxml-xmlsave.html
index 61f3891e..76c751cb 100644
--- a/doc/html/libxml-xmlsave.html
+++ b/doc/html/libxml-xmlsave.html
@@ -35,6 +35,7 @@ The content of this structure is not made public by the API.
XML_SAVE_XHTML = 16 : force XHTML1 specific rules
XML_SAVE_AS_XML = 32 : force XML serialization on HTML doc
XML_SAVE_AS_HTML = 64 : force HTML serialization on XML doc
+ XML_SAVE_WSNONSIG = 128 : format with non-significant whitespace
}
Function: xmlSaveCloseint xmlSaveClose (xmlSaveCtxtPtr ctxt)
Close a document saving context, i.e. make sure that all bytes have been output and free the associated data.
diff --git a/doc/libxml2-api.xml b/doc/libxml2-api.xml
index d1b863bb..ca1d68b5 100644
--- a/doc/libxml2-api.xml
+++ b/doc/libxml2-api.xml
@@ -617,6 +617,8 @@
minimal FTP implementation
minimal FTP implementation allowing to fetch resources like external subset.
Daniel Veillard
+
+
@@ -3004,6 +3006,7 @@
+
@@ -3836,6 +3839,8 @@
The parser tries to always have that amount of input ready. One of the point is providing context when reporting errors.
+
+
Macro to check [0-9]
@@ -4043,6 +4048,8 @@
Skips the end of line chars.
+
+
defined if the trio support should not be configured in
@@ -5270,7 +5277,7 @@ crash if you try to modify the tree)'/>
-
+
@@ -5280,6 +5287,7 @@ crash if you try to modify the tree)'/>
+
@@ -11042,7 +11050,7 @@ Could we use @subtypes for this?'/>
defined(LIBXML_FTP_ENABLED)
Try to open a data connection to the server. Currently only passive mode is supported.
-
+
@@ -11054,7 +11062,7 @@ Could we use @subtypes for this?'/>
defined(LIBXML_FTP_ENABLED)
Initiate fetch of the given file from the server.
-
+
diff --git a/doc/libxml2-refs.xml b/doc/libxml2-refs.xml
index 3f71a6c6..65246453 100644
--- a/doc/libxml2-refs.xml
+++ b/doc/libxml2-refs.xml
@@ -34,6 +34,7 @@
+
@@ -96,6 +97,7 @@
+
@@ -801,6 +803,7 @@
+
@@ -3579,6 +3582,7 @@
+
@@ -3647,6 +3651,7 @@
+
@@ -4358,6 +4363,7 @@
+
@@ -7129,6 +7135,10 @@
+
+
+
+
@@ -11166,6 +11176,8 @@
+
+
@@ -13486,6 +13498,7 @@
+
diff --git a/include/libxml/nanoftp.h b/include/libxml/nanoftp.h
index e3c28a01..548d1e1d 100644
--- a/include/libxml/nanoftp.h
+++ b/include/libxml/nanoftp.h
@@ -7,7 +7,7 @@
*
* Author: Daniel Veillard
*/
-
+
#ifndef __NANO_FTP_H__
#define __NANO_FTP_H__
@@ -15,12 +15,20 @@
#ifdef LIBXML_FTP_ENABLED
+/* Needed for portability to Windows 64 bits */
+#if defined(__MINGW32__) || defined(_WIN32_WCE)
+#include
+#else
+#define SOCKET int
+#define INVALID_SOCKET (-1)
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
/**
- * ftpListCallback:
+ * ftpListCallback:
* @userData: user provided data for the callback
* @filename: the file name (including "->" when links are shown)
* @attrib: the attribute string
@@ -44,7 +52,7 @@ typedef void (*ftpListCallback) (void *userData,
const char *month, int day, int hour,
int minute);
/**
- * ftpDataCallback:
+ * ftpDataCallback:
* @userData: the user provided context
* @data: the data received
* @len: its size in bytes
@@ -60,78 +68,78 @@ typedef void (*ftpDataCallback) (void *userData,
*/
XMLPUBFUN void XMLCALL
xmlNanoFTPInit (void);
-XMLPUBFUN void XMLCALL
+XMLPUBFUN void XMLCALL
xmlNanoFTPCleanup (void);
/*
* Creating/freeing contexts.
*/
-XMLPUBFUN void * XMLCALL
+XMLPUBFUN void * XMLCALL
xmlNanoFTPNewCtxt (const char *URL);
-XMLPUBFUN void XMLCALL
+XMLPUBFUN void XMLCALL
xmlNanoFTPFreeCtxt (void * ctx);
-XMLPUBFUN void * XMLCALL
+XMLPUBFUN void * XMLCALL
xmlNanoFTPConnectTo (const char *server,
int port);
/*
* Opening/closing session connections.
*/
-XMLPUBFUN void * XMLCALL
+XMLPUBFUN void * XMLCALL
xmlNanoFTPOpen (const char *URL);
-XMLPUBFUN int XMLCALL
+XMLPUBFUN int XMLCALL
xmlNanoFTPConnect (void *ctx);
-XMLPUBFUN int XMLCALL
+XMLPUBFUN int XMLCALL
xmlNanoFTPClose (void *ctx);
-XMLPUBFUN int XMLCALL
+XMLPUBFUN int XMLCALL
xmlNanoFTPQuit (void *ctx);
-XMLPUBFUN void XMLCALL
+XMLPUBFUN void XMLCALL
xmlNanoFTPScanProxy (const char *URL);
-XMLPUBFUN void XMLCALL
+XMLPUBFUN void XMLCALL
xmlNanoFTPProxy (const char *host,
int port,
const char *user,
const char *passwd,
int type);
-XMLPUBFUN int XMLCALL
+XMLPUBFUN int XMLCALL
xmlNanoFTPUpdateURL (void *ctx,
const char *URL);
/*
* Rather internal commands.
*/
-XMLPUBFUN int XMLCALL
+XMLPUBFUN int XMLCALL
xmlNanoFTPGetResponse (void *ctx);
-XMLPUBFUN int XMLCALL
+XMLPUBFUN int XMLCALL
xmlNanoFTPCheckResponse (void *ctx);
/*
* CD/DIR/GET handlers.
*/
-XMLPUBFUN int XMLCALL
+XMLPUBFUN int XMLCALL
xmlNanoFTPCwd (void *ctx,
const char *directory);
-XMLPUBFUN int XMLCALL
+XMLPUBFUN int XMLCALL
xmlNanoFTPDele (void *ctx,
const char *file);
-XMLPUBFUN int XMLCALL
+XMLPUBFUN SOCKET XMLCALL
xmlNanoFTPGetConnection (void *ctx);
-XMLPUBFUN int XMLCALL
+XMLPUBFUN int XMLCALL
xmlNanoFTPCloseConnection(void *ctx);
-XMLPUBFUN int XMLCALL
+XMLPUBFUN int XMLCALL
xmlNanoFTPList (void *ctx,
ftpListCallback callback,
void *userData,
const char *filename);
-XMLPUBFUN int XMLCALL
+XMLPUBFUN SOCKET XMLCALL
xmlNanoFTPGetSocket (void *ctx,
const char *filename);
-XMLPUBFUN int XMLCALL
+XMLPUBFUN int XMLCALL
xmlNanoFTPGet (void *ctx,
ftpDataCallback callback,
void *userData,
const char *filename);
-XMLPUBFUN int XMLCALL
+XMLPUBFUN int XMLCALL
xmlNanoFTPRead (void *ctx,
void *dest,
int len);
diff --git a/nanoftp.c b/nanoftp.c
index a54b85b3..a7ca5b6b 100644
--- a/nanoftp.c
+++ b/nanoftp.c
@@ -78,7 +78,9 @@
#if defined(__MINGW32__) || defined(_WIN32_WCE)
+#ifndef _WINSOCKAPI_
#define _WINSOCKAPI_
+#endif
#include
#include
#undef XML_SOCKLEN_T
@@ -92,7 +94,6 @@
#if !defined(__BEOS__) || defined(__HAIKU__)
#define closesocket(s) close(s)
#endif
-#define SOCKET int
#endif
#ifdef __BEOS__
@@ -484,7 +485,7 @@ xmlNanoFTPNewCtxt(const char *URL) {
ret->returnValue = 0;
ret->controlBufIndex = 0;
ret->controlBufUsed = 0;
- ret->controlFd = -1;
+ ret->controlFd = INVALID_SOCKET;
unescaped = xmlURIUnescapeString(URL, 0, NULL);
if (unescaped != NULL) {
@@ -511,8 +512,8 @@ xmlNanoFTPFreeCtxt(void * ctx) {
if (ctxt->protocol != NULL) xmlFree(ctxt->protocol);
if (ctxt->path != NULL) xmlFree(ctxt->path);
ctxt->passive = 1;
- if (ctxt->controlFd >= 0) closesocket(ctxt->controlFd);
- ctxt->controlFd = -1;
+ if (ctxt->controlFd != INVALID_SOCKET) closesocket(ctxt->controlFd);
+ ctxt->controlFd = INVALID_SOCKET;
ctxt->controlBufIndex = -1;
ctxt->controlBufUsed = -1;
xmlFree(ctxt);
@@ -567,7 +568,7 @@ xmlNanoFTPGetMore(void *ctx) {
int len;
int size;
- if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
+ if ((ctxt == NULL) || (ctxt->controlFd == INVALID_SOCKET)) return(-1);
if ((ctxt->controlBufIndex < 0) || (ctxt->controlBufIndex > FTP_BUF_SIZE)) {
#ifdef DEBUG_FTP
@@ -619,8 +620,8 @@ xmlNanoFTPGetMore(void *ctx) {
if ((len = recv(ctxt->controlFd, &ctxt->controlBuf[ctxt->controlBufIndex],
size, 0)) < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "recv failed");
- closesocket(ctxt->controlFd); ctxt->controlFd = -1;
- ctxt->controlFd = -1;
+ closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
+ ctxt->controlFd = INVALID_SOCKET;
return(-1);
}
#ifdef DEBUG_FTP
@@ -648,7 +649,7 @@ xmlNanoFTPReadResponse(void *ctx) {
int len;
int res = -1, cur = -1;
- if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
+ if ((ctxt == NULL) || (ctxt->controlFd == INVALID_SOCKET)) return(-1);
get_more:
/*
@@ -737,7 +738,7 @@ xmlNanoFTPCheckResponse(void *ctx) {
fd_set rfd;
struct timeval tv;
- if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
+ if ((ctxt == NULL) || (ctxt->controlFd == INVALID_SOCKET)) return(-1);
tv.tv_sec = 0;
tv.tv_usec = 0;
FD_ZERO(&rfd);
@@ -826,7 +827,7 @@ xmlNanoFTPQuit(void *ctx) {
char buf[200];
int len, res;
- if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
+ if ((ctxt == NULL) || (ctxt->controlFd == INVALID_SOCKET)) return(-1);
snprintf(buf, sizeof(buf), "QUIT\r\n");
len = strlen(buf);
@@ -951,7 +952,7 @@ xmlNanoFTPConnect(void *ctx) {
addrlen = sizeof (struct sockaddr_in);
}
- if (ctxt->controlFd < 0) {
+ if (ctxt->controlFd == INVALID_SOCKET) {
__xmlIOErr(XML_FROM_FTP, 0, "socket failed");
return(-1);
}
@@ -962,8 +963,8 @@ xmlNanoFTPConnect(void *ctx) {
if (connect(ctxt->controlFd, (struct sockaddr *) &ctxt->ftpAddr,
addrlen) < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "Failed to create a connection");
- closesocket(ctxt->controlFd); ctxt->controlFd = -1;
- ctxt->controlFd = -1;
+ closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
+ ctxt->controlFd = INVALID_SOCKET;
return(-1);
}
@@ -972,8 +973,8 @@ xmlNanoFTPConnect(void *ctx) {
*/
res = xmlNanoFTPGetResponse(ctxt);
if (res != 2) {
- closesocket(ctxt->controlFd); ctxt->controlFd = -1;
- ctxt->controlFd = -1;
+ closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
+ ctxt->controlFd = INVALID_SOCKET;
return(-1);
}
@@ -1030,7 +1031,7 @@ xmlNanoFTPConnect(void *ctx) {
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
closesocket(ctxt->controlFd);
- ctxt->controlFd = -1;
+ ctxt->controlFd = INVALID_SOCKET;
return(res);
}
res = xmlNanoFTPGetResponse(ctxt);
@@ -1052,13 +1053,13 @@ xmlNanoFTPConnect(void *ctx) {
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
closesocket(ctxt->controlFd);
- ctxt->controlFd = -1;
+ ctxt->controlFd = INVALID_SOCKET;
return(res);
}
res = xmlNanoFTPGetResponse(ctxt);
if (res > 3) {
closesocket(ctxt->controlFd);
- ctxt->controlFd = -1;
+ ctxt->controlFd = INVALID_SOCKET;
return(-1);
}
break;
@@ -1069,7 +1070,7 @@ xmlNanoFTPConnect(void *ctx) {
case -1:
default:
closesocket(ctxt->controlFd);
- ctxt->controlFd = -1;
+ ctxt->controlFd = INVALID_SOCKET;
return(-1);
}
}
@@ -1092,8 +1093,8 @@ xmlNanoFTPConnect(void *ctx) {
res = send(ctxt->controlFd, buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
- closesocket(ctxt->controlFd); ctxt->controlFd = -1;
- ctxt->controlFd = -1;
+ closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
+ ctxt->controlFd = INVALID_SOCKET;
return(res);
}
res = xmlNanoFTPGetResponse(ctxt);
@@ -1103,8 +1104,8 @@ xmlNanoFTPConnect(void *ctx) {
break;
}
if (proxyType == 1) {
- closesocket(ctxt->controlFd); ctxt->controlFd = -1;
- ctxt->controlFd = -1;
+ closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
+ ctxt->controlFd = INVALID_SOCKET;
return(-1);
}
case 2:
@@ -1123,8 +1124,8 @@ xmlNanoFTPConnect(void *ctx) {
res = send(ctxt->controlFd, buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
- closesocket(ctxt->controlFd); ctxt->controlFd = -1;
- ctxt->controlFd = -1;
+ closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
+ ctxt->controlFd = INVALID_SOCKET;
return(res);
}
res = xmlNanoFTPGetResponse(ctxt);
@@ -1145,8 +1146,8 @@ xmlNanoFTPConnect(void *ctx) {
res = send(ctxt->controlFd, buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
- closesocket(ctxt->controlFd); ctxt->controlFd = -1;
- ctxt->controlFd = -1;
+ closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
+ ctxt->controlFd = INVALID_SOCKET;
return(res);
}
res = xmlNanoFTPGetResponse(ctxt);
@@ -1156,8 +1157,8 @@ xmlNanoFTPConnect(void *ctx) {
return(0);
}
if (proxyType == 2) {
- closesocket(ctxt->controlFd); ctxt->controlFd = -1;
- ctxt->controlFd = -1;
+ closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
+ ctxt->controlFd = INVALID_SOCKET;
return(-1);
}
case 3:
@@ -1166,8 +1167,8 @@ xmlNanoFTPConnect(void *ctx) {
* send the code or at least the sequence in use.
*/
default:
- closesocket(ctxt->controlFd); ctxt->controlFd = -1;
- ctxt->controlFd = -1;
+ closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
+ ctxt->controlFd = INVALID_SOCKET;
return(-1);
}
}
@@ -1176,8 +1177,8 @@ xmlNanoFTPConnect(void *ctx) {
*/
res = xmlNanoFTPSendUser(ctxt);
if (res < 0) {
- closesocket(ctxt->controlFd); ctxt->controlFd = -1;
- ctxt->controlFd = -1;
+ closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
+ ctxt->controlFd = INVALID_SOCKET;
return(-1);
}
res = xmlNanoFTPGetResponse(ctxt);
@@ -1191,14 +1192,14 @@ xmlNanoFTPConnect(void *ctx) {
case 5:
case -1:
default:
- closesocket(ctxt->controlFd); ctxt->controlFd = -1;
- ctxt->controlFd = -1;
+ closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
+ ctxt->controlFd = INVALID_SOCKET;
return(-1);
}
res = xmlNanoFTPSendPasswd(ctxt);
if (res < 0) {
- closesocket(ctxt->controlFd); ctxt->controlFd = -1;
- ctxt->controlFd = -1;
+ closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
+ ctxt->controlFd = INVALID_SOCKET;
return(-1);
}
res = xmlNanoFTPGetResponse(ctxt);
@@ -1213,8 +1214,8 @@ xmlNanoFTPConnect(void *ctx) {
case 5:
case -1:
default:
- closesocket(ctxt->controlFd); ctxt->controlFd = -1;
- ctxt->controlFd = -1;
+ closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
+ ctxt->controlFd = INVALID_SOCKET;
return(-1);
}
@@ -1270,7 +1271,7 @@ xmlNanoFTPCwd(void *ctx, const char *directory) {
int len;
int res;
- if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
+ if ((ctxt == NULL) || (ctxt->controlFd == INVALID_SOCKET)) return(-1);
if (directory == NULL) return 0;
/*
@@ -1319,7 +1320,7 @@ xmlNanoFTPDele(void *ctx, const char *file) {
int len;
int res;
- if ((ctxt == NULL) || (ctxt->controlFd < 0) || (file == NULL)) return(-1);
+ if ((ctxt == NULL) || (ctxt->controlFd == INVALID_SOCKET) || (file == NULL)) return(-1);
if (file == NULL) return (0);
/*
@@ -1362,7 +1363,7 @@ xmlNanoFTPDele(void *ctx, const char *file) {
* Returns -1 incase of error, 0 otherwise
*/
-int
+SOCKET
xmlNanoFTPGetConnection(void *ctx) {
xmlNanoFTPCtxtPtr ctxt = (xmlNanoFTPCtxtPtr) ctx;
char buf[200], *cur;
@@ -1377,7 +1378,7 @@ xmlNanoFTPGetConnection(void *ctx) {
#endif
XML_SOCKLEN_T dataAddrLen;
- if (ctxt == NULL) return(-1);
+ if (ctxt == NULL) return INVALID_SOCKET;
memset (&dataAddr, 0, sizeof(dataAddr));
#ifdef SUPPORT_IP6
@@ -1393,9 +1394,9 @@ xmlNanoFTPGetConnection(void *ctx) {
dataAddrLen = sizeof (struct sockaddr_in);
}
- if (ctxt->dataFd < 0) {
+ if (ctxt->dataFd == INVALID_SOCKET) {
__xmlIOErr(XML_FROM_FTP, 0, "socket failed");
- return (-1);
+ return INVALID_SOCKET;
}
if (ctxt->passive) {
@@ -1412,19 +1413,19 @@ xmlNanoFTPGetConnection(void *ctx) {
res = send(ctxt->controlFd, buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
- return(res);
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
+ return INVALID_SOCKET;
}
res = xmlNanoFTPReadResponse(ctx);
if (res != 2) {
if (res == 5) {
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
- return(-1);
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
+ return INVALID_SOCKET;
} else {
/*
* retry with an active connection
*/
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
ctxt->passive = 0;
}
}
@@ -1435,10 +1436,10 @@ xmlNanoFTPGetConnection(void *ctx) {
if (sscanf (cur, "%u", &temp[0]) != 1) {
__xmlIOErr(XML_FROM_FTP, XML_FTP_EPSV_ANSWER,
"Invalid answer to EPSV\n");
- if (ctxt->dataFd != -1) {
- closesocket (ctxt->dataFd); ctxt->dataFd = -1;
+ if (ctxt->dataFd != INVALID_SOCKET) {
+ closesocket (ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
}
- return (-1);
+ return INVALID_SOCKET;
}
memcpy (&((struct sockaddr_in6 *)&dataAddr)->sin6_addr, &((struct sockaddr_in6 *)&ctxt->ftpAddr)->sin6_addr, sizeof(struct in6_addr));
((struct sockaddr_in6 *)&dataAddr)->sin6_port = htons (temp[0]);
@@ -1450,10 +1451,10 @@ xmlNanoFTPGetConnection(void *ctx) {
&temp[3], &temp[4], &temp[5]) != 6) {
__xmlIOErr(XML_FROM_FTP, XML_FTP_PASV_ANSWER,
"Invalid answer to PASV\n");
- if (ctxt->dataFd != -1) {
- closesocket (ctxt->dataFd); ctxt->dataFd = -1;
+ if (ctxt->dataFd != INVALID_SOCKET) {
+ closesocket (ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
}
- return (-1);
+ return INVALID_SOCKET;
}
for (i=0; i<6; i++) ad[i] = (unsigned char) (temp[i] & 0xff);
memcpy (&((struct sockaddr_in *)&dataAddr)->sin_addr, &ad[0], 4);
@@ -1462,8 +1463,8 @@ xmlNanoFTPGetConnection(void *ctx) {
if (connect(ctxt->dataFd, (struct sockaddr *) &dataAddr, dataAddrLen) < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "Failed to create a data connection");
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
- return (-1);
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
+ return INVALID_SOCKET;
}
} else {
getsockname(ctxt->dataFd, (struct sockaddr *) &dataAddr, &dataAddrLen);
@@ -1476,15 +1477,15 @@ xmlNanoFTPGetConnection(void *ctx) {
if (bind(ctxt->dataFd, (struct sockaddr *) &dataAddr, dataAddrLen) < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "bind failed");
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
- return (-1);
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
+ return INVALID_SOCKET;
}
getsockname(ctxt->dataFd, (struct sockaddr *) &dataAddr, &dataAddrLen);
if (listen(ctxt->dataFd, 1) < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "listen failed");
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
- return (-1);
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
+ return INVALID_SOCKET;
}
#ifdef SUPPORT_IP6
if ((ctxt->ftpAddr).ss_family == AF_INET6) {
@@ -1513,13 +1514,13 @@ xmlNanoFTPGetConnection(void *ctx) {
res = send(ctxt->controlFd, buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
- return(res);
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
+ return INVALID_SOCKET;
}
res = xmlNanoFTPGetResponse(ctxt);
if (res != 2) {
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
- return(-1);
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
+ return INVALID_SOCKET;
}
}
return(ctxt->dataFd);
@@ -1542,9 +1543,9 @@ xmlNanoFTPCloseConnection(void *ctx) {
fd_set rfd, efd;
struct timeval tv;
- if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
+ if ((ctxt == NULL) || (ctxt->controlFd == INVALID_SOCKET)) return(-1);
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
tv.tv_sec = 15;
tv.tv_usec = 0;
FD_ZERO(&rfd);
@@ -1556,7 +1557,7 @@ xmlNanoFTPCloseConnection(void *ctx) {
#ifdef DEBUG_FTP
perror("select");
#endif
- closesocket(ctxt->controlFd); ctxt->controlFd = -1;
+ closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
return(-1);
}
if (res == 0) {
@@ -1564,11 +1565,11 @@ xmlNanoFTPCloseConnection(void *ctx) {
xmlGenericError(xmlGenericErrorContext,
"xmlNanoFTPCloseConnection: timeout\n");
#endif
- closesocket(ctxt->controlFd); ctxt->controlFd = -1;
+ closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
} else {
res = xmlNanoFTPGetResponse(ctxt);
if (res != 2) {
- closesocket(ctxt->controlFd); ctxt->controlFd = -1;
+ closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
return(-1);
}
}
@@ -1729,7 +1730,7 @@ xmlNanoFTPList(void *ctx, ftpListCallback callback, void *userData,
if (xmlNanoFTPCwd(ctxt, ctxt->path) < 1)
return(-1);
ctxt->dataFd = xmlNanoFTPGetConnection(ctxt);
- if (ctxt->dataFd == -1)
+ if (ctxt->dataFd == INVALID_SOCKET)
return(-1);
snprintf(buf, sizeof(buf), "LIST -L\r\n");
} else {
@@ -1738,7 +1739,7 @@ xmlNanoFTPList(void *ctx, ftpListCallback callback, void *userData,
return(-1);
}
ctxt->dataFd = xmlNanoFTPGetConnection(ctxt);
- if (ctxt->dataFd == -1)
+ if (ctxt->dataFd == INVALID_SOCKET)
return(-1);
snprintf(buf, sizeof(buf), "LIST -L %s\r\n", filename);
}
@@ -1750,12 +1751,12 @@ xmlNanoFTPList(void *ctx, ftpListCallback callback, void *userData,
res = send(ctxt->controlFd, buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
return(res);
}
res = xmlNanoFTPReadResponse(ctxt);
if (res != 1) {
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
return(-res);
}
@@ -1771,18 +1772,18 @@ xmlNanoFTPList(void *ctx, ftpListCallback callback, void *userData,
#ifdef DEBUG_FTP
perror("select");
#endif
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
return(-1);
}
if (res == 0) {
res = xmlNanoFTPCheckResponse(ctxt);
if (res < 0) {
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
- ctxt->dataFd = -1;
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
+ ctxt->dataFd = INVALID_SOCKET;
return(-1);
}
if (res == 2) {
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
return(0);
}
@@ -1791,8 +1792,8 @@ xmlNanoFTPList(void *ctx, ftpListCallback callback, void *userData,
if ((len = recv(ctxt->dataFd, &buf[indx], sizeof(buf) - (indx + 1), 0)) < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "recv");
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
- ctxt->dataFd = -1;
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
+ ctxt->dataFd = INVALID_SOCKET;
return(-1);
}
#ifdef DEBUG_FTP
@@ -1824,18 +1825,18 @@ xmlNanoFTPList(void *ctx, ftpListCallback callback, void *userData,
*/
-int
+SOCKET
xmlNanoFTPGetSocket(void *ctx, const char *filename) {
xmlNanoFTPCtxtPtr ctxt = (xmlNanoFTPCtxtPtr) ctx;
char buf[300];
int res, len;
if (ctx == NULL)
- return(-1);
+ return INVALID_SOCKET;
if ((filename == NULL) && (ctxt->path == NULL))
- return(-1);
+ return INVALID_SOCKET;
ctxt->dataFd = xmlNanoFTPGetConnection(ctxt);
- if (ctxt->dataFd == -1)
- return(-1);
+ if (ctxt->dataFd == INVALID_SOCKET)
+ return INVALID_SOCKET;
snprintf(buf, sizeof(buf), "TYPE I\r\n");
len = strlen(buf);
@@ -1845,13 +1846,13 @@ xmlNanoFTPGetSocket(void *ctx, const char *filename) {
res = send(ctxt->controlFd, buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
- return(res);
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
+ return INVALID_SOCKET;
}
res = xmlNanoFTPReadResponse(ctxt);
if (res != 2) {
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
- return(-res);
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
+ return INVALID_SOCKET;
}
if (filename == NULL)
snprintf(buf, sizeof(buf), "RETR %s\r\n", ctxt->path);
@@ -1865,13 +1866,13 @@ xmlNanoFTPGetSocket(void *ctx, const char *filename) {
res = send(ctxt->controlFd, buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
- return(res);
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
+ return INVALID_SOCKET;
}
res = xmlNanoFTPReadResponse(ctxt);
if (res != 1) {
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
- return(-res);
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
+ return INVALID_SOCKET;
}
return(ctxt->dataFd);
}
@@ -1903,7 +1904,7 @@ xmlNanoFTPGet(void *ctx, ftpDataCallback callback, void *userData,
return(-1);
if (callback == NULL)
return(-1);
- if (xmlNanoFTPGetSocket(ctxt, filename) < 0)
+ if (xmlNanoFTPGetSocket(ctxt, filename) == INVALID_SOCKET)
return(-1);
do {
@@ -1916,18 +1917,18 @@ xmlNanoFTPGet(void *ctx, ftpDataCallback callback, void *userData,
#ifdef DEBUG_FTP
perror("select");
#endif
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
return(-1);
}
if (res == 0) {
res = xmlNanoFTPCheckResponse(ctxt);
if (res < 0) {
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
- ctxt->dataFd = -1;
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
+ ctxt->dataFd = INVALID_SOCKET;
return(-1);
}
if (res == 2) {
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
return(0);
}
@@ -1936,7 +1937,7 @@ xmlNanoFTPGet(void *ctx, ftpDataCallback callback, void *userData,
if ((len = recv(ctxt->dataFd, buf, sizeof(buf), 0)) < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "recv failed");
callback(userData, buf, len);
- closesocket(ctxt->dataFd); ctxt->dataFd = -1;
+ closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
return(-1);
}
callback(userData, buf, len);
@@ -1962,7 +1963,7 @@ xmlNanoFTPRead(void *ctx, void *dest, int len) {
xmlNanoFTPCtxtPtr ctxt = (xmlNanoFTPCtxtPtr) ctx;
if (ctx == NULL) return(-1);
- if (ctxt->dataFd < 0) return(0);
+ if (ctxt->dataFd == INVALID_SOCKET) return(0);
if (dest == NULL) return(-1);
if (len <= 0) return(0);
@@ -1990,7 +1991,7 @@ xmlNanoFTPRead(void *ctx, void *dest, int len) {
void*
xmlNanoFTPOpen(const char *URL) {
xmlNanoFTPCtxtPtr ctxt;
- int sock;
+ SOCKET sock;
xmlNanoFTPInit();
if (URL == NULL) return(NULL);
@@ -2003,7 +2004,7 @@ xmlNanoFTPOpen(const char *URL) {
return(NULL);
}
sock = xmlNanoFTPGetSocket(ctxt, ctxt->path);
- if (sock < 0) {
+ if (sock == INVALID_SOCKET) {
xmlNanoFTPFreeCtxt(ctxt);
return(NULL);
}
@@ -2026,14 +2027,14 @@ xmlNanoFTPClose(void *ctx) {
if (ctxt == NULL)
return(-1);
- if (ctxt->dataFd >= 0) {
+ if (ctxt->dataFd != INVALID_SOCKET) {
closesocket(ctxt->dataFd);
- ctxt->dataFd = -1;
+ ctxt->dataFd = INVALID_SOCKET;
}
- if (ctxt->controlFd >= 0) {
+ if (ctxt->controlFd != INVALID_SOCKET) {
xmlNanoFTPQuit(ctxt);
closesocket(ctxt->controlFd);
- ctxt->controlFd = -1;
+ ctxt->controlFd = INVALID_SOCKET;
}
xmlNanoFTPFreeCtxt(ctxt);
return(0);
diff --git a/nanohttp.c b/nanohttp.c
index 542c4eac..f6694575 100644
--- a/nanohttp.c
+++ b/nanohttp.c
@@ -75,18 +75,18 @@
#ifdef VMS
#include
#define XML_SOCKLEN_T unsigned int
-#define SOCKET int
#endif
#if defined(__MINGW32__) || defined(_WIN32_WCE)
+#ifndef _WINSOCKAPI_
#define _WINSOCKAPI_
+#endif
#include
#include
#undef XML_SOCKLEN_T
#define XML_SOCKLEN_T unsigned int
#endif
-
#include
#include
#include
@@ -103,6 +103,7 @@
#define closesocket(s) close(s)
#endif
#define SOCKET int
+#define INVALID_SOCKET (-1)
#endif
#ifdef __BEOS__
@@ -114,9 +115,6 @@
#ifndef XML_SOCKLEN_T
#define XML_SOCKLEN_T unsigned int
#endif
-#ifndef SOCKET
-#define SOCKET int
-#endif
#ifdef STANDALONE
#define DEBUG_HTTP
@@ -196,10 +194,10 @@ static int socket_errno(void) {
#ifdef SUPPORT_IP6
static
int have_ipv6(void) {
- int s;
+ SOCKET s;
s = socket (AF_INET6, SOCK_STREAM, 0);
- if (s != -1) {
+ if (s != INVALID_SOCKET) {
close (s);
return (1);
}
@@ -393,7 +391,7 @@ xmlNanoHTTPNewCtxt(const char *URL) {
memset(ret, 0, sizeof(xmlNanoHTTPCtxt));
ret->port = 80;
ret->returnValue = 0;
- ret->fd = -1;
+ ret->fd = INVALID_SOCKET;
ret->ContentLength = -1;
xmlNanoHTTPScanURL(ret, URL);
@@ -430,8 +428,8 @@ xmlNanoHTTPFreeCtxt(xmlNanoHTTPCtxtPtr ctxt) {
#endif
ctxt->state = XML_NANO_HTTP_NONE;
- if (ctxt->fd >= 0) closesocket(ctxt->fd);
- ctxt->fd = -1;
+ if (ctxt->fd != INVALID_SOCKET) closesocket(ctxt->fd);
+ ctxt->fd = INVALID_SOCKET;
xmlFree(ctxt);
}
@@ -842,7 +840,7 @@ xmlNanoHTTPScanAnswer(xmlNanoHTTPCtxtPtr ctxt, const char *line) {
* Returns -1 in case of failure, the file descriptor number otherwise
*/
-static int
+static SOCKET
xmlNanoHTTPConnectAttempt(struct sockaddr *addr)
{
#ifndef HAVE_POLL_H
@@ -870,12 +868,12 @@ xmlNanoHTTPConnectAttempt(struct sockaddr *addr)
s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
addrlen = sizeof(struct sockaddr_in);
}
- if (s == -1) {
+ if (s == INVALID_SOCKET) {
#ifdef DEBUG_HTTP
perror("socket");
#endif
__xmlIOErr(XML_FROM_HTTP, 0, "socket failed\n");
- return (-1);
+ return INVALID_SOCKET;
}
#ifdef _WINSOCKAPI_
{
@@ -916,7 +914,7 @@ xmlNanoHTTPConnectAttempt(struct sockaddr *addr)
#endif
__xmlIOErr(XML_FROM_HTTP, 0, "error setting non-blocking IO\n");
closesocket(s);
- return (-1);
+ return INVALID_SOCKET;
}
#endif /* !__BEOS__ */
#endif /* !VMS */
@@ -931,7 +929,7 @@ xmlNanoHTTPConnectAttempt(struct sockaddr *addr)
__xmlIOErr(XML_FROM_HTTP, 0,
"error connecting to HTTP server");
closesocket(s);
- return (-1);
+ return INVALID_SOCKET;
}
}
#ifndef HAVE_POLL_H
@@ -944,7 +942,7 @@ xmlNanoHTTPConnectAttempt(struct sockaddr *addr)
#endif
#ifndef _WINSOCKAPI_
if (s > FD_SETSIZE)
- return -1;
+ return INVALID_SOCKET;
#endif
FD_ZERO(&wfd);
FD_SET(s, &wfd);
@@ -972,12 +970,12 @@ xmlNanoHTTPConnectAttempt(struct sockaddr *addr)
/* Time out */
__xmlIOErr(XML_FROM_HTTP, 0, "Connect attempt timed out");
closesocket(s);
- return (-1);
+ return INVALID_SOCKET;
case -1:
/* Ermm.. ?? */
__xmlIOErr(XML_FROM_HTTP, 0, "Connect failed");
closesocket(s);
- return (-1);
+ return INVALID_SOCKET;
}
#ifndef HAVE_POLL_H
@@ -998,7 +996,7 @@ xmlNanoHTTPConnectAttempt(struct sockaddr *addr)
0) {
/* Solaris error code */
__xmlIOErr(XML_FROM_HTTP, 0, "getsockopt failed\n");
- return (-1);
+ return INVALID_SOCKET;
}
#endif
if (status) {
@@ -1006,13 +1004,13 @@ xmlNanoHTTPConnectAttempt(struct sockaddr *addr)
"Error connecting to remote host");
closesocket(s);
errno = status;
- return (-1);
+ return INVALID_SOCKET;
}
} else {
/* pbm */
__xmlIOErr(XML_FROM_HTTP, 0, "select failed\n");
closesocket(s);
- return (-1);
+ return INVALID_SOCKET;
}
return (s);
@@ -1029,7 +1027,7 @@ xmlNanoHTTPConnectAttempt(struct sockaddr *addr)
* Returns -1 in case of failure, the file descriptor number otherwise
*/
-static int
+static SOCKET
xmlNanoHTTPConnectHost(const char *host, int port)
{
struct hostent *h;
@@ -1042,7 +1040,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
struct sockaddr_in6 sockin6;
#endif
int i;
- int s;
+ SOCKET s;
memset (&sockin, 0, sizeof(sockin));
#ifdef SUPPORT_IP6
@@ -1073,7 +1071,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
status = getaddrinfo (host, NULL, &hints, &result);
if (status) {
__xmlIOErr(XML_FROM_HTTP, 0, "getaddrinfo failed\n");
- return (-1);
+ return INVALID_SOCKET;
}
for (res = result; res; res = res->ai_next) {
@@ -1081,7 +1079,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
if (res->ai_addrlen > sizeof(sockin)) {
__xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n");
freeaddrinfo (result);
- return (-1);
+ return INVALID_SOCKET;
}
memcpy (&sockin, res->ai_addr, res->ai_addrlen);
sockin.sin_port = htons (port);
@@ -1091,7 +1089,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
if (res->ai_addrlen > sizeof(sockin6)) {
__xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n");
freeaddrinfo (result);
- return (-1);
+ return INVALID_SOCKET;
}
memcpy (&sockin6, res->ai_addr, res->ai_addrlen);
sockin6.sin6_port = htons (port);
@@ -1101,7 +1099,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
continue; /* for */
s = xmlNanoHTTPConnectAttempt (addr);
- if (s != -1) {
+ if (s != INVALID_SOCKET) {
freeaddrinfo (result);
return (s);
}
@@ -1155,7 +1153,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
#else
__xmlIOErr(XML_FROM_HTTP, 0, "Failed to resolve host");
#endif
- return (-1);
+ return INVALID_SOCKET;
}
for (i = 0; h->h_addr_list[i]; i++) {
@@ -1163,7 +1161,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
/* A records (IPv4) */
if ((unsigned int) h->h_length > sizeof(ia)) {
__xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n");
- return (-1);
+ return INVALID_SOCKET;
}
memcpy (&ia, h->h_addr_list[i], h->h_length);
sockin.sin_family = h->h_addrtype;
@@ -1175,7 +1173,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
/* AAAA records (IPv6) */
if ((unsigned int) h->h_length > sizeof(ia6)) {
__xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n");
- return (-1);
+ return INVALID_SOCKET;
}
memcpy (&ia6, h->h_addr_list[i], h->h_length);
sockin6.sin6_family = h->h_addrtype;
@@ -1187,7 +1185,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
break; /* for */
s = xmlNanoHTTPConnectAttempt (addr);
- if (s != -1)
+ if (s != INVALID_SOCKET)
return (s);
}
}
@@ -1198,7 +1196,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
"xmlNanoHTTPConnectHost: unable to connect to '%s'.\n",
host);
#endif
- return (-1);
+ return INVALID_SOCKET;
}
@@ -1342,7 +1340,8 @@ xmlNanoHTTPMethodRedir(const char *URL, const char *method, const char *input,
const char *headers, int ilen ) {
xmlNanoHTTPCtxtPtr ctxt;
char *bp, *p;
- int blen, ret;
+ int blen;
+ SOCKET ret;
int nbRedirects = 0;
char *redirURL = NULL;
#ifdef DEBUG_HTTP
@@ -1386,7 +1385,7 @@ retry:
blen = strlen(ctxt->hostname);
ret = xmlNanoHTTPConnectHost(ctxt->hostname, ctxt->port);
}
- if (ret < 0) {
+ if (ret == INVALID_SOCKET) {
xmlNanoHTTPFreeCtxt(ctxt);
if (redirURL != NULL) xmlFree(redirURL);
return(NULL);
diff --git a/testapi.c b/testapi.c
index da6ce1bc..df14820a 100644
--- a/testapi.c
+++ b/testapi.c
@@ -11639,32 +11639,8 @@ static int
test_xmlNanoFTPGetConnection(void) {
int test_ret = 0;
-#if defined(LIBXML_FTP_ENABLED)
- int mem_base;
- int ret_val;
- void * ctx; /* an FTP context */
- int n_ctx;
-
- for (n_ctx = 0;n_ctx < gen_nb_xmlNanoFTPCtxtPtr;n_ctx++) {
- mem_base = xmlMemBlocks();
- ctx = gen_xmlNanoFTPCtxtPtr(n_ctx, 0);
-
- ret_val = xmlNanoFTPGetConnection(ctx);
- desret_int(ret_val);
- call_tests++;
- des_xmlNanoFTPCtxtPtr(n_ctx, ctx, 0);
- xmlResetLastError();
- if (mem_base != xmlMemBlocks()) {
- printf("Leak of %d blocks found in xmlNanoFTPGetConnection",
- xmlMemBlocks() - mem_base);
- test_ret++;
- printf(" %d", n_ctx);
- printf("\n");
- }
- }
- function_tests++;
-#endif
+ /* missing type support */
return(test_ret);
}
@@ -11707,39 +11683,8 @@ static int
test_xmlNanoFTPGetSocket(void) {
int test_ret = 0;
-#if defined(LIBXML_FTP_ENABLED)
- int mem_base;
- int ret_val;
- void * ctx; /* an FTP context */
- int n_ctx;
- const char * filename; /* the file to retrieve (or NULL if path is in context). */
- int n_filename;
-
- for (n_ctx = 0;n_ctx < gen_nb_xmlNanoFTPCtxtPtr;n_ctx++) {
- for (n_filename = 0;n_filename < gen_nb_filepath;n_filename++) {
- mem_base = xmlMemBlocks();
- ctx = gen_xmlNanoFTPCtxtPtr(n_ctx, 0);
- filename = gen_filepath(n_filename, 1);
-
- ret_val = xmlNanoFTPGetSocket(ctx, filename);
- desret_int(ret_val);
- call_tests++;
- des_xmlNanoFTPCtxtPtr(n_ctx, ctx, 0);
- des_filepath(n_filename, filename, 1);
- xmlResetLastError();
- if (mem_base != xmlMemBlocks()) {
- printf("Leak of %d blocks found in xmlNanoFTPGetSocket",
- xmlMemBlocks() - mem_base);
- test_ret++;
- printf(" %d", n_ctx);
- printf(" %d", n_filename);
- printf("\n");
- }
- }
- }
- function_tests++;
-#endif
+ /* missing type support */
return(test_ret);
}
@@ -12043,7 +11988,7 @@ static int
test_nanoftp(void) {
int test_ret = 0;
- if (quiet == 0) printf("Testing nanoftp : 16 of 22 functions ...\n");
+ if (quiet == 0) printf("Testing nanoftp : 14 of 22 functions ...\n");
test_ret += test_xmlNanoFTPCheckResponse();
test_ret += test_xmlNanoFTPCleanup();
test_ret += test_xmlNanoFTPCloseConnection();
|
|
|
|
|
|
|
|
|
|