Put our known stringlength into the mime parser so it doesn't need to strlen again.
authorWilfried Goesgens <dothebart@citadel.org>
Tue, 1 Oct 2013 07:57:33 +0000 (09:57 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Tue, 1 Oct 2013 07:57:33 +0000 (09:57 +0200)
citadel/modules/calendar/serv_calendar.c
citadel/modules/imap/imap_fetch.c
citadel/modules/notes/serv_notes.c
citadel/modules/vcard/serv_vcard.c
citadel/modules/wiki/serv_wiki.c
citadel/msgbase.c
citadel/msgbase.h

index 8d3fe42cbb8ee13106532ac429de4f7c581c1d0b..414f9caae242b0f84926eb86c07968e006e9a77a 100644 (file)
@@ -386,12 +386,11 @@ void ical_respond(long msgnum, char *partnum, char *action) {
 
        memset(&ird, 0, sizeof ird);
        strcpy(ird.desired_partnum, partnum);
-       mime_parser(msg->cm_fields[eMesageText],
-               NULL,
-               *ical_locate_part,              /* callback function */
-               NULL, NULL,
-               (void *) &ird,                  /* user data */
-               0
+       mime_parser(CM_RANGE(msg, eMesageText),
+                   *ical_locate_part,          /* callback function */
+                   NULL, NULL,
+                   (void *) &ird,                      /* user data */
+                   0
        );
 
        /* We're done with the incoming message, because we now have a
@@ -642,12 +641,11 @@ int ical_update_my_calendar_with_reply(icalcomponent *cal) {
                return(2);                      /* internal error */
        }
        oec.c = NULL;
-       mime_parser(msg->cm_fields[eMesageText],
-               NULL,
-               *ical_locate_original_event,    /* callback function */
-               NULL, NULL,
-               &oec,                           /* user data */
-               0
+       mime_parser(CM_RANGE(msg, eMesageText),
+                   *ical_locate_original_event,        /* callback function */
+                   NULL, NULL,
+                   &oec,                               /* user data */
+                   0
        );
        CM_Free(msg);
 
@@ -729,13 +727,12 @@ void ical_handle_rsvp(long msgnum, char *partnum, char *action) {
 
        memset(&ird, 0, sizeof ird);
        strcpy(ird.desired_partnum, partnum);
-       mime_parser(msg->cm_fields[eMesageText],
-               NULL,
-               *ical_locate_part,              /* callback function */
-               NULL, NULL,
-               (void *) &ird,                  /* user data */
-               0
-       );
+       mime_parser(CM_RANGE(msg, eMesageText),
+                   *ical_locate_part,          /* callback function */
+                   NULL, NULL,
+                   (void *) &ird,                      /* user data */
+                   0
+               );
 
        /* We're done with the incoming message, because we now have a
         * calendar object in memory.
@@ -1161,12 +1158,11 @@ void ical_hunt_for_conflicts_backend(long msgnum, void *data) {
        if (msg == NULL) return;
        memset(&ird, 0, sizeof ird);
        strcpy(ird.desired_partnum, "_HUNT_");
-       mime_parser(msg->cm_fields[eMesageText],
-               NULL,
-               *ical_locate_part,              /* callback function */
-               NULL, NULL,
-               (void *) &ird,                  /* user data */
-               0
+       mime_parser(CM_RANGE(msg, eMesageText),
+                   *ical_locate_part,          /* callback function */
+                   NULL, NULL,
+                   (void *) &ird,                      /* user data */
+                   0
        );
        CM_Free(msg);
 
@@ -1230,13 +1226,12 @@ void ical_conflicts(long msgnum, char *partnum) {
 
        memset(&ird, 0, sizeof ird);
        strcpy(ird.desired_partnum, partnum);
-       mime_parser(msg->cm_fields[eMesageText],
-               NULL,
-               *ical_locate_part,              /* callback function */
-               NULL, NULL,
-               (void *) &ird,                  /* user data */
-               0
-       );
+       mime_parser(CM_RANGE(msg, eMesageText),
+                   *ical_locate_part,          /* callback function */
+                   NULL, NULL,
+                   (void *) &ird,                      /* user data */
+                   0
+               );
 
        CM_Free(msg);
 
@@ -1411,13 +1406,12 @@ void ical_freebusy_backend(long msgnum, void *data) {
        if (msg == NULL) return;
        memset(&ird, 0, sizeof ird);
        strcpy(ird.desired_partnum, "_HUNT_");
-       mime_parser(msg->cm_fields[eMesageText],
-               NULL,
-               *ical_locate_part,              /* callback function */
-               NULL, NULL,
-               (void *) &ird,                  /* user data */
-               0
-       );
+       mime_parser(CM_RANGE(msg, eMesageText),
+                   *ical_locate_part,          /* callback function */
+                   NULL, NULL,
+                   (void *) &ird,                      /* user data */
+                   0
+               );
        CM_Free(msg);
 
        if (ird.cal) {
@@ -1612,12 +1606,11 @@ void ical_getics_backend(long msgnum, void *data) {
        if (msg == NULL) return;
        memset(&ird, 0, sizeof ird);
        strcpy(ird.desired_partnum, "_HUNT_");
-       mime_parser(msg->cm_fields[eMesageText],
-               NULL,
-               *ical_locate_part,              /* callback function */
-               NULL, NULL,
-               (void *) &ird,                  /* user data */
-               0
+       mime_parser(CM_RANGE(msg, eMesageText),
+                   *ical_locate_part,          /* callback function */
+                   NULL, NULL,
+                   (void *) &ird,                      /* user data */
+                   0
        );
        CM_Free(msg);
 
@@ -2413,13 +2406,12 @@ int ical_obj_beforesave(struct CtdlMessage *msg, recptypes *recp)
        }
 
        /* Do all of our lovely back-end parsing */
-       mime_parser(msg->cm_fields[eMesageText],
-               NULL,
-               *ical_obj_beforesave_backend,
-               NULL, NULL,
-               (void *)msg,
-               0
-       );
+       mime_parser(CM_RANGE(msg, eMesageText),
+                   *ical_obj_beforesave_backend,
+                   NULL, NULL,
+                   (void *)msg,
+                   0
+               );
 
        return(0);
 }
@@ -2482,13 +2474,12 @@ int ical_obj_aftersave(struct CtdlMessage *msg, recptypes *recp)
        if (CM_IsEmpty(msg, eMesageText)) return(1);
        
        /* Now recurse through it looking for our icalendar data */
-       mime_parser(msg->cm_fields[eMesageText],
-               NULL,
-               *ical_obj_aftersave_backend,
-               NULL, NULL,
-               NULL,
-               0
-       );
+       mime_parser(CM_RANGE(msg, eMesageText),
+                   *ical_obj_aftersave_backend,
+                   NULL, NULL,
+                   NULL,
+                   0
+               );
 
        return(0);
 }
index f9998937183a50652b1030986ec98440947497f7..f010b37dcfc59ad13a617fd472172b383e7c3893 100644 (file)
@@ -752,7 +752,7 @@ void imap_fetch_body(long msgnum, ConstStr item, int is_peek) {
         * (Note value of 1 passed as 'dont_decode' so client gets it encoded)
         */
        else {
-               mime_parser(msg->cm_fields[eMesageText], NULL,
+               mime_parser(CM_RANGE(msg, eMesageText),
                            *imap_load_part, NULL, NULL,
                            section,
                            1
@@ -1017,13 +1017,12 @@ void imap_fetch_bodystructure (long msgnum, const char *item,
 
        /* For messages already stored in RFC822 format, we have to parse. */
        IAPuts("BODYSTRUCTURE ");
-       mime_parser(msg->cm_fields[eMesageText],
-                       NULL,
-                       *imap_fetch_bodystructure_part, /* part */
-                       *imap_fetch_bodystructure_pre,  /* pre-multi */
-                       *imap_fetch_bodystructure_post, /* post-multi */
-                       NULL,
-                       1);     /* don't decode -- we want it as-is */
+       mime_parser(CM_RANGE(msg, eMesageText),
+                   *imap_fetch_bodystructure_part,     /* part */
+                   *imap_fetch_bodystructure_pre,      /* pre-multi */
+                   *imap_fetch_bodystructure_post,     /* post-multi */
+                   NULL,
+                   1); /* don't decode -- we want it as-is */
 }
 
 
index a250c8ccd63a652d7a317d1f33ad99ee7256a1c5..cb21be03ddd55e6448a9e2421f038be56af5e02c 100644 (file)
@@ -130,12 +130,11 @@ int serv_notes_beforesave(struct CtdlMessage *msg, recptypes *recp)
 
        /* Modern clients are using vNote format.  Check for one... */
 
-       mime_parser(msg->cm_fields[eMesageText],
-               NULL,
-               *notes_extract_vnote,
-               NULL, NULL,
-               &v,             /* user data ptr - put the vnote here */
-               0
+       mime_parser(CM_RANGE(msg, eMesageText),
+                   *notes_extract_vnote,
+                   NULL, NULL,
+                   &v,         /* user data ptr - put the vnote here */
+                   0
        );
 
        if (v == NULL) return(0);       /* no vNotes were found in this message */
index 3d62c83d0b710e97442ab2e25f1af64b4070a0f0..2722b3bca3a6da1ac6d854a1d743eab0819a7fc4 100644 (file)
@@ -375,12 +375,11 @@ int vcard_upload_beforesave(struct CtdlMessage *msg, recptypes *recp) {
 
        if (CM_IsEmpty(msg, eMesageText)) return(0);
 
-       mime_parser(msg->cm_fields[eMesageText],
-               NULL,
-               *vcard_extract_vcard,
-               NULL, NULL,
-               &v,             /* user data ptr - put the vcard here */
-               0
+       mime_parser(CM_RANGE(msg, eMesageText),
+                   *vcard_extract_vcard,
+                   NULL, NULL,
+                   &v,         /* user data ptr - put the vcard here */
+                   0
        );
 
        if (v == NULL) return(0);       /* no vCards were found in this message */
@@ -1107,13 +1106,12 @@ void dvca_callback(long msgnum, void *userdata) {
 
        msg = CtdlFetchMessage(msgnum, 1);
        if (msg == NULL) return;
-       mime_parser(msg->cm_fields[eMesageText],
-               NULL,
-               *dvca_mime_callback,    /* callback function */
-               NULL, NULL,
-               NULL,                   /* user data */
-               0
-       );
+       mime_parser(CM_RANGE(msg, eMesageText),
+                   *dvca_mime_callback,        /* callback function */
+                   NULL, NULL,
+                   NULL,                       /* user data */
+                   0
+               );
        CM_Free(msg);
 }
 
index ccfc77b7e66495e3c274d32a9a825798a6a1056f..36e010b37ee627a01cef07e187b7d12ec2d6fb8f 100644 (file)
@@ -407,7 +407,7 @@ void wiki_history(char *pagename) {
 
        
        cprintf("%d Revision history for '%s'\n", LISTING_FOLLOWS, pagename);
-       mime_parser(msg->cm_fields[eMesageText], NULL, *wiki_history_callback, NULL, NULL, NULL, 0);
+       mime_parser(CM_RANGE(msg, eMesageText), *wiki_history_callback, NULL, NULL, NULL, 0);
        cprintf("000\n");
 
        CM_Free(msg);
@@ -580,7 +580,7 @@ void wiki_rev(char *pagename, char *rev, char *operation)
        hecbd.stop_when = rev;
        striplt(hecbd.stop_when);
 
-       mime_parser(msg->cm_fields[eMesageText], NULL, *wiki_rev_callback, NULL, NULL, (void *)&hecbd, 0);
+       mime_parser(CM_RANGE(msg, eMesageText), *wiki_rev_callback, NULL, NULL, (void *)&hecbd, 0);
        CM_Free(msg);
 
        /* Were we successful? */
index d1270f4d1e75b18b0fa9e744eed4e821d56663e9..57eb0d21386380c0d6ff080d2830c21148c624b9 100644 (file)
@@ -1584,11 +1584,10 @@ int CtdlOutputMsg(long msg_num,         /* message number (local) to fetch */
        if (section) if (!IsEmptyStr(section)) if (strcmp(section, "0")) {
                memset(&encap, 0, sizeof encap);
                safestrncpy(encap.desired_section, section, sizeof encap.desired_section);
-               mime_parser(TheMessage->cm_fields[eMesageText],
-                       NULL,
-                       *extract_encapsulated_message,
-                       NULL, NULL, (void *)&encap, 0
-               );
+               mime_parser(CM_RANGE(TheMessage, eMesageText),
+                           *extract_encapsulated_message,
+                           NULL, NULL, (void *)&encap, 0
+                       );
 
                if ((Author != NULL) && (*Author == NULL))
                {
@@ -2004,7 +2003,6 @@ int CtdlOutputPreLoadedMsg(
 ) {
        struct CitContext *CCC = CC;
        int i;
-       char *mptr = NULL;
        const char *nl; /* newline string */
        struct ma_info ma;
 
@@ -2051,8 +2049,8 @@ int CtdlOutputPreLoadedMsg(
                                ERROR + RESOURCE_BUSY);
                } else {
                        /* Parse the message text component */
-                       mptr = TheMessage->cm_fields[eMesageText];
-                       mime_parser(mptr, NULL, *mime_download, NULL, NULL, NULL, 0);
+                       mime_parser(CM_RANGE(TheMessage, eMesageText),
+                                   *mime_download, NULL, NULL, NULL, 0);
                        /* If there's no file open by this time, the requested
                         * section wasn't found, so print an error
                         */
@@ -2078,8 +2076,8 @@ int CtdlOutputPreLoadedMsg(
                        /* Parse the message text component */
                        int found_it = 0;
 
-                       mptr = TheMessage->cm_fields[eMesageText];
-                       mime_parser(mptr, NULL, *mime_spew_section, NULL, NULL, (void *)&found_it, 0);
+                       mime_parser(CM_RANGE(TheMessage, eMesageText),
+                                   *mime_spew_section, NULL, NULL, (void *)&found_it, 0);
                        /* If section wasn't found, print an error
                         */
                        if (!found_it) {
@@ -2176,9 +2174,8 @@ START_TEXT:
        /* Tell the client about the MIME parts in this message */
        if (TheMessage->cm_format_type == FMT_RFC822) {
                if ( (mode == MT_CITADEL) || (mode == MT_MIME) ) {
-                       mptr = TheMessage->cm_fields[eMesageText];
                        memset(&ma, 0, sizeof(struct ma_info));
-                       mime_parser(mptr, NULL,
+                       mime_parser(CM_RANGE(TheMessage, eMesageText),
                                (do_proto ? *list_this_part : NULL),
                                (do_proto ? *list_this_pref : NULL),
                                (do_proto ? *list_this_suff : NULL),
@@ -2217,12 +2214,10 @@ START_TEXT:
         * message to the reader's screen width.
         */
        if (TheMessage->cm_format_type == FMT_CITADEL) {
-               mptr = TheMessage->cm_fields[eMesageText];
-
                if (mode == MT_MIME) {
                        cprintf("Content-type: text/x-citadel-variformat\n\n");
                }
-               memfmout(mptr, nl);
+               memfmout(TheMessage->cm_fields[eMesageText], nl);
        }
 
        /* If the message on disk is format 4 (MIME), we've gotta hand it
@@ -2238,17 +2233,17 @@ START_TEXT:
                        strcpy(ma.chosen_part, "1");
                        ma.chosen_pref = 9999;
                        ma.dont_decode = CCC->msg4_dont_decode;
-                       mime_parser(mptr, NULL,
-                               *choose_preferred, *fixed_output_pre,
-                               *fixed_output_post, (void *)&ma, 1);
-                       mime_parser(mptr, NULL,
-                               *output_preferred, NULL, NULL, (void *)&ma, 1);
+                       mime_parser(CM_RANGE(TheMessage, eMesageText),
+                                   *choose_preferred, *fixed_output_pre,
+                                   *fixed_output_post, (void *)&ma, 1);
+                       mime_parser(CM_RANGE(TheMessage, eMesageText),
+                                   *output_preferred, NULL, NULL, (void *)&ma, 1);
                }
                else {
                        ma.use_fo_hooks = 1;
-                       mime_parser(mptr, NULL,
-                               *fixed_output, *fixed_output_pre,
-                               *fixed_output_post, (void *)&ma, 0);
+                       mime_parser(CM_RANGE(TheMessage, eMesageText),
+                                   *fixed_output, *fixed_output_pre,
+                                   *fixed_output_post, (void *)&ma, 0);
                }
 
        }
index a9a4eaba47a1ef0848d10b8c7138014d11f074b5..aecdb18f6c9525dce5ea8578f464b39ff152006b 100644 (file)
@@ -146,6 +146,8 @@ void CM_FreeContents   (struct CtdlMessage *msg);
 int  CM_IsValidMsg     (struct CtdlMessage *msg);
 
 #define CM_KEY(Message, 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]
 
 void CtdlSerializeMessage(struct ser_ret *, struct CtdlMessage *);
 void ReplicationChecks(struct CtdlMessage *);