]> code.citadel.org Git - citadel.git/blobdiff - webcit/messages.c
* sanitize accesses, so valgrind doesn't moan of uninitialized values
[citadel.git] / webcit / messages.c
index 86b6a7c2f0bfc9754d37613ab647394416489204..2200841f3953a01011ce4b6ff81560a834ee70c5 100644 (file)
@@ -1071,6 +1071,8 @@ void read_message(long msgnum, int printable_view, char *section) {
 
         /** start msg buttons */
 
+       char Urlsep = '?';
+
         if (!printable_view) {
                 wprintf("<p id=\"msg%ld\" class=\"msgbuttons\" >\n",msgnum);
 
@@ -1078,16 +1080,18 @@ void read_message(long msgnum, int printable_view, char *section) {
                if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
                        wprintf("<a href=\"display_enter");
                        if (WC->is_mailbox) {
-                               wprintf("?replyquote=%ld", msgnum);
+                               wprintf("%creplyquote=%ld", Urlsep, msgnum);
+                               Urlsep = '&';
                        }
-                       wprintf("?recp=");
+                       wprintf("%crecp=", Urlsep);
+                       Urlsep = '&';
                        urlescputs(reply_to);
                        if (!IsEmptyStr(m_subject)) {
-                               wprintf("?subject=");
+                               wprintf("%csubject=", Urlsep);
                                if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%%20");
                                urlescputs(m_subject);
                        }
-                       wprintf("?references=");
+                       wprintf("%creferences=", Urlsep);
                        if (!IsEmptyStr(reply_references)) {
                                urlescputs(reply_references);
                                urlescputs("|");
@@ -1101,14 +1105,14 @@ void read_message(long msgnum, int printable_view, char *section) {
                        if (!WC->is_mailbox) {
                                wprintf("<a href=\"display_enter");
                                wprintf("?replyquote=%ld", msgnum);
-                               wprintf("?recp=");
+                               wprintf("&recp=");
                                urlescputs(reply_to);
                                if (!IsEmptyStr(m_subject)) {
-                                       wprintf("?subject=");
+                                       wprintf("&subject=");
                                        if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%%20");
                                        urlescputs(m_subject);
                                }
-                               wprintf("?references=");
+                               wprintf("&references=");
                                if (!IsEmptyStr(reply_references)) {
                                        urlescputs(reply_references);
                                        urlescputs("|");
@@ -1122,16 +1126,16 @@ void read_message(long msgnum, int printable_view, char *section) {
                if (WC->wc_view == VIEW_MAILBOX) {
                        wprintf("<a href=\"display_enter");
                        wprintf("?replyquote=%ld", msgnum);
-                       wprintf("?recp=");
+                       wprintf("&recp=");
                        urlescputs(reply_to);
-                       wprintf("?cc=");
+                       wprintf("&cc=");
                        urlescputs(reply_all);
                        if (!IsEmptyStr(m_subject)) {
-                               wprintf("?subject=");
+                               wprintf("&subject=");
                                if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%%20");
                                urlescputs(m_subject);
                        }
-                       wprintf("?references=");
+                       wprintf("&references=");
                        if (!IsEmptyStr(reply_references)) {
                                urlescputs(reply_references);
                                urlescputs("|");
@@ -1142,7 +1146,7 @@ void read_message(long msgnum, int printable_view, char *section) {
 
                /* Forward */
                if (WC->wc_view == VIEW_MAILBOX) {
-                       wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
+                       wprintf("<a href=\"display_enter?fwdquote=%ld&subject=", msgnum);
                        if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%%20");
                        urlescputs(m_subject);
                        wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Forward"));
@@ -1343,7 +1347,7 @@ ENDBODY:  /* If there are attached submessages, display them now... */
                                || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
                                || (WC->wc_view == VIEW_ADDRESSBOOK)
                        ) {
-                               wprintf("<a href=\"edit_vcard?msgnum=%ld?partnum=%s\">",
+                               wprintf("<a href=\"edit_vcard?msgnum=%ld&partnum=%s\">",
                                        msgnum, vcard_partnum);
                                wprintf("[%s]</a>", _("edit"));
                        }
@@ -1439,7 +1443,7 @@ void mobile_message_view(void) {
   msgnum = StrTol(WC->UrlFragment1);
   output_headers(1, 0, 0, 0, 0, 1);
   begin_burst();
-  do_template("msgcontrols");
+  do_template("msgcontrols", NULL);
   read_message(msgnum,1, "");
   wDumpContent(0);
 }
@@ -1691,8 +1695,8 @@ void pullquote_message(long msgnum, int forward_attachments, int include_headers
                while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
                        int len;
                        len = strlen(buf);
-                       if (buf[len-1] == '\n') buf[--len] = 0;
-                       if (buf[len-1] == '\r') buf[--len] = 0;
+                       if ((len > 0) && (buf[len-1] == '\n')) buf[--len] = 0;
+                       if ((len > 0) && (buf[len-1] == '\r')) buf[--len] = 0;
 
 #ifdef HAVE_ICONV
                        if (ic != (iconv_t)(-1) ) {
@@ -1814,7 +1818,7 @@ void display_summarized(int num) {
        wprintf("<tr id=\"m%ld\" style=\"font-weight:%s;\" "
                "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
                WC->summ[num].msgnum,
-               (WC->summ[num].is_new ? "bold" : "normal"),
+               ((WC->summ[num].is_new) ? "bold" : "normal"),
                WC->summ[num].msgnum
        );
 
@@ -1908,7 +1912,7 @@ void display_addressbook(long msgnum, char alpha) {
                                || (WC->wc_view == VIEW_ADDRESSBOOK)
                        ) {
                                wprintf("<a href=\"edit_vcard?"
-                                       "msgnum=%ld?partnum=%s\">",
+                                       "msgnum=%ld&partnum=%s\">",
                                        msgnum, vcard_partnum);
                                wprintf("[%s]</a>", _("edit"));
                        }
@@ -2116,16 +2120,27 @@ void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
 
                wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
                        addrbook[i].ab_msgnum);
-               wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
+               wprintf("?maxmsgs=1&is_summary=0&alpha=%s\">", bstr("alpha"));
                vcard_n_prettyize(addrbook[i].ab_name);
                escputs(addrbook[i].ab_name);
                wprintf("</a></td>\n");
                ++displayed;
        }
 
+       /* Placeholders for empty columns at end */
+       if ((num_ab % 4) != 0) {
+               for (i=0; i<(4-(num_ab % 4)); ++i) {
+                       wprintf("<td>&nbsp;</td>");
+               }
+       }
+
        wprintf("</tr></table>\n");
        end_tab((num_pages-1), num_pages);
 
+       begin_tab(num_pages, num_pages);
+       /* FIXME there ought to be something here */
+       end_tab(num_pages, num_pages);
+
        for (i=0; i<num_pages; ++i) {
                free(tablabels[i]);
        }
@@ -2134,10 +2149,11 @@ void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
 
 
 
-/**
- * \brief load message pointers from the server
- * \param servcmd the citadel command to send to the citserver
- * \param with_headers what headers???
+/*
+ * load message pointers from the server for a "read messages" operation
+ *
+ * servcmd:            the citadel command to send to the citserver
+ * with_headers:       also include some of the headers with the message numbers (more expensive)
  */
 int load_msg_ptrs(char *servcmd, int with_headers)
 {
@@ -2235,11 +2251,9 @@ int load_msg_ptrs(char *servcmd, int with_headers)
 
 
 typedef int (*QSortFunction) (const void*, const void*);
-/**
- * \brief qsort() compatible function to compare two longs in descending order.
- *
- * \param s1 first number to compare 
- * \param s2 second number to compare
+
+/*
+ * qsort() compatible function to compare two longs in descending order.
  */
 int longcmp_r(const void *s1, const void *s2) {
        long l1;
@@ -2254,11 +2268,8 @@ int longcmp_r(const void *s1, const void *s2) {
 }
 
  
-/**
- * \brief qsort() compatible function to compare two message summary structs by ascending subject.
- *
- * \param s1 first item to compare 
- * \param s2 second item to compare
+/*
+ * qsort() compatible function to compare two message summary structs by ascending subject.
  */
 int summcmp_subj(const void *s1, const void *s2) {
        struct message_summary *summ1;
@@ -2269,11 +2280,8 @@ int summcmp_subj(const void *s1, const void *s2) {
        return strcasecmp(summ1->subj, summ2->subj);
 }
 
-/**
- * \brief qsort() compatible function to compare two message summary structs by descending subject.
- *
- * \param s1 first item to compare 
- * \param s2 second item to compare
+/*
+ * qsort() compatible function to compare two message summary structs by descending subject.
  */
 int summcmp_rsubj(const void *s1, const void *s2) {
        struct message_summary *summ1;
@@ -2284,11 +2292,8 @@ int summcmp_rsubj(const void *s1, const void *s2) {
        return strcasecmp(summ2->subj, summ1->subj);
 }
 
-/**
- * \brief qsort() compatible function to compare two message summary structs by ascending sender.
- *
- * \param s1 first item to compare 
- * \param s2 second item to compare
+/*
+ * qsort() compatible function to compare two message summary structs by ascending sender.
  */
 int summcmp_sender(const void *s1, const void *s2) {
        struct message_summary *summ1;
@@ -2299,11 +2304,8 @@ int summcmp_sender(const void *s1, const void *s2) {
        return strcasecmp(summ1->from, summ2->from);
 }
 
-/**
- * \brief qsort() compatible function to compare two message summary structs by descending sender.
- *
- * \param s1 first item to compare 
- * \param s2 second item to compare
+/*
+ * qsort() compatible function to compare two message summary structs by descending sender.
  */
 int summcmp_rsender(const void *s1, const void *s2) {
        struct message_summary *summ1;
@@ -2314,11 +2316,8 @@ int summcmp_rsender(const void *s1, const void *s2) {
        return strcasecmp(summ2->from, summ1->from);
 }
 
-/**
- * \brief qsort() compatible function to compare two message summary structs by ascending date.
- *
- * \param s1 first item to compare 
- * \param s2 second item to compare
+/*
+ * qsort() compatible function to compare two message summary structs by ascending date.
  */
 int summcmp_date(const void *s1, const void *s2) {
        struct message_summary *summ1;
@@ -2332,11 +2331,8 @@ int summcmp_date(const void *s1, const void *s2) {
        else return 0;
 }
 
-/**
- * \brief qsort() compatible function to compare two message summary structs by descending date.
- *
- * \param s1 first item to compare 
- * \param s2 second item to compare
+/*
+ * qsort() compatible function to compare two message summary structs by descending date.
  */
 int summcmp_rdate(const void *s1, const void *s2) {
        struct message_summary *summ1;
@@ -2374,7 +2370,7 @@ const char* SortIcons[3] = {
        eUnSet
 }; 
 
-/** SortEnum to plain string representation */
+/* SortEnum to plain string representation */
 static const char* SortByStrings[] = {
        "date",
        "rdate",
@@ -2386,7 +2382,7 @@ static const char* SortByStrings[] = {
        "unset"
 };
 
-/** SortEnum to sort-Function Table */
+/* SortEnum to sort-Function Table */
 const QSortFunction SortFuncs[eUnSet] = {
        summcmp_date,
        summcmp_rdate,
@@ -2397,21 +2393,20 @@ const QSortFunction SortFuncs[eUnSet] = {
        summcmp_rdate
 };
 
-/** given a SortEnum, which icon should we choose? */
+/* given a SortEnum, which icon should we choose? */
 const int SortDateToIcon[eUnSet] = { eUp, eDown, eNone, eNone, eNone, eNone, eNone};
 const int SortSubjectToIcon[eUnSet] = { eNone, eNone, eUp, eDown, eNone, eNone, eNone};
 const int SortSenderToIcon[eUnSet] = { eNone, eNone, eNone, eNone, eUp, eDown, eNone};
 
-/** given a SortEnum, which would be the "opposite" search option? */
+/* given a SortEnum, which would be the "opposite" search option? */
 const int DateInvertSortString[eUnSet] =  { eRDate, eDate, eDate, eDate, eDate, eDate, eDate};
 const int SubjectInvertSortString[eUnSet] =  { eSubject, eSubject, eRSubject, eUnSet, eSubject, eSubject, eSubject};
 const int SenderInvertSortString[eUnSet] =  { eSender, eSender, eSender, eSender, eRSender, eUnSet, eSender};
 
 
-/**
- * \Brief Translates sortoption String to its SortEnum representation 
- * \param SortBy string to translate
- * \return the enum matching the string; defaults to RDate
+/*
+ * Translates sortoption String to its SortEnum representation 
+ * returns the enum matching the string; defaults to RDate
  */
 //SortByEnum 
 int StrToESort (const StrBuf *sortby)
@@ -2430,10 +2425,10 @@ int StrToESort (const StrBuf *sortby)
 
 
 
-/**
- * \brief command loop for reading messages
+/*
+ * command loop for reading messages
  *
- * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
+ * Set oper to "readnew" or "readold" or "readfwd" or "headers"
  */
 void readloop(char *oper)
 {
@@ -2466,7 +2461,7 @@ void readloop(char *oper)
        struct wcsession *WCC = WC;     /* This is done to make it run faster; WC is a function */
 
        if (WCC->wc_view == VIEW_WIKI) {
-               sprintf(buf, "wiki?room=%s?page=home", WCC->wc_roomname);
+               sprintf(buf, "wiki?room=%s&page=home", WCC->wc_roomname);
                http_redirect(buf);
                return;
        }
@@ -2487,7 +2482,7 @@ void readloop(char *oper)
        }
 
        SortBy = StrToESort(sortpref_value);
-       /** message board sort */
+       /* message board sort */
        if (SortBy == eReverse) {
                bbs_reverse = 1;
        }
@@ -2497,7 +2492,7 @@ void readloop(char *oper)
 
        output_headers(1, 1, 1, 0, 0, 0);
 
-       /**
+       /*
         * When in summary mode, always show ALL messages instead of just
         * new or old.  Otherwise, show what the user asked for.
         */
@@ -2552,7 +2547,7 @@ void readloop(char *oper)
                SortBy =  eRDate;
        }
 
-       /**
+       /*
         * Are we doing a summary view?  If so, we need to know old messages
         * and new messages, so we can do that pretty boldface thing for the
         * new messages.
@@ -2651,9 +2646,9 @@ void readloop(char *oper)
                        "<table cellspacing=0 style=\"width:100%%\">"
                        "<tr>"
                );
-               wprintf("<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> </th>\n"
-                       "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> </th>\n"
-                       "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> \n"
+               wprintf("<th width=%d%%>%s <a href=\"readfwd?startmsg=1&maxmsgs=9999999&is_summary=1&sortby=%s\"><img border=\"0\" src=\"%s\" /></a> </th>\n"
+                       "<th width=%d%%>%s <a href=\"readfwd?startmsg=1&maxmsgs=9999999&is_summary=1&sortby=%s\"><img border=\"0\" src=\"%s\" /></a> </th>\n"
+                       "<th width=%d%%>%s <a href=\"readfwd?startmsg=1&maxmsgs=9999999&is_summary=1&sortby=%s\"><img border=\"0\" src=\"%s\" /></a> \n"
                        "&nbsp;"
                        "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
                        " onClick=\"CtdlDeleteSelectedMessages(event)\" "
@@ -2716,9 +2711,9 @@ void readloop(char *oper)
                                if (lo < 1) lo = 1;
                                wprintf("<option %s value="
                                        "\"%s"
-                                       "?startmsg=%ld"
-                                       "?maxmsgs=%d"
-                                       "?is_summary=%d\">"
+                                       "&startmsg=%ld"
+                                       "&maxmsgs=%d"
+                                       "&is_summary=%d\">"
                                        "%d-%d</option> \n",
                                        ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
                                        oper,
@@ -2735,9 +2730,9 @@ void readloop(char *oper)
                                if (hi > nummsgs) hi = nummsgs;
                                wprintf("<option %s value="
                                        "\"%s"
-                                       "?startmsg=%ld"
-                                       "?maxmsgs=%d"
-                                       "?is_summary=%d\">"
+                                       "&startmsg=%ld"
+                                       "&maxmsgs=%d"
+                                       "&is_summary=%d\">"
                                        "%d-%d</option> \n",
                                        ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
                                        oper,
@@ -2749,7 +2744,7 @@ void readloop(char *oper)
                }
 
                wprintf("<option value=\"%s?startmsg=%ld"
-                       "?maxmsgs=9999999?is_summary=%d\">",
+                       "&maxmsgs=9999999&is_summary=%d\">",
                        oper,
                        WCC->msgarr[0], is_summary);
                wprintf(_("All"));
@@ -2883,9 +2878,9 @@ void readloop(char *oper)
                                if (lo < 1) lo = 1;
                                wprintf("<option %s value="
                                        "\"%s"
-                                       "?startmsg=%ld"
-                                       "?maxmsgs=%d"
-                                       "?is_summary=%d\">"
+                                       "&startmsg=%ld"
+                                       "&maxmsgs=%d"
+                                       "&is_summary=%d\">"
                                        "%d-%d</option> \n",
                                        ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
                                        oper,
@@ -2902,9 +2897,9 @@ void readloop(char *oper)
                                if (hi > nummsgs) hi = nummsgs;
                                wprintf("<option %s value="
                                        "\"%s"
-                                       "?startmsg=%ld"
-                                       "?maxmsgs=%d"
-                                       "?is_summary=%d\">"
+                                       "&startmsg=%ld"
+                                       "&maxmsgs=%d"
+                                       "&is_summary=%d\">"
                                        "%d-%d</option> \n",
                                        ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
                                        oper,
@@ -2915,8 +2910,8 @@ void readloop(char *oper)
                        }
                }
 
-               wprintf("<option value=\"%s?startmsg=%ld"
-                       "?maxmsgs=9999999?is_summary=%d\">",
+               wprintf("<option value=\"%s&startmsg=%ld"
+                       "&maxmsgs=9999999&is_summary=%d\">",
                        oper,
                        WCC->msgarr[0], is_summary);
                wprintf(_("All"));
@@ -2926,7 +2921,7 @@ void readloop(char *oper)
 
                /** forward/reverse */
                wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
-                       "OnChange=\"location.href='%s?sortby=forward'\"",  
+                       "OnChange=\"location.href='%s&sortby=forward'\"",  
                        (bbs_reverse ? "" : "checked"),
                        oper
                );
@@ -2934,7 +2929,7 @@ void readloop(char *oper)
                wprintf(_("oldest to newest"));
                wprintf("&nbsp;&nbsp;&nbsp;&nbsp;");
                wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
-                       "OnChange=\"location.href='%s?sortby=reverse'\"", 
+                       "OnChange=\"location.href='%s&sortby=reverse'\"", 
                        (bbs_reverse ? "checked" : ""),
                        oper
                );
@@ -3208,6 +3203,7 @@ void post_message(void)
                             ChrPtr(Wikipage),
                             ChrPtr(my_email_addr),
                             ChrPtr(references));
+               FreeStrBuf(&references);
 
                lprintf(9, "%s\n", CmdBuf);
                serv_puts(ChrPtr(CmdBuf));
@@ -3647,6 +3643,7 @@ void display_enter(void)
                                } 
                                sig ++;
                        }
+                       FreeStrBuf(&Sig);
                }
        }
 
@@ -3660,7 +3657,7 @@ void display_enter(void)
         * The following template embeds the TinyMCE richedit control, and automatically
         * transforms the textarea into a richedit textarea.
         */
-       do_template("richedit");
+       do_template("richedit", NULL);
 
        /** Enumerate any attachments which are already in place... */
        wprintf("<div class=\"attachment buttons\"><img src=\"static/diskette_24x.gif\" class=\"imgedit\" > ");