]> code.citadel.org Git - citadel.git/blobdiff - citadel/internet_addressing.c
fix all the <time.h> vs. <sys/time.h> issues, hopefully
[citadel.git] / citadel / internet_addressing.c
index 00fde5ca64b38fb5e3d86e7760a47e908ebf1da8..4180874c3b82d09454d60c6f76422366c31ba4f7 100644 (file)
 #include <pwd.h>
 #include <errno.h>
 #include <sys/types.h>
-#include <sys/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 <sys/wait.h>
 #include <string.h>
 #include <limits.h>
 #include "citadel.h"
 #include "server.h"
-#include <time.h>
 #include "sysdep_decls.h"
 #include "citserver.h"
 #include "support.h"
@@ -35,8 +45,8 @@
 
 
 struct trynamebuf {
-       char buffer1[256];
-       char buffer2[256];
+       char buffer1[SIZ];
+       char buffer2[SIZ];
 };
 
 char *inetcfg = NULL;
@@ -49,8 +59,8 @@ char *inetcfg = NULL;
 int CtdlHostAlias(char *fqdn) {
        int config_lines;
        int i;
-       char buf[256];
-       char host[256], type[256];
+       char buf[SIZ];
+       char host[SIZ], type[SIZ];
 
        if (!strcasecmp(fqdn, config.c_fqdn)) return(hostalias_localhost);
        if (!strcasecmp(fqdn, config.c_nodename)) return(hostalias_localhost);
@@ -305,14 +315,14 @@ void try_name(struct usersupp *us, void *data) {
  */
 int convert_internet_address(char *destuser, char *desthost, char *source)
 {
-       char user[256];
-       char node[256];
-       char name[256];
+       char user[SIZ];
+       char node[SIZ];
+       char name[SIZ];
        struct quickroom qrbuf;
        int i;
        int hostalias;
        struct trynamebuf tnb;
-       char buf[256];
+       char buf[SIZ];
        int passes = 0;
        char sourcealias[1024];
 
@@ -400,7 +410,7 @@ int convert_field(struct CtdlMessage *msg, int beg, int end) {
        int i;
        int colonpos = (-1);
        int processed = 0;
-       char buf[256];
+       char buf[SIZ];
        char user[1024];
        char node[1024];
        char name[1024];
@@ -463,19 +473,13 @@ int convert_field(struct CtdlMessage *msg, int beg, int end) {
                        msg->cm_fields['I'] = strdoop(value);
 
                        /* Strip angle brackets */
-                       if ((haschar(msg->cm_fields['I'], '<') == 1)
-                          && (haschar(msg->cm_fields['I'], '>') == 1)) {
-                               while ((strlen(msg->cm_fields['I']) > 0)
-                                     && (msg->cm_fields['I'][0] != '<')) {
-                                       strcpy(&msg->cm_fields['I'][0],
-                                               &msg->cm_fields['I'][1]);
-                               }
+                       while (haschar(msg->cm_fields['I'], '<') > 0) {
                                strcpy(&msg->cm_fields['I'][0],
                                        &msg->cm_fields['I'][1]);
-                               for (i = 0; i<strlen(msg->cm_fields['I']); ++i)
-                                       if (msg->cm_fields['I'][i] == '>')
-                                               msg->cm_fields['I'][i] = 0;
                        }
+                       for (i = 0; i<strlen(msg->cm_fields['I']); ++i)
+                               if (msg->cm_fields['I'][i] == '>')
+                                       msg->cm_fields['I'][i] = 0;
                }
 
                processed = 1;
@@ -489,13 +493,17 @@ int convert_field(struct CtdlMessage *msg, int beg, int end) {
 
 /*
  * Convert an RFC822 message (headers + body) to a CtdlMessage structure.
+ * NOTE: the supplied buffer becomes part of the CtdlMessage structure, and
+ * will be deallocated when CtdlFreeMessage() is called.  Therefore, the
+ * supplied buffer should be DEREFERENCED.  It should not be freed or used
+ * again.
  */
 struct CtdlMessage *convert_internet_message(char *rfc822) {
 
        struct CtdlMessage *msg;
-       int pos, beg, end;
+       int pos, beg, end, msglen;
        int done;
-       char buf[256];
+       char buf[SIZ];
        int converted;
 
        msg = mallok(sizeof(struct CtdlMessage));
@@ -518,18 +526,31 @@ struct CtdlMessage *convert_internet_message(char *rfc822) {
                 */
                beg = pos;
                end = (-1);
-               for (pos=beg; ((pos<=strlen(rfc822))&&(end<0)); ++pos) {
+
+               msglen = strlen(rfc822);        
+               while ( (end < 0) && (done == 0) ) {
+
                        if ((rfc822[pos]=='\n')
                           && (!isspace(rfc822[pos+1]))) {
                                end = pos;
                        }
-                       if ( (rfc822[pos]=='\n')        /* done w. headers? */
+
+                       /* done with headers? */
+                       if (   ((rfc822[pos]=='\n')
+                             ||(rfc822[pos]=='\r') )
                           && ( (rfc822[pos+1]=='\n')
-                             ||(rfc822[pos+1]=='\r'))) {
+                             ||(rfc822[pos+1]=='\r')) ) {
                                end = pos;
                                done = 1;
                        }
 
+                       if (pos >= (msglen-1) ) {
+                               end = pos;
+                               done = 1;
+                       }
+
+                       ++pos;
+
                }
 
                /* At this point we have a field.  Are we interested in it? */