Removed the caching of netconfig entries. The caching of configdb entries now serves...
[citadel.git] / citadel / modules / migrate / serv_migrate.c
index 83173268239cbc2f69074ee6e24d7ce8f5c2f2f6..01b71d6883d89bcf35ecf8e28b8a1f348a30ff3b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This module dumps and/or loads the Citadel database in XML format.
  *
- * Copyright (c) 1987-2015 by the citadel.org team
+ * Copyright (c) 1987-2016 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.
@@ -69,6 +69,7 @@ char migr_tempfilename1[PATH_MAX];
 char migr_tempfilename2[PATH_MAX];
 FILE *migr_global_message_list;
 int total_msgs = 0;
+char *ikey = NULL;                     // If we're importing a config key we store it here.
 
 
 /******************************************************************************
@@ -76,7 +77,7 @@ int total_msgs = 0;
  ******************************************************************************/
 
 /*
- * Output a string to the client with these characters escaped:  & < >
+ * Output a string to the client with these characters escaped:  & < > " '
  */
 void xml_strout(char *str) {
 
@@ -194,9 +195,9 @@ void migr_export_rooms(void) {
         * exporting the message multiple times.)
         */
        snprintf(cmd, sizeof cmd, "sort -n <%s >%s", migr_tempfilename1, migr_tempfilename2);
-       if (system(cmd) != 0) syslog(LOG_ALERT, "Error %d\n", errno);
+       if (system(cmd) != 0) syslog(LOG_ALERT, "Error %d", errno);
        snprintf(cmd, sizeof cmd, "uniq <%s >%s", migr_tempfilename2, migr_tempfilename1);
-       if (system(cmd) != 0) syslog(LOG_ALERT, "Error %d\n", errno);
+       if (system(cmd) != 0) syslog(LOG_ALERT, "Error %d", errno);
 
 
        snprintf(cmd, sizeof cmd, "wc -l %s", migr_tempfilename1);
@@ -415,7 +416,7 @@ void migr_export_messages(void) {
        Ctx = CC;
        migr_global_message_list = fopen(migr_tempfilename1, "r");
        if (migr_global_message_list != NULL) {
-               syslog(LOG_INFO, "Opened %s\n", migr_tempfilename1);
+               syslog(LOG_INFO, "Opened %s", migr_tempfilename1);
                while ((Ctx->kill_me == 0) && 
                       (fgets(buf, sizeof(buf), migr_global_message_list) != NULL)) {
                        msgnum = atol(buf);
@@ -432,9 +433,9 @@ void migr_export_messages(void) {
                fclose(migr_global_message_list);
        }
        if (Ctx->kill_me == 0)
-               syslog(LOG_INFO, "Exported %d messages.\n", count);
+               syslog(LOG_INFO, "Exported %d messages.", count);
        else
-               syslog(LOG_ERR, "Export aborted due to client disconnect! \n");
+               syslog(LOG_ERR, "Export aborted due to client disconnect!");
 
        migr_export_message(-1L);       /* This frees the encoding buffer */
 }
@@ -533,7 +534,7 @@ void migr_xml_start(void *data, const char *el, const char **attr) {
        }
 
        if (citadel_migrate_data != 1) {
-               syslog(LOG_ALERT, "Out-of-sequence tag <%s> detected.  Warning: ODD-DATA!\n", el);
+               syslog(LOG_ALERT, "Out-of-sequence tag <%s> detected.  Warning: ODD-DATA!", el);
                return;
        }
 
@@ -552,7 +553,16 @@ void migr_xml_start(void *data, const char *el, const char **attr) {
                import_msgnum = 0;
        }
        else if (!strcasecmp(el, "config")) {
-               syslog(LOG_DEBUG, "\033[31m IMPORT OF CONFIG START ELEMENT FIXME\033\0m");
+               if (ikey != NULL) {
+                       free(ikey);
+                       ikey = NULL;
+               }
+               while (*attr) {
+                       if (!strcasecmp(attr[0], "key")) {
+                               ikey = strdup(attr[1]);
+                       }
+                       attr += 2;
+               }
        }
 
 }
@@ -652,7 +662,7 @@ void migr_xml_end(void *data, const char *el)
        }
 
        if (citadel_migrate_data != 1) {
-               syslog(LOG_ALERT, "Out-of-sequence tag <%s> detected.  Warning: ODD-DATA!\n", el);
+               syslog(LOG_ALERT, "Out-of-sequence tag <%s> detected.  Warning: ODD-DATA!", el);
                return;
        }
 
@@ -662,8 +672,16 @@ void migr_xml_end(void *data, const char *el)
 
        if (!strcasecmp(el, "config"))
        {
-               syslog(LOG_DEBUG, "\033[31m IMPORT OF CONFIG END ELEMENT FIXME\033\0m");
-               CtdlSetConfigInt("c_enable_fulltext", 0);       /* always disable FIXME put this somewhere more appropriate */
+               syslog(LOG_DEBUG, "Imported config key=%s", ikey);
+
+               if (ikey != NULL) {
+                       CtdlSetConfigStr(ikey, ChrPtr(migr_chardata));
+                       free(ikey);
+                       ikey = NULL;
+               }
+               else {
+                       syslog(LOG_INFO, "Closed a <config> tag but no key name was supplied.");
+               }
        }
 
        /*** USER ***/
@@ -672,7 +690,7 @@ void migr_xml_end(void *data, const char *el)
                ; /* Nothing to do anymore */
        else if (!strcasecmp(el, "user")) {
                CtdlPutUser(&usbuf);
-               syslog(LOG_INFO, "Imported user: %s\n", usbuf.fullname);
+               syslog(LOG_INFO, "Imported user: %s", usbuf.fullname);
        }
 
        /*** OPENID ***/
@@ -689,7 +707,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);
-               syslog(LOG_INFO, "Imported OpenID: %s (%ld)\n", openid_url, openid_usernum);
+               syslog(LOG_INFO, "Imported OpenID: %s (%ld)", openid_url, openid_usernum);
        }
 
        /*** ROOM ***/
@@ -698,7 +716,7 @@ void migr_xml_end(void *data, const char *el)
                ; /* Nothing to do anymore */
        else if (!strcasecmp(el, "room")) {
                CtdlPutRoom(&qrbuf);
-               syslog(LOG_INFO, "Imported room: %s\n", qrbuf.QRname);
+               syslog(LOG_INFO, "Imported room: %s", qrbuf.QRname);
        }
 
        /*** ROOM MESSAGE POINTERS ***/
@@ -711,7 +729,7 @@ void migr_xml_end(void *data, const char *el)
                        msglist_alloc = 1000;
                        msglist = malloc(sizeof(long) * msglist_alloc);
 
-                       syslog(LOG_DEBUG, "Message list for: %s\n", FRname);
+                       syslog(LOG_DEBUG, "Message list for: %s", FRname);
 
                        ptr = ChrPtr(migr_chardata);
                        while (*ptr != 0) {
@@ -739,7 +757,7 @@ void migr_xml_end(void *data, const char *el)
                        free(msglist);
                        msglist = NULL;
                        msglist_alloc = 0;
-                       syslog(LOG_DEBUG, "Imported %d messages.\n", msgcount);
+                       syslog(LOG_DEBUG, "Imported %d messages.", msgcount);
                        if (server_shutting_down) {
                                return;
                }
@@ -752,7 +770,7 @@ void migr_xml_end(void *data, const char *el)
 
        else if (!strcasecmp(el, "floor")) {
                CtdlPutFloor(&flbuf, floornum);
-               syslog(LOG_INFO, "Imported floor #%d (%s)\n", floornum, flbuf.f_name);
+               syslog(LOG_INFO, "Imported floor #%d (%s)", floornum, flbuf.f_name);
        }
 
        /*** VISITS ***/
@@ -761,7 +779,7 @@ void migr_xml_end(void *data, const char *el)
                ; /* Nothing to do anymore */
        else if (!strcasecmp(el, "visit")) {
                put_visit(&vbuf);
-               syslog(LOG_INFO, "Imported visit: %ld/%ld/%ld\n", vbuf.v_roomnum, vbuf.v_roomgen, vbuf.v_usernum);
+               syslog(LOG_INFO, "Imported visit: %ld/%ld/%ld", vbuf.v_roomnum, vbuf.v_roomgen, vbuf.v_usernum);
        }
 
        /*** MESSAGES ***/
@@ -795,7 +813,7 @@ void migr_xml_end(void *data, const char *el)
                }
 
                syslog(LOG_INFO,
-                      "%s message #%ld, size=%d, refcount=%d, bodylength=%ld, content-type: %s / %s \n",
+                      "%s message #%ld, size=%d, refcount=%d, bodylength=%ld, content-type: %s / %s",
                       (rc!= 0)?"failed to import ":"Imported ",
                       import_msgnum,
                       StrLength(migr_MsgData),
@@ -865,6 +883,7 @@ void migr_do_import(void) {
        FreeStrBuf(&migr_MsgData);
        rebuild_euid_index();
        rebuild_usersbynumber();
+       CtdlSetConfigInt("MM_fulltext_wordbreaker", -1);        // Set an invalid wordbreaker to force re-indexing
        CC->dont_term = 0;
 }
 
@@ -882,7 +901,6 @@ void migr_do_listdirs(void) {
        cprintf("files|%s\n",           ctdl_file_dir);
        cprintf("userpics|%s\n",        ctdl_usrpic_dir);
        cprintf("messages|%s\n",        ctdl_message_dir);
-       cprintf("netconfigs|%s\n",      ctdl_netcfg_dir);
        cprintf("keys|%s\n",            ctdl_key_dir);
        cprintf("images|%s\n",          ctdl_image_dir);
        cprintf("info|%s\n",            ctdl_info_dir);
@@ -961,7 +979,7 @@ int migr_restore_message_metadata(long msgnum, int refcount)
 
 
        syslog(LOG_INFO,
-              "Setting message #%ld meta data to: refcount=%d, bodylength=%ld, content-type: %s / %s \n",
+              "Setting message #%ld meta data to: refcount=%d, bodylength=%ld, content-type: %s / %s",
               smi.meta_msgnum,
               smi.meta_refcount,
               smi.meta_rfc822_length,
@@ -1006,7 +1024,7 @@ void RemoveMessagesFromRooms(StrBuf *RoomNameVec, long msgnum) {
 void migr_do_restore_meta(void) {
        char buf[SIZ];
        int failGetMessage;
-       long msgnum;
+       long msgnum = 0;
        int lastnum = 0;
        int refcount = 0;
        CitContext *Ctx;
@@ -1027,13 +1045,13 @@ void migr_do_restore_meta(void) {
         * exporting the message multiple times.)
         */
        snprintf(cmd, sizeof cmd, "sort -n <%s >%s", migr_tempfilename1, migr_tempfilename2);
-       if (system(cmd) != 0) syslog(LOG_ALERT, "Error %d\n", errno);
+       if (system(cmd) != 0) syslog(LOG_ALERT, "Error %d", errno);
 
        RoomNames = NewStrBuf();
        Ctx = CC;
        migr_global_message_list = fopen(migr_tempfilename2, "r");
        if (migr_global_message_list != NULL) {
-               syslog(LOG_INFO, "Opened %s\n", migr_tempfilename1);
+               syslog(LOG_INFO, "Opened %s", migr_tempfilename1);
                while ((Ctx->kill_me == 0) && 
                       (fgets(buf, sizeof(buf), migr_global_message_list) != NULL)) {
                        msgnum = atol(buf);