X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fmigrate%2Fserv_migrate.c;h=f6fd819cec52bd951819722a273d5975773e599b;hb=c4bef9aed41d5709b7abbfaa92fb02a093d47024;hp=8b431c8afbfdf021b9f290da5c5746ad85688e08;hpb=63262a64633e72e4096aaeedda6950c02fb4d990;p=citadel.git diff --git a/citadel/modules/migrate/serv_migrate.c b/citadel/modules/migrate/serv_migrate.c index 8b431c8af..f6fd819ce 100644 --- a/citadel/modules/migrate/serv_migrate.c +++ b/citadel/modules/migrate/serv_migrate.c @@ -1,23 +1,15 @@ /* - * $Id$ - * * This module dumps and/or loads the Citadel database in XML format. * - * Copyright (c) 1987-2010 by the citadel.org team + * Copyright (c) 1987-2012 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 open source software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3. * * 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" @@ -57,12 +49,8 @@ #include "user_ops.h" #include "control.h" #include "euidindex.h" - - #include "ctdl_module.h" - - #define END_OF_MESSAGE "---eom---dbd---" char migr_tempfilename1[PATH_MAX]; @@ -70,14 +58,10 @@ char migr_tempfilename2[PATH_MAX]; FILE *migr_global_message_list; - - /* * Code which implements the export appears in this section */ - - /* * Output a string to the client with these characters escaped: & < > */ @@ -86,8 +70,11 @@ void xml_strout(char *str) { char *c = str; while (*c != 0) { - if (*c == '&') { - client_write("&", 5); + if (*c == '\"') { + client_write(""", 6); + } + else if (*c == '\'') { + client_write("'", 6); } else if (*c == '<') { client_write("<", 4); @@ -95,6 +82,9 @@ void xml_strout(char *str) { else if (*c == '>') { client_write(">", 4); } + else if (*c == '&') { + client_write("&", 5); + } else { client_write(c, 1); } @@ -142,7 +132,11 @@ void migr_export_rooms_backend(struct ctdlroom *buf, void *data) { cprintf("%ld\n", buf->QRhighest); cprintf("%ld\n", (long)buf->QRgen); cprintf("%u\n", buf->QRflags); - client_write("", 11); xml_strout(buf->QRdirname); client_write("\n", 13); + if (buf->QRflags & QR_DIRECTORY) { + client_write("", 11); + xml_strout(buf->QRdirname); + client_write("\n", 13); + } cprintf("%ld\n", buf->QRinfo); cprintf("%d\n", buf->QRfloor); cprintf("%ld\n", (long)buf->QRmtime); @@ -182,10 +176,10 @@ void migr_export_rooms(void) { * this will be handled by exporting the reference count, not by * exporting the message multiple times.) */ - snprintf(cmd, sizeof cmd, "sort <%s >%s", migr_tempfilename1, migr_tempfilename2); - if (system(cmd) != 0) CtdlLogPrintf(CTDL_ALERT, "Error %d\n", errno); + snprintf(cmd, sizeof cmd, "sort -n <%s >%s", migr_tempfilename1, migr_tempfilename2); + if (system(cmd) != 0) syslog(LOG_ALERT, "Error %d\n", errno); snprintf(cmd, sizeof cmd, "uniq <%s >%s", migr_tempfilename2, migr_tempfilename1); - if (system(cmd) != 0) CtdlLogPrintf(CTDL_ALERT, "Error %d\n", errno); + if (system(cmd) != 0) syslog(LOG_ALERT, "Error %d\n", errno); } @@ -208,6 +202,23 @@ void migr_export_floors(void) { } +/* + * Return nonzero if the supplied string contains only characters which are valid in a sequence set. + */ +int is_sequence_set(char *s) { + if (!s) return(0); + + char *c = s; + char ch; + while (ch = *c++, ch) { + if (!strchr("0123456789*,:", ch)) { + return(0); + } + } + return(1); +} + + /* * Traverse the visits file... @@ -231,7 +242,7 @@ void migr_export_visits(void) { cprintf("%ld\n", vbuf.v_usernum); client_write("", 8); - if (!IsEmptyStr(vbuf.v_seen)) { + if ( (!IsEmptyStr(vbuf.v_seen)) && (is_sequence_set(vbuf.v_seen)) ) { xml_strout(vbuf.v_seen); } else { @@ -239,7 +250,12 @@ void migr_export_visits(void) { } client_write("", 9); - client_write("", 12); xml_strout(vbuf.v_answered); client_write("\n", 14); + if ( (!IsEmptyStr(vbuf.v_answered)) && (is_sequence_set(vbuf.v_answered)) ) { + client_write("", 12); + xml_strout(vbuf.v_answered); + client_write("\n", 14); + } + cprintf("%u\n", vbuf.v_flags); cprintf("%d\n", vbuf.v_view); client_write("\n", 9); @@ -281,8 +297,8 @@ void migr_export_message(long msgnum) { client_write("", 23); xml_strout(smi.meta_content_type); client_write("\n", 25); client_write("", 10); - serialize_message(&smr, msg); - CtdlFreeMessage(msg); + CtdlSerializeMessage(&smr, msg); + CM_Free(msg); /* Predict the buffer size we need. Expand the buffer if necessary. */ int encoded_len = smr.len * 15 / 10 ; @@ -342,8 +358,8 @@ void migr_export_messages(void) { Ctx = CC; migr_global_message_list = fopen(migr_tempfilename1, "r"); if (migr_global_message_list != NULL) { - CtdlLogPrintf(CTDL_INFO, "Opened %s\n", migr_tempfilename1); - while ((Ctx->kill_me != 1) && + syslog(LOG_INFO, "Opened %s\n", migr_tempfilename1); + while ((Ctx->kill_me == 0) && (fgets(buf, sizeof(buf), migr_global_message_list) != NULL)) { msgnum = atol(buf); if (msgnum > 0L) { @@ -353,10 +369,10 @@ void migr_export_messages(void) { } fclose(migr_global_message_list); } - if (Ctx->kill_me != 1) - CtdlLogPrintf(CTDL_INFO, "Exported %d messages.\n", count); + if (Ctx->kill_me == 0) + syslog(LOG_INFO, "Exported %d messages.\n", count); else - CtdlLogPrintf(CTDL_ERR, "Export aborted due to client disconnect! \n"); + syslog(LOG_ERR, "Export aborted due to client disconnect! \n"); migr_export_message(-1L); /* This frees the encoding buffer */ } @@ -364,8 +380,6 @@ void migr_export_messages(void) { void migr_do_export(void) { - struct config *buf; - buf = &config; CitContext *Ctx; Ctx = CC; @@ -393,7 +407,6 @@ void migr_do_export(void) { cprintf("%d\n", config.c_restrict); client_write("", 17); xml_strout(config.c_site_location); client_write("\n", 19); client_write("", 10); xml_strout(config.c_sysadm); client_write("\n", 12); - cprintf("%d\n", config.c_setup_level); cprintf("%d\n", config.c_maxsessions); client_write("", 11); xml_strout(config.c_ip_addr); client_write("\n", 13); cprintf("%d\n", config.c_port_number); @@ -429,7 +442,6 @@ void migr_do_export(void) { cprintf("%d\n", config.c_pop3s_port); cprintf("%d\n", config.c_smtps_port); cprintf("%d\n", config.c_auto_cull); - cprintf("%d\n", config.c_instant_expunge); cprintf("%d\n", config.c_allow_spoofing); cprintf("%d\n", config.c_journal_email); cprintf("%d\n", config.c_journal_pubmsgs); @@ -464,12 +476,12 @@ void migr_do_export(void) { cprintf("%d\n", CitControl.version); client_write("\n", 11); - if (Ctx->kill_me != 1) migr_export_users(); - if (Ctx->kill_me != 1) migr_export_openids(); - if (Ctx->kill_me != 1) migr_export_rooms(); - if (Ctx->kill_me != 1) migr_export_floors(); - if (Ctx->kill_me != 1) migr_export_visits(); - if (Ctx->kill_me != 1) migr_export_messages(); + if (Ctx->kill_me == 0) migr_export_users(); + if (Ctx->kill_me == 0) migr_export_openids(); + if (Ctx->kill_me == 0) migr_export_rooms(); + if (Ctx->kill_me == 0) migr_export_floors(); + if (Ctx->kill_me == 0) migr_export_visits(); + if (Ctx->kill_me == 0) migr_export_messages(); client_write("\n", 24); client_write("000\n", 4); Ctx->dont_term = 0; @@ -549,7 +561,7 @@ void migr_xml_start(void *data, const char *el, const char **attr) { } if (citadel_migrate_data != 1) { - CtdlLogPrintf(CTDL_ALERT, "Out-of-sequence tag <%s> detected. Warning: ODD-DATA!\n"); + syslog(LOG_ALERT, "Out-of-sequence tag <%s> detected. Warning: ODD-DATA!\n", el); return; } @@ -594,7 +606,7 @@ void migr_xml_end(void *data, const char *el) { } if (citadel_migrate_data != 1) { - CtdlLogPrintf(CTDL_ALERT, "Out-of-sequence tag <%s> detected. Warning: ODD-DATA!\n"); + syslog(LOG_ALERT, "Out-of-sequence tag <%s> detected. Warning: ODD-DATA!\n", el); return; } @@ -603,14 +615,14 @@ void migr_xml_end(void *data, const char *el) { migr_chardata_len = 0; } - // CtdlLogPrintf(CTDL_DEBUG, "END TAG: <%s> DATA: <%s>\n", el, (migr_chardata_len ? migr_chardata : "")); + // syslog(LOG_DEBUG, "END TAG: <%s> DATA: <%s>\n", el, (migr_chardata_len ? migr_chardata : "")); /*** CONFIG ***/ if (!strcasecmp(el, "config")) { config.c_enable_fulltext = 0; /* always disable */ put_config(); - CtdlLogPrintf(CTDL_INFO, "Completed import of server configuration\n"); + syslog(LOG_INFO, "Completed import of server configuration\n"); } else if (!strcasecmp(el, "c_nodename")) safestrncpy(config.c_nodename, migr_chardata, sizeof config.c_nodename); @@ -628,7 +640,6 @@ void migr_xml_end(void *data, const char *el) { else if (!strcasecmp(el, "c_restrict")) config.c_restrict = atoi(migr_chardata); else if (!strcasecmp(el, "c_site_location")) safestrncpy(config.c_site_location, migr_chardata, sizeof config.c_site_location); else if (!strcasecmp(el, "c_sysadm")) safestrncpy(config.c_sysadm, migr_chardata, sizeof config.c_sysadm); - else if (!strcasecmp(el, "c_setup_level")) config.c_setup_level = atoi(migr_chardata); else if (!strcasecmp(el, "c_maxsessions")) config.c_maxsessions = atoi(migr_chardata); else if (!strcasecmp(el, "c_ip_addr")) safestrncpy(config.c_ip_addr, migr_chardata, sizeof config.c_ip_addr); else if (!strcasecmp(el, "c_port_number")) config.c_port_number = atoi(migr_chardata); @@ -664,7 +675,6 @@ void migr_xml_end(void *data, const char *el) { else if (!strcasecmp(el, "c_pop3s_port")) config.c_pop3s_port = atoi(migr_chardata); else if (!strcasecmp(el, "c_smtps_port")) config.c_smtps_port = atoi(migr_chardata); else if (!strcasecmp(el, "c_auto_cull")) config.c_auto_cull = atoi(migr_chardata); - else if (!strcasecmp(el, "c_instant_expunge")) config.c_instant_expunge = atoi(migr_chardata); else if (!strcasecmp(el, "c_allow_spoofing")) config.c_allow_spoofing = atoi(migr_chardata); else if (!strcasecmp(el, "c_journal_email")) config.c_journal_email = atoi(migr_chardata); else if (!strcasecmp(el, "c_journal_pubmsgs")) config.c_journal_pubmsgs = atoi(migr_chardata); @@ -699,7 +709,7 @@ void migr_xml_end(void *data, const char *el) { else if (!strcasecmp(el, "control")) { CitControl.MMfulltext = (-1L); /* always flush */ put_control(); - CtdlLogPrintf(CTDL_INFO, "Completed import of control record\n"); + syslog(LOG_INFO, "Completed import of control record\n"); } /*** USER ***/ @@ -718,7 +728,7 @@ void migr_xml_end(void *data, const char *el) { else if (!strcasecmp(el, "user")) { CtdlPutUser(&usbuf); - CtdlLogPrintf(CTDL_INFO, "Imported user: %s\n", usbuf.fullname); + syslog(LOG_INFO, "Imported user: %s\n", usbuf.fullname); } /*** OPENID ***/ @@ -735,7 +745,7 @@ void migr_xml_end(void *data, const char *el) { memcpy(&oid_data[sizeof(long)], openid_url, strlen(openid_url) + 1); cdb_store(CDB_OPENID, openid_url, strlen(openid_url), oid_data, oid_data_len); free(oid_data); - CtdlLogPrintf(CTDL_INFO, "Imported OpenID: %s (%ld)\n", openid_url, openid_usernum); + syslog(LOG_INFO, "Imported OpenID: %s (%ld)\n", openid_url, openid_usernum); } /*** ROOM ***/ @@ -759,7 +769,7 @@ void migr_xml_end(void *data, const char *el) { else if (!strcasecmp(el, "room")) { CtdlPutRoom(&qrbuf); - CtdlLogPrintf(CTDL_INFO, "Imported room: %s\n", qrbuf.QRname); + syslog(LOG_INFO, "Imported room: %s\n", qrbuf.QRname); } /*** ROOM MESSAGE POINTERS ***/ @@ -772,7 +782,7 @@ void migr_xml_end(void *data, const char *el) { msglist_alloc = 1000; msglist = malloc(sizeof(long) * msglist_alloc); - CtdlLogPrintf(CTDL_DEBUG, "Message list for: %s\n", FRname); + syslog(LOG_DEBUG, "Message list for: %s\n", FRname); ptr = migr_chardata; while (*ptr != 0) { @@ -800,8 +810,8 @@ void migr_xml_end(void *data, const char *el) { free(msglist); msglist = NULL; msglist_alloc = 0; - CtdlLogPrintf(CTDL_DEBUG, "Imported %d messages.\n", msgcount); - if (CtdlThreadCheckStop()) { + syslog(LOG_DEBUG, "Imported %d messages.\n", msgcount); + if (server_shutting_down) { return; } } @@ -817,7 +827,7 @@ void migr_xml_end(void *data, const char *el) { else if (!strcasecmp(el, "floor")) { CtdlPutFloor(&flbuf, floornum); - CtdlLogPrintf(CTDL_INFO, "Imported floor #%d (%s)\n", floornum, flbuf.f_name); + syslog(LOG_INFO, "Imported floor #%d (%s)\n", floornum, flbuf.f_name); } /*** VISITS ***/ @@ -839,7 +849,7 @@ void migr_xml_end(void *data, const char *el) { else if (!strcasecmp(el, "visit")) { put_visit(&vbuf); - CtdlLogPrintf(CTDL_INFO, "Imported visit: %ld/%ld/%ld\n", vbuf.v_roomnum, vbuf.v_roomgen, vbuf.v_usernum); + syslog(LOG_INFO, "Imported visit: %ld/%ld/%ld\n", vbuf.v_roomnum, vbuf.v_roomgen, vbuf.v_usernum); } /*** MESSAGES ***/ @@ -859,7 +869,7 @@ void migr_xml_end(void *data, const char *el) { free(decoded_msg); decoded_msg = NULL; PutMetaData(&smi); - CtdlLogPrintf(CTDL_INFO, "Imported message #%ld, size=%ld, refcount=%d, content-type: %s\n", + syslog(LOG_INFO, "Imported message #%ld, size=%ld, refcount=%d, content-type: %s\n", import_msgnum, msglen, smi.meta_refcount, smi.meta_content_type); } @@ -879,12 +889,12 @@ void migr_xml_end(void *data, const char *el) { * Import begins here */ void migr_do_import(void) { - char buf[SIZ]; + StrBuf *Buf; XML_Parser xp; int linelen; unbuffer_output(); - + Buf = NewStrBufPlain(NULL, SIZ); xp = XML_ParserCreate(NULL); if (!xp) { cprintf("%d Failed to create XML parser instance\n", ERROR+INTERNAL_ERROR); @@ -898,22 +908,22 @@ void migr_do_import(void) { cprintf("%d sock it to me\n", SEND_LISTING); unbuffer_output(); - while (client_getln(buf, sizeof buf) >= 0 && strcmp(buf, "000")) { - linelen = strlen(buf); - strcpy(&buf[linelen++], "\n"); + while (CtdlClientGetLine(Buf) >= 0 && strcmp(ChrPtr(Buf), "000")) { + linelen = StrLength(Buf); + StrBufAppendBufPlain(Buf, HKEY("\n"), 0); - if (CtdlThreadCheckStop()) + if (server_shutting_down) break; // Should we break or return? - if (buf[0] == '\0') + if (linelen == 0) continue; - XML_Parse(xp, buf, linelen, 0); + XML_Parse(xp, ChrPtr(Buf), linelen, 0); } XML_Parse(xp, "", 0, 1); XML_ParserFree(xp); - + FreeStrBuf(&Buf); rebuild_euid_index(); rebuild_usersbynumber(); CC->dont_term = 0; @@ -987,6 +997,6 @@ CTDL_MODULE_INIT(migrate) CtdlRegisterProtoHook(cmd_migr, "ARTV", "Across-the-wire migration (legacy syntax)"); } - /* return our Subversion id for the Log */ - return "$Id$"; + /* return our module name for the log */ + return "migrate"; }