* add contexttype, so the subst can precheck the context pointer for us, and bad...
authorWilfried Göesgens <willi@citadel.org>
Tue, 23 Sep 2008 21:43:29 +0000 (21:43 +0000)
committerWilfried Göesgens <willi@citadel.org>
Tue, 23 Sep 2008 21:43:29 +0000 (21:43 +0000)
* templatized vnote display

17 files changed:
webcit/auth.c
webcit/context_loop.c
webcit/gettext.c
webcit/iconbar.c
webcit/inetconf.c
webcit/mainmenu.c
webcit/netconf.c
webcit/notes.c
webcit/preferences.c
webcit/roomops.c
webcit/siteconfig.c
webcit/static/t/vnoteitem.html [new file with mode: 0644]
webcit/subst.c
webcit/summary.c
webcit/webcit.c
webcit/webcit.h
webcit/who.c

index 5b92c99bf458f7f249675da70ff43967dd0f5f82..2e58a710a0d053d5d5d249f26d90d69ee41c3b4c 100644 (file)
@@ -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 ;
 }
index f6dc44e8016c99abac208e95459209af2fca818d..1f0cf05e963c74dea87b103619cc6b92791fc031 100644 (file)
@@ -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);
 }
index 7e5caeb2f7129c9b7cd2218fd5afa55ba940a871..de380d6c84e1f951f870a942ea92b62d9c8c1c1c 100644 (file)
@@ -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");
index feb5b8421d9059e4a4ed88eda026f17573b82bb4..99350602b47902378fcbcb91a73a42729b677b96 100644 (file)
@@ -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);
 
 }
 
index 1f234a4f8866f2b46b8823f7906d7dbb4a5d3a21..cc04419c73031398e40094d87dec1c544a04d690 100644 (file)
@@ -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);
 }
index 5693329b01296d72b3d7ed96201a982ac4f81f05..d9337fda4cbb66a969a378666081fe2fc90fc9ee 100644 (file)
@@ -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();                    
        }
 }
index e152800f5bd7091315d465f3700e999126c0fa30..521c765a78ed0dadd892d9e8ea222d4476d9132a 100644 (file)
@@ -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);
 }
 /*@}*/
index 0775d9709d11e083adecdf2f993176beb47d8cd9..58e9bc8508de379f4bfa4ea40ee7e4aa216c8e6c 100644 (file)
@@ -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("<script type=\"text/javascript\">");
@@ -383,10 +386,82 @@ void add_new_note(void) {
        readloop("readfwd");
 }
 
+
+void tmpl_vcard_put_posleft(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       struct vnote *v = (struct vnote *) Context;
+       StrBufAppendPrintf(Target, "%d", v->pos_left);
+}
+
+void tmpl_vcard_put_postop(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       struct vnote *v = (struct vnote *) Context;
+       StrBufAppendPrintf(Target, "%d", v->pos_top);
+}
+
+void tmpl_vcard_put_poswidth(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       struct vnote *v = (struct vnote *) Context;
+       StrBufAppendPrintf(Target, "%d", v->pos_width);
+}
+
+void tmpl_vcard_put_posheight(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       struct vnote *v = (struct vnote *) Context;
+       StrBufAppendPrintf(Target, "%d", v->pos_height);
+}
+
+void tmpl_vcard_put_posheight2(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       struct vnote *v = (struct vnote *) Context;
+       StrBufAppendPrintf(Target, "%d", (v->pos_height / 16) - 5);
+}
+
+void tmpl_vcard_put_width2(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       struct vnote *v = (struct vnote *) Context;
+       StrBufAppendPrintf(Target, "%d", (v->pos_width / 9) - 1);
+}
+
+void tmpl_vcard_put_color(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       struct vnote *v = (struct vnote *) Context;
+       StrBufAppendPrintf(Target, "%02X%02X%02X", v->color_red, v->color_green, v->color_blue);
+}
+
+void tmpl_vcard_put_bgcolor(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       struct vnote *v = (struct vnote *) Context;
+       StrBufAppendPrintf(Target, "%02X%02X%02X", v->color_red/2, v->color_green/2, v->color_blue/2);
+}
+
+void tmpl_vcard_put_message(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       struct vnote *v = (struct vnote *) Context;
+       StrEscAppend(Target, NULL, v->body, 0, 0); ///TODO?
+}
+
+void tmpl_vcard_put_uid(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       struct vnote *v = (struct vnote *) Context;
+       StrBufAppendBufPlain(Target, v->uid, -1, 0);
+}
+
 void 
 InitModule_NOTES
 (void)
 {
        WebcitAddUrlHandler(HKEY("add_new_note"), add_new_note, 0);
        WebcitAddUrlHandler(HKEY("ajax_update_note"), ajax_update_note, 0);
+
+       RegisterNamespace("VNOTE:POS:LEFT", 0, 0, tmpl_vcard_put_posleft, CTX_VNOTE);
+       RegisterNamespace("VNOTE:POS:TOP", 0, 0, tmpl_vcard_put_postop, CTX_VNOTE);
+       RegisterNamespace("VNOTE:POS:WIDTH", 0, 0, tmpl_vcard_put_poswidth, CTX_VNOTE);
+       RegisterNamespace("VNOTE:POS:HEIGHT", 0, 0, tmpl_vcard_put_posheight, CTX_VNOTE);
+       RegisterNamespace("VNOTE:POS:HEIGHT2", 0, 0, tmpl_vcard_put_posheight2, CTX_VNOTE);
+       RegisterNamespace("VNOTE:POS:WIDTH2", 0, 0, tmpl_vcard_put_width2, CTX_VNOTE);
+       RegisterNamespace("VNOTE:COLOR", 0, 0, tmpl_vcard_put_color, CTX_VNOTE);
+       RegisterNamespace("VNOTE:BGCOLOR", 0, 0,tmpl_vcard_put_bgcolor, CTX_VNOTE);
+       RegisterNamespace("VNOTE:MSG", 0, 1, tmpl_vcard_put_message, CTX_VNOTE);
+       RegisterNamespace("VNOTE:UID", 0, 0, tmpl_vcard_put_uid, CTX_VNOTE);
 }
index 8d3b4f8dd586c54035ab8fe79677cb9362d702e1..8887f6fe5e9f37e10f05ab8b268a7db43014ff2b 100644 (file)
@@ -671,7 +671,7 @@ void set_preferences(void)
 #define PRF_YESNO 4
 
 
-void tmplput_CFG_Value(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context)
+void tmplput_CFG_Value(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
 {
        StrBuf *Setting;
        if (get_PREFERENCE(Token->Params[0]->Start,
@@ -680,7 +680,7 @@ void tmplput_CFG_Value(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *
                StrBufAppendBuf(Target, Setting, 0);
 }
 
-void tmplput_CFG_Descr(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context)
+void tmplput_CFG_Descr(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
 {
        const char *SettingStr;
        SettingStr = PrefGetLocalStr(Token->Params[0]->Start,
@@ -697,7 +697,7 @@ void CfgZoneTempl(StrBuf *TemplBuffer, void *vContext, WCTemplateToken *Token)
        SVPutBuf("ZONENAME", Zone, 1);
 }
 
-int ConditionalPreference(WCTemplateToken *Token, void *Context)
+int ConditionalPreference(WCTemplateToken *Token, void *Context, int ContextType)
 {
        StrBuf *Pref;
 
@@ -735,10 +735,10 @@ InitModule_PREFERENCES
        RegisterPreference("default_header_charset", _("Default character set for email headers:") ,PRF_STRING);
        RegisterPreference("emptyfloors", _("Show empty floors"), PRF_YESNO);
        
-       RegisterNamespace("PREF:VALUE", 1, 1, tmplput_CFG_Value);
-       RegisterNamespace("PREF:DESCR", 1, 1, tmplput_CFG_Descr);
-       RegisterIterator("PREF:ZONE", 0, ZoneHash, NULL, CfgZoneTempl, NULL);
+       RegisterNamespace("PREF:VALUE", 1, 1, tmplput_CFG_Value, CTX_SESSION);
+       RegisterNamespace("PREF:DESCR", 1, 1, tmplput_CFG_Descr, CTX_SESSION);
+       RegisterIterator("PREF:ZONE", 0, ZoneHash, NULL, CfgZoneTempl, NULL, CTX_PREF);
 
-       RegisterConditional(HKEY("COND:PREF"), 4, ConditionalPreference);
+       RegisterConditional(HKEY("COND:PREF"), 4, ConditionalPreference, CTX_NONE);
 }
 /*@}*/
index 7c291b4a9a36bcb09214c275c40feb27afe03388..c87f4af0a77893369b6e86ada6de36ee62eb0de5 100644 (file)
@@ -273,7 +273,7 @@ void zapped_list(void)
 /**
  * \brief read this room's info file (set v to 1 for verbose mode)
  */
-void readinfo(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context)
+void readinfo(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
 {
        char buf[256];
        char briefinfo[128];
@@ -322,7 +322,7 @@ void readinfo(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context)
  * keep the browser from using a cached icon from 
  * another room.
  */
-void embed_room_graphic(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context) {
+void embed_room_graphic(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) {
        char buf[SIZ];
 
        serv_puts("OIMG _roompic_");
@@ -378,7 +378,7 @@ void embed_room_graphic(StrBuf *Target, int nArgs, WCTemplateToken *Token, void
 /**
  * \brief Display the current view and offer an option to change it
  */
-void embed_view_o_matic(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context) {
+void embed_view_o_matic(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) {
        int i;
 
        wprintf("<form name=\"viewomatic\" action=\"changeview\">\n");
@@ -419,7 +419,7 @@ void embed_view_o_matic(StrBuf *Target, int nArgs, WCTemplateToken *Token, void
 /**
  * \brief Display a search box
  */
-void embed_search_o_matic(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context) {
+void embed_search_o_matic(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) {
        wprintf("<form name=\"searchomatic\" action=\"do_search\">\n");
        wprintf("<div style=\"display: inline;\"><input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
        wprintf("<label for=\"search_name\">");
@@ -3587,7 +3587,7 @@ void knrooms(void)
        /** offer the ability to switch views */
        wprintf("<ul class=\"room_actions\">\n");
        wprintf("<li class=\"start_page\">");
-       offer_start_page(NULL, 0, NULL, NULL);
+       offer_start_page(NULL, 0, NULL, NULL, CTX_NONE);
        wprintf("</li>");
        wprintf("<li><form name=\"roomlistomatic\">\n"
                "<select name=\"newview\" size=\"1\" "
@@ -3647,7 +3647,7 @@ void set_room_policy(void) {
 }
 
 
-void tmplput_RoomName(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context)
+void tmplput_RoomName(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        StrEscAppend(Target, NULL, WC->wc_roomname, 1, 1);
 }
@@ -3662,7 +3662,7 @@ void dotgoto(void) {
        smart_goto(bstr("room"));
 }
 
-void tmplput_roombanner(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context)
+void tmplput_roombanner(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        wprintf("<div id=\"banner\">\n");
        embed_room_banner(NULL, navbar_default);
@@ -3670,7 +3670,7 @@ void tmplput_roombanner(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
 }
 
 
-void tmplput_ungoto(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context)
+void tmplput_ungoto(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        struct wcsession *WCC = WC;
 
@@ -3680,7 +3680,7 @@ void tmplput_ungoto(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Co
 }
 
 
-int ConditionalHaveUngoto(WCTemplateToken *Tokens, void *Context)
+int ConditionalHaveUngoto(WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        struct wcsession *WCC = WC;
        
@@ -3689,7 +3689,7 @@ int ConditionalHaveUngoto(WCTemplateToken *Tokens, void *Context)
                (strcasecmp(WCC->ugname, WCC->wc_roomname) == 0));
 }
 
-int ConditinalRoomHasQRVisidir(WCTemplateToken *Tokens, void *Context)
+int ConditionalRoomHasQRVisidir(WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        struct wcsession *WCC = WC;
        
@@ -3697,7 +3697,7 @@ int ConditinalRoomHasQRVisidir(WCTemplateToken *Tokens, void *Context)
                ((WCC->room_flags & QR_VISDIR) != 0));
 }
 
-int ConditionalHaveRoomeditRights(WCTemplateToken *Tokens, void *Context)
+int ConditionalHaveRoomeditRights(WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        struct wcsession *WCC = WC;
 
@@ -3711,7 +3711,7 @@ void
 InitModule_ROOMOPS
 (void)
 {
-       RegisterNamespace("ROOMNAME", 0, 0, tmplput_RoomName);
+       RegisterNamespace("ROOMNAME", 0, 0, tmplput_RoomName, 0);
 
        WebcitAddUrlHandler(HKEY("knrooms"), knrooms, 0);
        WebcitAddUrlHandler(HKEY("gotonext"), _gotonext, 0);
@@ -3735,12 +3735,12 @@ InitModule_ROOMOPS
        WebcitAddUrlHandler(HKEY("set_room_policy"), set_room_policy, 0);
        WebcitAddUrlHandler(HKEY("set_floordiv_expanded"), set_floordiv_expanded, NEED_URL|AJAX);
        WebcitAddUrlHandler(HKEY("changeview"), change_view, 0);
-       RegisterNamespace("ROOMBANNER", 0, 0, tmplput_roombanner);
-       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_VISIDIR"), 0, ConditinalRoomHasQRVisidir);
-       RegisterConditional(HKEY("COND:UNGOTO"), 0, ConditionalHaveUngoto);
-       RegisterConditional(HKEY("COND:ROOM:EDITACCESS"), 0, ConditionalHaveRoomeditRights);
+       RegisterNamespace("ROOMBANNER", 0, 0, tmplput_roombanner, 0);
+       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_VISIDIR"), 0, ConditionalRoomHasQRVisidir, CTX_NONE);
+       RegisterConditional(HKEY("COND:UNGOTO"), 0, ConditionalHaveUngoto, CTX_NONE);
+       RegisterConditional(HKEY("COND:ROOM:EDITACCESS"), 0, ConditionalHaveRoomeditRights, CTX_NONE);
 
-       RegisterNamespace("ROOM:UNGOTO", 0, 0, tmplput_ungoto);
+       RegisterNamespace("ROOM:UNGOTO", 0, 0, tmplput_ungoto, 0);
 }
 
 /*@}*/
index 00ebd60cdaf8f035bf0c3d321f9916aa40c247b4..1a760033570b3befe85ae9801ed1243e8439d553 100644 (file)
@@ -986,7 +986,7 @@ void siteconfig(void)
        display_aide_menu();
 }
 
-void tmplput_servcfg(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context)
+void tmplput_servcfg(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        struct wcsession *WCC = WC;
        void *vBuf;
@@ -1004,7 +1004,7 @@ void tmplput_servcfg(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *C
        }
 }
 
-int ConditionalServCfg(WCTemplateToken *Tokens, void *Context)
+int ConditionalServCfg(WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        struct wcsession *WCC = WC;
        void *vBuf;
@@ -1029,7 +1029,7 @@ int ConditionalServCfg(WCTemplateToken *Tokens, void *Context)
        else return 0;
 }
 
-int ConditionalServCfgSubst(WCTemplateToken *Tokens, void *Context)
+int ConditionalServCfgSubst(WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        struct wcsession *WCC = WC;
        void *vBuf;
@@ -1054,11 +1054,11 @@ void
 InitModule_SITECONFIG
 (void)
 {
-       WebcitAddUrlHandler(HKEY("display_siteconfig"), display_siteconfig, 0);
-       WebcitAddUrlHandler(HKEY("siteconfig"), siteconfig, 0);
+       WebcitAddUrlHandler(HKEY("display_siteconfig"), display_siteconfig, CTX_NONE);
+       WebcitAddUrlHandler(HKEY("siteconfig"), siteconfig, CTX_NONE);
 
-       RegisterNamespace("SERV:CFG", 1, 1, tmplput_servcfg);
-       RegisterConditional(HKEY("COND:SERVCFG"), 3, ConditionalServCfg);
-       RegisterConditional(HKEY("COND:SERVCFG:SUBST"), 4, ConditionalServCfgSubst);
+       RegisterNamespace("SERV:CFG", 1, 1, tmplput_servcfg, CTX_SITECFG);
+       RegisterConditional(HKEY("COND:SERVCFG"), 3, ConditionalServCfg, CTX_NONE);
+       RegisterConditional(HKEY("COND:SERVCFG:SUBST"), 4, ConditionalServCfgSubst, CTX_NONE);
 }
 /*@}*/
diff --git a/webcit/static/t/vnoteitem.html b/webcit/static/t/vnoteitem.html
new file mode 100644 (file)
index 0000000..c44a60d
--- /dev/null
@@ -0,0 +1,66 @@
+
+
+<div id="note-<?VNOTE:UID>"
+ class="stickynote_outer"
+ style=" left: <?VNOTE:POS:LEFT>px; top: <?VNOTE:POS:TOP>px; width: <?VNOTE:POS:WIDTH>px; height: <?VNOTE:POS:HEIGHT>px; background-color: #<?VNOTE:COLOR>">
+<!--begin title bar div-->
+<div id='titlebar-<?VNOTE:UID>'
+ class="stickynote_titlebar"
+ onMouseDown="NotesDragMouseDown(event,'<?VNOTE:UID>')"
+ style=" background-color: #<?VNOTE:BGCOLOR>"
+>
+<table border=0 cellpadding=0 cellspacing=0 valign=middle width=100%%><tr>
+<td align=left valign=middle>
+<img onclick="NotesClickPalette(event,'<?VNOTE:UID>')" src="static/8paint16.gif">
+</td>
+<td></td><!-- nothing in the title bar, it's just for dragging-->
+<td align=right valign=middle>
+ <img onclick="DeleteStickyNote(event,'<?VNOTE:UID>','<?_("Delete this note?")>')"
+  src="static/closewindow.gif">
+</td></tr></table>
+</div>
+<!--end title bar div; begin body div-->
+<div id="notebody-<?VNOTE:UID>"        class="stickynote_body">
+  <?VNOTE:MSG("X")>
+</div>
+<!--end body div-->
+<script type="text/javascript">
+  new Ajax.InPlaceEditor('notebody-<?VNOTE:UID>', 'ajax_update_note?note_uid=<?VNOTE:UID>',
+{
+ rows:<?VNOTE:POS:HEIGHT2>,
+ cols:<?VNOTE:POS:WIDTH2>,
+ onEnterHover:false,
+ onLeaveHover:false,
+ okText:'<?_("Save")>',
+ cancelText:'<?_("Cancel")>',
+ clickToEditText:'<?_("Click on any note to edit it.")>'
+});
+</script>
+<div id="resize-<?VNOTE:UID>" 
+     class="stickynote_resize" onMouseDown="NotesResizeMouseDown(event,'<?VNOTE:UID>')"> </div>
+
+<div id="palette-<?VNOTE:UID>" class="stickynote_palette">
+  <table border=0 cellpadding=0 cellspacing=0>
+    <tr>
+      <td onClick="NotesClickColor(event,'<?VNOTE:UID>',128,128,128,'#808080','#404040')" bgcolor="#808080"> </td>
+      <td onClick="NotesClickColor(event,'<?VNOTE:UID>',255,128,128,'#ff8080','#7f4040')" bgcolor="#ff8080"> </td>
+      <td onClick="NotesClickColor(event,'<?VNOTE:UID>',128,128,255,'#8080ff','#40407f')" bgcolor="#8080ff"> </td>
+    </tr><tr>
+      <td onClick="NotesClickColor(event,'<?VNOTE:UID>',255,255,128,'#ffff80','#7f7f40')" bgcolor="#ffff80"> </td>
+      <td onClick="NotesClickColor(event,'<?VNOTE:UID>',128,255,128,'#80ff80','#407f40')" bgcolor="#80ff80"> </td>
+      <td onClick="NotesClickColor(event,'<?VNOTE:UID>',255,128,255,'#ff80ff','#7f407f')" bgcolor="#ff80ff"> </td>
+    </tr><tr>
+      <td onClick="NotesClickColor(event,'<?VNOTE:UID>',128,255,255,'#80ffff','#407f7f')" bgcolor="#80ffff"> </td>
+      <td onClick="NotesClickColor(event,'<?VNOTE:UID>',255,128,128,'#ff8080','#7f4040')" bgcolor="#ff8080"> </td>
+      <td onClick="NotesClickColor(event,'<?VNOTE:UID>',128,128,128,'#808080','#404040')" bgcolor="#808080"> </td>
+    </tr>
+  </table>
+</div></div>
+
+<div id="resize-<?VNOTE:UID>"
+ class="stickynote_resize"
+ onMouseDown="NotesResizeMouseDown(event,'<?VNOTE:UID>')">
+</div>
+<!--end resize handle div-->
+
+
index adee900ba3ddbdfce7b74d5e5311e593a62c17e4..2d9b27086d3e65bf76524c6829cb150c95209789 100644 (file)
@@ -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, 
+                               "<pre>\nHandler [%s] (in '%s' line %ld);"
+                               " requires context of type %ld, have %ld!\n[%s]\n</pre>\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, 
+                                       "<pre>\nHandler [%s] (in '%s' line %ld);"
+                                       " requires context of type %ld, have %ld!\n[%s]\n</pre>\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)
                                "<pre>\nError loading Template [%s]\n See Logfile for details\n</pre>\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);
 }
 
 /*@}*/
index 00a52096dddc9e4e1cf9f99ddd8aa97617c1bae0..2752cbd3a752a0e5cccc0fd8a384558a16f830dc 100644 (file)
@@ -259,7 +259,7 @@ void summary(void) {
         wprintf("</h2></div>");
        wprintf("<ul class=\"room_actions\">\n");
        wprintf("<li class=\"start_page\">");
-       offer_start_page(NULL, 0, NULL, NULL);
+       offer_start_page(NULL, 0, NULL, NULL, CTX_NONE);
         wprintf("</li></ul>");
         wprintf("</div>");
 
index b52c1a13d79f1d09726975cbcbe3f9713bfc7250..ed2eefc54bb4670794e31eb0a197948d4b8f32d8 100644 (file)
@@ -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("<a href=\"change_start_page?startpage=");
        urlescputs(WC->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);
 }
index ebf48cdcd3852701b4ee334d3d040c8af7c2f6b8..ebb565fc8cb91288dbd3b918e30a9ce95d553362 100644 (file)
@@ -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);
index 0cc06bc8adeead255652e3b6481d37f5e6a7ebac..02f3630e90e716aa982ecd07950fecfa762a26a3 100644 (file)
@@ -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);
 }