*/
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];
}
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)
{
char *aptr, *bptr, *eptr;
char *up;
- char buf[SIZ];
- int len, n;
- struct urlcontent *u;
+ char buf[SIZ] = "";
+ int len, n, keylen;
+ urlcontent *u;
+ struct wcsession *WCC = WC;
+ if (WCC->urlstrings == NULL)
+ WCC->urlstrings = NewHash(1, NULL);
eptr = buf + sizeof (buf);
up = url;
/** locate the = sign */
n = safestrncpy(buf, up, sizeof buf);
- if (n < 0) /** hm, we exceeded the buffer... hmmm what todo now? */
+ if (n < 0) /* hm, we exceeded the buffer... hmmm what to do now? */
n = -n;
up = buf;
-// while ((up < eptr) && (*up != '?') && (*up != '&'))
-// up++;
while (!IsEmptyStr(up)) {
aptr = up;
while ((aptr < eptr) && (*aptr != '\0') && (*aptr != '='))
*aptr = '\0';
aptr++;
bptr = aptr;
- while ((bptr < eptr) && (*bptr != '\0') &&
- (*bptr != '&') && (*bptr != ' '))
+ while ((bptr < eptr) && (*bptr != '\0')
+ && (*bptr != '&') && (*bptr != '?') && (*bptr != ' ')) {
bptr++;
+ }
*bptr = '\0';
- u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
- u->next = WC->urlstrings;
- WC->urlstrings = u;
+ u = (urlcontent *) malloc(sizeof(urlcontent));
- if (safestrncpy(u->url_key, up, sizeof u->url_key) < 0)
+ 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, aptr, len + 2);
- u->url_data[len] = 0;
- unescape_input(u->url_data);
+ 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);
+/* uncomment the following line to see each parameter in the log
+ lprintf(9, "%s = [%ld] %s\n", u->url_key, u->url_data_size, u->url_data);
+*/
}
}
-/**
- * \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)
+{
+ void *U;
+
+ 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 ("");
+ }
+}
+
+const char *XBSTR(char *key, 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, strlen (key), &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 *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 (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"
"<span class=\"imsg\">");
}
-/**
- * \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, const char *content_type,
int 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);
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();
}
}
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);
+}
+
/**
* \brief Generic function to output an arbitrary MIME part from an arbitrary
* message number on the server.
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 */
WC->upload_length = 0;
WC->upload = NULL;
- WC->vars = NULL;
WC->is_wap = 0;
hptr = req;
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");
* 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")) {
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")) {
else {
display_main_menu();
}
-
+}
SKIP_ALL_THIS_CRAP:
fflush(stdout);
if (content != NULL) {