X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fserver%2Fmsgbase.c;h=ae77f36336bb057f3545f5184d533f68662ea105;hb=4eff3b168807ab8c0b7ad773861836f62924878d;hp=66a56da97d9eca29cae2e29fef0a3ff07e3e4fcf;hpb=a4d74d94d85c1a0618bef8eb1c5c3302046a4c1d;p=citadel.git diff --git a/citadel/server/msgbase.c b/citadel/server/msgbase.c index 66a56da97..ae77f3633 100644 --- a/citadel/server/msgbase.c +++ b/citadel/server/msgbase.c @@ -1467,12 +1467,10 @@ int CtdlOutputMsg(long msg_num, // message number (local) to fetch 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); } @@ -1491,10 +1489,7 @@ int CtdlOutputMsg(long msg_num, // message number (local) to fetch 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); } @@ -1508,9 +1503,7 @@ int CtdlOutputMsg(long msg_num, // message number (local) to fetch 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); @@ -1519,18 +1512,15 @@ int CtdlOutputMsg(long msg_num, // message number (local) to fetch 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); } @@ -1540,41 +1530,33 @@ int CtdlOutputMsg(long msg_num, // message number (local) to fetch 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); } @@ -1918,26 +1900,23 @@ void DumpFormatFixed( } -/* - * 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]; @@ -1958,35 +1937,33 @@ int CtdlOutputPreLoadedMsg( 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); @@ -2043,7 +2020,7 @@ int CtdlOutputPreLoadedMsg( strcpy(luser, ""); strcpy(fuser, ""); strcpy(snode, ""); - if (mode == MT_RFC822) + if (mode == MT_RFC822) { OutputRFC822MsgHeaders( TheMessage, flags, @@ -2053,8 +2030,8 @@ int CtdlOutputPreLoadedMsg( luser, sizeof(luser), fuser, sizeof(fuser), snode, sizeof(snode) - ); - + ); + } for (i=0; !IsEmptyStr(&suser[i]); ++i) { suser[i] = tolower(suser[i]); @@ -2062,7 +2039,7 @@ int CtdlOutputPreLoadedMsg( } 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); @@ -2082,7 +2059,7 @@ int CtdlOutputPreLoadedMsg( 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); } @@ -2169,7 +2146,7 @@ START_TEXT: } -DONE: /* now we're done */ +DONE: // now we're done if (do_proto) cprintf("000\n"); return(om_ok); } @@ -2207,12 +2184,12 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms 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); @@ -2222,10 +2199,9 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms 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 0) for (j=0; jroom.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"); @@ -2286,12 +2260,12 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms 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); } @@ -2304,47 +2278,41 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms 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; @@ -2352,10 +2320,7 @@ long CtdlSaveThisMessage(struct CtdlMessage *msg, long msgid, int Reply) { 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]; @@ -2364,28 +2329,26 @@ long CtdlSaveThisMessage(struct CtdlMessage *msg, long msgid, int Reply) { 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); @@ -2399,7 +2362,7 @@ long CtdlSaveThisMessage(struct CtdlMessage *msg, long msgid, int Reply) { } } - /* Free the memory we used for the serialized message */ + // Free the memory we used for the serialized message free(smr.ser); return(retval); } @@ -2411,17 +2374,16 @@ long send_message(struct CtdlMessage *msg) { 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); } @@ -2431,29 +2393,23 @@ long send_message(struct CtdlMessage *msg) { 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;