* Get/save arbitrary configs
authorArt Cancro <ajc@citadel.org>
Sun, 9 Jan 2000 05:12:27 +0000 (05:12 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 9 Jan 2000 05:12:27 +0000 (05:12 +0000)
citadel/citadel.h
citadel/citserver.c
citadel/control.c
citadel/msgbase.c
citadel/msgbase.h
citadel/serv_icq.c
citadel/serv_upgrade.c
citadel/serv_vcard.c
citadel/server.h
citadel/sysconfig.h

index 7c8530945597fc97eba14886add5e617bf4e9635..763beeee22d79d1404ae1afd63cd0515560ad5a9 100644 (file)
@@ -239,11 +239,6 @@ struct floor {
 #define GF_ZAP         2               /* <;Z>ap floor mode */
 
 
-#define BASEROOM       "Lobby"
-#define MAILROOM       "Mail"
-#define AIDEROOM       "Aide"
-#define CONFIGROOM     "My Citadel Config"
-
 #define SPOOLMIME      "application/x-citadel-delivery-list"
 
 /*
index c61944d938ef597058d291965776d7a3cf5d7217..06ffc25b0e0434c9c14014f37e701276bf7545cb 100644 (file)
@@ -55,9 +55,10 @@ void master_startup(void) {
        check_ref_counts();
 
        lprintf(7, "Creating base rooms (if necessary)\n");
-       create_room(BASEROOM, 0, "", 0);
-       create_room(AIDEROOM, 4, "", 0);
-       create_room(config.c_twitroom, 0, "", 0);
+       create_room(BASEROOM,           0, "", 0);
+       create_room(AIDEROOM,           4, "", 0);
+       create_room(SYSCONFIGROOM,      4, "", 0);
+       create_room(config.c_twitroom,  0, "", 0);
        }
 
 /*
index 74e2edea994d0d43f27946e2d0be8826571d8bbd..2d2c9533400d93600cfa19f2b7045354b2ba9d98 100644 (file)
@@ -125,6 +125,8 @@ void cmd_conf(char *argbuf) {
        char cmd[256];
        char buf[256];
        int a;
+       char *confptr;
+       char confname[256];
 
        if (!(CC->logged_in)) {
                cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
@@ -255,8 +257,33 @@ void cmd_conf(char *argbuf) {
                        create_room(config.c_logpages, 4, "", 0);
                }
 
+       else if (!strcasecmp(cmd, "GETSYS")) {
+               extract(confname, argbuf, 1);
+               confptr = CtdlGetSysConfig(confname);
+               if (confptr != NULL) {
+                       cprintf("%d %s\n", LISTING_FOLLOWS, confname);
+                       client_write(confptr, strlen(confptr));
+                       if (confptr[strlen(confptr)-1] != 10)
+                               client_write("\n", 1);
+                       cprintf("000\n");
+                       phree(confptr);
+               }
+               else {
+                       cprintf("%d No such configuration.\n",
+                               ERROR+ILLEGAL_VALUE);
+               }
+       }
+
+       else if (!strcasecmp(cmd, "PUTSYS")) {
+               extract(confname, argbuf, 1);
+               cprintf("%d %s\n", SEND_LISTING, confname);
+               confptr = CtdlReadMessageBody("000", config.c_maxmsglen, NULL);
+               CtdlPutSysConfig(confname, confptr);
+               phree(confptr);
+       }
+
        else {
-               cprintf("%d The only valid options are GET and SET.\n",
+               cprintf("%d Illegal option(s) specified.\n",
                        ERROR+ILLEGAL_VALUE);
                }
        }
index 48515e8719e7b310837bb71f8aa326cc166f9051..1bb075bd6892699740ddaa501cc2320a00a4b78d 100644 (file)
@@ -32,6 +32,7 @@
 #define msg_repl ((struct repl *)CtdlGetUserData(SYM_REPL))
 
 extern struct config config;
+long config_msgnum;
 
 char *msgkeys[] = {
        "", "", "", "", "", "", "", "", 
@@ -2361,3 +2362,80 @@ void CtdlWriteObject(char *req_room,             /* Room to stuff it in */
        CtdlSaveMsg(msg, "", roomname, MES_LOCAL, 1);
        CtdlFreeMessage(msg);
 }
+
+
+
+
+
+
+void CtdlGetSysConfigBackend(long msgnum) {
+       config_msgnum = msgnum;
+}
+
+
+char *CtdlGetSysConfig(char *sysconfname) {
+       char hold_rm[ROOMNAMELEN];
+       long msgnum;
+       char *conf;
+       struct CtdlMessage *msg;
+       char buf[256];
+       
+       strcpy(hold_rm, CC->quickroom.QRname);
+       if (getroom(&CC->quickroom, SYSCONFIGROOM) != 0) {
+               getroom(&CC->quickroom, hold_rm);
+               return NULL;
+       }
+
+
+       /* We want the last (and probably only) config in this room */
+       begin_critical_section(S_CONFIG);
+       config_msgnum = (-1L);
+       CtdlForEachMessage(MSGS_LAST, 1, sysconfname, NULL,
+               CtdlGetSysConfigBackend);
+       msgnum = config_msgnum;
+       end_critical_section(S_CONFIG);
+
+       if (msgnum < 0L) {
+               conf = NULL;
+       }
+       else {
+               msg = CtdlFetchMessage(msgnum);
+               if (msg != NULL) {
+                       conf = strdoop(msg->cm_fields['M']);
+                       CtdlFreeMessage(msg);
+               }
+               else {
+                       conf = NULL;
+               }
+       }
+
+       getroom(&CC->quickroom, hold_rm);
+
+       if (conf != NULL) do {
+               extract_token(buf, conf, 0, '\n');
+               strcpy(conf, &conf[strlen(buf)+1]);
+       } while ( (strlen(conf)>0) && (strlen(buf)>0) );
+
+       return(conf);
+}
+
+void CtdlPutSysConfig(char *sysconfname, char *sysconfdata) {
+       char temp[PATH_MAX];
+       FILE *fp;
+
+       strcpy(temp, tmpnam(NULL));
+
+       fp = fopen(temp, "w");
+       if (fp == NULL) return;
+       fprintf(fp, "Content-type: %s\n\n", sysconfname);
+       fprintf(fp, "%s", sysconfdata);
+       fclose(fp);
+
+       /* this handy API function does all the work for us */
+       CtdlWriteObject(SYSCONFIGROOM, sysconfname, temp,
+               &CC->usersupp, 0, 1, 0);
+
+       unlink(temp);
+}
+
+
index 4cfb0a1a366ca12ce29665d3262caf31cd76931a..9932911ea9ccb278bc669a3b1e57d0235f929feb 100644 (file)
@@ -71,3 +71,5 @@ int is_valid_message(struct CtdlMessage *);
 int ReplicationChecks(struct CtdlMessage *);
 int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int flags);
 char *CtdlReadMessageBody(char *terminator, size_t maxlen, char *exist);
+char *CtdlGetSysConfig(char *sysconfname);
+void CtdlPutSysConfig(char *sysconfname, char *sysconfdata);
index 30f3dff55809243dfabc47f8173d36cda19820f8..0af084e111e5f597f10964e651e1c25737e4fb30 100644 (file)
@@ -1788,7 +1788,7 @@ void CtdlICQ_Read_Config(void) {
        char icq_rm[ROOMNAMELEN];
        
        strcpy(hold_rm, CC->quickroom.QRname);
-       MailboxName(icq_rm, &CC->usersupp, CONFIGROOM);
+       MailboxName(icq_rm, &CC->usersupp, USERCONFIGROOM);
        strcpy(ThisICQ->icq_config, "");
 
        if (getroom(&CC->quickroom, icq_rm) != 0) {
@@ -1822,7 +1822,7 @@ void CtdlICQ_Write_Config(void) {
        fclose(fp);
 
        /* this handy API function does all the work for us */
-       CtdlWriteObject(CONFIGROOM, ICQMIME, temp, &CC->usersupp, 0, 1, 0);
+       CtdlWriteObject(USERCONFIGROOM, ICQMIME, temp, &CC->usersupp, 0, 1, 0);
 
        unlink(temp);
 }
@@ -1852,7 +1852,7 @@ void CtdlICQ_Write_CL(void) {
        fclose(fp);
 
        /* this handy API function does all the work for us */
-       CtdlWriteObject(CONFIGROOM, ICQCLMIME, temp, &CC->usersupp, 0, 1, 0);
+       CtdlWriteObject(USERCONFIGROOM, ICQCLMIME, temp, &CC->usersupp, 0, 1, 0);
 
        unlink(temp);
 }
@@ -1913,7 +1913,7 @@ void CtdlICQ_Read_CL(void) {
        char icq_rm[ROOMNAMELEN];
        
        strcpy(hold_rm, CC->quickroom.QRname);
-       MailboxName(icq_rm, &CC->usersupp, CONFIGROOM);
+       MailboxName(icq_rm, &CC->usersupp, USERCONFIGROOM);
        strcpy(ThisICQ->icq_config, "");
 
        if (getroom(&CC->quickroom, icq_rm) != 0) {
index 1f31a3b59025db76a4c9a8c25ff30b9a88f63575..7562c5f66c5a0ad67eff37d33f07b3e1a995ee68 100644 (file)
@@ -96,7 +96,7 @@ void do_pre555_usersupp_upgrade(void) {
                fwrite(vcard, strlen(vcard)+1, 1, tp);
                fclose(tp);
 
-               CtdlWriteObject(CONFIGROOM, "text/x-vcard",
+               CtdlWriteObject(USERCONFIGROOM, "text/x-vcard",
                        tempfilename, &newus, 0, 1, CM_SKIP_HOOKS);
                unlink(tempfilename);
            }
index 1e906ba22b0ffe051891e2291d2f229e30552eba..7fb5fd23d7fc55f4f92d2a141b0252956c28f36c 100644 (file)
@@ -67,7 +67,7 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
        /* If this isn't the configuration room, or if this isn't a MIME
         * message, don't bother.
         */
-       if (strcasecmp(msg->cm_fields['O'], CONFIGROOM)) return(0);
+       if (strcasecmp(msg->cm_fields['O'], USERCONFIGROOM)) return(0);
        if (msg->cm_format_type != 4) return(0);
 
        ptr = msg->cm_fields['M'];
@@ -90,7 +90,7 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
                         * to make changes to another user's vCard instead of
                         * assuming that it's always the user saving his own.
                         */
-                       MailboxName(config_rm, &CC->usersupp, CONFIGROOM);
+                       MailboxName(config_rm, &CC->usersupp, USERCONFIGROOM);
                        CtdlDeleteMessages(config_rm, 0L, "text/x-vcard");
 
                        /* Set the Extended-ID to a standardized one so the
@@ -134,7 +134,7 @@ int vcard_upload_aftersave(struct CtdlMessage *msg) {
        /* If this isn't the configuration room, or if this isn't a MIME
         * message, don't bother.
         */
-       if (strcasecmp(msg->cm_fields['O'], CONFIGROOM)) return(0);
+       if (strcasecmp(msg->cm_fields['O'], USERCONFIGROOM)) return(0);
        if (msg->cm_format_type != 4) return(0);
 
        ptr = msg->cm_fields['M'];
@@ -185,7 +185,7 @@ struct vCard *vcard_get_user(struct usersupp *u) {
        struct vCard *v;
 
         strcpy(hold_rm, CC->quickroom.QRname); /* save current room */
-        MailboxName(config_rm, u, CONFIGROOM);
+        MailboxName(config_rm, u, USERCONFIGROOM);
 
         if (getroom(&CC->quickroom, config_rm) != 0) {
                 getroom(&CC->quickroom, hold_rm);
@@ -239,7 +239,7 @@ void vcard_write_user(struct usersupp *u, struct vCard *v) {
         * have to, because the vcard_upload_beforesave() hook above
         * is going to notice what we're trying to do, and delete the old vCard.
         */
-        CtdlWriteObject(CONFIGROOM,    /* which room */
+        CtdlWriteObject(USERCONFIGROOM,        /* which room */
                        "text/x-vcard", /* MIME type */
                        temp,           /* temp file */
                        u,              /* which user */
index 0c2083e53780999c02787950acc3188104f3e408..26e8020cea9eee3df1fd061dd8b2cd7677418186 100644 (file)
@@ -165,6 +165,7 @@ enum {
        S_NETDB,
        S_SUPPMSGMAIN,
        S_I_WANNA_SELECT,
+       S_CONFIG,
        MAX_SEMAPHORES
 };
 
index f654a63fdef05a7eec33c3161a3a550d69b699f8..3ce4597f87e514ffb5fca948d6931d33a2f09ebd 100644 (file)
  */
 #define POP3_PORT              1110
 #define SMTP_PORT              2525
+
+
+/*
+ * The names of rooms which are automatically created by the system
+ */
+#define BASEROOM               "Lobby"
+#define MAILROOM               "Mail"
+#define AIDEROOM               "Aide"
+#define USERCONFIGROOM         "My Citadel Config"
+#define SYSCONFIGROOM          "Local System Configuration"
 #define SMTP_SPOOLOUT_ROOM     "__CitadelSMTPspoolout__"