CtdlFetchMsgList() - treat no-record and zero-messages identically
authorArt Cancro <ajc@citadel.org>
Thu, 17 Aug 2023 22:32:56 +0000 (13:32 -0900)
committerArt Cancro <ajc@citadel.org>
Thu, 17 Aug 2023 22:32:56 +0000 (13:32 -0900)
In both cases, we return 0 to the caller and set the array pointer to NULL.
This simplifies the calling convention and eliminates extra code to check for both conditions

citadel/server/control.c
citadel/server/euidindex.c
citadel/server/modules/expire/serv_expire.c
citadel/server/modules/nntp/serv_nntp.c
citadel/server/room_ops.c

index 173ea61d4ce6d76fbbe17424834e3ae423a267e9..5daef726ea18a3193cb50c330976bd07783cb3d9 100644 (file)
@@ -58,10 +58,6 @@ void control_find_highest(struct ctdlroom *qrbuf, void *data) {
 
        // Load the message list
        num_msgs = CtdlFetchMsgList(qrbuf->QRnumber, &msglist);
-       if (num_msgs < 0) {
-               return; // No msglists record?  No further action.
-       }
-
        if (num_msgs > 0) {
                for (c=0; c<num_msgs; c++) {
                        if (msglist[c] > cfh->highest_msgnum_found) {
@@ -69,7 +65,6 @@ void control_find_highest(struct ctdlroom *qrbuf, void *data) {
                        }
                }
        }
-
        free(msglist);
 }
 
index 14aafd1d6ecd388f2fc0a3ab80ced745a2074897..0c603617e9f47a8d0f402d64b759fe207ffb2c27 100644 (file)
@@ -180,7 +180,7 @@ void cmd_euid(char *cmdbuf) {
        }
 
        num_msgs = CtdlFetchMsgList(CC->room.QRnumber, &msglist);
-       if (num_msgs >= 0) {
+       if (num_msgs > 0) {
                 for (i = 0; i < num_msgs; ++i) {
                         if (msglist[i] == msgnum) {
                                free(msglist);
index 028599ebc7a61d1b72e16698cf4d4fdd6fbcd7fa..9bf180ad01ec476b6b4256211d9d3fa1da2d4532 100644 (file)
@@ -113,9 +113,7 @@ void GatherPurgeMessages(struct ctdlroom *qrbuf, void *data) {
        if (!strcasecmp(qrbuf->QRname, SYSCONFIGROOM)) return;
 
        // Ok, we got this far ... now let's see what's in the room.
-       TRACE;
        num_msgs = CtdlFetchMsgList(qrbuf->QRnumber, &msglist);
-       TRACE;
 
        // Nothing to do if there aren't any messages
        if (num_msgs <= 0) {
index 30be5027bfe2b92f026f0169953af465838d0336..c8bc6013ea5de4004485fbd039790c150997c57c 100644 (file)
@@ -289,10 +289,6 @@ struct nntp_msglist nntp_fetch_msglist(struct ctdlroom *qrbuf) {
        struct cdbdata *cdbfr;
 
        nm.num_msgs = CtdlFetchMsgList(qrbuf->QRnumber, &nm.msgnums);
-       if (nm.msgnums < 0) {
-               nm.num_msgs = 0;
-               nm.msgnums = NULL;
-       }
        return(nm);
 }
 
index 5eb5e69fa67b91b86b23358f4d83100d78feec0f..749bcacb9130dbe8db1da339eade82c2cdd24787 100644 (file)
@@ -604,7 +604,7 @@ int CtdlIsNonEditable(struct ctdlroom *qrbuf) {
 // Retrieve a list of all messages (message numbers) in the specified room.
 // Returns the number of messages in the room, allocates a pointer to the array and stuffs it in the supplied location.
 // Caller must free that memory.
-// Returns (-1) if error.
+// If no messages in room, returns 0 and msgs is set to NULL.
 int CtdlFetchMsgList(long roomnum, long **msgs) {
        int num_msgs = 0;
         struct cdbdata *cdbfr;
@@ -613,12 +613,17 @@ int CtdlFetchMsgList(long roomnum, long **msgs) {
        if (cdbfr == NULL) {
                syslog(LOG_ERR, "room_ops: no msglist for room %ld", roomnum);
                *msgs = NULL;
-               return (-1);
+               return (0);
        }
 
-       *msgs = malloc(cdbfr->len);
-       memcpy(*msgs, cdbfr->ptr, cdbfr->len);
                num_msgs = cdbfr->len / sizeof(long);
+       if (num_msgs > 0) {
+               *msgs = malloc(cdbfr->len);
+               memcpy(*msgs, cdbfr->ptr, cdbfr->len);
+       }
+       else {
+               *msgs = NULL;
+       }
                cdb_free(cdbfr);
        // BEGIN diagnostic section remove this
        syslog(LOG_DEBUG, "\033[7mCtdlFetchMsgList(%ld) %d messages\033[0m", roomnum, num_msgs);