From 5ce2f5c9a18d4b8a9fd7fcc82fea11dc0f2b3d32 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Wilfried=20G=C3=B6esgens?=
Date: Sat, 20 Dec 2008 23:53:31 +0000
Subject: [PATCH] * shortcut notation to tokens for hashkeys; TKEY(n) will make
str,len for Hash access * some fixups to the message dropdown selectors
---
webcit/inetconf.c | 5 +-
webcit/messages.c | 171 +++++++++----------
webcit/msg_renderers.c | 2 +-
webcit/paramhandling.c | 89 ++++++++++
webcit/preferences.c | 15 +-
webcit/siteconfig.c | 15 +-
webcit/static/t/msg_listselector_top.html | 6 +-
webcit/static/t/select_messageindex_all.html | 2 +-
webcit/subst.c | 55 ++----
webcit/webcit.c | 60 -------
webcit/webcit.h | 5 +
11 files changed, 199 insertions(+), 226 deletions(-)
diff --git a/webcit/inetconf.c b/webcit/inetconf.c
index 56981ddaa..f50a045bd 100644
--- a/webcit/inetconf.c
+++ b/webcit/inetconf.c
@@ -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;
}
diff --git a/webcit/messages.c b/webcit/messages.c
index 91fe9b82e..c159a055a 100644
--- a/webcit/messages.c
+++ b/webcit/messages.c
@@ -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("\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("");
- }
-
-
- /**
+ /**
* 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) *
- (maxmsgsmsgnum;
}
- 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; aWBuf, 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("
");
}
/**
@@ -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 tag. */
wprintf("\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)
diff --git a/webcit/msg_renderers.c b/webcit/msg_renderers.c
index 97e0b66f9..d9955e8e5 100644
--- a/webcit/msg_renderers.c
+++ b/webcit/msg_renderers.c
@@ -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);
diff --git a/webcit/paramhandling.c b/webcit/paramhandling.c
index 7e85cfbe4..afa264f10 100644
--- a/webcit/paramhandling.c
+++ b/webcit/paramhandling.c
@@ -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
\n", WC->wc_session);
+ wprintf("Command:
\n");
+ StrEscPuts(WC->UrlFragment1);
+ wprintf("
\n");
+ StrEscPuts(WC->UrlFragment2);
+ wprintf("
\n");
+ StrEscPuts(WC->UrlFragment3);
+ wprintf("
\n");
+ wprintf("Variables:
\n");
+ dump_vars();
+ wprintf("
\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);
+}
diff --git a/webcit/preferences.c b/webcit/preferences.c
index 92b9d9191..0ed7b68d7 100644
--- a/webcit/preferences.c
+++ b/webcit/preferences.c
@@ -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
diff --git a/webcit/siteconfig.c b/webcit/siteconfig.c
index 58c7e1ca6..7d1a0b732 100644
--- a/webcit/siteconfig.c
+++ b/webcit/siteconfig.c
@@ -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;
diff --git a/webcit/static/t/msg_listselector_top.html b/webcit/static/t/msg_listselector_top.html
index d6cb59891..0c81f9cc1 100644
--- a/webcit/static/t/msg_listselector_top.html
+++ b/webcit/static/t/msg_listselector_top.html
@@ -6,7 +6,7 @@
>
@@ -14,8 +14,8 @@
+ OnChange="location.href='?SortBy=date&SortOrder=2'"
+ %("COND:BSTR", 1, "SortOrder", 2, "checked", "")>
>
diff --git a/webcit/static/t/select_messageindex_all.html b/webcit/static/t/select_messageindex_all.html
index a57429be7..e32694878 100644
--- a/webcit/static/t/select_messageindex_all.html
+++ b/webcit/static/t/select_messageindex_all.html
@@ -1 +1 @@
-
+
diff --git a/webcit/subst.c b/webcit/subst.c
index 1de23b6ae..a4c123594 100644
--- a/webcit/subst.c
+++ b/webcit/subst.c
@@ -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;
diff --git a/webcit/webcit.c b/webcit/webcit.c
index 909a40387..9303f65e6 100644
--- a/webcit/webcit.c
+++ b/webcit/webcit.c
@@ -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
\n", WC->wc_session);
- wprintf("Command:
\n");
- StrEscPuts(WC->UrlFragment1);
- wprintf("
\n");
- StrEscPuts(WC->UrlFragment2);
- wprintf("
\n");
- StrEscPuts(WC->UrlFragment3);
- wprintf("
\n");
- wprintf("Variables:
\n");
- dump_vars();
- wprintf("
\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);
diff --git a/webcit/webcit.h b/webcit/webcit.h
index 70f1e3780..73dce523e 100644
--- a/webcit/webcit.h
+++ b/webcit/webcit.h
@@ -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);
--
2.30.2