Diff for /embedaddon/libxml2/nanoftp.c between versions 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2013/07/22 01:22:19 version 1.1.1.3, 2014/06/15 19:53:29
Line 41 Line 41
 #include <netdb.h>  #include <netdb.h>
 #endif  #endif
 #ifdef HAVE_FCNTL_H  #ifdef HAVE_FCNTL_H
#include <fcntl.h> #include <fcntl.h>
 #endif  #endif
 #ifdef HAVE_ERRNO_H  #ifdef HAVE_ERRNO_H
 #include <errno.h>  #include <errno.h>
Line 188  void Line 188  void
 xmlNanoFTPInit(void) {  xmlNanoFTPInit(void) {
     const char *env;      const char *env;
 #ifdef _WINSOCKAPI_  #ifdef _WINSOCKAPI_
    WSADATA wsaData;        WSADATA wsaData;
 #endif  #endif
   
     if (initialized)      if (initialized)
Line 305  xmlNanoFTPScanURL(void *ctx, const char *URL) { Line 305  xmlNanoFTPScanURL(void *ctx, const char *URL) {
     /*      /*
      * Clear any existing data from the context       * Clear any existing data from the context
      */       */
    if (ctxt->protocol != NULL) {     if (ctxt->protocol != NULL) {
         xmlFree(ctxt->protocol);          xmlFree(ctxt->protocol);
         ctxt->protocol = NULL;          ctxt->protocol = NULL;
     }      }
    if (ctxt->hostname != NULL) {     if (ctxt->hostname != NULL) {
         xmlFree(ctxt->hostname);          xmlFree(ctxt->hostname);
         ctxt->hostname = NULL;          ctxt->hostname = NULL;
     }      }
    if (ctxt->path != NULL) {     if (ctxt->path != NULL) {
         xmlFree(ctxt->path);          xmlFree(ctxt->path);
         ctxt->path = NULL;          ctxt->path = NULL;
     }      }
Line 327  xmlNanoFTPScanURL(void *ctx, const char *URL) { Line 327  xmlNanoFTPScanURL(void *ctx, const char *URL) {
         xmlFreeURI(uri);          xmlFreeURI(uri);
         return;          return;
     }      }
    
     ctxt->protocol = xmlMemStrdup(uri->scheme);      ctxt->protocol = xmlMemStrdup(uri->scheme);
     ctxt->hostname = xmlMemStrdup(uri->server);      ctxt->hostname = xmlMemStrdup(uri->server);
     if (uri->path != NULL)      if (uri->path != NULL)
Line 358  xmlNanoFTPScanURL(void *ctx, const char *URL) { Line 358  xmlNanoFTPScanURL(void *ctx, const char *URL) {
  * @URL:  The URL used to update the context   * @URL:  The URL used to update the context
  *   *
  * Update an FTP context by parsing the URL and finding   * 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   * protocol, hostname, port or other information, the
  * error is raised. It indicates a new connection has to   * error is raised. It indicates a new connection has to
  * be established.   * be established.
Line 403  xmlNanoFTPUpdateURL(void *ctx, const char *URL) { Line 403  xmlNanoFTPUpdateURL(void *ctx, const char *URL) {
         ctxt->path = NULL;          ctxt->path = NULL;
     }      }
   
    if (uri->path == NULL)     if (uri->path == NULL)
         ctxt->path = xmlMemStrdup("/");          ctxt->path = xmlMemStrdup("/");
     else      else
         ctxt->path = xmlMemStrdup(uri->path);          ctxt->path = xmlMemStrdup(uri->path);
Line 427  void Line 427  void
 xmlNanoFTPScanProxy(const char *URL) {  xmlNanoFTPScanProxy(const char *URL) {
     xmlURIPtr uri;      xmlURIPtr uri;
   
    if (proxy != NULL) {     if (proxy != NULL) {
         xmlFree(proxy);          xmlFree(proxy);
         proxy = NULL;          proxy = NULL;
     }      }
Line 451  xmlNanoFTPScanProxy(const char *URL) { Line 451  xmlNanoFTPScanProxy(const char *URL) {
             xmlFreeURI(uri);              xmlFreeURI(uri);
         return;          return;
     }      }
    
     proxy = xmlMemStrdup(uri->server);      proxy = xmlMemStrdup(uri->server);
     if (uri->port != 0)      if (uri->port != 0)
         proxyPort = uri->port;          proxyPort = uri->port;
Line 523  xmlNanoFTPFreeCtxt(void * ctx) { Line 523  xmlNanoFTPFreeCtxt(void * ctx) {
  * xmlNanoFTPParseResponse:   * xmlNanoFTPParseResponse:
  * @buf:  the buffer containing the response   * @buf:  the buffer containing the response
  * @len:  the buffer length   * @len:  the buffer length
 *  *
  * Parsing of the server answer, we just extract the code.   * Parsing of the server answer, we just extract the code.
  *   *
  * returns 0 for errors   * returns 0 for errors
Line 535  xmlNanoFTPParseResponse(char *buf, int len) { Line 535  xmlNanoFTPParseResponse(char *buf, int len) {
     int val = 0;      int val = 0;
   
     if (len < 3) return(-1);      if (len < 3) return(-1);
    if ((*buf >= '0') && (*buf <= '9'))     if ((*buf >= '0') && (*buf <= '9'))
         val = val * 10 + (*buf - '0');          val = val * 10 + (*buf - '0');
     else      else
         return(0);          return(0);
     buf++;      buf++;
    if ((*buf >= '0') && (*buf <= '9'))     if ((*buf >= '0') && (*buf <= '9'))
         val = val * 10 + (*buf - '0');          val = val * 10 + (*buf - '0');
     else      else
         return(0);          return(0);
     buf++;      buf++;
    if ((*buf >= '0') && (*buf <= '9'))     if ((*buf >= '0') && (*buf <= '9'))
         val = val * 10 + (*buf - '0');          val = val * 10 + (*buf - '0');
     else      else
         return(0);          return(0);
     buf++;      buf++;
    if (*buf == '-')     if (*buf == '-')
         return(-val);          return(-val);
     return(val);      return(val);
 }  }
Line 749  xmlNanoFTPCheckResponse(void *ctx) { Line 749  xmlNanoFTPCheckResponse(void *ctx) {
         case -1:          case -1:
             __xmlIOErr(XML_FROM_FTP, 0, "select");              __xmlIOErr(XML_FROM_FTP, 0, "select");
             return(-1);              return(-1);
                        
     }      }
   
     return(xmlNanoFTPReadResponse(ctx));      return(xmlNanoFTPReadResponse(ctx));
Line 1103  xmlNanoFTPConnect(void *ctx) { Line 1103  xmlNanoFTPConnect(void *ctx) {
                     /* we assume it worked :-\ 1 is error for SITE command */                      /* we assume it worked :-\ 1 is error for SITE command */
                     proxyType = 1;                      proxyType = 1;
                     break;                      break;
                }                    }
                 if (proxyType == 1) {                  if (proxyType == 1) {
                     closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;                      closesocket(ctxt->controlFd); ctxt->controlFd = INVALID_SOCKET;
                     ctxt->controlFd = INVALID_SOCKET;                      ctxt->controlFd = INVALID_SOCKET;
Line 1134  xmlNanoFTPConnect(void *ctx) { Line 1134  xmlNanoFTPConnect(void *ctx) {
                     /* we assume it worked :-\ */                      /* we assume it worked :-\ */
                     proxyType = 2;                      proxyType = 2;
                     return(0);                      return(0);
                }                    }
                 if (ctxt->passwd == NULL)                  if (ctxt->passwd == NULL)
                     snprintf(buf, sizeof(buf), "PASS anonymous@\r\n");                      snprintf(buf, sizeof(buf), "PASS anonymous@\r\n");
                 else                  else
Line 1239  xmlNanoFTPConnectTo(const char *server, int port) { Line 1239  xmlNanoFTPConnectTo(const char *server, int port) {
     int res;      int res;
   
     xmlNanoFTPInit();      xmlNanoFTPInit();
    if (server == NULL)     if (server == NULL)
         return(NULL);          return(NULL);
     if (port <= 0)      if (port <= 0)
         return(NULL);          return(NULL);
Line 1332  xmlNanoFTPDele(void *ctx, const char *file) { Line 1332  xmlNanoFTPDele(void *ctx, const char *file) {
      *       450, 550       *       450, 550
      *       500, 501, 502, 421, 530       *       500, 501, 502, 421, 530
      */       */
         
     snprintf(buf, sizeof(buf), "DELE %s\r\n", file);      snprintf(buf, sizeof(buf), "DELE %s\r\n", file);
     buf[sizeof(buf) - 1] = 0;      buf[sizeof(buf) - 1] = 0;
     len = strlen(buf);      len = strlen(buf);
Line 1430  xmlNanoFTPGetConnection(void *ctx) { Line 1430  xmlNanoFTPGetConnection(void *ctx) {
                 ctxt->passive = 0;                  ctxt->passive = 0;
             }              }
         }          }
        cur = &ctxt->controlBuf[ctxt->controlBufAnswer];         cur = &ctxt->controlBuf[ctxt->controlBufAnswer];
         while (((*cur < '0') || (*cur > '9')) && *cur != '\0') cur++;          while (((*cur < '0') || (*cur > '9')) && *cur != '\0') cur++;
 #ifdef SUPPORT_IP6  #ifdef SUPPORT_IP6
         if ((ctxt->ftpAddr).ss_family == AF_INET6) {          if ((ctxt->ftpAddr).ss_family == AF_INET6) {
Line 1525  xmlNanoFTPGetConnection(void *ctx) { Line 1525  xmlNanoFTPGetConnection(void *ctx) {
         }          }
     }      }
     return(ctxt->dataFd);      return(ctxt->dataFd);
    
 }  }
   
 /**  /**
Line 1583  xmlNanoFTPCloseConnection(void *ctx) { Line 1583  xmlNanoFTPCloseConnection(void *ctx) {
  * @callback:  the user callback   * @callback:  the user callback
  * @userData:  the user callback data   * @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   * Returns -1 incase of error, the length of data parsed otherwise
  */   */
Line 1620  xmlNanoFTPParseList(const char *list, ftpListCallback  Line 1620  xmlNanoFTPParseList(const char *list, ftpListCallback 
         if (*cur == 0) return(0);          if (*cur == 0) return(0);
         i = 0;          i = 0;
         while (*cur != ' ') {          while (*cur != ' ') {
            if (i < 10)             if (i < 10)
                 attrib[i++] = *cur;                  attrib[i++] = *cur;
             cur++;              cur++;
             if (*cur == 0) return(0);              if (*cur == 0) return(0);
Line 1634  xmlNanoFTPParseList(const char *list, ftpListCallback  Line 1634  xmlNanoFTPParseList(const char *list, ftpListCallback 
         if (*cur == 0) return(0);          if (*cur == 0) return(0);
         i = 0;          i = 0;
         while (*cur != ' ') {          while (*cur != ' ') {
            if (i < 10)             if (i < 10)
                 owner[i++] = *cur;                  owner[i++] = *cur;
             cur++;              cur++;
             if (*cur == 0) return(0);              if (*cur == 0) return(0);
Line 1644  xmlNanoFTPParseList(const char *list, ftpListCallback  Line 1644  xmlNanoFTPParseList(const char *list, ftpListCallback 
         if (*cur == 0) return(0);          if (*cur == 0) return(0);
         i = 0;          i = 0;
         while (*cur != ' ') {          while (*cur != ' ') {
            if (i < 10)             if (i < 10)
                 group[i++] = *cur;                  group[i++] = *cur;
             cur++;              cur++;
             if (*cur == 0) return(0);              if (*cur == 0) return(0);
Line 1986  xmlNanoFTPRead(void *ctx, void *dest, int len) { Line 1986  xmlNanoFTPRead(void *ctx, void *dest, int len) {
  *   *
  * Start to fetch the given ftp:// resource   * Start to fetch the given ftp:// resource
  *   *
 * Returns an FTP context, or NULL  * Returns an FTP context, or NULL
  */   */
   
 void*  void*
Line 2043  xmlNanoFTPClose(void *ctx) { Line 2043  xmlNanoFTPClose(void *ctx) {
   
 #ifdef STANDALONE  #ifdef STANDALONE
 /************************************************************************  /************************************************************************
 *                                                                      * *                                                                        *
 *                      Basic test in Standalone mode                   * *                      Basic test in Standalone mode                   *
 *                                                                      * *                                                                      *
  ************************************************************************/   ************************************************************************/
 static  static
 void ftpList(void *userData, const char *filename, const char* attrib,  void ftpList(void *userData, const char *filename, const char* attrib,
Line 2060  void ftpData(void *userData, const char *data, int len Line 2060  void ftpData(void *userData, const char *data, int len
     if (len <= 0) {      if (len <= 0) {
         fclose((FILE*)userData);          fclose((FILE*)userData);
         return;          return;
    }       }
     fwrite(data, len, 1, (FILE*)userData);      fwrite(data, len, 1, (FILE*)userData);
 }  }
   
Line 2092  int main(int argc, char **argv) { Line 2092  int main(int argc, char **argv) {
         if (xmlNanoFTPGet(ctxt, ftpData, (void *) output, tstfile) < 0)          if (xmlNanoFTPGet(ctxt, ftpData, (void *) output, tstfile) < 0)
             xmlGenericError(xmlGenericErrorContext,              xmlGenericError(xmlGenericErrorContext,
                     "Failed to get file\n");                      "Failed to get file\n");
        
     }      }
     xmlNanoFTPClose(ctxt);      xmlNanoFTPClose(ctxt);
     xmlMemoryDump();      xmlMemoryDump();

Removed from v.1.1.1.2  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>