]> code.citadel.org Git - citadel.git/blobdiff - citadel/msgbase.c
warning fixes and cleanups for 64-bit machines
[citadel.git] / citadel / msgbase.c
index b4c8e0c088b52304007f6cac6f43fce07f0e7f6c..e5c1bcac02e760bf4d21ce666ad7492387a07016 100644 (file)
@@ -5,12 +5,27 @@
  *
  */
 
+#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>
@@ -20,6 +35,7 @@
 #include <sys/stat.h>
 #include "citadel.h"
 #include "server.h"
+#include "dynloader.h"
 #include "database.h"
 #include "msgbase.h"
 #include "support.h"
@@ -29,7 +45,6 @@
 #include "user_ops.h"
 #include "file_ops.h"
 #include "control.h"
-#include "dynloader.h"
 #include "tools.h"
 #include "mime_parser.h"
 #include "html.h"
@@ -806,32 +821,64 @@ void CtdlFreeMessage(struct CtdlMessage *msg)
 
 
 /*
- * 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")) 
@@ -840,9 +887,13 @@ void fixed_output(char *name, char *filename, char *partnum, char *disp,
                        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);
@@ -1216,7 +1267,7 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage,
                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);
        }
 
@@ -1528,7 +1579,7 @@ void serialize_message(struct ser_ret *ret,               /* return values */
                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;
@@ -1658,7 +1709,7 @@ long CtdlSaveMsg(struct CtdlMessage *msg, /* message to save */
         */
        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);
        }
 
@@ -1792,7 +1843,7 @@ long CtdlSaveMsg(struct CtdlMessage *msg, /* message to save */
        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);
@@ -1868,7 +1919,7 @@ long CtdlSaveMsg(struct CtdlMessage *msg, /* message to save */
                        "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 );
 
@@ -1994,7 +2045,7 @@ char *CtdlReadMessageBody(char *terminator,       /* token signalling EOT */
  * 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 */
@@ -2040,7 +2091,7 @@ struct CtdlMessage *make_message(
        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 */
@@ -2314,21 +2365,21 @@ void cmd_ent3(char *entargs)
 
        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;
@@ -2759,10 +2810,8 @@ char *CtdlGetSysConfig(char *sysconfname) {
 
        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) );