-/* $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
#ifdef THREADED_CLIENT
#include <pthread.h>
#endif
+#include <libcitadel.h>
#include "citadel.h"
#include "citadel_ipc.h"
#include "citadel_decls.h"
-#include "tools.h"
#include "citadel_dirs.h"
#ifdef THREADED_CLIENT
pthread_mutex_t rwlock;
static void CtdlIPC_putline(CtdlIPC *ipc, const char *buf);
+
+const char *svn_revision(void);
+
/*
* Does nothing. The server should always return 200.
*/
/*
- * 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)
}
+/* 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)
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]);
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;
}
}
/* 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)) {
}
-/* 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)
{
/* 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;
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;
}
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;
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;
}
/* 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)
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);
/*
* input string from socket - implemented in terms of serv_read()
*/
-#define CHUNKED_READ
#ifdef CHUNKED_READ
static void CtdlIPC_getline(CtdlIPC* ipc, char *buf)