Back to index

webcit  8.12-dfsg
Classes | Defines | Typedefs | Enumerations | Functions | Variables
subst.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _contexts
 ContextFilter resembles our RTTI information. More...
struct  _TemplateParam
struct  WCTemplateToken
 Representation of a token; everything thats inbetween <? and > More...
struct  WCTemplputParams
struct  _ConditionalStruct

Defines

#define TYPE_STR   1
#define TYPE_LONG   2
#define TYPE_PREFSTR   3
#define TYPE_PREFINT   4
#define TYPE_GETTEXT   5
#define TYPE_BSTR   6
#define TYPE_SUBTEMPLATE   7
#define TYPE_INTDEFINE   8
#define MAXPARAM   25
#define IS_NUMBER(a)   ((a == TYPE_LONG) || (a == TYPE_PREFINT) || (a == TYPE_INTDEFINE))
#define CTX   TP->Context
#define CCTX   TP->ControlContext
#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
#define CTX_USERLIST   8
#define CTX_MAILSUM   9
#define CTX_MIME_ATACH   10
#define CTX_FILELIST   11
#define CTX_STRBUF   12
#define CTX_STRBUFARR   13
#define CTX_LONGVECTOR   14
#define CTX_ROOMS   15
#define CTX_FLOORS   16
#define CTX_ITERATE   17
#define CTX_ICAL   18
#define CTX_DAVNS   19
#define CTX_TAB   20
#define CTX_VCARD   21
#define CTX_SIEVELIST   22
#define CTX_SIEVESCRIPT   23
#define CTX_MAILQITEM   24
#define CTX_MAILQ_RCPT   25
#define CTX_SRVLOG   26
#define CTX_UNKNOWN   27
#define TKEY(a)   TP->Tokens->Params[a]->Start, TP->Tokens->Params[a]->len
#define HAVE_PARAM(a)   (TP->Tokens->nParameters > a)
#define ERR_NAME   0
#define ERR_PARM1   1
#define ERR_PARM2   2
#define RegisterNamespace(a, b, c, d, e, f)   RegisterNS(a, sizeof(a)-1, b, c, d, e, f)
#define REGISTERTokenParamDefine(a)   RegisterTokenParamDefine(#a, sizeof(#a) - 1, a);
 teh r0x0r! forward your favourite define from C to the templates with one easy call!
#define IT_NOFLAG   0
#define IT_FLAG_DETECT_GROUPCHANGE   (1<<0)
#define RegisterIterator(a, b, c, d, e, f, g, h, i)   RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i)
#define do_template(a)   DoTemplate(a, sizeof(a) -1, NULL, &NoCtx)

Typedefs

typedef struct _contexts ContextFilter
 ContextFilter resembles our RTTI information.
typedef struct WCTemplateToken
typedef struct WCTemplputParams
typedef void(* WCHandlerFunc )(StrBuf *Target, WCTemplputParams *TP)
typedef int(* WCPreevalFunc )(WCTemplateToken *Token)
typedef int(* WCConditionalFunc )(StrBuf *Target, WCTemplputParams *TP)
 this is the signature of a conditional function Note: Target is just passed in for error messages; don't write onto it in regular cases.
typedef enum _eBitMask eBitMask
typedef struct _TemplateParam TemplateParam
typedef struct _ConditionalStruct ConditionalStruct
typedef void(* SubTemplFunc )(StrBuf *TemplBuffer, WCTemplputParams *TP)
typedef HashList *(* RetrieveHashlistFunc )(StrBuf *Target, WCTemplputParams *TP)
typedef void(* HashDestructorFunc )(HashList **KillMe)

Enumerations

enum  {
  WCS_STRING, WCS_FUNCTION, WCS_SERVCMD, WCS_STRBUF,
  WCS_STRBUF_REF, WCS_LONG
}
enum  _eBitMask { eNO = 0, eOR, eAND }

Functions

void LogTemplateError (StrBuf *Target, const char *Type, int ErrorPos, WCTemplputParams *TP, const char *Format,...) __attribute__((__format__(__printf__
 log an error while evaluating a token; print it to the actual template
void void LogError (StrBuf *Target, const char *Type, const char *Format,...)
 log an error while in global context; print it to Wildfire / Target
void GetTemplateTokenString (StrBuf *Target, WCTemplputParams *TP, int N, const char **Value, long *len)
 get the actual value of a token parameter in your tmplputs or conditionals use this function to access parameters that can also be retrieved from dynamic facilities: _ -> Gettext; retrieve this token from the i18n facilities : -> lookup a setting of that name B -> bstr; an URL-Parameter = -> subtemplate; parse a template by this name, and treat its content as this tokens value
int HaveTemplateTokenString (StrBuf *Target, WCTemplputParams *TP, int N, const char **Value, long *len)
long GetTemplateTokenNumber (StrBuf *Target, WCTemplputParams *TP, int N, long dflt)
 get the actual integer value of a token parameter in your tmplputs or conditionals use this function to access parameters that can also be retrieved from dynamic facilities: _ -> Gettext; retrieve this token from the i18n facilities : -> lookup a setting of that name B -> bstr; an URL-Parameter = -> subtemplate; parse a template by this name, and treat its content as this tokens value
void StrBufAppendTemplate (StrBuf *Target, WCTemplputParams *TP, const StrBuf *Source, int FormatTypeIndex)
 put a token value into the template use this function to append your strings into a Template.
void RegisterNS (const char *NSName, long len, int nMinArgs, int nMaxArgs, WCHandlerFunc HandlerFunc, WCPreevalFunc PreEvalFunc, int ContextRequired)
 register a template token handler call this function in your InitModule_MODULENAME which will be called at the server start
void RegisterConditional (const char *Name, long len, int nParams, WCConditionalFunc CondF, int ContextRequired)
 register a conditional token <pair> handler call this function in your InitModule_MODULENAME which will be called at the server start conditionals can be ? or ! with a pair or % similar to an implicit if
void RegisterTokenParamDefine (const char *Name, long len, long Value)
 register a string that will represent a long value this will allow to resolve <?...(#"Name")> to Value; that way plain strings can be used an lexed in templates without having the lookup overhead at runtime.
long GetTokenDefine (const char *Name, long len, long DefValue)
 retrieve the long value of a registered string define
void RegisterITERATOR (const char *Name, long len, int AdditionalParams, HashList *StaticList, RetrieveHashlistFunc GetHash, SubTemplFunc DoSubTempl, HashDestructorFunc Destructor, int ContextType, int XPectContextType, int Flags)
CompareFunc RetrieveSort (WCTemplputParams *TP, const char *OtherPrefix, long OtherPrefixLen, const char *Default, long ldefault, long DefaultDirection)
void RegisterSortFunc (const char *name, long len, const char *prepend, long preplen, CompareFunc Forward, CompareFunc Reverse, CompareFunc GroupChange, long ContextType)
void dbg_print_longvector (long *LongVector)
const StrBuf * DoTemplate (const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP)
 Display a variable-substituted template.
void url_do_template (void)
int CompareSubstToToken (TemplateParam *ParamToCompare, TemplateParam *ParamToLookup)
int CompareSubstToStrBuf (StrBuf *Compare, TemplateParam *ParamToLookup)

Variables

HashList * Conditionals
HashList * GlobalNS
HashList * Iterators
HashList * WirelessTemplateCache
HashList * WirelessLocalTemplateCache
HashList * TemplateCache
HashList * LocalTemplateCache
WCTemplputParams NoCtx

Class Documentation

struct _TemplateParam

Definition at line 113 of file subst.h.

Class Members
long len
long lvalue
eBitMask MaskBy
const char * Start
int Type
struct WCTemplputParams

Definition at line 165 of file subst.h.

Collaboration diagram for WCTemplputParams:
Class Members
void * Context
void * ControlContext
ContextFilter Filter
int nArgs
WCTemplateToken * Tokens
struct _ConditionalStruct

Definition at line 175 of file subst.h.

Collaboration diagram for _ConditionalStruct:
Class Members
WCConditionalFunc CondF
ContextFilter Filter
const char * PlainName

Define Documentation

#define CCTX   TP->ControlContext

Definition at line 39 of file subst.h.

#define CTX   TP->Context

Definition at line 38 of file subst.h.

#define CTX_DAVNS   19

Definition at line 60 of file subst.h.

#define CTX_FILELIST   11

Definition at line 52 of file subst.h.

#define CTX_FLOORS   16

Definition at line 57 of file subst.h.

#define CTX_ICAL   18

Definition at line 59 of file subst.h.

#define CTX_INETCFG   3

Definition at line 44 of file subst.h.

#define CTX_ITERATE   17

Definition at line 58 of file subst.h.

#define CTX_LONGVECTOR   14

Definition at line 55 of file subst.h.

#define CTX_MAILQ_RCPT   25

Definition at line 66 of file subst.h.

#define CTX_MAILQITEM   24

Definition at line 65 of file subst.h.

#define CTX_MAILSUM   9

Definition at line 50 of file subst.h.

#define CTX_MIME_ATACH   10

Definition at line 51 of file subst.h.

#define CTX_NODECONF   7

Definition at line 48 of file subst.h.

#define CTX_NONE   0

Definition at line 41 of file subst.h.

#define CTX_PREF   6

Definition at line 47 of file subst.h.

#define CTX_ROOMS   15

Definition at line 56 of file subst.h.

#define CTX_SESSION   2

Definition at line 43 of file subst.h.

#define CTX_SIEVELIST   22

Definition at line 63 of file subst.h.

#define CTX_SIEVESCRIPT   23

Definition at line 64 of file subst.h.

#define CTX_SITECFG   1

Definition at line 42 of file subst.h.

#define CTX_SRVLOG   26

Definition at line 67 of file subst.h.

#define CTX_STRBUF   12

Definition at line 53 of file subst.h.

#define CTX_STRBUFARR   13

Definition at line 54 of file subst.h.

#define CTX_TAB   20

Definition at line 61 of file subst.h.

#define CTX_UNKNOWN   27

Definition at line 69 of file subst.h.

#define CTX_USERLIST   8

Definition at line 49 of file subst.h.

#define CTX_VCARD   21

Definition at line 62 of file subst.h.

#define CTX_VNOTE   4

Definition at line 45 of file subst.h.

#define CTX_WHO   5

Definition at line 46 of file subst.h.

#define do_template (   a)    DoTemplate(a, sizeof(a) -1, NULL, &NoCtx)

Definition at line 382 of file subst.h.

#define ERR_NAME   0

Definition at line 192 of file subst.h.

#define ERR_PARM1   1

Definition at line 193 of file subst.h.

#define ERR_PARM2   2

Definition at line 194 of file subst.h.

#define HAVE_PARAM (   a)    (TP->Tokens->nParameters > a)

Definition at line 189 of file subst.h.

#define IS_NUMBER (   a)    ((a == TYPE_LONG) || (a == TYPE_PREFINT) || (a == TYPE_INTDEFINE))

Definition at line 24 of file subst.h.

#define IT_FLAG_DETECT_GROUPCHANGE   (1<<0)

Definition at line 352 of file subst.h.

#define IT_NOFLAG   0

Definition at line 351 of file subst.h.

#define MAXPARAM   25

Definition at line 22 of file subst.h.

#define RegisterIterator (   a,
  b,
  c,
  d,
  e,
  f,
  g,
  h,
 
)    RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i)

Definition at line 353 of file subst.h.

#define RegisterNamespace (   a,
  b,
  c,
  d,
  e,
 
)    RegisterNS(a, sizeof(a)-1, b, c, d, e, f)

Definition at line 287 of file subst.h.

#define REGISTERTokenParamDefine (   a)    RegisterTokenParamDefine(#a, sizeof(#a) - 1, a);

teh r0x0r! forward your favourite define from C to the templates with one easy call!

Definition at line 337 of file subst.h.

#define TKEY (   a)    TP->Tokens->Params[a]->Start, TP->Tokens->Params[a]->len

Definition at line 98 of file subst.h.

#define TYPE_BSTR   6

Definition at line 19 of file subst.h.

#define TYPE_GETTEXT   5

Definition at line 18 of file subst.h.

#define TYPE_INTDEFINE   8

Definition at line 21 of file subst.h.

#define TYPE_LONG   2

Definition at line 15 of file subst.h.

#define TYPE_PREFINT   4

Definition at line 17 of file subst.h.

#define TYPE_PREFSTR   3

Definition at line 16 of file subst.h.

#define TYPE_STR   1

Definition at line 14 of file subst.h.

#define TYPE_SUBTEMPLATE   7

Definition at line 20 of file subst.h.


Typedef Documentation

typedef enum _eBitMask eBitMask
typedef void(* HashDestructorFunc)(HashList **KillMe)

Definition at line 184 of file subst.h.

typedef HashList*(* RetrieveHashlistFunc)(StrBuf *Target, WCTemplputParams *TP)

Definition at line 183 of file subst.h.

typedef void(* SubTemplFunc)(StrBuf *TemplBuffer, WCTemplputParams *TP)

Definition at line 182 of file subst.h.

typedef struct _TemplateParam TemplateParam
typedef void(* WCHandlerFunc)(StrBuf *Target, WCTemplputParams *TP)

Definition at line 92 of file subst.h.

typedef int(* WCPreevalFunc)(WCTemplateToken *Token)

Definition at line 95 of file subst.h.

typedef struct WCTemplateToken

Definition at line 88 of file subst.h.

typedef struct WCTemplputParams

Definition at line 89 of file subst.h.


Enumeration Type Documentation

anonymous enum
Enumerator:
WCS_STRING 
WCS_FUNCTION 
WCS_SERVCMD 
WCS_STRBUF 
WCS_STRBUF_REF 
WCS_LONG 

Definition at line 29 of file subst.h.

     {
       WCS_STRING,       /* its a string */
       WCS_FUNCTION,     /* its a function callback */
       WCS_SERVCMD,      /* its a command to send to the citadel server */
       WCS_STRBUF,       /* its a strbuf we own */
       WCS_STRBUF_REF,   /* its a strbuf we mustn't free */
       WCS_LONG          /* its an integer */
};
enum _eBitMask
Enumerator:
eNO 
eOR 
eAND 

Definition at line 107 of file subst.h.

                       {
       eNO = 0,
       eOR,
       eAND
}eBitMask;

Function Documentation

int CompareSubstToStrBuf ( StrBuf *  Compare,
TemplateParam ParamToLookup 
)
int CompareSubstToToken ( TemplateParam ParamToCompare,
TemplateParam ParamToLookup 
)
void dbg_print_longvector ( long *  LongVector)

Definition at line 2674 of file subst.c.

{
       StrBuf *Buf = NewStrBufPlain(HKEY("Longvector: ["));
       int nItems = LongVector[0];
       int i;

       for (i = 0; i < nItems; i++) {
              if (i + 1 < nItems)
                     StrBufAppendPrintf(Buf, "%d: %ld | ", i, LongVector[i]);
              else
                     StrBufAppendPrintf(Buf, "%d: %ld]\n", i, LongVector[i]);

       }
       syslog(1, "%s", ChrPtr(Buf));
       FreeStrBuf(&Buf);
}
const StrBuf* DoTemplate ( const char *  templatename,
long  len,
StrBuf *  Target,
WCTemplputParams TP 
)

Display a variable-substituted template.

Parameters:
templatenametemplate file to load
Returns:
the mimetype of the template its doing

Definition at line 1717 of file subst.c.

{
       WCTemplputParams LocalTP;
       HashList *Static;
       HashList *StaticLocal;
       void *vTmpl;
       
       if (Target == NULL)
              Target = WC->WBuf;
       if (TP == NULL) {
              memset(&LocalTP, 0, sizeof(WCTemplputParams));
              TP = &LocalTP;
       }

       Static = TemplateCache;
       StaticLocal = LocalTemplateCache;

       if (len == 0)
       {
              syslog(1, "Can't to load a template with empty name!\n");
              StrBufAppendPrintf(Target, "<pre>\nCan't to load a template with empty name!\n</pre>");
              return NULL;
       }

       if (!GetHash(StaticLocal, templatename, len, &vTmpl) &&
           !GetHash(Static, templatename, len, &vTmpl)) {
              syslog(1, "didn't find Template [%s] %ld %ld\n", templatename, len , (long)strlen(templatename));
              StrBufAppendPrintf(Target, "<pre>\ndidn't find Template [%s] %ld %ld\n</pre>", 
                               templatename, len, 
                               (long)strlen(templatename));
#if 0
              dbg_PrintHash(Static, PrintTemplate, NULL);
              PrintHash(Static, VarPrintTransition, PrintTemplate);
#endif
              return NULL;
       }
       if (vTmpl == NULL) 
              return NULL;
       return ProcessTemplate(vTmpl, Target, TP);

}

Here is the call graph for this function:

Here is the caller graph for this function:

void RegisterITERATOR ( const char *  Name,
long  len,
int  AdditionalParams,
HashList *  StaticList,
RetrieveHashlistFunc  GetHash,
SubTemplFunc  DoSubTempl,
HashDestructorFunc  Destructor,
int  ContextType,
int  XPectContextType,
int  Flags 
)

Definition at line 1791 of file subst.c.

{
       HashIterator *It;

       It = (HashIterator*)malloc(sizeof(HashIterator));
       memset(It, 0, sizeof(HashIterator));
       It->StaticList = StaticList;
       It->AdditionalParams = AdditionalParams;
       It->GetHash = GetHash;
       It->DoSubTemplate = DoSubTempl;
       It->Destructor = Destructor;
       It->ContextType = ContextType;
       It->XPectContextType = XPectContextType;
       It->Flags = Flags;
       Put(Iterators, Name, len, It, NULL);
}
void RegisterSortFunc ( const char *  name,
long  len,
const char *  prepend,
long  preplen,
CompareFunc  Forward,
CompareFunc  Reverse,
CompareFunc  GroupChange,
long  ContextType 
)

Definition at line 2372 of file subst.c.

{
       SortStruct *NewSort;

       NewSort = (SortStruct*) malloc(sizeof(SortStruct));
       memset(NewSort, 0, sizeof(SortStruct));
       NewSort->Name = NewStrBufPlain(name, len);
       if (prepend != NULL)
              NewSort->PrefPrepend = NewStrBufPlain(prepend, preplen);
       else
              NewSort->PrefPrepend = NULL;
       NewSort->Forward = Forward;
       NewSort->Reverse = Reverse;
       NewSort->GroupChange = GroupChange;
       NewSort->ContextType = ContextType;
       if (ContextType == CTX_NONE) {
              syslog(1, "sorting requires a context. CTX_NONE won't make it.\n");
              exit(1);
       }
              
       Put(SortHash, name, len, NewSort, DestroySortStruct);
}

Here is the call graph for this function:

Here is the caller graph for this function:

CompareFunc RetrieveSort ( WCTemplputParams TP,
const char *  OtherPrefix,
long  OtherPrefixLen,
const char *  Default,
long  ldefault,
long  DefaultDirection 
)

Try to fallback to our remembered values...

Ok, its us, lets see in which direction we should sort...

Try to fallback to our remembered values...

Definition at line 2400 of file subst.c.

{
       const StrBuf *BSort = NULL;
       SortStruct *SortBy;
       void *vSortBy;
       long SortOrder = -1;
       
       if (havebstr("SortBy")) {
              BSort = sbstr("SortBy");
              if (OtherPrefix == NULL) {
                     set_room_pref("sort", NewStrBufDup(BSort), 0);
              }
              else {
                     set_X_PREFS(HKEY("sort"), OtherPrefix, OtherPrefixLen, NewStrBufDup(BSort), 0);
              }
       }
       else { 
              if (OtherPrefix == NULL) {
                     BSort = get_room_pref("sort");
              }
              else {
                     BSort = get_X_PREFS(HKEY("sort"), OtherPrefix, OtherPrefixLen);
              }
              if (BSort != NULL)
                     putbstr("SortBy", NewStrBufDup(BSort));
              else {
                     StrBuf *Buf;

                     BSort = Buf = NewStrBufPlain(Default, ldefault);
                     putbstr("SortBy", Buf);
              }
       }

       if (!GetHash(SortHash, SKEY(BSort), &vSortBy) || 
           (vSortBy == NULL)) {
              if (!GetHash(SortHash, Default, ldefault, &vSortBy) || 
                  (vSortBy == NULL)) {
                     LogTemplateError(
                            NULL, "Sorting", ERR_PARM1, TP,
                            "Illegal default sort: [%s]", Default);
                     wc_backtrace();
              }
       }
       SortBy = (SortStruct*)vSortBy;

       if (SortBy->ContextType != TP->Filter.ContextType)
              return NULL;

       if (havebstr("SortOrder")) {
              SortOrder = LBSTR("SortOrder");
       }
       else { 
              StrBuf *Buf = NULL;
              if (SortBy->PrefPrepend == NULL) {
                     Buf = get_room_pref("SortOrder");
                     SortOrder = StrTol(Buf);
              }
              else {
                     BSort = get_X_PREFS(HKEY("SortOrder"), OtherPrefix, OtherPrefixLen);
              }

              if (Buf == NULL)
                     SortOrder = DefaultDirection;

              Buf = NewStrBufPlain(NULL, 64);
              StrBufPrintf(Buf, "%ld", SortOrder);
              putbstr("SortOrder", Buf);
       }
       switch (SortOrder) {
       default:
       case 0:
              return NULL;
       case 1:
              return SortBy->Forward;
       case 2:
              return SortBy->Reverse;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void StrBufAppendTemplate ( StrBuf *  Target,
WCTemplputParams TP,
const StrBuf *  Source,
int  FormatTypeIndex 
)

put a token value into the template use this function to append your strings into a Template.

it can escape your string according to the token at FormattypeIndex: H: de-QP and utf8-ify X: escapize for HTML J: JSON Escapize

Parameters:
Targetthe destination buffer
TPthe template token information
Sourcestring to append
FormatTypeIndexwhich parameter contains the escaping functionality? if this token doesn't have as much parameters, plain append is done.

Definition at line 592 of file subst.c.

{
       const char *pFmt = NULL;
       char EscapeAs = ' ';

       if ((FormatTypeIndex < TP->Tokens->nParameters) &&
           (TP->Tokens->Params[FormatTypeIndex]->Type == TYPE_STR) &&
           (TP->Tokens->Params[FormatTypeIndex]->len >= 1)) {
              pFmt = TP->Tokens->Params[FormatTypeIndex]->Start;
              EscapeAs = *pFmt;
       }

       switch(EscapeAs)
       {
       case 'H':
              StrEscAppend(Target, Source, NULL, 0, 2);
              break;
       case 'X':
              StrEscAppend(Target, Source, NULL, 0, 0);
              break;
       case 'J':
              StrECMAEscAppend(Target, Source, NULL);
         break;
       case 'K':
              StrHtmlEcmaEscAppend(Target, Source, NULL, 0, 0);
         break;
       case 'U':
              StrBufUrlescAppend(Target, Source, NULL);
              break;
       case 'F':
              if (pFmt != NULL)    pFmt++;
              else                 pFmt = "JUSTIFY";
              if (*pFmt == '\0')   pFmt = "JUSTIFY";
              FmOut(Target, pFmt, Source);
              break;
       default:
              StrBufAppendBuf(Target, Source, 0);
       }
}

Here is the call graph for this function:

void url_do_template ( void  )

Definition at line 283 of file webcit.c.

                           {
       const StrBuf *MimeType;
       const StrBuf *Tmpl = sbstr("template");
       begin_burst();
       MimeType = DoTemplate(SKEY(Tmpl), NULL, &NoCtx);
       http_transmit_thing(ChrPtr(MimeType), 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

HashList* Conditionals

Definition at line 26 of file subst.c.

HashList* GlobalNS

Definition at line 24 of file subst.c.

HashList* Iterators

Definition at line 25 of file subst.c.

HashList* LocalTemplateCache

Definition at line 22 of file subst.c.

Definition at line 33 of file subst.c.

HashList* TemplateCache

Definition at line 21 of file subst.c.