* persistent session to the Citadel server, handling HTTP WebCit requests as
* they arrive and presenting a user interface.
*/
-
+#include <stdarg.h>
+#define SHOW_ME_VAPPEND_PRINTF
#include "webcit.h"
#include "groupdav.h"
#include "webserver.h"
void free_url(void *U)
{
urlcontent *u = (urlcontent*) U;
- free(u->url_data);
+ FreeStrBuf(&u->url_data);
free(u);
}
/*
* Extract variables from the URL.
*/
-void addurls(char *url, long ulen)
+void addurls(StrBuf *url)
{
- char *aptr, *bptr, *eptr;
- char *up;
- char *buf;
+ 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 = buf + ulen;
- up = buf;
+// 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))) {
aptr = up;
while ((aptr < eptr) && (*aptr != '\0') && (*aptr != '='))
aptr++;
- if (*aptr != '=')
+ if (*aptr != '=') {
+ ///free(buf);
return;
- *aptr = '\0';
+ }
+ ///*aptr = '\0';
aptr++;
bptr = aptr;
while ((bptr < eptr) && (*bptr != '\0')
&& (*bptr != '&') && (*bptr != '?') && (*bptr != ' ')) {
bptr++;
}
- *bptr = '\0';
- u = (urlcontent *) malloc(sizeof(urlcontent));
+ //*bptr = '\0';
+ keylen = aptr - up - 1; /* -1 -> '=' */
+ if(keylen > sizeof(u->url_key)) {
+ lprintf(1, "URLkey to long! [%s]", up);
+ continue;
+ }
- keylen = safestrncpy(u->url_key, up, sizeof u->url_key);
- if (keylen < 0){
+ u = (urlcontent *) malloc(sizeof(urlcontent));
+ memcpy(u->url_key, up, keylen);
+ u->url_key[keylen] = '\0';
+ if (keylen < 0) {
lprintf(1, "URLkey to long! [%s]", up);
+ free(u);
continue;
}
Put(WCC->urlstrings, u->url_key, keylen, u, free_url);
len = bptr - aptr;
- u->url_data = malloc(len + 2);
- safestrncpy(u->url_data, aptr, len + 2);
- u->url_data_size = unescape_input(u->url_data);
- u->url_data[u->url_data_size] = '\0';
+ u->url_data = NewStrBufPlain(aptr, len);
+ StrBufUnescape(u->url_data, 1);
+
up = bptr;
++up;
#ifdef DEBUG_URLSTRINGS
- lprintf(9, "%s = [%ld] %s\n", u->url_key, u->url_data_size, u->url_data);
+ lprintf(9, "%s = [%ld] %s\n", u->url_key, u->url_data_size, ChrPtr(u->url_data));
#endif
}
- free(buf);
+ //free(buf);
}
/*
urlcontent *u;
void *U;
long HKLen;
- char *HKey;
+ const char *HKey;
HashPos *Cursor;
Cursor = GetNewHashPos ();
while (GetNextHashPos(WCC->urlstrings, Cursor, &HKLen, &HKey, &U)) {
u = (urlcontent*) U;
- wprintf("%38s = %s\n", u->url_key, u->url_data);
+ wprintf("%38s = %s\n", u->url_key, ChrPtr(u->url_data));
}
}
if ((WC->urlstrings != NULL) &&
GetHash(WC->urlstrings, key, keylen, &U)) {
- *len = ((urlcontent *)U)->url_data_size;
- return ((urlcontent *)U)->url_data;
+ *len = StrLength(((urlcontent *)U)->url_data);
+ return ChrPtr(((urlcontent *)U)->url_data);
}
else {
*len = 0;
if ((WC->urlstrings != NULL) &&
GetHash(WC->urlstrings, key, strlen (key), &U)){
- *len = ((urlcontent *)U)->url_data_size;
- return ((urlcontent *)U)->url_data;
+ *len = StrLength(((urlcontent *)U)->url_data);
+ return ChrPtr(((urlcontent *)U)->url_data);
}
else {
*len = 0;
if ((WC->urlstrings != NULL) &&
GetHash(WC->urlstrings, key, strlen (key), &U))
- return ((urlcontent *)U)->url_data;
+ return ChrPtr(((urlcontent *)U)->url_data);
else
return ("");
}
if ((WC->urlstrings != NULL) &&
GetHash(WC->urlstrings, key, keylen, &U))
- return ((urlcontent *)U)->url_data;
+ return ChrPtr(((urlcontent *)U)->url_data);
else
return ("");
}
+const StrBuf *SBSTR(const char *key)
+{
+ void *U;
+
+ if ((WC->urlstrings != NULL) &&
+ GetHash(WC->urlstrings, key, strlen (key), &U))
+ return ((urlcontent *)U)->url_data;
+ else
+ return NULL;
+}
+
+const StrBuf *SBstr(const char *key, size_t keylen)
+{
+ void *U;
+
+ if ((WC->urlstrings != NULL) &&
+ GetHash(WC->urlstrings, key, keylen, &U))
+ return ((urlcontent *)U)->url_data;
+ else
+ return NULL;
+}
+
long LBstr(char *key, size_t keylen)
{
void *U;
if ((WC->urlstrings != NULL) &&
GetHash(WC->urlstrings, key, keylen, &U))
- return atol(((urlcontent *)U)->url_data);
+ return StrTol(((urlcontent *)U)->url_data);
else
return (0);
}
if ((WC->urlstrings != NULL) &&
GetHash(WC->urlstrings, key, strlen(key), &U))
- return atol(((urlcontent *)U)->url_data);
+ return StrTol(((urlcontent *)U)->url_data);
else
return (0);
}
if ((WC->urlstrings != NULL) &&
GetHash(WC->urlstrings, key, keylen, &U))
- return atoi(((urlcontent *)U)->url_data);
+ return StrTol(((urlcontent *)U)->url_data);
else
return (0);
}
if ((WC->urlstrings != NULL) &&
GetHash(WC->urlstrings, key, strlen(key), &U))
- return atoi(((urlcontent *)U)->url_data);
+ return StrToi(((urlcontent *)U)->url_data);
else
return (0);
}
if ((WC->urlstrings != NULL) &&
GetHash(WC->urlstrings, key, keylen, &U))
- return ((urlcontent *)U)->url_data_size != 0;
+ return (StrLength(((urlcontent *)U)->url_data) != 0);
else
return (0);
}
if ((WC->urlstrings != NULL) &&
GetHash(WC->urlstrings, key, strlen(key), &U))
- return ((urlcontent *)U)->url_data_size != 0;
+ return (StrLength(((urlcontent *)U)->url_data) != 0);
else
return (0);
}
if ((WC->urlstrings != NULL) &&
GetHash(WC->urlstrings, key, keylen, &U))
- return strcmp( ((urlcontent *)U)->url_data, "yes") == 0;
+ return strcmp( ChrPtr(((urlcontent *)U)->url_data), "yes") == 0;
else
return (0);
}
if ((WC->urlstrings != NULL) &&
GetHash(WC->urlstrings, key, strlen(key), &U))
- return strcmp( ((urlcontent *)U)->url_data, "yes") == 0;
+ return strcmp( ChrPtr(((urlcontent *)U)->url_data), "yes") == 0;
else
return (0);
}
*/
void wprintf(const char *format,...)
{
+ struct wcsession *WCC = WC;
+ va_list arg_ptr;
+
+ if (WCC->WBuf == NULL)
+ WCC->WBuf = NewStrBuf();
+
+ va_start(arg_ptr, format);
+ StrBufVAppendPrintf(WCC->WBuf, format, arg_ptr);
+ va_end(arg_ptr);
+
+/// if (StrLength(WCC-WBuf) > 2048)
+ ///client_write(wbuf, strlen(wbuf));
+}
+
+/*
+ * http-header-printing funcion. uses our vsnprintf wrapper
+ */
+void hprintf(const char *format,...)
+{
+ struct wcsession *WCC = WC;
va_list arg_ptr;
- char wbuf[4096];
va_start(arg_ptr, format);
- vsnprintf(wbuf, sizeof wbuf, format, arg_ptr);
+ StrBufVAppendPrintf(WCC->HBuf, format, arg_ptr);
va_end(arg_ptr);
- client_write(wbuf, strlen(wbuf));
+/// if (StrLength(WCC-WBuf) > 2048)
+ ///client_write(wbuf, strlen(wbuf));
}
{
if (print_standard_html_footer) {
wprintf("</div>\n"); /* end of "text" div */
- do_template("trailing");
+ do_template("trailing", NULL);
}
/* If we've been saving it all up for one big output burst,
urlesc(outbuf, SIZ, strbuf);
wprintf("%s", outbuf);
}
+/**
+ * urlescape buffer and print it as header
+ */
+void hurlescputs(char *strbuf) {
+ char outbuf[SIZ];
+
+ urlesc(outbuf, SIZ, strbuf);
+ hprintf("%s", outbuf);
+}
/*
char cookie[1024];
char httpnow[128];
- wprintf("HTTP/1.1 200 OK\n");
+ hprintf("HTTP/1.1 200 OK\n");
http_datestring(httpnow, sizeof httpnow, time(NULL));
if (do_httpheaders) {
- wprintf("Content-type: text/html; charset=utf-8\r\n"
+ hprintf("Content-type: text/html; charset=utf-8\r\n"
"Server: %s / %s\n"
"Connection: close\r\n",
PACKAGE_STRING, serv_info.serv_software
http_datestring(httpTomorow, sizeof httpTomorow,
time(NULL) + 60 * 60 * 24 * 2);
- wprintf("Pragma: public\r\n"
+ hprintf("Pragma: public\r\n"
"Cache-Control: max-age=3600, must-revalidate\r\n"
"Last-modified: %s\r\n"
"Expires: %s\r\n",
);
}
else {
- wprintf("Pragma: no-cache\r\n"
+ hprintf("Pragma: no-cache\r\n"
"Cache-Control: no-store\r\n"
"Expires: -1\r\n"
);
WC->wc_password, WC->wc_roomname);
if (unset_cookies) {
- wprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
+ hprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
} else {
- wprintf("Set-cookie: webcit=%s; path=/\r\n", cookie);
+ hprintf("Set-cookie: webcit=%s; path=/\r\n", cookie);
if (server_cookie != NULL) {
- wprintf("%s\n", server_cookie);
+ hprintf("%s\n", server_cookie);
}
}
"<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\">"
);
}
- do_template("head");
+ do_template("head", NULL);
}
/* ICONBAR */
* Generic function to do an HTTP redirect. Easy and fun.
*/
void http_redirect(const char *whichpage) {
- wprintf("HTTP/1.1 302 Moved Temporarily\n");
- wprintf("Location: %s\r\n", whichpage);
- wprintf("URI: %s\r\n", whichpage);
- wprintf("Content-type: text/html; charset=utf-8\r\n\r\n");
+ hprintf("HTTP/1.1 302 Moved Temporarily\n");
+ hprintf("Location: %s\r\n", whichpage);
+ hprintf("URI: %s\r\n", whichpage);
+ hprintf("Content-type: text/html; charset=utf-8\r\n");
wprintf("<html><body>");
wprintf("Go <a href=\"%s\">here</A>.", whichpage);
wprintf("</body></html>\n");
+ end_burst();
}
/*
* Output a piece of content to the web browser using conformant HTTP and MIME semantics
*/
-void http_transmit_thing(char *thing, size_t length, const char *content_type,
+void http_transmit_thing(const char *content_type,
int is_static) {
output_headers(0, 0, 0, 0, 0, is_static);
- wprintf("Content-type: %s\r\n"
+ hprintf("Content-type: %s\r\n"
"Server: %s\r\n"
"Connection: close\r\n",
content_type,
PACKAGE_STRING);
-#ifdef HAVE_ZLIB
- /* If we can send the data out compressed, please do so. */
- if (WC->gzip_ok) {
- char *compressed_data = NULL;
- size_t compressed_len;
-
- compressed_len = ((length * 101) / 100) + 100;
- compressed_data = malloc(compressed_len);
-
- if (compress_gzip((Bytef *) compressed_data,
- &compressed_len,
- (Bytef *) thing,
- (uLongf) length, Z_BEST_SPEED) == Z_OK) {
- wprintf("Content-encoding: gzip\r\n"
- "Content-length: %ld\r\n"
- "\r\n",
- (long) compressed_len
- );
- client_write(compressed_data, (size_t)compressed_len);
- free(compressed_data);
- return;
- }
- }
-#endif
-
- /* No compression ... just send it out as-is */
- wprintf("Content-length: %ld\r\n"
- "\r\n",
- (long) length
- );
- client_write(thing, (size_t)length);
+ end_burst();
}
/*
long i;
svput("BOXTITLE", WCS_STRING, Title);
- do_template("beginbox");
+ do_template("beginbox", NULL);
wprintf("<ul class=\"%s\">", Class);
wprintf("</ul>");
- do_template("endbox");
+ do_template("endbox", NULL);
}
*/
void output_static(char *what)
{
- FILE *fp;
+ int fd;
struct stat statbuf;
off_t bytes;
off_t count = 0;
- size_t res;
- char *bigbuffer;
const char *content_type;
int len;
+ const char *Err;
- fp = fopen(what, "rb");
- if (fp == NULL) {
+ fd = open(what, O_RDONLY);
+ if (fd <= 0) {
lprintf(9, "output_static('%s') -- NOT FOUND --\n", what);
- wprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
- wprintf("Content-Type: text/plain\r\n");
- wprintf("\r\n");
+ hprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
+ hprintf("Content-Type: text/plain\r\n");
wprintf("Cannot open %s: %s\r\n", what, strerror(errno));
+ end_burst();
} else {
len = strlen (what);
content_type = GuessMimeByFilename(what, len);
- if (fstat(fileno(fp), &statbuf) == -1) {
+ if (fstat(fd, &statbuf) == -1) {
lprintf(9, "output_static('%s') -- FSTAT FAILED --\n", what);
- wprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
- wprintf("Content-Type: text/plain\r\n");
- wprintf("\r\n");
+ hprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
+ hprintf("Content-Type: text/plain\r\n");
wprintf("Cannot fstat %s: %s\n", what, strerror(errno));
+ end_burst();
return;
}
count = 0;
bytes = statbuf.st_size;
- if ((bigbuffer = malloc(bytes + 2)) == NULL) {
- lprintf(9, "output_static('%s') -- MALLOC FAILED (%s) --\n", what, strerror(errno));
- wprintf("HTTP/1.1 500 internal server error\r\n");
- wprintf("Content-Type: text/plain\r\n");
- wprintf("\r\n");
- return;
- }
- while (count < bytes) {
- if ((res = fread(bigbuffer + count, 1, bytes - count, fp)) == 0) {
- lprintf(9, "output_static('%s') -- FREAD FAILED (%s) %zu bytes of %zu --\n", what, strerror(errno), bytes - count, bytes);
- wprintf("HTTP/1.1 500 internal server error \r\n");
- wprintf("Content-Type: text/plain\r\n");
- wprintf("\r\n");
+
+ 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");
+ end_burst();
return;
- }
- count += res;
}
- fclose(fp);
+ close(fd);
lprintf(9, "output_static('%s') %s\n", what, content_type);
- http_transmit_thing(bigbuffer, (size_t)bytes, content_type, 1);
- free(bigbuffer);
+ 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;
-
+
serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
serv_getln(buf, sizeof buf);
if (buf[0] == '2') {
bytes = extract_long(&buf[4], 0);
- xferbuf = malloc(bytes + 2);
/** Read it from the server */
- read_server_binary(xferbuf, bytes);
- serv_puts("CLOS");
- serv_getln(buf, sizeof buf);
-
- MimeType = GuessMimeType (xferbuf, bytes);
- /** Write it to the browser */
- if (!IsEmptyStr(MimeType))
- {
- http_transmit_thing(xferbuf,
- (size_t)bytes,
- MimeType,
- 0);
- free(xferbuf);
- 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 */
- free(xferbuf);
}
long msgnum = 0L;
char *vcard;
struct vCard *v;
- char *xferbuf;
- char *photosrc;
- int decoded;
+ char *photosrc;
const char *contentType;
+ 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);
- http_transmit_thing(xferbuf, decoded, contentType, 0);
+ contentType = GuessMimeType(ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
+ http_transmit_thing(contentType, 0);
free(v);
free(photosrc);
- free(xferbuf);
}
/*
extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
}
output_headers(0, 0, 0, 0, 0, 0);
- read_server_binary(content, bytes);
+
+ read_server_binary(WC->WBuf, bytes);
serv_puts("CLOS");
serv_getln(buf, sizeof buf);
- http_transmit_thing(content, bytes, content_type, 0);
- free(content);
+ http_transmit_thing(content_type, 0);
} else {
- wprintf("HTTP/1.1 404 %s\n", &buf[4]);
+ hprintf("HTTP/1.1 404 %s\n", &buf[4]);
output_headers(0, 0, 0, 0, 0, 0);
- wprintf("Content-Type: text/plain\r\n");
- wprintf("\r\n");
+ hprintf("Content-Type: text/plain\r\n");
wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
+ end_burst();
}
}
*/
void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
{
- wprintf("HTTP/1.1 200 OK\n");
+ hprintf("HTTP/1.1 200 OK\n");
output_headers(1, 1, 2, 0, 0, 0);
wprintf("<div id=\"banner\">\n");
wprintf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
* A template has been requested
*/
void url_do_template(void) {
- do_template(bstr("template"));
+ const StrBuf *Tmpl = sbstr("template");
+ begin_burst();
+ DoTemplate(ChrPtr(Tmpl), StrLength(Tmpl), NULL, NULL);
+ end_burst();
}
set_preference("startpage", NewStrBufPlain(bstr("startpage"), -1), 1);
output_headers(1, 1, 0, 0, 0, 0);
- do_template("newstartpage");
+ do_template("newstartpage", NULL);
wDumpContent(1);
}
*/
void authorization_required(const char *message)
{
- wprintf("HTTP/1.1 401 Authorization Required\r\n");
- wprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n", serv_info.serv_humannode);
- wprintf("Content-Type: text/html\r\n\r\n");
+ hprintf("HTTP/1.1 401 Authorization Required\r\n");
+ hprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n", serv_info.serv_humannode);
+ hprintf("Content-Type: text/html\r\n");
wprintf("<h1>");
wprintf(_("Authorization Required"));
wprintf("</h1>\r\n");
wprintf(_("The resource you requested requires a valid username and password. "
"You could not be logged in: %s\n"), message);
wDumpContent(0);
+
}
/*
u = (urlcontent *) malloc(sizeof(urlcontent));
safestrncpy(u->url_key, name, sizeof(u->url_key));
- u->url_data = malloc(length + 1);
- u->url_data_size = length;
- memcpy(u->url_data, content, length);
- u->url_data[length] = 0;
+ u->url_data = NewStrBufPlain(content, length);
+
Put(WC->urlstrings, u->url_key, strlen(u->url_key), u, free_url);
#ifdef DEBUG_URLSTRINGS
lprintf(9, "Key: <%s> len: [%ld] Data: <%s>\n", u->url_key, u->url_data_size, u->url_data);
void begin_ajax_response(void) {
output_headers(0, 0, 0, 0, 0, 0);
- wprintf("Content-type: text/html; charset=UTF-8\r\n"
+ hprintf("Content-type: text/html; charset=UTF-8\r\n"
"Server: %s\r\n"
"Connection: close\r\n"
"Pragma: no-cache\r\n"
* print ajax response footer
*/
void end_ajax_response(void) {
- wprintf("\r\n");
+ ///hprintf("\r\n");///// todo: is this right?
wDumpContent(0);
}
* \brief Detects a 'mobile' user agent
*/
int is_mobile_ua(char *user_agent) {
- if (strstr(user_agent,"iPhone OS") != NULL) {
- return 1;
- } else if (strstr(user_agent,"Windows CE") != NULL) {
- return 1;
- } else if (strstr(user_agent,"SymbianOS") != NULL) {
- return 1;
- }
- return 0;
+ if (strstr(user_agent,"iPhone OS") != NULL) {
+ return 1;
+ } else if (strstr(user_agent,"Windows CE") != NULL) {
+ return 1;
+ } else if (strstr(user_agent,"SymbianOS") != NULL) {
+ return 1;
+ } else if (strstr(user_agent, "Opera Mobi") != NULL) {
+ return 1;
+ } else if (strstr(user_agent, "Firefox/2.0.0 Opera 9.51 Beta") != NULL) {
+ // For some reason a new install of Opera 9.51beta decided to spoof.
+ return 1;
+ }
+ return 0;
}
char c_httpauth_user[SIZ];
char c_httpauth_pass[SIZ];
char cookie[SIZ];
- struct wcsession *WCC = WC;
-
+ struct wcsession *WCC;
+
safestrncpy(c_username, "", sizeof c_username);
safestrncpy(c_password, "", sizeof c_password);
safestrncpy(c_roomname, "", sizeof c_roomname);
safestrncpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS, sizeof c_httpauth_pass);
strcpy(browser_host, "");
+ WCC= WC;
+ if (WCC->WBuf == NULL)
+ WC->WBuf = NewStrBufPlain(NULL, 32768);
+ FlushStrBuf(WCC->WBuf);
+
+ if (WCC->HBuf == NULL)
+ WCC->HBuf = NewStrBuf();
+ FlushStrBuf(WCC->HBuf);
+
WCC->upload_length = 0;
WCC->upload = NULL;
WCC->is_mobile = 0;
}
else if (!strncasecmp(buf, "User-agent: ", 12)) {
safestrncpy(user_agent, &buf[12], sizeof user_agent);
+ #ifdef TECH_PREVIEW
if (is_mobile_ua(&buf[12])) {
WCC->is_mobile = 1;
}
+ #endif
}
else if (!strncasecmp(buf, "X-Forwarded-Host: ", 18)) {
if (follow_xff) {
BuffSize = ContentLength + SIZ;
content = malloc(BuffSize);
memset(content, 0, BuffSize);
- snprintf(content, BuffSize, "Content-type: %s\n"
- "Content-length: %d\n\n",
- ContentType, ContentLength);
+ hprintf("Content-type: %s\n"
+ "Content-length: %d\n\n",
+ ContentType, ContentLength);
body_start = strlen(content);
/** Read the entire input data at once. */
client_read(WCC->http_sock, &content[body_start], ContentLength);
if (!strncasecmp(ContentType, "application/x-www-form-urlencoded", 33)) {
- addurls(&content[body_start], ContentLength);
+ StrBuf *Content;
+
+ Content = _NewConstStrBuf(&content[body_start],ContentLength);
+ addurls(Content);
+ FreeStrBuf(&Content);
} else if (!strncasecmp(ContentType, "multipart", 9)) {
content_end = content + ContentLength + body_start;
mime_parser(content, content_end, *upload_handler, NULL, NULL, NULL, 0);
len = strlen(cmd);
for (a = 0; a < len; ++a) {
if ((cmd[a] == '?') || (cmd[a] == '&')) {
+ StrBuf *Params;
for (b = a; b < len; ++b) {
if (isspace(cmd[b])){
cmd[b] = 0;
len = b - 1;
}
}
- addurls(&cmd[a + 1], len - a);
+ //cmd[len - a] = '\0';
+ Params = _NewConstStrBuf(&cmd[a + 1], len - a);
+ addurls(Params);
cmd[a] = 0;
len = a - 1;
}
/* If it's a "force 404" situation then display the error and bail. */
if (!strcmp(action, "404")) {
- wprintf("HTTP/1.1 404 Not found\r\n");
- wprintf("Content-Type: text/plain\r\n");
- wprintf("\r\n");
+ hprintf("HTTP/1.1 404 Not found\r\n");
+ hprintf("Content-Type: text/plain\r\n");
wprintf("Not found\r\n");
+ end_burst();
goto SKIP_ALL_THIS_CRAP;
}
else
{
lprintf(9, "Suspicious request. Ignoring.");
- wprintf("HTTP/1.1 404 Security check failed\r\n");
- wprintf("Content-Type: text/plain\r\n");
- wprintf("\r\n");
+ hprintf("HTTP/1.1 404 Security check failed\r\n");
+ hprintf("Content-Type: text/plain\r\n");
wprintf("You have sent a malformed or invalid request.\r\n");
+ end_burst();
}
goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
}
bstr("nonce"), WCC->nonce);
if (ibstr("nonce") != WCC->nonce) {
lprintf(9, "Ignoring request with mismatched nonce.\n");
- wprintf("HTTP/1.1 404 Security check failed\r\n");
- wprintf("Content-Type: text/plain\r\n");
- wprintf("\r\n");
+ hprintf("HTTP/1.1 404 Security check failed\r\n");
+ hprintf("Content-Type: text/plain\r\n");
wprintf("Security check failed.\r\n");
+ end_burst();
goto SKIP_ALL_THIS_CRAP;
}
}
}
}
}
-
+////////todo: restorte language in this case
/*
* Functions which can be performed without logging in
*/
serv_printf("PASS %s", c_password);
serv_getln(buf, sizeof buf);
if (buf[0] == '2') {
+ StrBuf *Lang;
become_logged_in(c_username, c_password, buf);
+ if (get_preference("language", &Lang)) {
+ set_selected_language(ChrPtr(Lang));
+ go_selected_language(); /* set locale */
+ }
}
}
}