* migrated SUBST stuff to hash
authorWilfried Göesgens <willi@citadel.org>
Fri, 2 May 2008 12:10:49 +0000 (12:10 +0000)
committerWilfried Göesgens <willi@citadel.org>
Fri, 2 May 2008 12:10:49 +0000 (12:10 +0000)
* created cheaper variations of svprintf and applied them where appropriate

19 files changed:
webcit/auth.c
webcit/context_loop.c
webcit/graphics.c
webcit/inetconf.c
webcit/listsub.c
webcit/mainmenu.c
webcit/messages.c
webcit/pushemail.c
webcit/roomops.c
webcit/serv_func.c
webcit/sieve.c
webcit/subst.c
webcit/summary.c
webcit/sysdep.c
webcit/sysmsgs.c
webcit/useredit.c
webcit/vcard_edit.c
webcit/webcit.c
webcit/webcit.h

index 2ee1bdd4119d6865863df2cbc7805911cd822304..2655472245be3fc60628570dc96574621f4ffc49 100644 (file)
@@ -39,10 +39,10 @@ void display_login(char *mesg)
 
        if (mesg != NULL) if (!IsEmptyStr(mesg)) {
                        stresc(buf, SIZ,  mesg, 0, 0);
-                       svprintf("mesg", WCS_STRING, "%s", buf);
+                       svprintf(HKEY("mesg"), WCS_STRING, "%s", buf);
        }
 
-       svprintf("LOGIN_INSTRUCTIONS", WCS_STRING,
+       svprintf(HKEY("LOGIN_INSTRUCTIONS"), WCS_STRING,
                _("<ul>"
                "<li><b>If you already have an account on %s</b>, "
                "enter your user name and password and click &quot;Login.&quot; "
@@ -59,23 +59,23 @@ void display_login(char *mesg)
                serv_info.serv_humannode
        );
 
-       svprintf("USERNAME_BOX", WCS_STRING, "%s", _("User name:"));
-       svprintf("PASSWORD_BOX", WCS_STRING, "%s", _("Password:"));
-       svprintf("LANGUAGE_BOX", WCS_STRING, "%s", _("Language:"));
-       svprintf("LOGIN_BUTTON", WCS_STRING, "%s", _("Login"));
-       svprintf("NEWUSER_BUTTON", WCS_STRING, "%s", _("New User"));
-       svprintf("EXIT_BUTTON", WCS_STRING, "%s", _("Exit"));
-       svprintf("hello", WCS_SERVCMD, "MESG hello");
-       svprintf("BOXTITLE", WCS_STRING, _("%s - powered by <a href=\"http://www.citadel.org\">Citadel</a>"),
+       svput("USERNAME_BOX", WCS_STRING, _("User name:"));
+       svput("PASSWORD_BOX", WCS_STRING, _("Password:"));
+       svput("LANGUAGE_BOX", WCS_STRING, _("Language:"));
+       svput("LOGIN_BUTTON", WCS_STRING, _("Login"));
+       svput("NEWUSER_BUTTON", WCS_STRING, _("New User"));
+       svput("EXIT_BUTTON", WCS_STRING, _("Exit"));
+       svput("hello", WCS_SERVCMD, "MESG hello");
+       svprintf(HKEY("BOXTITLE"), WCS_STRING, _("%s - powered by <a href=\"http://www.citadel.org\">Citadel</a>"),
                serv_info.serv_humannode);
        svcallback("DO_LANGUAGE_BOX", offer_languages);
        if (serv_info.serv_newuser_disabled) {
-               svprintf("NEWUSER_BUTTON_PRE", WCS_STRING, "<div style=\"display:none;\">");
-               svprintf("NEWUSER_BUTTON_POST", WCS_STRING, "</div>");
+               svput("NEWUSER_BUTTON_PRE", WCS_STRING, "<div style=\"display:none;\">");
+               svput("NEWUSER_BUTTON_POST", WCS_STRING, "</div>");
        }
        else {
-               svprintf("NEWUSER_BUTTON_PRE", WCS_STRING, "");
-               svprintf("NEWUSER_BUTTON_POST", WCS_STRING, "");
+               svput("NEWUSER_BUTTON_PRE", WCS_STRING, "");
+               svput("NEWUSER_BUTTON_POST", WCS_STRING, "");
        }
 
        do_template("login");
@@ -469,7 +469,7 @@ void display_changepw(void)
 
        output_headers(1, 1, 1, 0, 0, 0);
 
-       svprintf("BOXTITLE", WCS_STRING, _("Change your password"));
+       svput("BOXTITLE", WCS_STRING, _("Change your password"));
        do_template("beginbox");
 
        if (!IsEmptyStr(WC->ImportantMessage)) {
index 3a742a7ee63beef5b14d55f853f75a00c979e00d..8d7bb9e6666acef7b190aeaf9267bfe80e27e23e 100644 (file)
@@ -100,7 +100,6 @@ void do_housekeeping(void)
                }
                free_attachments(sessions_to_kill);
                free_march_list(sessions_to_kill);
-               clear_substs(sessions_to_kill);
                DeleteHash(&(sessions_to_kill->hash_prefs));
                
                pthread_mutex_unlock(&sessions_to_kill->SessionMutex);
@@ -476,6 +475,8 @@ void context_loop(int sock)
                TheSession->hash_prefs = NewHash(1,NULL);       /* Get a hash table for the user preferences */
                pthread_mutex_init(&TheSession->SessionMutex, NULL);
                pthread_mutex_lock(&SessionListMutex);
+               TheSession->urlstrings = NULL;
+               TheSession->vars = NULL;
                TheSession->nonce = rand();
                TheSession->next = SessionList;
                SessionList = TheSession;
@@ -493,6 +494,9 @@ void context_loop(int sock)
         */
        pthread_mutex_lock(&TheSession->SessionMutex);          /* bind */
        pthread_setspecific(MyConKey, (void *)TheSession);
+       
+       TheSession->urlstrings = NewHash(1,NULL);
+       TheSession->vars = NewHash(1,NULL);
        TheSession->http_sock = sock;
        TheSession->lastreq = time(NULL);                       /* log */
        TheSession->gzip_ok = gzip_ok;
@@ -506,6 +510,9 @@ void context_loop(int sock)
 #ifdef ENABLE_NLS
        stop_selected_language();                               /* unset locale */
 #endif
+       DeleteHash(&TheSession->urlstrings);
+       DeleteHash(&TheSession->vars);
+
        pthread_mutex_unlock(&TheSession->SessionMutex);        /* unbind */
 
        /* Free the request buffer */
@@ -519,5 +526,6 @@ void context_loop(int sock)
         * Free up any session-local substitution variables which
         * were set during this transaction
         */
-       clear_local_substs();
+       
+       
 }
index e9c0d8c3410067c6a24f7753128278372b383579..a1d50b9e44e790369b5cdaef5918cf80c7d078d0 100644 (file)
@@ -24,7 +24,7 @@ void display_graphics_upload(char *description, char *filename, char *uplurl)
 
        output_headers(1, 1, 1, 0, 0, 0);
 
-       svprintf("BOXTITLE", WCS_STRING, _("Image upload"));
+       svput("BOXTITLE", WCS_STRING, _("Image upload"));
        do_template("beginbox");
 
        wprintf("<form enctype=\"multipart/form-data\" action=\"%s\" "
index b52d5df25650dcdf492a0dd720b6af77b56fa0bb..c61ee41665ce01f98c80e3159a90f8b4c7dc6dbd 100644 (file)
@@ -104,7 +104,7 @@ void display_inetconf(void)
                if (which == (ic_max / 2)) {
                        wprintf("</td><td valign=top>");
                }
-               svprintf("BOXTITLE", WCS_STRING, ic_boxtitle[which]);
+               svput("BOXTITLE", WCS_STRING, ic_boxtitle[which]);
                do_template("beginbox");
                wprintf("<span class=\"menudesc\">");
                escputs(ic_desc[which]);
index ef7d93b743f858b6d0e31593a675491980aa8832..ce9b1ed5250a37555f3167242adf42abe826b280 100644 (file)
@@ -48,7 +48,7 @@ void do_listsub(void)
        wprintf("<div align=center>");
        wprintf("<table border=0 width=75%%><tr><td>");
 
-       svprintf("BOXTITLE", WCS_STRING, _("List subscribe/unsubscribe"));
+       svput("BOXTITLE", WCS_STRING, _("List subscribe/unsubscribe"));
        do_template("beginbox");
        wprintf("<div align=center><br>");
 
index a869e8b3bdaa116ca92ac00fdb6d732afed101f4..4ab0eacb18485e5c6c07bde37264f2e6fd514ec2 100644 (file)
@@ -21,7 +21,7 @@ void display_main_menu(void)
                "<table width=\"100%%\" cellspacing=\"10px\" cellpadding=\"0\">"
                "<tr><td colspan=\"2\" class=\"advanced\">\n");
 
-       svprintf("BOXTITLE", WCS_STRING, _("Basic commands"));
+       svput("BOXTITLE", WCS_STRING, _("Basic commands"));
        do_template("beginbox");
 
        /**< start of first column */
@@ -264,7 +264,7 @@ void do_generic(void)
        serv_printf("%s", bstr("g_cmd"));
        serv_getln(buf, sizeof buf);
 
-       svprintf("BOXTITLE", WCS_STRING, _("Server command results"));
+       svput("BOXTITLE", WCS_STRING, _("Server command results"));
        do_template("beginbox");
 
        wprintf("<table border=0><tr><td>Command:</td><td><tt>");
@@ -378,7 +378,7 @@ void display_shutdown(void)
                if ((message == NULL) || (IsEmptyStr(message)))
                {
                        output_headers(1, 1, 1, 0, 0, 0);
-                       svprintf("BOXTITLE", WCS_STRING, _("Message to your Users:"));
+                       svput("BOXTITLE", WCS_STRING, _("Message to your Users:"));
                        do_template("beginbox");
                        wprintf("<form action=\"server_shutdown\">\n"
                                "<input type=\"hidden\" name=\"when\" value=\"page\">\n"
index 63d8cef69d27df0206635cb3126101104d73a159..ab45068e9d0c99ad801bc08e1d743d2ddf01e000 100644 (file)
@@ -3065,7 +3065,7 @@ void post_message(void)
                gotoroom(bstr("force_room"));
        }
 
-       if (GetHash(WCC->urlstrings, HKEY("display_name"), &U)) {
+       if (GetHash(WC->urlstrings, HKEY("display_name"), &U)) {
                u = (urlcontent*) U;
                display_name = u->url_data;
                dpLen = u->url_data_size;
index 019e0fa1bea1b50852521ef8e3a3b9e6b7e30d69..60cb62f6ef44a6af50e25b61276cd6a2f605bac0 100644 (file)
@@ -10,7 +10,8 @@ void display_pushemail(void) {
        int is_pager = 0;
        int is_funambol = 0;
        char mobnum[20];
-       svprintf("BOXTITLE", WCS_STRING, _("Push email and SMS settings"));
+
+       svput("BOXTITLE", WCS_STRING, _("Push email and SMS settings"));
        
        /* Find any existing settings*/
        if (goto_config_room() == 0) {
@@ -51,12 +52,12 @@ void display_pushemail(void) {
                }
                }
        if (is_none) {
-               svprintf("PUSH_NONE", WCS_STRING, "checked=\"checked\"");
+               svput("PUSH_NONE", WCS_STRING, "checked=\"checked\"");
        } else if (is_pager) {
-               svprintf("PUSH_TEXT", WCS_STRING, "checked=\"checked\"");
-               svprintf("SMSNUM", WCS_STRING, "value=\"%s\"", mobnum);
+               svput("PUSH_TEXT", WCS_STRING, "checked=\"checked\"");
+               svprintf(HKEY("SMSNUM"), WCS_STRING, "value=\"%s\"", mobnum);
        } else if (is_funambol) {
-               svprintf("PUSH_FNBL", WCS_STRING, "checked=\"checked\"");
+               svput("PUSH_FNBL", WCS_STRING, "checked=\"checked\"");
        }
        serv_printf("GOTO %s", WC->wc_roomname);
        serv_getln(buf, sizeof  buf);
index 73a9b90da2352a24888e81b2c13e421e1525c4db..e9a25ddc915b0c66c7038d1bc53b6d7ba8a9bcdb 100644 (file)
@@ -256,7 +256,7 @@ void zapped_list(void)
 {
        output_headers(1, 1, 1, 0, 0, 0);
 
-       svprintf("BOXTITLE", WCS_STRING, _("Zapped (forgotten) rooms"));
+       svput("BOXTITLE", WCS_STRING, _("Zapped (forgotten) rooms"));
        do_template("beginbox");
 
        listrms("LZRM -1");
@@ -491,8 +491,8 @@ void embed_room_banner(char *got, int navbar_style) {
                strcpy (with_files, "");
                
        stresc(sanitized_roomname, 256, WC->wc_roomname, 1, 1);
-       svprintf("ROOMNAME", WCS_STRING, "%s", sanitized_roomname);
-       svprintf("NUMMSGS", WCS_STRING,
+       svprintf(HKEY("ROOMNAME"), WCS_STRING, "%s", sanitized_roomname);
+       svprintf(HKEY("NUMMSGS"), WCS_STRING,
                _("%d new of %d messages%s"),
                extract_int(&got[4], 1),
                extract_int(&got[4], 2),
@@ -2388,7 +2388,7 @@ void display_entroom(void)
 
        output_headers(1, 1, 1, 0, 0, 0);
 
-       svprintf("BOXTITLE", WCS_STRING, _("Create a new room"));
+       svprintf(HKEY("BOXTITLE"), WCS_STRING, _("Create a new room"));
        do_template("beginbox");
 
        wprintf("<form name=\"create_room_form\" method=\"POST\" action=\"entroom\">\n");
@@ -2615,7 +2615,7 @@ void display_private(char *rname, int req_pass)
 {
        output_headers(1, 1, 1, 0, 0, 0);
 
-       svprintf("BOXTITLE", WCS_STRING, _("Go to a hidden room"));
+       svprintf(HKEY("BOXTITLE"), WCS_STRING, _("Go to a hidden room"));
        do_template("beginbox");
 
        wprintf("<p>");
@@ -3123,7 +3123,7 @@ void do_rooms_view(struct folder *fold, int max_folders, int num_floors) {
                if (levels == 1) {
                        /** Begin inner box */
                        stresc(boxtitle, 256, floor_name, 1, 0);
-                       svprintf("BOXTITLE", WCS_STRING, boxtitle);
+                       svprintf(HKEY("BOXTITLE"), WCS_STRING, boxtitle);
                        do_template("beginbox");
                }
 
index edff5ebd43a6ceee1a3d13b718f0972958d21d58..fed2011020372d934d32963f258f2be2198c49b4 100644 (file)
@@ -6,7 +6,7 @@
 #include "webserver.h"
 
 struct serv_info serv_info; /**< our connection data to the server */
-
+HashList *ServHash = NULL;//// TODO;
 /*
  * get info about the server we've connected to
  *
index 849af01e08747c3487675ff9b22f1964994bee9d..a566c79410214d30f6982d7ed4bde0e751effe94 100644 (file)
@@ -648,7 +648,7 @@ void display_add_remove_scripts(char *message)
 
        wprintf("<table border=0 cellspacing=10><tr valign=top><td>\n");
 
-       svprintf("BOXTITLE", WCS_STRING, _("Add a new script"));
+       svput("BOXTITLE", WCS_STRING, _("Add a new script"));
        do_template("beginbox");
 
        wprintf(_("To create a new script, enter the desired "
@@ -664,7 +664,7 @@ void display_add_remove_scripts(char *message)
 
        do_template("endbox");
 
-       svprintf("BOXTITLE", WCS_STRING, _("Edit scripts"));
+       svput("BOXTITLE", WCS_STRING, _("Edit scripts"));
        do_template("beginbox");
        wprintf("<br /><div align=center><a href=\"display_sieve\">%s</a><br /><br />\n",
                _("Return to the script editing screen")
@@ -673,7 +673,7 @@ void display_add_remove_scripts(char *message)
 
        wprintf("</td><td>");
 
-       svprintf("BOXTITLE", WCS_STRING, _("Delete scripts"));
+       svput("BOXTITLE", WCS_STRING, _("Delete scripts"));
        do_template("beginbox");
 
        wprintf(_("To delete an existing script, select the script "
index 5d1ad726e72f4be4b0883eb808e31f644015b500..e98001904489bad3dd50f0f5af971926b23c70cb 100644 (file)
 #include <unistd.h>
 
 #include "webcit.h"
+#include "webserver.h"
 
 /**
- * \brief Clear out the list of substitution variables local to this session
+ * \brief debugging function to print array to log
  */
-void clear_substs(struct wcsession *wc) {
-       struct wcsubst *ptr;
+void VarPrintTransition(void *vVar1, void *vVar2, int odd){}
+/**
+ * \brief debugging function to print array to log
+ */
+void VarPrintEntry(const char *Key, void *vSubst, int odd)
+{
+       wcsubst *ptr;
+       lprintf(1,"Subst[%s] : ", Key);
+       ptr = (wcsubst*) vSubst;
+
+       switch(ptr->wcs_type) {
+       case WCS_STRING:
+               lprintf(1, "  -> %s\n", ptr->wcs_value);
+               break;
+       case WCS_SERVCMD:
+               lprintf(1, "  -> Server [%s]\n", ptr->wcs_value);
+               break;
+       case WCS_FUNCTION:
+               lprintf(1, "  -> function at [%0xd]\n", ptr->wcs_function);
+               break;
+       default:
+               lprintf(1,"  WARNING: invalid type: [%ld]!\n", ptr->wcs_type);
+       }
+}
 
-       while (wc->vars != NULL) {
-               ptr = wc->vars->next;
 
-               if ((wc->vars->wcs_type == WCS_STRING)
-                  || (wc->vars->wcs_type == WCS_SERVCMD)) {
-                       free(wc->vars->wcs_value);
-               }
 
-               free(wc->vars);
-               wc->vars = ptr;
-       }
+/**
+ * \brief Clear out the list of substitution variables local to this session
+ */
+void clear_substs(struct wcsession *wc) {
 
-       wc->vars = NULL;
+       if (wc->vars != NULL) {
+       
+               DeleteHash(&wc->vars);
+       }
 }
 
 /**
@@ -43,39 +64,51 @@ void clear_local_substs(void) {
        clear_substs (WC);
 }
 
+/**
+ * \brief destructor; kill one entry.
+ */
+void deletevar(void *data)
+{
+       wcsubst *ptr = (wcsubst*)data;
+//             if ((wc->vars->wcs_type == WCS_STRING)
+//                || (wc->vars->wcs_type == WCS_SERVCMD)) {
+       if (ptr->wcs_type != WCS_FUNCTION)
+               free(ptr->wcs_value);
+       free(ptr);      
+}
 
-/*
- * \brief Add a substitution variable (local to this session)
+/**
+ * \brief Add a substitution variable (local to this session) (strlen version...)
  * \param keyname the replacementstring to substitute
  * \param keytype the kind of the key
  * \param format the format string ala printf
  * \param ... the arguments to substitute in the formatstring
  */
-void svprintf(char *keyname, int keytype, const char *format,...)
+void SVPRINTF(char *keyname, int keytype, const char *format,...)
 {
        va_list arg_ptr;
        char wbuf[SIZ];
-       struct wcsubst *ptr = NULL;
-       struct wcsubst *scan;
-
+       void *vPtr;
+       wcsubst *ptr = NULL;
+       size_t keylen;
+       struct wcsession *WCC = WC;
+       
+       keylen = strlen(keyname);
        /**
-        * First scan through to see if we're doing a replacement of
+        * First look if we're doing a replacement of
         * an existing key
         */
-       for (scan=WC->vars; scan!=NULL; scan=scan->next) {
-               if (!strcasecmp(scan->wcs_key, keyname)) {
-                       ptr = scan;
-                       if (ptr->wcs_value != NULL)
-                               free(ptr->wcs_value);
-               }
+       /*PrintHash(WCC->vars, VarPrintTransition, VarPrintEntry);*/
+       if (GetHash(WCC->vars, keyname, keylen, &vPtr)) {
+               ptr = (wcsubst*)vPtr;
+               if (ptr->wcs_value != NULL)
+                       free(ptr->wcs_value);
        }
-
-       /** Otherwise allocate a new one */
-       if (ptr == NULL) {
-               ptr = (struct wcsubst *) malloc(sizeof(struct wcsubst));
+       else    /** Otherwise allocate a new one */
+       {
+               ptr = (wcsubst *) malloc(sizeof(wcsubst));
                safestrncpy(ptr->wcs_key, keyname, sizeof ptr->wcs_key);
-               ptr->next = WC->vars;
-               WC->vars = ptr;
+               Put(WCC->vars, keyname, keylen, ptr,  deletevar);
        }
 
        /** Format the string and save it */
@@ -89,40 +122,123 @@ void svprintf(char *keyname, int keytype, const char *format,...)
        ptr->wcs_value = strdup(wbuf);
 }
 
+/**
+ * \brief Add a substitution variable (local to this session)
+ * \param keyname the replacementstring to substitute
+ * \param keytype the kind of the key
+ * \param format the format string ala printf
+ * \param ... the arguments to substitute in the formatstring
+ */
+void svprintf(char *keyname, size_t keylen, int keytype, const char *format,...)
+{
+       va_list arg_ptr;
+       char wbuf[SIZ];
+       void *vPtr;
+       wcsubst *ptr = NULL;
+       struct wcsession *WCC = WC;
+       size_t len;
+       
+       /**
+        * First look if we're doing a replacement of
+        * an existing key
+        */
+       /*PrintHash(WCC->vars, VarPrintTransition, VarPrintEntry);*/
+       if (GetHash(WCC->vars, keyname, keylen, &vPtr)) {
+               ptr = (wcsubst*)vPtr;
+               if (ptr->wcs_value != NULL)
+                       free(ptr->wcs_value);
+       }
+       else    /** Otherwise allocate a new one */
+       {
+               ptr = (wcsubst *) malloc(sizeof(wcsubst));
+               safestrncpy(ptr->wcs_key, keyname, sizeof ptr->wcs_key);
+               Put(WCC->vars, keyname, keylen, ptr,  deletevar);
+       }
+
+       /** Format the string and save it */
+
+       va_start(arg_ptr, format);
+       len = vsnprintf(wbuf, sizeof wbuf, format, arg_ptr);
+       va_end(arg_ptr);
+
+       ptr->wcs_value = (char*) malloc(len + 1);
+       memcpy(ptr->wcs_value, wbuf, len + 1);
+       ptr->wcs_function = NULL;
+       ptr->wcs_type = keytype;
+}
+
+/**
+ * \brief Add a substitution variable (local to this session)
+ * \param keyname the replacementstring to substitute
+ * \param keytype the kind of the key
+ * \param format the format string ala printf
+ * \param ... the arguments to substitute in the formatstring
+ */
+void SVPut(char *keyname, size_t keylen, int keytype, char *Data)
+{
+       void *vPtr;
+       wcsubst *ptr = NULL;
+       struct wcsession *WCC = WC;
+
+       
+       /**
+        * First look if we're doing a replacement of
+        * an existing key
+        */
+       /*PrintHash(WCC->vars, VarPrintTransition, VarPrintEntry);*/
+       if (GetHash(WCC->vars, keyname, keylen, &vPtr)) {
+               ptr = (wcsubst*)vPtr;
+               if (ptr->wcs_value != NULL)
+                       free(ptr->wcs_value);
+       }
+       else    /** Otherwise allocate a new one */
+       {
+               ptr = (wcsubst *) malloc(sizeof(wcsubst));
+               safestrncpy(ptr->wcs_key, keyname, sizeof ptr->wcs_key);
+               Put(WCC->vars, keyname, keylen, ptr,  deletevar);
+       }
+
+       ptr->wcs_function = NULL;
+       ptr->wcs_type = keytype;
+       ptr->wcs_value = strdup(Data);
+}
+
 /**
  * \brief Add a substitution variable (local to this session) that does a callback
  * \param keyname the keystring to substitute
  * \param fcn_ptr the function callback to give the substitution string
  */
-void svcallback(char *keyname, void (*fcn_ptr)() )
+void SVCallback(char *keyname, size_t keylen, var_callback_fptr fcn_ptr)
 {
-       struct wcsubst *scan;
-       struct wcsubst *ptr;
+       wcsubst *ptr;
+       void *vPtr;
+       struct wcsession *WCC = WC;
 
        /**
-        * First scan through to see if we're doing a replacement of
+        * First look if we're doing a replacement of
         * an existing key
         */
-       ptr = NULL;
-       for (scan=WC->vars; scan!=NULL; scan=scan->next) {
-               if (!strcasecmp(scan->wcs_key, keyname)) {
-                       ptr = scan;
-                       if (ptr->wcs_value != NULL)
-                               free(ptr->wcs_value);
-               }
+       /*PrintHash(WCC->vars, VarPrintTransition, VarPrintEntry);*/
+       if (GetHash(WCC->vars, keyname, keylen, &vPtr)) {
+               ptr = (wcsubst*)vPtr;
+               if (ptr->wcs_value != NULL)
+                       free(ptr->wcs_value);
        }
-
-       /** Otherwise allocate a new one */
-       if (ptr == NULL) {
-               ptr = (struct wcsubst *) malloc(sizeof(struct wcsubst));
+       else    /** Otherwise allocate a new one */
+       {
+               ptr = (wcsubst *) malloc(sizeof(wcsubst));
                safestrncpy(ptr->wcs_key, keyname, sizeof ptr->wcs_key);
-               ptr->next = WC->vars;
-               WC->vars = ptr;
+               Put(WCC->vars, keyname, keylen, ptr,  deletevar);
        }
+
        ptr->wcs_value = NULL;
        ptr->wcs_type = WCS_FUNCTION;
        ptr->wcs_function = fcn_ptr;
 }
+inline void SVCALLBACK(char *keyname, var_callback_fptr fcn_ptr)
+{
+       SVCallback(keyname, strlen(keyname), fcn_ptr);
+}
 
 
 
@@ -152,22 +268,39 @@ void pvo_do_cmd(char *servcmd) {
        }
 }
 
-
-
 /**
  * \brief Print the value of a variable
  * \param keyname get a key to print
  */
-void print_value_of(char *keyname) {
-       struct wcsubst *ptr;
+void print_value_of(char *keyname, size_t keylen) {
+       struct wcsession *WCC = WC;
+       wcsubst *ptr;
        void *fcn();
+       void *vVar;
 
+       /*if (WCC->vars != NULL) PrintHash(WCC->vars, VarPrintTransition, VarPrintEntry);*/
        if (keyname[0] == '=') {
                do_template(&keyname[1]);
        }
-
-       if (!strcasecmp(keyname, "SERV_PID")) {
-               wprintf("%d", WC->ctdl_pid);
+       /** Page-local variables */
+       if ((WCC->vars!= NULL) && GetHash(WCC->vars, keyname, keylen, &vVar)) {
+               ptr = (wcsubst*) vVar;
+               switch(ptr->wcs_type) {
+               case WCS_STRING:
+                       wprintf("%s", ptr->wcs_value);
+                       break;
+               case WCS_SERVCMD:
+                       pvo_do_cmd(ptr->wcs_value);
+                       break;
+               case WCS_FUNCTION:
+                       (*ptr->wcs_function) ();
+                       break;
+               default:
+                       lprintf(1,"WARNING: invalid value in SV-Hash at %s!", keyname);
+               }
+       }
+       else if (!strcasecmp(keyname, "SERV_PID")) {
+               wprintf("%d", WCC->ctdl_pid);
        }
 
        else if (!strcasecmp(keyname, "SERV_NODENAME")) {
@@ -198,27 +331,13 @@ void print_value_of(char *keyname) {
        }
 
        else if (!strcasecmp(keyname, "CURRENT_USER")) {
-               escputs(WC->wc_fullname);
+               escputs(WCC->wc_fullname);
        }
 
        else if (!strcasecmp(keyname, "CURRENT_ROOM")) {
-               escputs(WC->wc_roomname);
+               escputs(WCC->wc_roomname);
        }
 
-       /** Page-local variables */
-       else for (ptr = WC->vars; ptr != NULL; ptr = ptr->next) {
-               if (!strcasecmp(ptr->wcs_key, keyname)) {
-                       if (ptr->wcs_type == WCS_STRING) {
-                               wprintf("%s", ptr->wcs_value);
-                       }
-                       else if (ptr->wcs_type == WCS_SERVCMD) {
-                               pvo_do_cmd(ptr->wcs_value);
-                       }
-                       else if (ptr->wcs_type == WCS_FUNCTION) {
-                               (*ptr->wcs_function) ();
-                       }
-               }
-       }
 }
 
 extern char *static_dirs[PATH_MAX];  /**< Disk representation */
@@ -288,7 +407,7 @@ void do_template(void *templatename) {
                                }
                                strncpy(key, &inbuf[2], pos-2);
                                key[pos-2] = 0;
-                               print_value_of(key);
+                               print_value_of(key, pos-2);
                                pos++;
                                memmove(inbuf, &inbuf[pos], len - pos + 1);
                                len -= pos;
index 08b73f407c46c7fde12b155e787e78492cc02559..f71a43b080c5589ff1f8b71dcb2dd9972be00853 100644 (file)
@@ -28,7 +28,7 @@ void output_date(void) {
  * \brief Dummy section
  */
 void dummy_section(void) {
-       svprintf("BOXTITLE", WCS_STRING, "(dummy&nbsp;section)");
+       svput("BOXTITLE", WCS_STRING, "(dummy&nbsp;section)");
        do_template("beginbox");
        wprintf(_("(nothing)"));
        do_template("endbox");
index cbe41717e78cdc3e682254b96a9e4a1ff6fb74f6..84ea33d06eb17ce1d68b3b746272af9113e691da 100644 (file)
@@ -65,6 +65,7 @@
 
 pthread_mutex_t Critters[MAX_SEMAPHORES];      /* Things needing locking */
 pthread_key_t MyConKey;                                /* TSD key for MyContext() */
+pthread_key_t MyReq;                           /* TSD key for MyReq() */
 
 void InitialiseSemaphores(void)
 {
index 1dac62755e8a85c683e800a0538834c5f12f9f84..e336f0f774327e111a0f164fb6491ed77e7f31bf 100644 (file)
@@ -37,7 +37,7 @@ void display_edit(char *description, char *check_cmd,
                output_headers(1, 1, 0, 0, 0, 0);
        }
 
-       svprintf("BOXTITLE", WCS_STRING, _("Edit %s"), description);
+       svprintf(HKEY("BOXTITLE"), WCS_STRING, _("Edit %s"), description);
        do_template("beginbox");
 
        wprintf(_("Enter %s below. Text is formatted to the reader's browser."
index 1d37da65d8cf601389a3f7e6351e685fd2ed0c9c..425139a7e67e331ec3e57a3e6229cbd28043b63d 100644 (file)
@@ -36,7 +36,7 @@ void select_user_to_edit(char *message, char *preselect)
 
        wprintf("<table border=0 cellspacing=10><tr valign=top><td>\n");
 
-       svprintf("BOXTITLE", WCS_STRING, _("Add users"));
+       svput("BOXTITLE", WCS_STRING, _("Add users"));
        do_template("beginbox");
 
        wprintf(_("To create a new user account, enter the desired "
@@ -54,7 +54,7 @@ void select_user_to_edit(char *message, char *preselect)
 
        wprintf("</td><td>");
 
-       svprintf("BOXTITLE", WCS_STRING, _("Edit or Delete users"));
+       svput("BOXTITLE", WCS_STRING, _("Edit or Delete users"));
        do_template("beginbox");
 
        wprintf(_("To edit an existing user account, select the user "
index 4017387547f15b96636510dc150c80ce5c51f916..4b036e03fab68237dd857983f48ac650fff0eb16 100644 (file)
@@ -187,7 +187,7 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to, char *force_room
        /** Display the form */
        output_headers(1, 1, 1, 0, 0, 0);
 
-       svprintf("BOXTITLE", WCS_STRING, _("Edit contact information"));
+       svput("BOXTITLE", WCS_STRING, _("Edit contact information"));
        do_template("beginbox");
 
        wprintf("<form method=\"POST\" action=\"submit_vcard\">\n");
index 7887e0a18d4702f3dc87147adac8bb63e5588701..0d16385cb075478d631940cdc27ba74df14dc056 100644 (file)
@@ -674,7 +674,7 @@ void output_headers(        int do_httpheaders,     /* 1 = output HTTP headers
        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\">"
                        );
                }
@@ -794,7 +794,7 @@ void print_menu_box(char* Title, char *Class, int nLines, ...)
        va_list arg_list;
        long i;
        
-       svprintf("BOXTITLE", WCS_STRING, Title);
+       svput("BOXTITLE", WCS_STRING, Title);
        do_template("beginbox");
        
        wprintf("<ul class=\"%s\">", Class);
@@ -1368,7 +1368,6 @@ void session_loop(struct httprequest *req)
 
        WC->upload_length = 0;
        WC->upload = NULL;
-       WC->vars = NULL;
        WC->is_wap = 0;
 
        hptr = req;
index c6b4d00ab75bf29b79aed3fdb0b48df069d6eef1..bec5aa6c1dd23c40b4a59bdababcac4133382532 100644 (file)
@@ -284,13 +284,12 @@ struct roomlisting {
 /**
  * \brief Dynamic content for variable substitution in templates
  */
-struct wcsubst {
-       struct wcsubst *next;       /**< next item in the list */  
+typedef struct _wcsubst {
        int wcs_type;                       /**< which type of ??? */
        char wcs_key[32];                   /**< ??? what?*/
        void *wcs_value;                    /**< ???? what?*/
        void (*wcs_function)(void); /**< funcion hook ???*/
-};
+} wcsubst;
 
 /**
  * \brief Values for wcs_type
@@ -385,7 +384,7 @@ struct wcsession {
        struct message_summary *summ;           /**< array of messages for mailbox summary view */
        int is_wap;                             /**< Client is a WAP gateway */
        HashList *urlstrings;                   /**< variables passed to webcit in a URL */
-       struct wcsubst *vars;                   /**< HTTP variable substitutions for this page */
+       HashList *vars;                         /**< HTTP variable substitutions for this page */
        char this_page[512];                    /**< URL of current page */
        char http_host[512];                    /**< HTTP Host: header */
        HashList *hash_prefs;                   /**< WebCit preferences for this user */
@@ -635,9 +634,22 @@ void chat_send(void);
 void http_redirect(char *);
 void clear_substs(struct wcsession *wc);
 void clear_local_substs(void);
-void svprintf(char *keyname, int keytype, const char *format,...);
-void svcallback(char *keyname, void (*fcn_ptr)() );
+
+
+typedef void (*var_callback_fptr)();
+
+
+void SVPut(char *keyname, size_t keylen, int keytype, char *Data);
+#define svput(a, b, c) SVPut(a, sizeof(a) - 1, b, c)
+void svprintf(char *keyname, size_t keylen, int keytype, const char *format,...);
+void SVPRINTF(char *keyname, int keytype, const char *format,...);
+void SVCALLBACK(char *keyname, var_callback_fptr fcn_ptr);
+void SVCallback(char *keyname, size_t keylen,  var_callback_fptr fcn_ptr);
+#define svcallback(a, b) SVCallback(a, sizeof(a) - 1, b)
+
 void do_template(void *templatename);
+
+
 int lingering_close(int fd);
 char *memreadline(char *start, char *buf, int maxlen);
 char *memreadlinelen(char *start, char *buf, int maxlen, int *retlen);