Did away with lprintf all together now its called CtdlLogPrintf()
[citadel.git] / citadel / room_ops.c
index 4a5ed25da095a2e066b080d9ec0afc6aecb5b01a..e3720e3cc948490be0f52adf888886c71c0a2805 100644 (file)
@@ -40,6 +40,7 @@
 #include "citserver.h"
 #include "control.h"
 #include "citadel_dirs.h"
+#include "threads.h"
 
 struct floor *floorcache[MAXFLOORS];
 
@@ -932,7 +933,7 @@ void usergoto(char *where, int display_result, int transiently,
 
        if (retmsgs != NULL) *retmsgs = total_messages;
        if (retnew != NULL) *retnew = new_messages;
-       lprintf(CTDL_DEBUG, "<%s> %d new of %d total messages\n",
+       CtdlLogPrintf(CTDL_DEBUG, "<%s> %d new of %d total messages\n",
                CC->room.QRname,
                new_messages, total_messages
        );
@@ -1072,7 +1073,7 @@ void cmd_goto(char *gargs)
                                   ((ra & UA_KNOWN) == 0) &&
                                   (CC->user.axlevel < 6)
                                   ) {
-                               lprintf(CTDL_DEBUG, "Failed to acquire private room\n");
+                               CtdlLogPrintf(CTDL_DEBUG, "Failed to acquire private room\n");
                        } else {
                                memcpy(&CC->room, &QRscratch,
                                        sizeof(struct ctdlroom));
@@ -1122,6 +1123,8 @@ void cmd_rdir(void)
        struct dirent *filedir_entry;
        int d_namelen;
        char buf2[SIZ];
+       char mimebuf[64];
+       long len;
        
        if (CtdlAccessCheck(ac_logged_in)) return;
        
@@ -1138,48 +1141,62 @@ void cmd_rdir(void)
                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);
-       
+
        snprintf(buf, sizeof buf, "%s/%s", ctdl_file_dir, CC->room.QRdirname);
        filedir = opendir (buf);
-       if (filedir)
+       
+       if (filedir == NULL) {
+               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);
+       
+       snprintf(buf, sizeof buf, "%s/%s/filedir", ctdl_file_dir, CC->room.QRdirname);
+       fd = fopen(buf, "r");
+       if (fd == NULL)
+               fd = fopen("/dev/null", "r");
+       while ((filedir_entry = readdir(filedir)))
        {
-               snprintf(buf, sizeof buf, "%s/%s/filedir", ctdl_file_dir, CC->room.QRdirname);
-               fd = fopen(buf, "r");
-               if (fd == NULL)
-                       fd = fopen("/dev/null", "r");
-               while ((filedir_entry = readdir(filedir)))
+               if (strcasecmp(filedir_entry->d_name, "filedir") && filedir_entry->d_name[0] != '.')
                {
-                       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_namelen;
 #else
-                               d_namelen = strlen(filedir_entry->d_name);
+                       d_namelen = strlen(filedir_entry->d_name);
 #endif
-                               snprintf(buf, sizeof buf, "%s/%s/%s", ctdl_file_dir, CC->room.QRdirname, filedir_entry->d_name);
-                               stat(buf, &statbuf);    /* stat the file */
-                               if (!(statbuf.st_mode & S_IFREG))
-                               {
-                                       snprintf(buf2, sizeof buf2, "Command RDIR found something that is not a useable file. It should be cleaned up.\n RDIR found this non regular file:\n%s\n", buf);
-                                       aide_message(buf2, "RDIR found bad file");
-                                       continue;       /* not a useable file type so don't show it */
-                               }
-                               safestrncpy(comment, "", sizeof comment);
-                               fseek(fd, 0L, 0);       /* rewind descriptions file */
-                               /* Get the description from the descriptions file */
-                               while ((fgets(buf, sizeof buf, fd) != NULL) && (IsEmptyStr(comment))) 
-                               {
-                                       buf[strlen(buf) - 1] = 0;
-                                       if ((!strncasecmp(buf, filedir_entry->d_name, d_namelen)) && (buf[d_namelen] == ' '))
-                                               safestrncpy(comment, &buf[d_namelen + 1], sizeof comment);
-                               }
-                               cprintf("%s|%ld|%s\n", filedir_entry->d_name, (long)statbuf.st_size, comment);
+                       snprintf(buf, sizeof buf, "%s/%s/%s", ctdl_file_dir, CC->room.QRdirname, filedir_entry->d_name);
+                       stat(buf, &statbuf);    /* stat the file */
+                       if (!(statbuf.st_mode & S_IFREG))
+                       {
+                               snprintf(buf2, sizeof buf2, "Command RDIR found something that is not a useable file. It should be cleaned up.\n RDIR found this non regular file:\n%s\n", buf);
+                               aide_message(buf2, "RDIR found bad file");
+                               continue;       /* not a useable file type so don't show it */
+                       }
+                       safestrncpy(comment, "", sizeof comment);
+                       fseek(fd, 0L, 0);       /* rewind descriptions file */
+                       /* Get the description from the descriptions file */
+                       while ((fgets(buf, sizeof buf, fd) != NULL) && (IsEmptyStr(comment))) 
+                       {
+                               buf[strlen(buf) - 1] = 0;
+                               if ((!strncasecmp(buf, filedir_entry->d_name, d_namelen)) && (buf[d_namelen] == ' '))
+                                       safestrncpy(comment, &buf[d_namelen + 1], sizeof comment);
+                       }
+                       len = extract_token (mimebuf, comment, 0,' ', 64);
+                       if ((len <0) || strchr(mimebuf, '/') == NULL)
+                       {
+                               snprintf (mimebuf, 64, "application/octetstream");
+                               len = 0;
                        }
+                       cprintf("%s|%ld|%s|%s\n", 
+                               filedir_entry->d_name, 
+                               (long)statbuf.st_size, 
+                               mimebuf, 
+                               &comment[len]);
                }
-               fclose(fd);
-               closedir(filedir);
        }
+       fclose(fd);
+       closedir(filedir);
+       
        cprintf("000\n");
 }
 
@@ -1232,7 +1249,7 @@ int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
        long owner = 0L;
        char actual_old_name[ROOMNAMELEN];
 
-       lprintf(CTDL_DEBUG, "CtdlRenameRoom(%s, %s, %d)\n",
+       CtdlLogPrintf(CTDL_DEBUG, "CtdlRenameRoom(%s, %s, %d)\n",
                old_name, new_name, new_floor);
 
        if (new_floor >= 0) {
@@ -1323,11 +1340,11 @@ int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
                lgetfloor(&flbuf, old_floor);
                --flbuf.f_ref_count;
                lputfloor(&flbuf, old_floor);
-               lprintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", old_floor, flbuf.f_ref_count);
+               CtdlLogPrintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", old_floor, flbuf.f_ref_count);
                lgetfloor(&flbuf, new_floor);
                ++flbuf.f_ref_count;
                lputfloor(&flbuf, new_floor);
-               lprintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", new_floor, flbuf.f_ref_count);
+               CtdlLogPrintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", new_floor, flbuf.f_ref_count);
        }
 
        /* ...and everybody say "YATTA!" */     
@@ -1576,7 +1593,7 @@ void schedule_room_for_deletion(struct ctdlroom *qrbuf)
        char old_name[ROOMNAMELEN];
        static int seq = 0;
 
-       lprintf(CTDL_NOTICE, "Scheduling room <%s> for deletion\n",
+       CtdlLogPrintf(CTDL_NOTICE, "Scheduling room <%s> for deletion\n",
                qrbuf->QRname);
 
        safestrncpy(old_name, qrbuf->QRname, sizeof old_name);
@@ -1614,7 +1631,7 @@ void delete_room(struct ctdlroom *qrbuf)
        char filename[100];
        /* TODO: filename magic? does this realy work? */
 
-       lprintf(CTDL_NOTICE, "Deleting room <%s>\n", qrbuf->QRname);
+       CtdlLogPrintf(CTDL_NOTICE, "Deleting room <%s>\n", qrbuf->QRname);
 
        /* Delete the info file */
        assoc_file_name(filename, sizeof filename, qrbuf, ctdl_info_dir);
@@ -1745,11 +1762,11 @@ unsigned create_room(char *new_room_name,
        struct floor flbuf;
        struct visit vbuf;
 
-       lprintf(CTDL_DEBUG, "create_room(name=%s, type=%d, view=%d)\n",
+       CtdlLogPrintf(CTDL_DEBUG, "create_room(name=%s, type=%d, view=%d)\n",
                new_room_name, new_room_type, new_room_view);
 
        if (getroom(&qrbuf, new_room_name) == 0) {
-               lprintf(CTDL_DEBUG, "%s already exists.\n", new_room_name);
+               CtdlLogPrintf(CTDL_DEBUG, "%s already exists.\n", new_room_name);
                return(0);
        }
 
@@ -1957,9 +1974,9 @@ void cmd_einf(char *ok)
                return;
        }
        assoc_file_name(infofilename, sizeof infofilename, &CC->room, ctdl_info_dir);
-       lprintf(CTDL_DEBUG, "opening\n");
+       CtdlLogPrintf(CTDL_DEBUG, "opening\n");
        fp = fopen(infofilename, "w");
-       lprintf(CTDL_DEBUG, "checking\n");
+       CtdlLogPrintf(CTDL_DEBUG, "checking\n");
        if (fp == NULL) {
                cprintf("%d Cannot open %s: %s\n",
                  ERROR + INTERNAL_ERROR, infofilename, strerror(errno));