Clean up some of the page generation logic in www_msgs.c.

More application of stralloc.  Needs to be tested.  :-)

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
This commit is contained in:
Dan Cross 2018-10-11 20:43:04 +00:00 committed by Andrew Pamment
parent 0a91165b07
commit 37bcd31ff2

View File

@ -91,9 +91,7 @@ char *www_msgs_arealist(struct user_record *user) {
char *www_msgs_messagelist(struct user_record *user, int conference, int area, int skip) { char *www_msgs_messagelist(struct user_record *user, int conference, int area, int skip) {
struct msg_headers *mhrs; struct msg_headers *mhrs;
char *page; stralloc page = EMPTY_STRALLOC;
int max_len;
int len;
char buffer[4096]; char buffer[4096];
int i; int i;
struct tm msg_date; struct tm msg_date;
@ -109,51 +107,32 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
if (conference < 0 || conference >= conf.mail_conference_count || area < 0 || area >= conf.mail_conferences[conference]->mail_area_count) { if (conference < 0 || conference >= conf.mail_conference_count || area < 0 || area >= conf.mail_conferences[conference]->mail_area_count) {
return NULL; return NULL;
} }
page = (char *)malloz(4096); stralloc_copys(&page, "<div class=\"content-header\"><h2>");
max_len = 4096; stralloc_cats(&page, conf.mail_conferences[conference]->name);
len = 0; stralloc_cats(&page, " - ");
stralloc_cats(&page, conf.mail_conferences[conference]->mail_areas[area]->name);
sprintf(buffer, "<div class=\"content-header\"><h2>%s - %s</h2></div>\n", conf.mail_conferences[conference]->name, conf.mail_conferences[conference]->mail_areas[area]->name); stralloc_cats(&page, "</h2></div>\n");
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) { if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) {
sprintf(buffer, "<div class=\"button\"><a href=\"%smsgs/new/%d/%d\">New Message</a></div>\n", conf.www_url, conference, area); stralloc_cats(&page, "<div class=\"button\"><a href=\"");
if (len + strlen(buffer) > max_len - 1) { stralloc_cats(&page, conf.www_url);
max_len += 4096; stralloc_cats(&page, "msgs/new/");
page = (char *)realloc(page, max_len); stralloc_cat_long(&page, conference);
} stralloc_append1(&page, '/');
strcat(page, buffer); stralloc_cat_long(&page, area);
len += strlen(buffer); stralloc_cats(&page, "\">New Message</a></div>\n");
} }
mhrs = read_message_headers(conference, area, user, 0); mhrs = read_message_headers(conference, area, user, 0);
if (mhrs == NULL) { if (mhrs == NULL) {
sprintf(buffer, "<h3>No Messages</h3>\n"); stralloc_cats(&page, "<h3>No Messages</h3>\n");
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
return page;
} }
sprintf(buffer, "<div class=\"div-table\">\n"); stralloc_cats(&page, "<div class=\"div-table\">\n");
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path);
if (!jb) { if (!jb) {
free(page); free(page.s);
free_message_headers(mhrs); free_message_headers(mhrs);
return NULL; return NULL;
} }
@ -177,21 +156,21 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
subject = www_sanitize(mhrs->msgs[i]->subject); subject = www_sanitize(mhrs->msgs[i]->subject);
if (msgbase_is_flagged(user, conference, area, mhrs->msgs[i]->msg_h->MsgNum)) { if (msgbase_is_flagged(user, conference, area, mhrs->msgs[i]->msg_h->MsgNum)) {
if (conf.date_style == 1) { if (conf.date_style == 1) {
sprintf(buffer, "<div class=\"msg-summary-flag\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); snprintf(buffer, sizeof buffer, "<div class=\"msg-summary-flag\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100);
} else { } else {
sprintf(buffer, "<div class=\"msg-summary-flag\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); snprintf(buffer, sizeof buffer, "<div class=\"msg-summary-flag\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
} }
} else if (mhrs->msgs[i]->msg_h->MsgNum > jlr.HighReadMsg) { } else if (mhrs->msgs[i]->msg_h->MsgNum > jlr.HighReadMsg) {
if (conf.date_style == 1) { if (conf.date_style == 1) {
sprintf(buffer, "<div class=\"msg-summary\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); snprintf(buffer, sizeof buffer, "<div class=\"msg-summary\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100);
} else { } else {
sprintf(buffer, "<div class=\"msg-summary\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); snprintf(buffer, sizeof buffer, "<div class=\"msg-summary\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
} }
} else { } else {
if (conf.date_style == 1) { if (conf.date_style == 1) {
sprintf(buffer, "<div class=\"msg-summary-seen\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); snprintf(buffer, sizeof buffer, "<div class=\"msg-summary-seen\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100);
} else { } else {
sprintf(buffer, "<div class=\"msg-summary-seen\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); snprintf(buffer, sizeof buffer, "<div class=\"msg-summary-seen\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
} }
} }
@ -199,46 +178,28 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
free(from); free(from);
free(subject); free(subject);
if (len + strlen(buffer) > max_len - 1) { stralloc_cats(&page, buffer);
max_len += 4096;
page = (char *)realloc(page, max_len);
} }
strcat(page, buffer); stralloc_cats(&page, "</div>\n");
len += strlen(buffer);
}
sprintf(buffer, "</div>\n");
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
if (skip + 50 <= mhrs->msg_count) { if (skip + 50 <= mhrs->msg_count) {
sprintf(buffer, "<div class=\"msg-summary-next\"><a href=\"%smsgs/%d/%d/?skip=%d\">Next</a></div>\n", conf.www_url, conference, area, skip + 50); snprintf(buffer, sizeof buffer,
if (len + strlen(buffer) > max_len - 1) { "<div class=\"msg-summary-next\"><a href=\"%smsgs/%d/%d/?skip=%d\">Next</a></div>\n",
max_len += 4096; conf.www_url, conference, area, skip + 50);
page = (char *)realloc(page, max_len); stralloc_cats(&page, buffer);
}
strcat(page, buffer);
len += strlen(buffer);
} }
if (skip > 0) { if (skip > 0) {
if (skip - 50 < 0) { if (skip - 50 < 0) {
sprintf(buffer, "<div class=\"msg-summary-prev\"><a href=\"%smsgs/%d/%d/\">Prev</a></div>\n", conf.www_url, conference, area); snprintf(buffer, sizeof buffer, "<div class=\"msg-summary-prev\"><a href=\"%smsgs/%d/%d/\">Prev</a></div>\n", conf.www_url, conference, area);
} else { } else {
sprintf(buffer, "<div class=\"msg-summary-prev\"><a href=\"%smsgs/%d/%d/?skip=%d\">Prev</a></div>\n", conf.www_url, conference, area, skip - 50); snprintf(buffer, sizeof buffer, "<div class=\"msg-summary-prev\"><a href=\"%smsgs/%d/%d/?skip=%d\">Prev</a></div>\n", conf.www_url, conference, area, skip - 50);
} }
if (len + strlen(buffer) > max_len - 1) { stralloc_cats(&page, buffer);
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
} }
stralloc_0(&page);
free_message_headers(mhrs); free_message_headers(mhrs);
return page; return page.s;
} }
char *www_msgs_messageview(struct user_record *user, int conference, int area, int msg) { char *www_msgs_messageview(struct user_record *user, int conference, int area, int msg) {
@ -262,9 +223,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
int z; int z;
struct tm msg_date; struct tm msg_date;
time_t date; time_t date;
char *page; stralloc page = EMPTY_STRALLOC;
int max_len;
int len;
char buffer[4096]; char buffer[4096];
int chars; int chars;
int i; int i;
@ -281,7 +240,9 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
return NULL; return NULL;
} }
if (conf.mail_conferences[conference]->sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->read_sec_level <= user->sec_level) { if (!(conf.mail_conferences[conference]->sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->read_sec_level <= user->sec_level)) {
return NULL;
}
jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path);
if (!jb) { if (!jb) {
return NULL; return NULL;
@ -340,27 +301,13 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
!msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference) && !msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference) &&
!msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference)) { !msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference)) {
if (subject != NULL) {
free(subject); free(subject);
}
if (from != NULL) {
free(from); free(from);
}
if (to != NULL) {
free(to); free(to);
}
if (oaddress != NULL) {
free(oaddress); free(oaddress);
}
if (daddress != NULL) {
free(daddress); free(daddress);
}
if (msgid != NULL) {
free(msgid); free(msgid);
}
if (replyid != NULL) {
free(replyid); free(replyid);
}
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb); free(jb);
return NULL; return NULL;
@ -385,224 +332,124 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb); free(jb);
page = (char *)malloz(4096); stralloc_copys(&page, "<div class=\"content-header\"><a href=\"");
max_len = 4096; stralloc_cats(&page, conf.www_url);
len = 0; stralloc_cats(&page, "msgs/");
stralloc_cat_long(&page, conference);
sprintf(buffer, "<div class=\"content-header\"><a href=\"%smsgs/%d/%d\"><h2>%s - %s</h2></a></div>\n", conf.www_url, conference, area, conf.mail_conferences[conference]->name, conf.mail_conferences[conference]->mail_areas[area]->name); stralloc_append1(&page, '/');
if (len + strlen(buffer) > max_len - 1) { stralloc_cat_long(&page, area);
max_len += 4096; stralloc_cats(&page, "\"><h2>");
page = (char *)realloc(page, max_len); stralloc_cats(&page, conf.mail_conferences[conference]->name);
} stralloc_cats(&page, " - ");
strcat(page, buffer); stralloc_cats(&page, conf.mail_conferences[conference]->mail_areas[area]->name);
len += strlen(buffer); stralloc_cats(&page, "</h2></a></div>\n");
if (msgbase_is_flagged(user, conference, area, msg)) { if (msgbase_is_flagged(user, conference, area, msg)) {
sprintf(buffer, "<div class=\"msg-view-header-flagged\">\n"); stralloc_cats(&page, "<div class=\"msg-view-header-flagged\">\n");
} else { } else {
sprintf(buffer, "<div class=\"msg-view-header\">\n"); stralloc_cats(&page, "<div class=\"msg-view-header\">\n");
} }
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
subject_s = www_sanitize(subject); subject_s = www_sanitize(subject);
sprintf(buffer, "<div class=\"msg-view-subject\">%s</div>\n", subject_s); stralloc_cats(&page, "<div class=\"msg-view-subject\">");
if (len + strlen(buffer) > max_len - 1) { stralloc_cats(&page, subject_s);
max_len += 4096; stralloc_cats(&page, "</div>\n");
page = (char *)realloc(page, max_len);
}
free(subject_s); free(subject_s);
strcat(page, buffer);
len += strlen(buffer);
from_s = www_sanitize(from); from_s = www_sanitize(from);
if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_LOCAL_AREA && oaddress != NULL) { if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_LOCAL_AREA && oaddress != NULL) {
if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) { if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) {
sprintf(buffer, "<div class=\"msg-view-from\">From: %s (@%s)</div>\n", from_s, oaddress); snprintf(buffer, sizeof buffer, "<div class=\"msg-view-from\">From: %s (@%s)</div>\n", from_s, oaddress);
} else if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) { } else if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) {
nodeno = parse_fido_addr(oaddress); nodeno = parse_fido_addr(oaddress);
if (nodeno != NULL) { if (nodeno != NULL) {
nodename = nl_get_bbsname(nodeno, conf.mail_conferences[conference]->domain); nodename = nl_get_bbsname(nodeno, conf.mail_conferences[conference]->domain);
if (strcmp(nodename, "Unknown") == 0) { if (strcmp(nodename, "Unknown") == 0) {
sprintf(buffer, "<div class=\"msg-view-from\">From: %s (%s)</div>\n", from_s, oaddress); snprintf(buffer, sizeof buffer, "<div class=\"msg-view-from\">From: %s (%s)</div>\n", from_s, oaddress);
} else { } else {
sprintf(buffer, "<div class=\"msg-view-from\">From: %s (<span class=\"bbsname\">%s</span> - %s)</div>\n", from_s, nodename, oaddress); snprintf(buffer, sizeof buffer, "<div class=\"msg-view-from\">From: %s (<span class=\"bbsname\">%s</span> - %s)</div>\n", from_s, nodename, oaddress);
} }
free(nodename); free(nodename);
free(nodeno); free(nodeno);
} else { } else {
sprintf(buffer, "<div class=\"msg-view-from\">From: %s (%s)</div>\n", from_s, oaddress); snprintf(buffer, sizeof buffer, "<div class=\"msg-view-from\">From: %s (%s)</div>\n", from_s, oaddress);
} }
} else { } else {
sprintf(buffer, "<div class=\"msg-view-from\">From: %s (%s)</div>\n", from_s, oaddress); snprintf(buffer, sizeof buffer, "<div class=\"msg-view-from\">From: %s (%s)</div>\n", from_s, oaddress);
} }
} else { } else {
sprintf(buffer, "<div class=\"msg-view-from\">From: %s</div>\n", from_s); snprintf(buffer, sizeof buffer, "<div class=\"msg-view-from\">From: %s</div>\n", from_s);
} }
free(from_s); free(from_s);
if (len + strlen(buffer) > max_len - 1) { stralloc_cats(&page, buffer);
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
to_s = www_sanitize(to); to_s = www_sanitize(to);
sprintf(buffer, "<div class=\"msg-view-to\">To: %s</div>\n", to_s); stralloc_cats(&page, "<div class=\"msg-view-to\">To: ");
if (len + strlen(buffer) > max_len - 1) { stralloc_cats(&page, to_s);
max_len += 4096; stralloc_cats(&page, "</div>\n");
page = (char *)realloc(page, max_len);
}
free(to_s); free(to_s);
strcat(page, buffer);
len += strlen(buffer);
date = (time_t)jmh.DateWritten; date = (time_t)jmh.DateWritten;
gmtime_r(&date, &msg_date); gmtime_r(&date, &msg_date);
if (conf.date_style == 1) { if (conf.date_style == 1) {
sprintf(buffer, "<div class=\"msg-view-date\">Date: %.2d:%.2d %.2d-%.2d-%.2d</div>\n", msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); snprintf(buffer, sizeof buffer, "<div class=\"msg-view-date\">Date: %.2d:%.2d %.2d-%.2d-%.2d</div>\n", msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100);
} else { } else {
sprintf(buffer, "<div class=\"msg-view-date\">Date: %.2d:%.2d %.2d-%.2d-%.2d</div>\n", msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); snprintf(buffer, sizeof buffer, "<div class=\"msg-view-date\">Date: %.2d:%.2d %.2d-%.2d-%.2d</div>\n", msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
} }
if (len + strlen(buffer) > max_len - 1) { stralloc_cats(&page, buffer);
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
sprintf(buffer, "<div class=\"msg-view-options\"><a href=\"%smsgs/flag/%d/%d/%d\"><img src=\"%sstatic/flag.png\" /></a></div>", conf.www_url, conference, area, msg, conf.www_url); snprintf(buffer, sizeof buffer, "<div class=\"msg-view-options\"><a href=\"%smsgs/flag/%d/%d/%d\"><img src=\"%sstatic/flag.png\" /></a></div>", conf.www_url, conference, area, msg, conf.www_url);
if (len + strlen(buffer) > max_len - 1) { stralloc_cats(&page, buffer);
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
sprintf(buffer, "</div>\n"); stralloc_cats(&page, "</div>\n");
if (len + strlen(buffer) > max_len - 1) { stralloc_cats(&page, "<div id=\"msgbody\">\n");
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
sprintf(buffer, "<div id=\"msgbody\">\n");
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
aha_text = (char *)malloz(jmh.TxtLen + 1); aha_text = strndup(body, jmh.TxtLen);
memcpy(aha_text, body, jmh.TxtLen);
aha_text[jmh.TxtLen] = '\0';
aha_out = aha(aha_text); aha_out = aha(aha_text);
while (len + strlen(aha_out) > max_len - 1) { stralloc_cats(&page, aha_out);
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, aha_out);
len += strlen(aha_out);
free(aha_out); free(aha_out);
free(aha_text); free(aha_text);
sprintf(buffer, "</div>\n"); stralloc_cats(&page, "</div>\n");
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
sprintf(buffer, "<div class=\"msg-reply-form\">\n"); stralloc_cats(&page, "<div class=\"msg-reply-form\">\n");
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
if (conf.mail_conferences[conference]->mail_areas[area]->write_sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) { if (conf.mail_conferences[conference]->mail_areas[area]->write_sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) {
sprintf(buffer, "<h3>Reply</h3>\n"); stralloc_cats(&page, "<h3>Reply</h3>\n");
if (len + strlen(buffer) > max_len - 1) { stralloc_cats(&page, "<form action=\"");
max_len += 4096; stralloc_cats(&page, conf.www_url);
page = (char *)realloc(page, max_len); stralloc_cats(&page, "msgs/\" method=\"POST\" enctype=\"application/x-www-form-urlencoded;charset=UTF-8\">\n");
}
strcat(page, buffer);
len += strlen(buffer);
sprintf(buffer, "<form action=\"%smsgs/\" method=\"POST\" enctype=\"application/x-www-form-urlencoded;charset=UTF-8\">\n", conf.www_url);
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
sprintf(buffer, "<input type=\"hidden\" name=\"conference\" value=\"%d\" />\n", conference); stralloc_cats(&page, "<input type=\"hidden\" name=\"conference\" value=\"");
if (len + strlen(buffer) > max_len - 1) { stralloc_cat_long(&page, conference);
max_len += 4096; stralloc_cats(&page, "\" />\n");
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
sprintf(buffer, "<input type=\"hidden\" name=\"area\" value=\"%d\" />\n", area);
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
sprintf(buffer, "<input type=\"hidden\" name=\"replyid\" value=\"%s\" />\n", msgid); stralloc_cats(&page, "<input type=\"hidden\" name=\"area\" value=\"");
if (len + strlen(buffer) > max_len - 1) { stralloc_cat_long(&page, area);
max_len += 4096; stralloc_cats(&page, "\" />\n");
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
sprintf(buffer, "To : <input type=\"text\" name=\"recipient\" value=\"%s\" /><br />\n", from); stralloc_cats(&page, "<input type=\"hidden\" name=\"replyid\" value=\"");
if (len + strlen(buffer) > max_len - 1) { stralloc_cats(&page, msgid);
max_len += 4096; stralloc_cats(&page, "\" />\n");
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
stralloc_cats(&page, "To : <input type=\"text\" name=\"recipient\" value=\"");
stralloc_cats(&page, from);
stralloc_cats(&page, "\" /><br />\n");
stralloc_cats(&page, "Subject : <input type=\"text\" name=\"subject\" value=\"");
if (strncasecmp(subject, "re:", 3) == 0) { if (strncasecmp(subject, "re:", 3) == 0) {
sprintf(buffer, "Subject : <input type=\"text\" name=\"subject\" value=\"%s\" /><br />\n", subject); stralloc_cats(&page, "RE: ");
} else {
sprintf(buffer, "Subject : <input type=\"text\" name=\"subject\" value=\"RE: %s\" /><br />\n", subject);
} }
if (len + strlen(buffer) > max_len - 1) { stralloc_cats(&page, subject);
max_len += 4096; stralloc_cats(&page, "\" /><br />\n");
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
sprintf(buffer, "<textarea name=\"body\" rows=\"25\" cols=\"79\" wrap=\"soft\" id=\"replybody\">"); stralloc_cats(&page, "<textarea name=\"body\" rows=\"25\" cols=\"79\" wrap=\"soft\" id=\"replybody\">");
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
sprintf(buffer, " %c> ", from[0]); stralloc_append1(&page, ' ');
if (len + strlen(buffer) > max_len - 1) { stralloc_append1(&page, from[0]);
max_len += 4096; stralloc_cats(&page, "> ");
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
replybody = (char *)malloz(strlen(body) + 1); replybody = (char *)malloz(strlen(body) + 1);
@ -629,80 +476,34 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
for (i = 0; i < strlen(body2); i++) { for (i = 0; i < strlen(body2); i++) {
if (body2[i] == '\r') { if (body2[i] == '\r') {
sprintf(buffer, "\n %c> ", from[0]); snprintf(buffer, sizeof buffer, "\n %c> ", from[0]);
chars = 0; chars = 0;
} else if (chars == 73) { } else if (chars == 73) {
sprintf(buffer, "\n %c> %c", from[0], body2[i]); snprintf(buffer, sizeof buffer, "\n %c> %c", from[0], body2[i]);
chars = 1; chars = 1;
} else { } else {
sprintf(buffer, "%c", body2[i]); snprintf(buffer, sizeof buffer, "%c", body2[i]);
chars++; chars++;
} }
if (len + strlen(buffer) > max_len - 1) { stralloc_cats(&page, buffer);
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
} }
free(body2); free(body2);
sprintf(buffer, "</textarea>\n<br />"); stralloc_cats(&page, "</textarea>\n<br />");
if (len + strlen(buffer) > max_len - 1) { stralloc_cats(&page, "<input type=\"submit\" name=\"submit\" value=\"Reply\" />\n<br />");
max_len += 4096; stralloc_cats(&page, "</form>\n");
page = (char *)realloc(page, max_len); stralloc_cats(&page, "</div>\n");
} }
strcat(page, buffer); stralloc_0(&page);
len += strlen(buffer);
sprintf(buffer, "<input type=\"submit\" name=\"submit\" value=\"Reply\" />\n<br />");
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
sprintf(buffer, "</form>\n");
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
sprintf(buffer, "</div>\n");
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
}
if (subject != NULL) {
free(subject); free(subject);
}
if (from != NULL) {
free(from); free(from);
}
if (to != NULL) {
free(to); free(to);
}
if (oaddress != NULL) {
free(oaddress); free(oaddress);
}
if (daddress != NULL) {
free(daddress); free(daddress);
}
if (msgid != NULL) {
free(msgid); free(msgid);
}
if (replyid != NULL) {
free(replyid); free(replyid);
}
return page; return page.s;
} else {
return NULL;
}
} }
static char *www_wordwrap(char *content, int cutoff) { static char *www_wordwrap(char *content, int cutoff) {
@ -899,12 +700,14 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) { if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) {
if (conf.mail_conferences[conference]->fidoaddr->point) { if (conf.mail_conferences[conference]->fidoaddr->point) {
sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[conference]->fidoaddr->zone, snprintf(buffer, sizeof buffer, "%d:%d/%d.%d",
conf.mail_conferences[conference]->fidoaddr->zone,
conf.mail_conferences[conference]->fidoaddr->net, conf.mail_conferences[conference]->fidoaddr->net,
conf.mail_conferences[conference]->fidoaddr->node, conf.mail_conferences[conference]->fidoaddr->node,
conf.mail_conferences[conference]->fidoaddr->point); conf.mail_conferences[conference]->fidoaddr->point);
} else { } else {
sprintf(buffer, "%d:%d/%d", conf.mail_conferences[conference]->fidoaddr->zone, snprintf(buffer, sizeof buffer, "%d:%d/%d",
conf.mail_conferences[conference]->fidoaddr->zone,
conf.mail_conferences[conference]->fidoaddr->net, conf.mail_conferences[conference]->fidoaddr->net,
conf.mail_conferences[conference]->fidoaddr->node); conf.mail_conferences[conference]->fidoaddr->node);
} }
@ -914,7 +717,8 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
jsf.Buffer = (char *)buffer; jsf.Buffer = (char *)buffer;
JAM_PutSubfield(jsp, &jsf); JAM_PutSubfield(jsp, &jsf);
sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[conference]->fidoaddr->zone, snprintf(buffer, sizeof buffer, "%d:%d/%d.%d %08lx",
conf.mail_conferences[conference]->fidoaddr->zone,
conf.mail_conferences[conference]->fidoaddr->net, conf.mail_conferences[conference]->fidoaddr->net,
conf.mail_conferences[conference]->fidoaddr->node, conf.mail_conferences[conference]->fidoaddr->node,
conf.mail_conferences[conference]->fidoaddr->point, conf.mail_conferences[conference]->fidoaddr->point,
@ -936,7 +740,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
jmh.ReplyCRC = JAM_Crc32(buffer, strlen(replyid)); jmh.ReplyCRC = JAM_Crc32(buffer, strlen(replyid));
} }
} else if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) { } else if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) {
sprintf(buffer, "%d", conf.mail_conferences[conference]->maginode); snprintf(buffer, sizeof buffer, "%d", conf.mail_conferences[conference]->maginode);
jsf.LoID = JAMSFLD_OADDRESS; jsf.LoID = JAMSFLD_OADDRESS;
jsf.HiID = 0; jsf.HiID = 0;
jsf.DatLen = strlen(buffer); jsf.DatLen = strlen(buffer);