/*
* parse urlparts and post data
*
- * Copyright (c) 1996-2012 by the citadel.org team
+ * Copyright (c) 1996-2013 by the citadel.org team
*
* This program is open source software. You can redistribute it and/or
* modify it under the terms of the GNU General Public License, version 3.
#include "webcit.h"
#include "webserver.h"
+/* uncomment to see all parameters sent to the server by the browser. */
+/* #define DEBUG_URLSTRINGS */
+
+
void free_url(void *U)
{
urlcontent *u = (urlcontent*) U;
*/
void ParseURLParams(StrBuf *url)
{
- const char *aptr, *bptr, *eptr, *up;
- int len, keylen;
- urlcontent *u;
+ const char *aptr, *bptr, *eptr, *up = NULL;
+ int len, keylen = 0;
+ urlcontent *u = NULL;
wcsession *WCC = WC;
- if (WCC->Hdr->urlstrings == NULL)
+ if (WCC->Hdr->urlstrings == NULL) {
WCC->Hdr->urlstrings = NewHash(1, NULL);
+ }
eptr = ChrPtr(url) + StrLength(url);
up = ChrPtr(url);
while ((up < eptr) && (!IsEmptyStr(up))) {
aptr = up;
- while ((aptr < eptr) && (*aptr != '\0') && (*aptr != '='))
+ while ((aptr < eptr) && (*aptr != '\0') && (*aptr != '=')) {
aptr++;
+ }
if (*aptr != '=') {
return;
}
bptr++;
}
keylen = aptr - up - 1; /* -1 -> '=' */
- if(keylen > sizeof(u->url_key)) {
- syslog(1, "invalid url_key from %s", ChrPtr(WCC->Hdr->HR.browser_host));
- return;
+ if (keylen > sizeof(u->url_key)) {
+ syslog(LOG_WARNING, "%s:%d: invalid url_key of size %d in string size %d",
+ __FILE__, __LINE__, keylen, sizeof(u->url_key)
+ );
}
u = (urlcontent *) malloc(sizeof(urlcontent));
memcpy(u->url_key, up, keylen);
u->url_key[keylen] = '\0';
if (keylen < 0) {
- syslog(1, "invalid url_key from %s", ChrPtr(WCC->Hdr->HR.browser_host));
+ syslog(LOG_WARNING, "%s:%d: invalid url_key of size %d", __FILE__, __LINE__, keylen);
free(u);
return;
}
u->url_data = NewStrBufPlain(aptr, len);
StrBufUnescape(u->url_data, 1);
#ifdef DEBUG_URLSTRINGS
- syslog(9, "%s = [%d] %s\n",
+ syslog(LOG_DEBUG, "%s = [%d] %s\n",
u->url_key,
StrLength(u->url_data),
ChrPtr(u->url_data));
len = bptr - aptr;
u->url_data = NewStrBufPlain(aptr, len);
StrBufUnescape(u->url_data, 1);
- syslog(1, "REJECTED because of __ is internal only: %s = [%d] %s\n",
+ syslog(LOG_WARNING, "REJECTED because of __ is internal only: %s = [%d] %s\n",
u->url_key,
StrLength(u->url_data),
ChrPtr(u->url_data));
long keylen;
#ifdef DEBUG_URLSTRINGS
- syslog(9, "upload_handler() name=%s, type=%s, len=%d", name, cbtype, length);
+ syslog(LOG_DEBUG, "upload_handler() name=%s, type=%s, len="SIZE_T_FMT, name, cbtype, length);
#endif
if (WCC->Hdr->urlstrings == NULL)
WCC->Hdr->urlstrings = NewHash(1, NULL);
Put(WCC->Hdr->urlstrings, u->url_key, keylen, u, free_url);
}
else {
- syslog(1, "REJECTED because of __ is internal only: %s = [%d] %s\n",
+ syslog(LOG_INFO, "REJECTED because of __ is internal only: %s = [%d] %s\n",
u->url_key,
StrLength(u->url_data),
ChrPtr(u->url_data));
free_url(u);
}
#ifdef DEBUG_URLSTRINGS
- syslog(9, "Key: <%s> len: [%d] Data: <%s>",
+ syslog(LOG_DEBUG, "Key: <%s> len: [%d] Data: <%s>",
u->url_key,
StrLength(u->url_data),
ChrPtr(u->url_data));
WCC->upload_filename = NewStrBufPlain(filename, -1);
safestrncpy(WCC->upload_content_type, cbtype, sizeof(WC->upload_content_type));
#ifdef DEBUG_URLSTRINGS
- syslog(9, "File: <%s> len: [%ld]", filename, length);
+ syslog(LOG_DEBUG, "File: <%s> len: [%ld]", filename, (long int)length);
#endif
}
}
-
-
void PutBstr(const char *key, long keylen, StrBuf *Value)
{
urlcontent *u;
- wcsession *WCC = WC;
- if(keylen > sizeof(u->url_key)) {
- syslog(1, "invalid url_key from %s", ChrPtr(WCC->Hdr->HR.browser_host));
+ if(keylen >= sizeof(u->url_key)) {
+ syslog(LOG_WARNING, "%s:%d: invalid url_key of size %ld", __FILE__, __LINE__, keylen);
FreeStrBuf(&Value);
return;
}
u->url_data = Value;
Put(WC->Hdr->urlstrings, u->url_key, keylen, u, free_url);
}
+void PutlBstr(const char *key, long keylen, long Value)
+{
+ StrBuf *Buf;
+
+ Buf = NewStrBufPlain(NULL, sizeof(long) * 16);
+ StrBufPrintf(Buf, "%ld", Value);
+ PutBstr(key, keylen, Buf);
+}
RegisterNamespace("BSTR:PAIR:X", 1, 2, tmplput_bstr_pair_x, NULL, CTX_BSTRPAIRS);
RegisterNamespace("BSTR:PAIR:Y", 1, 2, tmplput_bstr_pair_y, NULL, CTX_BSTRPAIRS);
- RegisterConditional(HKEY("COND:BSTR"), 1, ConditionalBstr, CTX_NONE);
+ RegisterConditional("COND:BSTR", 1, ConditionalBstr, CTX_NONE);
RegisterNamespace("BSTR", 1, 2, tmplput_bstr, NULL, CTX_NONE);
RegisterNamespace("BSTR:FORWARD", 1, 2, tmplput_bstrforward, NULL, CTX_NONE);
RegisterNamespace("URLPART", 1, 2, tmplput_url_part, NULL, CTX_NONE);