]> code.citadel.org Git - citadel.git/commitdiff
* msgbase.c: new function serialize_message() for future use
authorArt Cancro <ajc@citadel.org>
Thu, 2 Sep 1999 02:09:59 +0000 (02:09 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 2 Sep 1999 02:09:59 +0000 (02:09 +0000)
citadel/ChangeLog
citadel/msgbase.c
citadel/msgbase.h
citadel/server.h

index d5352901c24cb4ec2ca6c9f2715c044bd692b858..af65cc0220f274552519f34db7646e0e96f8639e 100644 (file)
@@ -1,6 +1,9 @@
 $Log$
+Revision 1.360  1999/09/02 02:09:59  ajc
+* msgbase.c: new function serialize_message() for future use
+
 Revision 1.359  1999/09/01 21:09:25  ajc
-* database.c: isplay the GDBM version string on startup
+* database.c: display the GDBM version string on startup
 
 Revision 1.358  1999/09/01 02:36:34  ajc
 * Actually _enforce_ the max msg len limit
index 2e8ea9feb43e6b3c867d346389f156e1110b8abf..472a2b1dce663b49ba768548e9fe38c60e0b38f9 100644 (file)
@@ -240,7 +240,6 @@ void CtdlForEachMessage(int mode, long ref,
        if (num_msgs > 0)
                for (a = 0; a < num_msgs; ++a) {
                        thismsg = msglist[a];
-                       lprintf(9, "Iterating through <%ld>\n", thismsg);
                        if ((thismsg > 0)
                            && (
 
@@ -254,7 +253,6 @@ void CtdlForEachMessage(int mode, long ref,
                                || ((mode == MSGS_GT) && (thismsg > ref))
                            )
                            ) {
-                               lprintf(9, "Issuing callback for <%ld>\n", thismsg);
                                CallBack(thismsg);
                        }
                }
@@ -1027,6 +1025,53 @@ void copy_file(char *from, char *to)
 
 
 
+/*
+ * Serialize a struct CtdlMessage into the format used on disk and network
+ */
+char *serialize_message(struct CtdlMessage *msg) {
+       char *ser;
+       size_t len = 0;
+       size_t wlen;
+       int i;
+       static char *forder = FORDER;
+
+       lprintf(9, "serialize_message() called\n");
+
+       if ((msg->cm_magic) != CTDLMESSAGE_MAGIC) {
+               lprintf(3, "serialize_message() -- self-check failed\n");
+               return NULL;
+       }
+
+       len = 3;
+       for (i=0; i<26; ++i) if (msg->cm_fields[(int)forder[i]] != NULL)
+               len = len + strlen(msg->cm_fields[(int)forder[i]]) + 2;
+
+       lprintf(9, "calling malloc\n");
+       ser = mallok(len);
+       if (ser == NULL) return NULL;
+
+       ser[0] = 0xFF;
+       ser[1] = msg->cm_anon_type;
+       ser[2] = msg->cm_format_type;
+       wlen = 3;
+       lprintf(9, "stuff\n");
+
+       for (i=0; i<26; ++i) if (msg->cm_fields[(int)forder[i]] != NULL) {
+               ser[wlen++] = (char)forder[i];
+               strcpy(&ser[wlen], msg->cm_fields[(int)forder[i]]);
+               wlen = wlen + strlen(msg->cm_fields[(int)forder[i]]) + 1;
+       }
+       if (len != wlen) lprintf(3, "ERROR: len=%d wlen=%d\n", len, wlen);
+
+       return ser;
+}
+
+
+
+
+
+
+
 /*
  * message base operation to save a message and install its pointers
  */
@@ -1106,7 +1151,6 @@ void save_message(char *mtmp,     /* file containing proper message */
                        if (!strncasecmp(mptr, "Content-type: ", 14)) {
                                safestrncpy(content_type, mptr,
                                            sizeof(content_type));
-                               lprintf(9, "%s\n", content_type);
                                strcpy(content_type, &content_type[14]);
                                for (a = 0; a < strlen(content_type); ++a)
                                        if ((content_type[a] == ';')
@@ -1119,7 +1163,6 @@ void save_message(char *mtmp,     /* file containing proper message */
                        ++mptr;
                }
        }
-       lprintf(9, "Content type is <%s>\n", content_type);
 
        /* Save it to disk */
        newmsgid = send_message(message_in_memory, templen, generate_id);
@@ -1142,7 +1185,6 @@ void save_message(char *mtmp,     /* file containing proper message */
                                strcpy(actual_rm, config.c_twitroom);
                        }
                /* ...or if this message is destined for Aide> then go there. */
-               lprintf(9, "actual room forcing loop\n");
                if (strlen(force_room) > 0) {
                        strcpy(hold_rm, actual_rm);
                        strcpy(actual_rm, force_room);
@@ -1186,7 +1228,6 @@ void save_message(char *mtmp,     /* file containing proper message */
        if ((strlen(recipient) > 0) && (mailtype == MES_LOCAL)) {
                if (getuser(&userbuf, recipient) == 0) {
                        MailboxName(actual_rm, &userbuf, MAILROOM);
-                       lprintf(9, "Targeting mailbox: <%s>\n", actual_rm);
                        if (lgetroom(&qtemp, actual_rm) == 0) {
                                qtemp.QRhighest =
                                    AddMessageToRoom(&qtemp, newmsgid);
@@ -1392,9 +1433,7 @@ void cmd_ent0(char *entargs)
                        strcpy(buf, recipient);
                } else
                        strcpy(buf, "sysop");
-               lprintf(9, "calling alias()\n");
                e = alias(buf); /* alias and mail type */
-               lprintf(9, "alias() returned %d\n", e);
                if ((buf[0] == 0) || (e == MES_ERROR)) {
                        cprintf("%d Unknown address - cannot send message.\n",
                                ERROR + NO_SUCH_USER);
@@ -1576,7 +1615,6 @@ int CtdlDeleteMessages(char *room_name,           /* which room */
        }
        cdbfr = cdb_fetch(CDB_MSGLISTS, &qrbuf.QRnumber, sizeof(long));
 
-       lprintf(9, "doing mallok/memcpy loop\n");
        if (cdbfr != NULL) {
                msglist = mallok(cdbfr->len);
                memcpy(msglist, cdbfr->ptr, cdbfr->len);
index 54c1e368ae578a61b0d5e3a7a202889c8e8d8988..89aba058667cd6a0bf279a35300cd39d0d53765e 100644 (file)
@@ -36,6 +36,7 @@ int CtdlDeleteMessages(char *, long, char *);
 void CtdlWriteObject(char *, char *, char *, int, int, int);
 struct CtdlMessage *CtdlFetchMessage(long msgnum);
 void CtdlFreeMessage(struct CtdlMessage *msg);
+char *serialize_message(struct CtdlMessage *msg);
 
 
 
index 909d02775cd7e98a4cebfb78f77f3bf244bde60e..07cf699a848c2b2cd4eaac8c9f3982f23214369b 100644 (file)
@@ -349,3 +349,9 @@ struct CtdlMessage {
        char cm_format_type;            /* Format type */
        char *cm_fields[256];           /* Data fields */
 };
+
+/* Preferred field order */
+/*               *********                     Important fields */
+/*                        ****************     Semi-important fields */
+/*                                        *    Message text (must be last) */
+#define FORDER "IPTAONHRDBCEFGJKLQSUVWXYZM"