From fa2dd842abb5feedea3e2253255722fcaecc3c6f Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 5 Mar 2021 13:37:53 -0500 Subject: [PATCH] Added a comma after each msgnum exported. The parser was globbing them all together when it was just a newline. This unfortunately resets the oldest-compatible-export version to the current version, but it wasn't working anyway. --- citadel/citadel.h | 2 +- citadel/housekeeping.c | 13 ++-- citadel/modules/migrate/serv_migrate.c | 96 ++++++++++++++------------ citadel/modules/nntp/serv_nntp.c | 31 +++------ 4 files changed, 68 insertions(+), 74 deletions(-) diff --git a/citadel/citadel.h b/citadel/citadel.h index 437b6ceed..945b22505 100644 --- a/citadel/citadel.h +++ b/citadel/citadel.h @@ -37,7 +37,7 @@ extern "C" { #define REV_LEVEL 931 // This version #define REV_MIN 591 // Oldest compatible database -#define EXPORT_REV_MIN 760 // Oldest compatible export files +#define EXPORT_REV_MIN 931 // Oldest compatible export files #define LIBCITADEL_MIN 931 // Minimum required version of libcitadel #define SERVER_TYPE 0 // zero for stock Citadel; other developers please obtain SERVER_TYPE codes for your implementations diff --git a/citadel/housekeeping.c b/citadel/housekeeping.c index 7f49ad928..0ca383202 100644 --- a/citadel/housekeeping.c +++ b/citadel/housekeeping.c @@ -1,7 +1,7 @@ /* * This file contains miscellaneous housekeeping tasks. * - * Copyright (c) 1987-2018 by the citadel.org team + * Copyright (c) 1987-2021 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. @@ -78,8 +78,7 @@ void check_ref_counts(void) { /* * Provide hints as to whether we have any memory leaks */ -void keep_an_eye_on_memory_usage(void) -{ +void keep_an_eye_on_memory_usage(void) { static void *original_brk = NULL; if (!original_brk) original_brk = sbrk(0); // Remember the original program break so we can test for leaks syslog(LOG_DEBUG, "original_brk=%lx, current_brk=%lx, addl=%ld", (long)original_brk, (long)sbrk(0), (long)(sbrk(0)-original_brk)); // FIXME not so noisy please @@ -112,7 +111,7 @@ void do_housekeeping(void) { end_critical_section(S_HOUSEKEEPING); now = time(NULL); - if (do_housekeeping_now == 0) { + if ( (do_housekeeping_now == 0) && (!CtdlIsSingleUser()) ) { if ( (now - last_timer) > (time_t)300 ) { syslog(LOG_WARNING, "housekeeping: WARNING: housekeeping loop has not run for %ld minutes. Is something stuck?", @@ -161,8 +160,7 @@ void do_housekeeping(void) { } -void CtdlDisableHouseKeeping(void) -{ +void CtdlDisableHouseKeeping(void) { int ActiveBackgroundJobs; int do_housekeeping_now = 0; struct CitContext *nptr; @@ -212,8 +210,7 @@ retry_wait_for_contexts: } -void CtdlEnableHouseKeeping(void) -{ +void CtdlEnableHouseKeeping(void) { begin_critical_section(S_HOUSEKEEPING); housekeeping_in_progress = 0; end_critical_section(S_HOUSEKEEPING); diff --git a/citadel/modules/migrate/serv_migrate.c b/citadel/modules/migrate/serv_migrate.c index aad6615f5..f2f95c0bd 100644 --- a/citadel/modules/migrate/serv_migrate.c +++ b/citadel/modules/migrate/serv_migrate.c @@ -15,14 +15,17 @@ /* * Explanation of tags: * - * 0% nothing - * 2% finished exporting configuration - * 7% finished exporting users - * 12% finished exporting openids - * 17% finished exporting rooms - * 18% finished exporting floors - * 25% finished exporting visits - * 100% finished exporting messages + * 0% started + * 2% finished exporting configuration + * 7% finished exporting users + * 12% finished exporting openids + * 17% finished exporting rooms + * 18% finished exporting floors + * 25% finished exporting visits + * 26-99% exporting messages + * 100% finished exporting messages + * + * These tags are inserted into the XML stream to give the reader an approximation of its progress. */ #include "sysdep.h" @@ -134,15 +137,24 @@ void migr_export_users(void) { void migr_export_room_msg(long msgnum, void *userdata) { - cprintf("%ld\n", msgnum); + static int count = 0; + + cprintf("%ld,", msgnum); + if (++count%10==0) { + cprintf("\n"); + } fprintf(migr_global_message_list, "%ld\n", msgnum); } void migr_export_rooms_backend(struct ctdlroom *buf, void *data) { client_write(HKEY("\n")); - client_write(HKEY("")); xml_strout(buf->QRname); client_write(HKEY("\n")); - client_write(HKEY("")); xml_strout(buf->QRpasswd); client_write(HKEY("\n")); + client_write(HKEY("")); + xml_strout(buf->QRname); + client_write(HKEY("\n")); + client_write(HKEY("")); + xml_strout(buf->QRpasswd); + client_write(HKEY("\n")); cprintf("%ld\n", buf->QRroomaide); cprintf("%ld\n", buf->QRhighest); cprintf("%ld\n", (long)buf->QRgen); @@ -165,16 +177,15 @@ void migr_export_rooms_backend(struct ctdlroom *buf, void *data) { client_write(HKEY("\n")); /* message list goes inside this tag */ - CtdlGetRoom(&CC->room, buf->QRname); client_write(HKEY("")); - client_write(HKEY("")); xml_strout(CC->room.QRname); client_write(HKEY("\n")); - client_write(HKEY("")); + client_write(HKEY("")); + xml_strout(buf->QRname); // buf->QRname rather than CC->room.QRname to guarantee consistency + client_write(HKEY("\n")); + client_write(HKEY("\n")); CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL, migr_export_room_msg, NULL); client_write(HKEY("\n")); client_write(HKEY("\n")); - - } @@ -193,9 +204,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", errno); + if (system(cmd) != 0) syslog(LOG_ERR, "Error %d", errno); snprintf(cmd, sizeof cmd, "uniq <%s >%s", migr_tempfilename2, migr_tempfilename1); - if (system(cmd) != 0) syslog(LOG_ALERT, "Error %d", errno); + if (system(cmd) != 0) syslog(LOG_ERR, "Error %d", errno); snprintf(cmd, sizeof cmd, "wc -l %s", migr_tempfilename1); @@ -496,8 +507,13 @@ long import_msgnum = 0; /* * This callback stores up the data which appears in between tags. */ -void migr_xml_chardata(void *data, const XML_Char *s, int len) -{ +void migr_xml_chardata(void *data, const XML_Char *s, int len) { + + char aaa[65536]; + memcpy(aaa, s, len); + aaa[len] = 0; + syslog(LOG_DEBUG, "chardata <\033[35m%s\033[0m>", aaa); + StrBufAppendBufPlain(migr_chardata, s, len, 0); } @@ -526,7 +542,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!", el); + syslog(LOG_ERR, "Out-of-sequence tag <%s> detected. Warning: ODD-DATA!", el); return; } @@ -560,8 +576,7 @@ void migr_xml_start(void *data, const char *el, const char **attr) { } -int migr_userrecord(void *data, const char *el) -{ +int migr_userrecord(void *data, const char *el) { if (!strcasecmp(el, "u_version")) usbuf.version = atoi(ChrPtr(migr_chardata)); else if (!strcasecmp(el, "u_uid")) usbuf.uid = atol(ChrPtr(migr_chardata)); else if (!strcasecmp(el, "u_password")) safestrncpy(usbuf.password, ChrPtr(migr_chardata), sizeof usbuf.password); @@ -583,8 +598,7 @@ int migr_userrecord(void *data, const char *el) } -int migr_roomrecord(void *data, const char *el) -{ +int migr_roomrecord(void *data, const char *el) { if (!strcasecmp(el, "QRname")) safestrncpy(qrbuf.QRname, ChrPtr(migr_chardata), sizeof qrbuf.QRname); else if (!strcasecmp(el, "QRpasswd")) safestrncpy(qrbuf.QRpasswd, ChrPtr(migr_chardata), sizeof qrbuf.QRpasswd); else if (!strcasecmp(el, "QRroomaide")) qrbuf.QRroomaide = atol(ChrPtr(migr_chardata)); @@ -607,8 +621,7 @@ int migr_roomrecord(void *data, const char *el) } -int migr_floorrecord(void *data, const char *el) -{ +int migr_floorrecord(void *data, const char *el) { 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); @@ -620,8 +633,7 @@ int migr_floorrecord(void *data, const char *el) } -int migr_visitrecord(void *data, const char *el) -{ +int migr_visitrecord(void *data, const char *el) { if (!strcasecmp(el, "v_roomnum")) vbuf.v_roomnum = atol(ChrPtr(migr_chardata)); else if (!strcasecmp(el, "v_roomgen")) vbuf.v_roomgen = atol(ChrPtr(migr_chardata)); else if (!strcasecmp(el, "v_usernum")) vbuf.v_usernum = atol(ChrPtr(migr_chardata)); @@ -648,8 +660,7 @@ int migr_visitrecord(void *data, const char *el) } -void migr_xml_end(void *data, const char *el) -{ +void migr_xml_end(void *data, const char *el) { const char *ptr; int msgcount = 0; long msgnum = 0L; @@ -663,7 +674,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!", el); + syslog(LOG_ERR, "Out-of-sequence tag <%s> detected. Warning: ODD-DATA!", el); return; } @@ -671,8 +682,7 @@ void migr_xml_end(void *data, const char *el) /*** CONFIG ***/ - if (!strcasecmp(el, "config")) - { + if (!strcasecmp(el, "config")) { syslog(LOG_DEBUG, "Imported config key=%s", ikey); if (ikey != NULL) { @@ -722,7 +732,9 @@ void migr_xml_end(void *data, const char *el) /*** ROOM MESSAGE POINTERS ***/ - else if (!strcasecmp(el, "FRname")) safestrncpy(FRname, ChrPtr(migr_chardata), sizeof FRname); + else if (!strcasecmp(el, "FRname")) { + safestrncpy(FRname, ChrPtr(migr_chardata), sizeof FRname); + } else if (!strcasecmp(el, "FRmsglist")) { if (!IsEmptyStr(FRname)) { @@ -733,6 +745,7 @@ void migr_xml_end(void *data, const char *el) syslog(LOG_DEBUG, "Message list for: %s", FRname); ptr = ChrPtr(migr_chardata); + syslog(LOG_DEBUG, "\033[31m%s\033[0m", ptr); while (*ptr != 0) { while ((*ptr != 0) && (!isdigit(*ptr))) { ++ptr; @@ -745,6 +758,7 @@ void migr_xml_end(void *data, const char *el) msglist = realloc(msglist, sizeof(long) * msglist_alloc); } msglist[msgcount++] = msgnum; + syslog(LOG_DEBUG, "\033[32mmsgnum %ld , count is now %d\033[0m", msgnum, msgcount); } } while ((*ptr != 0) && (isdigit(*ptr))) { @@ -790,8 +804,7 @@ void migr_xml_end(void *data, const char *el) 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_text")) - { + else if (!strcasecmp(el, "msg_text")) { long rc; struct CtdlMessage *msg; @@ -894,8 +907,7 @@ void migr_do_listdirs(void) { StrBuf *PlainMessageBuf = NULL; HashList *UsedMessageIDS = NULL; -int migr_restore_message_metadata(long msgnum, int refcount) -{ +int migr_restore_message_metadata(long msgnum, int refcount) { struct MetaData smi; struct CtdlMessage *msg; char *mptr = NULL; @@ -965,9 +977,7 @@ int migr_restore_message_metadata(long msgnum, int refcount) ); PutMetaData(&smi); - CM_Free(msg); - return 0; } @@ -978,9 +988,7 @@ void migr_check_room_msg(long msgnum, void *userdata) { void migr_check_rooms_backend(struct ctdlroom *buf, void *data) { - /* message list goes inside this tag */ - CtdlGetRoom(&CC->room, buf->QRname); CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL, migr_check_room_msg, NULL); } @@ -1026,7 +1034,7 @@ 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", errno); + if (system(cmd) != 0) syslog(LOG_ERR, "Error %d", errno); RoomNames = NewStrBuf(); Ctx = CC; diff --git a/citadel/modules/nntp/serv_nntp.c b/citadel/modules/nntp/serv_nntp.c index 20fc17e84..c629fcc41 100644 --- a/citadel/modules/nntp/serv_nntp.c +++ b/citadel/modules/nntp/serv_nntp.c @@ -166,8 +166,7 @@ void newsgroup_to_room(char *target, char *source, size_t target_size) { // // Here's where our NNTP session begins its happy day. // -void nntp_greeting(void) -{ +void nntp_greeting(void) { strcpy(CC->cs_clientname, "NNTP session"); CC->cs_flags |= CS_STEALTH; @@ -201,8 +200,7 @@ void nntps_greeting(void) { // // implements the STARTTLS command // -void nntp_starttls(void) -{ +void nntp_starttls(void) { char ok_response[SIZ]; char nosup_response[SIZ]; char error_response[SIZ]; @@ -217,8 +215,7 @@ void nntp_starttls(void) // // Implements the CAPABILITY command // -void nntp_capabilities(void) -{ +void nntp_capabilities(void) { cprintf("101 Capability list:\r\n"); cprintf("IMPLEMENTATION Citadel %d\r\n", REV_LEVEL); cprintf("VERSION 2\r\n"); @@ -239,8 +236,7 @@ void nntp_capabilities(void) // // Implements the QUIT command // -void nntp_quit(void) -{ +void nntp_quit(void) { cprintf("221 Goodbye...\r\n"); CC->kill_me = KILLME_CLIENT_LOGGED_OUT; } @@ -249,8 +245,7 @@ void nntp_quit(void) // // Implements the AUTHINFO USER command (RFC 4643) // -void nntp_authinfo_user(const char *username) -{ +void nntp_authinfo_user(const char *username) { int a = CtdlLoginExistingUser(username); switch (a) { case login_already_logged_in: @@ -274,8 +269,7 @@ void nntp_authinfo_user(const char *username) // // Implements the AUTHINFO PASS command (RFC 4643) // -void nntp_authinfo_pass(const char *buf) -{ +void nntp_authinfo_pass(const char *buf) { int a; a = CtdlTryPassword(buf, strlen(buf)); @@ -381,8 +375,7 @@ void output_roomname_in_list_format(struct ctdlroom *qrbuf, int which_format, ch // // Called once per room by nntp_newgroups() to qualify and possibly output a single room // -void nntp_newgroups_backend(struct ctdlroom *qrbuf, void *data) -{ +void nntp_newgroups_backend(struct ctdlroom *qrbuf, void *data) { int ra; int view; time_t thetime = *(time_t *)data; @@ -449,8 +442,7 @@ void nntp_newgroups(const char *cmd) { // // Called once per room by nntp_list() to qualify and possibly output a single room // -void nntp_list_backend(struct ctdlroom *qrbuf, void *data) -{ +void nntp_list_backend(struct ctdlroom *qrbuf, void *data) { int ra; int view; struct nntp_list_data *nld = (struct nntp_list_data *)data; @@ -813,7 +805,6 @@ void nntp_article(const char *cmd) { // The memory for the returned string is pwnz0red by the caller. // char *message_id_from_msgnum(long msgnum) { - char *fetched_message_id = NULL; CC->redirect_buffer = NewStrBufPlain(NULL, SIZ); CtdlOutputMsg(msgnum, @@ -1027,8 +1018,7 @@ void nntp_xover(const char *cmd) { // // Main command loop for NNTP server sessions. // -void nntp_command_loop(void) -{ +void nntp_command_loop(void) { StrBuf *Cmd = NewStrBuf(); char cmdname[16]; @@ -1131,8 +1121,7 @@ void nntp_command_loop(void) // This cleanup function blows away the temporary memory used by // the NNTP server. // -void nntp_cleanup_function(void) -{ +void nntp_cleanup_function(void) { /* Don't do this stuff if this is not an NNTP session! */ if (CC->h_command_function != nntp_command_loop) return; -- 2.30.2