#include <string.h>
#include <ctype.h>
#include <limits.h>
+#include <libcitadel.h>
#include "citadel.h"
#include "server.h"
#include "citserver.h"
#include "config.h"
#include "database.h"
#include "msgbase.h"
-#include "tools.h"
#include "user_ops.h"
#include "room_ops.h"
#include "control.h"
cprintf("%d\n", buf->USscreenheight);
}
+void artv_dump_users_backend(struct ctdluser *buf, void *data) {
+ cprintf("user\n");
+
+#include "artv_dump.h"
+#include "dtds/user-defs.h"
+#include "undef_data.h"
+ cprintf("\n");
+}
+
void artv_export_users(void) {
ForEachUser(artv_export_users_backend, NULL);
}
+void artv_dump_users(void) {
+ ForEachUser(artv_dump_users_backend, NULL);
+}
+
void artv_export_room_msg(long msgnum, void *userdata) {
cprintf("%ld\n", msgnum);
fprintf(artv_global_message_list, "%ld\n", msgnum);
}
+void artv_dump_room_msg(long msgnum, void *userdata) {
+ cprintf(" msgnum: %ld\n", msgnum);
+ fprintf(artv_global_message_list, "%ld\n", msgnum);
+ cprintf("\n");
+}//// TODO
+
void artv_export_rooms_backend(struct ctdlroom *buf, void *data) {
cprintf("room\n");
}
+void artv_dump_rooms_backend(struct ctdlroom *buf, void *data) {
+ cprintf("room\n");
+
+#include "artv_dump.h"
+#include "dtds/room-defs.h"
+#include "undef_data.h"
+
+ getroom(&CC->room, buf->QRname);
+ /* format of message list export is all message numbers output
+ * one per line terminated by a 0.
+ */
+//*/
+ getroom(&CC->room, buf->QRname);
+ /* format of message list export is all message numbers output
+ * one per line terminated by a 0.
+ */
+ CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL,
+ artv_dump_room_msg, NULL);
+ cprintf("\n\n");
+
+}
+
void artv_export_rooms(void) {
system(cmd);
}
+void artv_dump_rooms(void) {
+ char cmd[SIZ];
+ artv_global_message_list = fopen(artv_tempfilename1, "w");
+ if (artv_global_message_list != NULL) {
+ ForEachRoom(artv_dump_rooms_backend, NULL);
+ fclose(artv_global_message_list);
+ }
+
+ /*
+ * Process the 'global' message list. (Sort it and remove dups.
+ * Dups are ok because a message may be in more than one room, but
+ * this will be handled by exporting the reference count, not by
+ * exporting the message multiple times.)
+ */
+ snprintf(cmd, sizeof cmd, "sort <%s >%s", artv_tempfilename1, artv_tempfilename2);
+ system(cmd);
+ snprintf(cmd, sizeof cmd, "uniq <%s >%s", artv_tempfilename2, artv_tempfilename1);
+ system(cmd);
+}
+
void artv_export_floors(void) {
struct floor qfbuf, *buf;
}
}
+void artv_dump_floors(void) {
+ struct floor qfbuf, *buf;
+ int i;
+
+ for (i=0; i < MAXFLOORS; ++i) {
+ cprintf("floor\n");
+ cprintf("%d\n", i);
+ getfloor(&qfbuf, i);
+ buf = &qfbuf;
+
+#include "artv_serialize.h"
+#include "dtds/floor-defs.h"
+#include "undef_data.h"
+ }
+}
+
}
}
+/*
+ * Traverse the visits file...
+ */
+void artv_dump_visits(void) {
+ struct visit vbuf;
+ struct cdbdata *cdbv;
+
+ cdb_rewind(CDB_VISIT);
+
+ while (cdbv = cdb_next_item(CDB_VISIT), cdbv != NULL) {
+ memset(&vbuf, 0, sizeof(struct visit));
+ memcpy(&vbuf, cdbv->ptr,
+ ((cdbv->len > sizeof(struct visit)) ?
+ sizeof(struct visit) : cdbv->len));
+ cdb_free(cdbv);
+
+ cprintf("---visit---\n");
+ cprintf(" Room-Num: %ld\n", vbuf.v_roomnum);
+ cprintf(" Room-Gen%ld\n", vbuf.v_roomgen);
+ cprintf(" User-Num%ld\n", vbuf.v_usernum);
+
+ if (!IsEmptyStr(vbuf.v_seen)) {
+ cprintf(" Seen: %s\n", vbuf.v_seen);
+ }
+ else {
+ cprintf(" LastSeen: %ld\n", vbuf.v_lastseen);
+ }
+
+ cprintf(" Answered: %s\n", vbuf.v_answered);
+ cprintf(" Flags: %u\n", vbuf.v_flags);
+ cprintf(" View: %d\n", vbuf.v_view);
+ }
+}
+
void artv_export_message(long msgnum) {
struct MetaData smi;
cprintf("%s\n", END_OF_MESSAGE);
}
+void artv_dump_message(long msgnum) {
+ struct MetaData smi;
+ struct CtdlMessage *msg;
+
+ msg = CtdlFetchMessage(msgnum, 1);
+ if (msg == NULL) return; /* fail silently */
+
+ cprintf("message\n");
+ GetMetaData(&smi, msgnum);
+ cprintf(" MessageNum: %ld\n", msgnum);
+ cprintf(" MetaRefcount: %d\n", smi.meta_refcount);
+ cprintf(" MetaContentType: %s\n", smi.meta_content_type);
+
+ dump_message(msg, 80);
+ CtdlFreeMessage(msg);
+
+ cprintf("%s\n", END_OF_MESSAGE);
+}
+
void artv_export_messages(void) {
Ctx = CC;
artv_global_message_list = fopen(artv_tempfilename1, "r");
if (artv_global_message_list != NULL) {
- lprintf(CTDL_INFO, "Opened %s\n", artv_tempfilename1);
+ CtdlLogPrintf(CTDL_INFO, "Opened %s\n", artv_tempfilename1);
while ((Ctx->kill_me != 1) &&
(fgets(buf, sizeof(buf), artv_global_message_list) != NULL)) {
msgnum = atol(buf);
fclose(artv_global_message_list);
}
if (Ctx->kill_me != 1)
- lprintf(CTDL_INFO, "Exported %d messages.\n", count);
+ CtdlLogPrintf(CTDL_INFO, "Exported %d messages.\n", count);
+ else
+ CtdlLogPrintf(CTDL_ERR, "Export aborted due to client disconnect! \n");
+}
+
+void artv_dump_messages(void) {
+ char buf[SIZ];
+ long msgnum;
+ int count = 0;
+ t_context *Ctx;
+
+ Ctx = CC;
+ artv_global_message_list = fopen(artv_tempfilename1, "r");
+ if (artv_global_message_list != NULL) {
+ CtdlLogPrintf(CTDL_INFO, "Opened %s\n", artv_tempfilename1);
+ while ((Ctx->kill_me != 1) &&
+ (fgets(buf, sizeof(buf), artv_global_message_list) != NULL)) {
+ msgnum = atol(buf);
+ if (msgnum > 0L) {
+ artv_dump_message(msgnum);
+ ++count;
+ }
+ }
+ fclose(artv_global_message_list);
+ }
+ if (Ctx->kill_me != 1)
+ CtdlLogPrintf(CTDL_INFO, "Exported %d messages.\n", count);
else
- lprintf(CTDL_ERR, "Export aborted due to client disconnect! \n");
+ CtdlLogPrintf(CTDL_ERR, "Export aborted due to client disconnect! \n");
}
#include "artv_serialize.h"
#include "dtds/config-defs.h"
#include "undef_data.h"
-
+ cprintf("\n");
+
/* Export the control file */
get_control();
cprintf("control\n");
cprintf("000\n");
}
+void artv_do_dump(void) {
+ struct config *buf;
+ buf = &config;
+ t_context *Ctx;
+
+ Ctx = CC;
+ cprintf("%d dumping Citadel structures.\n", LISTING_FOLLOWS);
+
+ cprintf("version\n%d\n", REV_LEVEL);
+
+ /* export the config file (this is done using x-macros) */
+ cprintf("config\n");
+
+#include "artv_dump.h"
+#include "dtds/config-defs.h"
+#include "undef_data.h"
+
+ /* Export the control file */
+ get_control();
+ cprintf("control\n");
+ cprintf(" MMhighest: %ld\n", CitControl.MMhighest);
+ cprintf(" MMflags: %u\n", CitControl.MMflags);
+ cprintf(" MMnextuser: %ld\n", CitControl.MMnextuser);
+ cprintf(" MMnextroom: %ld\n", CitControl.MMnextroom);
+ cprintf(" version: %d\n\n", CitControl.version);
+ if (Ctx->kill_me != 1)
+ artv_dump_users();
+ if (Ctx->kill_me != 1)
+ artv_dump_rooms();
+ if (Ctx->kill_me != 1)
+ artv_dump_floors();
+ if (Ctx->kill_me != 1)
+ artv_dump_visits();
+ if (Ctx->kill_me != 1)
+ artv_dump_messages();
+
+ cprintf("000\n");
+}
+
void artv_import_config(void) {
struct config *buf;
buf = &config;
- lprintf(CTDL_DEBUG, "Importing config file\n");
+ CtdlLogPrintf(CTDL_DEBUG, "Importing config file\n");
#include "artv_deserialize.h"
#include "dtds/config-defs.h"
config.c_enable_fulltext = 0; /* always disable */
put_config();
- lprintf(CTDL_INFO, "Imported config file\n");
+ CtdlLogPrintf(CTDL_INFO, "Imported config file\n");
}
void artv_import_control(void) {
char buf[SIZ];
- lprintf(CTDL_DEBUG, "Importing control file\n");
+ CtdlLogPrintf(CTDL_DEBUG, "Importing control file\n");
client_getln(buf, sizeof buf); CitControl.MMhighest = atol(buf);
client_getln(buf, sizeof buf); CitControl.MMflags = atoi(buf);
client_getln(buf, sizeof buf); CitControl.MMnextuser = atol(buf);
client_getln(buf, sizeof buf); CitControl.version = atoi(buf);
CitControl.MMfulltext = (-1L); /* always flush */
put_control();
- lprintf(CTDL_INFO, "Imported control file\n");
+ CtdlLogPrintf(CTDL_INFO, "Imported control file\n");
}
client_getln(cbuf, sizeof cbuf); buf->QRdefaultview = atoi(cbuf);
//*/
putroom(buf);
- lprintf(CTDL_INFO, "Imported room <%s>\n", qrbuf.QRname);
+ CtdlLogPrintf(CTDL_INFO, "Imported room <%s>\n", qrbuf.QRname);
/* format of message list export is all message numbers output
* one per line terminated by a 0.
*/
CtdlSaveMsgPointerInRoom(qrbuf.QRname, msgnum, 0, NULL);
++msgcount;
}
- lprintf(CTDL_INFO, "(%d messages)\n", msgcount);
+ CtdlLogPrintf(CTDL_INFO, "(%d messages)\n", msgcount);
}
client_getln(cbuf, sizeof cbuf); buf->f_ep.expire_value = atoi(cbuf);
//*/
putfloor(buf, i);
- lprintf(CTDL_INFO, "Imported floor #%d (%s)\n", i, flbuf.f_name);
+ CtdlLogPrintf(CTDL_INFO, "Imported floor #%d (%s)\n", i, flbuf.f_name);
}
client_getln(buf, sizeof buf); vbuf.v_flags = atoi(buf);
client_getln(buf, sizeof buf); vbuf.v_view = atoi(buf);
put_visit(&vbuf);
- lprintf(CTDL_INFO, "Imported visit %ld/%ld/%ld\n",
+ CtdlLogPrintf(CTDL_INFO, "Imported visit %ld/%ld/%ld\n",
vbuf.v_roomnum, vbuf.v_roomgen, vbuf.v_usernum);
}
client_getln(buf, sizeof buf); smi.meta_refcount = atoi(buf);
client_getln(smi.meta_content_type, sizeof smi.meta_content_type);
- lprintf(CTDL_INFO, "message #%ld\n", msgnum);
+ CtdlLogPrintf(CTDL_INFO, "message #%ld\n", msgnum);
/* decode base64 message text */
CtdlMakeTempFileName(tempfile, sizeof tempfile);
fseek(fp, 0L, SEEK_END);
msglen = ftell(fp);
fclose(fp);
- lprintf(CTDL_DEBUG, "msglen = %ld\n", msglen);
+ CtdlLogPrintf(CTDL_DEBUG, "msglen = %ld\n", msglen);
mbuf = malloc(msglen);
fp = fopen(tempfile, "rb");
unlink(tempfile);
PutMetaData(&smi);
- lprintf(CTDL_INFO, "Imported message %ld\n", msgnum);
+ CtdlLogPrintf(CTDL_INFO, "Imported message %ld\n", msgnum);
}
iterations = 0;
while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
- lprintf(CTDL_DEBUG, "import keyword: <%s>\n", buf);
+ CtdlLogPrintf(CTDL_DEBUG, "import keyword: <%s>\n", buf);
if ((abuf[0] == '\0') || (strcasecmp(buf, abuf))) {
cprintf ("\n\nImporting datatype %s\n", buf);
strncpy (abuf, buf, SIZ);
client_getln(s_version, sizeof s_version);
version = atoi(s_version);
if ((version<EXPORT_REV_MIN) || (version>REV_LEVEL)) {
- lprintf(CTDL_ERR, "Version mismatch in ARTV import; aborting\n");
+ CtdlLogPrintf(CTDL_ERR, "Version mismatch in ARTV import; aborting\n");
break;
}
}
else break;
iterations ++;
}
- lprintf(CTDL_INFO, "Invalid keyword <%s>. Flushing input.\n", buf);
+ CtdlLogPrintf(CTDL_INFO, "Invalid keyword <%s>. Flushing input.\n", buf);
while (client_getln(buf, sizeof buf), strcmp(buf, "000")) ;;
rebuild_euid_index();
}
extract_token(cmd, cmdbuf, 0, '|', sizeof cmd);
if (!strcasecmp(cmd, "export")) artv_do_export();
else if (!strcasecmp(cmd, "import")) artv_do_import();
+ else if (!strcasecmp(cmd, "dump")) artv_do_dump();
else cprintf("%d illegal command\n", ERROR + ILLEGAL_VALUE);
unlink(artv_tempfilename1);
CTDL_MODULE_INIT(vandelay)
{
- CtdlRegisterProtoHook(cmd_artv, "ARTV", "import/export data store");
-
+ if (!threading)
+ {
+ CtdlRegisterProtoHook(cmd_artv, "ARTV", "import/export data store");
+ }
+
/* return our Subversion id for the Log */
return "$Id$";
}