X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fmigrate%2Fserv_migrate.c;h=33b566361e7ba387f59bb79bbe8725cc80c4e7e2;hb=7a9b0685e406cc83597171cc39d008c7e5459ca8;hp=96ff75057f20e218285c7f1820416f6d82539961;hpb=d372b4e08a1b644c76985a89f55e77ab16fe691d;p=citadel.git diff --git a/citadel/modules/migrate/serv_migrate.c b/citadel/modules/migrate/serv_migrate.c index 96ff75057..33b566361 100644 --- a/citadel/modules/migrate/serv_migrate.c +++ b/citadel/modules/migrate/serv_migrate.c @@ -1,7 +1,7 @@ /* * This module dumps and/or loads the Citadel database in XML format. * - * Copyright (c) 1987-2018 by the citadel.org team + * Copyright (c) 1987-2020 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. @@ -34,18 +34,7 @@ #include #include #include - -#if TIME_WITH_SYS_TIME -# include -# include -#else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif - +#include #include #include #include @@ -114,21 +103,30 @@ void xml_strout(char *str) { /* * 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("\n")); - cprintf("%d\n", buf->version); - cprintf("%ld\n", (long)buf->uid); - client_write(HKEY("")); xml_strout(buf->password); client_write(HKEY("\n")); - cprintf("%u\n", buf->flags); - cprintf("%ld\n", buf->timescalled); - cprintf("%ld\n", buf->posted); - cprintf("%d\n", buf->axlevel); - cprintf("%ld\n", buf->usernum); - cprintf("%ld\n", (long)buf->lastcall); - cprintf("%d\n", buf->USuserpurge); - client_write(HKEY("")); xml_strout(buf->fullname); client_write(HKEY("\n")); - cprintf("%ld\n", buf->msgnum_bio); - cprintf("%ld\n", buf->msgnum_pic); + cprintf("%d\n", u.version); + cprintf("%ld\n", (long)u.uid); + client_write(HKEY("")); xml_strout(u.password); client_write(HKEY("\n")); + cprintf("%u\n", u.flags); + cprintf("%ld\n", u.timescalled); + cprintf("%ld\n", u.posted); + cprintf("%d\n", u.axlevel); + cprintf("%ld\n", u.usernum); + cprintf("%ld\n", (long)u.lastcall); + cprintf("%d\n", u.USuserpurge); + client_write(HKEY("")); xml_strout(u.fullname); client_write(HKEY("\n")); + cprintf("%ld\n", u.msgnum_bio); + cprintf("%ld\n", u.msgnum_pic); + cprintf("%s\n", u.emailaddrs); + cprintf("%ld\n", u.msgnum_inboxrules); + cprintf("%ld\n", u.lastproc_inboxrules); client_write(HKEY("\n")); } @@ -253,7 +251,6 @@ int is_sequence_set(char *s) { } - /* * Traverse the visits file... */ @@ -321,7 +318,7 @@ void migr_export_message(long msgnum) { /* Ok, here we go ... */ - msg = CtdlFetchMessage(msgnum, 1, 0); + msg = CtdlFetchMessage(msgnum, 1); if (msg == NULL) return; /* fail silently */ client_write(HKEY("\n")); @@ -359,7 +356,6 @@ void migr_export_message(long msgnum) { } - void migr_export_openids(void) { struct cdbdata *cdboi; long usernum; @@ -405,8 +401,6 @@ void migr_export_configs(void) { } - - void migr_export_messages(void) { char buf[SIZ]; long msgnum; @@ -434,16 +428,17 @@ void migr_export_messages(void) { } 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; @@ -478,8 +473,6 @@ void migr_do_export(void) { } - - /****************************************************************************** * Import code * * Here's the code that implements the import side. It's going to end up * @@ -585,6 +578,9 @@ int migr_userrecord(void *data, const char *el) else if (!strcasecmp(el, "u_fullname")) safestrncpy(usbuf.fullname, ChrPtr(migr_chardata), sizeof usbuf.fullname); else if (!strcasecmp(el, "u_msgnum_bio")) usbuf.msgnum_bio = atol(ChrPtr(migr_chardata)); else if (!strcasecmp(el, "u_msgnum_pic")) usbuf.msgnum_pic = atol(ChrPtr(migr_chardata)); + else if (!strcasecmp(el, "u_emailaddrs")) safestrncpy(usbuf.emailaddrs, ChrPtr(migr_chardata), sizeof usbuf.emailaddrs); + else if (!strcasecmp(el, "u_msgnum_inboxrules")) usbuf.msgnum_inboxrules = atol(ChrPtr(migr_chardata)); + else if (!strcasecmp(el, "u_lastproc_inboxrules")) usbuf.lastproc_inboxrules = atol(ChrPtr(migr_chardata)); else return 0; return 1; } @@ -613,9 +609,10 @@ int migr_roomrecord(void *data, const char *el) 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)); @@ -625,6 +622,7 @@ int migr_floorrecord(void *data, const char *el) return 1; } + int migr_visitrecord(void *data, const char *el) { if (!strcasecmp(el, "v_roomnum")) vbuf.v_roomnum = atol(ChrPtr(migr_chardata)); @@ -780,9 +778,9 @@ void migr_xml_end(void *data, const char *el) } /*** 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); @@ -835,8 +833,6 @@ void migr_xml_end(void *data, const char *el) } - - /* * Import begins here */ @@ -865,9 +861,7 @@ void migr_do_import(void) { 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); } @@ -946,7 +940,7 @@ int migr_restore_message_metadata(long msgnum, int refcount) /* Ok, here we go ... */ - msg = CtdlFetchMessage(msgnum, 1, 0); + msg = CtdlFetchMessage(msgnum, 1); if (msg == NULL) { return 1; } @@ -978,7 +972,6 @@ int migr_restore_message_metadata(long msgnum, int refcount) 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", smi.meta_msgnum, @@ -994,6 +987,7 @@ int migr_restore_message_metadata(long msgnum, int refcount) return 0; } + void migr_check_room_msg(long msgnum, void *userdata) { fprintf(migr_global_message_list, "%ld %s\n", msgnum, CC->room.QRname); } @@ -1007,6 +1001,7 @@ void migr_check_rooms_backend(struct ctdlroom *buf, void *data) { 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; @@ -1019,9 +1014,10 @@ void RemoveMessagesFromRooms(StrBuf *RoomNameVec, long msgnum) { 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; @@ -1069,14 +1065,16 @@ void migr_do_restore_meta(void) { } 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); } @@ -1097,8 +1095,6 @@ void migr_do_restore_meta(void) { } - - /****************************************************************************** * Dispatcher, Common code * ******************************************************************************/ @@ -1107,8 +1103,7 @@ void cmd_migr(char *cmdbuf) { if (CtdlAccessCheck(ac_internal)) return; - if (CtdlTrySingleUser()) - { + if (CtdlTrySingleUser()) { CtdlDisableHouseKeeping(); CtdlMakeTempFileName(migr_tempfilename1, sizeof migr_tempfilename1); CtdlMakeTempFileName(migr_tempfilename2, sizeof migr_tempfilename2); @@ -1136,12 +1131,12 @@ void cmd_migr(char *cmdbuf) { CtdlEnableHouseKeeping(); CtdlEndSingleUser(); } - else - { + else { cprintf("%d The migrator is already running.\n", ERROR + RESOURCE_BUSY); } } + /****************************************************************************** * Module Hook * ******************************************************************************/