removed a bunch of blank comment lines
[citadel.git] / webcit / paramhandling.c
index c656734410b6a8a12683b6351891c3fe62cfdfa1..a2dcca2f368f9efe1d0e8629c9b19cc58f5764ec 100644 (file)
@@ -1,7 +1,15 @@
 /*
- * $Id$
- *
  * parse urlparts and post data
+ *
+ * Copyright (c) 1996-2012 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  */
 
 #include "webcit.h"
@@ -43,7 +51,7 @@ void ParseURLParams(StrBuf *url)
                }
                keylen = aptr - up - 1; /* -1 -> '=' */
                if(keylen > sizeof(u->url_key)) {
-                       lprintf(1, "URLkey to long! [%s]", up);
+                       syslog(1, "URLkey to long! [%s]", up);
                        continue;
                }
 
@@ -51,24 +59,37 @@ void ParseURLParams(StrBuf *url)
                memcpy(u->url_key, up, keylen);
                u->url_key[keylen] = '\0';
                if (keylen < 0) {
-                       lprintf(1, "URLkey to long! [%s]", up);
+                       syslog(1, "URLkey to long! [%s]", up);
                        free(u);
                        continue;
                }
-
-               Put(WCC->Hdr->urlstrings, u->url_key, keylen, u, free_url);
-               len = bptr - aptr;
-               u->url_data = NewStrBufPlain(aptr, len);
-               StrBufUnescape(u->url_data, 1);
-            
-               up = bptr;
-               ++up;
+               
+               if (strncmp(u->url_key, "__", 2) != 0)
+               {
+                       Put(WCC->Hdr->urlstrings, u->url_key, keylen, u, free_url);
+                       len = bptr - aptr;
+                       u->url_data = NewStrBufPlain(aptr, len);
+                       StrBufUnescape(u->url_data, 1);
 #ifdef DEBUG_URLSTRINGS
-               lprintf(9, "%s = [%ld]  %s\n", 
-                       u->url_key, 
-                       StrLength(u->url_data), 
-                       ChrPtr(u->url_data)); 
+                       syslog(9, "%s = [%d]  %s\n", 
+                               u->url_key, 
+                               StrLength(u->url_data), 
+                               ChrPtr(u->url_data)); 
 #endif
+               }
+               else {
+                       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", 
+                               u->url_key, 
+                               StrLength(u->url_data), 
+                               ChrPtr(u->url_data)); 
+                       
+                       free_url(u);
+               }
+               up = bptr;
+               ++up;
        }
 }
 
@@ -294,8 +315,10 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
 {
        wcsession *WCC = WC;
        urlcontent *u;
+       long keylen;
+
 #ifdef DEBUG_URLSTRINGS
-       lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
+       syslog(9, "upload_handler() name=%s, type=%s, len=%d", name, cbtype, length);
 #endif
        if (WCC->Hdr->urlstrings == NULL)
                WCC->Hdr->urlstrings = NewHash(1, NULL);
@@ -304,25 +327,38 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
        if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
                u = (urlcontent *) malloc(sizeof(urlcontent));
                
-               safestrncpy(u->url_key, name, sizeof(u->url_key));
+               keylen = safestrncpy(u->url_key, name, sizeof(u->url_key));
                u->url_data = NewStrBufPlain(content, length);
                
-               Put(WCC->Hdr->urlstrings, u->url_key, strlen(u->url_key), u, free_url);
+               if (strncmp(u->url_key, "__", 2) != 0)
+               {
+                       Put(WCC->Hdr->urlstrings, u->url_key, keylen, u, free_url);
+               }
+               else {
+                       syslog(1, "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
-               lprintf(9, "Key: <%s> len: [%ld] Data: <%s>\n", 
+               syslog(9, "Key: <%s> len: [%d] Data: <%s>", 
                        u->url_key, 
                        StrLength(u->url_data), 
                        ChrPtr(u->url_data));
 #endif
        }
 
-       /** Uploaded files */
+       /* Uploaded files */
        if ( (length > 0) && (!IsEmptyStr(cbtype)) ) {
                WCC->upload = NewStrBufPlain(content, length);
                WCC->upload_length = length;
                WCC->upload_filename = NewStrBufPlain(filename, -1);
-               safestrncpy(WCC->upload_content_type, cbtype,
-                           sizeof(WC->upload_content_type));
+               safestrncpy(WCC->upload_content_type, cbtype, sizeof(WC->upload_content_type));
+#ifdef DEBUG_URLSTRINGS
+               syslog(9, "File: <%s> len: [%ld]", filename, length);
+#endif
                
        }
 
@@ -335,7 +371,7 @@ void PutBstr(const char *key, long keylen, StrBuf *Value)
        urlcontent *u;
 
        if(keylen > sizeof(u->url_key)) {
-               lprintf(1, "URLkey to long! [%s]", key);
+               syslog(1, "URLkey to long! [%s]", key);
                FreeStrBuf(&Value);
                return;
        }
@@ -377,20 +413,32 @@ void tmplput_bstr(StrBuf *Target, WCTemplputParams *TP)
                StrBufAppendTemplate(Target, TP, Buf, 1);
 }
 
+
+void tmplput_bstrforward(StrBuf *Target, WCTemplputParams *TP)
+{
+       const StrBuf *Buf = SBstr(TKEY(0));
+       if (Buf != NULL) {
+               StrBufAppendBufPlain(Target, HKEY("?"), 0);             
+               StrBufAppendBufPlain(Target, TKEY(0), 0);
+               StrBufAppendBufPlain(Target, HKEY("="), 0);             
+               StrBufAppendTemplate(Target, TP, Buf, 1);
+       }
+}
+
 void diagnostics(void)
 {
        output_headers(1, 1, 1, 0, 0, 0);
        wc_printf("Session: %d<hr />\n", WC->wc_session);
-       wc_printf("Command: <br /><PRE>\n");
+       wc_printf("Command: <br><PRE>\n");
 /*     
-StrEscPuts(WC->UrlFragment1);
-       wc_printf("<br />\n");
-       StrEscPuts(WC->UrlFragment2);
-       wc_printf("<br />\n");
-       StrEscPuts(WC->UrlFragment3);
+StrEscAppend(WC->WBuf, NULL, WC->UrlFragment1, 0, 0);
+       wc_printf("<br>\n");
+StrEscAppend(WC->WBuf, NULL, WC->UrlFragment12 0, 0);
+       wc_printf("<br>\n");
+StrEscAppend(WC->WBuf, NULL, WC->UrlFragment3, 0, 0);
 */
        wc_printf("</PRE><hr />\n");
-       wc_printf("Variables: <br /><PRE>\n");
+       wc_printf("Variables: <br><PRE>\n");
        dump_vars();
        wc_printf("</PRE><hr />\n");
        wDumpContent(1);
@@ -437,6 +485,7 @@ InitModule_PARAMHANDLING
 
        RegisterConditional(HKEY("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);
 }