1 /* c_rhelp.c
2  *
3  * Copyright (c) 1996-2005 Mike Gleason, NcFTP Software.
4  * All rights reserved.
5  *
6  */
7 
8 #include "syshdrs.h"
9 #ifdef PRAGMA_HDRSTOP
10 #	pragma hdrstop
11 #endif
12 
13 int
FTPRemoteHelp(const FTPCIPtr cip,const char * const pattern,const FTPLineListPtr llp)14 FTPRemoteHelp(const FTPCIPtr cip, const char *const pattern, const FTPLineListPtr llp)
15 {
16 	int result;
17 	ResponsePtr rp;
18 
19 	if ((cip == NULL) || (llp == NULL))
20 		return (kErrBadParameter);
21 	if (strcmp(cip->magic, kLibraryMagic))
22 		return (kErrBadMagic);
23 
24 	InitLineList(llp);
25 	rp = InitResponse();
26 	if (rp == NULL) {
27 		result = kErrMallocFailed;
28 		cip->errNo = kErrMallocFailed;
29 		FTPLogError(cip, kDontPerror, "Malloc failed.\n");
30 	} else {
31 		if ((pattern == NULL) || (*pattern == '\0'))
32 			result = RCmd(cip, rp, "HELP");
33 		else
34 			result = RCmd(cip, rp, "HELP %s", pattern);
35 		if (result < 0) {
36 			DoneWithResponse(cip, rp);
37 			return (result);
38 		} else if (result == 2) {
39 			if (CopyLineList(llp, &rp->msg) < 0) {
40 				result = kErrMallocFailed;
41 				cip->errNo = kErrMallocFailed;
42 				FTPLogError(cip, kDontPerror, "Malloc failed.\n");
43 			} else {
44 				result = kNoErr;
45 			}
46 		} else {
47 			cip->errNo = kErrHELPFailed;
48 			result = kErrHELPFailed;
49 		}
50 		DoneWithResponse(cip, rp);
51 	}
52 	return (result);
53 }	/* FTPRemoteHelp */
54