Also assert that the calculated length of the serialized message
is actually the final length. Either of these conditions not
being true is worth crashing the server so the developer who broke
it knows immediately.
+ assert(FieldOrder[NDiskFields-1] == eMessageText); // Message text MUST be last!
for (i=0; i < NDiskFields; ++i) {
if (msg->cm_fields[FieldOrder[i]] != NULL) {
ret.len += msg->cm_lengths[FieldOrder[i]] + 2;
for (i=0; i < NDiskFields; ++i) {
if (msg->cm_fields[FieldOrder[i]] != NULL) {
ret.len += msg->cm_lengths[FieldOrder[i]] + 2;
for (i=0; i < NDiskFields; ++i) {
if (msg->cm_fields[FieldOrder[i]] != NULL) {
for (i=0; i < NDiskFields; ++i) {
if (msg->cm_fields[FieldOrder[i]] != NULL) {
+ // future improvement: do the bigmsg check right here
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;
}
}
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);
- }
-
+ assert(ret.len == wlen); // Make sure we measured it correctly
string_trim(content_type);
aptr = content_type;
while (!IsEmptyStr(aptr)) {
string_trim(content_type);
aptr = content_type;
while (!IsEmptyStr(aptr)) {
- if ((*aptr == ';')
- || (*aptr == ' ')
- || (*aptr == 13)
- || (*aptr == 10)) {
+ if ( (*aptr == ';')
+ || (*aptr == ' ')
+ || (*aptr == 13)
+ || (*aptr == 10)
+ ) {
long IsAscii;
IsAscii = -1;
i = 0;
long IsAscii;
IsAscii = -1;
i = 0;
- while ((subject[i] != '\0') && (IsAscii = isascii(subject[i]) != 0 ))
+ while ((subject[i] != '\0') && (IsAscii = isascii(subject[i]) != 0 )) {
+ }
+ if (IsAscii != 0) {
CM_SetField(msg, eMsgSubject, subject);
CM_SetField(msg, eMsgSubject, subject);
else { // ok, we've got utf8 in the string.
char *rfc2047Subj;
rfc2047Subj = rfc2047encode(subject, length);
else { // ok, we've got utf8 in the string.
char *rfc2047Subj;
rfc2047Subj = rfc2047encode(subject, length);
// Use the negative of the message number for the metadata db index
TheIndex = (0L - smibuf->meta_msgnum);
// Use the negative of the message number for the metadata db index
TheIndex = (0L - smibuf->meta_msgnum);
-
- cdb_store(CDB_MSGMAIN,
- &TheIndex, (int)sizeof(long),
- smibuf, (int)sizeof(struct MetaData)
- );
+ cdb_store(CDB_MSGMAIN, &TheIndex, (int)sizeof(long), smibuf, (int)sizeof(struct MetaData));
#define CM_RANGE(Message, Which) Message->cm_fields[Which], \
Message->cm_fields[Which] + Message->cm_lengths[Which]
#define CM_RANGE(Message, Which) Message->cm_fields[Which], \
Message->cm_fields[Which] + Message->cm_lengths[Which]
+// Serialization routines use this struct to return a pointer and a length
+struct ser_ret {
+ size_t len;
+ unsigned char *ser;
+};
+
struct ser_ret CtdlSerializeMessage(struct CtdlMessage *);
struct CtdlMessage *CtdlDeserializeMessage(long msgnum, int with_body, const char *Buffer, long Length);
void ReplicationChecks(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 *);
// Data types for the Citadel Server
//
// Data types for the Citadel Server
//
-// Copyright (c) 1987-2023 by the citadel.org team
+// Copyright (c) 1987-2024 by the citadel.org team
//
// This program is open source software. Use, duplication, or disclosure
// is subject to the terms of the GNU General Public License, version 3.
//
// This program is open source software. Use, duplication, or disclosure
// is subject to the terms of the GNU General Public License, version 3.
-// Serialization routines use this struct to return a pointer and a length
-struct ser_ret {
- size_t len;
- unsigned char *ser;
-};
-
-
// The S_USETABLE database is used in several modules now, so we define its format here.
struct UseTable {
int hash;
// The S_USETABLE database is used in several modules now, so we define its format here.
struct UseTable {
int hash;