RINF command migrated to new data format
[citadel.git] / citadel / modules / ctdlproto / serv_rooms.c
index cac7758f4ad255b20b996697334a4dee9fb8ff44..09fb30061426e361b8d814540c0be3cf4243f358 100644 (file)
@@ -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.
  * GNU General Public License for more details.
  */
 
-#include "sysdep.h"
-#include <stdlib.h>
-#include <unistd.h>
 #include <stdio.h>
-#include <sys/stat.h>
-#include <ctype.h>
-#include <string.h>
 #include <dirent.h>    /* for cmd_rdir to read contents of the directory */
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
-
-#include <limits.h>
-#include <errno.h>
-#include "citadel.h"
 #include <libcitadel.h>
-#include "server.h"
-#include "database.h"
-#include "config.h"
-#include "room_ops.h"
-#include "sysdep_decls.h"
-#include "support.h"
-#include "msgbase.h"
-#include "citserver.h"
-#include "control.h"
-#include "citadel_dirs.h"
-#include "threads.h"
 
+#include "citserver.h"
 #include "ctdl_module.h"
-#include "user_ops.h"
+#include "room_ops.h"
+#include "config.h"
 
 /*
  * Back-back-end for all room listing commands
@@ -296,6 +266,7 @@ void cmd_lzrm(char *argbuf)
  */
 void cmd_goto(char *gargs)
 {
+       struct CitContext *CCC = CC;
        struct ctdlroom QRscratch;
        int c;
        int ok = 0;
@@ -311,7 +282,7 @@ void cmd_goto(char *gargs)
        extract_token(password, gargs, 1, '|', sizeof password);
        transiently = extract_int(gargs, 2);
 
-       CtdlGetUser(&CC->user, CC->curr_user);
+       CtdlGetUser(&CCC->user, CCC->curr_user);
 
        /*
         * Handle some of the macro named rooms
@@ -324,7 +295,7 @@ void cmd_goto(char *gargs)
        /* Then try a mailbox name match */
        if (c != 0) {
                CtdlMailboxName(augmented_roomname, sizeof augmented_roomname,
-                           &CC->user, towhere);
+                           &CCC->user, towhere);
                c = CtdlGetRoom(&QRscratch, augmented_roomname);
                if (c == 0)
                        safestrncpy(towhere, augmented_roomname, sizeof towhere);
@@ -334,15 +305,15 @@ void cmd_goto(char *gargs)
        if (c == 0) {
 
                /* Let internal programs go directly to any room. */
-               if (CC->internal_pgm) {
-                       memcpy(&CC->room, &QRscratch,
+               if (CCC->internal_pgm) {
+                       memcpy(&CCC->room, &QRscratch,
                                sizeof(struct ctdlroom));
-                       CtdlUserGoto(NULL, 1, transiently, NULL, NULL);
+                       CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
                        return;
                }
 
                /* See if there is an existing user/room relationship */
-               CtdlRoomAccess(&QRscratch, &CC->user, &ra, NULL);
+               CtdlRoomAccess(&QRscratch, &CCC->user, &ra, NULL);
 
                /* normal clients have to pass through security */
                if (ra & UA_GOTOALLOWED) {
@@ -352,14 +323,14 @@ void cmd_goto(char *gargs)
                if (ok == 1) {
                        if ((QRscratch.QRflags & QR_MAILBOX) &&
                            ((ra & UA_GOTOALLOWED))) {
-                               memcpy(&CC->room, &QRscratch,
+                               memcpy(&CCC->room, &QRscratch,
                                        sizeof(struct ctdlroom));
-                               CtdlUserGoto(NULL, 1, transiently, NULL, NULL);
+                               CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
                                return;
                        } else if ((QRscratch.QRflags & QR_PASSWORDED) &&
                            ((ra & UA_KNOWN) == 0) &&
                            (strcasecmp(QRscratch.QRpasswd, password)) &&
-                           (CC->user.axlevel < AxAideU)
+                           (CCC->user.axlevel < AxAideU)
                            ) {
                                cprintf("%d wrong or missing passwd\n",
                                        ERROR + PASSWORD_REQUIRED);
@@ -368,13 +339,13 @@ void cmd_goto(char *gargs)
                                   ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
                                   ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
                                   ((ra & UA_KNOWN) == 0) &&
-                                  (CC->user.axlevel < AxAideU)
+                                  (CCC->user.axlevel < AxAideU)
                                   ) {
-                               syslog(LOG_DEBUG, "Failed to acquire private room\n");
+                               CTDLM_syslog(LOG_DEBUG, "Failed to acquire private room");
                        } else {
-                               memcpy(&CC->room, &QRscratch,
+                               memcpy(&CCC->room, &QRscratch,
                                        sizeof(struct ctdlroom));
-                               CtdlUserGoto(NULL, 1, transiently, NULL, NULL);
+                               CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL);
                                return;
                        }
                }
@@ -447,7 +418,7 @@ void cmd_rdir(char *cmdbuf)
                cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
                return;
        }
-       cprintf("%d %s|%s/%s\n", LISTING_FOLLOWS, config.c_fqdn, ctdl_file_dir, CC->room.QRdirname);
+       cprintf("%d %s|%s/%s\n", LISTING_FOLLOWS, CtdlGetConfigStr("c_fqdn"), ctdl_file_dir, CC->room.QRdirname);
        
        snprintf(buf, sizeof buf, "%s/%s/filedir", ctdl_file_dir, CC->room.QRdirname);
        fd = fopen(buf, "r");
@@ -458,7 +429,7 @@ void cmd_rdir(char *cmdbuf)
                if (strcasecmp(filedir_entry->d_name, "filedir") && filedir_entry->d_name[0] != '.')
                {
 #ifdef _DIRENT_HAVE_D_NAMELEN
-                       d_namelen = filedir_entry->d_namelen;
+                       d_namelen = filedir_entry->d_namlen;
 #else
                        d_namelen = strlen(filedir_entry->d_name);
 #endif
@@ -626,8 +597,7 @@ void cmd_setr(char *args)
                CC->room.QRflags |= QR_PRIVATE;
 
        /* Some changes can't apply to BASEROOM */
-       if (!strncasecmp(CC->room.QRname, config.c_baseroom,
-                        ROOMNAMELEN)) {
+       if (!strncasecmp(CC->room.QRname, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN)) {
                CC->room.QRorder = 0;
                CC->room.QRpasswd[0] = '\0';
                CC->room.QRflags &= ~(QR_PRIVATE & QR_PASSWORDED &
@@ -650,8 +620,7 @@ void cmd_setr(char *args)
                }
        }
        /* Some changes can't apply to AIDEROOM */
-       if (!strncasecmp(CC->room.QRname, config.c_baseroom,
-                        ROOMNAMELEN)) {
+       if (!strncasecmp(CC->room.QRname, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN)) {
                CC->room.QRorder = 0;
                CC->room.QRflags &= ~QR_MAILBOX;
                CC->room.QRflags |= QR_PERMANENT;
@@ -739,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);
 }
 
 
@@ -792,7 +752,7 @@ void cmd_kill(char *argbuf)
                CtdlScheduleRoomForDeletion(&CC->room);
 
                /* Return to the Lobby */
-               CtdlUserGoto(config.c_baseroom, 0, 0, NULL, NULL);
+               CtdlUserGoto(CtdlGetConfigStr("c_baseroom"), 0, 0, NULL, NULL, NULL, NULL);
 
                /* tell the world what we did */
                snprintf(msg, sizeof msg, "The room \"%s\" has been deleted by %s.\n",
@@ -862,7 +822,7 @@ void cmd_cre8(char *args)
 
        if (CtdlAccessCheck(ac_logged_in)) return;
 
-       if (CC->user.axlevel < config.c_createax && !CC->internal_pgm) {
+       if (CC->user.axlevel < CtdlGetConfigInt("c_createax") && !CC->internal_pgm) {
                cprintf("%d You need higher access to create rooms.\n",
                        ERROR + HIGHER_ACCESS_REQUIRED);
                return;
@@ -929,6 +889,7 @@ void cmd_cre8(char *args)
 
 void cmd_einf(char *ok)
 {                              /* enter info file for current room */
+       struct CitContext *CCC = CC;
        FILE *fp;
        char infofilename[SIZ];
        char buf[SIZ];
@@ -941,10 +902,10 @@ void cmd_einf(char *ok)
                cprintf("%d Ok.\n", CIT_OK);
                return;
        }
-       assoc_file_name(infofilename, sizeof infofilename, &CC->room, ctdl_info_dir);
-       syslog(LOG_DEBUG, "opening\n");
+       assoc_file_name(infofilename, sizeof infofilename, &CCC->room, ctdl_info_dir);
+       CTDL_syslog(LOG_DEBUG, "opening %s", infofilename);
        fp = fopen(infofilename, "w");
-       syslog(LOG_DEBUG, "checking\n");
+       CTDLM_syslog(LOG_DEBUG, "checking");
        if (fp == NULL) {
                cprintf("%d Cannot open %s: %s\n",
                  ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
@@ -960,9 +921,8 @@ void cmd_einf(char *ok)
        fclose(fp);
 
        /* now update the room index so people will see our new info */
-       CtdlGetRoomLock(&CC->room, CC->room.QRname);            /* lock so no one steps on us */
-       CC->room.QRinfo = CC->room.QRhighest + 1L;
-       CtdlPutRoomLock(&CC->room);
+       CtdlGetRoomLock(&CCC->room, CCC->room.QRname);          /* lock so no one steps on us */
+       CtdlPutRoomLock(&CCC->room);
 }