CtdlSerializeMessage() now returns struct smr_ret
authorArt Cancro <ajc@citadel.org>
Fri, 26 Jan 2024 18:14:02 +0000 (13:14 -0500)
committerArt Cancro <ajc@citadel.org>
Fri, 26 Jan 2024 18:14:02 +0000 (13:14 -0500)
Instead of giving it a pointer to a struct to fill, now it just
returns a struct.  Because it is the current year and the compiler
can handle that.

citadel/server/msgbase.c
citadel/server/msgbase.h
webcit-ng/server/main.c
webcit-ng/server/webcit.h

index 40d1c8e5b6083e0321b435f0a56983bf40d763ac..3588ac8d08af9f79052c87fcfc425bb372c5d2fa 100644 (file)
@@ -2295,7 +2295,6 @@ int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int do_repl_check, stru
 // called by server-side modules.
 long CtdlSaveThisMessage(struct CtdlMessage *msg, long msgid, int Reply) {
        long retval;
-       struct ser_ret smr;
        int is_bigmsg = 0;
        char *holdM = NULL;
        long holdMLen = 0;
@@ -2310,7 +2309,7 @@ long CtdlSaveThisMessage(struct CtdlMessage *msg, long msgid, int Reply) {
        }
 
        // Serialize our data structure for storage in the database
-       CtdlSerializeMessage(&smr, msg);
+       struct ser_ret smr = CtdlSerializeMessage(msg);
 
        if (is_bigmsg) {
                // put the message body back into the message
@@ -2380,58 +2379,55 @@ long send_message(struct CtdlMessage *msg) {
 
 // Serialize a struct CtdlMessage into the format used on disk.
 // 
-// This function loads up a "struct ser_ret" (defined in server.h) which
+// This function returns a "struct ser_ret" (defined in server.h) which
 // contains the length of the serialized message and a pointer to the
 // serialized message in memory.  THE LATTER MUST BE FREED BY THE CALLER.
-void CtdlSerializeMessage(struct ser_ret *ret,         // return values
-                         struct CtdlMessage *msg)      // unserialized msg
-{
+struct ser_ret CtdlSerializeMessage(struct CtdlMessage *msg) {
+       struct ser_ret ret;
        size_t wlen;
        int i;
 
        // Check for valid message format
        if (CM_IsValidMsg(msg) == 0) {
                syslog(LOG_ERR, "msgbase: CtdlSerializeMessage() aborting due to invalid message");
-               ret->len = 0;
-               ret->ser = NULL;
-               return;
+               ret.len = 0;
+               ret.ser = NULL;
+               return(ret);
        }
 
-       ret->len = 3;
-       for (i=0; i < NDiskFields; ++i)
-               if (msg->cm_fields[FieldOrder[i]] != NULL)
-                       ret->len += msg->cm_lengths[FieldOrder[i]] + 2;
+       ret.len = 3;
+       for (i=0; i < NDiskFields; ++i) {
+               if (msg->cm_fields[FieldOrder[i]] != NULL) {
+                       ret.len += msg->cm_lengths[FieldOrder[i]] + 2;
+               }
+       }
 
-       ret->ser = malloc(ret->len);
-       if (ret->ser == NULL) {
-               syslog(LOG_ERR, "msgbase: CtdlSerializeMessage() malloc(%ld) failed: %m", (long)ret->len);
-               ret->len = 0;
-               ret->ser = NULL;
-               return;
+       ret.ser = malloc(ret.len);
+       if (ret.ser == NULL) {
+               syslog(LOG_ERR, "msgbase: CtdlSerializeMessage() malloc(%ld) failed: %m", (long)ret.len);
+               ret.len = 0;
+               ret.ser = NULL;
+               return(ret);
        }
 
-       ret->ser[0] = 0xFF;
-       ret->ser[1] = msg->cm_anon_type;
-       ret->ser[2] = msg->cm_format_type;
+       ret.ser[0] = 0xFF;
+       ret.ser[1] = msg->cm_anon_type;
+       ret.ser[2] = msg->cm_format_type;
        wlen = 3;
 
        for (i=0; i < NDiskFields; ++i) {
                if (msg->cm_fields[FieldOrder[i]] != NULL) {
-                       ret->ser[wlen++] = (char)FieldOrder[i];
-
-                       memcpy(&ret->ser[wlen],
-                              msg->cm_fields[FieldOrder[i]],
-                              msg->cm_lengths[FieldOrder[i]] + 1);
-
+                       ret.ser[wlen++] = (char)FieldOrder[i];
+                       memcpy(&ret.ser[wlen], msg->cm_fields[FieldOrder[i]], msg->cm_lengths[FieldOrder[i]] + 1);
                        wlen = wlen + msg->cm_lengths[FieldOrder[i]] + 1;
                }
        }
 
-       if (ret->len != wlen) {
-               syslog(LOG_ERR, "msgbase: ERROR; len=%ld wlen=%ld", (long)ret->len, (long)wlen);
+       if (ret.len != wlen) {
+               syslog(LOG_ERR, "msgbase: ERROR; len=%ld wlen=%ld", (long)ret.len, (long)wlen);
        }
 
-       return;
+       return(ret);
 }
 
 
index f432c085e513a2df1c4cc6d480faeb3178659b66..3e7e168d24a1d833695a517c4581e88aae62940a 100644 (file)
@@ -120,7 +120,7 @@ int  CM_IsValidMsg     (struct CtdlMessage *msg);
 #define CM_RANGE(Message, Which) Message->cm_fields[Which], \
                Message->cm_fields[Which] + Message->cm_lengths[Which]
 
-void CtdlSerializeMessage(struct ser_ret *, struct CtdlMessage *);
+struct ser_ret CtdlSerializeMessage(struct CtdlMessage *);
 struct CtdlMessage *CtdlDeserializeMessage(long msgnum, int with_body, const char *Buffer, long Length);
 void ReplicationChecks(struct CtdlMessage *);
 int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newmsgs,
index 77842528be485f644909f34a20a8c50c1816e500..9416679412cdc6acd4b271531f335a9eac2104dd 100644 (file)
@@ -1,6 +1,6 @@
 // Main entry point for the program.
 //
-// Copyright (c) 1996-2023 by the citadel.org team
+// Copyright (c) 1996-2024 by the citadel.org team
 //
 // This program is open source software.  Use, duplication, or
 // disclosure is subject to the GNU General Public License v3.
@@ -95,15 +95,10 @@ int main(int argc, char **argv) {
 
        // Tell 'em who's in da house
        syslog(LOG_NOTICE, "MAKE WEBCIT GREAT AGAIN!");
-       syslog(LOG_NOTICE, "Copyright (C) 1996-2023 by the citadel.org team");
+       syslog(LOG_NOTICE, "Copyright (C) 1996-2024 by the citadel.org team");
        syslog(LOG_NOTICE, " ");
-       syslog(LOG_NOTICE, "This program is open source software: you can redistribute it and/or");
-       syslog(LOG_NOTICE, "modify it under the terms of the GNU General Public License, version 3.");
-       syslog(LOG_NOTICE, " ");
-       syslog(LOG_NOTICE, "This program is distributed in the hope that it will be useful,");
-       syslog(LOG_NOTICE, "but WITHOUT ANY WARRANTY; without even the implied warranty of");
-       syslog(LOG_NOTICE, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the");
-       syslog(LOG_NOTICE, "GNU General Public License for more details.");
+       syslog(LOG_NOTICE, "This program is open source software.  Use, duplication, or");
+       syslog(LOG_NOTICE, "disclosure is subject to the GNU General Public License v3.");
        syslog(LOG_NOTICE, " ");
 
        // Ensure that we are linked to the correct version of libcitadel
index 908048ee19e614ebed86d1df81c37dccad11ca6f..3679d245c4fad8583ee58c287be14d0b0ef092bb 100644 (file)
@@ -1,9 +1,9 @@
 // webcit.h - "header of headers"
 //
-// Copyright (c) 1996-2023 by the citadel.org team
+// Copyright (c) 1996-2024 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.
+// This program is open source software.  Use, duplication, or
+// disclosure is subject to the GNU General Public License v3.
 
 #define SHOW_ME_VAPPEND_PRINTF