]> code.citadel.org Git - citadel.git/blobdiff - webcit/webcit.c
* migrated to new hash create signature
[citadel.git] / webcit / webcit.c
index ced1d04edb5a95a1154383bf2b2a25cd32d68d29..ed3bf025e0c0979e8f422c521a77563fceffab0a 100644 (file)
  */
 static char *unset = "; expires=28-May-1971 18:10:00 GMT";
 
+static 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);
+}
+
 /**   
  * \brief remove escaped strings from i.e. the url string (like %20 for blanks)
  * \param buf the buffer to examine
@@ -82,13 +99,13 @@ void addurls(char *url)
 {
        char *aptr, *bptr, *eptr;
        char *up;
-       char buf[SIZ];
+       char buf[SIZ] = "";
        int len, n, keylen;
        urlcontent *u;
        struct wcsession *WCC = WC;
 
        if (WCC->urlstrings == NULL)
-               WCC->urlstrings = NewHash();
+               WCC->urlstrings = NewHash(1, NULL);
        eptr = buf + sizeof (buf);
        up = url;
        /** locate the = sign */
@@ -107,13 +124,13 @@ void addurls(char *url)
                *aptr = '\0';
                aptr++;
                bptr = aptr;
-               while ((bptr < eptr) && (*bptr != '\0') && 
-                      (*bptr != '&') && (*bptr != ' '))
+               while ((bptr < eptr) && (*bptr != '\0')
+                     && (*bptr != '&') && (*bptr != '?') && (*bptr != ' ')) {
                        bptr++;
+               }
                *bptr = '\0';
                u = (urlcontent *) malloc(sizeof(urlcontent));
 
-
                keylen = safestrncpy(u->url_key, up, sizeof u->url_key);
                if (keylen < 0){
                        lprintf(1, "URLkey to long! [%s]", up);
@@ -128,8 +145,9 @@ void addurls(char *url)
                u->url_data[u->url_data_size] = '\0';
                up = bptr;
                ++up;
-
+/*
                lprintf(9, "%s = [%ld]  %s\n", u->url_key, u->url_data_size, u->url_data); 
+*/
        }
 }
 
@@ -165,15 +183,20 @@ void dump_vars(void)
  * \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
  */
-const 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, strlen (key), &U))
+       if ((WC->urlstrings != NULL) && 
+           GetHash(WC->urlstrings, key, keylen, &U)) {
+               *len = ((urlcontent *)U)->url_data_size;
                return ((urlcontent *)U)->url_data;
-       else    
+       }
+       else {
+               *len = 0;
                return ("");
+       }
 }
 
 const char *XBSTR(char *key, size_t *len)
@@ -191,6 +214,18 @@ const char *XBSTR(char *key, size_t *len)
        }
 }
 
+
+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;
@@ -202,19 +237,93 @@ const char *Bstr(char *key, size_t keylen)
                return ("");
 }
 
-const char *XBstr(char *key, size_t keylen, size_t *len)
+long LBstr(char *key, size_t keylen)
 {
        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 ("");
-       }
+           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);
 }
 
 /**
@@ -787,7 +896,7 @@ void output_static(char *what)
                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();
        }
 }
@@ -1044,11 +1153,11 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
                        size_t length, char *encoding, void *userdata)
 {
        urlcontent *u;
-
+/*
        lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
-
+*/
        if (WC->urlstrings == NULL)
-               WC->urlstrings = NewHash();
+               WC->urlstrings = NewHash(1, NULL);
 
        /* Form fields */
        if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
@@ -1061,7 +1170,7 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
                u->url_data[length] = 0;
                Put(WC->urlstrings, u->url_key, strlen(u->url_key), u, free_url);
 
-               /* lprintf(9, "Key: <%s>  Data: <%s>\n", u->url_key, u->url_data); */
+/*             lprintf(9, "Key: <%s> len: [%ld] Data: <%s>\n", u->url_key, u->url_data_size, u->url_data);*/
        }
 
        /** Uploaded files */
@@ -1415,7 +1524,7 @@ void session_loop(struct httprequest *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");
@@ -1596,6 +1705,7 @@ void session_loop(struct httprequest *req)
         * Various commands...
         */
 
+
        else if (!strcasecmp(action, "do_welcome")) {
                do_welcome();
        } else if (!strcasecmp(action, "blank")) {
@@ -1935,7 +2045,7 @@ void session_loop(struct httprequest *req)
        else {
                display_main_menu();
        }
-
+}
 SKIP_ALL_THIS_CRAP:
        fflush(stdout);
        if (content != NULL) {