/*
* This module dumps and/or loads the Citadel database in XML format.
*
- * Copyright (c) 1987-2017 by the citadel.org team
+ * Copyright (c) 1987-2019 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.
/*
* Export a user record as XML
*/
-void migr_export_users_backend(struct ctdluser *buf, void *data) {
+void migr_export_users_backend(char *username, void *data) {
+
+ struct ctdluser u;
+ if (CtdlGetUser(&u, username) != 0) {
+ return;
+ }
+
client_write(HKEY("<user>\n"));
- cprintf("<u_version>%d</u_version>\n", buf->version);
- cprintf("<u_uid>%ld</u_uid>\n", (long)buf->uid);
- client_write(HKEY("<u_password>")); xml_strout(buf->password); client_write(HKEY("</u_password>\n"));
- cprintf("<u_flags>%u</u_flags>\n", buf->flags);
- cprintf("<u_timescalled>%ld</u_timescalled>\n", buf->timescalled);
- cprintf("<u_posted>%ld</u_posted>\n", buf->posted);
- cprintf("<u_axlevel>%d</u_axlevel>\n", buf->axlevel);
- cprintf("<u_usernum>%ld</u_usernum>\n", buf->usernum);
- cprintf("<u_lastcall>%ld</u_lastcall>\n", (long)buf->lastcall);
- cprintf("<u_USuserpurge>%d</u_USuserpurge>\n", buf->USuserpurge);
- client_write(HKEY("<u_fullname>")); xml_strout(buf->fullname); client_write(HKEY("</u_fullname>\n"));
- cprintf("<u_msgnum_bio>%ld</u_msgnum_bio>\n", buf->msgnum_bio);
- cprintf("<u_msgnum_pic>%ld</u_msgnum_pic>\n", buf->msgnum_pic);
+ cprintf("<u_version>%d</u_version>\n", u.version);
+ cprintf("<u_uid>%ld</u_uid>\n", (long)u.uid);
+ client_write(HKEY("<u_password>")); xml_strout(u.password); client_write(HKEY("</u_password>\n"));
+ cprintf("<u_flags>%u</u_flags>\n", u.flags);
+ cprintf("<u_timescalled>%ld</u_timescalled>\n", u.timescalled);
+ cprintf("<u_posted>%ld</u_posted>\n", u.posted);
+ cprintf("<u_axlevel>%d</u_axlevel>\n", u.axlevel);
+ cprintf("<u_usernum>%ld</u_usernum>\n", u.usernum);
+ cprintf("<u_lastcall>%ld</u_lastcall>\n", (long)u.lastcall);
+ cprintf("<u_USuserpurge>%d</u_USuserpurge>\n", u.USuserpurge);
+ client_write(HKEY("<u_fullname>")); xml_strout(u.fullname); client_write(HKEY("</u_fullname>\n"));
+ cprintf("<u_msgnum_bio>%ld</u_msgnum_bio>\n", u.msgnum_bio);
+ cprintf("<u_msgnum_pic>%ld</u_msgnum_pic>\n", u.msgnum_pic);
client_write(HKEY("</user>\n"));
}
}
-
/*
* Traverse the visits file...
*/
cprintf("<msg_meta_refcount>%d</msg_meta_refcount>\n", smi.meta_refcount);
cprintf("<msg_meta_rfc822_length>%ld</msg_meta_rfc822_length>\n", smi.meta_rfc822_length);
client_write(HKEY("<msg_meta_content_type>")); xml_strout(smi.meta_content_type); client_write(HKEY("</msg_meta_content_type>\n"));
- client_write(HKEY("<msg_mimetype>")); xml_strout(smi.mimetype); client_write(HKEY("</msg_mimetype>\n"));
client_write(HKEY("<msg_text>"));
CtdlSerializeMessage(&smr, msg);
}
-
void migr_export_openids(void) {
struct cdbdata *cdboi;
long usernum;
}
-
-
void migr_export_messages(void) {
char buf[SIZ];
long msgnum;
}
fclose(migr_global_message_list);
}
- if (Ctx->kill_me == 0)
+ if (Ctx->kill_me == 0) {
syslog(LOG_INFO, "Exported %d messages.", count);
- else
+ }
+ else {
syslog(LOG_ERR, "Export aborted due to client disconnect!");
+ }
migr_export_message(-1L); /* This frees the encoding buffer */
}
-
void migr_do_export(void) {
CitContext *Ctx;
}
-
-
/******************************************************************************
* Import code *
* Here's the code that implements the import side. It's going to end up *
return 1;
}
+
int migr_floorrecord(void *data, const char *el)
{
- if (!strcasecmp(el, "f_num")) floornum = atoi(ChrPtr(migr_chardata));
+ if (!strcasecmp(el, "f_num")) floornum = atoi(ChrPtr(migr_chardata));
else if (!strcasecmp(el, "f_flags")) flbuf.f_flags = atoi(ChrPtr(migr_chardata));
else if (!strcasecmp(el, "f_name")) safestrncpy(flbuf.f_name, ChrPtr(migr_chardata), sizeof flbuf.f_name);
else if (!strcasecmp(el, "f_ref_count")) flbuf.f_ref_count = atoi(ChrPtr(migr_chardata));
return 1;
}
+
int migr_visitrecord(void *data, const char *el)
{
if (!strcasecmp(el, "v_roomnum")) vbuf.v_roomnum = atol(ChrPtr(migr_chardata));
}
/*** VISITS ***/
- else if ((!strncasecmp(el, HKEY("v_"))) &&
- migr_visitrecord(data, el))
+ else if ((!strncasecmp(el, HKEY("v_"))) && migr_visitrecord(data, el)) {
; /* Nothing to do anymore */
+ }
else if (!strcasecmp(el, "visit")) {
put_visit(&vbuf);
syslog(LOG_INFO, "Imported visit: %ld/%ld/%ld", vbuf.v_roomnum, vbuf.v_roomgen, vbuf.v_usernum);
else if (!strcasecmp(el, "msg_meta_refcount")) smi.meta_refcount = atoi(ChrPtr(migr_chardata));
else if (!strcasecmp(el, "msg_meta_rfc822_length")) smi.meta_rfc822_length = atoi(ChrPtr(migr_chardata));
else if (!strcasecmp(el, "msg_meta_content_type")) safestrncpy(smi.meta_content_type, ChrPtr(migr_chardata), sizeof smi.meta_content_type);
- else if (!strcasecmp(el, "msg_mimetype")) safestrncpy(smi.mimetype, ChrPtr(migr_chardata), sizeof smi.mimetype);
else if (!strcasecmp(el, "msg_text"))
{
}
syslog(LOG_INFO,
- "%s message #%ld, size=%d, refcount=%d, bodylength=%ld, content-type: %s / %s",
+ "%s message #%ld, size=%d, refcount=%d, bodylength=%ld, content-type: %s",
(rc!= 0)?"failed to import ":"Imported ",
import_msgnum,
StrLength(migr_MsgData),
smi.meta_refcount,
smi.meta_rfc822_length,
- smi.meta_content_type,
- smi.mimetype);
+ smi.meta_content_type
+ );
memset(&smi, 0, sizeof(smi));
}
}
-
-
/*
* Import begins here
*/
client_set_inbound_buf(SIZ * 10);
while (!Finished && client_read_random_blob(Buf, -1) >= 0) {
- if ((StrLength(Buf) > 4) &&
- !strcmp(ChrPtr(Buf) + StrLength(Buf) - 4, "000\n"))
- {
+ if ((StrLength(Buf) > 4) && !strcmp(ChrPtr(Buf) + StrLength(Buf) - 4, "000\n")) {
Finished = 1;
StrBufCutAt(Buf, StrLength(Buf) - 4, NULL);
}
smi.meta_rfc822_length = StrLength(CCC->redirect_buffer);
CCC->redirect_buffer = NULL;
-
syslog(LOG_INFO,
- "Setting message #%ld meta data to: refcount=%d, bodylength=%ld, content-type: %s / %s",
+ "Setting message #%ld meta data to: refcount=%d, bodylength=%ld, content-type: %s",
smi.meta_msgnum,
smi.meta_refcount,
smi.meta_rfc822_length,
- smi.meta_content_type,
- smi.mimetype);
+ smi.meta_content_type
+ );
PutMetaData(&smi);
return 0;
}
+
void migr_check_room_msg(long msgnum, void *userdata) {
fprintf(migr_global_message_list, "%ld %s\n", msgnum, CC->room.QRname);
}
CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL, migr_check_room_msg, NULL);
}
+
void RemoveMessagesFromRooms(StrBuf *RoomNameVec, long msgnum) {
struct MetaData smi;
const char *Pos = NULL;
CtdlDeleteMessages(ChrPtr(oneRoom), &msgnum, 1, "");
};
GetMetaData(&smi, msgnum);
- TDAP_AdjRefCount(msgnum, -smi.meta_refcount);
+ AdjRefCount(msgnum, -smi.meta_refcount);
}
+
void migr_do_restore_meta(void) {
char buf[SIZ];
int failGetMessage;
}
refcount = 1;
lastnum = msgnum;
- if (prn != NULL)
+ if (prn != NULL) {
StrBufPlain(RoomNames, prn + 1, -1);
+ }
StrBufTrim(RoomNames);
}
else {
if (prn != NULL) {
- if (StrLength(RoomNames) > 0)
+ if (StrLength(RoomNames) > 0) {
StrBufAppendBufPlain(RoomNames, HKEY("|"), 0);
+ }
StrBufAppendBufPlain(RoomNames, prn, -1, 1);
StrBufTrim(RoomNames);
}
}
-
-
/******************************************************************************
* Dispatcher, Common code *
******************************************************************************/
if (CtdlAccessCheck(ac_internal)) return;
- if (CtdlTrySingleUser())
- {
+ if (CtdlTrySingleUser()) {
CtdlDisableHouseKeeping();
CtdlMakeTempFileName(migr_tempfilename1, sizeof migr_tempfilename1);
CtdlMakeTempFileName(migr_tempfilename2, sizeof migr_tempfilename2);
CtdlEnableHouseKeeping();
CtdlEndSingleUser();
}
- else
- {
+ else {
cprintf("%d The migrator is already running.\n", ERROR + RESOURCE_BUSY);
}
}
+
/******************************************************************************
* Module Hook *
******************************************************************************/