/*
* $Id$
- */
-/**
- * \defgroup MainServer This is the main transaction loop of the web service. It maintains a
+ *
+ * This is the main transaction loop of the web service. It maintains a
* persistent session to the Citadel server, handling HTTP WebCit requests as
* they arrive and presenting a user interface.
- * \ingroup WebcitHttpServer
*/
-/*@{*/
+
#include "webcit.h"
#include "groupdav.h"
#include "webserver.h"
#include <stdio.h>
#include <stdarg.h>
-/**
+/*
* String to unset the cookie.
* Any date "in the past" will work, so I chose my birthday, right down to
* the exact minute. :)
*/
static char *unset = "; expires=28-May-1971 18:10:00 GMT";
-/**
- * \brief remove escaped strings from i.e. the url string (like %20 for blanks)
- * \param buf the buffer to examine
+HashList *HandlerHash = NULL;
+
+
+void WebcitAddUrlHandler(const char * UrlString, long UrlSLen, WebcitHandlerFunc F, int IsAjax)
+{
+ WebcitHandler *NewHandler;
+
+ if (HandlerHash == NULL)
+ HandlerHash = NewHash(1, NULL);
+
+ NewHandler = (WebcitHandler*) malloc(sizeof(WebcitHandler));
+ NewHandler->F = F;
+ NewHandler->IsAjax = IsAjax;
+
+ Put(HandlerHash, UrlString, UrlSLen, NewHandler, NULL);
+}
+
+/*
+ * remove escaped strings from i.e. the url string (like %20 for blanks)
*/
-void unescape_input(char *buf)
+long unescape_input(char *buf)
{
int a, b;
char hex[3];
long buflen;
+ long len;
buflen = strlen(buf);
if (buf[a] == '+')
buf[a] = ' ';
if (buf[a] == '%') {
- hex[0] = buf[a + 1];
- hex[1] = buf[a + 2];
- hex[2] = 0;
- b = 0;
- sscanf(hex, "%02x", &b);
- buf[a] = (char) b;
- memmove(&buf[a + 1], &buf[a + 3], buflen - a - 2);
+ /* don't let % chars through, rather truncate the input. */
+ if (a + 2 > buflen) {
+ buf[a] = '\0';
+ buflen = a;
+ }
+ else {
+ hex[0] = buf[a + 1];
+ hex[1] = buf[a + 2];
+ hex[2] = 0;
+ b = 0;
+ sscanf(hex, "%02x", &b);
+ buf[a] = (char) b;
+ len = buflen - a - 2;
+ if (len > 0)
+ memmove(&buf[a + 1], &buf[a + 3], len);
- buflen -=2;
+ buflen -=2;
+ }
}
a++;
}
+ return a;
+}
+void free_url(void *U)
+{
+ urlcontent *u = (urlcontent*) U;
+ free(u->url_data);
+ free(u);
}
-/**
- * \brief Extract variables from the URL.
- * \param url URL supplied by the HTTP parser
+/*
+ * Extract variables from the URL.
*/
-void addurls(char *url)
+void addurls(char *url, long ulen)
{
- char *up, *ptr;
- char buf[SIZ];
- int a, b, len;
- struct urlcontent *u;
-
- up = url;
+ char *aptr, *bptr, *eptr;
+ char *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;
while (!IsEmptyStr(up)) {
-
- /** locate the = sign */
- safestrncpy(buf, up, sizeof buf);
- b = (-1);
- for (a = 255; a >= 0; --a)
- if (buf[a] == '=')
- b = a;
- if (b < 0)
+ aptr = up;
+ while ((aptr < eptr) && (*aptr != '\0') && (*aptr != '='))
+ aptr++;
+ if (*aptr != '=')
return;
- buf[b] = 0;
-
- u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
- u->next = WC->urlstrings;
- WC->urlstrings = u;
- safestrncpy(u->url_key, buf, sizeof u->url_key);
-
- /** now chop that part off */
- for (a = 0; a <= b; ++a)
- ++up;
-
- /** locate "&" and "?" delimiters */
- ptr = up;
- len = b = strlen(up);
- for (a = 0; a < len; ++a) {
- if ( (ptr[0] == '&') || (ptr[0] == '?') ) {
- b = a;
- break;
- }
- ++ptr;
+ *aptr = '\0';
+ aptr++;
+ bptr = aptr;
+ while ((bptr < eptr) && (*bptr != '\0')
+ && (*bptr != '&') && (*bptr != '?') && (*bptr != ' ')) {
+ bptr++;
}
- ptr = up + b;
- *ptr = '\0';
+ *bptr = '\0';
+ u = (urlcontent *) malloc(sizeof(urlcontent));
- len = b;
+ keylen = safestrncpy(u->url_key, up, sizeof u->url_key);
+ if (keylen < 0){
+ lprintf(1, "URLkey to long! [%s]", up);
+ continue;
+ }
+
+ Put(WCC->urlstrings, u->url_key, keylen, u, free_url);
+ len = bptr - aptr;
u->url_data = malloc(len + 2);
- safestrncpy(u->url_data, up, b + 1);
- u->url_data[b] = 0;
- unescape_input(u->url_data);
- up = ptr;
+ safestrncpy(u->url_data, aptr, len + 2);
+ u->url_data_size = unescape_input(u->url_data);
+ u->url_data[u->url_data_size] = '\0';
+ up = bptr;
++up;
-
- /* lprintf(9, "%s = %s\n", u->url_key, u->url_data); */
+#ifdef DEBUG_URLSTRINGS
+ lprintf(9, "%s = [%ld] %s\n", u->url_key, u->url_data_size, u->url_data);
+#endif
}
}
-/**
- * \brief free urlstring memory
+/*
+ * free urlstring memory
*/
void free_urls(void)
{
- struct urlcontent *u;
-
- while (WC->urlstrings != NULL) {
- free(WC->urlstrings->url_data);
- u = WC->urlstrings->next;
- free(WC->urlstrings);
- WC->urlstrings = u;
- }
+ DeleteHash(&WC->urlstrings);
}
-/**
- * \brief Diagnostic function to display the contents of all variables
+/*
+ * Diagnostic function to display the contents of all variables
*/
+
void dump_vars(void)
{
- struct urlcontent *u;
-
- for (u = WC->urlstrings; u != NULL; u = u->next) {
+ struct wcsession *WCC = WC;
+ urlcontent *u;
+ void *U;
+ long HKLen;
+ 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);
}
}
-/**
- * \brief Return the value of a variable supplied to the current web page (from the url or a form)
- * \param key The name of the variable we want
+/*
+ * Return the value of a variable supplied to the current web page (from the url or a form)
*/
-char *bstr(char *key)
+
+const char *XBstr(char *key, size_t keylen, size_t *len)
{
- struct urlcontent *u;
+ void *U;
- for (u = WC->urlstrings; u != NULL; u = u->next) {
- if (!strcasecmp(u->url_key, key))
- return (u->url_data);
+ if ((WC->urlstrings != NULL) &&
+ GetHash(WC->urlstrings, key, keylen, &U)) {
+ *len = ((urlcontent *)U)->url_data_size;
+ return ((urlcontent *)U)->url_data;
+ }
+ else {
+ *len = 0;
+ return ("");
}
- return ("");
}
-/**
- * \brief web-printing funcion. uses our vsnprintf wrapper
- * \param format printf format string
- * \param ... the varargs to put into formatstring
+const char *XBSTR(char *key, size_t *len)
+{
+ void *U;
+
+ if ((WC->urlstrings != NULL) &&
+ GetHash(WC->urlstrings, key, strlen (key), &U)){
+ *len = ((urlcontent *)U)->url_data_size;
+ return ((urlcontent *)U)->url_data;
+ }
+ else {
+ *len = 0;
+ return ("");
+ }
+}
+
+
+const char *BSTR(char *key)
+{
+ void *U;
+
+ if ((WC->urlstrings != NULL) &&
+ GetHash(WC->urlstrings, key, strlen (key), &U))
+ return ((urlcontent *)U)->url_data;
+ else
+ return ("");
+}
+
+const char *Bstr(char *key, size_t keylen)
+{
+ void *U;
+
+ if ((WC->urlstrings != NULL) &&
+ GetHash(WC->urlstrings, key, keylen, &U))
+ return ((urlcontent *)U)->url_data;
+ else
+ return ("");
+}
+
+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);
+ else
+ return (0);
+}
+
+long LBSTR(char *key)
+{
+ void *U;
+
+ if ((WC->urlstrings != NULL) &&
+ GetHash(WC->urlstrings, key, strlen(key), &U))
+ return atol(((urlcontent *)U)->url_data);
+ else
+ return (0);
+}
+
+int IBstr(char *key, size_t keylen)
+{
+ void *U;
+
+ if ((WC->urlstrings != NULL) &&
+ GetHash(WC->urlstrings, key, keylen, &U))
+ return atoi(((urlcontent *)U)->url_data);
+ else
+ return (0);
+}
+
+int IBSTR(char *key)
+{
+ void *U;
+
+ if ((WC->urlstrings != NULL) &&
+ GetHash(WC->urlstrings, key, strlen(key), &U))
+ return atoi(((urlcontent *)U)->url_data);
+ else
+ return (0);
+}
+
+int HaveBstr(char *key, size_t keylen)
+{
+ void *U;
+
+ if ((WC->urlstrings != NULL) &&
+ GetHash(WC->urlstrings, key, keylen, &U))
+ return ((urlcontent *)U)->url_data_size != 0;
+ else
+ return (0);
+}
+
+int HAVEBSTR(char *key)
+{
+ void *U;
+
+ if ((WC->urlstrings != NULL) &&
+ GetHash(WC->urlstrings, key, strlen(key), &U))
+ return ((urlcontent *)U)->url_data_size != 0;
+ else
+ return (0);
+}
+
+
+int YesBstr(char *key, size_t keylen)
+{
+ void *U;
+
+ if ((WC->urlstrings != NULL) &&
+ GetHash(WC->urlstrings, key, keylen, &U))
+ return strcmp( ((urlcontent *)U)->url_data, "yes") == 0;
+ else
+ return (0);
+}
+
+int YESBSTR(char *key)
+{
+ void *U;
+
+ if ((WC->urlstrings != NULL) &&
+ GetHash(WC->urlstrings, key, strlen(key), &U))
+ return strcmp( ((urlcontent *)U)->url_data, "yes") == 0;
+ else
+ return (0);
+}
+
+/*
+ * web-printing funcion. uses our vsnprintf wrapper
*/
void wprintf(const char *format,...)
{
}
-/**
- * \brief wrap up an HTTP session, closes tags, etc.
- * \todo multiline params?
- * \param print_standard_html_footer should be set to 0 to transmit only, 1 to
- * append the main menu and closing tags, or 2 to
- * append the closing tags only.
+/*
+ * 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.
*/
void wDumpContent(int print_standard_html_footer)
{
}
-/**
- * \brief Copy a string, escaping characters which have meaning in HTML.
- * \param target target buffer
- * \param strbuf source buffer
- * \param nbsp If nonzero, spaces are converted to non-breaking spaces.
- * \param nolinebreaks if set, linebreaks are removed from the string.
+/*
+ * Copy a string, escaping characters which have meaning in HTML.
+ *
+ * target target buffer
+ * strbuf source buffer
+ * nbsp If nonzero, spaces are converted to non-breaking spaces.
+ * nolinebreaks if set, linebreaks are removed from the string.
*/
long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks)
{
return (bptr - target);
}
-/**
- * \brief WHAT???
- * \param strbuf what???
- * \param nbsp If nonzero, spaces are converted to non-breaking spaces.
- * \param nolinebreaks if set, linebreaks are removed from the string.
- */
void escputs1(char *strbuf, int nbsp, int nolinebreaks)
{
char *buf;
free(buf);
}
-/**
- * \brief static wrapper for ecsputs1
- * \param strbuf buffer to print escaped to client
+/*
+ * static wrapper for ecsputs1
*/
void escputs(char *strbuf)
{
}
-/**
- * \brief urlescape buffer and print it to the client
- * \param strbuf buffer to urlescape
+/*
+ * urlescape buffer and print it to the client
*/
void urlescputs(char *strbuf)
{
}
-/**
- * \brief Copy a string, escaping characters for JavaScript strings.
- * \param target output string
- * \param strbuf input string
+/*
+ * Copy a string, escaping characters for JavaScript strings.
*/
void jsesc(char *target, size_t tlen, char *strbuf)
{
*tptr = '\0';
}
-/**
- * \brief escape and print java script
- * \param strbuf the js code
+/*
+ * escape and print javascript
*/
void jsescputs(char *strbuf)
{
wprintf("%s", outbuf);
}
-/**
- * \brief Copy a string, escaping characters for message text hold
- * \param target target buffer
- * \param strbuf source buffer
+/*
+ * Copy a string, escaping characters for message text hold
*/
void msgesc(char *target, size_t tlen, char *strbuf)
{
-/**
- * \brief Output all that important stuff that the browser will want to see
+/*
+ * Output HTTP headers and leading HTML for a page
*/
-void output_headers( int do_httpheaders, /**< 1 = output HTTP headers */
- int do_htmlhead, /**< 1 = output HTML <head> section and <body> opener */
+void output_headers( int do_httpheaders, /* 1 = output HTTP headers */
+ int do_htmlhead, /* 1 = output HTML <head> section and <body> opener */
- int do_room_banner, /**< 0=no, 1=yes,
- * 2 = I'm going to embed my own, so don't open the
- * <div id="content"> either.
- */
+ int do_room_banner, /* 0=no, 1=yes,
+ * 2 = I'm going to embed my own, so don't open the
+ * <div id="content"> either.
+ */
- int unset_cookies, /**< 1 = session is terminating, so unset the cookies */
- int suppress_check, /**< 1 = suppress check for instant messages */
- int cache /**< 1 = allow browser to cache this page */
+ int unset_cookies, /* 1 = session is terminating, so unset the cookies */
+ int suppress_check, /* 1 = suppress check for instant messages */
+ int cache /* 1 = allow browser to cache this page */
) {
char cookie[1024];
char httpnow[128];
}
if (cache) {
+ char httpTomorow[128];
+
+ http_datestring(httpTomorow, sizeof httpTomorow,
+ time(NULL) + 60 * 60 * 24 * 2);
+
wprintf("Pragma: public\r\n"
"Cache-Control: max-age=3600, must-revalidate\r\n"
- "Last-modified: %s\r\n",
- httpnow
+ "Last-modified: %s\r\n"
+ "Expires: %s\r\n",
+ httpnow,
+ httpTomorow
);
}
else {
if (do_htmlhead) {
begin_burst();
if (!access("static.local/webcit.css", R_OK)) {
- svprintf("CSSLOCAL", WCS_STRING,
+ svprintf(HKEY("CSSLOCAL"), WCS_STRING,
"<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\">"
);
}
do_template("head");
}
- /** ICONBAR */
+ /* ICONBAR */
if (do_htmlhead) {
- /** check for ImportantMessages (these display in a div overlaying the main screen) */
+ /* check for ImportantMessages (these display in a div overlaying the main screen) */
if (!IsEmptyStr(WC->ImportantMessage)) {
- wprintf("<div id=\"important_message\">\n");
- wprintf("<span class=\"imsg\">"
- "%s</span><br />\n", WC->ImportantMessage);
- wprintf("</div>\n");
- wprintf("<script type=\"text/javascript\">\n"
- " setTimeout('hide_imsg_popup()', 3000); \n"
+ wprintf("<div id=\"important_message\">\n"
+ "<span class=\"imsg\">");
+ escputs(WC->ImportantMessage);
+ wprintf("</span><br />\n"
+ "</div>\n"
+ "<script type=\"text/javascript\">\n"
+ " setTimeout('hide_imsg_popup()', 5000); \n"
"</script>\n");
- safestrncpy(WC->ImportantMessage, "", sizeof WC->ImportantMessage);
+ WC->ImportantMessage[0] = 0;
}
if ( (WC->logged_in) && (!unset_cookies) ) {
}
-/**
- * \brief Generic function to do an HTTP redirect. Easy and fun.
- * \param whichpage target url to 302 to
+/*
+ * Generic function to do an HTTP redirect. Easy and fun.
*/
void http_redirect(char *whichpage) {
wprintf("HTTP/1.1 302 Moved Temporarily\n");
-/**
- * \brief Output a piece of content to the web browser
+/*
+ * Output a piece of content to the web browser using conformant HTTP and MIME semantics
*/
-void http_transmit_thing(char *thing, size_t length, char *content_type,
+void http_transmit_thing(char *thing, size_t length, const char *content_type,
int is_static) {
output_headers(0, 0, 0, 0, 0, is_static);
PACKAGE_STRING);
#ifdef HAVE_ZLIB
- /** If we can send the data out compressed, please do so. */
+ /* If we can send the data out compressed, please do so. */
if (WC->gzip_ok) {
char *compressed_data = NULL;
size_t compressed_len;
}
#endif
- /** No compression ... just send it out as-is */
+ /* No compression ... just send it out as-is */
wprintf("Content-length: %ld\r\n"
"\r\n",
(long) length
va_list arg_list;
long i;
- svprintf("BOXTITLE", WCS_STRING, Title);
+ svput("BOXTITLE", WCS_STRING, Title);
do_template("beginbox");
wprintf("<ul class=\"%s\">", Class);
FILE *fp;
struct stat statbuf;
off_t bytes;
+ off_t count = 0;
+ size_t res;
char *bigbuffer;
- char content_type[128];
+ const char *content_type;
int len;
fp = fopen(what, "rb");
if (fp == NULL) {
lprintf(9, "output_static('%s') -- NOT FOUND --\n", what);
- wprintf("HTTP/1.1 404 %s\n", strerror(errno));
+ wprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
wprintf("Content-Type: text/plain\r\n");
wprintf("\r\n");
- wprintf("Cannot open %s: %s\n", what, strerror(errno));
+ wprintf("Cannot open %s: %s\r\n", what, strerror(errno));
} else {
len = strlen (what);
- if (!strncasecmp(&what[len - 4], ".gif", 4))
- safestrncpy(content_type, "image/gif", sizeof content_type);
- else if (!strncasecmp(&what[len - 4], ".txt", 4))
- safestrncpy(content_type, "text/plain", sizeof content_type);
- else if (!strncasecmp(&what[len - 4], ".css", 4))
- safestrncpy(content_type, "text/css", sizeof content_type);
- else if (!strncasecmp(&what[len - 4], ".jpg", 4))
- safestrncpy(content_type, "image/jpeg", sizeof content_type);
- else if (!strncasecmp(&what[len - 4], ".png", 4))
- safestrncpy(content_type, "image/png", sizeof content_type);
- else if (!strncasecmp(&what[len - 4], ".ico", 4))
- safestrncpy(content_type, "image/x-icon", sizeof content_type);
- else if (!strncasecmp(&what[len - 5], ".html", 5))
- safestrncpy(content_type, "text/html", sizeof content_type);
- else if (!strncasecmp(&what[len - 4], ".htm", 4))
- safestrncpy(content_type, "text/html", sizeof content_type);
- else if (!strncasecmp(&what[len - 4], ".wml", 4))
- safestrncpy(content_type, "text/vnd.wap.wml", sizeof content_type);
- else if (!strncasecmp(&what[len - 5], ".wmls", 5))
- safestrncpy(content_type, "text/vnd.wap.wmlscript", sizeof content_type);
- else if (!strncasecmp(&what[len - 5], ".wmlc", 5))
- safestrncpy(content_type, "application/vnd.wap.wmlc", sizeof content_type);
- else if (!strncasecmp(&what[len - 6], ".wmlsc", 6))
- safestrncpy(content_type, "application/vnd.wap.wmlscriptc", sizeof content_type);
- else if (!strncasecmp(&what[len - 5], ".wbmp", 5))
- safestrncpy(content_type, "image/vnd.wap.wbmp", sizeof content_type);
- else if (!strncasecmp(&what[len - 3], ".js", 3))
- safestrncpy(content_type, "text/javascript", sizeof content_type);
- else
- safestrncpy(content_type, "application/octet-stream", sizeof content_type);
-
- fstat(fileno(fp), &statbuf);
+ content_type = GuessMimeByFilename(what, len);
+
+ if (fstat(fileno(fp), &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");
+ wprintf("Cannot fstat %s: %s\n", what, strerror(errno));
+ return;
+ }
+
+ count = 0;
bytes = statbuf.st_size;
- bigbuffer = malloc(bytes + 2);
- fread(bigbuffer, bytes, 1, fp);
+ 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");
+ return;
+ }
+ count += res;
+ }
+
fclose(fp);
lprintf(9, "output_static('%s') %s\n", what, content_type);
http_transmit_thing(bigbuffer, (size_t)bytes, content_type, 1);
free(bigbuffer);
}
- if (!strcasecmp(bstr("force_close_session"), "yes")) {
+ if (yesbstr("force_close_session")) {
end_webcit_session();
}
}
-
/**
* \brief When the browser requests an image file from the Citadel server,
* this function is called to transmit it.
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);
serv_puts("CLOS");
serv_getln(buf, sizeof buf);
+ MimeType = GuessMimeType (xferbuf, bytes);
/** Write it to the browser */
- http_transmit_thing(xferbuf, (size_t)bytes, "image/gif", 0);
+ if (!IsEmptyStr(MimeType))
+ {
+ http_transmit_thing(xferbuf,
+ (size_t)bytes,
+ MimeType,
+ 0);
+ free(xferbuf);
+ return;
+ }
+ /* hm... unknown mimetype? fallback to blank gif */
free(xferbuf);
+ }
- } else {
- /**
- * Instead of an ugly 404, send a 1x1 transparent GIF
- * when there's no such image on the server.
- */
- char blank_gif[SIZ];
- snprintf (blank_gif, SIZ, "%s%s", static_dirs[0], "/blank.gif");
- output_static(blank_gif);
- }
-
-
+
+ /**
+ * Instead of an ugly 404, send a 1x1 transparent GIF
+ * when there's no such image on the server.
+ */
+ char blank_gif[SIZ];
+ snprintf (blank_gif, SIZ, "%s%s", static_dirs[0], "/blank.gif");
+ output_static(blank_gif);
+}
+/**
+ * \brief Extract an embedded photo from a vCard for display on the client
+ *
+ * \param msgnum
+ */
+void display_vcard_photo_img(char *msgnum_as_string)
+{
+ long msgnum = 0L;
+ char *vcard;
+ struct vCard *v;
+ char *xferbuf;
+ char *photosrc;
+ int decoded;
+ const char *contentType;
+
+ msgnum = atol(msgnum_as_string);
+
+ 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");
+ return;
+ }
+ memset(xferbuf, 1, SIZ);
+ decoded = CtdlDecodeBase64(
+ xferbuf,
+ photosrc,
+ strlen(photosrc));
+ contentType = GuessMimeType(xferbuf, decoded);
+ http_transmit_thing(xferbuf, decoded, contentType, 0);
+ free(v);
+ free(photosrc);
+ free(xferbuf);
}
/**
wprintf("\">");
wprintf(_("Make this my start page"));
wprintf("</a>");
-/*
+#ifdef TECH_PREVIEW
wprintf("<br/><a href=\"rss?room=");
urlescputs(WC->wc_roomname);
wprintf("\" title=\"RSS 2.0 feed for ");
escputs(WC->wc_roomname);
wprintf("\"><img alt=\"RSS\" border=\"0\" src=\"static/xml_button.gif\"/></a>\n");
-*/
+#endif
}
void *content, char *cbtype, char *cbcharset,
size_t length, char *encoding, void *userdata)
{
- struct urlcontent *u;
-
+ urlcontent *u;
+/*
lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
+*/
+ if (WC->urlstrings == NULL)
+ WC->urlstrings = NewHash(1, NULL);
/* Form fields */
if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
- u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
- u->next = WC->urlstrings;
- WC->urlstrings = u;
+ 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;
- /* lprintf(9, "Key: <%s> Data: <%s>\n", u->url_key, u->url_data); */
+ Put(WC->urlstrings, u->url_key, strlen(u->url_key), u, free_url);
+
+/* lprintf(9, "Key: <%s> len: [%ld] Data: <%s>\n", u->url_key, u->url_data_size, u->url_data);*/
}
/** Uploaded files */
char pathname[1024];
int a, b, nBackDots, nEmpty;
int ContentLength = 0;
- int BytesRead = 0;
char ContentType[512];
char *content = NULL;
char *content_end = NULL;
WC->upload_length = 0;
WC->upload = NULL;
- WC->vars = NULL;
WC->is_wap = 0;
hptr = req;
}
if (ContentLength > 0) {
- content = malloc(ContentLength + SIZ);
- memset(content, 0, ContentLength + SIZ);
- snprintf(content, ContentLength + SIZ, "Content-type: %s\n"
+ int BuffSize;
+
+ BuffSize = ContentLength + SIZ;
+ content = malloc(BuffSize);
+ memset(content, 0, BuffSize);
+ snprintf(content, BuffSize, "Content-type: %s\n"
"Content-length: %d\n\n",
ContentType, ContentLength);
body_start = strlen(content);
/** Read the entire input data at once. */
- client_read(WC->http_sock, &content[BytesRead+body_start], ContentLength);
+ client_read(WC->http_sock, &content[body_start], ContentLength);
if (!strncasecmp(ContentType, "application/x-www-form-urlencoded", 33)) {
- addurls(&content[body_start]);
+ addurls(&content[body_start], ContentLength);
} else if (!strncasecmp(ContentType, "multipart", 9)) {
content_end = content + ContentLength + body_start;
mime_parser(content, content_end, *upload_handler, NULL, NULL, NULL, 0);
len = b - 1;
}
}
- addurls(&cmd[a + 1]);
+ addurls(&cmd[a + 1], len - a);
cmd[a] = 0;
len = a - 1;
}
if (strlen(bstr("nonce")) > 0) {
lprintf(9, "Comparing supplied nonce %s to session nonce %ld\n",
bstr("nonce"), WC->nonce);
- if (atoi(bstr("nonce")) != WC->nonce) {
+ if (ibstr("nonce") != WC->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");
do_listsub();
goto SKIP_ALL_THIS_CRAP;
}
-#ifdef WEBCIT_WITH_CALENDAR_SERVICE
if (!strcasecmp(action, "freebusy")) {
do_freebusy(cmd);
goto SKIP_ALL_THIS_CRAP;
}
-#endif
/**
* If we're not logged in, but we have HTTP Authentication data,
}
/** This needs to run early */
+#ifdef TECH_PREVIEW
if (!strcasecmp(action, "rss")) {
display_rss(bstr("room"), request_method);
goto SKIP_ALL_THIS_CRAP;
}
+#endif
/**
* The GroupDAV stuff relies on HTTP authentication instead of
if (!strcasecmp(action, "image")) {
output_image();
+ } else if (!strcasecmp(action, "display_mime_icon")) {
+ display_mime_icon();
- /**
- * All functions handled below this point ... make sure we log in
- * before doing anything else!
- */
+ /*
+ * All functions handled below this point ... make sure we log in
+ * before doing anything else!
+ */
} else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
do_login();
+ } else if ((!WC->logged_in) && (!strcasecmp(action, "display_openid_login"))) {
+ display_openid_login(NULL);
+ } else if ((!WC->logged_in) && (!strcasecmp(action, "openid_login"))) {
+ do_openid_login();
+ } else if (!strcasecmp(action, "finalize_openid_login")) {
+ finalize_openid_login();
} else if (!WC->logged_in) {
display_login(NULL);
}
- /**
+ /*
* Various commands...
*/
+ else {
+ void *vHandler;
+ WebcitHandler *Handler;
+
+ GetHash(HandlerHash, action, strlen(action) /* TODO*/, &vHandler),
+ Handler = (WebcitHandler*) vHandler;
+ if (Handler != NULL) {
+ if (Handler->IsAjax)
+ begin_ajax_response();
+ Handler->F();
+ if (Handler->IsAjax)
+ end_ajax_response();
+ }
+
+
else if (!strcasecmp(action, "do_welcome")) {
do_welcome();
} else if (!strcasecmp(action, "blank")) {
print_message(index[1]);
} else if (!strcasecmp(action, "msgheaders")) {
display_headers(index[1]);
+ } else if (!strcasecmp(action, "vcardphoto")) {
+ display_vcard_photo_img(index[1]);
} else if (!strcasecmp(action, "wiki")) {
display_wiki_page();
} else if (!strcasecmp(action, "display_enter")) {
delete_room();
} else if (!strcasecmp(action, "validate")) {
validate();
+ /* The users photo display / upload facility */
} else if (!strcasecmp(action, "display_editpic")) {
display_graphics_upload(_("your photo"),
- "UIMG 0|_userpic_",
+ "_userpic_",
"editpic");
} else if (!strcasecmp(action, "editpic")) {
- do_graphics_upload("UIMG 1|_userpic_");
+ do_graphics_upload("_userpic_");
+ /* room picture dispay / upload facility */
} else if (!strcasecmp(action, "display_editroompic")) {
display_graphics_upload(_("the icon for this room"),
- "UIMG 0|_roompic_",
+ "_roompic_",
"editroompic");
} else if (!strcasecmp(action, "editroompic")) {
- do_graphics_upload("UIMG 1|_roompic_");
+ do_graphics_upload("_roompic_");
+ /* the greetingpage hello pic */
+ } else if (!strcasecmp(action, "display_edithello")) {
+ display_graphics_upload(_("the Greetingpicture for the login prompt"),
+ "hello",
+ "edithellopic");
+ } else if (!strcasecmp(action, "edithellopic")) {
+ do_graphics_upload("hello");
+ /* the logoff banner */
+ } else if (!strcasecmp(action, "display_editgoodbyepic")) {
+ display_graphics_upload(_("the Logoff banner picture"),
+ "UIMG 0|%s|goodbuye",
+ "editgoodbuyepic");
+ } else if (!strcasecmp(action, "editgoodbuyepic")) {
+ do_graphics_upload("UIMG 1|%s|goodbuye");
+
} else if (!strcasecmp(action, "delete_floor")) {
delete_floor();
} else if (!strcasecmp(action, "rename_floor")) {
display_floorconfig(NULL);
} else if (!strcasecmp(action, "toggle_self_service")) {
toggle_self_service();
-#ifdef WEBCIT_WITH_CALENDAR_SERVICE
} else if (!strcasecmp(action, "display_edit_task")) {
display_edit_task();
} else if (!strcasecmp(action, "save_task")) {
respond_to_request();
} else if (!strcasecmp(action, "handle_rsvp")) {
handle_rsvp();
-#endif
} else if (!strcasecmp(action, "summary")) {
summary();
} else if (!strcasecmp(action, "summary_inner_div")) {
dump_vars();
wprintf("</PRE><hr />\n");
wDumpContent(1);
- } else if (!strcasecmp(action, "updatenote")) {
- updatenote();
+ } else if (!strcasecmp(action, "add_new_note")) {
+ add_new_note();
+ } else if (!strcasecmp(action, "ajax_update_note")) {
+ ajax_update_note();
} else if (!strcasecmp(action, "display_room_directory")) {
display_room_directory();
+ } else if (!strcasecmp(action, "display_pictureview")) {
+ display_pictureview();
} else if (!strcasecmp(action, "download_file")) {
download_file(index[1]);
} else if (!strcasecmp(action, "upload_file")) {
upload_file();
+ } else if (!strcasecmp(action, "display_openids")) {
+ display_openids();
+ } else if (!strcasecmp(action, "openid_attach")) {
+ openid_attach();
}
/** When all else fais, display the main menu. */
else {
display_main_menu();
}
-
+}
SKIP_ALL_THIS_CRAP:
fflush(stdout);
if (content != NULL) {