more moving to new logging standard
[citadel.git] / citadel / modules / ctdlproto / serv_rooms.c
index fa3d23ac43aac6fb4e52520c962627d3e2323eaf..10ddfc1f3ff87a9923d41de8703b8e308ff7e32a 100644 (file)
@@ -1,7 +1,7 @@
 /* 
  * Server functions which perform operations on room objects.
  *
- * Copyright (c) 1987-2015 by the citadel.org team
+ * Copyright (c) 1987-2017 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.
@@ -341,7 +341,7 @@ void cmd_goto(char *gargs)
                                   ((ra & UA_KNOWN) == 0) &&
                                   (CCC->user.axlevel < AxAideU)
                                   ) {
-                               CTDLM_syslog(LOG_DEBUG, "Failed to acquire private room");
+                               syslog(LOG_DEBUG, "rooms: failed to acquire private room");
                        } else {
                                memcpy(&CCC->room, &QRscratch,
                                        sizeof(struct ctdlroom));
@@ -708,29 +708,20 @@ void cmd_seta(char *new_ra)
 }
 
 /* 
- * retrieve info file for this room
+ * Retrieve info file for this room (this ought to be upgraded to handle non-plain-text)
  */
-void cmd_rinf(char *gargs)
+void cmd_rinf(char *argbuf)
 {
-       char filename[PATH_MAX];
-       char buf[SIZ];
-       FILE *info_fp;
-
-       assoc_file_name(filename, sizeof filename, &CC->room, ctdl_info_dir);
-       info_fp = fopen(filename, "r");
-
-       if (info_fp == NULL) {
-               cprintf("%d No info file.\n", ERROR + FILE_NOT_FOUND);
-               return;
+       struct CtdlMessage *msg = CtdlFetchMessage(CC->room.msgnum_info, 1, 1);
+       if (msg != NULL) {
+               cprintf("%d Info:\n", LISTING_FOLLOWS);
+               CtdlOutputPreLoadedMsg(msg, MT_CITADEL, HEADERS_NONE, 0, 0, 0);
+               CM_Free(msg);
+               cprintf("000\n");
        }
-       cprintf("%d Info:\n", LISTING_FOLLOWS);
-       while (fgets(buf, sizeof buf, info_fp) != NULL) {
-               if (!IsEmptyStr(buf))
-                       buf[strlen(buf) - 1] = 0;
-               cprintf("%s\n", buf);
+       else {
+               cprintf("%d No info file.\n", ERROR + FILE_NOT_FOUND);
        }
-       cprintf("000\n");
-       fclose(info_fp);
 }
 
 
@@ -895,14 +886,13 @@ void cmd_cre8(char *args)
 }
 
 
-
+/*
+ * Upload the room banner text for this room.
+ * This should be amended to handle content types other than plain text.
+ */
 void cmd_einf(char *ok)
 {                              /* enter info file for current room */
-       struct CitContext *CCC = CC;
-       FILE *fp;
-       char infofilename[SIZ];
        char buf[SIZ];
-
        unbuffer_output();
 
        if (CtdlAccessCheck(ac_room_aide)) return;
@@ -911,27 +901,27 @@ void cmd_einf(char *ok)
                cprintf("%d Ok.\n", CIT_OK);
                return;
        }
-       assoc_file_name(infofilename, sizeof infofilename, &CCC->room, ctdl_info_dir);
-       CTDL_syslog(LOG_DEBUG, "opening %s", infofilename);
-       fp = fopen(infofilename, "w");
-       CTDLM_syslog(LOG_DEBUG, "checking");
-       if (fp == NULL) {
-               cprintf("%d Cannot open %s: %s\n",
-                 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
-               return;
+
+       StrBuf *NewBanner = NewStrBufPlain("Content-type: text/plain; charset=UTF-8\nContent-transfer-encoding: 8bit\n\n", -1);
+
+       cprintf("%d Transmit new banner in plain text now.\n", SEND_LISTING);
+       while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) {
+               StrBufAppendBufPlain(NewBanner, buf, -1, 0);
+               StrBufAppendBufPlain(NewBanner, HKEY("\n"), 0);
        }
-       cprintf("%d Send info...\n", SEND_LISTING);
-
-       do {
-               client_getln(buf, sizeof buf);
-               if (strcmp(buf, "000"))
-                       fprintf(fp, "%s\n", buf);
-       } while (strcmp(buf, "000"));
-       fclose(fp);
-
-       /* now update the room index so people will see our new info */
-       CtdlGetRoomLock(&CCC->room, CCC->room.QRname);          /* lock so no one steps on us */
-       CtdlPutRoomLock(&CCC->room);
+
+       // We have read the new banner from the user , now save it
+       long new_msgnum = quickie_message("Citadel", NULL, NULL, SYSCONFIGROOM, ChrPtr(NewBanner), FMT_RFC822, "Banner submitted with EINF command");
+       FreeStrBuf(&NewBanner);
+
+       // Update the room record with a pointer to our new banner
+       CtdlGetRoomLock(&CC->room, CC->room.QRname);
+       long old_msgnum = CC->room.msgnum_info;
+       CC->room.msgnum_info = new_msgnum;
+       CtdlPutRoomLock(&CC->room);
+
+       // Delete the old one
+       CtdlDeleteMessages(SYSCONFIGROOM, &old_msgnum, 1, "");
 }