1 /* ncftp.h
2  *
3  * Copyright (c) 1996-2001 Mike Gleason, NCEMRSoft.
4  * All rights reserved.
5  *
6  */
7 
8 #ifndef _ncftp_h_
9 #define _ncftp_h_ 1
10 
11 #define kLibraryVersion "@(#) LibNcFTP 3.0.6 (April 14, 2001)"
12 
13 #if defined(WIN32) || defined(_WINDOWS)
14 #	define longest_int LONGLONG
15 #	define longest_uint ULONGLONG
16 #	ifndef HAVE_LONG_LONG
17 #		define HAVE_LONG_LONG 1
18 #	endif
19 #	ifndef SCANF_LONG_LONG
20 #		define SCANF_LONG_LONG "%I64d"
21 #	endif
22 #	ifndef PRINTF_LONG_LONG
23 #		define PRINTF_LONG_LONG "%I64d"
24 #	endif
25 #	ifndef PRINTF_LONG_LONG_I64D
26 #		define PRINTF_LONG_LONG_I64D 1
27 #	endif
28 #	ifndef SCANF_LONG_LONG_I64D
29 #		define SCANF_LONG_LONG_I64D 1
30 #	endif
31 #	ifndef USE_SIO
32 #		define USE_SIO 1
33 #	endif
34 #	ifndef NO_SIGNALS
35 #		define NO_SIGNALS 1
36 #	endif
37 #else
38 #	include <stdio.h>
39 #	include <sys/time.h>
40 #	if !defined(__ultrix) || !defined(XTI)
41 #		include <sys/socket.h>
42 #	endif
43 #	include <netinet/in.h>
44 #	if 1 /* %config1% -- set by configure script -- do not modify */
45 #		ifndef USE_SIO
46 #			define USE_SIO 1
47 #		endif
48 #		ifndef NO_SIGNALS
49 #			define NO_SIGNALS 1
50 #		endif
51 #	else
52 #		ifndef USE_SIO
53 #			define USE_SIO 0
54 #		endif
55 		/* #undef NO_SIGNALS */
56 #	endif
57 #endif
58 
59 #include "ncftp_errno.h"
60 
61 /* This is used to verify validty of the data passed in.
62  * It also specifies the minimum version that is binary-compatibile with
63  * this version.  (So this may not necessarily be kLibraryVersion.)
64  */
65 #define kLibraryMagic "LibNcFTP 3.0.6"
66 
67 #ifndef longest_int
68 #define longest_int long long
69 #define longest_uint unsigned long long
70 #endif
71 
72 #ifndef forever
73 #	define forever for ( ; ; )
74 #endif
75 
76 typedef void (*FTPSigProc)(int);
77 
78 typedef struct Line *LinePtr;
79 typedef struct Line {
80 	LinePtr prev, next;
81 	char *line;
82 } Line;
83 
84 typedef struct LineList {
85 	LinePtr first, last;
86 	int nLines;
87 } LineList, *LineListPtr;
88 
89 typedef struct Response {
90 	LineList msg;
91 	int codeType;
92 	int code;
93 	int printMode;
94 	int eofOkay;
95 	int hadEof;
96 } Response, *ResponsePtr;
97 
98 #if USE_SIO && !defined(_SReadlineInfo_)
99 #define _SReadlineInfo_ 1
100 typedef struct SReadlineInfo {
101 	char *buf;		/* Pointer to beginning of buffer. */
102 	char *bufPtr;		/* Pointer to current position in buffer. */
103 	char *bufLim;		/* Pointer to end of buffer. */
104 	size_t bufSize;		/* Current size of buffer block. */
105 	size_t bufSizeMax;	/* Maximum size available for buffer. */
106 	int malloc;		/* If non-zero, malloc() was used for buf. */
107 	int fd;			/* File descriptor to use for I/O. */
108 	int timeoutLen;		/* Timeout to use, in seconds. */
109 	int requireEOLN;	/* When buffer is full, continue reading and discarding until \n? */
110 } SReadlineInfo;
111 #endif
112 
113 typedef struct FTPLibraryInfo {
114 	char magic[16];				/* Don't modify this field. */
115 	int init;				/* Don't modify this field. */
116 	int socksInit;				/* Don't modify this field. */
117 	unsigned int defaultPort;		/* Don't modify this field. */
118 	char ourHostName[64];			/* Don't modify this field. */
119 	int hresult;				/* Don't modify this field. */
120 	int htried;				/* Don't modify this field. */
121 	char defaultAnonPassword[80];		/* You may set this after init. */
122 } FTPLibraryInfo, *FTPLIPtr;
123 
124 typedef struct FTPConnectionInfo *FTPCIPtr;
125 typedef void (*FTPProgressMeterProc)(const FTPCIPtr, int);
126 typedef void (*FTPLogProc)(const FTPCIPtr, char *);
127 typedef void (*FTPConnectMessageProc)(const FTPCIPtr, ResponsePtr);
128 typedef void (*FTPLoginMessageProc)(const FTPCIPtr, ResponsePtr);
129 typedef void (*FTPRedialStatusProc)(const FTPCIPtr, int, int);
130 typedef void (*FTPPrintResponseProc)(const FTPCIPtr, ResponsePtr);
131 typedef int (*FTPFtwProc)(const FTPCIPtr cip, const char *fn, int flag);
132 typedef void (*FTPGetPassphraseProc)(const FTPCIPtr, LineListPtr pwPrompt, char *pass, size_t dsize);
133 
134 typedef struct FTPConnectionInfo {
135 	char magic[16];				/* Don't modify this field. */
136 	char host[64];				/* REQUIRED input parameter. */
137 	char user[64];				/* OPTIONAL input parameter. */
138 	char pass[64];				/* OPTIONAL input parameter. */
139 	char acct[64];				/* OPTIONAL input parameter. */
140 	unsigned int port;			/* OPTIONAL input parameter. */
141 	unsigned int xferTimeout;		/* OPTIONAL input parameter. */
142 	unsigned int connTimeout;		/* OPTIONAL input parameter. */
143 	unsigned int ctrlTimeout;		/* OPTIONAL input parameter. */
144 	unsigned int abortTimeout;		/* OPTIONAL input parameter. */
145 	FILE *debugLog;				/* OPTIONAL input parameter. */
146 	FILE *errLog;				/* OPTIONAL input parameter. */
147 	FTPLogProc debugLogProc;		/* OPTIONAL input parameter. */
148 	FTPLogProc errLogProc;			/* OPTIONAL input parameter. */
149 	FTPLIPtr lip;				/* Do not modify this field. */
150 	int maxDials;				/* OPTIONAL input parameter. */
151 	int redialDelay;			/* OPTIONAL input parameter. */
152 	int dataPortMode;			/* OPTIONAL input parameter. */
153 	char actualHost[64];			/* Do not modify this field. */
154 	char ip[32];				/* Do not modify this field. */
155 	int connected;				/* Do not modify this field. */
156 	int loggedIn;				/* Do not modify this field. */
157 	int curTransferType;			/* Do not modify this field. */
158 	char *startingWorkingDirectory;		/* Use, but do not modify. */
159 	longest_int startPoint;			/* Do not modify this field. */
160 	int hasPASV;				/* Do not modify this field. */
161 	int hasSIZE;				/* Do not modify this field. */
162 	int hasMDTM;				/* Do not modify this field. */
163 	int hasREST;				/* Do not modify this field. */
164 	int hasNLST_d;				/* Do not modify this field. */
165 	int hasUTIME;				/* Do not modify this field. */
166 	int hasFEAT;				/* Do not modify this field. */
167 	int hasMLSD;				/* Do not modify this field. */
168 	int hasMLST;				/* Do not modify this field. */
169 	int usedMLS;				/* Do not modify this field. */
170 	int hasCLNT;				/* Do not modify this field. */
171 	int hasRETRBUFSIZE;			/* Do not modify this field. */
172 	int hasRBUFSIZ;				/* Do not modify this field. */
173 	int hasRBUFSZ;				/* Do not modify this field. */
174 	int hasSTORBUFSIZE;			/* Do not modify this field. */
175 	int hasSBUFSIZ;				/* Do not modify this field. */
176 	int hasSBUFSZ;				/* Do not modify this field. */
177 	int hasBUFSIZE;				/* Do not modify this field. */
178 	int mlsFeatures;			/* Do not modify this field. */
179 	int STATfileParamWorks;			/* Do not modify this field. */
180 	int NLSTfileParamWorks;			/* Do not modify this field. */
181 	struct sockaddr_in servCtlAddr;		/* Do not modify this field. */
182 	struct sockaddr_in servDataAddr;	/* Do not modify this field. */
183 	struct sockaddr_in ourCtlAddr;		/* Do not modify this field. */
184 	struct sockaddr_in ourDataAddr;		/* Do not modify this field. */
185 	int netMode;				/* Do not use or modify. */
186 	char *buf;				/* Do not modify this field. */
187 	size_t bufSize;				/* Do not modify this field. */
188 	FILE *cin;				/* Do not use or modify. */
189 	FILE *cout;				/* Do not use or modify. */
190 	int ctrlSocketR;			/* You may use but not modify/close. */
191 	int ctrlSocketW;			/* You may use but not modify/close. */
192 	int dataSocket;				/* You may use but not modify/close. */
193 	int errNo;				/* You may modify this if you want. */
194 	unsigned short ephemLo;			/* You may modify this if you want. */
195 	unsigned short ephemHi;			/* You may modify this if you want. */
196 	int cancelXfer;				/* You may modify this. */
197 	longest_int bytesTransferred;		/* Do not modify this field. */
198 	FTPProgressMeterProc progress;		/* You may modify this if you want. */
199 	int useProgressMeter;			/* Used internally. */
200 	int leavePass;				/* You may modify this. */
201 	double sec;				/* Do not modify this field. */
202 	double secLeft;				/* Do not modify this field. */
203 	double kBytesPerSec;			/* Do not modify this field. */
204 	double percentCompleted;		/* Do not modify this field. */
205 	longest_int expectedSize;		/* Do not modify this field. */
206 	time_t mdtm;				/* Do not modify this field. */
207 	time_t nextProgressUpdate;		/* Do not modify this field. */
208 	const char *rname;			/* Do not modify this field. */
209 	const char *lname;			/* Do not modify this field. */
210 	struct timeval t0;			/* Do not modify this field. */
211 	int stalled;				/* Do not modify this field. */
212 	int dataTimedOut;			/* Do not modify this field. */
213 	int eofOkay;				/* Do not use or modify. */
214 	char lastFTPCmdResultStr[128];		/* You may modify this if you want. */
215 	LineList lastFTPCmdResultLL;		/* Use, but do not modify. */
216 	int lastFTPCmdResultNum;		/* You may modify this if you want. */
217 	char firewallHost[64];			/* You may modify this. */
218 	char firewallUser[64];			/* You may modify this. */
219 	char firewallPass[64];			/* You may modify this. */
220 	unsigned int firewallPort;		/* You may modify this. */
221 	int firewallType;			/* You may modify this. */
222 	int require20;				/* You may modify this. */
223 	int usingTAR;				/* Use, but do not modify. */
224 	FTPConnectMessageProc onConnectMsgProc; /* You may modify this. */
225 	FTPRedialStatusProc redialStatusProc;	/* You may modify this. */
226 	FTPPrintResponseProc printResponseProc; /* You may modify this. */
227 	FTPLoginMessageProc onLoginMsgProc;	/* You may modify this. */
228 	size_t ctrlSocketRBufSize;		/* You may modify this. */
229 	size_t ctrlSocketSBufSize;		/* You may modify this. */
230 	size_t dataSocketRBufSize;		/* You may modify this. */
231 	size_t dataSocketSBufSize;		/* You may modify this. */
232 	int serverType;				/* Do not use or modify. */
233 	int ietfCompatLevel;			/* Do not use or modify. */
234 	int numDownloads;			/* Do not use or modify. */
235 	int numUploads;				/* Do not use or modify. */
236 	int numListings;			/* Do not use or modify. */
237 	int doNotGetStartingWorkingDirectory;	/* You may modify this. */
238 #if USE_SIO
239 	char srlBuf[768];
240 	SReadlineInfo ctrlSrl;		/* Do not use or modify. */
241 #endif
242 	FTPGetPassphraseProc passphraseProc;	/* You may modify this. */
243 	int iUser;				/* Scratch integer field you can use. */
244 	void *pUser;				/* Scratch pointer field you can use. */
245 	longest_int llUser;			/* Scratch long long field you can use. */
246 	const char *asciiFilenameExtensions;	/* You may assign this. */
247 	int reserved[32];			/* Do not use or modify. */
248 } FTPConnectionInfo;
249 
250 typedef struct FileInfo *FileInfoPtr, **FileInfoVec;
251 typedef struct FileInfo {
252 	FileInfoPtr prev, next;
253 	char *relname;
254 	char *rname;
255 	char *rlinkto;
256 	char *lname;
257 	char *plug;	/* permissions, links, user, group */
258 	int type;
259 	time_t mdtm;
260 	longest_int size;
261 	size_t relnameLen;
262 } FileInfo;
263 
264 typedef struct FileInfoList {
265 	FileInfoPtr first, last;
266 	FileInfoVec vec;
267 	size_t maxFileLen;
268 	size_t maxPlugLen;
269 	int nFileInfos;
270 	int sortKey;
271 	int sortOrder;
272 } FileInfoList, *FileInfoListPtr;
273 
274 /* Used with UnMlsT() */
275 typedef struct MLstItem{
276 	char fname[512];
277 	char linkto[512];
278 	int ftype;
279 	longest_int fsize;
280 	time_t ftime;
281 	int mode;		/* "UNIX.mode" fact */
282 	int uid;		/* "UNIX.uid" fact */
283 	int gid;		/* "UNIX.gid" fact */
284 	char perm[16];		/* "perm" fact */
285 	char owner[16];		/* "UNIX.owner" fact */
286 	char group[16];		/* "UNIX.group" fact */
287 } MLstItem, *MLstItemPtr;
288 
289 /* Messages we pass to the current progress meter function. */
290 #define kPrInitMsg			1
291 #define kPrUpdateMsg			2
292 #define kPrEndMsg			3
293 
294 /* Parameter for OpenDataConnection() */
295 #define kSendPortMode			0
296 #define kPassiveMode			1
297 #define kFallBackToSendPortMode		2
298 
299 /* Parameter for AcceptDataConnection() */
300 #define kAcceptForWriting		00100
301 #define kAcceptForReading		00101
302 #define kNetWriting			kAcceptForWriting
303 #define kNetReading			kAcceptForReading
304 
305 /* Value for printMode field of Response structure.
306  * Generally, don't worry about this.
307  */
308 #define kResponseNoPrint 00001
309 #define kResponseNoSave  00002
310 #define kResponseNoProc  00002
311 
312 #define kDefaultFTPPort			21
313 
314 #define kDefaultFTPBufSize		32768
315 
316 #ifdef USE_SIO
317 /* This version of the library can handle timeouts without
318  * a user-installed signal handler.
319  */
320 #define kDefaultXferTimeout		600
321 #define kDefaultConnTimeout		30
322 #define kDefaultCtrlTimeout		135
323 #define kDefaultAbortTimeout	10
324 #else
325 /* The library doesn't use timeouts by default because it would
326  * break apps that don't have a SIGALRM handler.
327  */
328 #define kDefaultXferTimeout		(0)	/* No timeout. */
329 #define kDefaultConnTimeout		(0)	/* No timeout. */
330 #define kDefaultCtrlTimeout		(0)	/* No timeout. */
331 #define kDefaultAbortTimeout		10
332 #endif
333 
334 
335 /* Suggested timeout values, in seconds, if you use timeouts. */
336 #define kSuggestedDefaultXferTimeout	(0)	/* No timeout on data blocks. */
337 #define kSuggestedDefaultConnTimeout	30
338 #define kSuggestedDefaultCtrlTimeout	135	/* 2*MSL, + slop */
339 #define kSuggestedAbortTimeout		10
340 
341 #define kDefaultMaxDials		3
342 #define kDefaultRedialDelay		20	/* seconds */
343 
344 #define kDefaultDataPortMode		kSendPortMode
345 
346 #define kRedialStatusDialing		0
347 #define kRedialStatusSleeping		1
348 
349 #ifndef INADDR_NONE
350 #	define INADDR_NONE		(0xffffffff)	/* <netinet/in.h> should have it. */
351 #endif
352 
353 #define kTypeAscii			'A'
354 #define kTypeBinary			'I'
355 #define kTypeEbcdic			'E'
356 
357 #define kGlobChars 			"[*?"
358 #define GLOBCHARSINSTR(a)		(strpbrk(a, kGlobChars) != NULL)
359 
360 #define kGlobYes			1
361 #define kGlobNo				0
362 #define kRecursiveYes			1
363 #define kRecursiveNo			0
364 #define kAppendYes			1
365 #define kAppendNo			0
366 #define kResumeYes			1
367 #define kResumeNo			0
368 #define kDeleteYes			1
369 #define kDeleteNo			0
370 #define kTarYes				1
371 #define kTarNo				0
372 
373 #define UNIMPLEMENTED_CMD(a)		((a == 500) || (a == 502) || (a == 504))
374 
375 /* Possible values returned by GetDateAndTime. */
376 #define kSizeUnknown			((longest_int) (-1))
377 #define kModTimeUnknown			((time_t) (-1))
378 
379 #define kCommandAvailabilityUnknown	(-1)
380 #define kCommandAvailable		1
381 #define kCommandNotAvailable		0
382 
383 /* Values returned by FTPDecodeURL. */
384 #define kNotURL				(-1)
385 #define kMalformedURL			(-2)
386 
387 /* Values for the firewall/proxy open. */
388 #define kFirewallNotInUse			0
389 #define kFirewallUserAtSite			1
390 #define kFirewallLoginThenUserAtSite		2
391 #define kFirewallSiteSite			3
392 #define kFirewallOpenSite			4
393 #define kFirewallUserAtUserPassAtPass		5
394 #define kFirewallFwuAtSiteFwpUserPass		6
395 #define kFirewallUserAtSiteFwuPassFwp		7
396 #define kFirewallLastType			kFirewallUserAtSiteFwuPassFwp
397 
398 /* For MLSD, MLST, and STAT. */
399 #define kPreferredMlsOpts	(kMlsOptType | kMlsOptSize | kMlsOptModify | kMlsOptUNIXmode | kMlsOptUNIXowner | kMlsOptUNIXgroup | kMlsOptUNIXuid | kMlsOptUNIXgid | kMlsOptPerm)
400 
401 #define kMlsOptType		00001
402 #define kMlsOptSize		00002
403 #define kMlsOptModify		00004
404 #define kMlsOptUNIXmode		00010
405 #define kMlsOptUNIXowner	00020
406 #define kMlsOptUNIXgroup	00040
407 #define kMlsOptPerm		00100
408 #define kMlsOptUNIXuid		00200
409 #define kMlsOptUNIXgid		00400
410 #define kMlsOptUnique		01000
411 
412 /* For FTPFtw(). */
413 #define kFtwFile 0
414 #define kFtwDir 1
415 
416 /* For FTPChdir3(). */
417 #define kChdirOnly		00000
418 #define kChdirAndMkdir		00001
419 #define kChdirAndGetCWD		00002
420 #define kChdirOneSubdirAtATime	00004
421 
422 /* Return codes for custom ConfirmResumeDownloadProcs. */
423 #define kConfirmResumeProcNotUsed 0
424 #define kConfirmResumeProcSaidSkip 1
425 #define kConfirmResumeProcSaidResume 2
426 #define kConfirmResumeProcSaidOverwrite 3
427 #define kConfirmResumeProcSaidAppend 4
428 #define kConfirmResumeProcSaidBestGuess 5
429 #define kConfirmResumeProcSaidCancel 6
430 
431 typedef int (*ConfirmResumeDownloadProc)(
432 	const char *volatile *localpath,
433 	volatile longest_int localsize,
434 	volatile time_t localmtime,
435 	const char *volatile remotepath,
436 	volatile longest_int remotesize,
437 	volatile time_t remotetime,
438 	volatile longest_int *volatile startPoint
439 );
440 
441 typedef int (*ConfirmResumeUploadProc)(
442 	const char *volatile localpath,
443 	volatile longest_int localsize,
444 	volatile time_t localmtime,
445 	const char *volatile *remotepath,
446 	volatile longest_int remotesize,
447 	volatile time_t remotetime,
448 	volatile longest_int *volatile startPoint
449 );
450 
451 #define NoConfirmResumeDownloadProc	((ConfirmResumeDownloadProc) 0)
452 #define NoConfirmResumeUploadProc	((ConfirmResumeUploadProc) 0)
453 #define NoGetPassphraseProc			((FTPGetPassphraseProc) 0)
454 
455 /* Types of FTP server software.
456  *
457  * We try to recognize a few of these, for information
458  * only, and occasional uses to determine some additional
459  * or broken functionality.
460  */
461 #define kServerTypeUnknown		0
462 #define kServerTypeWuFTPd		1
463 #define kServerTypeNcFTPd		2
464 #define kServerTypeProFTPD		3
465 #define kServerTypeMicrosoftFTP		4
466 #define kServerTypeWarFTPd		5
467 #define kServerTypeServ_U		6
468 #define kServerTypeWFTPD		7
469 #define kServerTypeVFTPD		8
470 #define kServerTypeFTP_Max		9
471 #define kServerTypeRoxen		10
472 #define kServerTypeNetWareFTP		11
473 #define kServerTypeWS_FTP		12
474 
475 
476 #if !defined(WIN32) && !defined(_WINDOWS) && !defined(closesocket)
477 #	define closesocket close
478 #endif
479 
480 #if !defined(WIN32) && !defined(_WINDOWS) && !defined(ioctlsocket)
481 #	define ioctlsocket ioctl
482 #endif
483 
484 #if defined(WIN32) || defined(_WINDOWS)
485 #	define LOCAL_PATH_DELIM '\\'
486 #	define LOCAL_PATH_DELIM_STR "\\"
487 #	define LOCAL_PATH_ALTDELIM '/'
488 #	define IsLocalPathDelim(c) ((c == LOCAL_PATH_DELIM) || (c == LOCAL_PATH_ALTDELIM))
489 #	define UNC_PATH_PREFIX "\\\\"
490 #	define IsUNCPrefixed(s) (IsLocalPathDelim(s[0]) && IsLocalPathDelim(s[1]))
491 #else
492 #	define LOCAL_PATH_DELIM '/'
493 #	define LOCAL_PATH_DELIM_STR "/"
494 #	define StrFindLocalPathDelim(a) strchr(a, LOCAL_PATH_DELIM)
495 #	define StrRFindLocalPathDelim(a) strrchr(a, LOCAL_PATH_DELIM)
496 #	define StrRemoveTrailingLocalPathDelim StrRemoveTrailingSlashes
497 #	define IsLocalPathDelim(c) (c == LOCAL_PATH_DELIM)
498 #	define TVFSPathToLocalPath(s)
499 #	define LocalPathToTVFSPath(s)
500 #endif
501 
502 #ifdef __cplusplus
503 extern "C"
504 {
505 #endif	/* __cplusplus */
506 
507 #ifndef _libncftp_ftp_c_
508 extern char gLibNcFTPVersion[64];
509 #endif
510 
511 #ifndef _libncftp_errno_c_
512 extern int gLibNcFTP_Uses_Me_To_Quiet_Variable_Unused_Warnings;
513 #endif
514 
515 #if (defined(__GNUC__)) && (__GNUC__ >= 2)
516 #	ifndef UNUSED
517 #		define UNUSED(a) a __attribute__ ((unused))
518 #	endif
519 #	define LIBNCFTP_USE_VAR(a)
520 #else
521 #	define LIBNCFTP_USE_VAR(a) gLibNcFTP_Uses_Me_To_Quiet_Variable_Unused_Warnings = (a == 0)
522 #	ifndef UNUSED
523 #		define UNUSED(a) a
524 #	endif
525 #endif
526 
527 /* Public routines */
528 void FTPAbortDataTransfer(const FTPCIPtr cip);
529 int FTPChdir(const FTPCIPtr cip, const char *const cdCwd);
530 int FTPChdirAndGetCWD(const FTPCIPtr cip, const char *const cdCwd, char *const newCwd, const size_t newCwdSize);
531 int FTPChdir3(FTPCIPtr cip, const char *const cdCwd, char *const newCwd, const size_t newCwdSize, int flags);
532 int FTPChmod(const FTPCIPtr cip, const char *const pattern, const char *const mode, const int doGlob);
533 int FTPCloseHost(const FTPCIPtr cip);
534 int FTPCmd(const FTPCIPtr cip, const char *const cmdspec, ...)
535 #if (defined(__GNUC__)) && (__GNUC__ >= 2)
536 __attribute__ ((format (printf, 2, 3)))
537 #endif
538 ;
539 int FTPDecodeURL(const FTPCIPtr cip, char *const url, LineListPtr cdlist, char *const fn, const size_t fnsize, int *const xtype, int *const wantnlst);
540 int FTPDelete(const FTPCIPtr cip, const char *const pattern, const int recurse, const int doGlob);
541 int FTPFileExists(const FTPCIPtr cip, const char *const file);
542 int FTPFileModificationTime(const FTPCIPtr cip, const char *const file, time_t *const mdtm);
543 int FTPFileSize(const FTPCIPtr cip, const char *const file, longest_int *const size, const int type);
544 int FTPFileSizeAndModificationTime(const FTPCIPtr cip, const char *const file, longest_int *const size, const int type, time_t *const mdtm);
545 int FTPFileType(const FTPCIPtr cip, const char *const file, int *const ftype);
546 int FTPGetCWD(const FTPCIPtr cip, char *const newCwd, const size_t newCwdSize);
547 int FTPGetFiles3(const FTPCIPtr cip, const char *pattern, const char *const dstdir, const int recurse, int doGlob, const int xtype, const int resumeflag, int appendflag, const int deleteflag, const int tarflag, const ConfirmResumeDownloadProc resumeProc, int reserved);
548 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 ConfirmResumeDownloadProc resumeProc, int reserved);
549 int FTPInitConnectionInfo(const FTPLIPtr lip, const FTPCIPtr cip, size_t bufsize);
550 int FTPInitLibrary(const FTPLIPtr lip);
551 int FTPIsDir(const FTPCIPtr cip, const char *const dir);
552 int FTPIsRegularFile(const FTPCIPtr cip, const char *const file);
553 int FTPList(const FTPCIPtr cip, const int outfd, const int longMode, const char *const lsflag);
554 int FTPListToMemory(const FTPCIPtr cip, const char *const pattern, const LineListPtr llines, const char *const lsflags);
555 int FTPLocalGlob(FTPCIPtr cip, LineListPtr fileList, const char *pattern, int doGlob);
556 int FTPLoginHost(const FTPCIPtr cip);
557 int FTPMkdir(const FTPCIPtr cip, const char *const newDir, const int recurse);
558 int FTPMkdir2(const FTPCIPtr cip, const char *const newDir, const int recurse, const char *const curDir);
559 int FTPOpenHost(const FTPCIPtr cip);
560 int FTPOpenHostNoLogin(const FTPCIPtr cip);
561 void FTPPerror(const FTPCIPtr cip, const int err, const int eerr, const char *const s1, const char *const s2);
562 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 ConfirmResumeUploadProc resumeProc, int reserved);
563 int FTPPutFiles3(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, 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 ConfirmResumeUploadProc resumeProc, int reserved);
564 int FTPRemoteGlob(FTPCIPtr cip, LineListPtr fileList, const char *pattern, int doGlob);
565 int FTPRename(const FTPCIPtr cip, const char *const oldname, const char *const newname);
566 int FTPRmdir(const FTPCIPtr cip, const char *const pattern, const int recurse, const int doGlob);
567 void FTPShutdownHost(const FTPCIPtr cip);
568 const char *FTPStrError(int e);
569 int FTPSymlink(const FTPCIPtr cip, const char *const lfrom, const char *const lto);
570 int FTPUmask(const FTPCIPtr cip, const char *const umsk);
571 int FTPUtime(const FTPCIPtr cip, const char *const file, time_t actime, time_t modtime, time_t crtime);
572 
573 /* LineList routines */
574 int CopyLineList(LineListPtr, LineListPtr);
575 void DisposeLineListContents(LineListPtr);
576 void InitLineList(LineListPtr);
577 LinePtr RemoveLine(LineListPtr, LinePtr);
578 LinePtr AddLine(LineListPtr, const char *);
579 
580 /* Other routines that might be useful. */
581 char *StrDup(const char *);
582 char *FGets(char *, size_t, FILE *);
583 void GetHomeDir(char *, size_t);
584 void GetUsrName(char *, size_t);
585 void Scramble(unsigned char *dst, size_t dsize, unsigned char *src, char *key);
586 time_t UnMDTMDate(char *);
587 int MkDirs(const char *const, int mode1);
588 char *GetPass(const char *const prompt);
589 int FilenameExtensionIndicatesASCII(const char *const pathName, const char *const extnList);
590 void StrRemoveTrailingSlashes(char *dst);
591 #if defined(WIN32) || defined(_WINDOWS)
592 char *StrFindLocalPathDelim(const char *src);
593 char *StrRFindLocalPathDelim(const char *src);
594 void StrRemoveTrailingLocalPathDelim(char *dst);
595 void TVFSPathToLocalPath(char *dst);
596 void LocalPathToTVFSPath(char *dst);
597 int gettimeofday(struct timeval *const tp, void *junk);
598 void WinSleep(unsigned int seconds);
599 #endif
600 
601 #ifdef HAVE_SIGACTION
602 void (*NcSignal(int signum, void (*handler)(int)))(int);
603 #elif !defined(NcSignal)
604 #	define NcSignal signal
605 #endif
606 
607 /* Obselete routines. */
608 int FTPGetOneFile(const FTPCIPtr cip, const char *const file, const char *const dstfile);
609 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);
610 int FTPGetFiles(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob);
611 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);
612 int FTPGetOneFileAscii(const FTPCIPtr cip, const char *const file, const char *const dstfile);
613 int FTPGetFilesAscii(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob);
614 int FTPPutOneFile(const FTPCIPtr cip, const char *const file, const char *const dstfile);
615 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);
616 int FTPPutFiles(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob);
617 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);
618 int FTPPutOneFileAscii(const FTPCIPtr cip, const char *const file, const char *const dstfile);
619 int FTPPutFilesAscii(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob);
620 
621 /* Private routines, or stuff for testing */
622 char *FTPGetLocalCWD(char *buf, size_t size);
623 int FTPQueryFeatures(const FTPCIPtr);
624 int FTPMListOneFile(const FTPCIPtr cip, const char *const file, const MLstItemPtr mlip);
625 void FTPInitializeOurHostName(const FTPLIPtr);
626 void FTPInitializeAnonPassword(const FTPLIPtr);
627 int FTPListToMemory2(const FTPCIPtr cip, const char *const pattern, const LineListPtr llines, const char *const lsflags, const int blanklines, int *const tryMLSD);
628 void FTPInitIOTimer(const FTPCIPtr);
629 int FTPStartDataCmd(const FTPCIPtr, int, int, longest_int, const char *,...)
630 #if (defined(__GNUC__)) && (__GNUC__ >= 2)
631 __attribute__ ((format (printf, 5, 6)))
632 #endif
633 ;
634 void FTPStartIOTimer(const FTPCIPtr);
635 void FTPStopIOTimer(const FTPCIPtr);
636 void FTPUpdateIOTimer(const FTPCIPtr);
637 int FTPSetTransferType(const FTPCIPtr, int);
638 int FTPEndDataCmd(const FTPCIPtr, int);
639 int FTPRemoteHelp(const FTPCIPtr, const char *const, const LineListPtr);
640 int FTPCmdNoResponse(const FTPCIPtr, const char *const cmdspec,...)
641 #if (defined(__GNUC__)) && (__GNUC__ >= 2)
642 __attribute__ ((format (printf, 2, 3)))
643 #endif
644 ;
645 int WaitResponse(const FTPCIPtr, unsigned int);
646 int FTPLocalRecursiveFileList(FTPCIPtr, LineListPtr, FileInfoListPtr);
647 int FTPLocalRecursiveFileList2(FTPCIPtr cip, LineListPtr fileList, FileInfoListPtr files, int erelative);
648 int FTPRemoteRecursiveFileList(FTPCIPtr, LineListPtr, FileInfoListPtr);
649 int FTPRemoteRecursiveFileList1(FTPCIPtr, char *const, FileInfoListPtr);
650 int FTPRebuildConnectionInfo(const FTPLIPtr lip, const FTPCIPtr cip);
651 int FTPFileExistsStat(const FTPCIPtr cip, const char *const file);
652 int FTPFileExistsNlst(const FTPCIPtr cip, const char *const file);
653 int FTPFileExists2(const FTPCIPtr cip, const char *const file, const int tryMDTM, const int trySIZE, const int tryMLST, const int trySTAT, const int tryNLST);
654 int FTPFtw(const FTPCIPtr cip, const char *const dir, FTPFtwProc proc, int maxdepth);
655 int BufferGets(char *, size_t, int, char *, char **, char **, size_t);
656 void DisposeFileInfoListContents(FileInfoListPtr);
657 void InitFileInfoList(FileInfoListPtr);
658 void InitFileInfo(FileInfoPtr);
659 FileInfoPtr RemoveFileInfo(FileInfoListPtr, FileInfoPtr);
660 FileInfoPtr AddFileInfo(FileInfoListPtr, FileInfoPtr);
661 void SortFileInfoList(FileInfoListPtr, int, int);
662 void VectorizeFileInfoList(FileInfoListPtr);
663 void UnvectorizeFileInfoList(FileInfoListPtr);
664 int ComputeRNames(FileInfoListPtr, const char *, int, int);
665 int ComputeLNames(FileInfoListPtr, const char *, const char *, int);
666 int ConcatFileInfoList(FileInfoListPtr, FileInfoListPtr);
667 int ConcatFileToFileInfoList(FileInfoListPtr, char *);
668 int LineListToFileInfoList(LineListPtr, FileInfoListPtr);
669 int LineToFileInfoList(LinePtr, FileInfoListPtr);
670 void URLCopyToken(char *, size_t, const char *, size_t);
671 int UnMlsT(const char *const, const MLstItemPtr);
672 int UnMlsD(FileInfoListPtr, LineListPtr);
673 int UnLslR(FileInfoListPtr, LineListPtr, int);
674 void TraceResponse(const FTPCIPtr, ResponsePtr);
675 void PrintResponse(const FTPCIPtr, LineListPtr);
676 void DoneWithResponse(const FTPCIPtr, ResponsePtr);
677 ResponsePtr InitResponse(void);
678 void ReInitResponse(const FTPCIPtr, ResponsePtr);
679 int GetTelnetString(const FTPCIPtr, char *, size_t, FILE *, FILE *);
680 int GetResponse(const FTPCIPtr, ResponsePtr);
681 int RCmd(const FTPCIPtr, ResponsePtr, const char *, ...)
682 #if (defined(__GNUC__)) && (__GNUC__ >= 2)
683 __attribute__ ((format (printf, 3, 4)))
684 #endif
685 ;
686 
687 #ifdef __cplusplus
688 }
689 #endif	/* __cplusplus */
690 
691 #endif /* _ncftp_h_ */
692