From 3841dfefb6b086720b6d5d9af39aaf8b19730e6d Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Tue, 17 Jul 2012 20:37:51 +0200 Subject: [PATCH] Rework templating context access so contexts can be accessed through several layers - remove now unneeded control context - the CTX macro now gets the type of pointer we want to cast later - add stack / unstack function that manage the linked list of contexts --- webcit/dav_main.c | 7 +- webcit/downloads.c | 10 +- webcit/mainmenu.c | 11 +- webcit/messages.c | 22 +-- webcit/msg_renderers.c | 97 ++++++------- webcit/netconf.c | 26 ++-- webcit/notes.c | 20 +-- webcit/pushemail.c | 5 +- webcit/roomlist.c | 2 +- webcit/roomtokens.c | 40 +++--- webcit/roomviews.c | 8 +- webcit/sieve.c | 34 ++--- webcit/siteconfig.c | 6 +- webcit/smtpqueue.c | 26 ++-- webcit/subst.c | 317 ++++++++++++++++++++++------------------- webcit/subst.h | 17 ++- webcit/useredit.c | 32 ++--- webcit/vcard_edit.c | 2 +- webcit/who.c | 28 ++-- 19 files changed, 368 insertions(+), 342 deletions(-) diff --git a/webcit/dav_main.c b/webcit/dav_main.c index 9d20819dc..157c95397 100644 --- a/webcit/dav_main.c +++ b/webcit/dav_main.c @@ -271,7 +271,7 @@ int Conditional_DAV_NSCURRENT(StrBuf *Target, WCTemplputParams *TP) wcsession *WCC = WC; void *vHandler; - vHandler = CTX; + vHandler = CTX(CTX_NONE); return WCC->Hdr->HR.Handler == vHandler; } @@ -282,8 +282,9 @@ void tmplput_DAV_NAMESPACE(StrBuf *Target, WCTemplputParams *TP) if (TP->Filter.ContextType == CTX_DAVNS) { WebcitHandler *H; - H = (WebcitHandler*) CTX; - StrBufAppendTemplate(Target, TP, H->Name, 0); + H = (WebcitHandler*) CTX(CTX_DAVNS); + if (H != NULL) + StrBufAppendTemplate(Target, TP, H->Name, 0); } else if (WCC->Hdr->HR.Handler != NULL) { StrBufAppendTemplate(Target, TP, WCC->Hdr->HR.Handler->Name, 0); diff --git a/webcit/downloads.c b/webcit/downloads.c index 60783c568..f7f9c9dc5 100644 --- a/webcit/downloads.c +++ b/webcit/downloads.c @@ -38,22 +38,22 @@ void FreeFiles(void *vFile) /* -------------------------------------------------------------------------------- */ void tmplput_FILE_NAME(StrBuf *Target, WCTemplputParams *TP) { - FileListStruct *F = (FileListStruct*) CTX; + FileListStruct *F = (FileListStruct*) CTX(CTX_FILELIST); StrBufAppendTemplate(Target, TP, F->Filename, 0); } void tmplput_FILE_SIZE(StrBuf *Target, WCTemplputParams *TP) { - FileListStruct *F = (FileListStruct*) CTX; + FileListStruct *F = (FileListStruct*) CTX(CTX_FILELIST); StrBufAppendPrintf(Target, "%ld", F->FileSize); } void tmplput_FILEMIMETYPE(StrBuf *Target, WCTemplputParams *TP) { - FileListStruct *F = (FileListStruct*) CTX; + FileListStruct *F = (FileListStruct*) CTX(CTX_FILELIST); StrBufAppendTemplate(Target, TP, F->MimeType, 0); } void tmplput_FILE_COMMENT(StrBuf *Target, WCTemplputParams *TP) { - FileListStruct *F = (FileListStruct*) CTX; + FileListStruct *F = (FileListStruct*) CTX(CTX_FILELIST); StrBufAppendTemplate(Target, TP, F->Comment, 0); } @@ -61,7 +61,7 @@ void tmplput_FILE_COMMENT(StrBuf *Target, WCTemplputParams *TP) int Conditional_FILE_ISPIC(StrBuf *Target, WCTemplputParams *TP) { - FileListStruct *F = (FileListStruct*) CTX; + FileListStruct *F = (FileListStruct*) CTX(CTX_FILELIST); return F->IsPic; } diff --git a/webcit/mainmenu.c b/webcit/mainmenu.c index cbf9dc38f..31aec3986 100644 --- a/webcit/mainmenu.c +++ b/webcit/mainmenu.c @@ -41,7 +41,6 @@ void do_generic(void) return; } - memset(&SubTP, 0, sizeof(WCTemplputParams)); Buf = NewStrBuf(); serv_puts(bstr("g_cmd")); StrBuf_ServGetln(Buf); @@ -91,11 +90,11 @@ void do_generic(void) begin_burst(); output_headers(1, 0, 0, 0, 1, 0); - SubTP.Filter.ContextType = CTX_STRBUF; - SubTP.Context = Buf; - - DoTemplate(HKEY("aide_display_generic_result"), NULL, &SubTP); - + StackContext(NULL, &SubTP, Buf, CTX_STRBUF, 0, NULL); + { + DoTemplate(HKEY("aide_display_generic_result"), NULL, &SubTP); + } + UnStackContext(&SubTP); wDumpContent(1); FreeStrBuf(&Buf); diff --git a/webcit/messages.c b/webcit/messages.c index 2ce2ff6c8..c362b2f63 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -238,10 +238,11 @@ int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, co evaluate_mime_part(Msg, Mime); } DeleteHashPos(&it); - memset(&SubTP, 0, sizeof(WCTemplputParams)); - SubTP.Filter.ContextType = CTX_MAILSUM; - SubTP.Context = Msg; - *OutMime = DoTemplate(tmpl, tmpllen, Target, &SubTP); + StackContext(NULL, &SubTP, Msg, CTX_MAILSUM, 0, NULL); + { + *OutMime = DoTemplate(tmpl, tmpllen, Target, &SubTP); + } + UnStackContext(&SubTP); DestroyMessageSummary(Msg); FreeStrBuf(&FoundCharset); @@ -786,11 +787,14 @@ void readloop(long oper, eCustomRoomRenderer ForceRenderer) if (Stat.sortit) { CompareFunc SortIt; - memset(&SubTP, 0, sizeof(WCTemplputParams)); - SubTP.Filter.ContextType = CTX_MAILSUM; - SubTP.Context = NULL; - SortIt = RetrieveSort(&SubTP, NULL, 0, - HKEY("date"), Stat.defaultsortorder); + StackContext(NULL, &SubTP, NULL, CTX_MAILSUM, 0, NULL); + { + SortIt = RetrieveSort(&SubTP, + NULL, 0, + HKEY("date"), + Stat.defaultsortorder); + } + UnStackContext(&SubTP); if (SortIt != NULL) SortByPayload(WCC->summ, SortIt); } diff --git a/webcit/msg_renderers.c b/webcit/msg_renderers.c index d2de1f4bd..8e215262f 100644 --- a/webcit/msg_renderers.c +++ b/webcit/msg_renderers.c @@ -247,7 +247,7 @@ void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) } int Conditional_ANONYMOUS_MESSAGE(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return Msg->nhdr != 0; } @@ -273,7 +273,7 @@ void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) } void tmplput_MAIL_SUMM_FROM(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); StrBufAppendTemplate(Target, TP, Msg->from, 0); } @@ -293,7 +293,7 @@ void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) } void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); if (TP->Tokens->nParameters == 4) { @@ -312,7 +312,7 @@ void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP) } int Conditional_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return StrLength(Msg->subj) > 0; @@ -335,13 +335,13 @@ void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) } void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); StrBufAppendTemplate(Target, TP, Msg->reply_inreplyto, 0); } int Conditional_MAIL_SUMM_UNREAD(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return (Msg->Flags & MSGFLAG_READ) != 0; } @@ -361,7 +361,7 @@ void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) } void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); StrBufAppendTemplate(Target, TP, Msg->reply_references, 0); } @@ -388,7 +388,7 @@ void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) } void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); StrBufAppendTemplate(Target, TP, Msg->cccc, 0); } @@ -403,7 +403,7 @@ void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) } void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); StrBufAppendTemplate(Target, TP, Msg->Room, 0); } @@ -415,17 +415,17 @@ void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) } void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); StrBufAppendTemplate(Target, TP, Msg->Rfca, 0); } int Conditional_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return StrLength(Msg->Rfca) > 0; } int Conditional_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return StrLength(Msg->cccc) > 0; } @@ -443,12 +443,12 @@ void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) } void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); StrBufAppendTemplate(Target, TP, Msg->OtherNode, 0); } int Conditional_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return StrLength(Msg->OtherNode) > 0; } @@ -475,22 +475,22 @@ void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) } void tmplput_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); StrBufAppendTemplate(Target, TP, Msg->to, 0); } int Conditional_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return StrLength(Msg->to) != 0; } int Conditional_MAIL_SUMM_SUBJ(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return StrLength(Msg->subj) != 0; } void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); StrBufAppendTemplate(Target, TP, Msg->AllRcpt, 0); } @@ -513,27 +513,27 @@ void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) void tmplput_MAIL_SUMM_DATE_BRIEF(StrBuf *Target, WCTemplputParams *TP) { char datebuf[64]; - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_BRIEF); StrBufAppendBufPlain(Target, datebuf, -1, 0); } void tmplput_MAIL_SUMM_EUID(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); StrBufAppendTemplate(Target, TP, Msg->euid, 0); } void tmplput_MAIL_SUMM_DATE_FULL(StrBuf *Target, WCTemplputParams *TP) { char datebuf[64]; - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_FULL); StrBufAppendBufPlain(Target, datebuf, -1, 0); } void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); StrBufAppendPrintf(Target, "%ld", Msg->date, 0); } @@ -755,7 +755,7 @@ void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime) void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments)); } @@ -776,12 +776,12 @@ void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) } void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); StrBufAppendTemplate(Target, TP, Msg->hnod, 0); } int Conditional_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return StrLength(Msg->hnod) > 0; } @@ -860,14 +860,14 @@ void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCh void tmplput_MAIL_SUMM_N(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); StrBufAppendPrintf(Target, "%ld", Msg->msgnum); } void tmplput_MAIL_SUMM_PERMALINK(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); char perma_link[1024]; strcpy(perma_link, "/readfwd?go="); @@ -879,25 +879,25 @@ void tmplput_MAIL_SUMM_PERMALINK(StrBuf *Target, WCTemplputParams *TP) int Conditional_MAIL_MIME_ALL(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return GetCount(Msg->Attachments) > 0; } int Conditional_MAIL_MIME_SUBMESSAGES(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return GetCount(Msg->Submessages) > 0; } int Conditional_MAIL_MIME_ATTACHLINKS(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return GetCount(Msg->AttachLinks) > 0; } int Conditional_MAIL_MIME_ATTACH(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return GetCount(Msg->AllAttach) > 0; } @@ -953,7 +953,7 @@ void tmplput_EDIT_WIKI_BODY(StrBuf *Target, WCTemplputParams *TP) void tmplput_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); StrBufAppendTemplate(Target, TP, Msg->MsgBody->Data, 0); } @@ -1127,58 +1127,58 @@ void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *Foun HashList *iterate_get_mime_All(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return Msg->Attachments; } HashList *iterate_get_mime_Submessages(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return Msg->Submessages; } HashList *iterate_get_mime_AttachLinks(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return Msg->AttachLinks; } HashList *iterate_get_mime_Attachments(StrBuf *Target, WCTemplputParams *TP) { - message_summary *Msg = (message_summary*) CTX; + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return Msg->AllAttach; } void tmplput_MIME_Name(StrBuf *Target, WCTemplputParams *TP) { - wc_mime_attachment *mime = (wc_mime_attachment*) CTX; + wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH); StrBufAppendTemplate(Target, TP, mime->Name, 0); } void tmplput_MIME_FileName(StrBuf *Target, WCTemplputParams *TP) { - wc_mime_attachment *mime = (wc_mime_attachment*) CTX; + wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH); StrBufAppendTemplate(Target, TP, mime->FileName, 0); } void tmplput_MIME_PartNum(StrBuf *Target, WCTemplputParams *TP) { - wc_mime_attachment *mime = (wc_mime_attachment*) CTX; + wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH); StrBufAppendTemplate(Target, TP, mime->PartNum, 0); } void tmplput_MIME_MsgNum(StrBuf *Target, WCTemplputParams *TP) { - wc_mime_attachment *mime = (wc_mime_attachment*) CTX; + wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH); StrBufAppendPrintf(Target, "%ld", mime->msgnum); } void tmplput_MIME_Disposition(StrBuf *Target, WCTemplputParams *TP) { - wc_mime_attachment *mime = (wc_mime_attachment*) CTX; + wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH); StrBufAppendTemplate(Target, TP, mime->Disposition, 0); } void tmplput_MIME_ContentType(StrBuf *Target, WCTemplputParams *TP) { - wc_mime_attachment *mime = (wc_mime_attachment*) CTX; + wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH); StrBufAppendTemplate(Target, TP, mime->ContentType, 0); } @@ -1189,13 +1189,13 @@ void examine_charset(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset void tmplput_MIME_Charset(StrBuf *Target, WCTemplputParams *TP) { - wc_mime_attachment *mime = (wc_mime_attachment*) CTX; + wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH); StrBufAppendTemplate(Target, TP, mime->Charset, 0); } void tmplput_MIME_Data(StrBuf *Target, WCTemplputParams *TP) { - wc_mime_attachment *mime = (wc_mime_attachment*) CTX; + wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH); if (mime->Renderer != NULL) mime->Renderer->f(mime, NULL, NULL); StrBufAppendTemplate(Target, TP, mime->Data, 0); @@ -1205,7 +1205,7 @@ void tmplput_MIME_Data(StrBuf *Target, WCTemplputParams *TP) void tmplput_MIME_LoadData(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; - wc_mime_attachment *mime = (wc_mime_attachment*) CTX; + wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH); wc_mime_attachment *att; if (( (!strcasecmp(ChrPtr(mime->Disposition), "inline"))|| @@ -1233,7 +1233,7 @@ void tmplput_MIME_LoadData(StrBuf *Target, WCTemplputParams *TP) void tmplput_MIME_Length(StrBuf *Target, WCTemplputParams *TP) { - wc_mime_attachment *mime = (wc_mime_attachment*) CTX; + wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH); StrBufAppendPrintf(Target, "%ld", mime->length); } @@ -1430,10 +1430,7 @@ int json_RenderView_or_Tail(SharedMessageStatus *Stat, void **ViewSpecific, long oper) { - WCTemplputParams SubTP; - - memset(&SubTP, 0, sizeof(WCTemplputParams)); - DoTemplate(HKEY("mailsummary_json"),NULL, &SubTP); + DoTemplate(HKEY("mailsummary_json"),NULL, NULL); return 0; } diff --git a/webcit/netconf.c b/webcit/netconf.c index caecca46f..4dd20d45e 100644 --- a/webcit/netconf.c +++ b/webcit/netconf.c @@ -193,15 +193,15 @@ void display_edit_node(void) DeleteHash(&NodeConfig); return; } - - memset(&SubTP, 0, sizeof(WCTemplputParams)); - SubTP.Filter.ContextType = CTX_NODECONF; - SubTP.Context = vNode; - begin_burst(); - Tmpl = sbstr("template"); - output_headers(1, 0, 0, 0, 1, 0); - DoTemplate(SKEY(Tmpl), NULL, &SubTP); - end_burst(); + StackContext(NULL, &SubTP, vNode, CTX_NODECONF, 0, NULL); + { + begin_burst(); + Tmpl = sbstr("template"); + output_headers(1, 0, 0, 0, 1, 0); + DoTemplate(SKEY(Tmpl), NULL, &SubTP); + end_burst(); + } + UnStackContext(&SubTP); DeleteHash(&NodeConfig); } @@ -261,25 +261,25 @@ void delete_node(void) void tmplput_NodeName(StrBuf *Target, WCTemplputParams *TP) { - NodeConf *Node = (NodeConf*) CTX; + NodeConf *Node = (NodeConf*) CTX(CTX_NODECONF); StrBufAppendTemplate(Target, TP, Node->NodeName, 0); } void tmplput_Secret(StrBuf *Target, WCTemplputParams *TP) { - NodeConf *Node = (NodeConf*) CTX; + NodeConf *Node = (NodeConf*) CTX(CTX_NODECONF); StrBufAppendTemplate(Target, TP, Node->Secret, 0); } void tmplput_Host(StrBuf *Target, WCTemplputParams *TP) { - NodeConf *Node= (NodeConf*) CTX; + NodeConf *Node= (NodeConf*) CTX(CTX_NODECONF); StrBufAppendTemplate(Target, TP, Node->Host, 0); } void tmplput_Port(StrBuf *Target, WCTemplputParams *TP) { - NodeConf *Node= (NodeConf*) CTX; + NodeConf *Node= (NodeConf*) CTX(CTX_NODECONF); StrBufAppendTemplate(Target, TP, Node->Port, 0); } diff --git a/webcit/notes.c b/webcit/notes.c index d9d0ebf65..114124840 100644 --- a/webcit/notes.c +++ b/webcit/notes.c @@ -351,61 +351,61 @@ void add_new_note(void) { void tmpl_vcard_put_posleft(StrBuf *Target, WCTemplputParams *TP) { - struct vnote *v = (struct vnote *) CTX; + struct vnote *v = (struct vnote *) CTX(CTX_VNOTE); StrBufAppendPrintf(Target, "%d", v->pos_left); } void tmpl_vcard_put_postop(StrBuf *Target, WCTemplputParams *TP) { - struct vnote *v = (struct vnote *) CTX; + struct vnote *v = (struct vnote *) CTX(CTX_VNOTE); StrBufAppendPrintf(Target, "%d", v->pos_top); } void tmpl_vcard_put_poswidth(StrBuf *Target, WCTemplputParams *TP) { - struct vnote *v = (struct vnote *) CTX; + struct vnote *v = (struct vnote *) CTX(CTX_VNOTE); StrBufAppendPrintf(Target, "%d", v->pos_width); } void tmpl_vcard_put_posheight(StrBuf *Target, WCTemplputParams *TP) { - struct vnote *v = (struct vnote *) CTX; + struct vnote *v = (struct vnote *) CTX(CTX_VNOTE); StrBufAppendPrintf(Target, "%d", v->pos_height); } void tmpl_vcard_put_posheight2(StrBuf *Target, WCTemplputParams *TP) { - struct vnote *v = (struct vnote *) CTX; + struct vnote *v = (struct vnote *) CTX(CTX_VNOTE); StrBufAppendPrintf(Target, "%d", (v->pos_height / 16) - 5); } void tmpl_vcard_put_width2(StrBuf *Target, WCTemplputParams *TP) { - struct vnote *v = (struct vnote *) CTX; + struct vnote *v = (struct vnote *) CTX(CTX_VNOTE); StrBufAppendPrintf(Target, "%d", (v->pos_width / 9) - 1); } void tmpl_vcard_put_color(StrBuf *Target, WCTemplputParams *TP) { - struct vnote *v = (struct vnote *) CTX; + struct vnote *v = (struct vnote *) CTX(CTX_VNOTE); StrBufAppendPrintf(Target, "%02X%02X%02X", v->color_red, v->color_green, v->color_blue); } void tmpl_vcard_put_bgcolor(StrBuf *Target, WCTemplputParams *TP) { - struct vnote *v = (struct vnote *) CTX; + struct vnote *v = (struct vnote *) CTX(CTX_VNOTE); StrBufAppendPrintf(Target, "%02X%02X%02X", v->color_red/2, v->color_green/2, v->color_blue/2); } void tmpl_vcard_put_message(StrBuf *Target, WCTemplputParams *TP) { - struct vnote *v = (struct vnote *) CTX; + struct vnote *v = (struct vnote *) CTX(CTX_VNOTE); StrEscAppend(Target, NULL, v->body, 0, 0); /*TODO?*/ } void tmpl_vcard_put_uid(StrBuf *Target, WCTemplputParams *TP) { - struct vnote *v = (struct vnote *) CTX; + struct vnote *v = (struct vnote *) CTX(CTX_VNOTE); StrBufAppendBufPlain(Target, v->uid, -1, 0); } diff --git a/webcit/pushemail.c b/webcit/pushemail.c index 2cdc91f53..92fd026b1 100644 --- a/webcit/pushemail.c +++ b/webcit/pushemail.c @@ -13,9 +13,7 @@ void display_pushemail(void) WCTemplputParams SubTP; char mobnum[20]; - memset(&SubTP, 0, sizeof(WCTemplputParams)); - SubTP.Filter.ContextType = CTX_LONGVECTOR; - SubTP.Context = &vector; + StackContext(NULL, &SubTP, &vector, CTX_LONGVECTOR, 0, NULL); vector[0] = 16; /* Find any existing settings*/ @@ -89,6 +87,7 @@ void display_pushemail(void) output_headers(1, 1, 1, 0, 0, 0); DoTemplate(HKEY("prefs_pushemail"), NULL, &SubTP); wDumpContent(1); + UnStackContext(&SubTP); FreeStrBuf(&Buf); } diff --git a/webcit/roomlist.c b/webcit/roomlist.c index beb2faae7..5ade41ead 100644 --- a/webcit/roomlist.c +++ b/webcit/roomlist.c @@ -595,7 +595,7 @@ int CompareRooms(const folder *room1, const folder *room2) int ConditionalRoomIsRESTSubRoom(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; - folder *Folder = (folder *)CTX; + folder *Folder = (folder *)CTX(CTX_ROOMS); HashPos *it; StrBuf * Dir; void *vDir; diff --git a/webcit/roomtokens.c b/webcit/roomtokens.c index c7eec1257..7a993dd6a 100644 --- a/webcit/roomtokens.c +++ b/webcit/roomtokens.c @@ -61,7 +61,7 @@ void tmplput_roombanner(StrBuf *Target, WCTemplputParams *TP) void tmplput_FLOOR_ID(StrBuf *Target, WCTemplputParams *TP) { - Floor *myFloor = (Floor *)CTX; + Floor *myFloor = (Floor *)CTX(CTX_FLOORS); StrBufAppendPrintf(Target, "%d", myFloor->ID); } @@ -69,14 +69,14 @@ void tmplput_FLOOR_ID(StrBuf *Target, WCTemplputParams *TP) void tmplput_ROOM_FLOORID(StrBuf *Target, WCTemplputParams *TP) { - folder *Folder = (folder *)CTX; + folder *Folder = (folder *)CTX(CTX_ROOMS); StrBufAppendPrintf(Target, "%d", Folder->floorid); } void tmplput_ROOM_FLOOR_ID(StrBuf *Target, WCTemplputParams *TP) { - folder *Folder = (folder *)CTX; + folder *Folder = (folder *)CTX(CTX_ROOMS); const Floor *pFloor = Folder->Floor; if (pFloor == NULL) @@ -88,7 +88,7 @@ void tmplput_ROOM_FLOOR_ID(StrBuf *Target, WCTemplputParams *TP) void tmplput_ROOM_FLOOR_NAME(StrBuf *Target, WCTemplputParams *TP) { - folder *Folder = (folder *)CTX; + folder *Folder = (folder *)CTX(CTX_ROOMS); const Floor *pFloor = Folder->Floor; if (pFloor == NULL) @@ -117,7 +117,7 @@ void tmplput_ThisRoomFloorName(StrBuf *Target, WCTemplputParams *TP) void tmplput_FLOOR_NAME(StrBuf *Target, WCTemplputParams *TP) { - Floor *myFloor = (Floor *)CTX; + Floor *myFloor = (Floor *)CTX(CTX_FLOORS); StrBufAppendTemplate(Target, TP, myFloor->Name, 0); } @@ -125,7 +125,7 @@ void tmplput_FLOOR_NAME(StrBuf *Target, WCTemplputParams *TP) void tmplput_FLOOR_NROOMS(StrBuf *Target, WCTemplputParams *TP) { - Floor *myFloor = (Floor *)CTX; + Floor *myFloor = (Floor *)CTX(CTX_FLOORS); StrBufAppendPrintf(Target, "%d", myFloor->NRooms); } @@ -133,7 +133,7 @@ void tmplput_FLOOR_NROOMS(StrBuf *Target, WCTemplputParams *TP) void tmplput_ROOM_FLOOR_NROOMS(StrBuf *Target, WCTemplputParams *TP) { - folder *Folder = (folder *)CTX; + folder *Folder = (folder *)CTX(CTX_ROOMS); const Floor *pFloor = Folder->Floor; if (pFloor == NULL) @@ -144,7 +144,7 @@ void tmplput_ROOM_FLOOR_NROOMS(StrBuf *Target, WCTemplputParams *TP) int ConditionalFloorHaveNRooms(StrBuf *Target, WCTemplputParams *TP) { - Floor *MyFloor = (Floor *)CTX; + Floor *MyFloor = (Floor *)CTX(CTX_FLOORS); int HaveN; HaveN = GetTemplateTokenNumber(Target, TP, 0, 0); @@ -156,7 +156,7 @@ int ConditionalFloorHaveNRooms(StrBuf *Target, WCTemplputParams *TP) int ConditionalFloorIsRESTSubFloor(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; - Floor *MyFloor = (Floor *)CTX; + Floor *MyFloor = (Floor *)CTX(CTX_FLOORS); /** if we have dav_depth the client just wants the subfloors */ if ((WCC->Hdr->HR.dav_depth == 1) && (GetCount(WCC->Directory) == 0)) @@ -168,7 +168,7 @@ int ConditionalFloorIsRESTSubFloor(StrBuf *Target, WCTemplputParams *TP) int ConditionalFloorIsSUBROOM(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; - Floor *MyFloor = (Floor *)CTX; + Floor *MyFloor = (Floor *)CTX(CTX_FLOORS); return WCC->CurRoom.floorid == MyFloor->ID; } @@ -176,7 +176,7 @@ int ConditionalFloorIsSUBROOM(StrBuf *Target, WCTemplputParams *TP) int ConditionalFloorIsVirtual(StrBuf *Target, WCTemplputParams *TP) { - Floor *MyFloor = (Floor *)CTX; + Floor *MyFloor = (Floor *)CTX(CTX_FLOORS); return MyFloor->ID == VIRTUAL_MY_FLOOR; } @@ -202,7 +202,7 @@ void tmplput_ThisRoom(StrBuf *Target, WCTemplputParams *TP) void tmplput_ROOM_NAME(StrBuf *Target, WCTemplputParams *TP) { - folder *Folder = (folder *)CTX; + folder *Folder = (folder *)CTX(CTX_ROOMS); StrBufAppendTemplate(Target, TP, Folder->name, 0); } @@ -210,7 +210,7 @@ void tmplput_ROOM_NAME(StrBuf *Target, WCTemplputParams *TP) void tmplput_ROOM_BASENAME(StrBuf *Target, WCTemplputParams *TP) { - folder *room = (folder *)CTX; + folder *room = (folder *)CTX(CTX_ROOMS); if (room->nRoomNameParts > 1) StrBufAppendTemplate(Target, TP, @@ -222,7 +222,7 @@ void tmplput_ROOM_BASENAME(StrBuf *Target, WCTemplputParams *TP) void tmplput_ROOM_LEVEL_N_TIMES(StrBuf *Target, WCTemplputParams *TP) { - folder *room = (folder *)CTX; + folder *room = (folder *)CTX(CTX_ROOMS); int i; const char *AppendMe; long AppendMeLen; @@ -239,7 +239,7 @@ void tmplput_ROOM_LEVEL_N_TIMES(StrBuf *Target, WCTemplputParams *TP) int ConditionalRoomIsInbox(StrBuf *Target, WCTemplputParams *TP) { - folder *Folder = (folder *)CTX; + folder *Folder = (folder *)CTX(CTX_ROOMS); return Folder->is_inbox; } @@ -295,7 +295,7 @@ int ConditionalRoomHas_QRFlag(StrBuf *Target, WCTemplputParams *TP) void tmplput_ROOM_QRFLAGS(StrBuf *Target, WCTemplputParams *TP) { - folder *Folder = (folder *)CTX; + folder *Folder = (folder *)CTX(CTX_ROOMS); StrBufAppendPrintf(Target, "%d", Folder->QRFlags); } @@ -351,7 +351,7 @@ int ConditionalRoomHas_UAFlag(StrBuf *Target, WCTemplputParams *TP) void tmplput_ROOM_ACL(StrBuf *Target, WCTemplputParams *TP) { - folder *Folder = (folder *)CTX; + folder *Folder = (folder *)CTX(CTX_ROOMS); StrBufAppendPrintf(Target, "%ld", Folder->RAFlags, 0); } @@ -459,7 +459,7 @@ int ConditionalThisRoomOrder(StrBuf *Target, WCTemplputParams *TP) void tmplput_ROOM_LISTORDER(StrBuf *Target, WCTemplputParams *TP) { - folder *Folder = (folder *)CTX; + folder *Folder = (folder *)CTX(CTX_ROOMS); StrBufAppendPrintf(Target, "%d", Folder->Order); } @@ -516,7 +516,7 @@ void tmplput_ThisRoomInfoText(StrBuf *Target, WCTemplputParams *TP) void tmplput_ROOM_LASTCHANGE(StrBuf *Target, WCTemplputParams *TP) { - folder *Folder = (folder *)CTX; + folder *Folder = (folder *)CTX(CTX_ROOMS); StrBufAppendPrintf(Target, "%d", Folder->lastchange); } @@ -556,7 +556,7 @@ void tmplput_ThisRoomX_FileString(StrBuf *Target, WCTemplputParams *TP) int ConditionalIsThisThatRoom(StrBuf *Target, WCTemplputParams *TP) { - folder *Folder = (folder *)CTX; + folder *Folder = (folder *)CTX(CTX_ROOMS); wcsession *WCC = WC; if (WCC == NULL) diff --git a/webcit/roomviews.c b/webcit/roomviews.c index f297bc020..eacc55cf5 100644 --- a/webcit/roomviews.c +++ b/webcit/roomviews.c @@ -63,7 +63,7 @@ void initialize_viewdefs(void) { void tmplput_ROOM_COLLECTIONTYPE(StrBuf *Target, WCTemplputParams *TP) { - folder *Folder = (folder *)CTX; + folder *Folder = (folder *)CTX(CTX_ROOMS); switch(Folder->view) { case VIEW_CALENDAR: @@ -91,7 +91,7 @@ void tmplput_ROOM_COLLECTIONTYPE(StrBuf *Target, WCTemplputParams *TP) int ConditionalRoomHasGroupdavContent(StrBuf *Target, WCTemplputParams *TP) { - folder *Folder = (folder *)CTX; + folder *Folder = (folder *)CTX(CTX_ROOMS); syslog(0, "-> %s: %d\n", ChrPtr(Folder->name), Folder->view); @@ -228,12 +228,12 @@ int ConditionalThisRoomHaveView(StrBuf *Target, WCTemplputParams *TP) void tmplput_ROOM_VIEW(StrBuf *Target, WCTemplputParams *TP) { - folder *Folder = (folder *)CTX; + folder *Folder = (folder *)CTX(CTX_ROOMS); StrBufAppendPrintf(Target, "%d", Folder->view); } void tmplput_ROOM_DEFVIEW(StrBuf *Target, WCTemplputParams *TP) { - folder *Folder = (folder *)CTX; + folder *Folder = (folder *)CTX(CTX_ROOMS); StrBufAppendPrintf(Target, "%d", Folder->defview); } diff --git a/webcit/sieve.c b/webcit/sieve.c index d93fdcc6c..a49d6b30d 100644 --- a/webcit/sieve.c +++ b/webcit/sieve.c @@ -488,22 +488,22 @@ typedef struct __SieveListing { int ConditionalSieveScriptIsActive(StrBuf *Target, WCTemplputParams *TP) { - SieveListing *SieveList = (SieveListing *)CTX; + SieveListing *SieveList = (SieveListing *)CTX(CTX_SIEVELIST); return SieveList->IsActive; } int ConditionalSieveScriptIsRulesScript(StrBuf *Target, WCTemplputParams *TP) { - SieveListing *SieveList = (SieveListing *)CTX; + SieveListing *SieveList = (SieveListing *)CTX(CTX_SIEVELIST); return SieveList->IsActive; } void tmplput_SieveScriptName(StrBuf *Target, WCTemplputParams *TP) { - SieveListing *SieveList = (SieveListing *)CTX; + SieveListing *SieveList = (SieveListing *)CTX(CTX_SIEVELIST); StrBufAppendTemplate(Target, TP, SieveList->Name, 0); } void tmplput_SieveScriptContent(StrBuf *Target, WCTemplputParams *TP) { - SieveListing *SieveList = (SieveListing *)CTX; + SieveListing *SieveList = (SieveListing *)CTX(CTX_SIEVELIST); StrBufAppendTemplate(Target, TP, SieveList->Content, 0); } void FreeSieveListing(void *vSieveListing) @@ -683,7 +683,7 @@ typedef struct __SieveRule { int ConditionalSieveRule_hfield(StrBuf *Target, WCTemplputParams *TP) { - SieveRule *Rule = (SieveRule *)CTX; + SieveRule *Rule = (SieveRule *)CTX(CTX_SIEVESCRIPT); return GetTemplateTokenNumber(Target, TP, @@ -694,7 +694,7 @@ int ConditionalSieveRule_hfield(StrBuf *Target, WCTemplputParams *TP) } int ConditionalSieveRule_compare(StrBuf *Target, WCTemplputParams *TP) { - SieveRule *Rule = (SieveRule *)CTX; + SieveRule *Rule = (SieveRule *)CTX(CTX_SIEVESCRIPT); return GetTemplateTokenNumber(Target, TP, 3, @@ -704,7 +704,7 @@ int ConditionalSieveRule_compare(StrBuf *Target, WCTemplputParams *TP) } int ConditionalSieveRule_action(StrBuf *Target, WCTemplputParams *TP) { - SieveRule *Rule = (SieveRule *)CTX; + SieveRule *Rule = (SieveRule *)CTX(CTX_SIEVESCRIPT); return GetTemplateTokenNumber(Target, TP, 3, @@ -714,7 +714,7 @@ int ConditionalSieveRule_action(StrBuf *Target, WCTemplputParams *TP) } int ConditionalSieveRule_sizecomp(StrBuf *Target, WCTemplputParams *TP) { - SieveRule *Rule = (SieveRule *)CTX; + SieveRule *Rule = (SieveRule *)CTX(CTX_SIEVESCRIPT); return GetTemplateTokenNumber(Target, TP, 3, @@ -724,7 +724,7 @@ int ConditionalSieveRule_sizecomp(StrBuf *Target, WCTemplputParams *TP) } int ConditionalSieveRule_final(StrBuf *Target, WCTemplputParams *TP) { - SieveRule *Rule = (SieveRule *)CTX; + SieveRule *Rule = (SieveRule *)CTX(CTX_SIEVESCRIPT); return GetTemplateTokenNumber(Target, TP, 3, @@ -734,7 +734,7 @@ int ConditionalSieveRule_final(StrBuf *Target, WCTemplputParams *TP) } int ConditionalSieveRule_ThisRoom(StrBuf *Target, WCTemplputParams *TP) { - SieveRule *Rule = (SieveRule *)CTX; + SieveRule *Rule = (SieveRule *)CTX(CTX_SIEVESCRIPT); return GetTemplateTokenNumber(Target, TP, 3, @@ -744,39 +744,39 @@ int ConditionalSieveRule_ThisRoom(StrBuf *Target, WCTemplputParams *TP) } int ConditionalSieveRule_Active(StrBuf *Target, WCTemplputParams *TP) { - SieveRule *Rule = (SieveRule *)CTX; + SieveRule *Rule = (SieveRule *)CTX(CTX_SIEVESCRIPT); return Rule->active; } void tmplput_SieveRule_htext(StrBuf *Target, WCTemplputParams *TP) { - SieveRule *Rule = (SieveRule *)CTX; + SieveRule *Rule = (SieveRule *)CTX(CTX_SIEVESCRIPT); StrBufAppendTemplate(Target, TP, Rule->htext, 0); } void tmplput_SieveRule_fileinto(StrBuf *Target, WCTemplputParams *TP) { - SieveRule *Rule = (SieveRule *)CTX; + SieveRule *Rule = (SieveRule *)CTX(CTX_SIEVESCRIPT); StrBufAppendTemplate(Target, TP, Rule->fileinto, 0); } void tmplput_SieveRule_redirect(StrBuf *Target, WCTemplputParams *TP) { - SieveRule *Rule = (SieveRule *)CTX; + SieveRule *Rule = (SieveRule *)CTX(CTX_SIEVESCRIPT); StrBufAppendTemplate(Target, TP, Rule->redirect, 0); } void tmplput_SieveRule_automsg(StrBuf *Target, WCTemplputParams *TP) { - SieveRule *Rule = (SieveRule *)CTX; + SieveRule *Rule = (SieveRule *)CTX(CTX_SIEVESCRIPT); StrBufAppendTemplate(Target, TP, Rule->automsg, 0); } void tmplput_SieveRule_sizeval(StrBuf *Target, WCTemplputParams *TP) { - SieveRule *Rule = (SieveRule *)CTX; + SieveRule *Rule = (SieveRule *)CTX(CTX_SIEVESCRIPT); StrBufAppendPrintf(Target, "%d", Rule->sizeval); } void tmplput_SieveRule_lookup_FileIntoRoom(StrBuf *Target, WCTemplputParams *TP) { void *vRoom; - SieveRule *Rule = (SieveRule *)CTX; + SieveRule *Rule = (SieveRule *)CTX(CTX_SIEVESCRIPT); wcsession *WCC = WC; HashList *Rooms = GetRoomListHashLKRA(Target, TP); diff --git a/webcit/siteconfig.c b/webcit/siteconfig.c index a16d9cfe8..5bd9fffcb 100644 --- a/webcit/siteconfig.c +++ b/webcit/siteconfig.c @@ -375,7 +375,7 @@ int ConditionalServCfgCTXStrBuf(StrBuf *Target, WCTemplputParams *TP) wcsession *WCC = WC; void *vBuf; StrBuf *Buf; - StrBuf *ZoneToCheck = (StrBuf*) CTX; + StrBuf *ZoneToCheck = (StrBuf*) CTX(CTX_STRBUF); if ((WCC->is_aide) || (ZoneToCheck == NULL)) { if (WCC->ServCfg == NULL) @@ -407,13 +407,13 @@ void DeleteLogStatusStruct(void *v) void tmplput_servcfg_LogName(StrBuf *Target, WCTemplputParams *TP) { - LogStatusStruct *Stat = (LogStatusStruct*) CTX; + LogStatusStruct *Stat = (LogStatusStruct*) CTX(CTX_SRVLOG); StrBufAppendTemplate(Target, TP, Stat->Name, 1); } int ConditionalServCfgThisLogEnabled(StrBuf *Target, WCTemplputParams *TP) { - LogStatusStruct *Stat = (LogStatusStruct*) CTX; + LogStatusStruct *Stat = (LogStatusStruct*) CTX(CTX_SRVLOG); return Stat->Enable; } diff --git a/webcit/smtpqueue.c b/webcit/smtpqueue.c index 360886380..fc95a0dc6 100644 --- a/webcit/smtpqueue.c +++ b/webcit/smtpqueue.c @@ -126,54 +126,54 @@ OneQueItem *DeserializeQueueItem(StrBuf *RawQItem, long QueMsgID) void tmplput_MailQID(StrBuf *Target, WCTemplputParams *TP) { - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); StrBufAppendPrintf(Target, "%ld", Item->QueMsgID);; } void tmplput_MailQPayloadID(StrBuf *Target, WCTemplputParams *TP) { - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); StrBufAppendPrintf(Target, "%ld", Item->MessageID); } void tmplput_MailQBounceTo(StrBuf *Target, WCTemplputParams *TP) { - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); StrBufAppendTemplate(Target, TP, Item->BounceTo, 0); } void tmplput_MailQAttempted(StrBuf *Target, WCTemplputParams *TP) { char datebuf[64]; - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); webcit_fmt_date(datebuf, 64, Item->ReattemptWhen, DATEFMT_BRIEF); StrBufAppendBufPlain(Target, datebuf, -1, 0); } void tmplput_MailQSubmitted(StrBuf *Target, WCTemplputParams *TP) { char datebuf[64]; - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); webcit_fmt_date(datebuf, 64, Item->Submitted, DATEFMT_BRIEF); StrBufAppendBufPlain(Target, datebuf, -1, 0); } void tmplput_MailQEnvelopeFrom(StrBuf *Target, WCTemplputParams *TP) { - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); StrBufAppendTemplate(Target, TP, Item->EnvelopeFrom, 0); } void tmplput_MailQSourceRoom(StrBuf *Target, WCTemplputParams *TP) { - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); StrBufAppendTemplate(Target, TP, Item->SenderRoom, 0); } int Conditional_MailQ_HaveSourceRoom(StrBuf *Target, WCTemplputParams *TP) { - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); return StrLength(Item->SenderRoom) > 0; } void tmplput_MailQRetry(StrBuf *Target, WCTemplputParams *TP) { char datebuf[64]; - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); if (Item->Retry == 0) { StrBufAppendBufPlain(Target, _("First Attempt pending"), -1, 0); @@ -186,23 +186,23 @@ void tmplput_MailQRetry(StrBuf *Target, WCTemplputParams *TP) void tmplput_MailQRCPT(StrBuf *Target, WCTemplputParams *TP) { - MailQEntry *Entry = (MailQEntry*) CTX; + MailQEntry *Entry = (MailQEntry*) CTX(CTX_MAILQ_RCPT); StrBufAppendTemplate(Target, TP, Entry->Recipient, 0); } void tmplput_MailQRCPTStatus(StrBuf *Target, WCTemplputParams *TP) { - MailQEntry *Entry = (MailQEntry*) CTX; + MailQEntry *Entry = (MailQEntry*) CTX(CTX_MAILQ_RCPT); StrBufAppendPrintf(Target, "%ld", Entry->Status); } void tmplput_MailQStatusMsg(StrBuf *Target, WCTemplputParams *TP) { - MailQEntry *Entry = (MailQEntry*) CTX; + MailQEntry *Entry = (MailQEntry*) CTX(CTX_MAILQ_RCPT); StrBufAppendTemplate(Target, TP, Entry->StatusMessage, 0); } HashList *iterate_get_Recipients(StrBuf *Target, WCTemplputParams *TP) { - OneQueItem *Item = (OneQueItem*) CTX; + OneQueItem *Item = (OneQueItem*) CTX(CTX_MAILQITEM); return Item->MailQEntries; } diff --git a/webcit/subst.c b/webcit/subst.c index 1a8d029f0..aa8d6665a 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -117,7 +117,47 @@ const char *CtxNames[] = { "Context UNKNOWN" }; +void StackContext(WCTemplputParams *Super, + WCTemplputParams *Sub, + void *Context, + int ContextType, + int nArgs, + WCTemplateToken *Tokens) +{ + memset(Sub, 0, sizeof(WCTemplputParams)); + + if (Super != NULL) { + Sub->Sub = Super->Sub; + Super->Sub = Sub; + } + Sub->Super = Super; + + Sub->Context = Context; + Sub->Filter.ContextType = ContextType; + Sub->nArgs = nArgs; + Sub->Tokens = Tokens; +} + +void UnStackContext(WCTemplputParams *Sub) +{ + if (Sub->Super != NULL) + { + Sub->Super->Sub = Sub->Sub; + } +} + +void *GetContextPayload(WCTemplputParams *TP, int ContextType) +{ + WCTemplputParams *whichTP = TP; + if (ContextType == CTX_NONE) + return TP->Context; + + while ((whichTP != NULL) && (whichTP->Filter.ContextType != ContextType)) + whichTP = whichTP->Super; + + return whichTP->Context; +} void DestroySortStruct(void *vSort) { @@ -163,23 +203,19 @@ void LogTemplateError (StrBuf *Target, const char *Type, int ErrorPos, WCTemplpu if (TP->Tokens != NULL) { syslog(1, "%s [%s] (in '%s' line %ld); %s; [%s]\n", - Type, - Err, - ChrPtr(TP->Tokens->FileName), - TP->Tokens->Line, - ChrPtr(Error), - ChrPtr(TP->Tokens->FlatToken)); + Type, + Err, + ChrPtr(TP->Tokens->FileName), + TP->Tokens->Line, + ChrPtr(Error), + ChrPtr(TP->Tokens->FlatToken)); } else { syslog(1, "%s: %s;\n", - Type, - ChrPtr(Error)); + Type, + ChrPtr(Error)); } -/* - if (Target == NULL) - return; -*/ WCC = WC; if (WCC == NULL) { FreeStrBuf(&Info); @@ -295,38 +331,31 @@ void RegisterNS(const char *NSName, NewHandler->Filter.nMinArgs = nMinArgs; NewHandler->Filter.nMaxArgs = nMaxArgs; NewHandler->Filter.ContextType = ContextRequired; - NewHandler->Filter.ControlContextType = CTX_NONE; NewHandler->PreEvalFunc = PreevalFunc; NewHandler->HandlerFunc = HandlerFunc; Put(GlobalNS, NSName, len, NewHandler, NULL); } -void RegisterControlNS(const char *NSName, - long len, - int nMinArgs, - int nMaxArgs, - WCHandlerFunc HandlerFunc, - int ControlContextRequired) + + +int CheckContext(StrBuf *Target, ContextFilter *Need, WCTemplputParams *TP, const char *ErrType) { - HashHandler *NewHandler; + WCTemplputParams *TPP = TP; - NewHandler = (HashHandler*) malloc(sizeof(HashHandler)); - memset(NewHandler, 0, sizeof(HashHandler)); - NewHandler->Filter.nMinArgs = nMinArgs; - NewHandler->Filter.nMaxArgs = nMaxArgs; - NewHandler->Filter.ContextType = CTX_NONE; - NewHandler->Filter.ControlContextType = ControlContextRequired; - NewHandler->HandlerFunc = HandlerFunc; - Put(GlobalNS, NSName, len, NewHandler, NULL); -} + if ((Need != NULL) && + (Need->ContextType != CTX_NONE) && + (Need->ContextType != TPP->Filter.ContextType)) { + while ((TPP != NULL) && + (Need->ContextType != TPP->Filter.ContextType)) + { + TPP = TPP->Super; + } + if (TPP != NULL) + return 1; -int CheckContext(StrBuf *Target, ContextFilter *Need, WCTemplputParams *TP, const char *ErrType) -{ - if ((Need->ContextType != CTX_NONE) && - (Need->ContextType != TP->Filter.ContextType)) { LogTemplateError( Target, ErrType, ERR_PARM1, TP, " WARNING: requires Context: [%s], have [%s]!", @@ -334,16 +363,6 @@ int CheckContext(StrBuf *Target, ContextFilter *Need, WCTemplputParams *TP, cons ContextName(TP->Filter.ContextType)); return 0; } - - if ((Need->ControlContextType != CTX_NONE) && - (Need->ControlContextType != TP->Filter.ControlContextType)) { - LogTemplateError( - Target, ErrType, ERR_PARM1, TP, - " WARNING: requires Control Context: [%s], have [%s]!", - ContextName(Need->ControlContextType), - ContextName(TP->Filter.ControlContextType)); - return 0; - } /* if (TP->Tokens->nParameters < Need->nMinArgs) { LogTemplateError(Target, ErrType, ERR_NAME, TP, @@ -427,7 +446,7 @@ void GetTemplateTokenString(StrBuf *Target, long *len) { StrBuf *Buf; - WCTemplputParams SubTP; +/// WCTemplputParams SubTP; if (N >= TP->Tokens->nParameters) { LogTemplateError(Target, @@ -495,11 +514,9 @@ void GetTemplateTokenString(StrBuf *Target, break; } - memset(&SubTP, 0, sizeof(WCTemplputParams *)); - SubTP.Context = TP->Context; - SubTP.Filter.ContextType = TP->Filter.ContextType; Buf = NewStrBuf(); - DoTemplate(TKEY(N), Buf, &SubTP); + DoTemplate(TKEY(N), Buf, TP); + *Value = ChrPtr(Buf); *len = StrLength(Buf); /* we can't free it here, so we put it into the subst so its discarded later on. */ @@ -1573,12 +1590,24 @@ int EvaluateToken(StrBuf *Target, int state, WCTemplputParams *TP) TmplGettext(Target, TP); break; case SV_CONDITIONAL: /** Forward conditional evaluation */ + Handler = (HashHandler*) TP->Tokens->PreEval; + if (!CheckContext(Target, &Handler->Filter, TP, "Conditional")) { + return -1; + } return EvaluateConditional(Target, 1, state, TP); break; case SV_NEG_CONDITIONAL: /** Reverse conditional evaluation */ + Handler = (HashHandler*) TP->Tokens->PreEval; + if (!CheckContext(Target, &Handler->Filter, TP, "Conditional")) { + return -1; + } return EvaluateConditional(Target, 0, state, TP); break; case SV_CUST_STR_CONDITIONAL: /** Conditional put custom strings from params */ + Handler = (HashHandler*) TP->Tokens->PreEval; + if (!CheckContext(Target, &Handler->Filter, TP, "Conditional")) { + return -1; + } if (TP->Tokens->nParameters >= 6) { if (EvaluateConditional(Target, 0, state, TP)) { GetTemplateTokenString(Target, TP, 5, &AppendMe, &AppendMeLen); @@ -1645,7 +1674,8 @@ const StrBuf *ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, WCTemplputParams memcpy(&TP.Filter, &CallingTP->Filter, sizeof(ContextFilter)); TP.Context = CallingTP->Context; - TP.ControlContext = CallingTP->ControlContext; + TP.Sub = CallingTP->Sub; + TP.Super = CallingTP->Super; if (LoadTemplates != 0) { if (LoadTemplates > 1) @@ -1877,6 +1907,7 @@ void tmpl_iterate_subtmpl(StrBuf *Target, WCTemplputParams *TP) void *vContext; void *vLastContext = NULL; StrBuf *SubBuf; + WCTemplputParams IterateTP; WCTemplputParams SubTP; IterateStruct Status; @@ -1885,7 +1916,6 @@ void tmpl_iterate_subtmpl(StrBuf *Target, WCTemplputParams *TP) long StopAt = -1; memset(&Status, 0, sizeof(IterateStruct)); - memcpy (&SubTP, &TP, sizeof(WCTemplputParams)); It = (HashIterator*) TP->Tokens->Preeval2; if (It == NULL) { @@ -1940,42 +1970,47 @@ void tmpl_iterate_subtmpl(StrBuf *Target, WCTemplputParams *TP) } } nMembersUsed = GetCount(List); - SubBuf = NewStrBuf(); - SubTP.Filter.ContextType = It->ContextType; - SubTP.Filter.ControlContextType = CTX_ITERATE; - SubTP.ControlContext = &Status; + + StackContext (TP, &IterateTP, &Status, CTX_ITERATE, 0, TP->Tokens); + { + SubBuf = NewStrBuf(); - if (HAVE_PARAM(2)) { - StartAt = GetTemplateTokenNumber(Target, TP, 2, 0); - } - if (HAVE_PARAM(3)) { - StepWidth = GetTemplateTokenNumber(Target, TP, 3, 0); - } - if (HAVE_PARAM(4)) { - StopAt = GetTemplateTokenNumber(Target, TP, 4, -1); - } - it = GetNewHashPos(List, StepWidth); - if (StopAt < 0) { - StopAt = GetCount(List); - } - while (GetNextHashPos(List, it, &Status.KeyLen, &Status.Key, &vContext)) { - if ((Status.n >= StartAt) && (Status.n <= StopAt)) { - if (DetectGroupChange && Status.n > 0) { - Status.GroupChange = SortBy->GroupChange(vContext, vLastContext); + if (HAVE_PARAM(2)) { + StartAt = GetTemplateTokenNumber(Target, TP, 2, 0); + } + if (HAVE_PARAM(3)) { + StepWidth = GetTemplateTokenNumber(Target, TP, 3, 0); + } + if (HAVE_PARAM(4)) { + StopAt = GetTemplateTokenNumber(Target, TP, 4, -1); + } + it = GetNewHashPos(List, StepWidth); + if (StopAt < 0) { + StopAt = GetCount(List); + } + while (GetNextHashPos(List, it, &Status.KeyLen, &Status.Key, &vContext)) { + if ((Status.n >= StartAt) && (Status.n <= StopAt)) { + if (DetectGroupChange && Status.n > 0) { + Status.GroupChange = SortBy->GroupChange(vContext, vLastContext); + } + Status.LastN = (Status.n + 1) == nMembersUsed; + StackContext(&IterateTP, &SubTP, vContext, It->ContextType, 0, NULL); + { + if (It->DoSubTemplate != NULL) + It->DoSubTemplate(SubBuf, &SubTP); + DoTemplate(TKEY(1), SubBuf, &SubTP); + + StrBufAppendBuf(Target, SubBuf, 0); + FlushStrBuf(SubBuf); + } + UnStackContext(&SubTP); + Status.oddeven = ! Status.oddeven; + vLastContext = vContext; } - Status.LastN = (Status.n + 1) == nMembersUsed; - SubTP.Context = vContext; - if (It->DoSubTemplate != NULL) - It->DoSubTemplate(SubBuf, &SubTP); - DoTemplate(TKEY(1), SubBuf, &SubTP); - - StrBufAppendBuf(Target, SubBuf, 0); - FlushStrBuf(SubBuf); - Status.oddeven = ! Status.oddeven; - vLastContext = vContext; + Status.n++; } - Status.n++; } + UnStackContext(&IterateTP); FreeStrBuf(&SubBuf); DeleteHashPos(&it); if (It->Destructor != NULL) @@ -1985,7 +2020,7 @@ void tmpl_iterate_subtmpl(StrBuf *Target, WCTemplputParams *TP) int conditional_ITERATE_ISGROUPCHANGE(StrBuf *Target, WCTemplputParams *TP) { - IterateStruct *Ctx = CCTX; + IterateStruct *Ctx = CTX(CTX_ITERATE); if (TP->Tokens->nParameters < 3) return Ctx->GroupChange; @@ -1994,7 +2029,7 @@ int conditional_ITERATE_ISGROUPCHANGE(StrBuf *Target, WCTemplputParams *TP) void tmplput_ITERATE_ODDEVEN(StrBuf *Target, WCTemplputParams *TP) { - IterateStruct *Ctx = CCTX; + IterateStruct *Ctx = CTX(CTX_ITERATE); if (Ctx->oddeven) StrBufAppendBufPlain(Target, HKEY("odd"), 0); else @@ -2004,7 +2039,7 @@ void tmplput_ITERATE_ODDEVEN(StrBuf *Target, WCTemplputParams *TP) void tmplput_ITERATE_KEY(StrBuf *Target, WCTemplputParams *TP) { - IterateStruct *Ctx = CCTX; + IterateStruct *Ctx = CTX(CTX_ITERATE); StrBufAppendBufPlain(Target, Ctx->Key, Ctx->KeyLen, 0); } @@ -2012,19 +2047,19 @@ void tmplput_ITERATE_KEY(StrBuf *Target, WCTemplputParams *TP) void tmplput_ITERATE_LASTN(StrBuf *Target, WCTemplputParams *TP) { - IterateStruct *Ctx = CCTX; + IterateStruct *Ctx = CTX(CTX_ITERATE); StrBufAppendPrintf(Target, "%d", Ctx->n); } int conditional_ITERATE_FIRSTN(StrBuf *Target, WCTemplputParams *TP) { - IterateStruct *Ctx = CCTX; + IterateStruct *Ctx = CTX(CTX_ITERATE); return Ctx->n == 0; } int conditional_ITERATE_LASTN(StrBuf *Target, WCTemplputParams *TP) { - IterateStruct *Ctx = CCTX; + IterateStruct *Ctx = CTX(CTX_ITERATE); return Ctx->LastN; } @@ -2054,6 +2089,7 @@ int EvaluateConditional(StrBuf *Target, int Neg, int state, WCTemplputParams *TP if (!CheckContext(Target, &Cond->Filter, TP, "Conditional")) { return 0; } + res = Cond->CondF(Target, TP); if (res == Neg) rc = TP->Tokens->Params[1]->lvalue; @@ -2078,25 +2114,6 @@ void RegisterConditional(const char *Name, long len, Cond->Filter.nMinArgs = nParams; Cond->CondF = CondF; Cond->Filter.ContextType = ContextRequired; - Cond->Filter.ControlContextType = CTX_NONE; - Put(Conditionals, Name, len, Cond, NULL); -} - -void RegisterControlConditional(const char *Name, long len, - int nParams, - WCConditionalFunc CondF, - int ControlContextRequired) -{ - ConditionalStruct *Cond; - - Cond = (ConditionalStruct*)malloc(sizeof(ConditionalStruct)); - memset(Cond, 0, sizeof(ConditionalStruct)); - Cond->PlainName = Name; - Cond->Filter.nMaxArgs = nParams; - Cond->Filter.nMinArgs = nParams; - Cond->CondF = CondF; - Cond->Filter.ContextType = CTX_NONE; - Cond->Filter.ControlContextType = ControlContextRequired; Put(Conditionals, Name, len, Cond, NULL); } @@ -2150,11 +2167,11 @@ HashList *Defines; */ void tmplput_ContextString(StrBuf *Target, WCTemplputParams *TP) { - StrBufAppendTemplate(Target, TP, (StrBuf*)CTX, 0); + StrBufAppendTemplate(Target, TP, (StrBuf*)CTX(CTX_STRBUF), 0); } int ConditionalContextStr(StrBuf *Target, WCTemplputParams *TP) { - StrBuf *TokenText = (StrBuf*) CTX; + StrBuf *TokenText = (StrBuf*) CTX((CTX_STRBUF)); const char *CompareToken; long len; @@ -2164,7 +2181,7 @@ int ConditionalContextStr(StrBuf *Target, WCTemplputParams *TP) void tmplput_ContextStringArray(StrBuf *Target, WCTemplputParams *TP) { - HashList *Arr = (HashList*) CTX; + HashList *Arr = (HashList*) CTX(CTX_STRBUFARR); void *pV; int val; @@ -2176,7 +2193,7 @@ void tmplput_ContextStringArray(StrBuf *Target, WCTemplputParams *TP) } int ConditionalContextStrinArray(StrBuf *Target, WCTemplputParams *TP) { - HashList *Arr = (HashList*) CTX; + HashList *Arr = (HashList*) CTX(CTX_STRBUFARR); void *pV; int val; const char *CompareToken; @@ -2218,10 +2235,12 @@ void tmpl_do_boxed(StrBuf *Target, WCTemplputParams *TP) } } /* else TODO error? logging? */ - memcpy (&SubTP, TP, sizeof(WCTemplputParams)); - SubTP.Context = Headline; - SubTP.Filter.ContextType = CTX_STRBUF; - DoTemplate(HKEY("box_begin"), Target, &SubTP); + + StackContext (TP, &SubTP, Headline, CTX_STRBUF, 0, NULL); + { + DoTemplate(HKEY("box_begin"), Target, &SubTP); + } + UnStackContext(&SubTP); DoTemplate(TKEY(0), Target, TP); DoTemplate(HKEY("box_end"), Target, TP); FreeStrBuf(&Headline); @@ -2244,7 +2263,6 @@ int preeval_do_tabbed(WCTemplateToken *Token) long len; int i, nTabs; - memset(&TPP, 0, sizeof(WCTemplputParams)); TP = &TPP; TP->Tokens = Token; @@ -2307,7 +2325,6 @@ void tmpl_do_tabbed(StrBuf *Target, WCTemplputParams *TP) WCTemplputParams SubTP; memset(&TS, 0, sizeof(tab_struct)); - memcpy (&SubTP, &TP, sizeof(WCTemplputParams)); nTabs = ntabs = TP->Tokens->nParameters / 2; TabNames = (StrBuf **) malloc(ntabs * sizeof(StrBuf*)); @@ -2334,33 +2351,37 @@ void tmpl_do_tabbed(StrBuf *Target, WCTemplputParams *TP) nTabs --; } } - memcpy (&SubTP, TP, sizeof(WCTemplputParams)); - SubTP.Filter.ControlContextType = CTX_TAB; - SubTP.ControlContext = &TS; + StackContext (TP, &SubTP, &TS, CTX_TAB, 0, NULL); + { +//// TODO jetzt memcpy (&SubTP, TP, sizeof(WCTemplputParams)); +// SubTP.Filter.ControlContextType = ; - StrTabbedDialog(Target, nTabs, TabNames); - for (i = 0; i < ntabs; i++) { - memset(&TS, 0, sizeof(tab_struct)); - TS.CurrentTab = i; - TS.TabTitle = TabNames[i]; - StrBeginTab(Target, i, nTabs, TabNames); - DoTemplate(TKEY(i * 2 + 1), Target, &SubTP); - StrEndTab(Target, i, nTabs); + StrTabbedDialog(Target, nTabs, TabNames); + for (i = 0; i < ntabs; i++) { + memset(&TS, 0, sizeof(tab_struct)); + TS.CurrentTab = i; + TS.TabTitle = TabNames[i]; + StrBeginTab(Target, i, nTabs, TabNames); + DoTemplate(TKEY(i * 2 + 1), Target, &SubTP); + StrEndTab(Target, i, nTabs); + } + for (i = 0; i < ntabs; i++) + FreeStrBuf(&TabNames[i]); + free(TabNames); } - for (i = 0; i < ntabs; i++) - FreeStrBuf(&TabNames[i]); + UnStackContext(&SubTP); } void tmplput_TAB_N(StrBuf *Target, WCTemplputParams *TP) { - tab_struct *Ctx = CCTX; + tab_struct *Ctx = CTX(CTX_TAB); StrBufAppendPrintf(Target, "%d", Ctx->CurrentTab); } void tmplput_TAB_TITLE(StrBuf *Target, WCTemplputParams *TP) { - tab_struct *Ctx = CCTX; + tab_struct *Ctx = CTX(CTX_TAB); StrBufAppendTemplate(Target, TP, Ctx->TabTitle, 0); } @@ -2647,7 +2668,7 @@ void tmplput_SORT_ORDER(StrBuf *Target, WCTemplputParams *TP) void tmplput_long_vector(StrBuf *Target, WCTemplputParams *TP) { - long *LongVector = (long*) CTX; + long *LongVector = (long*) CTX(CTX_LONGVECTOR); if ((TP->Tokens->Params[0]->Type == TYPE_LONG) && (TP->Tokens->Params[0]->lvalue <= LongVector[0])) @@ -2690,7 +2711,7 @@ void dbg_print_longvector(long *LongVector) int ConditionalLongVector(StrBuf *Target, WCTemplputParams *TP) { - long *LongVector = (long*) CTX; + long *LongVector = (long*) CTX(CTX_LONGVECTOR); if ((TP->Tokens->Params[2]->Type == TYPE_LONG) && (TP->Tokens->Params[2]->lvalue <= LongVector[0])&& @@ -2740,8 +2761,8 @@ InitModule_SUBST RegisterNamespace("ITERATE", 2, 100, tmpl_iterate_subtmpl, preeval_iterate, CTX_NONE); RegisterNamespace("DOBOXED", 1, 2, tmpl_do_boxed, NULL, CTX_NONE); RegisterNamespace("DOTABBED", 2, 100, tmpl_do_tabbed, preeval_do_tabbed, CTX_NONE); - RegisterControlNS(HKEY("TAB:N"), 0, 0, tmplput_TAB_N, CTX_TAB); - RegisterControlNS(HKEY("TAB:SUBJECT"), 0, 1, tmplput_TAB_TITLE, CTX_TAB); + RegisterNamespace("TAB:N", 0, 0, tmplput_TAB_N, NULL, CTX_TAB); + RegisterNamespace("TAB:SUBJECT", 0, 1, tmplput_TAB_TITLE, NULL, CTX_TAB); RegisterNamespace("LONGVECTOR", 1, 1, tmplput_long_vector, NULL, CTX_LONGVECTOR); @@ -2752,19 +2773,19 @@ InitModule_SUBST RegisterConditional(HKEY("COND:LONGVECTOR"), 4, ConditionalLongVector, CTX_LONGVECTOR); - RegisterControlConditional(HKEY("COND:ITERATE:ISGROUPCHANGE"), 2, - conditional_ITERATE_ISGROUPCHANGE, - CTX_ITERATE); - RegisterControlConditional(HKEY("COND:ITERATE:LASTN"), 2, - conditional_ITERATE_LASTN, - CTX_ITERATE); - RegisterControlConditional(HKEY("COND:ITERATE:FIRSTN"), 2, - conditional_ITERATE_FIRSTN, - CTX_ITERATE); + RegisterConditional(HKEY("COND:ITERATE:ISGROUPCHANGE"), 2, + conditional_ITERATE_ISGROUPCHANGE, + CTX_ITERATE); + RegisterConditional(HKEY("COND:ITERATE:LASTN"), 2, + conditional_ITERATE_LASTN, + CTX_ITERATE); + RegisterConditional(HKEY("COND:ITERATE:FIRSTN"), 2, + conditional_ITERATE_FIRSTN, + CTX_ITERATE); - RegisterControlNS(HKEY("ITERATE:ODDEVEN"), 0, 0, tmplput_ITERATE_ODDEVEN, CTX_ITERATE); - RegisterControlNS(HKEY("ITERATE:KEY"), 0, 0, tmplput_ITERATE_KEY, CTX_ITERATE); - RegisterControlNS(HKEY("ITERATE:N"), 0, 0, tmplput_ITERATE_LASTN, CTX_ITERATE); + RegisterNamespace("ITERATE:ODDEVEN", 0, 0, tmplput_ITERATE_ODDEVEN, NULL, CTX_ITERATE); + RegisterNamespace("ITERATE:KEY", 0, 0, tmplput_ITERATE_KEY, NULL, CTX_ITERATE); + RegisterNamespace("ITERATE:N", 0, 0, tmplput_ITERATE_LASTN, NULL, CTX_ITERATE); RegisterNamespace("CURRENTFILE", 0, 1, tmplput_CURRENT_FILE, NULL, CTX_NONE); RegisterNamespace("DEF:STR", 1, 1, tmplput_DefStr, NULL, CTX_NONE); RegisterNamespace("DEF:VAL", 1, 1, tmplput_DefVal, NULL, CTX_NONE); diff --git a/webcit/subst.h b/webcit/subst.h index b44b33a52..f0aa90c24 100644 --- a/webcit/subst.h +++ b/webcit/subst.h @@ -35,9 +35,6 @@ enum { WCS_LONG /* its an integer */ }; -#define CTX TP->Context -#define CCTX TP->ControlContext - #define CTX_NONE 0 #define CTX_SITECFG 1 #define CTX_SESSION 2 @@ -78,7 +75,6 @@ enum { */ typedef struct _contexts { int ContextType; /* do we require a User Context ? */ - int ControlContextType; /* are we inside of a control structure? */ int nMinArgs; /* How many arguments do we need at least? */ int nMaxArgs; /* up to how many arguments can we handle? */ } ContextFilter; @@ -97,6 +93,9 @@ typedef int (*WCPreevalFunc)(WCTemplateToken *Token); /* make a template token a lookup key: */ #define TKEY(a) TP->Tokens->Params[a]->Start, TP->Tokens->Params[a]->len +void *GetContextPayload(WCTemplputParams *TP, int ContextType); +#define CTX(a) GetContextPayload(TP, a) + /** * @ingroup subst * this is the signature of a conditional function @@ -165,9 +164,9 @@ struct WCTemplateToken { struct WCTemplputParams { ContextFilter Filter; void *Context; - void *ControlContext; int nArgs; WCTemplateToken *Tokens; + WCTemplputParams *Sub, *Super; }; @@ -363,6 +362,14 @@ void RegisterITERATOR(const char *Name, long len, /* Our identifier */ +void StackContext(WCTemplputParams *Super, + WCTemplputParams *Sub, + void *Context, + int ContextType, + int nArgs, + WCTemplateToken *Tokens); + +void UnStackContext(WCTemplputParams *Sub); diff --git a/webcit/useredit.c b/webcit/useredit.c index 6b407827f..d728fb107 100644 --- a/webcit/useredit.c +++ b/webcit/useredit.c @@ -330,80 +330,80 @@ HashList *iterate_load_userlist(StrBuf *Target, WCTemplputParams *TP) void tmplput_USERLIST_UserName(StrBuf *Target, WCTemplputParams *TP) { - UserListEntry *ul = (UserListEntry*) CTX; + UserListEntry *ul = (UserListEntry*) CTX(CTX_USERLIST); StrBufAppendTemplate(Target, TP, ul->UserName, 0); } void tmplput_USERLIST_Password(StrBuf *Target, WCTemplputParams *TP) { - UserListEntry *ul = (UserListEntry*) CTX; + UserListEntry *ul = (UserListEntry*) CTX(CTX_USERLIST); StrBufAppendTemplate(Target, TP, ul->Passvoid, 0); } void tmplput_USERLIST_AccessLevelNo(StrBuf *Target, WCTemplputParams *TP) { - UserListEntry *ul = (UserListEntry*) CTX; + UserListEntry *ul = (UserListEntry*) CTX(CTX_USERLIST); StrBufAppendPrintf(Target, "%d", ul->AccessLevel, 0); } void tmplput_USERLIST_AccessLevelStr(StrBuf *Target, WCTemplputParams *TP) { - UserListEntry *ul = (UserListEntry*) CTX; + UserListEntry *ul = (UserListEntry*) CTX(CTX_USERLIST); StrBufAppendBufPlain(Target, _(axdefs[ul->AccessLevel]), -1, 0); } void tmplput_USERLIST_UID(StrBuf *Target, WCTemplputParams *TP) { - UserListEntry *ul = (UserListEntry*) CTX; + UserListEntry *ul = (UserListEntry*) CTX(CTX_USERLIST); StrBufAppendPrintf(Target, "%d", ul->UID, 0); } void tmplput_USERLIST_LastLogonNo(StrBuf *Target, WCTemplputParams *TP) { - UserListEntry *ul = (UserListEntry*) CTX; + UserListEntry *ul = (UserListEntry*) CTX(CTX_USERLIST); StrBufAppendPrintf(Target,"%ld", ul->LastLogonT, 0); } void tmplput_USERLIST_LastLogonStr(StrBuf *Target, WCTemplputParams *TP) { - UserListEntry *ul = (UserListEntry*) CTX; + UserListEntry *ul = (UserListEntry*) CTX(CTX_USERLIST); StrEscAppend(Target, NULL, asctime(localtime(&ul->LastLogonT)), 0, 0); } void tmplput_USERLIST_nLogons(StrBuf *Target, WCTemplputParams *TP) { - UserListEntry *ul = (UserListEntry*) CTX; + UserListEntry *ul = (UserListEntry*) CTX(CTX_USERLIST); StrBufAppendPrintf(Target, "%d", ul->nLogons, 0); } void tmplput_USERLIST_nPosts(StrBuf *Target, WCTemplputParams *TP) { - UserListEntry *ul = (UserListEntry*) CTX; + UserListEntry *ul = (UserListEntry*) CTX(CTX_USERLIST); StrBufAppendPrintf(Target, "%d", ul->nPosts, 0); } void tmplput_USERLIST_Flags(StrBuf *Target, WCTemplputParams *TP) { - UserListEntry *ul = (UserListEntry*) CTX; + UserListEntry *ul = (UserListEntry*) CTX(CTX_USERLIST); StrBufAppendPrintf(Target, "%d", ul->Flags, 0); } void tmplput_USERLIST_DaysTillPurge(StrBuf *Target, WCTemplputParams *TP) { - UserListEntry *ul = (UserListEntry*) CTX; + UserListEntry *ul = (UserListEntry*) CTX(CTX_USERLIST); StrBufAppendPrintf(Target, "%d", ul->DaysTillPurge, 0); } int ConditionalUser(StrBuf *Target, WCTemplputParams *TP) { - UserListEntry *ul = (UserListEntry*) CTX; + UserListEntry *ul = (UserListEntry*) CTX(CTX_USERLIST); if (havebstr("usernum")) { return ibstr("usernum") == ul->UID; } @@ -416,13 +416,13 @@ int ConditionalUser(StrBuf *Target, WCTemplputParams *TP) int ConditionalFlagINetEmail(StrBuf *Target, WCTemplputParams *TP) { - UserListEntry *ul = (UserListEntry*) CTX; + UserListEntry *ul = (UserListEntry*) CTX(CTX_USERLIST); return (ul->Flags & US_INTERNET) != 0; } int ConditionalUserAccess(StrBuf *Target, WCTemplputParams *TP) { - UserListEntry *ul = (UserListEntry*) CTX; + UserListEntry *ul = (UserListEntry*) CTX(CTX_USERLIST); if (ul == NULL) return 0; @@ -436,7 +436,7 @@ int ConditionalUserAccess(StrBuf *Target, WCTemplputParams *TP) } int ConditionalHaveBIO(StrBuf *Target, WCTemplputParams *TP) { - UserListEntry *ul = (UserListEntry*) CTX; + UserListEntry *ul = (UserListEntry*) CTX(CTX_USERLIST); if (ul == NULL) return 0; @@ -808,8 +808,6 @@ void showuser(void) do_template("user_show"); end_burst(); } - - void InitModule_USEREDIT (void) diff --git a/webcit/vcard_edit.c b/webcit/vcard_edit.c index d531098c6..38b799316 100644 --- a/webcit/vcard_edit.c +++ b/webcit/vcard_edit.c @@ -651,7 +651,7 @@ TODO: check for layer II void tmplput_VCARD_ITEM(StrBuf *Target, WCTemplputParams *TP) { - HashList *VC = CTX; + HashList *VC = CTX(CTX_VCARD); eVC evc; void *vStr; diff --git a/webcit/who.c b/webcit/who.c index 66667e758..ac30cc72d 100644 --- a/webcit/who.c +++ b/webcit/who.c @@ -214,83 +214,83 @@ void DeleteWholistHash(HashList **KillMe) void tmplput_who_username(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendTemplate(Target, TP, User->UserName, 0); } void tmplput_who_room(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendTemplate(Target, TP, User->Room, 0); } void tmplput_who_host(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendTemplate(Target, TP, User->Host, 0); } void tmplput_who_realroom(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendTemplate(Target, TP, User->RealRoom, 0); } int conditional_who_realroom(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); return StrLength(User->RealRoom) > 0; } void tmplput_who_realhost(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendTemplate(Target, TP, User->RealHost, 0); } int conditional_who_realhost(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); return StrLength(User->RealHost) > 0; } void tmplput_who_lastactive(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendPrintf(Target, "%d", User->LastActive); } void tmplput_who_idlesince(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendPrintf(Target, "%d", User->IdleSince); } void tmplput_who_session(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendPrintf(Target, "%d", User->Session); } int conditional_who_idle(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); return User->Idle; } int conditional_who_nsessions(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); return User->SessionCount; } void tmplput_who_nsessions(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendPrintf(Target, "%d", User->SessionCount); } int conditional_who_isme(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); return (User->Session == WC->ctdl_pid); } -- 2.30.2