* shortcut notation to tokens for hashkeys; TKEY(n) will make str,len for Hash access
authorWilfried Göesgens <willi@citadel.org>
Sat, 20 Dec 2008 23:53:31 +0000 (23:53 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 20 Dec 2008 23:53:31 +0000 (23:53 +0000)
* some fixups to the message dropdown selectors

webcit/inetconf.c
webcit/messages.c
webcit/msg_renderers.c
webcit/paramhandling.c
webcit/preferences.c
webcit/siteconfig.c
webcit/static/t/msg_listselector_top.html
webcit/static/t/select_messageindex_all.html
webcit/subst.c
webcit/webcit.c
webcit/webcit.h

index 56981ddaae694f0bd21ec28aa0bc1d7737bfdb9f..f50a045bdafb164077e3234a8f99e471b9b45207 100644 (file)
@@ -197,10 +197,7 @@ HashList *GetInetConfHash(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo
 
        if (WCC->InetCfg == NULL)
                load_inetconf();
-       GetHash(WCC->InetCfg, 
-               Tokens->Params[2]->Start, 
-               Tokens->Params[2]->len,
-               &vHash);
+       GetHash(WCC->InetCfg, TKEY(2), &vHash);
        svprintf(HKEY("SERVCFG:INET:TYPE"), WCS_STRING, Tokens->Params[2]->Start);
        return vHash;
 }
index 91fe9b82e764a4e26ce8b3ca0f18c1f774177c42..c159a055acf38399a4e693eafde6051224bf61ec 100644 (file)
@@ -530,6 +530,8 @@ void DrawMessageDropdown(StrBuf *Selector, long maxmsgs, long startmsg)
        }
        vector[6] = StartMsg;
        FlushStrBuf(TmpBuf);
+       vector[1] = lbstr("maxmsgs") == 9999999;
+       vector[2] = 0;
        DoTemplate(HKEY("select_messageindex_all"), TmpBuf, &vector, CTX_LONGVECTOR);
        StrBufAppendBuf(Selector, TmpBuf, 0);
        FreeStrBuf(&TmpBuf);
@@ -592,12 +594,9 @@ void readloop(long oper)
        long *displayed_msgs = NULL;
        int num_displayed = 0;
        int is_summary = 0;
-       int is_addressbook = 0;
        int is_singlecard = 0;
-       int is_calendar = 0;
        struct calview calv;
-       int is_tasks = 0;
-       int is_notes = 0;
+
        int is_bbview = 0;
        int lowest_displayed = (-1);
        int highest_displayed = 0;
@@ -619,18 +618,15 @@ void readloop(long oper)
                return;
        case VIEW_CALENDAR:
                load_seen = 1;
-               is_calendar = 1;
                strcpy(cmd, "MSGS ALL|||1");
                maxmsgs = 32767;
                parse_calendar_view_request(&calv);
                break;
        case VIEW_TASKS:
-               is_tasks = 1;
                strcpy(cmd, "MSGS ALL");
                maxmsgs = 32767;
                break;
        case VIEW_NOTES:
-               is_notes = 1;
                strcpy(cmd, "MSGS ALL");
                maxmsgs = 32767;
                wprintf("<div id=\"new_notes_here\"></div>\n");
@@ -638,7 +634,6 @@ void readloop(long oper)
        case VIEW_ADDRESSBOOK:
                is_singlecard = ibstr("is_singlecard");
                if (is_singlecard != 1) {
-                       is_addressbook = 1;
                        if (oper == do_search) {
                                snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
                        }
@@ -683,29 +678,29 @@ void readloop(long oper)
                        maxmsgs = 9999999;
                } 
 
-               bbs_reverse = is_bbview && (lbstr("SortOrder") == 2);
-
+               if (is_bbview) {
+                       if (havebstr("SortOrder")) {
+                               bbs_reverse = lbstr("SortOrder") == 2;
+                       }
+                       else {
+                               StrBuf *Buf = NewStrBufPlain(HKEY("1"));
+                               putbstr("SortOrder", Buf);
+                               Buf = NewStrBufPlain(HKEY("date"));
+                               putbstr("SortBy", Buf);
+                               bbs_reverse = 0;
+                       }
+               }
                sortit = is_summary || WCC->is_mobile;
+               if (WCC->is_mobile) {
+                       maxmsgs = 20;
+                       snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
+                                ((oper == do_search) ? "SEARCH" : "ALL"),
+                                ((oper == do_search) ? bstr("query") : "")
+                               );
+               }
        }
-
-
        output_headers(1, 1, 1, 0, 0, 0);
 
-       /* TODO: how can we best sort this in?
-       if (WCC->is_mobile) {
-               maxmsgs = 20;
-               snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
-                       (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
-                       (!strcmp(oper, "do_search") ? bstr("query") : "")
-               );
-               SortBy =  eRDate;
-       }
-       */
-       /*
-        * Are we doing a summary view?  If so, we need to know old messages
-        * and new messages, so we can do that pretty boldface thing for the
-        * new messages.
-        */
        nummsgs = load_msg_ptrs(cmd, (is_summary || WCC->is_mobile));
        if (nummsgs == 0) {
                if (care_for_empty_list) {
@@ -725,6 +720,15 @@ void readloop(long oper)
 
                goto DONE;
        }
+
+       if (sortit) {
+               CompareFunc SortIt;
+               SortIt =  RetrieveSort(CTX_MAILSUM, NULL, 
+                                      HKEY("date"), 2);
+               if (SortIt != NULL)
+                       SortByPayload(WCC->summ, SortIt);
+       }
+
        if (is_bbview && (startmsg == 0L)) {
                if (bbs_reverse) {
                        Msg = GetMessagePtrAt((nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0, WCC->summ);
@@ -737,23 +741,10 @@ void readloop(long oper)
        }
 
        if (load_seen) load_seen_flags();
+       if (is_summary) do_template("summary_header", NULL);
+       
 
-       if (sortit) {
-               CompareFunc SortIt;
-               SortIt =  RetrieveSort(CTX_MAILSUM, NULL, 
-                                      HKEY("date"), 2);
-               if (SortIt != NULL)
-                       SortByPayload(WCC->summ, SortIt);
-       }
-
-       if (is_summary) {
-               do_template("summary_header", NULL);
-       } else if (WCC->is_mobile) {
-               wprintf("<div id=\"message_list\">");
-       }
-
-
-       /**
+        /**
         * If we're not currently looking at ALL requested
         * messages, then display the selector bar
         */
@@ -771,13 +762,20 @@ void readloop(long oper)
        at = GetNewHashPos(WCC->summ, 0);
        while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
                Msg = (message_summary*) vMsg;          
-               if ((Msg->msgnum >= startmsg) && (num_displayed < maxmsgs)) {
-                               
-                       /** Display the message */
-                       if (is_summary) {
-                               DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
-                       }
-                       else if (is_addressbook) {
+               if ((Msg->msgnum >= startmsg) && (num_displayed < maxmsgs)) {                   
+                       switch (WCC->wc_view) {
+                       case VIEW_WIKI:
+                               break;
+                       case VIEW_CALENDAR:
+                               load_calendar_item(Msg, Msg->is_new, &calv);
+                               break;
+                       case VIEW_TASKS:
+                               display_task(Msg, Msg->is_new);
+                               break;
+                       case VIEW_NOTES:
+                               display_note(Msg, Msg->is_new);
+                               break;
+                       case VIEW_ADDRESSBOOK:
                                fetch_ab_name(Msg, buf);
                                ++num_ab;
                                addrbook = realloc(addrbook,
@@ -785,30 +783,25 @@ void readloop(long oper)
                                safestrncpy(addrbook[num_ab-1].ab_name, buf,
                                            sizeof(addrbook[num_ab-1].ab_name));
                                addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
-                       }
-                       else if (is_calendar) {
-                               load_calendar_item(Msg, Msg->is_new, &calv);
-                       }
-                       else if (is_tasks) {
-                               display_task(Msg, Msg->is_new);
-                       }
-                       else if (is_notes) {
-                               display_note(Msg, Msg->is_new);
-                       } else if (WCC->is_mobile) {
-                               DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
-                       }
-                       else {
-                               if (displayed_msgs == NULL) {
-                                       displayed_msgs = malloc(sizeof(long) *
-                                                               (maxmsgs<nummsgs ? maxmsgs : nummsgs));
+                               break;
+                       default:
+                               /** Display the message */
+                               if (is_summary) {
+                                       DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
+                               }
+                               else {
+                                       if (displayed_msgs == NULL) {
+                                               displayed_msgs = malloc(sizeof(long) *
+                                                                       (maxmsgs<nummsgs ? maxmsgs : nummsgs));
+                                       }
+                                       displayed_msgs[num_displayed] = Msg->msgnum;
                                }
-                               displayed_msgs[num_displayed] = Msg->msgnum;
-                       }
                        
-                       if (lowest_displayed < 0) lowest_displayed = a;
-                       highest_displayed = a;
+                               if (lowest_displayed < 0) lowest_displayed = a;
+                               highest_displayed = a;
                        
-                       ++num_displayed;
+                               ++num_displayed;
+                       }
                }
        }
        DeleteHashPos(&at);
@@ -822,7 +815,7 @@ void readloop(long oper)
                /** if we do a split bbview in the future, begin messages div here */
 
                for (a=0; a<num_displayed; ++a) {
-                       read_message(WC->WBuf, HKEY("view_message"), displayed_msgs[a], 0, NULL);
+                       read_message(WCC->WBuf, HKEY("view_message"), displayed_msgs[a], 0, NULL);
                }
 
                /** if we do a split bbview in the future, end messages div here */
@@ -833,8 +826,6 @@ void readloop(long oper)
 
        if (is_summary) {
                do_template("summary_trailer", NULL);
-       } else if (WCC->is_mobile) {
-               wprintf("</div>");
        }
 
        /**
@@ -849,8 +840,6 @@ void readloop(long oper)
         * messages, then display the selector bar
         */
        if (is_bbview) {
-               /** begin bbview scroller */
-
                DoTemplate(HKEY("msg_listselector_bottom"), BBViewToolBar, MessageDropdown, CTX_STRBUF);
                StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
 
@@ -859,18 +848,23 @@ void readloop(long oper)
        }
        
 DONE:
-       if (is_tasks) {
-               do_tasks_view();        /** Render the task list */
-       }
-
-       if (is_calendar) {
+       switch (WCC->wc_view) {
+       case VIEW_WIKI:
+               break;
+       case VIEW_CALENDAR:
                render_calendar_view(&calv);
-       }
-
-       if (is_addressbook) {
+               break;
+       case VIEW_TASKS:
+               do_tasks_view();        /** Render the task list */
+               break;
+       case VIEW_NOTES:
+               break;
+       case VIEW_ADDRESSBOOK:
                do_addrbook_view(addrbook, num_ab);     /** Render the address book */
+               break;
+       default:
+               break;
        }
-
        /** Note: wDumpContent() will output one additional </div> tag. */
        wprintf("</div>\n");            /** end of 'content' div */
        wDumpContent(1);
@@ -1574,19 +1568,12 @@ void download_postpart(void) {
                 1);
 }
 
-
-
 void h_readnew(void) { readloop(readnew);}
 void h_readold(void) { readloop(readold);}
 void h_readfwd(void) { readloop(readfwd);}
 void h_headers(void) { readloop(headers);}
 void h_do_search(void) { readloop(do_search);}
 
-
-
-
-
-
 void 
 InitModule_MSG
 (void)
index 97e0b66f9f4fe566baa83a53b430dbcf729feb2a..d9955e8e586b2fc8319be574ca3c9cc85bf6145f 100644 (file)
@@ -664,7 +664,7 @@ void tmplput_QUOTED_MAIL_BODY(StrBuf *Target, int nArgs, WCTemplateToken *Tokens
        long MsgNum;
        StrBuf *Buf;
 
-       MsgNum = LBstr(Tokens->Params[0]->Start, Tokens->Params[0]->len);
+       MsgNum = LBstr(TKEY(0));
        Buf = NewStrBuf();
        read_message(Buf, HKEY("view_message_replyquote"), MsgNum, 0, NULL);
        StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Buf, 1);
index 7e85cfbe4c721d225b00a621957d14a3dde6ae55..afa264f10352d44bb486bc0b285f59d9b8a03a89 100644 (file)
@@ -332,3 +332,92 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
        }
 
 }
+
+
+
+void PutBstr(const char *key, long keylen, StrBuf *Value)
+{
+       urlcontent *u;
+
+       if(keylen > sizeof(u->url_key)) {
+               lprintf(1, "URLkey to long! [%s]", key);
+               FreeStrBuf(&Value);
+               return;
+       }
+       u = (urlcontent*)malloc(sizeof(urlcontent));
+       memcpy(u->url_key, key, keylen + 1);
+       u->url_data = Value;
+       Put(WC->urlstrings, u->url_key, keylen, u, free_url);
+}
+
+
+
+int ConditionalBstr(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       if(Tokens->nParameters == 3)
+               return HaveBstr(TKEY(2));
+       else {
+               if (Tokens->Params[3]->Type == TYPE_LONG)
+                       return LBstr(TKEY(2)) == Tokens->Params[3]->lvalue;
+               else 
+                       return strcmp(Bstr(TKEY(2)),
+                                     Tokens->Params[3]->Start) == 0;
+       }
+}
+
+void tmplput_bstr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       const StrBuf *Buf = SBstr(TKEY(0));
+       if (Buf != NULL)
+               StrBufAppendTemplate(Target, nArgs, Tokens, 
+                                    Context, ContextType,
+                                    Buf, 1);
+}
+
+void diagnostics(void)
+{
+       output_headers(1, 1, 1, 0, 0, 0);
+       wprintf("Session: %d<hr />\n", WC->wc_session);
+       wprintf("Command: <br /><PRE>\n");
+       StrEscPuts(WC->UrlFragment1);
+       wprintf("<br />\n");
+       StrEscPuts(WC->UrlFragment2);
+       wprintf("<br />\n");
+       StrEscPuts(WC->UrlFragment3);
+       wprintf("</PRE><hr />\n");
+       wprintf("Variables: <br /><PRE>\n");
+       dump_vars();
+       wprintf("</PRE><hr />\n");
+       wDumpContent(1);
+}
+
+
+void tmplput_url_part(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       StrBuf *UrlBuf;
+       wcsession *WCC = WC;
+       
+       if (WCC != NULL) {
+               if (Tokens->Params[0]->lvalue == 0)
+                       UrlBuf = WCC->UrlFragment1;
+               else if (Tokens->Params[0]->lvalue == 1)
+                       UrlBuf = WCC->UrlFragment2;
+               else
+                       UrlBuf = WCC->UrlFragment3;
+
+               StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType,
+                                    UrlBuf, 1);
+       }
+}
+
+
+void 
+InitModule_PARAMHANDLING
+(void)
+{
+       WebcitAddUrlHandler(HKEY("diagnostics"), diagnostics, NEED_URL);
+
+       RegisterConditional(HKEY("COND:BSTR"), 1, ConditionalBstr, CTX_NONE);
+       RegisterNamespace("BSTR", 1, 2, tmplput_bstr, CTX_NONE);
+       RegisterNamespace("URLPART", 1, 2, tmplput_url_part, CTX_NONE);
+}
index 92b9d91917ae6fc765ddbdf0605eae27b4c2e0e8..0ed7b68d729b9927d09fbecbe07e73cdc4ca85ac 100644 (file)
@@ -735,17 +735,14 @@ void set_preferences(void)
 void tmplput_CFG_Value(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        StrBuf *Setting;
-       if (get_PREFERENCE(Tokens->Params[0]->Start,
-                          Tokens->Params[0]->len,
-                          &Setting))
+       if (get_PREFERENCE(TKEY(0), &Setting))
        StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Setting, 1);
 }
 
 void tmplput_CFG_Descr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        const char *SettingStr;
-       SettingStr = PrefGetLocalStr(Tokens->Params[0]->Start,
-                                    Tokens->Params[0]->len);
+       SettingStr = PrefGetLocalStr(TKEY(0));
        if (SettingStr != NULL) 
                StrBufAppendBufPlain(Target, SettingStr, -1, 0);
 }
@@ -762,9 +759,7 @@ int ConditionalPreference(WCTemplateToken *Tokens, void *Context, int ContextTyp
 {
        StrBuf *Pref;
 
-       if (!get_PREFERENCE(Tokens->Params[2]->Start,
-                           Tokens->Params[2]->len,
-                           &Pref)) 
+       if (!get_PREFERENCE(TKEY(2), &Pref)) 
                return 0;
        
        if (Tokens->nParameters == 3) {
@@ -781,9 +776,7 @@ int ConditionalHazePreference(WCTemplateToken *Tokens, void *Context, int Contex
 {
        StrBuf *Pref;
 
-       if (!get_PREFERENCE(Tokens->Params[2]->Start,
-                           Tokens->Params[2]->len,
-                           &Pref) || 
+       if (!get_PREFERENCE(TKEY(2), &Pref) || 
            (Pref == NULL)) 
                return 0;
        else 
index 58c7e1ca637f9b89dddf18f31bae93ac921b32c7..7d1a0b732bf1bab0ef75c71ea0c5cb1a468d1d72 100644 (file)
@@ -254,10 +254,7 @@ void tmplput_servcfg(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *C
        if (WCC->is_aide) {
                if (WCC->ServCfg == NULL)
                        load_siteconfig();
-               GetHash(WCC->ServCfg, 
-                       Tokens->Params[0]->Start,
-                       Tokens->Params[0]->len, 
-                       &vBuf);
+               GetHash(WCC->ServCfg, TKEY(0), &vBuf);
                Buf = (StrBuf*) vBuf;
                StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Buf, 1);
        }
@@ -272,10 +269,7 @@ int ConditionalServCfg(WCTemplateToken *Tokens, void *Context, int ContextType)
        if (WCC->is_aide) {
                if (WCC->ServCfg == NULL)
                        load_siteconfig();
-               GetHash(WCC->ServCfg, 
-                       Tokens->Params[2]->Start,
-                       Tokens->Params[2]->len, 
-                       &vBuf);
+               GetHash(WCC->ServCfg, TKEY(2), &vBuf);
                if (vBuf == NULL) return 0;
                Buf = (StrBuf*) vBuf;
                if (Tokens->nParameters == 3) {
@@ -297,10 +291,7 @@ int ConditionalServCfgSubst(WCTemplateToken *Tokens, void *Context, int ContextT
        if (WCC->is_aide) {
                if (WCC->ServCfg == NULL)
                        load_siteconfig();
-               GetHash(WCC->ServCfg, 
-                       Tokens->Params[2]->Start,
-                       Tokens->Params[2]->len, 
-                       &vBuf);
+               GetHash(WCC->ServCfg, TKEY(2), &vBuf);
                if (vBuf == NULL) return 0;
                Buf = (StrBuf*) vBuf;
 
index d6cb5989126e87c3c0f9b1a156b8fba6a1afe2f0..0c81f9cc1b2014f13c0b87698122b91b2a0656ff 100644 (file)
@@ -6,7 +6,7 @@
 </select>
 
 <input type="radio" name="direction" value="" 
-  OnChange="location.href='<?URLPART(1)>?SortBy=date&SortOrder=2'"
+  OnChange="location.href='<?URLPART(1)>?SortBy=date&SortOrder=1'"
   <?%("COND:BSTR", 1, "SortOrder", 1, "checked", "")>
 >
 <?_("oldest to newest")> 
@@ -14,8 +14,8 @@
 &nbsp;&nbsp;&nbsp;&nbsp;
 
 <input type="radio" name="direction" value="" 
-  OnChange="location.href='<?URLPART(1)>?SortBy=date&SortOrder=1'"
-  <?%("COND:BSTR", 1, "SortOrder", 1, "", "checked")>
+  OnChange="location.href='<?URLPART(1)>?SortBy=date&SortOrder=2'"
+  <?%("COND:BSTR", 1, "SortOrder", 2, "checked", "")>
 >
 <?_("newest to oldest")>
 </p>
index a57429be7cbb1aa7f106721920d7c8c4081f3562..e32694878560f6593d8120557d5c809fa13fc5e5 100644 (file)
@@ -1 +1 @@
-<option <?%("COND:LONGVECTOR", 1, 1, 6, "selected", "")> value="<?URLPART(0)>?startmsg=<?LONGVECTOR(6)>&maxmsgs=9999999&is_summary=0&SortBy=date&SortOrder=<?BSTR("SortOrder")>"><?_("All")></option>
+<option <?%("COND:LONGVECTOR", 1, 1, 2, "", "selected")> value="<?URLPART(0)>?startmsg=<?LONGVECTOR(6)>&maxmsgs=9999999&is_summary=0&SortBy=date&SortOrder=<?BSTR("SortOrder")>"><?_("All")></option>
index 1de23b6ae5e67ffb899d09b0a8324e581727be96..a4c123594a2a3e7f267f9bdd2d6a2ce35e2acfbf 100644 (file)
@@ -485,16 +485,12 @@ void GetTemplateTokenString(WCTemplateToken *Tokens,
                *len = Tokens->Params[N]->len;
                break;
        case TYPE_BSTR:
-               Buf = (StrBuf*) SBstr(Tokens->Params[N]->Start, 
-                                     Tokens->Params[N]->len);
+               Buf = (StrBuf*) SBstr(TKEY(N));
                *Value = ChrPtr(Buf);
                *len = StrLength(Buf);
                break;
        case TYPE_PREFSTR:
-               get_PREFERENCE(
-                       Tokens->Params[N]->Start, 
-                       Tokens->Params[N]->len, 
-                       &Buf);
+               get_PREFERENCE(TKEY(N), &Buf);
                *Value = ChrPtr(Buf);
                *len = StrLength(Buf);
                break;
@@ -956,8 +952,8 @@ WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf,
                        break;
                }
                if (!GetHash(Conditionals, 
-                            NewToken->Params[0]->Start,
-                            NewToken->Params[0]->len,
+                            NewToken->Params[0]->Start, 
+                            NewToken->Params[0]->len, 
                             &vVar) || 
                    (vVar == NULL)) {
                        if ((NewToken->Params[0]->len == 1) &&
@@ -1240,7 +1236,7 @@ int EvaluateToken(StrBuf *Target, WCTemplateToken *Tokens, WCTemplate *pTmpl, vo
                break;
        case SV_SUBTEMPL:
                if (Tokens->nParameters == 1)
-                       DoTemplate(Tokens->Params[0]->Start, Tokens->Params[0]->len, NULL, NULL, ContextType);
+                       DoTemplate(TKEY(0), NULL, NULL, ContextType);
                break;
        case SV_PREEVALUATED:
                Handler = (HashHandler*) Tokens->PreEval;
@@ -1491,10 +1487,7 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo
        StrBuf *SubBuf;
        int oddeven = 0;
        
-       if (!GetHash(Iterators, 
-                    Tokens->Params[0]->Start,
-                    Tokens->Params[0]->len,
-                    &vIt)) {
+       if (!GetHash(Iterators, TKEY(0), &vIt)) {
                lprintf(1, "unknown Iterator [%s] (in '%s' line %ld); "
                        " [%s]\n", 
                        Tokens->Params[0]->Start,
@@ -1575,10 +1568,7 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo
 
                if (It->DoSubTemplate != NULL)
                        It->DoSubTemplate(SubBuf, vContext, Tokens);
-               DoTemplate(Tokens->Params[1]->Start,
-                          Tokens->Params[1]->len,
-                          SubBuf, vContext,
-                          It->ContextType);
+               DoTemplate(TKEY(1), SubBuf, vContext, It->ContextType);
                        
                StrBufAppendBuf(Target, SubBuf, 0);
                FlushStrBuf(SubBuf);
@@ -1640,10 +1630,7 @@ int ConditionalVar(WCTemplateToken *Tokens, void *Context, int ContextType)
        void *vsubst;
        wcsubst *subst;
        
-       if (!GetHash(WC->vars, 
-                    Tokens->Params[2]->Start,
-                    Tokens->Params[2]->len,
-                    &vsubst))
+       if (!GetHash(WC->vars, TKEY(2), &vsubst))
                return 0;
        subst = (wcsubst*) vsubst;
        if ((subst->ContextRequired != CTX_NONE) &&
@@ -1716,11 +1703,7 @@ void tmpl_do_boxed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Con
        if (nArgs == 2) {
                if (Tokens->Params[1]->Type == TYPE_STR) {
                        Headline = NewStrBuf();
-                       DoTemplate(Tokens->Params[1]->Start, 
-                                  Tokens->Params[1]->len,
-                                  Headline, 
-                                  Context, 
-                                  ContextType);
+                       DoTemplate(TKEY(1), Headline, Context, ContextType);
                }
                else {
                        const char *Ch;
@@ -1734,11 +1717,7 @@ void tmpl_do_boxed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Con
        }
        
        DoTemplate(HKEY("beginbox"), Target, Headline, CTX_STRBUF);
-       DoTemplate(Tokens->Params[0]->Start, 
-                  Tokens->Params[0]->len,
-                  Target, 
-                  Context, 
-                  ContextType);
+       DoTemplate(TKEY(0), Target, Context, ContextType);
        DoTemplate(HKEY("endbox"), Target, Context, ContextType);
        FreeStrBuf(&Headline);
 }
@@ -1758,11 +1737,7 @@ void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Co
        for (i = 0; i < ntabs; i++) {
                TabNames[i] = NewStrBuf();
                if (Tokens->Params[i * 2]->len > 0) {
-                       DoTemplate(Tokens->Params[i * 2]->Start, 
-                                  Tokens->Params[i * 2]->len,
-                                  TabNames[i],
-                                  Context,
-                                  ContextType);
+                       DoTemplate(TKEY(i * 2), TabNames[i], Context, ContextType);
                }
                else { 
                        /** A Tab without subject? we can't count that, add it as silent */
@@ -1774,11 +1749,7 @@ void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Co
        for (i = 0; i < ntabs; i++) {
                StrBeginTab(Target, i, nTabs);
 
-               DoTemplate(Tokens->Params[i * 2 + 1]->Start, 
-                          Tokens->Params[i * 2 + 1]->len,
-                          Target,
-                          Context, 
-                          ContextType);
+               DoTemplate(TKEY(i * 2 + 1), Target, Context, ContextType);
                StrEndTab(Target, i, nTabs);
        }
 }
@@ -1907,7 +1878,7 @@ int GetSortMetric(WCTemplateToken *Tokens, SortStruct **Next, SortStruct **Param
        
        *SortOrder = 0;
        *Next = NULL;
-       if (!GetHash(SortHash, Tokens->Params[0]->Start, Tokens->Params[0]->len, &vSort) || 
+       if (!GetHash(SortHash, TKEY(0), &vSort) || 
            (vSort == NULL))
                return eNO_SUCH_SORT;
        *Param = (SortStruct*) vSort;
index 909a403871602a8f01fd68faddf8527fc7f2105f..9303f65e641eb1524419ef1417ebf6a8abc9fd53 100644 (file)
@@ -1001,23 +1001,6 @@ void sleeeeeeeeeep(int seconds)
        select(0, NULL, NULL, NULL, &tv);
 }
 
-void diagnostics(void)
-{
-       output_headers(1, 1, 1, 0, 0, 0);
-       wprintf("Session: %d<hr />\n", WC->wc_session);
-       wprintf("Command: <br /><PRE>\n");
-       StrEscPuts(WC->UrlFragment1);
-       wprintf("<br />\n");
-       StrEscPuts(WC->UrlFragment2);
-       wprintf("<br />\n");
-       StrEscPuts(WC->UrlFragment3);
-       wprintf("</PRE><hr />\n");
-       wprintf("Variables: <br /><PRE>\n");
-       dump_vars();
-       wprintf("</PRE><hr />\n");
-       wDumpContent(1);
-}
-
 
 int ConditionalImportantMesage(WCTemplateToken *Tokens, void *Context, int ContextType)
 {
@@ -1042,27 +1025,6 @@ void tmplput_importantmessage(StrBuf *Target, int nArgs, WCTemplateToken *Tokens
        }
 }
 
-int ConditionalBstr(WCTemplateToken *Tokens, void *Context, int ContextType)
-{
-       if(Tokens->nParameters == 3)
-               return HaveBstr(Tokens->Params[2]->Start, 
-                               Tokens->Params[2]->len);
-       else
-               return strcmp(Bstr(Tokens->Params[2]->Start, 
-                                  Tokens->Params[2]->len),
-                             Tokens->Params[3]->Start) == 0;
-}
-
-void tmplput_bstr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
-{
-       const StrBuf *Buf = SBstr(Tokens->Params[0]->Start, 
-                           Tokens->Params[0]->len);
-       if (Buf != NULL)
-               StrBufAppendTemplate(Target, nArgs, Tokens, 
-                                    Context, ContextType,
-                                    Buf, 1);
-}
-
 void tmplput_trailing_javascript(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
 {
        wcsession *WCC = WC;
@@ -1079,24 +1041,6 @@ void tmplput_csslocal(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *
                        csslocal, 0);
 }
 
-void tmplput_url_part(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
-{
-       StrBuf *UrlBuf;
-       wcsession *WCC = WC;
-       
-       if (WCC != NULL) {
-               if (Tokens->Params[0]->lvalue == 0)
-                       UrlBuf = WCC->UrlFragment1;
-               else if (Tokens->Params[0]->lvalue == 1)
-                       UrlBuf = WCC->UrlFragment2;
-               else
-                       UrlBuf = WCC->UrlFragment3;
-
-               StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType,
-                                    UrlBuf, 1);
-       }
-}
-
 
 
 
@@ -1108,12 +1052,8 @@ InitModule_WEBCIT
        WebcitAddUrlHandler(HKEY("do_template"), url_do_template, ANONYMOUS);
        WebcitAddUrlHandler(HKEY("sslg"), seconds_since_last_gexp, AJAX);
        WebcitAddUrlHandler(HKEY("ajax_servcmd"), ajax_servcmd, 0);
-       WebcitAddUrlHandler(HKEY("diagnostics"), diagnostics, NEED_URL);
 
        RegisterConditional(HKEY("COND:IMPMSG"), 0, ConditionalImportantMesage, CTX_NONE);
-       RegisterConditional(HKEY("COND:BSTR"), 1, ConditionalBstr, CTX_NONE);
-       RegisterNamespace("BSTR", 1, 2, tmplput_bstr, CTX_NONE);
-       RegisterNamespace("URLPART", 1, 2, tmplput_url_part, CTX_NONE);
        RegisterNamespace("CSSLOCAL", 0, 0, tmplput_csslocal, CTX_NONE);
        RegisterNamespace("IMPORTANTMESSAGE", 0, 0, tmplput_importantmessage, CTX_NONE);
        RegisterNamespace("OFFERSTARTPAGE", 0, 0, offer_start_page, CTX_NONE);
index 70f1e37806b078ac4d84c3a7d5fe5d0957a4d386..73dce523e2ba77c7d9e76bf402bd6b00d055ec1f 100644 (file)
@@ -271,6 +271,8 @@ typedef struct _TemplateParam {
        long lvalue;
 } TemplateParam;
 
+/* make a template token a lookup key: */
+#define TKEY(a) Tokens->Params[a]->Start, Tokens->Params[a]->len
 typedef struct _TemplateToken {
        const StrBuf *FileName; /* Reference to print error messages; not to be freed */
        StrBuf *FlatToken;
@@ -765,6 +767,9 @@ int YESBSTR(const char *key);
 #define bstr(a) (char*) Bstr(a, sizeof(a) - 1)
 const char *BSTR(const char *key);
 const char *Bstr(const char *key, size_t keylen);
+/* if you want to ease some parts by just parametring yourself... */
+#define putbstr(a, b) PutBstr(a, sizeof(a) - 1, b)
+void PutBstr(const char *key, long keylen, StrBuf *Value);