return(r);
}
- /*
- * Check to make sure the message is actually IN this room
- */
+ // Check to make sure the message is actually IN this room
r = check_cached_msglist(msg_num);
if (r == om_access_denied) {
- /* Not in the cache? We get ONE shot to check it again. */
+ // Not in the cache? We get ONE shot to check it again.
CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL, NULL, NULL);
r = check_cached_msglist(msg_num);
}
return(r);
}
- /*
- * Fetch the message from disk. If we're in HEADERS_FAST mode,
- * request that we don't even bother loading the body into memory.
- */
+ // Fetch the message from disk. If we're in HEADERS_FAST mode, request that we don't even bother loading the body into memory.
if (headers_only == HEADERS_FAST) {
TheMessage = CtdlFetchMessage(msg_num, 0);
}
return(om_no_such_msg);
}
- /* Here is the weird form of this command, to process only an
- * encapsulated message/rfc822 section.
- */
+ // Here is the weird form of this command, to process only an encapsulated message/rfc822 section.
if (section) if (!IsEmptyStr(section)) if (strcmp(section, "0")) {
memset(&encap, 0, sizeof encap);
safestrncpy(encap.desired_section, section, sizeof encap.desired_section);
NULL, NULL, (void *)&encap, 0
);
- if ((Author != NULL) && (*Author == NULL))
- {
+ if ((Author != NULL) && (*Author == NULL)) {
long len;
CM_GetAsField(TheMessage, eAuthor, Author, &len);
}
- if ((Address != NULL) && (*Address == NULL))
- {
+ if ((Address != NULL) && (*Address == NULL)) {
long len;
CM_GetAsField(TheMessage, erFc822Addr, Address, &len);
}
- if ((MessageID != NULL) && (*MessageID == NULL))
- {
+ if ((MessageID != NULL) && (*MessageID == NULL)) {
long len;
CM_GetAsField(TheMessage, emessageId, MessageID, &len);
}
if (encap.msg) {
encap.msg[encap.msglen] = 0;
TheMessage = convert_internet_message(encap.msg);
- encap.msg = NULL; /* no free() here, TheMessage owns it now */
+ encap.msg = NULL; // no free() here, TheMessage owns it now
- /* Now we let it fall through to the bottom of this
- * function, because TheMessage now contains the
- * encapsulated message instead of the top-level
- * message. Isn't that neat?
- */
+ // Now we let it fall through to the bottom of this function, because TheMessage now contains the
+ // encapsulated message instead of the top-level message. Isn't that neat?
}
else {
if (do_proto) {
- cprintf("%d msg %ld has no part %s\n",
- ERROR + MESSAGE_NOT_FOUND,
- msg_num,
- section);
+ cprintf("%d msg %ld has no part %s\n", ERROR + MESSAGE_NOT_FOUND, msg_num, section);
}
retcode = om_no_such_msg;
}
}
- /* Ok, output the message now */
- if (retcode == CIT_OK)
+ // Ok, output the message now
+ if (retcode == CIT_OK) {
retcode = CtdlOutputPreLoadedMsg(TheMessage, mode, headers_only, do_proto, crlf, flags);
- if ((Author != NULL) && (*Author == NULL))
- {
+ }
+ if ((Author != NULL) && (*Author == NULL)) {
long len;
CM_GetAsField(TheMessage, eAuthor, Author, &len);
}
- if ((Address != NULL) && (*Address == NULL))
- {
+ if ((Address != NULL) && (*Address == NULL)) {
long len;
CM_GetAsField(TheMessage, erFc822Addr, Address, &len);
}
- if ((MessageID != NULL) && (*MessageID == NULL))
- {
+ if ((MessageID != NULL) && (*MessageID == NULL)) {
long len;
CM_GetAsField(TheMessage, emessageId, MessageID, &len);
}
}
-/*
- * Get a message off disk. (returns om_* values found in msgbase.h)
- */
+// Get a message off disk. (returns om_* values found in msgbase.h)
int CtdlOutputPreLoadedMsg(
struct CtdlMessage *TheMessage,
- int mode, /* how would you like that message? */
- int headers_only, /* eschew the message body? */
- int do_proto, /* do Citadel protocol responses? */
- int crlf, /* Use CRLF newlines instead of LF? */
- int flags /* should the bessage be exported clean? */
+ int mode, // how would you like that message?
+ int headers_only, // eschew the message body?
+ int do_proto, // do Citadel protocol responses?
+ int crlf, // Use CRLF newlines instead of LF?
+ int flags // should the bessage be exported clean?
) {
int i;
- const char *nl; /* newline string */
+ const char *nl; // newline string
int nlen;
struct ma_info ma;
- /* Buffers needed for RFC822 translation. These are all filled
- * using functions that are bounds-checked, and therefore we can
- * make them substantially smaller than SIZ.
- */
+ // Buffers needed for RFC822 translation. These are all filled
+ // using functions that are bounds-checked, and therefore we can
+ // make them substantially smaller than SIZ.
char suser[1024];
char luser[1024];
char fuser[1024];
return(om_no_such_msg);
}
- /* Suppress envelope recipients if required to avoid disclosing BCC addresses.
- * Pad it with spaces in order to avoid changing the RFC822 length of the message.
- */
+ // Suppress envelope recipients if required to avoid disclosing BCC addresses.
+ // Pad it with spaces in order to avoid changing the RFC822 length of the message.
if ( (flags & SUPPRESS_ENV_TO) && (!CM_IsEmpty(TheMessage, eenVelopeTo)) ) {
memset(TheMessage->cm_fields[eenVelopeTo], ' ', TheMessage->cm_lengths[eenVelopeTo]);
}
- /* Are we downloading a MIME component? */
+ // Are we downloading a MIME component?
if (mode == MT_DOWNLOAD) {
if (TheMessage->cm_format_type != FMT_RFC822) {
- if (do_proto)
- cprintf("%d This is not a MIME message.\n",
- ERROR + ILLEGAL_VALUE);
- } else if (CC->download_fp != NULL) {
- if (do_proto) cprintf(
- "%d You already have a download open.\n",
- ERROR + RESOURCE_BUSY);
- } else {
- /* Parse the message text component */
- mime_parser(CM_RANGE(TheMessage, eMesageText),
- *mime_download, NULL, NULL, NULL, 0);
- /* If there's no file open by this time, the requested
- * section wasn't found, so print an error
- */
+ if (do_proto) {
+ cprintf("%d This is not a MIME message.\n", ERROR + ILLEGAL_VALUE);
+ }
+ }
+ else if (CC->download_fp != NULL) {
+ if (do_proto) {
+ cprintf( "%d You already have a download open.\n", ERROR + RESOURCE_BUSY);
+ }
+ }
+ else {
+ // Parse the message text component
+ mime_parser(CM_RANGE(TheMessage, eMesageText), *mime_download, NULL, NULL, NULL, 0);
+
+ // If there's no file open by this time, the requested * section wasn't found, so print an error
if (CC->download_fp == NULL) {
- if (do_proto) cprintf(
- "%d Section %s not found.\n",
- ERROR + FILE_NOT_FOUND,
- CC->download_desired_section);
+ if (do_proto) {
+ cprintf( "%d Section %s not found.\n", ERROR + FILE_NOT_FOUND, CC->download_desired_section);
+ }
}
}
return((CC->download_fp != NULL) ? om_ok : om_mime_error);
strcpy(luser, "");
strcpy(fuser, "");
strcpy(snode, "");
- if (mode == MT_RFC822)
+ if (mode == MT_RFC822) {
OutputRFC822MsgHeaders(
TheMessage,
flags,
luser, sizeof(luser),
fuser, sizeof(fuser),
snode, sizeof(snode)
- );
-
+ );
+ }
for (i=0; !IsEmptyStr(&suser[i]); ++i) {
suser[i] = tolower(suser[i]);
}
if (mode == MT_RFC822) {
- /* Construct a fun message id */
+ // Construct a fun message id
cprintf("Message-ID: <%s", mid);
if (strchr(mid, '@')==NULL) {
cprintf("@%s", snode);
cprintf("From: \"%s\" <%s@%s>%s", luser, suser, snode, nl);
}
- /* Blank line signifying RFC822 end-of-headers */
+ // Blank line signifying RFC822 end-of-headers
if (TheMessage->cm_format_type != FMT_RFC822) {
cprintf("%s", nl);
}
}
-DONE: /* now we're done */
+DONE: // now we're done
if (do_proto) cprintf("000\n");
return(om_ok);
}
strcpy(hold_rm, CC->room.QRname);
- /* Sanity checks */
+ // Sanity checks
if (newmsgidlist == NULL) return(ERROR + INTERNAL_ERROR);
if (num_newmsgs < 1) return(ERROR + INTERNAL_ERROR);
if (num_newmsgs > 1) supplied_msg = NULL;
- /* Now the regular stuff */
+ // Now the regular stuff
if (CtdlGetRoomLock(&CC->room, ((roomname != NULL) ? roomname : CC->room.QRname) ) != 0) {
syslog(LOG_ERR, "msgbase: no such room <%s>", roomname);
return(ERROR + ROOM_NOT_FOUND);
num_msgs_to_be_merged = 0;
num_msgs = CtdlFetchMsgList(CC->room.QRnumber, &msglist);
- /* Create a list of msgid's which were supplied by the caller, but do
- * not already exist in the target room. It is absolutely taboo to
- * have more than one reference to the same message in a room.
- */
+ // Create a list of msgid's which were supplied by the caller, but do
+ // not already exist in the target room. It is absolutely taboo to
+ // have more than one reference to the same message in a room.
for (i=0; i<num_newmsgs; ++i) {
unique = 1;
if (num_msgs > 0) for (j=0; j<num_msgs; ++j) {
syslog(LOG_DEBUG, "msgbase: %d unique messages to be merged", num_msgs_to_be_merged);
- /*
- * Now merge the new messages
- */
+ // Now merge the new messages
msglist = realloc(msglist, (sizeof(long) * (num_msgs + num_msgs_to_be_merged)) );
if (msglist == NULL) {
syslog(LOG_ALERT, "msgbase: ERROR; can't realloc message list!");
free(msgs_to_be_merged);
- abort(); // FIXME FIXME FOOFOO
+ abort(); // FIXME
return (ERROR + INTERNAL_ERROR);
}
memcpy(&msglist[num_msgs], msgs_to_be_merged, (sizeof(long) * num_msgs_to_be_merged) );
num_msgs += num_msgs_to_be_merged;
- /* Sort the message list, so all the msgid's are in order */
+ // Sort the message list, so all the msgid's are in order
num_msgs = sort_msglist(msglist, num_msgs);
- /* Determine the highest message number */
+ // Determine the highest message number
highest_msg = msglist[num_msgs - 1];
- /* Write it back to disk. */
+ // Write it back to disk.
cdb_store(CDB_MSGLISTS, &CC->room.QRnumber, (int)sizeof(long), msglist, (int)(num_msgs * sizeof(long)));
- /* Free up the memory we used. */
+ // Free up the memory we used.
free(msglist);
- /* Update the highest-message pointer and unlock the room. */
+ // Update the highest-message pointer and unlock the room.
CC->room.QRhighest = highest_msg;
CtdlPutRoomLock(&CC->room);
- /* Perform replication checks if necessary */
+ // Perform replication checks if necessary
if ( (DoesThisRoomNeedEuidIndexing(&CC->room)) && (do_repl_check) ) {
syslog(LOG_DEBUG, "msgbase: CtdlSaveMsgPointerInRoom() doing repl checks");
if (msg != NULL) {
ReplicationChecks(msg);
- /* If the message has an Exclusive ID, index that... */
+ // If the message has an Exclusive ID, index that...
if (!CM_IsEmpty(msg, eExclusiveID)) {
index_message_by_euid(msg->cm_fields[eExclusiveID], &CC->room, msgid);
}
- /* Free up the memory we may have allocated */
+ // Free up the memory we may have allocated
if (msg != supplied_msg) {
CM_Free(msg);
}
syslog(LOG_DEBUG, "msgbase: CtdlSaveMsgPointerInRoom() skips repl checks");
}
- /* Submit this room for processing by hooks */
+ // Submit this room for processing by hooks
int total_roomhook_errors = PerformRoomHooks(&CC->room);
if (total_roomhook_errors) {
syslog(LOG_WARNING, "msgbase: room hooks returned %d errors", total_roomhook_errors);
}
- /* Go back to the room we were in before we wandered here... */
+ // Go back to the room we were in before we wandered here...
CtdlGetRoom(&CC->room, hold_rm);
- /* Bump the reference count for all messages which were merged */
+ // Bump the reference count for all messages which were merged
if (!suppress_refcount_adj) {
AdjRefCountList(msgs_to_be_merged, num_msgs_to_be_merged, +1);
}
- /* Free up memory... */
+ // Free up memory...
if (msgs_to_be_merged != NULL) {
free(msgs_to_be_merged);
}
- /* Return success. */
+ // Return success.
return (0);
}
-/*
- * This is the same as CtdlSaveMsgPointersInRoom() but it only accepts
- * a single message.
- */
+// This is the same as CtdlSaveMsgPointersInRoom() but it only accepts a single message.
int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int do_repl_check, struct CtdlMessage *supplied_msg) {
return CtdlSaveMsgPointersInRoom(roomname, &msgid, 1, do_repl_check, supplied_msg, 0);
}
-/*
- * Message base operation to save a new message to the message store
- * (returns new message number)
- *
- * This is the back end for CtdlSubmitMsg() and should not be directly
- * called by server-side modules.
- *
- */
+// Message base operation to save a new message to the message store
+// (returns new message number)
+//
+// This is the back end for CtdlSubmitMsg() and should not be directly
+// called by server-side modules.
long CtdlSaveThisMessage(struct CtdlMessage *msg, long msgid, int Reply) {
long retval;
struct ser_ret smr;
char *holdM = NULL;
long holdMLen = 0;
- /*
- * If the message is big, set its body aside for storage elsewhere
- * and we hide the message body from the serializer
- */
+ // If the message is big, set its body aside for storage elsewhere and we hide the message body from the serializer
if (!CM_IsEmpty(msg, eMesageText) && msg->cm_lengths[eMesageText] > BIGMSG) {
is_bigmsg = 1;
holdM = msg->cm_fields[eMesageText];
msg->cm_lengths[eMesageText] = 0;
}
- /* Serialize our data structure for storage in the database */
+ // Serialize our data structure for storage in the database
CtdlSerializeMessage(&smr, msg);
if (is_bigmsg) {
- /* put the message body back into the message */
+ // put the message body back into the message
msg->cm_fields[eMesageText] = holdM;
msg->cm_lengths[eMesageText] = holdMLen;
}
if (smr.len == 0) {
if (Reply) {
- cprintf("%d Unable to serialize message\n",
- ERROR + INTERNAL_ERROR);
+ cprintf("%d Unable to serialize message\n", ERROR + INTERNAL_ERROR);
}
else {
syslog(LOG_ERR, "msgbase: CtdlSaveMessage() unable to serialize message");
-
}
return (-1L);
}
- /* Write our little bundle of joy into the message base */
+ // Write our little bundle of joy into the message base
retval = cdb_store(CDB_MSGMAIN, &msgid, (int)sizeof(long), smr.ser, smr.len);
if (retval < 0) {
syslog(LOG_ERR, "msgbase: can't store message %ld: %ld", msgid, retval);
}
}
- /* Free the memory we used for the serialized message */
+ // Free the memory we used for the serialized message
free(smr.ser);
return(retval);
}
char msgidbuf[256];
long msgidbuflen;
- /* Get a new message number */
+ // Get a new message number
newmsgid = get_new_message_number();
- /* Generate an ID if we don't have one already */
+ // Generate an ID if we don't have one already
if (CM_IsEmpty(msg, emessageId)) {
msgidbuflen = snprintf(msgidbuf, sizeof msgidbuf, "%08lX-%08lX@%s",
- (long unsigned int) time(NULL),
- (long unsigned int) newmsgid,
- CtdlGetConfigStr("c_fqdn")
- );
-
+ (long unsigned int) time(NULL),
+ (long unsigned int) newmsgid,
+ CtdlGetConfigStr("c_fqdn")
+ );
CM_SetField(msg, emessageId, msgidbuf);
}
retval = newmsgid;
}
- /* Return the *local* message ID to the caller
- * (even if we're storing an incoming network message)
- */
+ // Return the *local* message ID to the caller (even if we're storing a remotely originated message)
return(retval);
}
-/*
- * Serialize a struct CtdlMessage into the format used on disk.
- *
- * This function loads up 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 */
+// Serialize a struct CtdlMessage into the format used on disk.
+//
+// This function loads up 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
{
size_t wlen;
int i;
- /*
- * Check for valid message format
- */
+ // Check for valid message format
if (CM_IsValidMsg(msg) == 0) {
syslog(LOG_ERR, "msgbase: CtdlSerializeMessage() aborting due to invalid message");
ret->len = 0;