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>
61 typedef enum TemplateNodeType {
70 /* value's types of variables */
71 valueInt = 200, /* smallest of any values type */
79 #define TND_DEFINED (0x0001)
80 #define TND_NOT (0x0002)
81 #define TND_HTMLESCAPE (0x0004)
82 #define TND_URLESCAPE (0x0008)
83 #define TND_GLOBAL (0x0010)
84 #define TND___FIRST (0x0020)
85 #define TND___LAST (0x0040)
86 #define TND___COUNTER (0x0080)
87 #define TND___SIZE (0x0100)
88 #define TND___ODD (0x0200)
89 #define TND___EVEN (0x0400)
91 #define TND__SPECIALMASK (TND___FIRST | TND___LAST | TND___COUNTER | TND___SIZE | TND___ODD | TND___EVEN)
92 struct TemplateNodeData;
93 typedef struct TemplateNodeData *TemplateNode;
95 typedef struct VariableValueData * VariableValue;
96 typedef struct VariableValueData {
97 TemplateNodeType type; /* should be first, see resetTemplate/freeTemplate */
105 VariableValue ptrValue; /* special value to handle loop variables,
106 points to members of loopValues */
110 typedef struct LoopInstanceData * LoopInstance;
111 typedef struct LoopInstanceData {
116 typedef struct TemplateNodeData {
117 TemplateNodeType type; /* should be first, see resetTemplate/freeTemplate */
143 TemplateNode bodyNode;
145 GList *childrenLoop; /* to reset instance */
146 GList *listVarValues; /* list of loop variables */
157 TemplateNode elseNode;
167 typedef void (*outFn)(char *, int);
169 typedef char* (*urlEscapeFn)(char *, int * /* in/out */);
170 typedef char* (*htmlEscapeFn)(char *, int * /* in/out */);
172 typedef struct TemplateData {
174 MemoryContext *templateContext;
177 urlEscapeFn urlEscape;
178 htmlEscapeFn htmlEscape;
181 typedef struct TemplateData *Template;
183 int parseTemplateFile(Template tmpl, char* filename ); /* return non-zero if error */
184 int initTemplate( Template tmpl, MemoryContext *mc, char *basedir, char *filename );
185 void freeTemplate( Template tmpl );
186 void resetTemplate( Template tmpl );
187 int printTemplate( Template tmpl );
190 #define TVAR_NOTFOUND (1)
191 #define TVAR_FORBIDDEN (2)
192 #define TVAR_NOROW (3)
193 #define TVAR_LOOPMARK (4)
195 int setTemplateValueInt( Template tmpl, char * key, int val );
196 int setTemplateValueString( Template tmpl, char * key, char * val );
197 int setTemplateValueTime( Template tmpl, char * key, time_t val );
198 int setTemplateValueBool( Template tmpl, char * key, int val );
199 int setTemplateValueUndefined( Template tmpl, char * key );
200 int setTemplateValueDouble( Template tmpl, char * key, double val );
201 int addTemplateRow( Template tmpl, char * key );
203 void dumpTemplate( Template tmpl );