/*
* Output a piece of content to the web browser using conformant HTTP and MIME semantics
*/
-void http_transmit_thing(StrBuf *thing, const char *content_type,
+void http_transmit_thing(const char *content_type,
int is_static) {
output_headers(0, 0, 0, 0, 0, is_static);
content_type,
PACKAGE_STRING);
- WC->WBuf = thing;
end_burst();
- WC->WBuf = NULL;
}
/*
struct stat statbuf;
off_t bytes;
off_t count = 0;
- StrBuf *Buf;
const char *content_type;
int len;
const char *Err;
count = 0;
bytes = statbuf.st_size;
- Buf = NewStrBufPlain(NULL, bytes + 2);
- if (Buf == NULL) {
- lprintf(9, "output_static('%s') -- MALLOC FAILED (%s) --\n", what, strerror(errno));
- hprintf("HTTP/1.1 500 internal server error\r\n");
- hprintf("Content-Type: text/plain\r\n");
- end_burst();
- return;
- }
-/// StrBufAppendBuf(Buf, WC->WBuf, 0);
- if (StrBufReadBLOB(Buf, &fd, 1, bytes, &Err) < 0)
+
+ if (StrBufReadBLOB(WC->WBuf, &fd, 1, bytes, &Err) < 0)
{
+ if (fd > 0) close(fd);
lprintf(9, "output_static('%s') -- FREAD FAILED (%s) --\n", what, strerror(errno));
hprintf("HTTP/1.1 500 internal server error \r\n");
hprintf("Content-Type: text/plain\r\n");
close(fd);
lprintf(9, "output_static('%s') %s\n", what, content_type);
- http_transmit_thing(Buf, content_type, 1);
- FreeStrBuf(&Buf);
+ http_transmit_thing(content_type, 1);
}
if (yesbstr("force_close_session")) {
end_webcit_session();
*/
void output_image()
{
+ struct wcsession *WCC = WC;
char buf[SIZ];
char *xferbuf = NULL;
off_t bytes;
const char *MimeType;
- StrBuf *Buf;
-
+
serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
serv_getln(buf, sizeof buf);
if (buf[0] == '2') {
/** Read it from the server */
- Buf = read_server_binary(bytes);
- serv_puts("CLOS");
- serv_getln(buf, sizeof buf);
-
- MimeType = GuessMimeType (ChrPtr(Buf), StrLength(Buf));
- /** Write it to the browser */
- if (!IsEmptyStr(MimeType))
- {
- http_transmit_thing(Buf,
- MimeType,
- 0);
- FreeStrBuf(&Buf);
- return;
+ if (read_server_binary(WCC->WBuf, bytes) > 0) {
+ serv_puts("CLOS");
+ serv_getln(buf, sizeof buf);
+
+ MimeType = GuessMimeType (ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
+ /** Write it to the browser */
+ if (!IsEmptyStr(MimeType))
+ {
+ http_transmit_thing(MimeType, 0);
+ return;
+ }
}
/* hm... unknown mimetype? fallback to blank gif */
}
long msgnum = 0L;
char *vcard;
struct vCard *v;
- char *xferbuf;
char *photosrc;
- int decoded;
const char *contentType;
- StrBuf *Buf;
+ struct wcsession *WCC = WC;
- msgnum = StrTol(WC->UrlFragment1);
+ msgnum = StrTol(WCC->UrlFragment1);
vcard = load_mimepart(msgnum,"1");
v = vcard_load(vcard);
photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
- xferbuf = malloc(strlen(photosrc));
- if (xferbuf == NULL) {
- lprintf(5, "xferbuf malloc failed\n");
+ FlushStrBuf(WCC->WBuf);
+ StrBufAppendBufPlain(WCC->WBuf, photosrc, -1, 0);
+ if (StrBufDecodeBase64(WCC->WBuf) <= 0) {
+ FlushStrBuf(WCC->WBuf);
+
+ hprintf("HTTP/1.1 500 %s\n","Unable to get photo");
+ output_headers(0, 0, 0, 0, 0, 0);
+ hprintf("Content-Type: text/plain\r\n");
+ wprintf(_("Could Not decode vcard photo\n"));
+ end_burst();
return;
}
- memset(xferbuf, 1, SIZ);
- decoded = CtdlDecodeBase64(
- xferbuf,
- photosrc,
- strlen(photosrc));
- contentType = GuessMimeType(xferbuf, decoded);
- Buf = _NewConstStrBuf(xferbuf, decoded);
- http_transmit_thing(Buf, contentType, 0);
+ contentType = GuessMimeType(ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
+ http_transmit_thing(contentType, 0);
free(v);
free(photosrc);
- free(xferbuf);
- FreeStrBuf(&Buf);
}
/*
serv_printf("OPNA %s|%s", msgnum, partnum);
serv_getln(buf, sizeof buf);
if (buf[0] == '2') {
- StrBuf *Buf;
bytes = extract_long(&buf[4], 0);
content = malloc(bytes + 2);
if (force_download) {
}
output_headers(0, 0, 0, 0, 0, 0);
- Buf = read_server_binary(bytes);
+ read_server_binary(WC->WBuf, bytes);
serv_puts("CLOS");
serv_getln(buf, sizeof buf);
- http_transmit_thing(Buf, content_type, 0);
- FreeStrBuf(&Buf);
+ http_transmit_thing(content_type, 0);
} else {
hprintf("HTTP/1.1 404 %s\n", &buf[4]);
output_headers(0, 0, 0, 0, 0, 0);
strcpy(browser_host, "");
WCC= WC;
+ if (WCC->WBuf == NULL)
+ WCC->WBuf = NewStrBuf();
+ FlushStrBuf(WCC->WBuf);
+
if (WCC->HBuf == NULL)
WCC->HBuf = NewStrBuf();
FlushStrBuf(WCC->HBuf);
+
WCC->upload_length = 0;
WCC->upload = NULL;
WCC->is_mobile = 0;