pref.c

来自「这是一个开放源代码的与WINNT/WIN2K/WIN2003兼容的操作系统」· C语言 代码 · 共 792 行 · 第 1/2 页

C
792
字号
/* pref.c
 *
 * Copyright (c) 1992-2001 by Mike Gleason.
 * All rights reserved.
 *
 */

#include "syshdrs.h"

#ifdef ncftp
#include "progress.h"
#endif

#include "pref.h"
#include "util.h"

/* How many times they've run this program. */
extern int gNumProgramRuns;

/* Their $PAGER. */
char gPager[128];

/* These correspond to the various timeouts from LibNcFTP. */
int gConnTimeout, gXferTimeout, gCtrlTimeout;

/* Active or passive FTP?  (PORT or PASV?)  Or both? */
extern int gDataPortMode, gFwDataPortMode;

/* When the destination file already exists, resume transfer or ask user? */
int gAutoResume;

/* "Save a bookmark to this site before closing?" */
int gConfirmClose;

/* Should we update the bookmark for the user? */
int gAutoSaveChangesToExistingBookmarks;

/* "Save your password with the bookmark?" */
int gSavePasswords;

int gMaySetXtermTitle;

/* Number of seconds between connection attempts. */
int gRedialDelay;

/* Some messages we only want to bug the user about once, ever. */
char gOneTimeMessagesSeen[256];

/* Tune the size of the socket buffer using SO_RCVBUF or SO_SNDBUF? */
int gSOBufsize;

/* Size of the user log before we trim it.  0 means do not log at all. */
int gMaxLogSize;

/* Use ASCII mode automatically for files with these extensions. */
char gAutoAscii[512];

#ifdef ncftp
/* Which meter to use. */
FTPProgressMeterProc gProgressMeter;
#endif

/* Allow us to plug our other products? */
int gDoNotDisplayAds;

/* Do we need to save the prefs, or can we skip it? */
int gPrefsDirty = 0;

extern FTPLibraryInfo gLib;
extern FTPConnectionInfo gConn;
extern char gOurDirectoryPath[], gUser[], gVersion[];

PrefOpt gPrefOpts[] = {
	{ "anonopen",				PREFOBSELETE },
	{ "anonpass", 				SetAnonPass, kPrefOptObselete },
	{ "anon-password",			SetAnonPass, 1 },
	{ "auto-ascii",				SetAutoAscii, 1 },
	{ "auto-resume",			SetAutoResume, 1 },
	{ "autosave-bookmark-changes",		SetAutoSaveChangesToExistingBookmarks, 1 },
	{ "blank-lines",			PREFOBSELETE },
	{ "confirm-close",			SetConfirmClose, 1 },
	{ "connect-timeout",			SetConnTimeout, 1 },
	{ "control-timeout",			SetCtrlTimeout, 1 },
	{ "logsize",				SetLogSize, 1 },
	{ "maxbookmarks",			PREFOBSELETE },
	{ "one-time-messages-seen",		SetOneTimeMessages, 0 },
	{ "pager",				SetPager, 1 },
	{ "passive",				SetPassive, 1 },
	{ "progress-meter",			SetProgressMeter, 1 },
	{ "redial-delay",			SetRedialDelay, 1 },
	{ "remote-msgs", 			PREFOBSELETE },
	{ "restore-lcwd", 			PREFOBSELETE },
	{ "save-passwords",			SetSavePasswords, 1 },
	{ "show-trailing-space",		PREFOBSELETE },
	{ "show-status-in-xterm-titlebar",	SetXtTitle, 1 },
#ifdef SO_RCVBUF
	{ "so-bufsize",				SetSOBufsize, 1 },
#endif
	{ "startup-lcwd", 			PREFOBSELETE },
	{ "startup-msgs", 			PREFOBSELETE },
	{ "timeout",				PREFOBSELETE },
	{ "total-runs", 			PREFOBSELETE },
	{ "total-xfer-hundredths-of-seconds", 	PREFOBSELETE },
	{ "total-xfer-kbytes", 			PREFOBSELETE },
	{ "trace",				PREFOBSELETE },
	{ "utime",				PREFOBSELETE },
	{ "visual",				PREFOBSELETE },
	{ "xfer-timeout",			SetXferTimeout, 1 },
	{ "yes-i-know-about-NcFTPd",		SetNoAds, 1 },
	{ NULL,					(PrefProc) 0, kPrefOptInvisible, },
};

int gNumPrefOpts = ((int)(sizeof(gPrefOpts) / sizeof(PrefOpt)) - 1);



void
SetAnonPass(int UNUSED(t), const char *const val, FILE *const fp)
{
	LIBNCFTP_USE_VAR(t);
	if (fp != NULL) {
		(void) fprintf(fp, "%s", gLib.defaultAnonPassword);
	} else {
		(void) STRNCPY(gLib.defaultAnonPassword, val);
	}
}	/* SetAnonPass */



void
SetAutoAscii(int UNUSED(t), const char *const val, FILE *const fp)
{
	LIBNCFTP_USE_VAR(t);
	if (fp != NULL) {
		(void) fprintf(fp, "%s", gAutoAscii);
	} else {
		(void) STRNCPY(gAutoAscii, val);
		if ((gAutoAscii[0] == '\0') || (ISTREQ(gAutoAscii, "no")) || (ISTREQ(gAutoAscii, "off")) || (ISTREQ(gAutoAscii, "false"))) {
			gConn.asciiFilenameExtensions = NULL;
		} else {
			gConn.asciiFilenameExtensions = gAutoAscii;
		}
	}
}	/* SetAutoAscii */



void
SetAutoResume(int UNUSED(t), const char *const val, FILE *const fp)
{
	LIBNCFTP_USE_VAR(t);
	if (fp != NULL) {
		(void) fprintf(fp, "%s", YESNO(gAutoResume));
	} else {
		gAutoResume = StrToBool(val);
	}
}	/* SetAutoResume */



void
SetAutoSaveChangesToExistingBookmarks(int UNUSED(t), const char *const val, FILE *const fp)
{
	LIBNCFTP_USE_VAR(t);
	if (fp != NULL) {
		(void) fprintf(fp, "%s", YESNO(gAutoSaveChangesToExistingBookmarks));
	} else {
		gAutoSaveChangesToExistingBookmarks = StrToBool(val);
	}
}	/* SetAutoSaveChangesToExistingBookmarks */



void
SetConfirmClose(int UNUSED(t), const char *const val, FILE *const fp)
{
	LIBNCFTP_USE_VAR(t);
	if (fp != NULL) {
		(void) fprintf(fp, "%s", YESNO(gConfirmClose));
	} else {
		gConfirmClose = StrToBool(val);
	}
}	/* SetConfirmClose */



void
SetConnTimeout(int UNUSED(t), const char *const val, FILE *const fp)
{
	LIBNCFTP_USE_VAR(t);
	if (fp != NULL) {
		(void) fprintf(fp, "%d", gConnTimeout);
	} else {
		gConn.connTimeout = gConnTimeout = atoi(val);
	}
}	/* SetConnTimeout */



void
SetCtrlTimeout(int UNUSED(t), const char *const val, FILE *const fp)
{
	LIBNCFTP_USE_VAR(t);
	if (fp != NULL) {
		(void) fprintf(fp, "%d", gCtrlTimeout);
	} else {
		gConn.ctrlTimeout = gCtrlTimeout = atoi(val);
	}
}	/* SetCtrlTimeout */



void
SetLogSize(int UNUSED(t), const char *const val, FILE *const fp)
{
	LIBNCFTP_USE_VAR(t);
	if (fp != NULL) {
		(void) fprintf(fp, "%d", gMaxLogSize);
	} else {
		gMaxLogSize = atoi(val);
	}
}	/* SetLogSize */



void
SetNoAds(int UNUSED(t), const char *const val, FILE *const fp)
{
	LIBNCFTP_USE_VAR(t);
	if (fp != NULL) {
		(void) fprintf(fp, "%s", YESNO(gDoNotDisplayAds));
	} else {
		gDoNotDisplayAds = StrToBool(val);
	}
}	/* SetNoAds */



void
SetOneTimeMessages(int UNUSED(t), const char *const val, FILE *const fp)
{
	LIBNCFTP_USE_VAR(t);
	if (fp != NULL) {
		(void) fprintf(fp, "%s", gOneTimeMessagesSeen);
	} else {
		(void) STRNCPY(gOneTimeMessagesSeen, val);
	}
}	/* SetOneTimeMessages */



void
SetPager(int UNUSED(t), const char *const val, FILE *const fp)
{
	LIBNCFTP_USE_VAR(t);
	if (fp != NULL) {
		(void) fprintf(fp, "%s", gPager);
	} else {
		(void) STRNCPY(gPager, val);
	}
}	/* SetPager */



void
SetPassive(int UNUSED(t), const char *const val, FILE *const fp)
{
	int m;

	LIBNCFTP_USE_VAR(t);
	if (fp != NULL) {
		m = (gFwDataPortMode >= 0) ? gFwDataPortMode : gDataPortMode;
		if (m == kSendPortMode) {
			(void) fprintf(fp, "%s", "off");
		} else if (m == kPassiveMode) {
			(void) fprintf(fp, "%s", "on");
		} else {
			(void) fprintf(fp, "%s", "optional");
		}
	} else {
		if (gFwDataPortMode >= 0) {
			gDataPortMode = gFwDataPortMode;
			return;
		}
		if (ISTRNEQ(val, "opt", 3))
			gDataPortMode = kFallBackToSendPortMode;
		else if (ISTREQ(val, "on"))
			gDataPortMode = kPassiveMode;
		else if ((int) isdigit(val[0]))
			gDataPortMode = atoi(val);
		else
			gDataPortMode = kSendPortMode;
		gConn.dataPortMode = gDataPortMode;
	}
}	/* SetPassive */



#ifdef ncftp
void
SetProgressMeter(int UNUSED(t), const char *const val, FILE *const fp)
{
	LIBNCFTP_USE_VAR(t);
	if (fp != NULL) {
		if (gProgressMeter == PrStatBar) {
			(void) fprintf(fp, "%s", "2 (statbar)");
		} else if (gProgressMeter == PrPhilBar) {
			(void) fprintf(fp, "%s", "1 (philbar)");
		} else {
			(void) fprintf(fp, "%s", "0 (simple)");
		}
	} else {
		if ((val[0] == '0') || (ISTRNEQ(val, "simple", 6)))
			gProgressMeter = PrSizeAndRateMeter;
		else if ((val[0] == '1') || (ISTRNEQ(val, "phil", 4)))
			gProgressMeter = PrPhilBar;
		else
			gProgressMeter = PrStatBar;
		gConn.progress = gProgressMeter;
	}
}	/* SetProgressMeter */
#else
void
SetProgressMeter(int UNUSED(t), const char *const UNUSED(val), FILE *const UNUSED(fp))
{
	LIBNCFTP_USE_VAR(t);
	LIBNCFTP_USE_VAR(val);
	LIBNCFTP_USE_VAR(fp);
}	/* SetProgressMeter */
#endif



void
SetRedialDelay(int UNUSED(t), const char *const val, FILE *const fp)
{
	int i;

	LIBNCFTP_USE_VAR(t);
	if (fp != NULL) {
		(void) fprintf(fp, "%d", gRedialDelay);
	} else {
		i = atoi(val);
		if (i < 10)
			i = 10;
		gRedialDelay = atoi(val);
	}
}	/* SetRedialDelay */



void
SetSavePasswords(int UNUSED(t), const char *const val, FILE *const fp)
{
	LIBNCFTP_USE_VAR(t);
	if (fp != NULL) {
		if (gSavePasswords < 0)
			(void) fprintf(fp, "%s", "ask");
		else
			(void) fprintf(fp, "%s", YESNO(gSavePasswords));
	} else {
		if (ISTREQ(val, "ask"))
			gSavePasswords = -1;
		else
			gSavePasswords = StrToBool(val);
	}
}	/* SetSavePasswords */



void
SetSOBufsize(int UNUSED(t), const char *const val, FILE *const fp)
{
	LIBNCFTP_USE_VAR(t);
	if (fp != NULL) {
		(void) fprintf(fp, "%d", gSOBufsize);
		if (gSOBufsize <= 0)
			(void) fprintf(fp, "%s", " (use system default)");
	} else {
		gConn.dataSocketRBufSize = gConn.dataSocketSBufSize = gSOBufsize = atoi(val);
	}
}	/* SetSOBufsize */




void
SetXferTimeout(int UNUSED(t), const char *const val, FILE *const fp)
{
	LIBNCFTP_USE_VAR(t);
	if (fp != NULL) {
		(void) fprintf(fp, "%d", gXferTimeout);
	} else {
		gConn.xferTimeout = gXferTimeout = atoi(val);
	}
}	/* SetXferTimeout */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?