#include <netdb.h>
#endif
#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
+#include <fcntl.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
xmlNanoFTPInit(void) {
const char *env;
#ifdef _WINSOCKAPI_
- WSADATA wsaData;
+ WSADATA wsaData;
#endif
if (initialized)
/*
* Clear any existing data from the context
*/
- if (ctxt->protocol != NULL) {
+ if (ctxt->protocol != NULL) {
xmlFree(ctxt->protocol);
ctxt->protocol = NULL;
}
- if (ctxt->hostname != NULL) {
+ if (ctxt->hostname != NULL) {
xmlFree(ctxt->hostname);
ctxt->hostname = NULL;
}
- if (ctxt->path != NULL) {
+ if (ctxt->path != NULL) {
xmlFree(ctxt->path);
ctxt->path = NULL;
}
xmlFreeURI(uri);
return;
}
-
+
ctxt->protocol = xmlMemStrdup(uri->scheme);
ctxt->hostname = xmlMemStrdup(uri->server);
if (uri->path != NULL)
* @URL: The URL used to update the context
*
* Update an FTP context by parsing the URL and finding
- * new path it indicates. If there is an error in the
+ * new path it indicates. If there is an error in the
* protocol, hostname, port or other information, the
* error is raised. It indicates a new connection has to
* be established.
ctxt->path = NULL;
}
- if (uri->path == NULL)
+ if (uri->path == NULL)
ctxt->path = xmlMemStrdup("/");
else
ctxt->path = xmlMemStrdup(uri->path);
xmlNanoFTPScanProxy(const char *URL) {
xmlURIPtr uri;
- if (proxy != NULL) {
+ if (proxy != NULL) {
xmlFree(proxy);
proxy = NULL;
}
xmlFreeURI(uri);
return;
}
-
+
proxy = xmlMemStrdup(uri->server);
if (uri->port != 0)
proxyPort = uri->port;
* xmlNanoFTPParseResponse:
* @buf: the buffer containing the response
* @len: the buffer length
- *
+ *
* Parsing of the server answer, we just extract the code.
*
* returns 0 for errors
int val = 0;
if (len < 3) return(-1);
- if ((*buf >= '0') && (*buf <= '9'))
+ if ((*buf >= '0') && (*buf <= '9'))
val = val * 10 + (*buf - '0');
else
return(0);
buf++;
- if ((*buf >= '0') && (*buf <= '9'))
+ if ((*buf >= '0') && (*buf <= '9'))
val = val * 10 + (*buf - '0');
else
return(0);
buf++;
- if ((*buf >= '0') && (*buf <= '9'))
+ if ((*buf >= '0') && (*buf <= '9'))
val = val * 10 + (*buf - '0');
else
return(0);
buf++;
- if (*buf == '-')
+ if (*buf == '-')
return(-val);
return(val);
}
case -1:
__xmlIOErr(XML_FROM_FTP, 0, "select");
return(-1);
-
+
}
return(xmlNanoFTPReadResponse(ctx));
#ifdef DEBUG_FTP
xmlGenericError(xmlGenericErrorContext, "%s", buf);
#endif
- res = send(ctxt->controlFd, buf, len, 0);
+ res = send(ctxt->controlFd, SEND_ARG2_CAST buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
return(res);
#ifdef DEBUG_FTP
xmlGenericError(xmlGenericErrorContext, "%s", buf);
#endif
- res = send(ctxt->controlFd, buf, len, 0);
+ res = send(ctxt->controlFd, SEND_ARG2_CAST buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
return(res);
#ifdef DEBUG_FTP
xmlGenericError(xmlGenericErrorContext, "%s", buf); /* Just to be consistent, even though we know it can't have a % in it */
#endif
- res = send(ctxt->controlFd, buf, len, 0);
+ res = send(ctxt->controlFd, SEND_ARG2_CAST buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
return(res);
return (-1);
}
if (tmp->ai_addrlen > sizeof(ctxt->ftpAddr)) {
+ if (result)
+ freeaddrinfo (result);
__xmlIOErr(XML_FROM_FTP, 0, "gethostbyname address mismatch");
return (-1);
}
#endif
{
if (proxy)
- hp = gethostbyname (proxy);
+ hp = gethostbyname (GETHOSTBYNAME_ARG_CAST proxy);
else
- hp = gethostbyname (ctxt->hostname);
+ hp = gethostbyname (GETHOSTBYNAME_ARG_CAST ctxt->hostname);
if (hp == NULL) {
__xmlIOErr(XML_FROM_FTP, 0, "gethostbyname failed");
return (-1);
#ifdef DEBUG_FTP
xmlGenericError(xmlGenericErrorContext, "%s", buf);
#endif
- res = send(ctxt->controlFd, buf, len, 0);
+ res = send(ctxt->controlFd, SEND_ARG2_CAST buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
closesocket(ctxt->controlFd);
#ifdef DEBUG_FTP
xmlGenericError(xmlGenericErrorContext, "%s", buf);
#endif
- res = send(ctxt->controlFd, buf, len, 0);
+ res = send(ctxt->controlFd, SEND_ARG2_CAST buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
closesocket(ctxt->controlFd);
#ifdef DEBUG_FTP
xmlGenericError(xmlGenericErrorContext, "%s", buf);
#endif
- res = send(ctxt->controlFd, buf, len, 0);
+ res = send(ctxt->controlFd, SEND_ARG2_CAST buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
/* we assume it worked :-\ 1 is error for SITE command */
proxyType = 1;
break;
- }
+ }
if (proxyType == 1) {
closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
ctxt->controlFd = INVALID_SOCKET;
#ifdef DEBUG_FTP
xmlGenericError(xmlGenericErrorContext, "%s", buf);
#endif
- res = send(ctxt->controlFd, buf, len, 0);
+ res = send(ctxt->controlFd, SEND_ARG2_CAST buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
/* we assume it worked :-\ */
proxyType = 2;
return(0);
- }
+ }
if (ctxt->passwd == NULL)
snprintf(buf, sizeof(buf), "PASS anonymous@\r\n");
else
#ifdef DEBUG_FTP
xmlGenericError(xmlGenericErrorContext, "%s", buf);
#endif
- res = send(ctxt->controlFd, buf, len, 0);
+ res = send(ctxt->controlFd, SEND_ARG2_CAST buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
int res;
xmlNanoFTPInit();
- if (server == NULL)
+ if (server == NULL)
return(NULL);
if (port <= 0)
return(NULL);
ctxt = (xmlNanoFTPCtxtPtr) xmlNanoFTPNewCtxt(NULL);
+ if (ctxt == NULL)
+ return(NULL);
ctxt->hostname = xmlMemStrdup(server);
+ if (ctxt->hostname == NULL) {
+ xmlNanoFTPFreeCtxt(ctxt);
+ return(NULL);
+ }
if (port != 0)
ctxt->port = port;
res = xmlNanoFTPConnect(ctxt);
#ifdef DEBUG_FTP
xmlGenericError(xmlGenericErrorContext, "%s", buf);
#endif
- res = send(ctxt->controlFd, buf, len, 0);
+ res = send(ctxt->controlFd, SEND_ARG2_CAST buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
return(res);
int len;
int res;
- if ((ctxt == NULL) || (ctxt->controlFd == INVALID_SOCKET) || (file == NULL)) return(-1);
- if (file == NULL) return (0);
+ if ((ctxt == NULL) || (ctxt->controlFd == INVALID_SOCKET) ||
+ (file == NULL)) return(-1);
/*
* Expected response code for DELE:
* 450, 550
* 500, 501, 502, 421, 530
*/
-
+
snprintf(buf, sizeof(buf), "DELE %s\r\n", file);
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP
xmlGenericError(xmlGenericErrorContext, "%s", buf);
#endif
- res = send(ctxt->controlFd, buf, len, 0);
+ res = send(ctxt->controlFd, SEND_ARG2_CAST buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
return(res);
#ifdef DEBUG_FTP
xmlGenericError(xmlGenericErrorContext, "%s", buf);
#endif
- res = send(ctxt->controlFd, buf, len, 0);
+ res = send(ctxt->controlFd, SEND_ARG2_CAST buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
ctxt->passive = 0;
}
}
- cur = &ctxt->controlBuf[ctxt->controlBufAnswer];
+ cur = &ctxt->controlBuf[ctxt->controlBufAnswer];
while (((*cur < '0') || (*cur > '9')) && *cur != '\0') cur++;
#ifdef SUPPORT_IP6
if ((ctxt->ftpAddr).ss_family == AF_INET6) {
xmlGenericError(xmlGenericErrorContext, "%s", buf);
#endif
- res = send(ctxt->controlFd, buf, len, 0);
+ res = send(ctxt->controlFd, SEND_ARG2_CAST buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
}
}
return(ctxt->dataFd);
-
+
}
/**
* @callback: the user callback
* @userData: the user callback data
*
- * Parse at most one entry from the listing.
+ * Parse at most one entry from the listing.
*
* Returns -1 incase of error, the length of data parsed otherwise
*/
if (*cur == 0) return(0);
i = 0;
while (*cur != ' ') {
- if (i < 10)
+ if (i < 10)
attrib[i++] = *cur;
cur++;
if (*cur == 0) return(0);
if (*cur == 0) return(0);
i = 0;
while (*cur != ' ') {
- if (i < 10)
+ if (i < 10)
owner[i++] = *cur;
cur++;
if (*cur == 0) return(0);
if (*cur == 0) return(0);
i = 0;
while (*cur != ' ') {
- if (i < 10)
+ if (i < 10)
group[i++] = *cur;
cur++;
if (*cur == 0) return(0);
#ifdef DEBUG_FTP
xmlGenericError(xmlGenericErrorContext, "%s", buf);
#endif
- res = send(ctxt->controlFd, buf, len, 0);
+ res = send(ctxt->controlFd, SEND_ARG2_CAST buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
#ifdef DEBUG_FTP
xmlGenericError(xmlGenericErrorContext, "%s", buf);
#endif
- res = send(ctxt->controlFd, buf, len, 0);
+ res = send(ctxt->controlFd, SEND_ARG2_CAST buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
#ifdef DEBUG_FTP
xmlGenericError(xmlGenericErrorContext, "%s", buf);
#endif
- res = send(ctxt->controlFd, buf, len, 0);
+ res = send(ctxt->controlFd, SEND_ARG2_CAST buf, len, 0);
if (res < 0) {
__xmlIOErr(XML_FROM_FTP, 0, "send failed");
closesocket(ctxt->dataFd); ctxt->dataFd = INVALID_SOCKET;
*
* Start to fetch the given ftp:// resource
*
- * Returns an FTP context, or NULL
+ * Returns an FTP context, or NULL
*/
void*
#ifdef STANDALONE
/************************************************************************
- * *
- * Basic test in Standalone mode *
- * *
+ * *
+ * Basic test in Standalone mode *
+ * *
************************************************************************/
static
void ftpList(void *userData, const char *filename, const char* attrib,
if (len <= 0) {
fclose((FILE*)userData);
return;
- }
+ }
fwrite(data, len, 1, (FILE*)userData);
}
if (xmlNanoFTPGet(ctxt, ftpData, (void *) output, tstfile) < 0)
xmlGenericError(xmlGenericErrorContext,
"Failed to get file\n");
-
+
}
xmlNanoFTPClose(ctxt);
xmlMemoryDump();