/*
* Extract variables from the URL.
*/
-void addurls(StrBuf *url)
+void ParseURLParams(StrBuf *url)
{
const char *aptr, *bptr, *eptr, *up;
-/// char *buf;
int len, keylen;
urlcontent *u;
struct wcsession *WCC = WC;
if (WCC->urlstrings == NULL)
WCC->urlstrings = NewHash(1, NULL);
-// buf = (char*) malloc (ulen + 1);
-// memcpy(buf, url, ulen);
-/// buf[ulen] = '\0';
eptr = ChrPtr(url) + StrLength(url);
up = ChrPtr(url);
while ((up < eptr) && (!IsEmptyStr(up))) {
while ((aptr < eptr) && (*aptr != '\0') && (*aptr != '='))
aptr++;
if (*aptr != '=') {
- ///free(buf);
return;
}
- ///*aptr = '\0';
aptr++;
bptr = aptr;
while ((bptr < eptr) && (*bptr != '\0')
&& (*bptr != '&') && (*bptr != '?') && (*bptr != ' ')) {
bptr++;
}
- //*bptr = '\0';
keylen = aptr - up - 1; /* -1 -> '=' */
if(keylen > sizeof(u->url_key)) {
lprintf(1, "URLkey to long! [%s]", up);
ChrPtr(u->url_data));
#endif
}
- //free(buf);
}
/*
}
+void put_trailing_javascript(void) {
+ wprintf("%s", ChrPtr(WC->trailing_javascript));
+}
+
/*
* wrap up an HTTP session, closes tags, etc.
*
* print_standard_html_footer should be set to:
- * 0 to transmit only,
- * 1 to append the main menu and closing tags,
- * 2 to append the closing tags only.
+ * 0 - to transmit only,
+ * nonzero - to append the closing tags
*/
void wDumpContent(int print_standard_html_footer)
{
if (print_standard_html_footer) {
- wprintf("</div>\n"); /* end of "text" div */
+ wprintf("</div> <!-- end of 'content' div -->\n");
+ svcallback("TRAILING_JAVASCRIPT", put_trailing_javascript);
do_template("trailing", NULL);
}
free(photosrc);
}
+/*
+ * Generic function to output an arbitrary MIME attachment from
+ * message being composed
+ *
+ * partnum The MIME part to be output
+ * filename Fake filename to give
+ * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
+ */
+void postpart(const char *partnum, const char *filename, int force_download)
+{
+ char content_type[256];
+ int num = atoi(partnum);
+ struct wc_attachment *part = WC->first_attachment;
+
+ while(num && part) {
+ num--;
+ part=part->next;
+ }
+
+ if (part) {
+ if (force_download) {
+ strcpy(content_type, "application/octet-stream");
+ }
+ else {
+ strncpy(content_type, part->content_type, sizeof content_type);
+ }
+ output_headers(0, 0, 0, 0, 0, 0);
+ StrBufAppendBufPlain(WC->WBuf, part->data, part->length, 0);
+ http_transmit_thing(content_type, 0);
+ } else {
+ hprintf("HTTP/1.1 404 %s\n",partnum);
+ output_headers(0, 0, 0, 0, 0, 0);
+ hprintf("Content-Type: text/plain\r\n");
+ wprintf(_("An error occurred while retrieving this part: %s/%s\n"), partnum, filename);
+ end_burst();
+ }
+}
+
+
/*
* Generic function to output an arbitrary MIME part from an arbitrary
* message number on the server.
WCC->upload_length = 0;
WCC->upload = NULL;
WCC->is_mobile = 0;
+ WCC->trailing_javascript = NewStrBuf();
/** Figure out the action */
index[0] = action;
if (!strncasecmp(ChrPtr(ContentType), "application/x-www-form-urlencoded", 33)) {
StrBufCutLeft(content, body_start);
- addurls(content);
+ ParseURLParams(content);
} else if (!strncasecmp(ChrPtr(ContentType), "multipart", 9)) {
content_end = ChrPtr(content) + ContentLength + body_start;
mime_parser(ChrPtr(content), content_end, *upload_handler, NULL, NULL, NULL, 0);
while (pch < pche) {
if ((*pch == '?') || (*pch == '&')) {
StrBufCutLeft(UrlLine, pch - pchs + 1);
- addurls(UrlLine);
+ ParseURLParams(UrlLine);
break;
}
pch ++;
get_serv_info(browser_host, user_agent);
if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
+ begin_burst();
wprintf(_("You are connected to a Citadel "
"server running Citadel %d.%02d. \n"
"In order to run this version of WebCit "
MINIMUM_CIT_VERSION / 100,
MINIMUM_CIT_VERSION % 100
);
+ end_burst();
end_webcit_session();
goto SKIP_ALL_THIS_CRAP;
}
set_selected_language(ChrPtr(Lang));
go_selected_language(); /* set locale */
}
+ get_preference("default_header_charset", &WCC->DefaultCharset);
}
}
}
free(WCC->upload);
WCC->upload_length = 0;
}
+ FreeStrBuf(&WCC->trailing_javascript);
}
1);
}
+void view_postpart(void) {
+ postpart(ChrPtr(WC->UrlFragment1),
+ ChrPtr(WC->UrlFragment2),
+ 0);
+}
+
+void download_postpart(void) {
+ postpart(ChrPtr(WC->UrlFragment1),
+ ChrPtr(WC->UrlFragment2),
+ 1);
+}
+
int ConditionalImportantMesage(WCTemplateToken *Tokens, void *Context, int ContextType)
{
WebcitAddUrlHandler(HKEY("vcardphoto"), display_vcard_photo_img, NEED_URL);
WebcitAddUrlHandler(HKEY("mimepart"), view_mimepart, NEED_URL);
WebcitAddUrlHandler(HKEY("mimepart_download"), download_mimepart, NEED_URL);
+ WebcitAddUrlHandler(HKEY("postpart"), view_postpart, NEED_URL);
+ WebcitAddUrlHandler(HKEY("postpart_download"), download_postpart, NEED_URL);
WebcitAddUrlHandler(HKEY("diagnostics"), diagnostics, NEED_URL);
RegisterConditional(HKEY("COND:IMPMSG"), 0, ConditionalImportantMesage, CTX_NONE);