* new template callback: ITERATE("iterator", "subtemplate",...); its to iterate over registered hashlists
* new RegisterIterator() call; use this to register your hashlist with the ITERATE functionality
char buf[256];
long len;
char *Name;
+ const char *VCName;
void *Namee;
StrBuf *DefAddrBook;
HashList *List;
SortByHashKey(List, 1);
it = GetNewHashPos();
- while (GetNextHashPos(List, it, &len, &Name, &Namee)) {
+ while (GetNextHashPos(List, it, &len, &VCName, &Namee)) {
wprintf("<option value=\"");
urlescputs((char*)Namee);
if (strcmp(ChrPtr(DefAddrBook), Namee) == 0)
char target_label[64];
long len;
char *Name;
+ const char *VCName;
void *Namee;
HashList *List;
HashPos *it;
}
SortByHashKey(List, 1);
it = GetNewHashPos();
- while (GetNextHashPos(List, it, &len, &Name, &Namee)) {
+ while (GetNextHashPos(List, it, &len, &VCName, &Namee)) {
wprintf("<option value=\"");
escputs((char*)Namee);
wprintf("\">");
}
SortByHashKey(List, 1);
it = GetNewHashPos();
- while (GetNextHashPos(List, it, &len, &Name, (void**)&Namee)) {
+ while (GetNextHashPos(List, it, &len, &VCName, (void**)&Namee)) {
wprintf("<option value=\"");
escputs((char*)Namee);
wprintf("\">");
urlcontent *u;
void *U;
long HKLen;
- char *HKey;
+ const char *HKey;
HashPos *Cursor;
Cursor = GetNewHashPos ();
void calendar_month_view_display_events(int year, int month, int day)
{
long hklen;
- char *HashKey;
+ const char *HashKey;
void *vCal;
HashPos *Pos;
disp_cal *Cal;
*/
void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
long hklen;
- char *HashKey;
+ const char *HashKey;
void *vCal;
HashPos *Pos;
time_t event_tt;
int dend)
{
long hklen;
- char *HashKey;
+ const char *HashKey;
void *vCal;
HashPos *Pos;
icalproperty *p = NULL;
*/
void calendar_summary_view(void) {
long hklen;
- char *HashKey;
+ const char *HashKey;
void *vCal;
HashPos *Pos;
disp_cal *Cal;
*/
void do_tasks_view(void) {
long hklen;
- char *HashKey;
+ const char *HashKey;
void *vCal;
disp_cal *Cal;
HashPos *Pos;
HashPos *HashPos;
HashList *Hash;
void *Value;
- char *Key;
+ const char *Key;
StrBuf *Buf;
StrBuf *SubBuf = NULL;
RegisterPreference("default_header_charset", _("Default character set for email headers:") ,PRF_STRING);
RegisterPreference("emptyfloors", _("Show empty floors"), PRF_YESNO);
- RegisterNS(HKEY("PREF:VALUE"), 1, 1, tmplput_CFG_Value);
- RegisterNS(HKEY("PREF:DESCR"), 1, 1, tmplput_CFG_Descr);
+ RegisterNamespace("PREF:VALUE", 1, 1, tmplput_CFG_Value);
+ RegisterNamespace("PREF:DESCR", 1, 1, tmplput_CFG_Descr);
}
/*@}*/
char buf[SIZ];
int i, j;
struct wcsession *WCC = WC;
+ const char *VCZname;
char general[65536];
char access[SIZ];
}
SortByHashKey(List, 0);
it = GetNewHashPos();
- while (GetNextHashPos(List, it, &len, &ZName, &ZNamee)) {
+ while (GetNextHashPos(List, it, &len, &VCZname, &ZNamee)) {
sprintf(&general[strlen(general)], "<option %s value=\"%s\">%s</option>\n",
(!strcasecmp((char*)ZName, buf) ? "selected" : ""),
ZName, ZName
HashList *LocalTemplateCache;
HashList *GlobalNS;
+HashList *Iterators;
typedef struct _WCTemplate {
StrBuf *Data;
/*if (WCC->vars != NULL) PrintHash(WCC->vars, VarPrintTransition, VarPrintEntry);*/
if (keyname[0] == '=') {
- DoTemplate(keyname+1, keylen - 1, NULL);
+ DoTemplate(keyname+1, keylen - 1, NULL, NULL);
}
/** Page-local variables */
if ((WCC->vars!= NULL) && GetHash(WCC->vars, keyname, keylen, &vVar)) {
* \brief Display a variable-substituted template
* \param templatename template file to load
*/
-void DoTemplate(const char *templatename, long len, void *Context)
+void DoTemplate(const char *templatename, long len, void *Context, StrBuf *Target)
{
HashList *Static;
HashList *StaticLocal;
escputs(WC->wc_roomname);////TODO: respcect Target
}
+
+typedef struct _HashIterator {
+ HashList *StaticList;
+ RetrieveHashlistFunc GetHash;
+ HashDestructorFunc Destructor;
+ SubTemplFunc DoSubTemplate;
+} HashIterator;
+
+void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context)
+{
+ void *vIt;
+ HashIterator *It;
+ HashList *List;
+ HashPos *it;
+ long len;
+ const char *Key;
+ void *vContext;
+ StrBuf *SubBuf;
+
+ if (!GetHash(Iterators,
+ Tokens->Params[0]->Start,
+ Tokens->Params[0]->len,
+ &vIt))
+ return;
+ It = (HashIterator*) vIt;
+ if (It->StaticList == NULL)
+ List = It->GetHash();
+ else
+ List = It->StaticList;
+
+ SubBuf = NewStrBuf();
+ it = GetNewHashPos();
+ while (GetNextHashPos(List, it, &len, &Key, &vContext)) {
+ It->DoSubTemplate(SubBuf, vContext);
+ DoTemplate(Tokens->Params[0]->Start,
+ Tokens->Params[0]->len,
+ vContext, SubBuf);
+
+ StrBufAppendBuf(Target, SubBuf, 0);
+ FlushStrBuf(SubBuf);
+ }
+ DeleteHashPos(&it);
+ It->Destructor(List);
+}
+
+
+void RegisterITERATOR(const char *Name, long len,
+ HashList *StaticList,
+ RetrieveHashlistFunc GetHash,
+ SubTemplFunc DoSubTempl,
+ HashDestructorFunc Destructor)
+{
+ HashIterator *It = (HashIterator*)malloc(sizeof(HashIterator));
+ It->StaticList = StaticList;
+ It->GetHash = GetHash;
+ It->DoSubTemplate = DoSubTempl;
+ It->Destructor = Destructor;
+ Put(Iterators, Name, len, It, NULL);
+}
+
void
InitModule_SUBST
(void)
{
- RegisterNS(HKEY("SERV_PID"), 0, 0, tmplput_serv_ip);
- RegisterNS(HKEY("SERV_NODENAME"), 0, 0, tmplput_serv_nodename);
- RegisterNS(HKEY("SERV_HUMANNODE"), 0, 0, tmplput_serv_humannode);
- RegisterNS(HKEY("SERV_FQDN"), 0, 0, tmplput_serv_fqdn);
- RegisterNS(HKEY("SERV_SOFTWARE"), 0, 0, tmmplput_serv_software);
- RegisterNS(HKEY("SERV_REV_LEVEL"), 0, 0, tmplput_serv_rev_level);
- RegisterNS(HKEY("SERV_BBS_CITY"), 0, 0, tmmplput_serv_bbs_city);
- RegisterNS(HKEY("CURRENT_USER"), 0, 0, tmplput_current_user);
- RegisterNS(HKEY("CURRENT_ROOM"), 0, 0, tmplput_current_room);
+ 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("CURRENT_USER", 0, 0, tmplput_current_user);
+ RegisterNamespace("CURRENT_ROOM", 0, 0, tmplput_current_room);
+ RegisterNamespace("ITERATE", 2, 4, tmpl_iterate_subtmpl);
}
/*@}*/
urlcontent *u;
void *U;
long HKLen;
- char *HKey;
+ const char *HKey;
HashPos *Cursor;
Cursor = GetNewHashPos ();
} WCTemplateToken;
typedef void (*WCHandlerFunc)(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context);
+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)
+
+
+typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, void *Context);
+typedef HashList *(*RetrieveHashlistFunc)(void);
+typedef void (*HashDestructorFunc) (HashList *KillMe);
+void RegisterITERATOR(const char *Name, long len,
+ HashList *StaticList,
+ RetrieveHashlistFunc GetHash,
+ SubTemplFunc DoSubTempl,
+ HashDestructorFunc Destructor);
+#define RegisterIterator(a, b, c, d) RegisterITERATOR(a, sizeof(a)-1, b, c, d)
-void RegisterNS(const char *NSName, long len, int nMinArgs, int nMaxArgs, WCHandlerFunc HandlerFunc);
/**
* \brief Values for wcs_type
extern HashList *TemplateCache;
extern HashList *LocalTemplateCache;
extern HashList *GlobalNS;
+extern HashList *Iterators;
void InitialiseSemaphores(void);
void begin_critical_section(int which_one);
void SVCallback(char *keyname, size_t keylen, var_callback_fptr fcn_ptr);
#define svcallback(a, b) SVCallback(a, sizeof(a) - 1, b)
-void DoTemplate(const char *templatename, long len, void *Context);
-#define do_template(a, b) DoTemplate(a, sizeof(a) -1, b);
+void DoTemplate(const char *templatename, long len, void *Context, StrBuf *Target);
+#define do_template(a, b) DoTemplate(a, sizeof(a) -1, b, NULL);
int lingering_close(int fd);
LocalTemplateCache = NewHash(1, NULL);
TemplateCache = NewHash(1, NULL);
GlobalNS = NewHash(1, NULL);
+ Iterators = NewHash(1, NULL);
#ifdef DBG_PRINNT_HOOKS_AT_START
DeleteHash(&WirelessLocalTemplateCache);
DeleteHash(&TemplateCache);
DeleteHash(&LocalTemplateCache);
+ DeleteHash(&Iterators);
#ifdef ENABLE_NLS
void ShutdownLocale(void);
#endif
struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
HashList *List;
HashPos *it;
- char *UserName;
+ const char *UserName;
long len;
time_t now;
int bg = 0;
void *VUser;
HashList *List;
HashPos *it;
- char *UserName;
+ const char *UserName;
long len;
char buf[SIZ];
time_t now;