// Implements the message store.
//
-// Copyright (c) 1987-2021 by the citadel.org team
+// Copyright (c) 1987-2022 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.
#include <stdio.h>
#include <regex.h>
#include <sys/stat.h>
+#include <assert.h>
#include <libcitadel.h>
#include "ctdl_module.h"
#include "citserver.h"
}
}
- /* All compares succeeded: we have a match! */
+ // All compares succeeded: we have a match!
return 0;
}
is_set = malloc(num_msgs * sizeof(char));
memset(is_set, 0, (num_msgs * sizeof(char)) );
- /* Decide which message set we're manipulating */
+ // Decide which message set we're manipulating
switch(which_set) {
case ctdlsetseen_seen:
vset = NewStrBufPlain(vbuf.v_seen, -1);
need_to_free_re = 1;
}
- /* Learn about the user and room in question */
+ // Learn about the user and room in question
if (server_shutting_down) {
if (need_to_free_re) regfree(&re);
return -1;
return -1;
}
- /* Load the message list */
+ // Load the message list
cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
if (cdbfr == NULL) {
if (need_to_free_re) regfree(&re);
- return 0; /* No messages at all? No further action. */
+ return 0; // No messages at all? No further action.
}
msglist = (long *) cdbfr->ptr;
num_msgs = cdbfr->len / sizeof(long);
- cdbfr->ptr = NULL; /* clear this so that cdb_free() doesn't free it */
- cdb_free(cdbfr); /* we own this memory now */
+ cdbfr->ptr = NULL; // clear this so that cdb_free() doesn't free it
+ cdb_free(cdbfr); // we own this memory now
/*
* Now begin the traversal.
is_seen = 0;
}
else {
- is_seen = is_msg_in_sequence_set(
- vbuf.v_seen, thismsg);
+ is_seen = is_msg_in_sequence_set(vbuf.v_seen, thismsg);
if (is_seen) lastold = thismsg;
}
- if ((thismsg > 0L)
- && (
-
- (mode == MSGS_ALL)
- || ((mode == MSGS_OLD) && (is_seen))
- || ((mode == MSGS_NEW) && (!is_seen))
- || ((mode == MSGS_LAST) && (a >= (num_msgs - ref)))
- || ((mode == MSGS_FIRST) && (a < ref))
+ if (
+ (thismsg > 0L)
+ && (
+ (mode == MSGS_ALL)
+ || ((mode == MSGS_OLD) && (is_seen))
+ || ((mode == MSGS_NEW) && (!is_seen))
+ || ((mode == MSGS_LAST) && (a >= (num_msgs - ref)))
+ || ((mode == MSGS_FIRST) && (a < ref))
|| ((mode == MSGS_GT) && (thismsg > ref))
|| ((mode == MSGS_LT) && (thismsg < ref))
|| ((mode == MSGS_EQ) && (thismsg == ref))
// Inline callback function for mime parser that wants to display text
-//
void fixed_output(char *name, char *filename, char *partnum, char *disp,
void *content, char *cbtype, char *cbcharset, size_t length,
char *encoding, char *cbid, void *cbuserdata)
// If we're in the middle of a multipart/alternative scope and
// we've already printed another section, skip this one.
- //
if ( (ma->is_ma) && (ma->did_print) ) {
syslog(LOG_DEBUG, "msgbase: skipping part %s (%s)", partnum, cbtype);
return;
// and then set ma->chosen_pref to that MIME type's position in our preference
// list. If we then hit another match, we only replace the first match if
// the preference value is lower.
-//
void choose_preferred(char *name, char *filename, char *partnum, char *disp,
void *content, char *cbtype, char *cbcharset, size_t length,
char *encoding, char *cbid, void *cbuserdata)
// Now that we've chosen our preferred part, output it.
-//
void output_preferred(char *name,
char *filename,
char *partnum,
syslog(LOG_DEBUG, "msgbase: final selection: %s (%s)", actual_rm, room);
if (strcasecmp(actual_rm, CC->room.QRname)) {
- /* CtdlGetRoom(&CC->room, actual_rm); */
CtdlUserGoto(actual_rm, 0, 1, NULL, NULL, NULL, NULL);
}
if (recps == NULL) {
qualified_for_journaling = CtdlGetConfigInt("c_journal_pubmsgs");
}
- else if (recps->num_local + recps->num_ignet + recps->num_internet > 0) {
+ else if (recps->num_local + recps->num_internet > 0) {
qualified_for_journaling = CtdlGetConfigInt("c_journal_email");
}
else {
/*
* Back end function used by CtdlMakeMessage() and similar functions
*/
-StrBuf *CtdlReadMessageBodyBuf(char *terminator, /* token signalling EOT */
+StrBuf *CtdlReadMessageBodyBuf(char *terminator, // token signalling EOT
long tlen,
- size_t maxlen, /* maximum message length */
- StrBuf *exist, /* if non-null, append to it;
- exist is ALWAYS freed */
- int crlf /* CRLF newlines instead of LF */
+ size_t maxlen, // maximum message length
+ StrBuf *exist, // if non-null, append to it; exist is ALWAYS freed
+ int crlf // CRLF newlines instead of LF
) {
StrBuf *Message;
StrBuf *LineBuf;
int flushing = 0;
int finished = 0;
int dotdot = 0;
+ int lines_read = 0; // FIXME remove this after debugging
LineBuf = NewStrBufPlain(NULL, SIZ);
if (exist == NULL) {
if (CtdlClientGetLine(LineBuf) < 0) {
finished = 1;
}
+ ++lines_read;
if ((StrLength(LineBuf) == tlen) && (!strcmp(ChrPtr(LineBuf), terminator))) {
finished = 1;
}
} while (!finished);
FreeStrBuf(&LineBuf);
+
+ // DEBUG remove this
+ int lines_in_buffer = num_tokens(ChrPtr(Message), '\n');
+ syslog(LOG_DEBUG, "\033[31mLines from client : %d\033[0m", lines_read);
+ syslog(LOG_DEBUG, "\033[32mLines in buffer : %d\033[0m", lines_in_buffer);
+ assert(lines_read == lines_in_buffer);
+
+
return Message;
}
/*
* Write a generic object to this room
*
- * Note: this could be much more efficient. Right now we use two temporary
- * files, and still pull the message into memory as with all others.
+ * Returns the message number of the written object, in case you need it.
*/
-void CtdlWriteObject(char *req_room, /* Room to stuff it in */
+long CtdlWriteObject(char *req_room, /* Room to stuff it in */
char *content_type, /* MIME type of this object */
char *raw_message, /* Data to be written */
off_t raw_length, /* Size of raw_message */
struct ctdluser *is_mailbox, /* Mailbox room? */
int is_binary, /* Is encoding necessary? */
- int is_unique, /* Del others of this type? */
unsigned int flags /* Internal save flags */
) {
struct ctdlroom qrbuf;
if (CtdlGetRoom(&qrbuf, roomname) != 0) {
CtdlCreateRoom(roomname, ( (is_mailbox != NULL) ? 5 : 3 ), "", 0, 1, 0, VIEW_BBS);
}
- /* If the caller specified this object as unique, delete all
- * other objects of this type that are currently in the room.
- */
- if (is_unique) {
- syslog(LOG_DEBUG, "msgbase: deleted %d other msgs of this type",
- CtdlDeleteMessages(roomname, NULL, 0, content_type)
- );
- }
+
/* Now write the data */
- CtdlSubmitMsg(msg, NULL, roomname);
+ long new_msgnum = CtdlSubmitMsg(msg, NULL, roomname);
CM_Free(msg);
+ return new_msgnum;
}