*
*/
+#ifdef DLL_EXPORT
+#define IN_LIBCIT
+#endif
+
#include "sysdep.h"
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
-#include <time.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+
#include <ctype.h>
#include <string.h>
#include <syslog.h>
#include <sys/stat.h>
#include "citadel.h"
#include "server.h"
+#include "dynloader.h"
#include "database.h"
#include "msgbase.h"
#include "support.h"
#include "user_ops.h"
#include "file_ops.h"
#include "control.h"
-#include "dynloader.h"
#include "tools.h"
#include "mime_parser.h"
#include "html.h"
}
+/*
+ * Manipulate the "seen msgs" string.
+ */
+void CtdlSetSeen(long target_msgnum, int target_setting) {
+ char newseen[SIZ];
+ struct cdbdata *cdbfr;
+ int i;
+ int is_seen = 0;
+ int was_seen = 1;
+ long lo = (-1L);
+ long hi = (-1L);
+ struct visit vbuf;
+ long *msglist;
+ int num_msgs = 0;
+
+ /* Learn about the user and room in question */
+ get_mm();
+ getuser(&CC->usersupp, CC->curr_user);
+ CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
+
+ /* Load the message list */
+ cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->quickroom.QRnumber, sizeof(long));
+ if (cdbfr != NULL) {
+ msglist = mallok(cdbfr->len);
+ memcpy(msglist, cdbfr->ptr, cdbfr->len);
+ num_msgs = cdbfr->len / sizeof(long);
+ cdb_free(cdbfr);
+ } else {
+ return; /* No messages at all? No further action. */
+ }
+
+ lprintf(9, "before optimize: %s\n", vbuf.v_seen);
+ strcpy(newseen, "");
+
+ for (i=0; i<num_msgs; ++i) {
+ is_seen = 0;
+
+ if (msglist[i] == target_msgnum) {
+ is_seen = target_setting;
+ }
+ else {
+ if (is_msg_in_mset(vbuf.v_seen, msglist[i])) {
+ is_seen = 1;
+ }
+ }
+
+ if (is_seen == 1) {
+ if (lo < 0L) lo = msglist[i];
+ hi = msglist[i];
+ }
+ if ( ((is_seen == 0) && (was_seen == 1))
+ || ((is_seen == 1) && (i == num_msgs-1)) ) {
+ if ( (strlen(newseen) + 20) > SIZ) {
+ strcpy(newseen, &newseen[20]);
+ newseen[0] = '*';
+ }
+ if (strlen(newseen) > 0) strcat(newseen, ",");
+ if (lo == hi) {
+ sprintf(&newseen[strlen(newseen)], "%ld", lo);
+ }
+ else {
+ sprintf(&newseen[strlen(newseen)], "%ld:%ld",
+ lo, hi);
+ }
+ lo = (-1L);
+ hi = (-1L);
+ }
+ was_seen = is_seen;
+ }
+
+ safestrncpy(vbuf.v_seen, newseen, SIZ);
+ lprintf(9, " after optimize: %s\n", vbuf.v_seen);
+ phree(msglist);
+ CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
+}
/*
long thismsg;
struct SuppMsgInfo smi;
struct CtdlMessage *msg;
+ int is_seen;
+ long lastold = 0L;
+ int printed_lastold = 0;
/* Learn about the user and room in question */
get_mm();
}
+ /*
+ * Now begin the traversal.
+ */
if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
GetSuppMsgInfo(&smi, msglist[a]);
if (num_msgs > 0)
for (a = 0; a < num_msgs; ++a) {
thismsg = msglist[a];
- if ((thismsg > 0)
+ is_seen = is_msg_in_mset(vbuf.v_seen, thismsg);
+ if (is_seen) lastold = thismsg;
+ if ((thismsg > 0L)
&& (
(mode == MSGS_ALL)
- || ((mode == MSGS_OLD) && (thismsg <= vbuf.v_lastseen))
- || ((mode == MSGS_NEW) && (thismsg > vbuf.v_lastseen))
- || ((mode == MSGS_NEW) && (thismsg >= vbuf.v_lastseen)
- && (CC->usersupp.flags & US_LASTOLD))
+ || ((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_EQ) && (thismsg == ref))
)
) {
+ if ((mode == MSGS_NEW) && (CC->usersupp.flags & US_LASTOLD) && (lastold > 0L) && (printed_lastold == 0) && (!is_seen)) {
+ if (CallBack)
+ CallBack(lastold, userdata);
+ printed_lastold = 1;
+ ++num_processed;
+ }
if (CallBack) CallBack(thismsg, userdata);
++num_processed;
}
/*
- * Callback function for mime parser that wants to display text
+ * Pre callback function for multipart/alternative
+ *
+ * NOTE: this differs from the standard behavior for a reason. Normally when
+ * displaying multipart/alternative you want to show the _last_ usable
+ * format in the message. Here we show the _first_ one, because it's
+ * usually text/plain. Since this set of functions is designed for text
+ * output to non-MIME-aware clients, this is the desired behavior.
+ *
*/
-void fixed_output(char *name, char *filename, char *partnum, char *disp,
+void fixed_output_pre(char *name, char *filename, char *partnum, char *disp,
void *content, char *cbtype, size_t length, char *encoding,
void *cbuserdata)
- {
- char *ptr;
- char *wptr;
- size_t wlen;
- CIT_UBYTE ch;
-
+{
+ lprintf(9, "fixed_output_pre() type=<%s>\n", cbtype);
if (!strcasecmp(cbtype, "multipart/alternative")) {
- strcpy(ma->prefix, partnum);
- strcat(ma->prefix, ".");
ma->is_ma = 1;
ma->did_print = 0;
return;
}
-
- if ( (!strncasecmp(partnum, ma->prefix, strlen(ma->prefix)))
- && (ma->is_ma == 1)
- && (ma->did_print == 1) ) {
+}
+
+/*
+ * Post callback function for multipart/alternative
+ */
+void fixed_output_post(char *name, char *filename, char *partnum, char *disp,
+ void *content, char *cbtype, size_t length, char *encoding,
+ void *cbuserdata)
+{
+ lprintf(9, "fixed_output_post() type=<%s>\n", cbtype);
+ if (!strcasecmp(cbtype, "multipart/alternative")) {
+ ma->is_ma = 0;
+ ma->did_print = 0;
+ return;
+ }
+}
+
+/*
+ * 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, size_t length, char *encoding,
+ void *cbuserdata)
+ {
+ char *ptr;
+ char *wptr;
+ size_t wlen;
+ CIT_UBYTE ch = 0;
+
+ lprintf(9, "fixed_output() type=<%s>\n", cbtype);
+
+ /*
+ * 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 == 1) && (ma->did_print == 1) ) {
lprintf(9, "Skipping part %s (%s)\n", partnum, cbtype);
return;
}
-
ma->did_print = 1;
if ( (!strcasecmp(cbtype, "text/plain"))
wptr = content;
while (wlen--) {
ch = *wptr++;
+ /**********
if (ch==10) cprintf("\r\n");
else cprintf("%c", ch);
+ **********/
+ cprintf("%c", ch);
}
+ if (ch != '\n') cprintf("\n");
}
else if (!strcasecmp(cbtype, "text/html")) {
ptr = html_to_ascii(content, 80, 0);
CtdlAllocUserData(SYM_MA_INFO, sizeof(struct ma_info));
memset(ma, 0, sizeof(struct ma_info));
mime_parser(mptr, NULL,
- *fixed_output, NULL, NULL,
+ *fixed_output, *fixed_output_pre, *fixed_output_post,
NULL, 0);
}
ret->len = ret->len +
strlen(msg->cm_fields[(int)forder[i]]) + 2;
- lprintf(9, "calling malloc(%d)\n", ret->len);
+ lprintf(9, "serialize_message() calling malloc(%d)\n", ret->len);
ret->ser = mallok(ret->len);
if (ret->ser == NULL) {
ret->len = 0;
*/
if (msg->cm_fields['T'] == NULL) {
lprintf(9, "Generating timestamp\n");
- sprintf(aaa, "%ld", time(NULL));
+ sprintf(aaa, "%ld", (long)time(NULL));
msg->cm_fields['T'] = strdoop(aaa);
}
newmsgid = send_message(msg, network_fp);
if (network_fp != NULL) {
fclose(network_fp);
- system("exec nohup ./netproc -i >/dev/null 2>&1 &");
+ /* FIXME start a network run here */
}
if (newmsgid <= 0L) return(-1);
"Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n"
"bounceto|%s@%s\n"
"remote|%s|0||\n",
- SPOOLMIME, newmsgid, time(NULL),
+ SPOOLMIME, newmsgid, (long)time(NULL),
msg->cm_fields['A'], msg->cm_fields['N'],
recipient );
* Build a binary message to be saved on disk.
*/
-struct CtdlMessage *make_message(
+static struct CtdlMessage *make_message(
struct usersupp *author, /* author's usersupp structure */
char *recipient, /* NULL if it's not mail */
char *room, /* room where it's going */
sprintf(buf, "cit%ld", author->usernum); /* Path */
msg->cm_fields['P'] = strdoop(buf);
- sprintf(buf, "%ld", time(NULL)); /* timestamp */
+ sprintf(buf, "%ld", (long)time(NULL)); /* timestamp */
msg->cm_fields['T'] = strdoop(buf);
if (fake_name[0]) /* author */
}
+/*
+ * Check to see whether we have permission to post a message in the current
+ * room. Returns a *CITADEL ERROR CODE* and puts a message in errmsgbuf, or
+ * returns 0 on success.
+ */
+int CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf) {
+
+ if (!(CC->logged_in)) {
+ sprintf(errmsgbuf, "Not logged in.");
+ return (ERROR + NOT_LOGGED_IN);
+ }
+
+ if ((CC->usersupp.axlevel < 2)
+ && ((CC->quickroom.QRflags & QR_MAILBOX) == 0)) {
+ sprintf(errmsgbuf, "Need to be validated to enter "
+ "(except in %s> to sysop)", MAILROOM);
+ return (ERROR + HIGHER_ACCESS_REQUIRED);
+ }
+
+ if ((CC->usersupp.axlevel < 4)
+ && (CC->quickroom.QRflags & QR_NETWORK)) {
+ sprintf(errmsgbuf, "Need net privileges to enter here.");
+ return (ERROR + HIGHER_ACCESS_REQUIRED);
+ }
+
+ if ((CC->usersupp.axlevel < 6)
+ && (CC->quickroom.QRflags & QR_READONLY)) {
+ sprintf(errmsgbuf, "Sorry, this is a read-only room.");
+ return (ERROR + HIGHER_ACCESS_REQUIRED);
+ }
+
+ strcpy(errmsgbuf, "Ok");
+ return(0);
+}
+
int mtsflag = 0;
struct usersupp tempUS;
char buf[SIZ];
+ int err = 0;
post = extract_int(entargs, 0);
extract(recipient, entargs, 1);
/* first check to make sure the request is valid. */
- if (!(CC->logged_in)) {
- cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
+ err = CtdlDoIHavePermissionToPostInThisRoom(buf);
+ if (err) {
+ cprintf("%d %s\n", err, buf);
return;
}
- if ((CC->usersupp.axlevel < 2) && ((CC->quickroom.QRflags & QR_MAILBOX) == 0)) {
- cprintf("%d Need to be validated to enter ",
- ERROR + HIGHER_ACCESS_REQUIRED);
- cprintf("(except in %s> to sysop)\n", MAILROOM);
- return;
- }
- if ((CC->usersupp.axlevel < 4) && (CC->quickroom.QRflags & QR_NETWORK)) {
- cprintf("%d Need net privileges to enter here.\n",
- ERROR + HIGHER_ACCESS_REQUIRED);
- return;
- }
- if ((CC->usersupp.axlevel < 6) && (CC->quickroom.QRflags & QR_READONLY)) {
- cprintf("%d Sorry, this is a read-only room.\n",
- ERROR + HIGHER_ACCESS_REQUIRED);
- return;
- }
- mtsflag = 0;
+ /* Check some other permission type things. */
if (post == 2) {
if (CC->usersupp.axlevel < 6) {
cprintf("%d %ld\n", SEND_BINARY, msglen);
- client_read(&ch, 1); /* 0xFF magic number */
+ client_read((char*)&ch, 1); /* 0xFF magic number */
msg->cm_magic = CTDLMESSAGE_MAGIC;
- client_read(&ch, 1); /* anon type */
+ client_read((char*)&ch, 1); /* anon type */
msg->cm_anon_type = ch;
- client_read(&ch, 1); /* format type */
+ client_read((char*)&ch, 1); /* format type */
msg->cm_format_type = ch;
msglen = msglen - 3;
while (msglen > 0) {
- client_read(&which_field, 1);
+ client_read((char*)&which_field, 1);
if (!isalpha(which_field)) valid_msg = 0;
--msglen;
tempbuf[0] = 0;
do {
- client_read(&ch, 1);
+ client_read((char*)&ch, 1);
--msglen;
a = strlen(tempbuf);
tempbuf[a+1] = 0;
+/*
+ * Check whether the current user has permission to delete messages from
+ * the current room (returns 1 for yes, 0 for no)
+ */
+int CtdlDoIHavePermissionToDeleteMessagesFromThisRoom(void) {
+ getuser(&CC->usersupp, CC->curr_user);
+ if ((CC->usersupp.axlevel < 6)
+ && (CC->usersupp.usernum != CC->quickroom.QRroomaide)
+ && ((CC->quickroom.QRflags & QR_MAILBOX) == 0)
+ && (!(CC->internal_pgm))) {
+ return(0);
+ }
+ return(1);
+}
+
+
+
/*
* Delete message from current room
*/
long delnum;
int num_deleted;
- getuser(&CC->usersupp, CC->curr_user);
- if ((CC->usersupp.axlevel < 6)
- && (CC->usersupp.usernum != CC->quickroom.QRroomaide)
- && ((CC->quickroom.QRflags & QR_MAILBOX) == 0)
- && (!(CC->internal_pgm))) {
+ if (CtdlDoIHavePermissionToDeleteMessagesFromThisRoom() == 0) {
cprintf("%d Higher access required.\n",
ERROR + HIGHER_ACCESS_REQUIRED);
return;
getroom(&CC->quickroom, hold_rm);
- lprintf(9, "eggstracting...\n");
if (conf != NULL) do {
extract_token(buf, conf, 0, '\n');
- lprintf(9, "eggstracted <%s>\n", buf);
strcpy(conf, &conf[strlen(buf)+1]);
} while ( (strlen(conf)>0) && (strlen(buf)>0) );