From: Wilfried Göesgens Date: Tue, 23 Sep 2008 21:43:29 +0000 (+0000) Subject: * add contexttype, so the subst can precheck the context pointer for us, and bad... X-Git-Tag: v7.86~1912 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=b4ad306de9560ec731db113ed509a1172209c444 * add contexttype, so the subst can precheck the context pointer for us, and bad templates don't make us see funny things in pointers * templatized vnote display --- diff --git a/webcit/auth.c b/webcit/auth.c index 5b92c99bf..2e58a710a 100644 --- a/webcit/auth.c +++ b/webcit/auth.c @@ -882,12 +882,12 @@ void changepw(void) } } -int ConditionalAide(WCTemplateToken *Token, void *Context) +int ConditionalAide(WCTemplateToken *Token, void *Context, int ContextType) { return (WC->is_aide == 0); } -int ConditionalRoomAide(WCTemplateToken *Token, void *Context) +int ConditionalRoomAide(WCTemplateToken *Token, void *Context, int ContextType) { return (WC->is_room_aide == 0); } @@ -915,8 +915,8 @@ InitModule_AUTH WebcitAddUrlHandler(HKEY("changepw"), changepw, 0); WebcitAddUrlHandler(HKEY("termquit"), do_logout, 0); - RegisterConditional(HKEY("COND:AIDE"), 2, ConditionalAide); - RegisterConditional(HKEY("COND:ROOMAIDE"), 2, ConditionalRoomAide); + RegisterConditional(HKEY("COND:AIDE"), 2, ConditionalAide, CTX_NONE); + RegisterConditional(HKEY("COND:ROOMAIDE"), 2, ConditionalRoomAide, CTX_NONE); return ; } diff --git a/webcit/context_loop.c b/webcit/context_loop.c index f6dc44e80..1f0cf05e9 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -621,7 +621,7 @@ void context_loop(int *sock) } -void tmpl_nonce(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) +void tmpl_nonce(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { struct wcsession *WCC = WC; StrBufAppendPrintf(Target, "%ld", @@ -632,5 +632,5 @@ void InitModule_CONTEXT (void) { - RegisterNamespace("NONCE", 0, 0, tmpl_nonce); + RegisterNamespace("NONCE", 0, 0, tmpl_nonce, 0); } diff --git a/webcit/gettext.c b/webcit/gettext.c index 7e5caeb2f..de380d6c8 100644 --- a/webcit/gettext.c +++ b/webcit/gettext.c @@ -204,7 +204,7 @@ void httplang_to_locale(StrBuf *LocaleString) * depending on the browser locale change the sequence of the * language chooser. */ -void offer_languages(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context) { +void offer_languages(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) { int i; #ifndef HAVE_USELOCALE char *Lang = getenv("LANG"); diff --git a/webcit/iconbar.c b/webcit/iconbar.c index feb5b8421..99350602b 100644 --- a/webcit/iconbar.c +++ b/webcit/iconbar.c @@ -803,7 +803,7 @@ void commit_iconbar(void) { } -void tmplput_iconbar(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) +void tmplput_iconbar(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { struct wcsession *WCC = WC; @@ -824,7 +824,7 @@ InitModule_ICONBAR WebcitAddUrlHandler(HKEY("iconbar_ajax_rooms"), do_iconbar_roomlist, AJAX); WebcitAddUrlHandler(HKEY("display_customize_iconbar"), display_customize_iconbar, 0); WebcitAddUrlHandler(HKEY("commit_iconbar"), commit_iconbar, 0); - RegisterNamespace("ICONBAR", 0, 0, tmplput_iconbar); + RegisterNamespace("ICONBAR", 0, 0, tmplput_iconbar, 0); } diff --git a/webcit/inetconf.c b/webcit/inetconf.c index 1f234a4f8..cc04419c7 100644 --- a/webcit/inetconf.c +++ b/webcit/inetconf.c @@ -380,7 +380,7 @@ void InetCfgSubst(StrBuf *TemplBuffer, void *vContext, WCTemplateToken *Token) SVPutBuf("SERVCFG:INET:HOSTNAME", vContext, 1); } -void DeleteInectConfHash(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context) +void DeleteInectConfHash(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) { struct wcsession *WCC = WC; if (WCC->InetCfg == NULL) @@ -411,6 +411,6 @@ InitModule_INETCONF { WebcitAddUrlHandler(HKEY("display_inetconf"), display_inetconf, 0); WebcitAddUrlHandler(HKEY("save_inetconf"), new_save_inetconf, AJAX); - RegisterIterator("SERVCFG:INET", 1, NULL, GetInetConfHash, InetCfgSubst, NULL); - RegisterNamespace("SERVCFG:FLUSHINETCFG",0, 0, DeleteInectConfHash); + RegisterIterator("SERVCFG:INET", 1, NULL, GetInetConfHash, InetCfgSubst, NULL, CTX_INETCFG); + RegisterNamespace("SERVCFG:FLUSHINETCFG",0, 0, DeleteInectConfHash, CTX_INETCFG); } diff --git a/webcit/mainmenu.c b/webcit/mainmenu.c index 5693329b0..d9337fda4 100644 --- a/webcit/mainmenu.c +++ b/webcit/mainmenu.c @@ -11,7 +11,7 @@ void display_main_menu(void) { begin_burst(); output_headers(1, 0, 0, 0, 1, 0); - DoTemplate(HKEY("display_main_menu"), NULL, NULL); + DoTemplate(HKEY("display_main_menu"), NULL, NULL, 0); end_burst(); /* @@ -161,7 +161,7 @@ void display_aide_menu(void) { begin_burst(); output_headers(1, 0, 0, 0, 1, 0); - DoTemplate(HKEY("display_aide_menu"), NULL, NULL); + DoTemplate(HKEY("display_aide_menu"), NULL, NULL, 0); end_burst(); /* output_headers(1, 1, 2, 0, 0, 0); @@ -369,7 +369,7 @@ void display_shutdown(void) } begin_burst(); output_headers(1, 0, 0, 0, 1, 0); - DoTemplate(HKEY("display_serverrestart"), NULL, NULL); + DoTemplate(HKEY("display_serverrestart"), NULL, NULL, 0); end_burst(); lingering_close(WC->http_sock); sleeeeeeeeeep(10); @@ -384,7 +384,7 @@ void display_shutdown(void) { begin_burst(); output_headers(1, 0, 0, 0, 1, 0); - DoTemplate(HKEY("display_serverrestartpage"), NULL, NULL); + DoTemplate(HKEY("display_serverrestartpage"), NULL, NULL, 0); end_burst(); } else @@ -393,7 +393,7 @@ void display_shutdown(void) serv_getln(buf, sizeof buf); // should we care? begin_burst(); output_headers(1, 0, 0, 0, 1, 0); - DoTemplate(HKEY("display_serverrestartpagedo"), NULL, NULL); + DoTemplate(HKEY("display_serverrestartpagedo"), NULL, NULL, 0); end_burst(); } } @@ -409,7 +409,7 @@ void display_shutdown(void) } begin_burst(); output_headers(1, 0, 0, 0, 1, 0); - DoTemplate(HKEY("display_aide_menu"), NULL, NULL); + DoTemplate(HKEY("display_aide_menu"), NULL, NULL, 0); end_burst(); } } diff --git a/webcit/netconf.c b/webcit/netconf.c index e152800f5..521c765a7 100644 --- a/webcit/netconf.c +++ b/webcit/netconf.c @@ -540,6 +540,6 @@ InitModule_NETCONF WebcitAddUrlHandler(HKEY("display_confirm_delete_node"), display_confirm_delete_node, 0); WebcitAddUrlHandler(HKEY("delete_node"), delete_node, 0); WebcitAddUrlHandler(HKEY("display_add_node"), display_add_node, 0); - RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NodeCfgSubst, DeleteHash); + RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NodeCfgSubst, DeleteHash, CTX_NODECONF); } /*@}*/ diff --git a/webcit/notes.c b/webcit/notes.c index 0775d9709..58e9bc850 100644 --- a/webcit/notes.c +++ b/webcit/notes.c @@ -345,7 +345,10 @@ void display_note(long msgnum, int unread) { v = vnote_new_from_msg(msgnum); if (v) { - display_vnote_div(v); +// display_vnote_div(v); + DoTemplate(HKEY("vnoteitem"), + v, WC->WBuf, CTX_VNOTE); + /* uncomment these lines to see ugly debugging info wprintf(" +
+ +
+ + + + + + + + + + + + + + +
+
+ +
+
+ + + diff --git a/webcit/subst.c b/webcit/subst.c index adee900ba..2d9b27086 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -51,12 +51,18 @@ typedef struct _WCTemplate { typedef struct _HashHandler { int nMinArgs; int nMaxArgs; + int ContextRequired; WCHandlerFunc HandlerFunc; }HashHandler; void *load_template(StrBuf *filename, StrBuf *Key, HashList *PutThere); -void RegisterNS(const char *NSName, long len, int nMinArgs, int nMaxArgs, WCHandlerFunc HandlerFunc) +void RegisterNS(const char *NSName, + long len, + int nMinArgs, + int nMaxArgs, + WCHandlerFunc HandlerFunc, + int ContextRequired) { HashHandler *NewHandler; @@ -64,6 +70,7 @@ void RegisterNS(const char *NSName, long len, int nMinArgs, int nMaxArgs, WCHand NewHandler->nMinArgs = nMinArgs; NewHandler->nMaxArgs = nMaxArgs; NewHandler->HandlerFunc = HandlerFunc; + NewHandler->ContextRequired = ContextRequired; Put(GlobalNS, NSName, len, NewHandler, NULL); } @@ -460,7 +467,7 @@ void pvo_do_cmd(StrBuf *Target, StrBuf *servcmd) { * \brief Print the value of a variable * \param keyname get a key to print */ -void print_value_of(StrBuf *Target, WCTemplateToken *Token, void *Context) { +void print_value_of(StrBuf *Target, WCTemplateToken *Token, void *Context, int ContextType) { struct wcsession *WCC = WC; wcsubst *ptr; void *vVar; @@ -468,7 +475,7 @@ void print_value_of(StrBuf *Target, WCTemplateToken *Token, void *Context) { /*if (WCC->vars != NULL) PrintHash(WCC->vars, VarPrintTransition, VarPrintEntry);*/ /// TODO: debricated! if (Token->pName[0] == '=') { - DoTemplate(Token->pName+1, Token->NameEnd - 1, NULL, NULL); + DoTemplate(Token->pName+1, Token->NameEnd - 1, NULL, NULL, 0); } //////TODO: if param[1] == "U" -> urlescape @@ -484,7 +491,7 @@ void print_value_of(StrBuf *Target, WCTemplateToken *Token, void *Context) { pvo_do_cmd(Target, ptr->wcs_value); break; case WCS_FUNCTION: - (*ptr->wcs_function) (Target, Token->nParameters, Token, Context); + (*ptr->wcs_function) (Target, Token->nParameters, Token, Context, ContextType); break; case WCS_STRBUF: case WCS_STRBUF_REF: @@ -782,7 +789,7 @@ WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf, -int EvaluateConditional(StrBuf *Target, WCTemplateToken *Token, WCTemplate *pTmpl, void *Context, int Neg, int state) +int EvaluateConditional(StrBuf *Target, WCTemplateToken *Token, WCTemplate *pTmpl, void *Context, int Neg, int state, int ContextType) { void *vConditional = NULL; ConditionalStruct *Cond; @@ -829,30 +836,31 @@ int EvaluateConditional(StrBuf *Target, WCTemplateToken *Token, WCTemplate *pTmp ChrPtr(Token->FlatToken)); return 0; } - if (Cond->CondF(Token, Context) == Neg) + if (Cond->CondF(Token, Context, ContextType) == Neg) return Token->Params[1]->lvalue; return 0; } -int EvaluateToken(StrBuf *Target, WCTemplateToken *Token, WCTemplate *pTmpl, void *Context, int state) +int EvaluateToken(StrBuf *Target, WCTemplateToken *Token, WCTemplate *pTmpl, void *Context, int state, int ContextType) { HashHandler *Handler; void *vVar; // much output, since pName is not terminated... // lprintf(1,"Doing token: %s\n",Token->pName); + switch (Token->Flags) { case SV_GETTEXT: TmplGettext(Target, Token->nParameters, Token); break; case SV_CONDITIONAL: /** Forward conditional evaluation */ - return EvaluateConditional(Target, Token, pTmpl, Context, 1, state); + return EvaluateConditional(Target, Token, pTmpl, Context, 1, state, ContextType); break; case SV_NEG_CONDITIONAL: /** Reverse conditional evaluation */ - return EvaluateConditional(Target, Token, pTmpl, Context, 0, state); + return EvaluateConditional(Target, Token, pTmpl, Context, 0, state, ContextType); break; case SV_CUST_STR_CONDITIONAL: /** Conditional put custom strings from params */ if (Token->nParameters >= 6) { - if (EvaluateConditional(Target, Token, pTmpl, Context, 0, state)) + if (EvaluateConditional(Target, Token, pTmpl, Context, 0, state, ContextType)) StrBufAppendBufPlain(Target, Token->Params[5]->Start, Token->Params[5]->len, @@ -866,20 +874,66 @@ int EvaluateToken(StrBuf *Target, WCTemplateToken *Token, WCTemplate *pTmpl, voi break; case SV_SUBTEMPL: if (Token->nParameters == 1) - DoTemplate(Token->Params[0]->Start, Token->Params[0]->len, NULL, NULL); + DoTemplate(Token->Params[0]->Start, Token->Params[0]->len, NULL, NULL, ContextType); break; case SV_PREEVALUATED: Handler = (HashHandler*) Token->PreEval; + if ((Handler->ContextRequired != CTX_NONE) && + (Handler->ContextRequired != ContextType)) { + lprintf(1, "Handler [%s] (in '%s' line %ld); " + "requires context of type %ld, have %ld [%s]\n", + Token->pName, + ChrPtr(pTmpl->FileName), + Token->Line, + Handler->ContextRequired, + ContextType, + ChrPtr(Token->FlatToken)); + StrBufAppendPrintf( + Target, + "
\nHandler [%s] (in '%s' line %ld);"
+				" requires context of type %ld, have %ld!\n[%s]\n
\n", + Token->pName, + ChrPtr(pTmpl->FileName), + Token->Line, + Handler->ContextRequired, + ContextType, + ChrPtr(Token->FlatToken)); + return -1; + + } Handler->HandlerFunc(Target, Token->nParameters, Token, - Context); + Context, + ContextType); break; default: if (GetHash(GlobalNS, Token->pName, Token->NameEnd, &vVar)) { Handler = (HashHandler*) vVar; - if ((Token->nParameters < Handler->nMinArgs) || - (Token->nParameters > Handler->nMaxArgs)) { + if ((Handler->ContextRequired != CTX_NONE) && + (Handler->ContextRequired != ContextType)) { + lprintf(1, "Handler [%s] (in '%s' line %ld); " + "requires context of type %ld, have %ld [%s]\n", + Token->pName, + ChrPtr(pTmpl->FileName), + Token->Line, + Handler->ContextRequired, + ContextType, + ChrPtr(Token->FlatToken)); + StrBufAppendPrintf( + Target, + "
\nHandler [%s] (in '%s' line %ld);"
+					" requires context of type %ld, have %ld!\n[%s]\n
\n", + Token->pName, + ChrPtr(pTmpl->FileName), + Token->Line, + Handler->ContextRequired, + ContextType, + ChrPtr(Token->FlatToken)); + return -1; + } + else if ((Token->nParameters < Handler->nMinArgs) || + (Token->nParameters > Handler->nMaxArgs)) { lprintf(1, "Handler [%s] (in '%s' line %ld); " "doesn't work with %ld params [%s]\n", Token->pName, @@ -901,18 +955,19 @@ int EvaluateToken(StrBuf *Target, WCTemplateToken *Token, WCTemplate *pTmpl, voi Handler->HandlerFunc(Target, Token->nParameters, Token, - Context); /*TODO: subset of that */ + Context, + ContextType); /*TODO: subset of that */ } } else { - print_value_of(Target, Token, Context); + print_value_of(Target, Token, Context, ContextType); } } return 0; } -void ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, void *Context) +void ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, void *Context, int ContextType) { WCTemplate *pTmpl = Tmpl; int done = 0; @@ -931,8 +986,6 @@ void ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, void *Context) "
\nError loading Template [%s]\n See Logfile for details\n
\n", ChrPtr(Tmpl->FileName)); return; - - } } @@ -952,7 +1005,7 @@ void ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, void *Context) StrBufAppendBufPlain( Target, pData, pTmpl->Tokens[i]->pTokenStart - pData, 0); - state = EvaluateToken(Target, pTmpl->Tokens[i], pTmpl, Context, state); + state = EvaluateToken(Target, pTmpl->Tokens[i], pTmpl, Context, state, ContextType); while ((state != 0) && (i+1 < pTmpl->nTokensUsed)) { /* condition told us to skip till its end condition */ i++; @@ -964,7 +1017,8 @@ void ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, void *Context) pTmpl, Context, pTmpl->Tokens[i]->Flags, - state)) + state, + ContextType)) state = 0; } } @@ -1096,7 +1150,7 @@ const char* PrintTemplate(void *vSubst) * \brief Display a variable-substituted template * \param templatename template file to load */ -void DoTemplate(const char *templatename, long len, void *Context, StrBuf *Target) +void DoTemplate(const char *templatename, long len, void *Context, StrBuf *Target, int ContextType) { HashList *Static; HashList *StaticLocal; @@ -1132,7 +1186,7 @@ void DoTemplate(const char *templatename, long len, void *Context, StrBuf *Targe } if (vTmpl == NULL) return; - ProcessTemplate(vTmpl, Target, Context); + ProcessTemplate(vTmpl, Target, Context, ContextType); } int LoadTemplateDir(const char *DirName, HashList *wireless, HashList *big) @@ -1205,49 +1259,49 @@ void InitTemplateCache(void) LocalTemplateCache); } -void tmplput_serv_ip(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) +void tmplput_serv_ip(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { StrBufAppendPrintf(Target, "%d", WC->ctdl_pid); } -void tmplput_serv_nodename(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) +void tmplput_serv_nodename(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { StrEscAppend(Target, NULL, serv_info.serv_nodename, 0, 0); } -void tmplput_serv_humannode(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) +void tmplput_serv_humannode(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { StrEscAppend(Target, NULL, serv_info.serv_humannode, 0, 0); } -void tmplput_serv_fqdn(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) +void tmplput_serv_fqdn(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { StrEscAppend(Target, NULL, serv_info.serv_fqdn, 0, 0); } -void tmmplput_serv_software(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) +void tmmplput_serv_software(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { StrEscAppend(Target, NULL, serv_info.serv_software, 0, 0); } -void tmplput_serv_rev_level(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) +void tmplput_serv_rev_level(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { StrBufAppendPrintf(Target, "%d.%02d", serv_info.serv_rev_level / 100, serv_info.serv_rev_level % 100); } -void tmmplput_serv_bbs_city(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) +void tmmplput_serv_bbs_city(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { StrEscAppend(Target, NULL, serv_info.serv_bbs_city, 0, 0); } -void tmplput_current_user(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) +void tmplput_current_user(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { StrEscAppend(Target, NULL, WC->wc_fullname, 0, 0); } -void tmplput_current_room(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) +void tmplput_current_room(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { StrEscAppend(Target, NULL, WC->wc_roomname, 0, 0); } @@ -1256,12 +1310,13 @@ void tmplput_current_room(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo typedef struct _HashIterator { HashList *StaticList; int AdditionalParams; + int ContextType; RetrieveHashlistFunc GetHash; HashDestructorFunc Destructor; SubTemplFunc DoSubTemplate; } HashIterator; -void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) +void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { void *vIt; HashIterator *It; @@ -1320,12 +1375,15 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo SubBuf = NewStrBuf(); it = GetNewHashPos(); while (GetNextHashPos(List, it, &len, &Key, &vContext)) { - svprintf(HKEY("ITERATE:ODDEVEN"), WCS_STRING, "%s", (oddeven)?"odd":"even"); - svprintf(HKEY("ITERATE:KEY"), WCS_STRING, "%s",Key); + svprintf(HKEY("ITERATE:ODDEVEN"), WCS_STRING, "%s", + (oddeven) ? "odd" : "even"); + svprintf(HKEY("ITERATE:KEY"), WCS_STRING, "%s", Key); + It->DoSubTemplate(SubBuf, vContext, Tokens); DoTemplate(Tokens->Params[1]->Start, Tokens->Params[1]->len, - vContext, SubBuf); + vContext, SubBuf, + It->ContextType); StrBufAppendBuf(Target, SubBuf, 0); FlushStrBuf(SubBuf); @@ -1337,7 +1395,7 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo It->Destructor(&List); } -int ConditionalVar(WCTemplateToken *Tokens, void *Context) +int ConditionalVar(WCTemplateToken *Tokens, void *Context, int ContextType) { void *vsubst; wcsubst *subst; @@ -1348,6 +1406,12 @@ int ConditionalVar(WCTemplateToken *Tokens, void *Context) &vsubst)) return 0; subst = (wcsubst*) vsubst; + if ((subst->ContextRequired != CTX_NONE) && + (subst->ContextRequired != ContextType)) { + lprintf(1," WARNING: Conditional requires Context: [%ld]!\n", Tokens->Params[2]->Start); + return -1; + } + switch(subst->wcs_type) { case WCS_FUNCTION: return (subst->wcs_function!=NULL); @@ -1366,6 +1430,7 @@ int ConditionalVar(WCTemplateToken *Tokens, void *Context) return (subst->lvalue == Tokens->Params[3]->lvalue); default: lprintf(1," WARNING: invalid type: [%ld]!\n", subst->wcs_type); + return -1; } return 0; } @@ -1375,7 +1440,8 @@ void RegisterITERATOR(const char *Name, long len, HashList *StaticList, RetrieveHashlistFunc GetHash, SubTemplFunc DoSubTempl, - HashDestructorFunc Destructor) + HashDestructorFunc Destructor, + int ContextType) { HashIterator *It = (HashIterator*)malloc(sizeof(HashIterator)); It->StaticList = StaticList; @@ -1383,39 +1449,44 @@ void RegisterITERATOR(const char *Name, long len, It->GetHash = GetHash; It->DoSubTemplate = DoSubTempl; It->Destructor = Destructor; + It->ContextType = ContextType; Put(Iterators, Name, len, It, NULL); } void RegisterConditional(const char *Name, long len, int nParams, - WCConditionalFunc CondF) + WCConditionalFunc CondF, + int ContextRequired) { ConditionalStruct *Cond = (ConditionalStruct*)malloc(sizeof(ConditionalStruct)); Cond->nParams = nParams; Cond->CondF = CondF; + Cond->ContextRequired = ContextRequired; Put(Contitionals, Name, len, Cond, NULL); } -void tmpl_do_boxed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) +void tmpl_do_boxed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { if (nArgs == 2) { StrBuf *Headline = NewStrBuf(); DoTemplate(Tokens->Params[1]->Start, Tokens->Params[1]->len, Context, - Headline); + Headline, + ContextType); SVPutBuf("BOXTITLE", Headline, 0); } - - DoTemplate(HKEY("beginbox"), Context, Target); + + DoTemplate(HKEY("beginbox"), Context, Target, ContextType); DoTemplate(Tokens->Params[0]->Start, Tokens->Params[0]->len, Context, - Target); - DoTemplate(HKEY("endbox"), Context, Target); + Target, + ContextType); + DoTemplate(HKEY("endbox"), Context, Target, ContextType); } -void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) +void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { StrBuf **TabNames; int i, ntabs, nTabs; @@ -1429,7 +1500,8 @@ void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Co DoTemplate(Tokens->Params[i * 2]->Start, Tokens->Params[i * 2]->len, Context, - TabNames[i]); + TabNames[i], + ContextType); } else { /** A Tab without subject? we can't count that, add it as silent */ @@ -1444,7 +1516,8 @@ void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Co DoTemplate(Tokens->Params[i * 2 + 1]->Start, Tokens->Params[i * 2 + 1]->len, Context, - Target); + Target, + ContextType); StrEndTab(Target, i, nTabs); } } @@ -1453,20 +1526,20 @@ void InitModule_SUBST (void) { - RegisterNamespace("SERV:PID", 0, 0, tmplput_serv_ip); - RegisterNamespace("SERV:NODENAME", 0, 0, tmplput_serv_nodename); - RegisterNamespace("SERV:HUMANNODE", 0, 0, tmplput_serv_humannode); - RegisterNamespace("SERV:FQDN", 0, 0, tmplput_serv_fqdn); - RegisterNamespace("SERV:SOFTWARE", 0, 0, tmmplput_serv_software); - RegisterNamespace("SERV:REV_LEVEL", 0, 0, tmplput_serv_rev_level); - RegisterNamespace("SERV:BBS_CITY", 0, 0, tmmplput_serv_bbs_city); -/// RegisterNamespace("SERV:LDAP_SUPP", 0, 0, tmmplput_serv_ldap_enabled); - RegisterNamespace("CURRENT_USER", 0, 0, tmplput_current_user); - RegisterNamespace("CURRENT_ROOM", 0, 0, tmplput_current_room); - RegisterNamespace("ITERATE", 2, 100, tmpl_iterate_subtmpl); - RegisterNamespace("DOBOXED", 1, 2, tmpl_do_boxed); - RegisterNamespace("DOTABBED", 2, 100, tmpl_do_tabbed); - RegisterConditional(HKEY("COND:SUBST"), 3, ConditionalVar); + RegisterNamespace("SERV:PID", 0, 0, tmplput_serv_ip, CTX_NONE); + RegisterNamespace("SERV:NODENAME", 0, 0, tmplput_serv_nodename, CTX_NONE); + RegisterNamespace("SERV:HUMANNODE", 0, 0, tmplput_serv_humannode, CTX_NONE); + RegisterNamespace("SERV:FQDN", 0, 0, tmplput_serv_fqdn, CTX_NONE); + RegisterNamespace("SERV:SOFTWARE", 0, 0, tmmplput_serv_software, CTX_NONE); + RegisterNamespace("SERV:REV_LEVEL", 0, 0, tmplput_serv_rev_level, CTX_NONE); + RegisterNamespace("SERV:BBS_CITY", 0, 0, tmmplput_serv_bbs_city, CTX_NONE); +/// RegisterNamespace("SERV:LDAP_SUPP", 0, 0, tmmplput_serv_ldap_enabled, 0); + RegisterNamespace("CURRENT_USER", 0, 0, tmplput_current_user, CTX_NONE); + RegisterNamespace("CURRENT_ROOM", 0, 0, tmplput_current_room, CTX_NONE); + RegisterNamespace("ITERATE", 2, 100, tmpl_iterate_subtmpl, CTX_NONE); + RegisterNamespace("DOBOXED", 1, 2, tmpl_do_boxed, CTX_NONE); + RegisterNamespace("DOTABBED", 2, 100, tmpl_do_tabbed, CTX_NONE); + RegisterConditional(HKEY("COND:SUBST"), 3, ConditionalVar, CTX_NONE); } /*@}*/ diff --git a/webcit/summary.c b/webcit/summary.c index 00a52096d..2752cbd3a 100644 --- a/webcit/summary.c +++ b/webcit/summary.c @@ -259,7 +259,7 @@ void summary(void) { wprintf(""); wprintf(""); wprintf(""); diff --git a/webcit/webcit.c b/webcit/webcit.c index b52c1a13d..ed2eefc54 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -1059,7 +1059,7 @@ void url_do_template(void) { const StrBuf *Tmpl = sbstr("template"); begin_burst(); output_headers(1, 0, 0, 0, 1, 0); - DoTemplate(ChrPtr(Tmpl), StrLength(Tmpl), NULL, NULL); + DoTemplate(ChrPtr(Tmpl), StrLength(Tmpl), NULL, NULL, 0); end_burst(); } @@ -1068,7 +1068,7 @@ void url_do_template(void) { /* * Offer to make any page the user's "start page." */ -void offer_start_page(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context) { +void offer_start_page(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) { wprintf("this_page); wprintf("\">"); @@ -1816,7 +1816,7 @@ void download_mimepart(void) { } -int ConditionalImportantMesage(WCTemplateToken *Tokens, void *Context) +int ConditionalImportantMesage(WCTemplateToken *Tokens, void *Context, int ContextType) { struct wcsession *WCC = WC; if (WCC != NULL) @@ -1825,7 +1825,7 @@ int ConditionalImportantMesage(WCTemplateToken *Tokens, void *Context) return 0; } -void tmplput_importantmessage(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) +void tmplput_importantmessage(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { struct wcsession *WCC = WC; @@ -1835,7 +1835,7 @@ void tmplput_importantmessage(StrBuf *Target, int nArgs, WCTemplateToken *Tokens } } -int ConditionalBstr(WCTemplateToken *Tokens, void *Context) +int ConditionalBstr(WCTemplateToken *Tokens, void *Context, int ContextType) { if(Tokens->nParameters == 1) return HaveBstr(Tokens->Params[0]->Start, @@ -1846,7 +1846,7 @@ int ConditionalBstr(WCTemplateToken *Tokens, void *Context) Tokens->Params[1]->Start) == 0; } -void tmplput_bstr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) +void tmplput_bstr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { StrBufAppendBuf(Target, SBstr(Tokens->Params[0]->Start, @@ -1867,9 +1867,10 @@ InitModule_WEBCIT WebcitAddUrlHandler(HKEY("mimepart"), view_mimepart, NEED_URL); WebcitAddUrlHandler(HKEY("mimepart_download"), download_mimepart, NEED_URL); WebcitAddUrlHandler(HKEY("diagnostics"), diagnostics, NEED_URL); - RegisterConditional(HKEY("COND:IMPMSG"), 0, ConditionalImportantMesage); - RegisterConditional(HKEY("COND:BSTR"), 1, ConditionalBstr); - RegisterNamespace("BSTR", 1, 2, tmplput_bstr); - RegisterNamespace("IMPORTANTMESSAGE", 0, 0, tmplput_importantmessage); - RegisterNamespace("OFFERSTARTPAGE", 0, 0, offer_start_page); + + 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("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 ebf48cdcd..ebb565fc8 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -282,7 +282,7 @@ typedef struct _TemplateToken { TemplateParam *Params[MAXPARAM]; } WCTemplateToken; -typedef void (*WCHandlerFunc)(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context); +typedef void (*WCHandlerFunc)(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType); /** @@ -293,24 +293,37 @@ typedef struct _wcsubst { char wcs_key[32]; /**< copy of our hashkey for debugging */ StrBuf *wcs_value; /**< if we're a string, keep it here */ long lvalue; /**< type long? keep data here */ + int ContextRequired; /**< do we require a context type? */ WCHandlerFunc wcs_function; /**< funcion hook ???*/ } wcsubst; +#define CTX_NONE 0 +#define CTX_SITECFG 1 +#define CTX_SESSION 2 +#define CTX_INETCFG 3 +#define CTX_VNOTE 4 +#define CTX_WHO 5 +#define CTX_PREF 6 +#define CTX_NODECONF 7 + void RegisterNS(const char *NSName, long len, int nMinArgs, int nMaxArgs, - WCHandlerFunc HandlerFunc); -#define RegisterNamespace(a, b, c, d) RegisterNS(a, sizeof(a)-1, b, c, d) + WCHandlerFunc HandlerFunc, + int ContextRequired); +#define RegisterNamespace(a, b, c, d, e) RegisterNS(a, sizeof(a)-1, b, c, d, e) -typedef int (*WCConditionalFunc)(WCTemplateToken *Token, void *Context); +typedef int (*WCConditionalFunc)(WCTemplateToken *Token, void *Context, int ContextType); typedef struct _ConditionalStruct { int nParams; + int ContextRequired; WCConditionalFunc CondF; } ConditionalStruct; void RegisterConditional(const char *Name, long len, int nParams, - WCConditionalFunc CondF); + WCConditionalFunc CondF, + int ContextRequired); @@ -322,8 +335,9 @@ void RegisterITERATOR(const char *Name, long len, HashList *StaticList, RetrieveHashlistFunc GetHash, SubTemplFunc DoSubTempl, - HashDestructorFunc Destructor); -#define RegisterIterator(a, b, c, d, e, f) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f) + HashDestructorFunc Destructor, + int ContextType); +#define RegisterIterator(a, b, c, d, e, f, g) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g) void SVPut(char *keyname, size_t keylen, int keytype, char *Data); #define svput(a, b, c) SVPut(a, sizeof(a) - 1, b, c) @@ -338,8 +352,8 @@ void SVCallback(char *keyname, size_t keylen, WCHandlerFunc fcn_ptr); void SVPUTBuf(const char *keyname, int keylen, const StrBuf *Buf, int ref); #define SVPutBuf(a, b, c); SVPUTBuf(a, sizeof(a) - 1, b, c) -void DoTemplate(const char *templatename, long len, void *Context, StrBuf *Target); -#define do_template(a, b) DoTemplate(a, sizeof(a) -1, b, NULL); +void DoTemplate(const char *templatename, long len, void *Context, StrBuf *Target, int ContextType); +#define do_template(a, b) DoTemplate(a, sizeof(a) -1, b, NULL, 0); void url_do_template(void); int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup); @@ -726,7 +740,7 @@ void set_ROOM_PREFS(const char *key, size_t keylen, StrBuf *value, int save_to_s int is_msg_in_mset(char *mset, long msgnum); void display_addressbook(long msgnum, char alpha); -void offer_start_page(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context); +void offer_start_page(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType); void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext); void output_html(char *, int); void do_listsub(void); @@ -795,7 +809,7 @@ void do_selected_iconbar(void); int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen); void spawn_another_worker_thread(void); void display_rss(char *roomname, StrBuf *request_method); -void offer_languages(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context); +void offer_languages(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType); void set_selected_language(const char *); void go_selected_language(void); void stop_selected_language(void); diff --git a/webcit/who.c b/webcit/who.c index 0cc06bc8a..02f3630e9 100644 --- a/webcit/who.c +++ b/webcit/who.c @@ -496,5 +496,5 @@ InitModule_WHO WebcitAddUrlHandler(HKEY("terminate_session"), _terminate_session, 0); WebcitAddUrlHandler(HKEY("edit_me"), edit_me, 0); - RegisterIterator("WHOLIST", 0, NULL, GetWholistHash, WholistSubst, DeleteWholistHash); + RegisterIterator("WHOLIST", 0, NULL, GetWholistHash, WholistSubst, DeleteWholistHash, CTX_WHO); }