home *** CD-ROM | disk | FTP | other *** search
/ ftp.ncftp.com / ftp.ncftp.com.zip / ftp.ncftp.com / ncftp / older_versions / ncftp-3.2.2-src.tar.bz2 / ncftp-3.2.2-src.tar / ncftp-3.2.2 / libncftp / ncftp.h < prev    next >
C/C++ Source or Header  |  2008-09-04  |  42KB  |  1,110 lines

  1. /* ncftp.h
  2.  *
  3.  * Copyright (c) 1996-2008 Mike Gleason, NcFTP Software.
  4.  * All rights reserved.
  5.  *
  6.  */
  7.  
  8. #ifndef _ncftp_h_
  9. #define _ncftp_h_ 1
  10.  
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif    /* __cplusplus */
  15.  
  16. #define kLibraryVersion "@(#) LibNcFTP 3.2.3 (September 4, 2008)"
  17.  
  18. /* This is used to verify validty of the data passed in. */
  19. #define kLibraryMagic "LibNcFTP 3.2.3"
  20.  
  21. #if (defined(WIN32) || defined(_WINDOWS)) && !defined(__CYGWIN__)
  22.     /* Includes for Windows */
  23. #    pragma once
  24. #    pragma warning(disable : 4127)    // warning C4127: conditional expression is constant
  25. #    pragma warning(disable : 4100)    // warning C4100: 'lpReserved' : unreferenced formal parameter
  26. #    pragma warning(disable : 4514)    // warning C4514: unreferenced inline function has been removed
  27. #    pragma warning(disable : 4115)    // warning C4115: '_RPC_ASYNC_STATE' : named type definition in parentheses
  28. #    pragma warning(disable : 4201)    // warning C4201: nonstandard extension used : nameless struct/union
  29. #    pragma warning(disable : 4214)    // warning C4214: nonstandard extension used : bit field types other than int
  30. #    pragma warning(disable : 4115)    // warning C4115: 'IRpcStubBuffer' : named type definition in parentheses
  31. #    pragma warning(disable : 4711)    // warning C4711: function selected for automatic inline expansion
  32.     /* We now try for at least Windows 2000 compatibility (0x0500).
  33.      * The code will still work on older systems, though.
  34.      * Prior versions used 0x0400 instead.
  35.      */
  36. #    ifndef WINVER
  37. #        define WINVER 0x0500
  38. #    endif
  39. #    ifndef _WIN32_WINNT
  40. #        define _WIN32_WINNT 0x0500
  41. #    endif
  42. #    ifndef _INC_WINDOWS
  43. #        include <windows.h>    /* includes <winsock2.h> if _WIN32_WINNT >= 0x400 */
  44. #    endif
  45. #    ifndef _INC_TYPES
  46. #        include <sys/types.h>
  47. #    endif
  48. #    ifndef _INC_STAT
  49. #        include <sys/stat.h>
  50. #    endif
  51. #    ifndef _INC_IO
  52. #        include <io.h>
  53. #    endif
  54. #    ifndef _INC_CONIO
  55. #        include <conio.h>
  56. #    endif
  57. #    ifndef _INC_DIRECT
  58. #        include <direct.h>
  59. #    endif
  60. #    ifndef _INC_STDIO
  61. #        include <stdio.h>
  62. #    endif
  63. #    ifndef _INC_STRING
  64. #        include <string.h>
  65. #    endif
  66. #    ifndef _INC_STDLIB
  67. #        include <stdlib.h>
  68. #    endif
  69. #    ifndef _INC_STDDEF
  70. #        include <stddef.h>
  71. #    endif
  72. #    ifndef _INC_STDARG
  73. #        include <stdarg.h>
  74. #    endif
  75. #    ifndef _INC_CTYPE
  76. #        include <ctype.h>
  77. #    endif
  78. #    ifndef _INC_TIME
  79. #        include <time.h>
  80. #    endif
  81. #    ifndef _INC_ERRNO
  82. #        include <errno.h>
  83. #    endif
  84. #    ifndef _INC_SIGNAL
  85. #        include <signal.h>
  86. #    endif
  87. #    ifndef _INC_SETJMP
  88. #        include <setjmp.h>
  89. #    endif
  90. #    define longest_int __int64
  91. #    define longest_uint __uint64
  92. #    ifndef HAVE_LONG_LONG
  93. #        define HAVE_LONG_LONG 1
  94. #    endif
  95. #    ifndef SCANF_LONG_LONG
  96. #        define SCANF_LONG_LONG "%I64d"
  97. #    endif
  98. #    ifndef PRINTF_LONG_LONG
  99. #        define PRINTF_LONG_LONG "%I64d"
  100. #    endif
  101. #    ifndef PRINTF_LONG_LONG_I64D
  102. #        define PRINTF_LONG_LONG_I64D 1
  103. #    endif
  104. #    ifndef SCANF_LONG_LONG_I64D
  105. #        define SCANF_LONG_LONG_I64D 1
  106. #    endif
  107. #    ifndef USE_SIO
  108. #        define USE_SIO 1
  109. #    endif
  110. #    ifndef NO_SIGNALS
  111. #        define NO_SIGNALS 1
  112. #    endif
  113. #    ifndef main_void_return_t
  114. #        define main_void_return_t void
  115. #    endif
  116. #    ifndef strcasecmp
  117. #        define strcasecmp _stricmp
  118. #        define strncasecmp _strnicmp
  119. #        define strdup _strdup
  120. #        define fdopen _fdopen
  121. #    endif
  122. #    ifndef mode_t
  123. #        define mode_t int
  124. #    endif
  125. #    ifndef S_ISREG
  126. #        define S_ISREG(m)      (((m) & _S_IFMT) == _S_IFREG)
  127. #        define S_ISDIR(m)      (((m) & _S_IFMT) == _S_IFDIR)
  128. #        define S_ISLNK(m)      (0)
  129. #    endif
  130. #    ifndef open
  131. #        define open _open
  132. #        define write _write
  133. #        define read _read
  134. #        define close _close
  135. #        define lseek _lseek
  136. #        define stat _stat
  137. #        define lstat _stat
  138. #        define fstat _fstat
  139. #        define dup _dup
  140. #        define utime _utime
  141. #        define utimbuf _utimbuf
  142. #    endif
  143. #    ifndef unlink
  144. #        define unlink remove
  145. #    endif
  146. #    ifndef HAVE_LONG_FILE_NAMES
  147. #        define HAVE_LONG_FILE_NAMES 1
  148. #    endif
  149. #    ifndef HAVE_MKTIME
  150. #        define HAVE_MKTIME 1
  151. #    endif
  152. #    ifndef HAVE_MEMMOVE
  153. #        define HAVE_MEMMOVE 1
  154. #    endif
  155. #    ifndef HAVE_STRSTR
  156. #        define HAVE_STRSTR 1
  157. #    endif
  158. #    ifndef HAVE_VSNPRINTF
  159. #        define HAVE_VSNPRINTF 1
  160. #    endif
  161. #    ifndef HAVE_SNPRINTF
  162. #        define HAVE_SNPRINTF 1
  163. #    endif
  164. #    ifndef vsnprintf
  165. #        define vsnprintf _vsnprintf
  166. #    endif
  167. #    ifndef snprintf
  168. #        define snprintf _snprintf
  169. #    endif
  170. #else
  171.     /* Includes for UNIX */
  172. #    include <unistd.h>
  173. #    include <sys/types.h>
  174. #    include <sys/stat.h>
  175. #    include <sys/time.h>
  176. #    include <sys/wait.h>
  177. #    include <stdio.h>
  178. #    include <string.h>
  179. #    ifdef HAVE_STRINGS_H
  180. #        include <strings.h>
  181. #    endif
  182. #    include <stdlib.h>
  183. #    include <stddef.h>
  184. #    include <stdarg.h>
  185. #    include <ctype.h>
  186. #    include <time.h>
  187. #    include <errno.h>
  188. #    include <signal.h>
  189. #    include <setjmp.h>
  190. #    if !defined(__ultrix) || !defined(XTI)
  191. #        include <sys/socket.h>
  192. #    endif
  193. #    include <netinet/in.h>
  194. #    include <fcntl.h>
  195. #    include <netdb.h>
  196. #    ifndef USE_SIO
  197. #        define USE_SIO 1
  198. #    endif
  199. #    ifndef NO_SIGNALS
  200. #        define NO_SIGNALS 1
  201. #    endif
  202. #endif
  203.  
  204. #include "ncftp_errno.h"
  205.  
  206. #ifndef longest_int
  207. #define longest_int long long
  208. #define longest_uint unsigned long long
  209. #endif
  210.  
  211. #ifndef forever
  212. #    define forever for ( ; ; )
  213. #endif
  214.  
  215. typedef void (*FTPSigProc)(int);
  216.  
  217. typedef struct FTPLine *FTPLinePtr;
  218. typedef struct FTPLine {
  219.     FTPLinePtr prev, next;
  220.     char *line;
  221. } FTPLine;
  222.  
  223. typedef struct FTPLineList {
  224.     FTPLinePtr first, last;
  225.     int nLines;
  226. } FTPLineList, *FTPLineListPtr;
  227.  
  228. typedef struct Response {
  229.     FTPLineList msg;
  230.     int codeType;
  231.     int code;
  232.     int printMode;
  233.     int eofOkay;
  234.     int hadEof;
  235. } Response, *ResponsePtr;
  236.  
  237. #if USE_SIO && !defined(_SReadlineInfo_)
  238. #define _SReadlineInfo_ 1
  239. typedef struct SReadlineInfo {
  240.     char *buf;        /* Pointer to beginning of buffer. */
  241.     char *bufPtr;        /* Pointer to current position in buffer. */
  242.     char *bufLim;        /* Pointer to end of buffer. */
  243.     size_t bufSize;        /* Current size of buffer block. */
  244.     size_t bufSizeMax;    /* Maximum size available for buffer. */
  245.     int malloc;        /* If non-zero, malloc() was used for buf. */
  246.     int fd;            /* File descriptor to use for I/O. */
  247.     int timeoutLen;        /* Timeout to use, in seconds. */
  248.     int requireEOLN;    /* When buffer is full, continue reading and discarding until \n? */
  249. } SReadlineInfo;
  250. #endif
  251.  
  252. typedef struct FTPLibraryInfo {
  253.     char magic[16];                /* Don't modify this field. */
  254.     int init;                /* Don't modify this field. */
  255.     int socksInit;                /* Don't modify this field. */
  256.     unsigned int defaultPort;        /* Don't modify this field. */
  257.     char defaultAnonPassword[80];        /* You may set this after init. */
  258. } FTPLibraryInfo, *FTPLIPtr;
  259.  
  260. typedef struct FTPConnectionInfo *FTPCIPtr;
  261. typedef void (*FTPProgressMeterProc)(const FTPCIPtr, int);
  262. typedef void (*FTPLogProc)(const FTPCIPtr, char *);
  263. typedef void (*FTPConnectMessageProc)(const FTPCIPtr, ResponsePtr);
  264. typedef void (*FTPLoginMessageProc)(const FTPCIPtr, ResponsePtr);
  265. typedef void (*FTPRedialStatusProc)(const FTPCIPtr, int, int);
  266. typedef void (*FTPPrintResponseProc)(const FTPCIPtr, ResponsePtr);
  267. typedef void (*FTPGetPassphraseProc)(const FTPCIPtr, FTPLineListPtr pwPrompt, char *pass, size_t dsize);
  268.  
  269. typedef struct FTPConnectionInfo {
  270.     char magic[16];                /* Don't modify this field. */
  271.     
  272.     char host[64];                /* REQUIRED input parameter. */
  273.     char user[64];                /* OPTIONAL input parameter. */
  274.     char pass[64];                /* OPTIONAL input parameter. */
  275.     char acct[64];                /* OPTIONAL input parameter. */
  276.     unsigned int passIsEmpty;        /* OPTIONAL input parameter. */
  277.     unsigned int port;            /* OPTIONAL input parameter. */
  278.  
  279.     int errNo;                /* You may modify this if you want. */
  280.     char lastFTPCmdResultStr[128];        /* You may modify this if you want. */
  281.     FTPLineList lastFTPCmdResultLL;        /* Use, but do not modify. */
  282.     int lastFTPCmdResultNum;        /* You may modify this if you want. */
  283.  
  284.     FILE *debugLog;                /* OPTIONAL input parameter. */
  285.     FTPLogProc debugLogProc;        /* OPTIONAL input parameter. */
  286.  
  287.     unsigned int xferTimeout;        /* OPTIONAL input parameter. */
  288.     unsigned int connTimeout;        /* OPTIONAL input parameter. */
  289.     unsigned int ctrlTimeout;        /* OPTIONAL input parameter. */
  290.     unsigned int abortTimeout;        /* OPTIONAL input parameter. */
  291.  
  292.     int maxDials;                /* OPTIONAL input parameter. */
  293.     int redialDelay;            /* OPTIONAL input parameter. */
  294.  
  295.     int dataPortMode;            /* OPTIONAL input parameter. */
  296.  
  297.     int firewallType;            /* OPTIONAL input parameter. */
  298.     char firewallHost[64];            /* OPTIONAL input parameter. */
  299.     char firewallUser[64];            /* OPTIONAL input parameter. */
  300.     char firewallPass[64];            /* OPTIONAL input parameter. */
  301.     unsigned int firewallPort;        /* OPTIONAL input parameter. */
  302.  
  303.     size_t ctrlSocketRBufSize;        /* OPTIONAL input parameter. */
  304.     size_t ctrlSocketSBufSize;        /* OPTIONAL input parameter. */
  305.     size_t dataSocketRBufSize;        /* OPTIONAL input parameter. */
  306.     size_t dataSocketSBufSize;        /* OPTIONAL input parameter. */
  307.  
  308.     const char *asciiFilenameExtensions;    /* OPTIONAL input parameter. */
  309.     int shutdownUnusedSideOfSockets;    /* OPTIONAL input parameter. */
  310.  
  311.     unsigned short ephemLo;            /* OPTIONAL input parameter. */
  312.     unsigned short ephemHi;            /* OPTIONAL input parameter. */
  313.  
  314.     FTPConnectMessageProc onConnectMsgProc; /* OPTIONAL input parameter. */
  315.     FTPRedialStatusProc redialStatusProc;    /* OPTIONAL input parameter. */
  316.     FTPPrintResponseProc printResponseProc; /* OPTIONAL input parameter. */
  317.     FTPLoginMessageProc onLoginMsgProc;    /* OPTIONAL input parameter. */
  318.  
  319.     FTPGetPassphraseProc passphraseProc;    /* OPTIONAL input parameter. */
  320.  
  321.     /* Used during transfers; valid during progress meter updates. */
  322.     FTPProgressMeterProc progress;        /* OPTIONAL input parameter. */
  323.     longest_int bytesTransferred;        /* Do not modify this field. */
  324.     int useProgressMeter;            /* Used internally. */
  325.     struct timeval t0;            /* Do not modify this field. */
  326.     double sec;                /* Do not modify this field. */
  327.     double secLeft;                /* Do not modify this field. */
  328.     double kBytesPerSec;            /* Do not modify this field. */
  329.     double percentCompleted;        /* Do not modify this field. */
  330.     longest_int expectedSize;        /* Do not modify this field. */
  331.     time_t mdtm;                /* Do not modify this field. */
  332.     time_t nextProgressUpdate;        /* Do not modify this field. */
  333.     const char *rname;            /* Do not modify this field. */
  334.     const char *lname;            /* Do not modify this field. */
  335.     int stalled;                /* Do not modify this field. */
  336.     int dataTimedOut;            /* Do not modify this field. */
  337.     int cancelXfer;                /* You may modify this. */
  338.     int canceling;                /* Use, but do not modify. */
  339.     int canceled;                /* Use, but do not modify. */
  340.  
  341.     char actualHost[64];            /* Do not modify this field. */
  342.     char ip[32];                /* Do not modify this field. */
  343.  
  344.     char *startingWorkingDirectory;        /* Use, but do not modify. */
  345.  
  346.     int connected;                /* Do not modify this field. */
  347.     int loggedIn;                /* Do not modify this field. */
  348.     int curTransferType;            /* Do not modify this field. */
  349.     longest_int startPoint;            /* Do not modify this field. */
  350.     FILE *errLog;                /* DEPRECATED input parameter. */
  351.     FTPLogProc errLogProc;            /* DEPRECATED input parameter. */
  352.     FTPLIPtr lip;                /* Do not modify this field. */
  353.  
  354.     int hasPASV;                /* Do not modify this field. */
  355.     int hasSIZE;                /* Do not modify this field. */
  356.     int hasMDTM;                /* Do not modify this field. */
  357.     int hasMDTM_set;            /* Do not modify this field. */
  358.     int hasREST;                /* Do not modify this field. */
  359.     int hasNLST_a;                /* Do not modify this field. */
  360.     int hasNLST_d;                /* Do not modify this field. */
  361.     int hasFEAT;                /* Do not modify this field. */
  362.     int hasMLSD;                /* Do not modify this field. */
  363.     int hasMLST;                /* Do not modify this field. */
  364.     int usedMLS;                /* Do not modify this field. */
  365.     int hasCLNT;                /* Do not modify this field. */
  366.     int hasHELP_SITE;            /* Do not modify this field. */
  367.     int hasSITE_UTIME;            /* Do not modify this field. */
  368.     int hasSITE_RETRBUFSIZE;        /* Do not modify this field. */
  369.     int hasSITE_RBUFSIZ;            /* Do not modify this field. */
  370.     int hasSITE_RBUFSZ;            /* Do not modify this field. */
  371.     int hasSITE_STORBUFSIZE;        /* Do not modify this field. */
  372.     int hasSITE_SBUFSIZ;            /* Do not modify this field. */
  373.     int hasSITE_SBUFSZ;            /* Do not modify this field. */
  374.     int hasSITE_BUFSIZE;            /* Do not modify this field. */
  375.     int mlsFeatures;            /* Do not modify this field. */
  376.     int STATfileParamWorks;            /* Do not modify this field. */
  377.     int NLSTfileParamWorks;            /* Do not modify this field. */
  378.  
  379.     struct sockaddr_in servCtlAddr;        /* Do not modify this field. */
  380.     struct sockaddr_in servDataAddr;    /* Do not modify this field. */
  381.     struct sockaddr_in ourCtlAddr;        /* Do not modify this field. */
  382.     struct sockaddr_in ourDataAddr;        /* Do not modify this field. */
  383.     int netMode;                /* Do not use or modify. */
  384.     char *buf;                /* Do not modify this field. */
  385.     size_t bufSize;                /* Do not modify this field. */
  386.     int doAllocBuf;                /* Do not modify this field. */
  387.     FILE *cin;                /* Do not use or modify. */
  388.     FILE *cout;                /* Do not use or modify. */
  389.     int ctrlSocketR;            /* You may use but not modify/close. */
  390.     int ctrlSocketW;            /* You may use but not modify/close. */
  391.     int dataSocket;                /* You may use but not modify/close. */
  392.     int dataSocketConnected;        /* Do not use or modify. */
  393.     int leavePass;                /* You may modify this. */
  394.     int eofOkay;                /* Do not use or modify. */
  395.     int require20;                /* You may modify this. */
  396.     int allowProxyForPORT;            /* You may modify this. */
  397.     int usingTAR;                /* Use, but do not modify. */
  398.     int serverType;                /* Do not use or modify. */
  399.     int ietfCompatLevel;            /* Do not use or modify. */
  400.  
  401.     int numDials;                /* Do not modify. */
  402.     int totalDials;                /* Do not modify. */
  403.     struct timeval initTime;        /* Do not modify. */
  404.     struct timeval startTime;        /* Do not modify. */
  405.     struct timeval connectTime;        /* Do not modify. */
  406.     struct timeval loginTime;        /* Do not modify. */
  407.     struct timeval disconnectTime;        /* Do not modify. */
  408.     struct timeval lastCmdStart;        /* Do not modify. */
  409.     struct timeval lastCmdFinish;        /* Do not modify. */
  410.     int numDownloads;            /* Do not modify. */
  411.     int numUploads;                /* Do not modify. */
  412.     int numListings;            /* Do not modify. */
  413.  
  414.     int doNotGetStartingWorkingDirectory;    /* You may modify this. */
  415.     char textEOLN[4];            /* Set automatically per platform. */
  416.     int asciiTranslationMode;        /* You may modify this. */
  417.     const char *manualOverrideFeatures;    /* You may modify this. */
  418.  
  419.     /* Only set the following field if all the following are true:
  420.      *   Your client FTP program is running on a private network (e.g. 192.168.1.0); and
  421.      *   You are accessing a server outside your network (e.g., on the Internet); and
  422.      *   Your network's firewall does NOT fix private addresses in PORT for you; and
  423.      *   You know what your external IP address is.
  424.      */
  425.     struct sockaddr_in clientKnownExternalAddr;    
  426.  
  427.     int maxNumberOfSuccessivePASVAttempts;    /* You may modify this. */
  428.  
  429. #if USE_SIO
  430.     char srlBuf[768];
  431.     SReadlineInfo ctrlSrl;            /* Do not use or modify. */
  432. #endif
  433.     int iUser;                /* Scratch integer field you can use. */
  434.     void *pUser;                /* Scratch pointer field you can use. */
  435.     longest_int llUser;            /* Scratch long long field you can use. */
  436.     int reserved[32];            /* Do not use or modify. */
  437. } FTPConnectionInfo;
  438.  
  439. typedef struct FTPFileInfo *FTPFileInfoPtr, **FTPFileInfoVec;
  440. typedef struct FTPFileInfo {
  441.     FTPFileInfoPtr prev, next;
  442.     char *relname;
  443.     char *rname;
  444.     char *rlinkto;
  445.     char *lname;
  446.     char *plug;    /* permissions, links, user, group */
  447.     int type;
  448.     time_t mdtm;
  449.     longest_int size;
  450.     size_t relnameLen;
  451.     int mode;    /* Only set by UnMlsD() */
  452. } FTPFileInfo;
  453.  
  454. typedef struct FTPFileInfoList {
  455.     FTPFileInfoPtr first, last;
  456.     FTPFileInfoVec vec;
  457.     size_t maxFileLen;
  458.     size_t maxPlugLen;
  459.     int nFileInfos;
  460.     int sortKey;
  461.     int sortOrder;
  462. } FTPFileInfoList, *FTPFileInfoListPtr;
  463.  
  464. /* Used with UnMlsT() */
  465. typedef struct MLstItem{
  466.     char fname[512];
  467.     char linkto[512];
  468.     int ftype;
  469.     longest_int fsize;
  470.     time_t ftime;
  471.     int mode;        /* "UNIX.mode" fact */
  472.     int uid;        /* "UNIX.uid" fact */
  473.     int gid;        /* "UNIX.gid" fact */
  474.     char perm[16];        /* "perm" fact */
  475.     char owner[16];        /* "UNIX.owner" fact */
  476.     char group[16];        /* "UNIX.group" fact */
  477. } MLstItem, *MLstItemPtr;
  478.  
  479. /* Messages we pass to the current progress meter function. */
  480. #define kPrInitMsg            1
  481. #define kPrUpdateMsg            2
  482. #define kPrEndMsg            3
  483.  
  484. /* Parameter for OpenDataConnection() */
  485. #define kSendPortMode            0
  486. #define kPassiveMode            1
  487. #define kFallBackToSendPortMode        2
  488.  
  489. /* Parameter for AcceptDataConnection() */
  490. #define kAcceptForWriting        00100
  491. #define kAcceptForReading        00101
  492. #define kNetWriting            kAcceptForWriting
  493. #define kNetReading            kAcceptForReading
  494.  
  495. /* Value for printMode field of Response structure.
  496.  * Generally, don't worry about this.
  497.  */
  498. #define kResponseNoPrint 00001
  499. #define kResponseNoSave  00002
  500. #define kResponseNoProc  00002
  501.  
  502. #define kDefaultFTPPort            21
  503.  
  504. #if ((defined(AIX) || (defined(_AIX))))
  505. #    define kDefaultFTPBufSize    4096
  506. #else
  507. #    define kDefaultFTPBufSize    32768
  508. #endif
  509.  
  510. #ifdef USE_SIO
  511. /* This version of the library can handle timeouts without
  512.  * a user-installed signal handler.
  513.  */
  514. #define kDefaultXferTimeout        600
  515. #define kDefaultConnTimeout        10
  516. #define kDefaultCtrlTimeout        135
  517. #define kDefaultAbortTimeout        10
  518. #else
  519. /* The library doesn't use timeouts by default because it would
  520.  * break apps that don't have a SIGALRM handler.
  521.  */
  522. #define kDefaultXferTimeout        (0)    /* No timeout. */
  523. #define kDefaultConnTimeout        (0)    /* No timeout. */
  524. #define kDefaultCtrlTimeout        (0)    /* No timeout. */
  525. #define kDefaultAbortTimeout        10
  526. #endif
  527.  
  528.  
  529. /* Suggested timeout values, in seconds, if you use timeouts. */
  530. #define kSuggestedDefaultXferTimeout    600
  531. #define kSuggestedDefaultConnTimeout    10
  532. #define kSuggestedDefaultCtrlTimeout    135    /* 2*MSL, + slop */ 
  533. #define kSuggestedAbortTimeout        10
  534.  
  535. #define kDefaultMaxDials        3
  536. #define kDefaultRedialDelay        20    /* seconds */
  537.  
  538. #define kDefaultDataPortMode        kFallBackToSendPortMode
  539.  
  540. #define kDefaultMaxNumberOfSuccessivePASVAttempts    3
  541.  
  542. #define kRedialStatusDialing        0
  543. #define kRedialStatusSleeping        1
  544.  
  545. #ifndef INADDR_NONE
  546. #    define INADDR_NONE        (0xffffffff)    /* <netinet/in.h> should have it. */
  547. #endif
  548. #ifndef INADDR_ANY
  549. #    define INADDR_ANY        (0x00000000)
  550. #endif
  551.  
  552. #define kTypeAscii            'A'
  553. #define kTypeBinary            'I'
  554. #define kTypeEbcdic            'E'
  555.  
  556. #define kGlobChars             "[*?"
  557. #define GLOBCHARSINSTR(a)        (strpbrk(a, kGlobChars) != NULL)
  558.  
  559. #define kGlobYes            1
  560. #define kGlobNo                0
  561. #define kRecursiveYes            1
  562. #define kRecursiveNo            0
  563. #define kAppendYes            1
  564. #define kAppendNo            0
  565. #define kResumeYes            1
  566. #define kResumeNo            0
  567. #define kDeleteYes            1
  568. #define kDeleteNo            0
  569. #define kTarYes                1
  570. #define kTarNo                0
  571.  
  572. #define FTP_UNIMPLEMENTED_CMD(a)    ((a == 500) || (a == 502) || (a == 504))
  573. #define FTP_SYNTAX_ERROR_IN_PARAMETERS(a)    (a == 501)    
  574.  
  575. /* Possible values returned by GetDateAndTime. */
  576. #define kSizeUnknown            ((longest_int) (-1))
  577. #define kModTimeUnknown            ((time_t) (-1))
  578.  
  579. #define kCommandAvailabilityUnknown    (-1)
  580. #define kCommandAvailable        1
  581. #define kCommandNotAvailable        0
  582.  
  583. /* Values returned by FTPDecodeURL. */
  584. #define kNotURL                (-1)
  585. #define kMalformedURL            (-2)
  586.  
  587. /* Values for the firewall/proxy open. */
  588. #define kFirewallNotInUse            0
  589. #define kFirewallUserAtSite            1
  590. #define kFirewallLoginThenUserAtSite        2
  591. #define kFirewallSiteSite            3
  592. #define kFirewallOpenSite            4
  593. #define kFirewallUserAtUserPassAtPass        5
  594. #define kFirewallFwuAtSiteFwpUserPass        6
  595. #define kFirewallUserAtSiteFwuPassFwp        7
  596. #define kFirewallUserAtSitePort            8
  597. #define kFirewallUserAtSitePort2        9
  598. #define kFirewallLastType            kFirewallUserAtSitePort2
  599.  
  600. /* For MLSD, MLST, and STAT. */
  601. #define kPreferredMlsOpts    (kMlsOptType | kMlsOptSize | kMlsOptModify | kMlsOptUNIXmode | kMlsOptUNIXowner | kMlsOptUNIXgroup | kMlsOptUNIXuid | kMlsOptUNIXgid | kMlsOptPerm)
  602.  
  603. #define kMlsOptType        00001
  604. #define kMlsOptSize        00002
  605. #define kMlsOptModify        00004
  606. #define kMlsOptUNIXmode        00010
  607. #define kMlsOptUNIXowner    00020
  608. #define kMlsOptUNIXgroup    00040
  609. #define kMlsOptPerm        00100
  610. #define kMlsOptUNIXuid        00200
  611. #define kMlsOptUNIXgid        00400
  612. #define kMlsOptUnique        01000
  613.  
  614. /* For FTPChdir3(). */
  615. #define kChdirOnly        00000
  616. #define kChdirAndMkdir        00001
  617. #define kChdirAndGetCWD        00002
  618. #define kChdirOneSubdirAtATime    00004
  619. #define kChdirFullPath        00010
  620.  
  621. /* Return codes for custom ConfirmResumeDownloadProcs. */
  622. #define kConfirmResumeProcNotUsed 0
  623. #define kConfirmResumeProcSaidSkip 1
  624. #define kConfirmResumeProcSaidResume 2
  625. #define kConfirmResumeProcSaidOverwrite 3
  626. #define kConfirmResumeProcSaidAppend 4
  627. #define kConfirmResumeProcSaidBestGuess 5
  628. #define kConfirmResumeProcSaidCancel 6
  629.  
  630. typedef int (*FTPConfirmResumeDownloadProc)(
  631.     const FTPCIPtr cip,
  632.     const char **localpath,
  633.     longest_int localsize,
  634.     time_t localmtime,
  635.     const char *remotepath,
  636.     longest_int remotesize,
  637.     time_t remotetime,
  638.     longest_int *startPoint
  639. );
  640.  
  641. typedef int (*FTPConfirmResumeUploadProc)(
  642.     const FTPCIPtr cip,
  643.     const char *localpath,
  644.     longest_int localsize,
  645.     time_t localmtime,
  646.     const char **remotepath,
  647.     longest_int remotesize,
  648.     time_t remotetime,
  649.     longest_int *startPoint
  650. );
  651.  
  652. #define kNoFTPConfirmResumeDownloadProc    ((FTPConfirmResumeDownloadProc) 0)
  653. #define kNoFTPConfirmResumeUploadProc    ((FTPConfirmResumeUploadProc) 0)
  654. #define kNoFTPGetPassphraseProc        ((FTPGetPassphraseProc) 0)
  655. #define kNoFTPLogProcProc        ((FTPLogProc) 0)
  656. #define kNoFTPConnectMessageProc    ((FTPConnectMessageProc) 0)
  657. #define kNoFTPLoginMessageProc        ((FTPLoginMessageProc) 0)
  658. #define kNoFTPRedialStatusProc        ((FTPRedialStatusProc) 0)
  659.  
  660. /* Types of FTP server software.
  661.  *
  662.  * We try to recognize a few of these, for information
  663.  * only, and occasional uses to determine some additional
  664.  * or broken functionality.
  665.  */
  666. #define kServerTypeUnknown        0
  667. #define kServerTypeWuFTPd        1
  668. #define kServerTypeNcFTPd        2
  669. #define kServerTypeProFTPD        3
  670. #define kServerTypeMicrosoftFTP        4
  671. #define kServerTypeWarFTPd        5
  672. #define kServerTypeServ_U        6
  673. #define kServerTypeWFTPD        7
  674. #define kServerTypeVFTPD        8
  675. #define kServerTypeFTP_Max        9
  676. #define kServerTypeRoxen        10
  677. #define kServerTypeNetWareFTP        11
  678. #define kServerTypeWS_FTP        12
  679. #define kServerTypeDguxFTP        13
  680. #define kServerTypeIBMFTPCS        14
  681. #define kServerTypePyramid        15
  682.  
  683. /* This specifies the algorithm to use (if any) for processing the
  684.  * text during ASCII transfers.
  685.  */
  686. #define kAsciiTranslationModeNone    (-1)
  687. #define kAsciiTranslationModeFixEOLNs    0
  688. #define kAsciiTranslationModeStripCRs    1
  689. #define kAsciiTranslationModeDefault    kAsciiTranslationModeFixEOLNs
  690.  
  691. #if (defined(WIN32) || defined(_WINDOWS)) && !defined(__CYGWIN__)
  692.     /* Windows has separate functions to close and ioctl sockets. */
  693. #else
  694.     /* UNIX uses close() and ioctl() for all types of descriptors */
  695. #    define closesocket close
  696. #    define ioctlsocket ioctl
  697. #endif
  698.  
  699. #ifndef STDIN_FILENO
  700. #    define STDIN_FILENO 0
  701. #    define STDOUT_FILENO 1
  702. #    define STDERR_FILENO 2
  703. #endif
  704.  
  705. #if (defined(WIN32) || defined(_WINDOWS)) && !defined(__CYGWIN__)
  706. #    define LOCAL_PATH_DELIM '\\'
  707. #    define LOCAL_PATH_DELIM_STR "\\"
  708. #    define LOCAL_PATH_ALTDELIM '/'
  709. #    define IsLocalPathDelim(c) ((c == LOCAL_PATH_DELIM) || (c == LOCAL_PATH_ALTDELIM))
  710. #    define UNC_PATH_PREFIX "\\\\"
  711. #    define IsUNCPrefixed(s) (IsLocalPathDelim(s[0]) && IsLocalPathDelim(s[1]))
  712. #elif defined(__CYGWIN__)
  713. #    define LOCAL_PATH_DELIM '/'
  714. #    define LOCAL_PATH_DELIM_STR "/"
  715. #    define LOCAL_PATH_ALTDELIM '\\'
  716. #    define IsLocalPathDelim(c) ((c == LOCAL_PATH_DELIM) || (c == LOCAL_PATH_ALTDELIM))
  717. #    define UNC_PATH_PREFIX "//"
  718. #    define IsUNCPrefixed(s) (IsLocalPathDelim(s[0]) && IsLocalPathDelim(s[1]))
  719. #else
  720. #    define LOCAL_PATH_DELIM '/'
  721. #    define LOCAL_PATH_DELIM_STR "/"
  722. #    define StrFindLocalPathDelim(a) strchr(a, LOCAL_PATH_DELIM)
  723. #    define StrRFindLocalPathDelim(a) strrchr(a, LOCAL_PATH_DELIM)
  724. #    define StrRemoveTrailingLocalPathDelim StrRemoveTrailingSlashes
  725. #    define IsLocalPathDelim(c) (c == LOCAL_PATH_DELIM)
  726. #    define TVFSPathToLocalPath(s)
  727. #    define LocalPathToTVFSPath(s)
  728. #endif
  729.  
  730. #if (defined(WIN32) || defined(_WINDOWS)) && !defined(__CYGWIN__)
  731. typedef struct dirent {
  732.     char d_name[MAX_PATH];
  733. } dirent;
  734.  
  735. typedef struct DIR {
  736.     HANDLE searchHandle;
  737.     char *dirpath;
  738.     WIN32_FIND_DATA ffd;
  739.     dirent dent;
  740. } DIR;
  741.  
  742. /* Identical in declaration to struct _stati64.
  743.  * Unfortunately, we don't get _stati64 unless we're on an IA-64
  744.  */
  745. struct WinStat64 {
  746.     _dev_t st_dev;
  747.     _ino_t st_ino;
  748.     unsigned short st_mode;
  749.     short st_nlink;
  750.     short st_uid;
  751.     short st_gid;
  752.     _dev_t st_rdev;
  753.     __int64 st_size;
  754.     time_t st_atime;
  755.     time_t st_mtime;
  756.     time_t st_ctime;
  757. };
  758.  
  759. int WinFStat64(const int h0, struct WinStat64 *const stp);
  760. int WinStat64(const char *const path, struct WinStat64 *const stp);
  761.  
  762. #    ifndef Stat
  763. #        define Stat WinStat64
  764. #        define Lstat WinStat64
  765. #        define Fstat WinFStat64
  766. #    endif
  767. #endif    /* WIN32 */
  768.  
  769. /* The following block may be changed by configure script */
  770. #ifndef Stat
  771. #define Stat stat64    /* set by configure at 2008-07-15 10:17:24 */
  772. #define Lstat lstat64    /* set by configure at 2008-07-15 10:17:24 */
  773. #define Fstat fstat64    /* set by configure at 2008-07-15 10:17:24 */
  774. #endif
  775.  
  776. #define kFtwNoAutoGrowButContinue (-1)
  777. #define kFtwNoAutoGrowAndFail 0
  778. #define kFtwAutoGrow 1
  779. #define kFtwMagic 0xF234567F
  780.  
  781. typedef struct FtwInfo *FtwInfoPtr;
  782.  
  783. typedef int (*FtwProc)(const FtwInfoPtr ftwip);
  784.  
  785. typedef struct FtwInfo {
  786.     unsigned int init;
  787.     FtwProc proc;
  788.     char *curPath;
  789.     size_t curPathLen;
  790.     size_t curPathAllocSize;
  791.     size_t startPathLen;
  792.     char *curFile;
  793.     size_t curFileLen;
  794.     int curType;
  795.     struct Stat curStat;
  796.     int noAutoMallocAndFree;
  797.     int dirSeparator;
  798.     char rootDir[4];
  799.     int autoGrow;
  800.     size_t depth;
  801.     size_t maxDepth;
  802.     size_t numDirs;
  803.     size_t numFiles;
  804.     size_t numLinks;
  805.     const char *rlinkto;    /* only valid during FTPFtw() */
  806.     size_t direntbufSize;
  807.     void *direntbuf;
  808.     void *cip;        /* only valid during FTPFtw() */
  809.     void *userdata;
  810. } FtwInfo;
  811.  
  812. typedef struct GetoptInfo {
  813.     unsigned int init;    /* When properly initialized, set to 0xF123456F */
  814.     int err;    /* if error message should be printed */
  815.     int ind;    /* index into parent argv vector */
  816.     int opt;    /* character checked for validity */
  817.     char *arg;    /* argument associated with option */
  818.     char *place;    /* saved position in an arg */
  819. } GetoptInfo, *GetoptInfoPtr;
  820.  
  821. #if (defined(__APPLE_CC__)) || (defined(MACOSX))
  822. #else
  823.     /* These definitions are here to preserve backwards-compatibility
  824.      * with code which was designed using an earlier version of the
  825.      * library.
  826.      */
  827. #    define Line FTPLine
  828. #    define LinePtr FTPLinePtr
  829. #    define LineList FTPLineList
  830. #    define LineListPtr FTPLineListPtr
  831. #    define FileInfo FTPFileInfo
  832. #    define FileInfoPtr FTPFileInfoPtr
  833. #    define FileInfoList FTPFileInfoList
  834. #    define FileInfoListPtr FTPFileInfoListPtr
  835. #    define FileInfoListVec FTPFileInfoListVec
  836. #endif
  837.  
  838. extern const char gLibNcFTPVersion[];
  839. extern int gLibNcFTP_Uses_Me_To_Quiet_Variable_Unused_Warnings;
  840.  
  841. #if (defined(__APPLE_CC__)) && (__APPLE_CC__ < 10000)
  842. #    define LIBNCFTP_USE_VAR(a) gLibNcFTP_Uses_Me_To_Quiet_Variable_Unused_Warnings = (a == 0)
  843. #    ifndef UNUSED
  844. #        define UNUSED(a) a
  845. #    endif
  846. #elif (defined(__GNUC__)) && (__GNUC__ >= 3) && (! defined(__cplusplus))
  847. #    ifndef UNUSED
  848. #        define UNUSED(a) a __attribute__ ((__unused__))
  849. #    endif
  850. #    define LIBNCFTP_USE_VAR(a)
  851. #elif (defined(__GNUC__)) && (__GNUC__ == 2) && (! defined(__cplusplus))
  852. #    ifndef UNUSED
  853. #        define UNUSED(a) a __attribute__ ((unused))
  854. #    endif
  855. #    define LIBNCFTP_USE_VAR(a)
  856. #else
  857. #    define LIBNCFTP_USE_VAR(a) gLibNcFTP_Uses_Me_To_Quiet_Variable_Unused_Warnings = (a == 0)
  858. #    ifndef UNUSED
  859. #        define UNUSED(a) a
  860. #    endif
  861. #endif
  862.  
  863. /* Public routines */
  864. void FTPAbortDataTransfer(const FTPCIPtr cip);
  865. int FTPChdir(const FTPCIPtr cip, const char *const cdCwd);
  866. int FTPChdirAndGetCWD(const FTPCIPtr cip, const char *const cdCwd, char *const newCwd, const size_t newCwdSize);
  867. int FTPChdir3(FTPCIPtr cip, const char *const cdCwd, char *const newCwd, const size_t newCwdSize, int flags);
  868. int FTPChdirList(FTPCIPtr cip, FTPLineListPtr const cdlist, char *const newCwd, const size_t newCwdSize, int flags);
  869. int FTPChmod(const FTPCIPtr cip, const char *const pattern, const char *const mode, const int doGlob);
  870. int FTPCloseHost(const FTPCIPtr cip);
  871. int FTPCmd(const FTPCIPtr cip, const char *const cmdspec, ...)
  872. #if (defined(__GNUC__)) && (__GNUC__ >= 2)
  873. __attribute__ ((format (printf, 2, 3)))
  874. #endif
  875. ;
  876. int FTPDecodeHostName(const FTPCIPtr cip, const char *const hstr0);
  877. int FTPDecodeURL(const FTPCIPtr cip, char *const url, FTPLineListPtr cdlist, char *const fn, const size_t fnsize, int *const xtype, int *const wantnlst);
  878. int FTPDelete(const FTPCIPtr cip, const char *const pattern, const int recurse, const int doGlob);
  879. int FTPFileExists(const FTPCIPtr cip, const char *const file);
  880. int FTPFileModificationTime(const FTPCIPtr cip, const char *const file, time_t *const mdtm);
  881. int FTPFileSize(const FTPCIPtr cip, const char *const file, longest_int *const size, const int type);
  882. longest_int FTPLocalASCIIFileSize(const char *const fn, char *buf, const size_t bufsize);
  883. int FTPFileSizeAndModificationTime(const FTPCIPtr cip, const char *const file, longest_int *const size, const int type, time_t *const mdtm);
  884. int FTPFileType(const FTPCIPtr cip, const char *const file, int *const ftype);
  885. int FTPFtw(const FTPCIPtr cip, const FtwInfoPtr ftwip, const char *const path, FtwProc proc);
  886. int FTPGetCWD(const FTPCIPtr cip, char *const newCwd, const size_t newCwdSize);
  887. int FTPGetFileToMemory(const FTPCIPtr cip, const char *const file, char *memBuf, const size_t maxNumberOfBytesToWriteToMemBuf, size_t *const numberOfBytesWrittenToMemBuf, const longest_int startPoint, const int deleteflag);
  888. int FTPGetFiles3(const FTPCIPtr cip, const char *pattern1, const char *const dstdir1, const int recurse, int doGlob, const int xtype, const int resumeflag, int appendflag, const int deleteflag, const int tarflag, const FTPConfirmResumeDownloadProc resumeProc, int UNUSED(reserved));
  889. int FTPGetOneFile3(const FTPCIPtr cip, const char *const file, const char *const dstfile, const int xtype, const int fdtouse, const int resumeflag, const int appendflag, const int deleteflag, const FTPConfirmResumeDownloadProc resumeProc, int UNUSED(reserved));
  890. int FTPInitConnectionInfo(const FTPLIPtr lip, const FTPCIPtr cip, size_t bufsize);
  891. int FTPInitLibrary(const FTPLIPtr lip);
  892. int FTPIsDir(const FTPCIPtr cip, const char *const dir);
  893. int FTPIsRegularFile(const FTPCIPtr cip, const char *const file);
  894. int FTPList(const FTPCIPtr cip, const int outfd, const int longMode, const char *const lsflag);
  895. int FTPListToMemory(const FTPCIPtr cip, const char *const pattern, const FTPLineListPtr llines, const char *const lsflags);
  896. int FTPListToMemory2(const FTPCIPtr cip, const char *const pattern, const FTPLineListPtr llines, const char *const lsflags, const int blanklines, int *const tryMLSD);
  897. int FTPLocalGlob(FTPCIPtr cip, FTPLineListPtr fileList, const char *pattern, int doGlob);
  898. int FTPLoginHost(const FTPCIPtr cip);
  899. int FTPMkdir(const FTPCIPtr cip, const char *const newDir, const int recurse);
  900. int FTPMkdir2(const FTPCIPtr cip, const char *const newDir, const int recurse, const char *const curDir);
  901. int FTPMkParentDir(const FTPCIPtr cip, const char *const path, const int recurse, const char *const curDir);
  902. int FTPOpenHost(const FTPCIPtr cip);
  903. int FTPOpenHostNoLogin(const FTPCIPtr cip);
  904. void FTPPerror(const FTPCIPtr cip, const int err, const int eerr, const char *const s1, const char *const s2);
  905. int FTPPutFileFromMemory(const FTPCIPtr cip, const char *volatile dstfile, const char *volatile src, const size_t srcLen, const int appendflag);
  906. int FTPPutFiles3(const FTPCIPtr cip, const char *const pattern, const char *const dstdir1, const int recurse, const int doGlob, const int xtype, int appendflag, const char *const tmppfx, const char *const tmpsfx, const int resumeflag, const int deleteflag, const FTPConfirmResumeUploadProc resumeProc, int UNUSED(reserved));
  907. int FTPPutOneFile3(const FTPCIPtr cip, const char *const file, const char *const dstfile, const int xtype, const int fdtouse, const int appendflag, const char *const tmppfx, const char *const tmpsfx, const int resumeflag, const int deleteflag, const FTPConfirmResumeUploadProc resumeProc, int UNUSED(reserved));
  908. int FTPReadLoginConfigFile(FTPCIPtr cip, const char *const fn);
  909. int FTPRemoteGlob(FTPCIPtr cip, FTPLineListPtr fileList, const char *pattern, int doGlob);
  910. int FTPRename(const FTPCIPtr cip, const char *const oldname, const char *const newname);
  911. int FTPRmdir(const FTPCIPtr cip, const char *const pattern, const int recurse, const int doGlob);
  912. void FTPShutdownHost(const FTPCIPtr cip);
  913. const char *FTPStrError(int e);
  914. char *FTPStrError2(const FTPCIPtr cip, int e, char *const dst, const size_t dstsize, int eerr);
  915. int FTPSymlink(const FTPCIPtr cip, const char *const lfrom, const char *const lto);
  916. int FTPUmask(const FTPCIPtr cip, const char *const umsk);
  917. int FTPUtime(const FTPCIPtr cip, const char *const file, time_t actime, time_t modtime, time_t crtime);
  918.  
  919. /* FTPLineList routines */
  920. int CopyLineList(FTPLineListPtr, FTPLineListPtr);
  921. void DisposeLineListContents(FTPLineListPtr);
  922. void InitLineList(FTPLineListPtr);
  923. FTPLinePtr RemoveLine(FTPLineListPtr, FTPLinePtr);
  924. FTPLinePtr AddLine(FTPLineListPtr, const char *);
  925.  
  926. /* Ftw routines */
  927. void FtwInit(FtwInfo *const ftwip);
  928. void FtwDispose(FtwInfo *const ftwip);
  929. int Ftw(FtwInfo *const ftwip, const char *const path, FtwProc proc);
  930. void FtwSetBuf(FtwInfo *const ftwip, char *const buf, const size_t bufsize, int autogrow);
  931. #if (defined(WIN32) || defined(_WINDOWS)) && !defined(__CYGWIN__)
  932. DIR *opendir(const char *const path);
  933. struct dirent *readdir(DIR *dir);
  934. void closedir(DIR *dir);
  935. #endif    /* WIN32 */
  936.  
  937. /* Getopt routines */
  938. void GetoptReset(GetoptInfo *const opt);
  939. int Getopt(GetoptInfo *const opt, int nargc, char **const nargv, const char *const ostr);
  940.  
  941. /* Other routines that might be useful. */
  942. void InitWinsock(void);
  943. void DisposeWinsock(void);
  944. char *StrDup(const char *);
  945. char *FGets(char *, size_t, FILE *);
  946. void GetHomeDir(char *const dst, const size_t size);
  947. void GetTmpDir(char *const dst, const size_t size);
  948. void GetUsrName(char *, size_t);
  949. void Scramble(unsigned char *dst, size_t dsize, unsigned char *src, char *key);
  950. double FTPDuration(struct timeval *t0);
  951. struct tm *Gmtime(time_t t, struct tm *const tp);
  952. struct tm *Localtime(time_t t, struct tm *const tp);
  953. time_t GetUTCOffset(const int mon, const int mday);
  954. time_t GetUTCOffset2(const int year, const int mon, const int mday, const int hour, const int min);
  955. time_t UnMDTMDate(char *);
  956. int MkDirs(const char *const, int mode1);
  957. char *GetPass(const char *const prompt, char *const pwbuf, const size_t pwbufsize);
  958. int FilenameExtensionIndicatesASCII(const char *const pathName, const char *const extnList);
  959. void StrRemoveTrailingSlashes(char *dst);
  960. int StrToBoolOrInt(const char *s);
  961. int FTPFixPrivateAddr(struct sockaddr_in *maybePrivateAddr, struct sockaddr_in *knownNonPrivateAddrToUseIfNeeded);
  962. #if defined(WIN32) || defined(_WINDOWS) || defined(__CYGWIN__)
  963. char *StrFindLocalPathDelim(const char *src);
  964. char *StrRFindLocalPathDelim(const char *src);
  965. void StrRemoveTrailingLocalPathDelim(char *dst);
  966. void TVFSPathToLocalPath(char *dst);
  967. void LocalPathToTVFSPath(char *dst);
  968. #endif
  969. #if (defined(WIN32) || defined(_WINDOWS)) && !defined(__CYGWIN__)
  970. int gettimeofday(struct timeval *const tp, void *junk);
  971. void WinSleep(unsigned int seconds);
  972. #endif
  973.  
  974. #ifdef HAVE_SIGACTION
  975. void (*NcSignal(int signum, void (*handler)(int)))(int);
  976. #elif !defined(NcSignal)
  977. #    define NcSignal signal
  978. #endif
  979.  
  980. /* Obselete routines. */
  981. int FTPGetOneFile(const FTPCIPtr cip, const char *const file, const char *const dstfile);
  982. int FTPGetOneFile2(const FTPCIPtr cip, const char *const file, const char *const dstfile, const int xtype, const int fdtouse, const int resumeflag, const int appendflag);
  983. int FTPGetFiles(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob);
  984. int FTPGetFiles2(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob, const int xtype, const int resumeflag, const int appendflag);
  985. int FTPGetOneFileAscii(const FTPCIPtr cip, const char *const file, const char *const dstfile);
  986. int FTPGetFilesAscii(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob);
  987. int FTPPutOneFile(const FTPCIPtr cip, const char *const file, const char *const dstfile);
  988. int FTPPutOneFile2(const FTPCIPtr cip, const char *const file, const char *const dstfile, const int xtype, const int fdtouse, const int appendflag, const char *const tmppfx, const char *const tmpsfx);
  989. int FTPPutFiles(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob);
  990. int FTPPutFiles2(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob, const int xtype, const int appendflag, const char *const tmppfx, const char *const tmpsfx);
  991. int FTPPutOneFileAscii(const FTPCIPtr cip, const char *const file, const char *const dstfile);
  992. int FTPPutFilesAscii(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob);
  993.  
  994. /* Everything else below are private routines, or stuff for testing */
  995. int FTPInitConnectionInfo2(const FTPLIPtr lip, const FTPCIPtr cip, char *const buf, size_t bufSize);
  996. int FTPSendPort(const FTPCIPtr cip, struct sockaddr_in *saddr);
  997. int FTPSendPassive(const FTPCIPtr cip, struct sockaddr_in *saddr, int *weird);
  998. int FTPSetStartOffset(const FTPCIPtr cip, longest_int restartPt);
  999. void FTPCloseControlConnection(const FTPCIPtr cip);
  1000. int FTPSendCommandStr(const FTPCIPtr cip, char *const command, const size_t siz);
  1001. int FTPSendCommand(const FTPCIPtr cip, const char *const cmdspec, va_list ap)
  1002. #if (defined(__GNUC__)) && (__GNUC__ >= 2)
  1003. __attribute__ ((format (printf, 2, 0)))
  1004. #endif
  1005. ;
  1006. char *FTPGetLocalCWD(char *buf, size_t size);
  1007. int FTPQueryFeatures(const FTPCIPtr);
  1008. void FTPManualOverrideFeatures(const FTPCIPtr cip);
  1009. int FTPMListOneFile(const FTPCIPtr cip, const char *const file, const MLstItemPtr mlip);
  1010. void FTPInitializeAnonPassword(const FTPLIPtr);
  1011. void FTPInitIOTimer(const FTPCIPtr);
  1012. int FTPStartDataCmd(const FTPCIPtr, const int, const int, const longest_int, const char *const ,...)
  1013. #if (defined(__GNUC__)) && (__GNUC__ >= 2)
  1014. __attribute__ ((format (printf, 5, 6)))
  1015. #endif
  1016. ;
  1017. int FTPStartDataCmd2(const FTPCIPtr cip, const int netMode, const int type, const longest_int startPoint, char *const cmdstr, const size_t cmdstrSize, const char *variableCommandSpec, ...)
  1018. #if (defined(__GNUC__)) && (__GNUC__ >= 2)
  1019. __attribute__ ((format (printf, 7, 8)))
  1020. #endif
  1021. ;
  1022. int FTPStartDataCmd3(const FTPCIPtr cip, const int netMode, const int type, const longest_int startPoint, char *const cmdstr, const size_t cmdstrSize, const char *const variableCommandSpec, va_list ap)
  1023. #if (defined(__GNUC__)) && (__GNUC__ >= 2)
  1024. __attribute__ ((format (printf, 7, 0)))
  1025. #endif
  1026. ;
  1027. void FTPStartIOTimer(const FTPCIPtr);
  1028. void FTPStopIOTimer(const FTPCIPtr);
  1029. void FTPUpdateIOTimer(const FTPCIPtr);
  1030. int FTPSetTransferType(const FTPCIPtr, int);
  1031. int FTPEndDataCmd(const FTPCIPtr, int);
  1032. int FTPRemoteHelp(const FTPCIPtr, const char *const, const FTPLineListPtr);
  1033. int FTPCmdNoResponse(const FTPCIPtr, const char *const cmdspec,...)
  1034. #if (defined(__GNUC__)) && (__GNUC__ >= 2)
  1035. __attribute__ ((format (printf, 2, 3)))
  1036. #endif
  1037. ;
  1038. void FTPInitialLogEntry(const FTPCIPtr cip);
  1039. int WaitResponse(const FTPCIPtr, unsigned int);
  1040.  
  1041. /* We suggest using the Ftw() routines rather than these two. */
  1042. int FTPLocalRecursiveFileList(FTPCIPtr, FTPLineListPtr, FTPFileInfoListPtr);
  1043. int FTPLocalRecursiveFileList2(FTPCIPtr cip, FTPLineListPtr fileList, FTPFileInfoListPtr files, int erelative);
  1044.  
  1045. /* FTPFtw() is recommended since it is more reliable (read: thorough),
  1046.  * but these two work faster.
  1047.  */
  1048. int FTPRemoteRecursiveFileList(FTPCIPtr, FTPLineListPtr, FTPFileInfoListPtr);
  1049. int FTPRemoteRecursiveFileList1(FTPCIPtr, char *const, FTPFileInfoListPtr);
  1050.  
  1051. int FTPRebuildConnectionInfo(const FTPLIPtr lip, const FTPCIPtr cip);
  1052.  
  1053. /* FTPFileExists() calls these as needed. */
  1054. int FTPFileExistsStat(const FTPCIPtr cip, const char *const file);
  1055. int FTPFileExistsNlst(const FTPCIPtr cip, const char *const file);
  1056. int FTPFileExists2(const FTPCIPtr cip, const char *const file, const int tryMDTM, const int trySIZE, const int tryMLST, const int trySTAT, const int tryNLST);
  1057.  
  1058. void FTPGetDateStr(time_t t, const char *fmt, char *const ltstr1, const size_t ltstr1size, char *const gtstr1, const size_t gtstr1size);
  1059. int BufferGets(char *, size_t, int, char *, char **, char **, size_t);
  1060. void DisposeFileInfoListContents(FTPFileInfoListPtr);
  1061. void InitFileInfoList(FTPFileInfoListPtr);
  1062. void InitFileInfo(FTPFileInfoPtr);
  1063. FTPFileInfoPtr RemoveFileInfo(FTPFileInfoListPtr, FTPFileInfoPtr);
  1064. FTPFileInfoPtr AddFileInfo(FTPFileInfoListPtr, FTPFileInfoPtr);
  1065. void SortFileInfoList(FTPFileInfoListPtr, int, int);
  1066. void VectorizeFileInfoList(FTPFileInfoListPtr);
  1067. void UnvectorizeFileInfoList(FTPFileInfoListPtr);
  1068. int IsValidUNCPath(const char *const src);
  1069. void CompressPath(char *const dst, const char *const src, const size_t dsize, int dosCompat);
  1070. void PathCat(char *const dst, const size_t dsize, const char *const cwd, const char *const src, int dosCompat);
  1071. int DPathCat(char **const dst0, const char *const cwd, const char *const src, int dosCompat);
  1072. int ComputeRNames(FTPFileInfoListPtr, const char *, int, int);
  1073. int ComputeLNames(FTPFileInfoListPtr, const char *, const char *, int);
  1074. int ConcatFileInfoList(FTPFileInfoListPtr, FTPFileInfoListPtr);
  1075. int ConcatFileToFileInfoList(FTPFileInfoListPtr, char *);
  1076. int LineListToFileInfoList(FTPLineListPtr, FTPFileInfoListPtr);
  1077. int LineToFileInfoList(FTPLinePtr, FTPFileInfoListPtr);
  1078. void URLCopyToken(char *, size_t, const char *, size_t);
  1079. int UnMlsT(const FTPCIPtr, const char *const, const MLstItemPtr);
  1080. int UnMlsD(const FTPCIPtr, FTPFileInfoListPtr, FTPLineListPtr);
  1081. int UnLslR(const FTPCIPtr, FTPFileInfoListPtr, FTPLineListPtr, int);
  1082. void TraceResponse(const FTPCIPtr, ResponsePtr);
  1083. void PrintResponse(const FTPCIPtr, FTPLineListPtr);
  1084. void DoneWithResponse(const FTPCIPtr, ResponsePtr);
  1085. ResponsePtr InitResponse(void);
  1086. void ReInitResponse(const FTPCIPtr, ResponsePtr);
  1087. int GetTelnetString(const FTPCIPtr, char *, size_t, FILE *, FILE *);
  1088. int GetResponse(const FTPCIPtr, ResponsePtr);
  1089. int RCmd(const FTPCIPtr, ResponsePtr, const char *, ...)
  1090. #if (defined(__GNUC__)) && (__GNUC__ >= 2)
  1091. __attribute__ ((format (printf, 3, 4)))
  1092. #endif
  1093. ;
  1094. void PrintF(const FTPCIPtr cip, const char *const fmt, ...)
  1095. #if (defined(__GNUC__)) && (__GNUC__ >= 2)
  1096. __attribute__ ((format (printf, 2, 3)))
  1097. #endif
  1098. ;
  1099. void FTPLogError(const FTPCIPtr cip, const int pError, const char *const fmt, ...)
  1100. #if (defined(__GNUC__)) && (__GNUC__ >= 2)
  1101. __attribute__ ((format (printf, 3, 4)))
  1102. #endif
  1103. ;
  1104.  
  1105. #ifdef __cplusplus
  1106. }
  1107. #endif    /* __cplusplus */
  1108.  
  1109. #endif /* _ncftp_h_ */
  1110.