From f68aa02272d05ffbceea9e0188984d9bf9b83dd1 Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Mon, 31 Dec 2012 19:29:52 +0100 Subject: [PATCH] Implement new configuration option "HelpFile" This new configuration option allows to specify a specially formatted text file which can be used by the HELP command to provide information about the commands and their syntaxes. --- src/ngircd/conf.c | 17 +++++++++++++++++ src/ngircd/conf.h | 3 +++ src/ngircd/defines.h | 3 +++ 3 files changed, 23 insertions(+) diff --git a/src/ngircd/conf.c b/src/ngircd/conf.c index 423221cb..fa1bfba1 100644 --- a/src/ngircd/conf.c +++ b/src/ngircd/conf.c @@ -54,6 +54,7 @@ static CONF_SERVER New_Server; static int New_Server_Idx; static char Conf_MotdFile[FNAME_LEN]; +static char Conf_HelpFile[FNAME_LEN]; static void Set_Defaults PARAMS(( bool InitServers )); static bool Read_Config PARAMS(( bool TestOnly, bool IsStarting )); @@ -316,6 +317,7 @@ Conf_Test( void ) printf(" AdminInfo1 = %s\n", Conf_ServerAdmin1); printf(" AdminInfo2 = %s\n", Conf_ServerAdmin2); printf(" AdminEMail = %s\n", Conf_ServerAdminMail); + printf(" HelpFile = %s\n", Conf_HelpFile); printf(" Info = %s\n", Conf_ServerInfo); printf(" Listen = %s\n", Conf_ListenAddress); if (Using_MotdFile) { @@ -701,8 +703,11 @@ Set_Defaults(bool InitServers) Conf_ListenAddress = NULL; array_free(&Conf_ListenPorts); array_free(&Conf_Motd); + array_free(&Conf_Helptext); strlcpy(Conf_MotdFile, SYSCONFDIR, sizeof(Conf_MotdFile)); strlcat(Conf_MotdFile, MOTD_FILE, sizeof(Conf_MotdFile)); + strlcpy(Conf_HelpFile, SYSCONFDIR, sizeof(Conf_HelpFile)); + strlcat(Conf_HelpFile, HELP_FILE, sizeof(Conf_HelpFile)); strcpy(Conf_ServerPwd, ""); strlcpy(Conf_PidFile, PID_FILE, sizeof(Conf_PidFile)); Conf_UID = Conf_GID = 0; @@ -1047,6 +1052,12 @@ Read_Config(bool TestOnly, bool IsStarting) Using_MotdFile = true; } + /* Try to read ngIRCd help text file. */ + (void)Read_TextFile(Conf_HelpFile, "help text", &Conf_Helptext); + if (!array_bytes(&Conf_Helptext)) + Config_Error(LOG_WARNING, + "No help text available, HELP command will be of limited use."); + #ifdef SSL_SUPPORT /* Make sure that all SSL-related files are readable */ CheckFileReadable("CertFile", Conf_SSLOptions.CertFile); @@ -1312,6 +1323,12 @@ Handle_GLOBAL( int Line, char *Var, char *Arg ) Config_Error_TooLong(Line, Var); return; } + if (strcasecmp(Var, "HelpFile") == 0) { + len = strlcpy(Conf_HelpFile, Arg, sizeof(Conf_HelpFile)); + if (len >= sizeof(Conf_HelpFile)) + Config_Error_TooLong(Line, Var); + return; + } if (strcasecmp(Var, "Listen") == 0) { if (Conf_ListenAddress) { Config_Error(LOG_ERR, diff --git a/src/ngircd/conf.h b/src/ngircd/conf.h index f85a25fa..ac42746c 100644 --- a/src/ngircd/conf.h +++ b/src/ngircd/conf.h @@ -111,6 +111,9 @@ GLOBAL char Conf_ServerAdminMail[CLIENT_INFO_LEN]; /** Message of the day (MOTD) of this server */ GLOBAL array Conf_Motd; +/** Help text of this server */ +GLOBAL array Conf_Helptext; + /** Array of ports this server should listen on */ GLOBAL array Conf_ListenPorts; diff --git a/src/ngircd/defines.h b/src/ngircd/defines.h index ad9716fd..28a260b8 100644 --- a/src/ngircd/defines.h +++ b/src/ngircd/defines.h @@ -77,6 +77,9 @@ /** Name of the MOTD file. */ #define MOTD_FILE "/ngircd.motd" +/** Name of the help file. */ +#define HELP_FILE "/ngircd.help" + /** Default chroot() directory. */ #define CHROOT_DIR "" -- 2.39.2