"Fossies" - the Fresh Open Source Software Archive

Member "citadel/modules/inetcfg/serv_inetcfg.c" (5 Jun 2021, 3397 Bytes) of package /linux/www/citadel.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "serv_inetcfg.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 9.01_vs_902.

    1 /*
    2  * This module handles the loading/saving and maintenance of the
    3  * system's Internet configuration.  It's not an optional component; I
    4  * wrote it as a module merely to keep things as clean and loosely coupled
    5  * as possible.
    6  *
    7  * Copyright (c) 1987-2021 by the citadel.org team
    8  *
    9  * This program is open source software; you can redistribute it and/or modify
   10  * it under the terms of the GNU General Public License version 3.
   11  *
   12  * This program is distributed in the hope that it will be useful,
   13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15  * GNU General Public License for more details.
   16  */
   17 
   18 #include "sysdep.h"
   19 #include <stdlib.h>
   20 #include <unistd.h>
   21 #include <stdio.h>
   22 #include <fcntl.h>
   23 #include <signal.h>
   24 #include <pwd.h>
   25 #include <errno.h>
   26 #include <sys/types.h>
   27 #include <time.h>
   28 #include <sys/wait.h>
   29 #include <string.h>
   30 #include <limits.h>
   31 #include <libcitadel.h>
   32 #include "citadel.h"
   33 #include "server.h"
   34 #include "citserver.h"
   35 #include "support.h"
   36 #include "config.h"
   37 #include "user_ops.h"
   38 #include "database.h"
   39 #include "msgbase.h"
   40 #include "internet_addressing.h"
   41 #include "genstamp.h"
   42 #include "domain.h"
   43 #include "ctdl_module.h"
   44 
   45 
   46 void inetcfg_setTo(struct CtdlMessage *msg) {
   47     char *conf;
   48     char buf[SIZ];
   49     
   50     if (CM_IsEmpty(msg, eMesageText)) return;
   51     conf = strdup(msg->cm_fields[eMesageText]);
   52 
   53     if (conf != NULL) {
   54         do {
   55             extract_token(buf, conf, 0, '\n', sizeof buf);
   56             strcpy(conf, &conf[strlen(buf)+1]);
   57         } while ( (!IsEmptyStr(conf)) && (!IsEmptyStr(buf)) );
   58 
   59         if (inetcfg != NULL) free(inetcfg);
   60         inetcfg = conf;
   61     }
   62 }
   63 
   64 
   65 /*
   66  * This handler detects changes being made to the system's Internet
   67  * configuration.
   68  */
   69 int inetcfg_aftersave(struct CtdlMessage *msg, struct recptypes *recp) {
   70     char *ptr;
   71     int linelen;
   72 
   73     /* If this isn't the configuration room, or if this isn't a MIME
   74      * message, don't bother.
   75      */
   76     if ((msg->cm_fields[eOriginalRoom]) && (strcasecmp(msg->cm_fields[eOriginalRoom], SYSCONFIGROOM))) {
   77         return(0);
   78     }
   79     if (msg->cm_format_type != 4) {
   80         return(0);
   81     }
   82 
   83     ptr = msg->cm_fields[eMesageText];
   84     while (ptr != NULL) {
   85     
   86         linelen = strcspn(ptr, "\n");
   87         if (linelen == 0) {
   88             return(0);  /* end of headers */    
   89         }
   90         
   91         if (!strncasecmp(ptr, "Content-type: ", 14)) {
   92             if (!strncasecmp(&ptr[14], INTERNETCFG, strlen(INTERNETCFG))) {
   93                 inetcfg_setTo(msg); /* changing configs */
   94             }
   95         }
   96 
   97         ptr = strchr((char *)ptr, '\n');
   98         if (ptr != NULL) ++ptr;
   99     }
  100 
  101     return(0);
  102 }
  103 
  104 
  105 void inetcfg_init_backend(long msgnum, void *userdata) {
  106     struct CtdlMessage *msg;
  107 
  108         msg = CtdlFetchMessage(msgnum, 1);
  109         if (msg != NULL) {
  110         inetcfg_setTo(msg);
  111                 CM_Free(msg);
  112     }
  113 }
  114 
  115 
  116 void inetcfg_init(void) {
  117     syslog(LOG_DEBUG, "EVQ: called inetcfg_init()");
  118     if (CtdlGetRoom(&CC->room, SYSCONFIGROOM) != 0) {
  119         return;
  120     }
  121     CtdlForEachMessage(MSGS_LAST, 1, NULL, INTERNETCFG, NULL, inetcfg_init_backend, NULL);
  122 }
  123 
  124 
  125 /*****************************************************************************/
  126 /*                      MODULE INITIALIZATION STUFF                          */
  127 /*****************************************************************************/
  128 
  129 
  130 CTDL_MODULE_INIT(inetcfg)
  131 {
  132     if (!threading)
  133     {
  134         CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);
  135         inetcfg_init();
  136     }
  137     
  138     /* return our module name for the log */
  139     return "inetcfg";
  140 }