From 1ce87e9f74acae1f6c294bc19189542b859a466b Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 1 May 2015 10:25:36 -0400 Subject: [PATCH] More conversion to the new config system. WARNING BROKEN BUILD --- citadel/control.c | 112 ++++++++++++++++++---------------- citadel/ical_dezonify.c | 13 +++- citadel/include/ctdl_module.h | 23 +++---- citadel/journaling.c | 13 +++- citadel/msgbase.c | 23 +++---- citadel/room_ops.c | 30 ++++----- citadel/threads.c | 5 +- 7 files changed, 120 insertions(+), 99 deletions(-) diff --git a/citadel/control.c b/citadel/control.c index c4612bb91..01f3d5fc8 100644 --- a/citadel/control.c +++ b/citadel/control.c @@ -288,6 +288,17 @@ long get_new_room_number(void) +/* + * Helper function for cmd_conf() to handle boolean values + */ +int confbool(char *v) +{ + if (IsEmptyStr(v)) return(0); + if (atoi(v) != 0) return(1); + return(0); +} + + /* * Get or set global configuration options * @@ -299,7 +310,8 @@ void cmd_conf(char *argbuf) { char cmd[16]; char buf[256]; - int a; + int a, i; + long ii; char *confptr; char confname[128]; @@ -398,115 +410,111 @@ void cmd_conf(char *argbuf) while (client_getln(buf, sizeof buf) >= 0 && strcmp(buf, "000")) { switch (a) { case 0: - safestrncpy(config.c_nodename, buf, sizeof config.c_nodename); + CtdlSetConfigStr("c_nodename", buf); break; case 1: - safestrncpy(config.c_fqdn, buf, sizeof config.c_fqdn); + CtdlSetConfigStr("c_fqdn", buf); break; case 2: - safestrncpy(config.c_humannode, buf, sizeof config.c_humannode); + CtdlSetConfigStr("c_humannode", buf); break; case 3: /* placeholder -- field no longer in use */ break; case 4: - config.c_creataide = atoi(buf); + CtdlSetConfigInt("c_creataide", atoi(buf)); break; case 5: - config.c_sleeping = atoi(buf); + CtdlSetConfigInt("c_sleeping", atoi(buf)); break; case 6: - config.c_initax = atoi(buf); - if (config.c_initax < 1) - config.c_initax = 1; - if (config.c_initax > 6) - config.c_initax = 6; + i = atoi(buf); + if (i < 1) i = 1; + if (i > 6) i = 6; + CtdlSetConfigInt("c_initax", i); break; case 7: - config.c_regiscall = atoi(buf); - if (config.c_regiscall != 0) - config.c_regiscall = 1; + CtdlSetConfigInt("c_regiscall", confbool(buf)); break; case 8: - config.c_twitdetect = atoi(buf); - if (config.c_twitdetect != 0) - config.c_twitdetect = 1; + CtdlSetConfigInt("c_twitdetect", confbool(buf)); break; case 9: - safestrncpy(config.c_twitroom, buf, sizeof config.c_twitroom); + CtdlSetConfigStr("c_twitroom", buf); break; case 10: - safestrncpy(config.c_moreprompt, buf, sizeof config.c_moreprompt); + CtdlSetConfigStr("c_moreprompt", buf); break; case 11: - config.c_restrict = atoi(buf); - if (config.c_restrict != 0) - config.c_restrict = 1; + CtdlSetConfigInt("c_restrict", confbool(buf)); break; case 12: - safestrncpy(config.c_site_location, buf, sizeof config.c_site_location); + CtdlSetConfigInt("c_site_location", confbool(buf)); break; case 13: - safestrncpy(config.c_sysadm, buf, sizeof config.c_sysadm); + CtdlSetConfigInt("c_sysadm", confbool(buf)); break; case 14: - config.c_maxsessions = atoi(buf); - if (config.c_maxsessions < 0) - config.c_maxsessions = 0; + i = atoi(buf); + if (i < 0) i = 0; + CtdlSetConfigInt("c_maxsessions", i); break; case 15: /* placeholder -- field no longer in use */ break; case 16: - config.c_userpurge = atoi(buf); + CtdlSetConfigInt("c_userpurge", atoi(buf)); break; case 17: - config.c_roompurge = atoi(buf); + CtdlSetConfigInt("c_roompurge", atoi(buf)); break; case 18: - safestrncpy(config.c_logpages, buf, sizeof config.c_logpages); + CtdlSetConfigStr("c_logpages", buf); break; case 19: - config.c_createax = atoi(buf); - if (config.c_createax < 1) - config.c_createax = 1; - if (config.c_createax > 6) - config.c_createax = 6; + i = atoi(buf); + if (i < 1) i = 1; + if (i > 6) i = 6; + CtdlSetConfigInt("c_createax", i); break; case 20: - if (atoi(buf) >= 8192) - config.c_maxmsglen = atoi(buf); + ii = atol(buf); + if (ii >= 8192) { + CtdlSetConfigLong("c_maxmsglen", ii); + } break; case 21: - if (atoi(buf) >= 2) - config.c_min_workers = atoi(buf); + i = atoi(buf); + if (i >= 3) { // minimum value + CtdlSetConfigInt("c_min_workers", i); + } + break; case 22: - if (atoi(buf) >= config.c_min_workers) - config.c_max_workers = atoi(buf); + i = atoi(buf); + if (i >= CtdlGetConfigInt("c_min_workers")) { // max must be >= min + CtdlSetConfigInt("c_max_workers", i); + } + break; case 23: - config.c_pop3_port = atoi(buf); + CtdlSetConfigInt("c_pop3_port", atoi(buf)); break; case 24: - config.c_smtp_port = atoi(buf); + CtdlSetConfigInt("c_smtp_port", atoi(buf)); break; case 25: - config.c_rfc822_strict_from = atoi(buf); + CtdlSetConfigInt("c_rfc822_strict_from", atoi(buf)); break; case 26: - config.c_aide_zap = atoi(buf); - if (config.c_aide_zap != 0) - config.c_aide_zap = 1; + CtdlSetConfigInt("c_aide_zap", confbool(buf)); break; case 27: - config.c_imap_port = atoi(buf); + CtdlSetConfigInt("c_imap_port", atoi(buf)); break; case 28: - config.c_net_freq = atol(buf); + CtdlSetConfigLong("c_net_freq", atol(buf)); break; case 29: - config.c_disable_newu = atoi(buf); - if (config.c_disable_newu != 0) - config.c_disable_newu = 1; + CtdlSetConfigInt("c_disable_newu", confbool(buf)); break; case 30: /* niu */ diff --git a/citadel/ical_dezonify.c b/citadel/ical_dezonify.c index 41c67a7e7..34c0e4bff 100644 --- a/citadel/ical_dezonify.c +++ b/citadel/ical_dezonify.c @@ -2,6 +2,16 @@ * Function to go through an ical component set and convert all non-UTC * date/time properties to UTC. It also strips out any VTIMEZONE * subcomponents afterwards, because they're irrelevant. + * + * Copyright (c) 1987-2015 by the citadel.org team + * + * This program is open source software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. */ @@ -34,8 +44,7 @@ icaltimezone *get_default_icaltimezone(void) { icaltimezone *zone = NULL; - char *default_zone_name = config.c_default_cal_zone; - //char *default_zone_name = "America/New_York"; + char *default_zone_name = CtdlGetConfigStr("c_default_cal_zone"); if (!zone) { zone = icaltimezone_get_builtin_timezone(default_zone_name); diff --git a/citadel/include/ctdl_module.h b/citadel/include/ctdl_module.h index 744e64fd3..05a5a7037 100644 --- a/citadel/include/ctdl_module.h +++ b/citadel/include/ctdl_module.h @@ -293,23 +293,14 @@ enum { */ void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, const char *search_string, const char *func_name); - -#define SET_CFGSTRBUF(which, buffer) safestrncpy(config.which, ChrPtr(buffer), sizeof(config.which)) -#define SET_CFGSTR(which, buffer) safestrncpy(config.which, buffer, sizeof(config.which)) - -extern struct config config; - - -#define NODENAME config.c_nodename -#define FQDN config.c_fqdn +#define NODENAME CtdlGetConfigStr("c_nodename") +#define FQDN CtdlGetConfigStr("c_fqdn") #define CTDLUID ctdluid -#define CREATAIDE config.c_creataide -#define REGISCALL config.c_regiscall -#define TWITDETECT config.c_twitdetect -#define TWITROOM config.c_twitroom -#define RESTRICT_INTERNET config.c_restrict - -#define CFG_KEY(which) config.which, strlen(config.which) +#define CREATAIDE CtdlGetConfigInt("c_creataide") +#define REGISCALL CtdlGetConfigInt("c_regiscall") +#define TWITDETECT CtdlGetConfigInt("c_twitdetect") +#define TWITROOM CtdlGetConfigStr("c_twitroom") +#define RESTRICT_INTERNET CtdlGetConfigInt("c_restrict") typedef void (*CfgLineParser)(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *rncfg); typedef void (*CfgLineSerializer)(const CfgLineType *ThisOne, StrBuf *OuptputBuffer, OneRoomNetCfg *rncfg, RoomNetCfgLine *data); diff --git a/citadel/journaling.c b/citadel/journaling.c index eb9e378e7..8af9afdca 100644 --- a/citadel/journaling.c +++ b/citadel/journaling.c @@ -1,5 +1,15 @@ /* * Message journaling functions. + * + * Copyright (c) 1987-2015 by the citadel.org team + * + * This program is open source software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. */ #include @@ -8,6 +18,7 @@ #include "ctdl_module.h" #include "citserver.h" +#include "config.h" #include "user_ops.h" #include "serv_vcard.h" /* Needed for vcard_getuser and extract_inet_email_addrs */ #include "internet_addressing.h" @@ -100,7 +111,7 @@ void JournalRunQueueMsg(struct jnlq *jmsg) { if (jmsg == NULL) return; - journal_recps = validate_recipients(config.c_journal_dest, NULL, 0); + journal_recps = validate_recipients(CtdlGetConfigStr("c_journal_dest"), NULL, 0); if (journal_recps != NULL) { if ( (journal_recps->num_local > 0) diff --git a/citadel/msgbase.c b/citadel/msgbase.c index ddc12aafd..a63c1b077 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -1,7 +1,7 @@ /* * Implements the message store. * - * Copyright (c) 1987-2012 by the citadel.org team + * Copyright (c) 1987-2015 by the citadel.org team * * This program is open source software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3. @@ -22,6 +22,7 @@ #include "ctdl_module.h" #include "citserver.h" #include "control.h" +#include "config.h" #include "clientsocket.h" #include "genstamp.h" #include "room_ops.h" @@ -1818,7 +1819,7 @@ void OutputRFC822MsgHeaders( if (haschar(mptr, '@') == 0) { sanitize_truncated_recipient(mptr); - cprintf("To: %s@%s", mptr, config.c_fqdn); + cprintf("To: %s@%s", mptr, CtdlGetConfigStr("c_fqdn")); cprintf("%s", nl); } else @@ -2166,7 +2167,7 @@ int CtdlOutputPreLoadedMsg( strcpy(suser, ""); strcpy(luser, ""); strcpy(fuser, ""); - memcpy(snode, CFG_KEY(c_nodename) + 1); + memcpy(snode, CtdlGetConfigStr("c_nodename"), strlen(CtdlGetConfigStr("c_nodename")) + 1); if (mode == MT_RFC822) OutputRFC822MsgHeaders( TheMessage, @@ -2507,7 +2508,7 @@ long send_message(struct CtdlMessage *msg) { msgidbuflen = snprintf(msgidbuf, sizeof msgidbuf, "%08lX-%08lX@%s", (long unsigned int) time(NULL), (long unsigned int) newmsgid, - config.c_fqdn + CtdlGetConfigStr("c_fqdn") ); /* Generate an ID if we don't have one already */ @@ -2767,7 +2768,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ if (TWITDETECT) { if (CCC->user.axlevel == AxProbU) { strcpy(hold_rm, actual_rm); - strcpy(actual_rm, config.c_twitroom); + strcpy(actual_rm, CtdlGetConfigStr("c_twitroom")); MSGM_syslog(LOG_DEBUG, "Diverting to twit room\n"); } } @@ -3026,7 +3027,7 @@ void quickie_message(const char *from, if (fromaddr != NULL) CM_SetField(msg, erFc822Addr, fromaddr, strlen(fromaddr)); if (room != NULL) CM_SetField(msg, eOriginalRoom, room, strlen(room)); - CM_SetField(msg, eNodeName, CFG_KEY(c_nodename)); + CM_SetField(msg, eNodeName, CtdlGetConfigStr("c_nodename"), strlen(CtdlGetConfigStr("c_nodename"))); if (to != NULL) { CM_SetField(msg, eRecipient, to, strlen(to)); recp = validate_recipients(to, NULL, 0); @@ -3499,8 +3500,8 @@ struct CtdlMessage *CtdlMakeMessageLen( CM_SetField(msg, eOriginalRoom, CCC->room.QRname, strlen(CCC->room.QRname)); } - CM_SetField(msg, eNodeName, CFG_KEY(c_nodename)); - CM_SetField(msg, eHumanNode, CFG_KEY(c_humannode)); + CM_SetField(msg, eNodeName, CtdlGetConfigStr("c_nodename"), strlen(CtdlGetConfigStr("c_nodename"))); + CM_SetField(msg, eHumanNode, CtdlGetConfigStr("c_humannode"), strlen(CtdlGetConfigStr("c_humannode"))); if (rcplen > 0) { CM_SetField(msg, eRecipient, recipient, rcplen); @@ -3552,7 +3553,7 @@ struct CtdlMessage *CtdlMakeMessageLen( } else { StrBuf *MsgBody; - MsgBody = CtdlReadMessageBodyBuf(HKEY("000"), config.c_maxmsglen, NULL, 0, 0); + MsgBody = CtdlReadMessageBodyBuf(HKEY("000"), CtdlGetConfigLong("c_maxmsglen"), NULL, 0, 0); if (MsgBody != NULL) { CM_SetAsFieldSB(msg, eMesageText, &MsgBody); } @@ -4033,8 +4034,8 @@ void CtdlWriteObject(char *req_room, /* Room to stuff it in */ msg->cm_format_type = 4; CM_SetField(msg, eAuthor, CCC->user.fullname, strlen(CCC->user.fullname)); CM_SetField(msg, eOriginalRoom, req_room, strlen(req_room)); - CM_SetField(msg, eNodeName, CFG_KEY(c_nodename)); - CM_SetField(msg, eHumanNode, CFG_KEY(c_humannode)); + CM_SetField(msg, eNodeName, CtdlGetConfigStr("c_nodename"), strlen(CtdlGetConfigStr("c_nodename"))); + CM_SetField(msg, eHumanNode, CtdlGetConfigStr("c_humannode"), strlen(CtdlGetConfigStr("c_humannode"))); msg->cm_flags = flags; CM_SetAsFieldSB(msg, eMesageText, &encoded_message); diff --git a/citadel/room_ops.c b/citadel/room_ops.c index 729846d3e..1c01f9946 100644 --- a/citadel/room_ops.c +++ b/citadel/room_ops.c @@ -1,7 +1,7 @@ /* * Server functions which perform operations on room objects. * - * Copyright (c) 1987-2012 by the citadel.org team + * Copyright (c) 1987-2015 by the citadel.org team * * This program is open source software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 3. @@ -32,7 +32,7 @@ struct floor *floorcache[MAXFLOORS]; int CtdlDoIHavePermissionToReadMessagesInThisRoom(void) { if ( (!(CC->logged_in)) && (!(CC->internal_pgm)) - && (!config.c_guest_logins) + && (!CtdlGetConfigInt("c_guest_logins")) ) { return(om_not_logged_in); } @@ -139,7 +139,7 @@ void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf, is_me = 1; } - if ((is_me) && (config.c_guest_logins) && (!CC->logged_in)) { + if ((is_me) && (CtdlGetConfigInt("c_guest_logins")) && (!CC->logged_in)) { is_guest = 1; } @@ -166,7 +166,7 @@ void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf, } /* Force the properties of the Aide room */ - if (!strcasecmp(roombuf->QRname, config.c_aideroom)) { + if (!strcasecmp(roombuf->QRname, CtdlGetConfigStr("c_aideroom"))) { if (userbuf->axlevel >= AxAideU) { retval = UA_KNOWN | UA_GOTOALLOWED | UA_POSTALLOWED | UA_DELETEALLOWED | UA_REPLYALLOWED; } else { @@ -339,9 +339,9 @@ void room_sanity_check(struct ctdlroom *qrbuf) /* Listing order of 0 is illegal except for base rooms */ if (qrbuf->QRorder == 0) if (!(qrbuf->QRflags & QR_MAILBOX) && - strncasecmp(qrbuf->QRname, config.c_baseroom, ROOMNAMELEN) + strncasecmp(qrbuf->QRname, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN) && - strncasecmp(qrbuf->QRname, config.c_aideroom, ROOMNAMELEN)) + strncasecmp(qrbuf->QRname, CtdlGetConfigStr("c_aideroom"), ROOMNAMELEN)) qrbuf->QRorder = 64; } @@ -819,7 +819,7 @@ void CtdlUserGoto(char *where, int display_result, int transiently, /* Know the room ... but not if it's the page log room, or if the * caller specified that we're only entering this room transiently. */ - if ((strcasecmp(CCC->room.QRname, config.c_logpages)) + if ((strcasecmp(CCC->room.QRname, CtdlGetConfigStr("c_logpages"))) && (transiently == 0) ) { vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT; vbuf.v_flags = vbuf.v_flags | V_ACCESS; @@ -945,7 +945,7 @@ void CtdlUserGoto(char *where, int display_result, int transiently, */ void convert_room_name_macros(char *towhere, size_t maxlen) { if (!strcasecmp(towhere, "_BASEROOM_")) { - safestrncpy(towhere, config.c_baseroom, maxlen); + safestrncpy(towhere, CtdlGetConfigStr("c_baseroom"), maxlen); } else if (!strcasecmp(towhere, "_MAIL_")) { safestrncpy(towhere, MAILROOM, maxlen); @@ -957,7 +957,7 @@ void convert_room_name_macros(char *towhere, size_t maxlen) { safestrncpy(towhere, USERDRAFTROOM, maxlen); } else if (!strcasecmp(towhere, "_BITBUCKET_")) { - safestrncpy(towhere, config.c_twitroom, maxlen); + safestrncpy(towhere, CtdlGetConfigStr("c_twitroom"), maxlen); } else if (!strcasecmp(towhere, "_CALENDAR_")) { safestrncpy(towhere, USERCALENDARROOM, maxlen); @@ -1039,8 +1039,8 @@ int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) { } /* Reject change of floor for baseroom/aideroom */ - if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN) || - !strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) { + if (!strncasecmp(old_name, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN) || + !strncasecmp(old_name, CtdlGetConfigStr("c_aideroom"), ROOMNAMELEN)) { new_floor = 0; } @@ -1055,12 +1055,12 @@ int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) { begin_critical_section(S_CONFIG); /* If baseroom/aideroom name changes, update config */ - if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN)) { - safestrncpy(config.c_baseroom, new_name, ROOMNAMELEN); + if (!strncasecmp(old_name, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN)) { + safestrncpy(CtdlGetConfigStr("c_baseroom"), new_name, ROOMNAMELEN); put_config(); } - if (!strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) { - safestrncpy(config.c_aideroom, new_name, ROOMNAMELEN); + if (!strncasecmp(old_name, CtdlGetConfigStr("c_aideroom"), ROOMNAMELEN)) { + safestrncpy(CtdlGetConfigStr("c_aideroom"), new_name, ROOMNAMELEN); put_config(); } diff --git a/citadel/threads.c b/citadel/threads.c index 228a5b0aa..5cb70334c 100644 --- a/citadel/threads.c +++ b/citadel/threads.c @@ -1,7 +1,7 @@ /* * Thread handling stuff for Citadel server * - * Copyright (c) 1987-2011 by the citadel.org team + * Copyright (c) 1987-2015 by the citadel.org team * * This program is open source software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 3. @@ -19,6 +19,7 @@ #include "modules_init.h" #include "serv_extensions.h" #include "ctdl_module.h" +#include "config.h" #include "context.h" #include "threads.h" @@ -171,7 +172,7 @@ void go_threading(void) * they are all in use. */ while (!server_shutting_down) { - if ((active_workers == num_workers) && (num_workers < config.c_max_workers)) { + if ((active_workers == num_workers) && (num_workers < CtdlGetConfigInt("c_max_workers"))) { CtdlThreadCreate(worker_thread); } usleep(1000000); -- 2.30.2