2 * Copyright (c) 2008 Teodor Sigaev <teodor@sigaev.ru>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 /******************************************************************************
32 ******************************************************************************
33 * <% [^]VARNAME[, "FORMAT"] [||"DEFAULTVALUE"] [|(h|u)]%>
34 * - '^' mark means global variable.
35 * - format value should be as in strftime for time value and printf
36 * for all other. Currently, bool values have only "true"/"false"
38 * <@IF [NOT] [DEFINED] [^]VARNAME@>
50 ******************************************************************************/
52 #ifndef __TEMPLATE_H__
53 #define __TEMPLATE_H__
55 #include <sys/types.h>
60 typedef enum TemplateNodeType {
69 /* value's types of variables */
70 valueInt = 200, /* smallest of any values type */
78 #define TND_DEFINED (0x0001)
79 #define TND_NOT (0x0002)
80 #define TND_HTMLESCAPE (0x0004)
81 #define TND_URLESCAPE (0x0008)
82 #define TND_GLOBAL (0x0010)
83 #define TND___FIRST (0x0020)
84 #define TND___LAST (0x0040)
85 #define TND___COUNTER (0x0080)
86 #define TND___SIZE (0x0100)
87 #define TND___ODD (0x0200)
88 #define TND___EVEN (0x0400)
90 #define TND__SPECIALMASK (TND___FIRST | TND___LAST | TND___COUNTER | TND___SIZE | TND___ODD | TND___EVEN)
91 struct TemplateNodeData;
92 typedef struct TemplateNodeData *TemplateNode;
94 typedef struct VariableValueData * VariableValue;
95 typedef struct VariableValueData {
96 TemplateNodeType type; /* should be first, see resetTemplate/freeTemplate */
104 VariableValue ptrValue; /* special value to handle loop variables,
105 points to members of loopValues */
109 typedef struct LoopInstanceData * LoopInstance;
110 typedef struct LoopInstanceData {
115 typedef struct TemplateNodeData {
116 TemplateNodeType type; /* should be first, see resetTemplate/freeTemplate */
142 TemplateNode bodyNode;
144 GList *childrenLoop; /* to reset instance */
145 GList *listVarValues; /* list of loop variables */
156 TemplateNode elseNode;
166 typedef void (*outFn)(char *, int);
168 typedef char* (*urlEscapeFn)(char *, int * /* in/out */);
169 typedef char* (*htmlEscapeFn)(char *, int * /* in/out */);
171 typedef struct TemplateData {
173 MemoryContext *templateContext;
176 urlEscapeFn urlEscape;
177 htmlEscapeFn htmlEscape;
180 typedef struct TemplateData *Template;
182 int parseTemplateFile(Template tmpl, char* filename ); /* return non-zero if error */
183 int initTemplate( Template tmpl, MemoryContext *mc, char *basedir, char *filename );
184 void freeTemplate( Template tmpl );
185 void resetTemplate( Template tmpl );
186 int printTemplate( Template tmpl );
189 #define TVAR_NOTFOUND (1)
190 #define TVAR_FORBIDDEN (2)
191 #define TVAR_NOROW (3)
192 #define TVAR_LOOPMARK (4)
194 int setTemplateValueInt( Template tmpl, char * key, int val );
195 int setTemplateValueString( Template tmpl, char * key, char * val );
196 int setTemplateValueTime( Template tmpl, char * key, time_t val );
197 int setTemplateValueBool( Template tmpl, char * key, int val );
198 int setTemplateValueUndefined( Template tmpl, char * key );
199 int setTemplateValueDouble( Template tmpl, char * key, double val );
200 int addTemplateRow( Template tmpl, char * key );
202 void dumpTemplate( Template tmpl );