* Began (but did not finish) applying GPL3+ declarations to each source file. This...
[citadel.git] / citadel / citadel_ipc.c
index 96d5f1e7917e9b5a70567aa107d1282d9a0185a3..ef902281dd69ae44310bc98799eb5de28abae09a 100644 (file)
@@ -1,4 +1,21 @@
-/* $Id$ */
+/* $Id$ 
+ *
+ * Copyright (c) 1987-2009 by the citadel.org team
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
 
 #include "sysdep.h"
 #if TIME_WITH_SYS_TIME
@@ -80,6 +97,9 @@ static void CtdlIPC_getline(CtdlIPC* ipc, char *buf);
 static void CtdlIPC_putline(CtdlIPC *ipc, const char *buf);
 
 
+
+const char *svn_revision(void);
+
 /*
  * Does nothing.  The server should always return 200.
  */
@@ -142,7 +162,7 @@ int CtdlIPCQuit(CtdlIPC *ipc)
 
 
 /*
- * Asks the server to logout.  Should always return 200, even if no user
+ * Asks the server to log out.  Should always return 200, even if no user
  * was logged in.  The user will not be logged in after this!
  */
 int CtdlIPCLogout(CtdlIPC *ipc)
@@ -367,6 +387,22 @@ int CtdlIPCSetConfig(CtdlIPC *ipc, struct ctdluser *uret, char *cret)
 }
 
 
+/* RENU */
+int CtdlIPCRenameUser(CtdlIPC *ipc, char *oldname, char *newname, char *cret)
+{
+       register int ret;
+       char cmd[256];
+
+       if (!oldname) return -2;
+       if (!newname) return -2;
+       if (!cret) return -2;
+
+       snprintf(cmd, sizeof cmd, "RENU %s|%s", oldname, newname);
+       ret = CtdlIPCGenericCommand(ipc, cmd, NULL, 0, NULL, NULL, cret);
+       return ret;
+}
+
+
 /* GOTO */
 int CtdlIPCGotoRoom(CtdlIPC *ipc, const char *room, const char *passwd,
                struct ctdlipcroom **rret, char *cret)
@@ -516,6 +552,8 @@ int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime,
                                        safestrncpy(mret[0]->node, &aaa[5], SIZ);
                                else if (!strncasecmp(aaa, "rcpt=", 5))
                                        safestrncpy(mret[0]->recipient, &aaa[5], SIZ);
+                               else if (!strncasecmp(aaa, "wefw=", 5))
+                                       safestrncpy(mret[0]->references, &aaa[5], SIZ);
                                else if (!strncasecmp(aaa, "time=", 5))
                                        mret[0]->time = atol(&aaa[5]);
 
@@ -701,6 +739,20 @@ int CtdlIPCServerInfo(CtdlIPC *ipc, char *cret)
                                        break;
                        case 15:        ipc->ServInfo.newuser_disabled = atoi(buf);
                                        break;
+                       case 16:        strcpy(ipc->ServInfo.default_cal_zone, buf);
+                                       break;
+                       case 17:        ipc->ServInfo.load_avg = atof(buf);
+                                       break;
+                       case 18:        ipc->ServInfo.worker_avg = atof(buf);
+                                       break;
+                       case 19:        ipc->ServInfo.thread_count = atoi(buf);
+                                       break;
+                       case 20:        ipc->ServInfo.has_sieve = atoi(buf);
+                                       break;
+                       case 21:        ipc->ServInfo.fulltext_enabled = atoi(buf);
+                                       break;
+                       case 22:        strcpy(ipc->ServInfo.svn_revision, buf);
+                                       break;
                        }
                }
 
@@ -861,17 +913,24 @@ int CtdlIPCSetRoomAide(CtdlIPC *ipc, const char *username, char *cret)
 
 
 /* ENT0 */
-int CtdlIPCPostMessage(CtdlIPC *ipc, int flag, int *subject_required,  const struct ctdlipcmessage *mr, char *cret)
+int CtdlIPCPostMessage(CtdlIPC *ipc, int flag, int *subject_required,  struct ctdlipcmessage *mr, char *cret)
 {
        register int ret;
        char cmd[SIZ];
+       char *ptr;
 
        if (!cret) return -2;
        if (!mr) return -2;
 
+       if (mr->references) {
+               for (ptr=mr->references; *ptr != 0; ++ptr) {
+                       if (*ptr == '|') *ptr = '!';
+               }
+       }
+
        snprintf(cmd, sizeof cmd,
-                       "ENT0 %d|%s|%d|%d|%s|%s", flag, mr->recipient,
-                       mr->anonymous, mr->type, mr->subject, mr->author);
+                       "ENT0 %d|%s|%d|%d|%s|%s||||||%s|", flag, mr->recipient,
+                       mr->anonymous, mr->type, mr->subject, mr->author, mr->references);
        ret = CtdlIPCGenericCommand(ipc, cmd, mr->text, strlen(mr->text), NULL,
                        NULL, cret);
        if ((flag == 0) && (subject_required != NULL)) {
@@ -1160,26 +1219,6 @@ int CtdlIPCMoveFile(CtdlIPC *ipc, const char *filename, const char *destroom, ch
 }
 
 
-/* NETF */
-int CtdlIPCNetSendFile(CtdlIPC *ipc, const char *filename, const char *destnode, char *cret)
-{
-       register int ret;
-       char *aaa;
-
-       if (!cret) return -2;
-       if (!filename) return -2;
-       if (!destnode) return -2;
-
-       aaa = (char *)malloc(strlen(filename) + strlen(destnode) + 7);
-       if (!aaa) return -1;
-
-       sprintf(aaa, "NETF %s|%s", filename, destnode);
-       ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
-       free(aaa);
-       return ret;
-}
-
-
 /* RWHO */
 int CtdlIPCOnlineUsers(CtdlIPC *ipc, char **listing, time_t *stamp, char *cret)
 {
@@ -1326,14 +1365,18 @@ int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf,
 
 
 /* UOPN */
-int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment,
-               const char *path,
+int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment, 
+               const char *path, 
                void (*progress_gauge_callback)
                        (CtdlIPC*, unsigned long, unsigned long),
                char *cret)
 {
        register int ret;
        char *aaa;
+       FILE *uploadFP;
+       char MimeTestBuf[64];
+       const char *MimeType;
+       long len;
 
        if (!cret) return -1;
        if (!save_as) return -1;
@@ -1342,15 +1385,24 @@ int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment,
        if (!*path) return -1;
        if (ipc->uploading) return -1;
 
+       uploadFP = fopen(path, "r");
+       if (!uploadFP) return -2;
+
+       len = fread(&MimeTestBuf[0], 1, 64, uploadFP);
+       rewind (uploadFP);
+       if (len < 0) 
+               return -3;
+
+       MimeType = GuessMimeType(&MimeTestBuf[0], len);
        aaa = (char *)malloc(strlen(save_as) + strlen(comment) + 7);
        if (!aaa) return -1;
 
-       sprintf(aaa, "UOPN %s|%s", save_as, comment);
+       sprintf(aaa, "UOPN %s|%s|%s", save_as, MimeType,  comment);
        ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
        free(aaa);
        if (ret / 100 == 2) {
                ipc->uploading = 1;
-               ret = CtdlIPCWriteUpload(ipc, path, progress_gauge_callback, cret);
+               ret = CtdlIPCWriteUpload(ipc, uploadFP, progress_gauge_callback, cret);
                ret = CtdlIPCEndUpload(ipc, (ret == -2 ? 1 : 0), cret);
                ipc->uploading = 0;
        }
@@ -1366,7 +1418,11 @@ int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *path,
                char *cret)
 {
        register int ret;
+       FILE *uploadFP;
        char *aaa;
+       char MimeTestBuf[64];
+       const char *MimeType;
+       long len;
 
        if (!cret) return -1;
        if (!save_as) return -1;
@@ -1377,12 +1433,21 @@ int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *path,
        aaa = (char *)malloc(strlen(save_as) + 17);
        if (!aaa) return -1;
 
-       sprintf(aaa, "UIMG %d|%s", for_real, save_as);
+       uploadFP = fopen(path, "r");
+       if (!uploadFP) return -2;
+
+       len = fread(&MimeTestBuf[0], 1, 64, uploadFP);
+       rewind (uploadFP);
+       if (len < 0) 
+               return -3;
+       MimeType = GuessMimeType(&MimeTestBuf[0], 64);
+
+       sprintf(aaa, "UIMG %d|%s|%s", for_real, MimeType, save_as);
        ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
        free(aaa);
        if (ret / 100 == 2 && for_real) {
                ipc->uploading = 1;
-               ret = CtdlIPCWriteUpload(ipc, path, progress_gauge_callback, cret);
+               ret = CtdlIPCWriteUpload(ipc, uploadFP, progress_gauge_callback, cret);
                ret = CtdlIPCEndUpload(ipc, (ret == -2 ? 1 : 0), cret);
                ipc->uploading = 0;
        }
@@ -2347,7 +2412,7 @@ int CtdlIPCEndUpload(CtdlIPC *ipc, int discard, char *cret)
 
 
 /* WRIT */
-int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path,
+int CtdlIPCWriteUpload(CtdlIPC *ipc, FILE *uploadFP,
                void (*progress_gauge_callback)
                        (CtdlIPC*, unsigned long, unsigned long),
                char *cret)
@@ -2357,15 +2422,10 @@ int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path,
        size_t bytes;
        char aaa[SIZ];
        char buf[4096];
-       FILE *fd;
+       FILE *fd = uploadFP;
        int ferr;
 
        if (!cret) return -1;
-       if (!path) return -1;
-       if (!*path) return -1;
-
-       fd = fopen(path, "r");
-       if (!fd) return -2;
 
        fseek(fd, 0L, SEEK_END);
        bytes = ftell(fd);