| 1 |
|
| #include <stdio.h> |
| 2 |
|
| #include <stdlib.h> |
| 3 |
|
| #include <string.h> |
| 4 |
|
| #include <ctype.h> |
| 5 |
|
| |
| 6 |
|
| #include "tmplpro.h" |
| 7 |
|
| #include "pconst.h" |
| 8 |
|
| #include "procore.h" |
| 9 |
|
| #include "prostate.h" |
| 10 |
|
| #include "provalue.h" |
| 11 |
|
| #include "tagstack.h" |
| 12 |
|
| #include "pbuffer.h" |
| 13 |
|
| #include "parse_expr.h" |
| 14 |
|
| #include "pparam.h" |
| 15 |
|
| #include "optint.h" |
| 16 |
|
| #include "proscope.h" |
| 17 |
|
| #include "proscope.inc" |
| 18 |
|
| #include "pstrutils.inc" |
| 19 |
|
| #include "pmiscdef.h" /*for snprintf */ |
| 20 |
|
| /* for mmap_load_file & mmap_unload_file */ |
| 21 |
|
| #include "loadfile.inc" |
| 22 |
|
| #include "loopvar.inc" |
| 23 |
|
| |
| 24 |
|
| #define HTML_TEMPLATE_NO_TAG -1 |
| 25 |
|
| #define HTML_TEMPLATE_BAD_TAG 0 |
| 26 |
|
| #define HTML_TEMPLATE_FIRST_TAG_USED 1 |
| 27 |
|
| #define HTML_TEMPLATE_TAG_VAR 1 |
| 28 |
|
| #define HTML_TEMPLATE_TAG_INCLUDE 2 |
| 29 |
|
| #define HTML_TEMPLATE_TAG_LOOP 3 |
| 30 |
|
| #define HTML_TEMPLATE_TAG_IF 4 |
| 31 |
|
| #define HTML_TEMPLATE_TAG_ELSE 5 |
| 32 |
|
| #define HTML_TEMPLATE_TAG_UNLESS 6 |
| 33 |
|
| #define HTML_TEMPLATE_TAG_ELSIF 7 |
| 34 |
|
| #define HTML_TEMPLATE_LAST_TAG_USED 7 |
| 35 |
|
| |
| 36 |
|
| static |
| 37 |
|
| const char* const tagname[]={ |
| 38 |
|
| "Bad or unsupported tag", /* 0 */ |
| 39 |
|
| "var", "include", "loop", "if", "else", "unless", "elsif" |
| 40 |
|
| }; |
| 41 |
|
| |
| 42 |
|
| static |
| 43 |
|
| const char* const TAGNAME[]={ |
| 44 |
|
| "Bad or unsupported tag", /* 0 */ |
| 45 |
|
| "VAR", "INCLUDE", "LOOP", "IF", "ELSE", "UNLESS", "ELSIF" |
| 46 |
|
| }; |
| 47 |
|
| |
| 48 |
|
| static int debuglevel=0; |
| 49 |
|
| |
| 50 |
|
| #define TAG_OPT_NAME 0 |
| 51 |
|
| #define TAG_OPT_EXPR 1 |
| 52 |
|
| #define TAG_OPT_ESCAPE 2 |
| 53 |
|
| #define TAG_OPT_DEFAULT 3 |
| 54 |
|
| #define MIN_TAG_OPT 0 |
| 55 |
|
| #define MAX_TAG_OPT 3 |
| 56 |
|
| |
| 57 |
|
| static const char* const tagopt[]={"name", "expr", "escape", "default" }; |
| 58 |
|
| static const char* const TAGOPT[]={"NAME", "EXPR", "ESCAPE", "DEFAULT" }; |
| 59 |
|
| |
| 60 |
|
| #include "prostate.inc" |
| 61 |
|
| #include "tags.inc" |
| 62 |
|
| |
| 63 |
|
| static const char tag_can_be_closed[]={ |
| 64 |
|
| 1 /*Bad or unsupported tag*/, |
| 65 |
|
| 0 /*VAR*/, |
| 66 |
|
| 0 /*INCLUDE*/, |
| 67 |
|
| 1 /*LOOP*/, |
| 68 |
|
| 1 /*IF*/, |
| 69 |
|
| 0 /*ELSE*/, |
| 70 |
|
| 1 /*UNLESS*/, |
| 71 |
|
| 1 /*ELSIF*/, |
| 72 |
|
| 0 /**/, |
| 73 |
|
| }; |
| 74 |
|
| |
| 75 |
|
| static const char tag_has_opt[][6]={ |
| 76 |
|
| /* "name", "expr", "escape", "default", todo, todo */ |
| 77 |
|
| |
| 78 |
|
| { 0, 0, 0, 0, 0, 0 }, /*Bad or unsupported tag*/ |
| 79 |
|
| { 1, 1, 1, 1, 0, 0 }, /*VAR*/ |
| 80 |
|
| { 1, 1, 0, 1, 0, 0 }, /*INCLUDE*/ |
| 81 |
|
| { 1, 0, 0, 0, 0, 0 }, /*LOOP*/ |
| 82 |
|
| { 1, 1, 0, 0, 0, 0 }, /*IF*/ |
| 83 |
|
| { 0, 0, 0, 0, 0, 0 }, /*ELSE*/ |
| 84 |
|
| { 1, 1, 0, 0, 0, 0 }, /*UNLESS*/ |
| 85 |
|
| { 1, 1, 0, 0, 0, 0 }, /*ELSIF*/ |
| 86 |
|
| { 0, 0, 0, 0, 0, 0 }, /**/ |
| 87 |
|
| }; |
| 88 |
|
| |
| 89 |
|
| typedef void (*tag_handler_func)(struct tmplpro_state *state, const PSTRING* const TagOptVal); |
| 90 |
|
| |
| 91 |
|
| static const tag_handler_func output_closetag_handler[]={ |
| 92 |
|
| tag_handler_unknown, /*Bad or unsupported tag*/ |
| 93 |
|
| tag_handler_unknown, /*VAR*/ |
| 94 |
|
| tag_handler_unknown, /*INCLUDE*/ |
| 95 |
|
| tag_handler_closeloop, /*LOOP*/ |
| 96 |
|
| tag_handler_closeif, /*IF*/ |
| 97 |
|
| tag_handler_unknown, /*ELSE*/ |
| 98 |
|
| tag_handler_closeunless, /*UNLESS*/ |
| 99 |
|
| tag_handler_unknown, /*ELSIF*/ |
| 100 |
|
| tag_handler_unknown, /**/ |
| 101 |
|
| }; |
| 102 |
|
| static const tag_handler_func output_opentag_handler[]={ |
| 103 |
|
| tag_handler_unknown, /*Bad or unsupported tag*/ |
| 104 |
|
| tag_handler_var, /*VAR*/ |
| 105 |
|
| tag_handler_include, /*INCLUDE*/ |
| 106 |
|
| tag_handler_loop, /*LOOP*/ |
| 107 |
|
| tag_handler_if, /*IF*/ |
| 108 |
|
| tag_handler_else, /*ELSE*/ |
| 109 |
|
| tag_handler_unless, /*UNLESS*/ |
| 110 |
|
| tag_handler_elsif, /*ELSIF*/ |
| 111 |
|
| tag_handler_unknown, /**/ |
| 112 |
|
| }; |
| 113 |
|
| |
| 114 |
|
| static |
| 115 |
|
| int |
| 116 |
33092 |
| is_string(struct tmplpro_state *state, const char* pattern,const char* PATTERN) |
| 117 |
|
| { |
| 118 |
33092 |
| const char* cur_pos=state->cur_pos; |
| 119 |
33092 |
| register const char* const next_to_end = state->next_to_end; |
| 120 |
70412 |
▶ | while (*pattern && cur_pos<next_to_end) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (*pattern && cur_pos<next_to_end) { |
61887 |
8525 |
70412 |
| while (*pattern && cur_pos<next_to_end) { |
61887 |
0 |
61887 |
|
| 121 |
61887 |
▶ | if (*pattern == *cur_pos || *PATTERN == *cur_pos) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (*pattern == *cur_pos || *PATTERN == *cur_pos) { |
37815 |
24072 |
61887 |
| if (*pattern == *cur_pos || *PATTERN == *cur_pos) { |
13248 |
24567 |
37815 |
|
| 122 |
37320 |
| pattern++; |
| 123 |
37320 |
| PATTERN++; |
| 124 |
37320 |
| cur_pos++; |
| 125 |
|
| } else { |
| 126 |
24567 |
| return 0; |
| 127 |
|
| } |
| 128 |
|
| } |
| 129 |
8525 |
▶ | if (cur_pos>=next_to_end) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (cur_pos>=next_to_end) return 0; |
0 |
8525 |
8525 |
|
| 130 |
8525 |
| state->cur_pos=cur_pos; |
| 131 |
8525 |
| return 1; |
| 132 |
|
| } |
| 133 |
|
| |
| 134 |
|
| static |
| 135 |
|
| INLINE |
| 136 |
|
| void |
| 137 |
26234 |
| jump_over_space(struct tmplpro_state *state) |
| 138 |
|
| { |
| 139 |
26234 |
| register const char* const next_to_end = state->next_to_end; |
| 140 |
32384 |
▶ | while (isspace(*(state->cur_pos)) && state->cur_pos<next_to_end) {state->cur_pos++;}; |
Branch: 2 branches
| Branch | True | False | Total |
| while (isspace(*(state->cur_pos)) && state->cur_pos<next_to_end) {state->cur_pos++;}; |
6150 |
26234 |
32384 |
| while (isspace(*(state->cur_pos)) && state->cur_pos<next_to_end) {state->cur_pos++;}; |
6150 |
0 |
6150 |
|
| 141 |
26234 |
| } |
| 142 |
|
| |
| 143 |
|
| static |
| 144 |
|
| INLINE |
| 145 |
|
| void |
| 146 |
|
| jump_to_char(struct tmplpro_state *state, char c) |
| 147 |
|
| { |
| 148 |
|
| register const char* const next_to_end = state->next_to_end; |
| 149 |
|
| while (c!=*(state->cur_pos) && state->cur_pos<next_to_end) {state->cur_pos++;}; |
| 150 |
|
| } |
| 151 |
|
| |
| 152 |
|
| static |
| 153 |
|
| PSTRING |
| 154 |
2410 |
| read_tag_parameter_value (struct tmplpro_state *state) |
| 155 |
|
| { |
| 156 |
|
| PSTRING modifier_value; |
| 157 |
|
| char cur_char; |
| 158 |
2410 |
| char quote_char=0; |
| 159 |
|
| register const char* cur_pos; |
| 160 |
2410 |
| const char* const next_to_end=state->next_to_end; |
| 161 |
2410 |
| jump_over_space(state); |
| 162 |
2410 |
| cur_pos=state->cur_pos; |
| 163 |
2410 |
| cur_char=*cur_pos; |
| 164 |
2410 |
▶ | if (('"'==cur_char) || ('\''==cur_char)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (('"'==cur_char) || ('\''==cur_char)) { |
935 |
1475 |
2410 |
| if (('"'==cur_char) || ('\''==cur_char)) { |
42 |
893 |
935 |
|
| 165 |
1517 |
| quote_char=*cur_pos; |
| 166 |
1517 |
| cur_pos++; |
| 167 |
|
| } |
| 168 |
2410 |
| modifier_value.begin=cur_pos; |
| 169 |
2410 |
| cur_char=*cur_pos; |
| 170 |
2410 |
▶ | if (quote_char) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (quote_char) { |
1517 |
893 |
2410 |
|
| 171 |
1517 |
| while (quote_char!=cur_char |
| 172 |
|
| #ifdef COMPAT_ON_BROKEN_QUOTE |
| 173 |
|
| /* compatibility mode; HTML::Template doesn't allow '>' inside quotes */ |
| 174 |
|
| && ('>' != quote_char) |
| 175 |
|
| #endif |
| 176 |
14288 |
▶ | && cur_pos<next_to_end) { |
Branch: 2 branches
| Branch | True | False | Total |
| && cur_pos<next_to_end) { |
12773 |
1515 |
14288 |
| && cur_pos<next_to_end) { |
12771 |
2 |
12773 |
|
| 177 |
12771 |
| cur_pos++; |
| 178 |
12771 |
| cur_char=*cur_pos; |
| 179 |
|
| } |
| 180 |
|
| } else { |
| 181 |
5132 |
▶ | while ('>'!=cur_char && ! isspace(cur_char) && cur_pos<next_to_end) { |
Branch: 3 branches
| Branch | True | False | Total |
| while ('>'!=cur_char && ! isspace(cur_char) && cur_pos<next_to_end) { |
4319 |
813 |
5132 |
| while ('>'!=cur_char && ! isspace(cur_char) && cur_pos<next_to_end) { |
4239 |
80 |
4319 |
| while ('>'!=cur_char && ! isspace(cur_char) && cur_pos<next_to_end) { |
4239 |
0 |
4239 |
|
| 182 |
4239 |
| cur_pos++; |
| 183 |
4239 |
| cur_char=*cur_pos; |
| 184 |
|
| } |
| 185 |
|
| } |
| 186 |
2410 |
▶ | if (cur_pos>=next_to_end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cur_pos>=next_to_end) { |
2 |
2408 |
2410 |
|
| 187 |
2 |
| log_state(state,TMPL_LOG_ERROR,"quote char %c at pos " MOD_TD " is not terminated\n", |
| 188 |
2 |
| quote_char,TO_PTRDIFF_T(state->cur_pos - state->top)); |
| 189 |
2 |
| modifier_value.endnext=modifier_value.begin; |
| 190 |
2 |
| jump_over_space(state); |
| 191 |
2 |
| return modifier_value; |
| 192 |
|
| } |
| 193 |
2408 |
| modifier_value.endnext=cur_pos; |
| 194 |
2408 |
▶ | if (quote_char) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (quote_char) { |
1515 |
893 |
2408 |
|
| 195 |
1515 |
▶ | if (quote_char==*cur_pos) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (quote_char==*cur_pos) { |
1515 |
0 |
1515 |
|
| 196 |
1515 |
| cur_pos++; |
| 197 |
|
| } else { |
| 198 |
0 |
| log_state(state,TMPL_LOG_ERROR,"found %c instead of end quote %c at pos " MOD_TD "\n", |
| 199 |
0 |
| *cur_pos,quote_char,TO_PTRDIFF_T(cur_pos - state->top)); |
| 200 |
|
| } |
| 201 |
|
| } |
| 202 |
2408 |
| state->cur_pos=cur_pos; |
| 203 |
|
| /* if (debuglevel) log_state(state,TMPL_LOG_DEBUG2," at pos " MOD_TD "",TO_PTRDIFF_T(state->cur_pos-state->top)); */ |
| 204 |
2408 |
| jump_over_space(state); |
| 205 |
2408 |
| return modifier_value; |
| 206 |
|
| } |
| 207 |
|
| |
| 208 |
|
| static |
| 209 |
|
| int |
| 210 |
17896 |
| try_tag_parameter (struct tmplpro_state *state,const char *modifier,const char *MODIFIER) |
| 211 |
|
| { |
| 212 |
17896 |
| const char* const initial_pos=state->cur_pos; |
| 213 |
17896 |
| jump_over_space(state); |
| 214 |
17896 |
▶ | if (is_string(state, modifier, MODIFIER)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_string(state, modifier, MODIFIER)) { |
1737 |
16159 |
17896 |
|
| 215 |
1737 |
| jump_over_space(state); |
| 216 |
1737 |
▶ | if ('='==*(state->cur_pos)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ('='==*(state->cur_pos)) { |
1735 |
2 |
1737 |
|
| 217 |
1735 |
| state->cur_pos++; |
| 218 |
1735 |
| jump_over_space(state); |
| 219 |
1735 |
| return 1; |
| 220 |
|
| } |
| 221 |
|
| } |
| 222 |
16161 |
| state->cur_pos=initial_pos; |
| 223 |
16161 |
| return 0; |
| 224 |
|
| } |
| 225 |
|
| |
| 226 |
|
| static |
| 227 |
|
| void |
| 228 |
2865 |
| try_tmpl_var_options (struct tmplpro_state *state, int tag_type, PSTRING* TagOptVal) |
| 229 |
|
| { |
| 230 |
|
| int i; |
| 231 |
2865 |
| int opt_found = 1; |
| 232 |
|
| /* reading parameter */ |
| 233 |
7339 |
▶ | while (opt_found) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (opt_found) { |
4474 |
2865 |
7339 |
|
| 234 |
4474 |
| int found_in_loop=0; |
| 235 |
22370 |
▶ | for (i=MIN_TAG_OPT; i<=MAX_TAG_OPT; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=MIN_TAG_OPT; i<=MAX_TAG_OPT; i++) { |
17896 |
4474 |
22370 |
|
| 236 |
17896 |
▶ | if ( |
Branch: 1 branch
| Branch | True | False | Total |
| if ( |
1735 |
16161 |
17896 |
|
| 237 |
|
| /* we will complain about syntax errors later; |
| 238 |
|
| tag_has_opt[tag_type][i] && */ |
| 239 |
17896 |
| try_tag_parameter(state, tagopt[i], TAGOPT[i])) { |
| 240 |
1735 |
| TagOptVal[i] = read_tag_parameter_value(state); |
| 241 |
1735 |
| found_in_loop=1; |
| 242 |
1735 |
▶ | if (debuglevel) log_state(state,TMPL_LOG_DEBUG,"in tag %s: found option %s=%.*s\n", TAGNAME[tag_type], TAGOPT[i],(int)(TagOptVal[i].endnext-TagOptVal[i].begin),TagOptVal[i].begin); |
Branch: 1 branch
| Branch | True | False | Total |
| if (debuglevel) log_state(state,TMPL_LOG_DEBUG,"in tag %s: found option %s=%.*s\n", TAGNAME[tag_type], TAGOPT[i],(int)(TagOptVal[i].endnext-TagOptVal[i].begin),TagOptVal[i].begin); |
4 |
1731 |
1735 |
|
| 243 |
|
| } |
| 244 |
|
| } |
| 245 |
4474 |
▶ | if (!found_in_loop) opt_found = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!found_in_loop) opt_found = 0; |
2865 |
1609 |
4474 |
|
| 246 |
|
| } |
| 247 |
2865 |
| } |
| 248 |
|
| |
| 249 |
|
| static |
| 250 |
|
| void |
| 251 |
3394 |
| process_tmpl_tag(struct tmplpro_state *state) |
| 252 |
|
| { |
| 253 |
3394 |
| const int is_tag_closed=state->is_tag_closed; |
| 254 |
|
| |
| 255 |
3394 |
| int tag_type=HTML_TEMPLATE_BAD_TAG; |
| 256 |
|
| PSTRING TagOptVal[MAX_TAG_OPT+1]; |
| 257 |
|
| |
| 258 |
|
| int i; |
| 259 |
16970 |
▶ | for (i=MIN_TAG_OPT; i<=MAX_TAG_OPT; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=MIN_TAG_OPT; i<=MAX_TAG_OPT; i++) { |
13576 |
3394 |
16970 |
|
| 260 |
13576 |
| TagOptVal[i].begin = NULL; |
| 261 |
13576 |
| TagOptVal[i].endnext = NULL; |
| 262 |
|
| } |
| 263 |
|
| |
| 264 |
9397 |
▶ | for (i=HTML_TEMPLATE_FIRST_TAG_USED; i<=HTML_TEMPLATE_LAST_TAG_USED; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=HTML_TEMPLATE_FIRST_TAG_USED; i<=HTML_TEMPLATE_LAST_TAG_USED; i++) { |
9397 |
0 |
9397 |
|
| 265 |
9397 |
▶ | if (is_string(state, tagname[i], TAGNAME[i])) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_string(state, tagname[i], TAGNAME[i])) { |
3394 |
6003 |
9397 |
|
| 266 |
3394 |
| tag_type=i; |
| 267 |
3394 |
| state->tag=tag_type; |
| 268 |
3394 |
▶ | if (debuglevel) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (debuglevel) { |
5 |
3389 |
3394 |
|
| 269 |
5 |
▶ | if (is_tag_closed) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_tag_closed) { |
1 |
4 |
5 |
|
| 270 |
1 |
| tmpl_log(TMPL_LOG_DEBUG, "found </TMPL_%s> at pos " MOD_TD "\n",TAGNAME[i], TO_PTRDIFF_T(state->cur_pos-state->top)); |
| 271 |
|
| } else { |
| 272 |
4 |
| tmpl_log(TMPL_LOG_DEBUG, "found <TMPL_%s> at pos " MOD_TD "\n",TAGNAME[i], TO_PTRDIFF_T(state->cur_pos-state->top)); |
| 273 |
|
| } |
| 274 |
|
| } |
| 275 |
3394 |
| break; |
| 276 |
|
| } |
| 277 |
|
| } |
| 278 |
3394 |
▶ | if (HTML_TEMPLATE_BAD_TAG==tag_type) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (HTML_TEMPLATE_BAD_TAG==tag_type) { |
0 |
3394 |
3394 |
|
| 279 |
0 |
| state->param->found_syntax_error=1; |
| 280 |
0 |
| log_state(state,TMPL_LOG_ERROR, "found bad/unsupported tag at pos " MOD_TD "\n", TO_PTRDIFF_T(state->cur_pos-state->top)); |
| 281 |
|
| /* TODO: flush its data --- */ |
| 282 |
0 |
| state->cur_pos++; |
| 283 |
0 |
| return; |
| 284 |
|
| } |
| 285 |
|
| |
| 286 |
3394 |
▶ | if (is_tag_closed && !tag_can_be_closed[tag_type]) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (is_tag_closed && !tag_can_be_closed[tag_type]) { |
798 |
2596 |
3394 |
| if (is_tag_closed && !tag_can_be_closed[tag_type]) { |
0 |
798 |
798 |
|
| 287 |
0 |
| state->param->found_syntax_error=1; |
| 288 |
0 |
| log_state(state,TMPL_LOG_ERROR, "incorrect closed tag </TMPL_%s> at pos " MOD_TD "\n", |
| 289 |
0 |
| TAGNAME[tag_type], TO_PTRDIFF_T(state->cur_pos-state->top)); |
| 290 |
|
| } |
| 291 |
|
| |
| 292 |
3394 |
▶ | if (is_tag_closed || ! tag_has_opt[tag_type][TAG_OPT_NAME]) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (is_tag_closed || ! tag_has_opt[tag_type][TAG_OPT_NAME]) { |
2596 |
798 |
3394 |
| if (is_tag_closed || ! tag_has_opt[tag_type][TAG_OPT_NAME]) { |
2190 |
406 |
2596 |
|
| 293 |
|
| /* tag has no parameter */ |
| 294 |
|
| #ifdef COMPAT_ALLOW_NAME_IN_CLOSING_TAG |
| 295 |
|
| /* requested compatibility mode |
| 296 |
|
| to try reading NAME inside </closing tags NAME=" "> |
| 297 |
|
| (useful for comments?) */ |
| 298 |
|
| try_tag_parameter(state, tagopt[TAG_OPT_NAME], TAGOPT[TAG_OPT_NAME]); |
| 299 |
|
| read_tag_parameter_value(state); |
| 300 |
|
| #endif |
| 301 |
|
| } else { |
| 302 |
2190 |
| try_tmpl_var_options(state, tag_type, TagOptVal); |
| 303 |
|
| /* suport for short syntax */ |
| 304 |
2190 |
▶ | if (TagOptVal[TAG_OPT_NAME].begin == NULL && |
Branch: 1 branch
| Branch | True | False | Total |
| if (TagOptVal[TAG_OPT_NAME].begin == NULL && |
1234 |
956 |
2190 |
|
| 305 |
1234 |
▶ | tag_has_opt[tag_type][TAG_OPT_NAME] && |
Branch: 1 branch
| Branch | True | False | Total |
| tag_has_opt[tag_type][TAG_OPT_NAME] && |
1234 |
0 |
1234 |
|
| 306 |
1234 |
▶ | (!tag_has_opt[tag_type][TAG_OPT_EXPR] || TagOptVal[TAG_OPT_EXPR].begin == NULL )) { |
Branch: 2 branches
| Branch | True | False | Total |
| (!tag_has_opt[tag_type][TAG_OPT_EXPR] || TagOptVal[TAG_OPT_EXPR].begin == NULL )) { |
1201 |
33 |
1234 |
| (!tag_has_opt[tag_type][TAG_OPT_EXPR] || TagOptVal[TAG_OPT_EXPR].begin == NULL )) { |
642 |
559 |
1201 |
|
| 307 |
675 |
| TagOptVal[TAG_OPT_NAME]=read_tag_parameter_value(state); |
| 308 |
675 |
| try_tmpl_var_options(state, tag_type, TagOptVal); |
| 309 |
|
| } |
| 310 |
|
| |
| 311 |
2190 |
▶ | if (TagOptVal[TAG_OPT_NAME].begin == NULL && |
Branch: 1 branch
| Branch | True | False | Total |
| if (TagOptVal[TAG_OPT_NAME].begin == NULL && |
559 |
1631 |
2190 |
|
| 312 |
559 |
▶ | tag_has_opt[tag_type][TAG_OPT_NAME] && |
Branch: 1 branch
| Branch | True | False | Total |
| tag_has_opt[tag_type][TAG_OPT_NAME] && |
559 |
0 |
559 |
|
| 313 |
559 |
▶ | (!tag_has_opt[tag_type][TAG_OPT_EXPR] || TagOptVal[TAG_OPT_EXPR].begin == NULL )) { |
Branch: 2 branches
| Branch | True | False | Total |
| (!tag_has_opt[tag_type][TAG_OPT_EXPR] || TagOptVal[TAG_OPT_EXPR].begin == NULL )) { |
559 |
0 |
559 |
| (!tag_has_opt[tag_type][TAG_OPT_EXPR] || TagOptVal[TAG_OPT_EXPR].begin == NULL )) { |
0 |
559 |
559 |
|
| 314 |
0 |
| state->param->found_syntax_error=1; |
| 315 |
0 |
| log_state(state,TMPL_LOG_ERROR,"NAME or EXPR is required for TMPL_%s\n", TAGNAME[tag_type]); |
| 316 |
|
| } |
| 317 |
10950 |
▶ | for (i=MIN_TAG_OPT; i<=MAX_TAG_OPT; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=MIN_TAG_OPT; i<=MAX_TAG_OPT; i++) { |
8760 |
2190 |
10950 |
|
| 318 |
8760 |
▶ | if (TagOptVal[i].begin!=NULL && ! tag_has_opt[tag_type][i]) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (TagOptVal[i].begin!=NULL && ! tag_has_opt[tag_type][i]) { |
2410 |
6350 |
8760 |
| if (TagOptVal[i].begin!=NULL && ! tag_has_opt[tag_type][i]) { |
0 |
2410 |
2410 |
|
| 319 |
0 |
| state->param->found_syntax_error=1; |
| 320 |
0 |
| log_state(state,TMPL_LOG_ERROR,"TMPL_%s does not support %s= option\n", TAGNAME[tag_type], TAGOPT[i]); |
| 321 |
|
| } |
| 322 |
|
| } |
| 323 |
|
| } |
| 324 |
|
| |
| 325 |
3394 |
▶ | if (state->is_tag_commented) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (state->is_tag_commented) { |
18 |
3376 |
3394 |
|
| 326 |
|
| /* try read comment end */ |
| 327 |
|
| /* jump_over_space(state); it should be already done :( */ |
| 328 |
18 |
| jump_over_space(state); |
| 329 |
18 |
▶ | if (state->cur_pos<state->next_to_end-2 && '-'==*(state->cur_pos) && '-'==*(state->cur_pos+1)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (state->cur_pos<state->next_to_end-2 && '-'==*(state->cur_pos) && '-'==*(state->cur_pos+1)) { |
18 |
0 |
18 |
| if (state->cur_pos<state->next_to_end-2 && '-'==*(state->cur_pos) && '-'==*(state->cur_pos+1)) { |
18 |
0 |
18 |
| if (state->cur_pos<state->next_to_end-2 && '-'==*(state->cur_pos) && '-'==*(state->cur_pos+1)) { |
18 |
0 |
18 |
|
| 330 |
18 |
| state->cur_pos+=2; |
| 331 |
|
| } |
| 332 |
|
| } |
| 333 |
|
| /* template tags could also be decorated as xml <tmpl_TAG /> */ |
| 334 |
3394 |
▶ | if (!is_tag_closed && '/'==*(state->cur_pos)) state->cur_pos++; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!is_tag_closed && '/'==*(state->cur_pos)) state->cur_pos++; |
2596 |
798 |
3394 |
| if (!is_tag_closed && '/'==*(state->cur_pos)) state->cur_pos++; |
4 |
2592 |
2596 |
|
| 335 |
|
| |
| 336 |
3394 |
▶ | if ('>'==*(state->cur_pos)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ('>'==*(state->cur_pos)) { |
3391 |
3 |
3394 |
|
| 337 |
3391 |
| state->cur_pos++; |
| 338 |
|
| } else { |
| 339 |
3 |
| state->param->found_syntax_error=1; |
| 340 |
3 |
| log_state(state,TMPL_LOG_ERROR,"end tag:found %c instead of > at pos " MOD_TD "\n", |
| 341 |
3 |
| *state->cur_pos, TO_PTRDIFF_T(state->cur_pos-state->top)); |
| 342 |
|
| } |
| 343 |
|
| /* flush run chars (if in SHOW mode) */ |
| 344 |
3394 |
▶ | if (state->is_visible) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (state->is_visible) { |
2485 |
909 |
3394 |
|
| 345 |
2485 |
| (state->param->WriterFuncPtr)(state->param->ext_writer_state,state->last_processed_pos,state->tag_start); |
| 346 |
2485 |
| state->last_processed_pos=state->cur_pos; |
| 347 |
|
| } |
| 348 |
3394 |
▶ | if (is_tag_closed) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_tag_closed) { |
798 |
2596 |
3394 |
|
| 349 |
798 |
| output_closetag_handler[tag_type](state,TagOptVal); |
| 350 |
|
| } else { |
| 351 |
2596 |
| output_opentag_handler[tag_type](state,TagOptVal); |
| 352 |
|
| } |
| 353 |
|
| } |
| 354 |
|
| |
| 355 |
|
| |
| 356 |
|
| /* max offset to ensure we are not out of file when try <!--/ */ |
| 357 |
|
| #define TAG_WIDTH_OFFSET 4 |
| 358 |
|
| static |
| 359 |
|
| void |
| 360 |
521 |
| process_state (struct tmplpro_state * state) |
| 361 |
|
| { |
| 362 |
|
| static const char* const metatag="tmpl_"; |
| 363 |
|
| static const char* const METATAG="TMPL_"; |
| 364 |
|
| int is_tag_closed; |
| 365 |
|
| int is_tag_commented; |
| 366 |
521 |
| register const char* const last_safe_pos=state->next_to_end-TAG_WIDTH_OFFSET; |
| 367 |
|
| /* constructor */ |
| 368 |
521 |
| tagstack_init(&(state->tag_stack)); |
| 369 |
|
| /* magic; 256 > 50 (50 is min.required for double to string conversion */ |
| 370 |
521 |
| pbuffer_init_as(&(state->expr_left_pbuffer), 256); |
| 371 |
521 |
| pbuffer_init_as(&(state->expr_right_pbuffer), 256); |
| 372 |
|
| |
| 373 |
524 |
▶ | if (debuglevel) tmpl_log(TMPL_LOG_DEBUG,"process_state:initiated at scope stack depth = %d\n", |
Branch: 1 branch
| Branch | True | False | Total |
| if (debuglevel) tmpl_log(TMPL_LOG_DEBUG,"process_state:initiated at scope stack depth = %d\n", |
3 |
518 |
521 |
|
| 374 |
3 |
| curScopeLevel(&state->param->var_scope_stack)); |
| 375 |
|
| |
| 376 |
6841 |
▶ | while (state->cur_pos < last_safe_pos) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (state->cur_pos < last_safe_pos) { |
5976 |
344 |
6320 |
|
| 377 |
5976 |
| register const char* cur_pos=state->cur_pos; |
| 378 |
60762 |
▶ | while ('<'!=*(cur_pos++)) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ('<'!=*(cur_pos++)) { |
54963 |
5799 |
60762 |
|
| 379 |
54963 |
▶ | if (cur_pos >= last_safe_pos) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cur_pos >= last_safe_pos) { |
177 |
54786 |
54963 |
|
| 380 |
177 |
| goto exit_mainloop; |
| 381 |
|
| } |
| 382 |
|
| }; |
| 383 |
5799 |
| state->tag_start=cur_pos-1; |
| 384 |
5799 |
| is_tag_closed=0; |
| 385 |
5799 |
| is_tag_commented=0; |
| 386 |
5799 |
| state->cur_pos=cur_pos; |
| 387 |
5799 |
▶ | if (('!'==*(cur_pos)) && ('-'==*(cur_pos+1)) && ('-'==*(cur_pos+2))) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (('!'==*(cur_pos)) && ('-'==*(cur_pos+1)) && ('-'==*(cur_pos+2))) { |
33 |
5766 |
5799 |
| if (('!'==*(cur_pos)) && ('-'==*(cur_pos+1)) && ('-'==*(cur_pos+2))) { |
28 |
5 |
33 |
| if (('!'==*(cur_pos)) && ('-'==*(cur_pos+1)) && ('-'==*(cur_pos+2))) { |
28 |
0 |
28 |
|
| 388 |
28 |
| state->cur_pos+=3; |
| 389 |
28 |
| jump_over_space(state); |
| 390 |
28 |
| is_tag_commented=1; |
| 391 |
|
| } |
| 392 |
5799 |
▶ | if ('/'==*(state->cur_pos)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ('/'==*(state->cur_pos)) { |
1918 |
3881 |
5799 |
|
| 393 |
1918 |
| state->cur_pos++; |
| 394 |
1918 |
| is_tag_closed=1; |
| 395 |
|
| } |
| 396 |
5799 |
▶ | if (is_string(state,metatag,METATAG)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_string(state,metatag,METATAG)) { |
2405 |
3394 |
5799 |
|
| 397 |
3394 |
| state->is_tag_commented=is_tag_commented; |
| 398 |
3394 |
| state->is_tag_closed=is_tag_closed; |
| 399 |
3394 |
| process_tmpl_tag(state); |
| 400 |
|
| } |
| 401 |
|
| } |
| 402 |
344 |
| exit_mainloop:; |
| 403 |
521 |
| (state->param->WriterFuncPtr)(state->param->ext_writer_state,state->last_processed_pos,state->next_to_end); |
| 404 |
|
| |
| 405 |
|
| /* destructor */ |
| 406 |
521 |
| pbuffer_free(&(state->expr_right_pbuffer)); |
| 407 |
521 |
| pbuffer_free(&(state->expr_left_pbuffer)); |
| 408 |
521 |
| tagstack_free(&(state->tag_stack)); |
| 409 |
521 |
▶ | if (debuglevel) tmpl_log(TMPL_LOG_DEBUG,"process_state:finished\n"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (debuglevel) tmpl_log(TMPL_LOG_DEBUG,"process_state:finished\n"); |
3 |
518 |
521 |
|
| 410 |
521 |
| } |
| 411 |
|
| |
| 412 |
|
| static |
| 413 |
|
| void |
| 414 |
521 |
| init_state (struct tmplpro_state *state, struct tmplpro_param *param) |
| 415 |
|
| { |
| 416 |
|
| /* initializing state */ |
| 417 |
521 |
| state->param=param; |
| 418 |
521 |
| state->last_processed_pos=state->top; |
| 419 |
521 |
| state->cur_pos=state->top; |
| 420 |
521 |
| state->tag=HTML_TEMPLATE_NO_TAG; |
| 421 |
521 |
| state->is_visible=1; |
| 422 |
521 |
| } |
| 423 |
|
| |
| 424 |
|
| static |
| 425 |
|
| int |
| 426 |
309 |
| tmplpro_exec_tmpl_filename (struct tmplpro_param *param, const char* filename) |
| 427 |
|
| { |
| 428 |
|
| struct tmplpro_state state; |
| 429 |
|
| int mmapstatus; |
| 430 |
|
| PSTRING memarea; |
| 431 |
309 |
| int retval = 0; |
| 432 |
|
| const char* saved_masterpath; |
| 433 |
|
| /* |
| 434 |
|
| * param->masterpath is path to upper level template |
| 435 |
|
| * (or NULL in toplevel) which called <include filename>. |
| 436 |
|
| * we use it to calculate filepath for filename. |
| 437 |
|
| * Then filename becames upper level template for its <include>. |
| 438 |
|
| */ |
| 439 |
309 |
| const char* filepath=(param->FindFileFuncPtr)(param->ext_findfile_state,filename, param->masterpath); |
| 440 |
309 |
▶ | if (NULL==filepath) return ERR_PRO_FILE_NOT_FOUND; |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL==filepath) return ERR_PRO_FILE_NOT_FOUND; |
0 |
309 |
309 |
|
| 441 |
|
| /* filepath should be alive for every nested template */ |
| 442 |
309 |
| filepath = strdup(filepath); |
| 443 |
309 |
▶ | if (NULL==filepath) return ERR_PRO_NOT_ENOUGH_MEMORY; |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL==filepath) return ERR_PRO_NOT_ENOUGH_MEMORY; |
0 |
309 |
309 |
|
| 444 |
309 |
| saved_masterpath=param->masterpath; /* saving current file name */ |
| 445 |
309 |
| param->masterpath=filepath; |
| 446 |
309 |
▶ | if (param->filters) memarea=(param->LoadFileFuncPtr)(param->ext_filter_state,filepath); |
Branch: 1 branch
| Branch | True | False | Total |
| if (param->filters) memarea=(param->LoadFileFuncPtr)(param->ext_filter_state,filepath); |
9 |
300 |
309 |
|
| 447 |
300 |
| else memarea=mmap_load_file(filepath); |
| 448 |
309 |
▶ | if (memarea.begin == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (memarea.begin == NULL) { |
0 |
309 |
309 |
|
| 449 |
0 |
| retval = ERR_PRO_CANT_OPEN_FILE; |
| 450 |
0 |
| goto cleanup_filepath; |
| 451 |
|
| } |
| 452 |
309 |
| state.top =memarea.begin; |
| 453 |
309 |
| state.next_to_end=memarea.endnext; |
| 454 |
309 |
▶ | if (memarea.begin < memarea.endnext) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (memarea.begin < memarea.endnext) { |
305 |
4 |
309 |
|
| 455 |
|
| /* to avoid crash with empty file */ |
| 456 |
305 |
| init_state(&state,param); |
| 457 |
305 |
▶ | if (debuglevel) log_state(&state,TMPL_LOG_DEBUG, "exec_tmpl: loading %s\n",filename); |
Branch: 1 branch
| Branch | True | False | Total |
| if (debuglevel) log_state(&state,TMPL_LOG_DEBUG, "exec_tmpl: loading %s\n",filename); |
2 |
303 |
305 |
|
| 458 |
305 |
| process_state(&state); |
| 459 |
|
| } |
| 460 |
|
| /* destroying */ |
| 461 |
309 |
▶ | if (param->filters) mmapstatus=(param->UnloadFileFuncPtr)(param->ext_filter_state,memarea); |
Branch: 1 branch
| Branch | True | False | Total |
| if (param->filters) mmapstatus=(param->UnloadFileFuncPtr)(param->ext_filter_state,memarea); |
9 |
300 |
309 |
|
| 462 |
300 |
| else mmapstatus=mmap_unload_file(memarea); |
| 463 |
309 |
▶ | if (mmapstatus && debuglevel) log_state(&state,TMPL_LOG_DEBUG, "exec_tmpl: unloading %s caused munmap error\n",filename); |
Branch: 2 branches
| Branch | True | False | Total |
| if (mmapstatus && debuglevel) log_state(&state,TMPL_LOG_DEBUG, "exec_tmpl: unloading %s caused munmap error\n",filename); |
305 |
4 |
309 |
| if (mmapstatus && debuglevel) log_state(&state,TMPL_LOG_DEBUG, "exec_tmpl: unloading %s caused munmap error\n",filename); |
4 |
0 |
4 |
|
| 464 |
309 |
| cleanup_filepath: |
| 465 |
309 |
▶ | if (filepath!=NULL) free((void*) filepath); |
Branch: 1 branch
| Branch | True | False | Total |
| if (filepath!=NULL) free((void*) filepath); |
309 |
0 |
309 |
|
| 466 |
309 |
| param->masterpath=saved_masterpath; |
| 467 |
309 |
| return retval; |
| 468 |
|
| } |
| 469 |
|
| |
| 470 |
|
| static |
| 471 |
|
| int |
| 472 |
216 |
| tmplpro_exec_tmpl_scalarref (struct tmplpro_param *param, PSTRING memarea) |
| 473 |
|
| { |
| 474 |
|
| struct tmplpro_state state; |
| 475 |
216 |
| const char* saved_masterpath=param->masterpath; /* saving current file name */ |
| 476 |
216 |
| param->masterpath=NULL; /* no upper file */ |
| 477 |
216 |
| state.top = memarea.begin; |
| 478 |
216 |
| state.next_to_end=memarea.endnext; |
| 479 |
216 |
▶ | if (memarea.begin != memarea.endnext) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (memarea.begin != memarea.endnext) { |
216 |
0 |
216 |
|
| 480 |
216 |
| init_state(&state,param); |
| 481 |
216 |
| process_state(&state); |
| 482 |
|
| } |
| 483 |
|
| /* exit cleanup code */ |
| 484 |
216 |
| param->masterpath=saved_masterpath; |
| 485 |
216 |
| return 0; |
| 486 |
|
| } |
| 487 |
|
| |
| 488 |
|
| #include "builtin_findfile.inc" |
| 489 |
|
| #include "callback_stubs.inc" |
| 490 |
|
| |
| 491 |
|
| API_IMPL |
| 492 |
|
| int |
| 493 |
|
| APICALL |
| 494 |
448 |
| tmplpro_exec_tmpl (struct tmplpro_param *param) |
| 495 |
|
| { |
| 496 |
448 |
| int exitcode=0; |
| 497 |
448 |
| param->htp_errno=0; |
| 498 |
448 |
▶ | if (param->GetAbstractValFuncPtr==NULL || |
Branch: 1 branch
| Branch | True | False | Total |
| if (param->GetAbstractValFuncPtr==NULL || |
448 |
0 |
448 |
|
| 499 |
448 |
▶ | param->AbstractVal2pstringFuncPtr==NULL || |
Branch: 1 branch
| Branch | True | False | Total |
| param->AbstractVal2pstringFuncPtr==NULL || |
448 |
0 |
448 |
|
| 500 |
448 |
▶ | param->AbstractVal2abstractArrayFuncPtr==NULL || |
Branch: 1 branch
| Branch | True | False | Total |
| param->AbstractVal2abstractArrayFuncPtr==NULL || |
448 |
0 |
448 |
|
| 501 |
|
| /*param->GetAbstractArrayLengthFuncPtr==NULL ||*/ |
| 502 |
448 |
▶ | param->GetAbstractMapFuncPtr==NULL || |
Branch: 1 branch
| Branch | True | False | Total |
| param->GetAbstractMapFuncPtr==NULL || |
448 |
0 |
448 |
|
| 503 |
448 |
▶ | (param->IsExprUserfncFuncPtr!=NULL && param->IsExprUserfncFuncPtr != stub_is_expr_userfnc_func && |
Branch: 2 branches
| Branch | True | False | Total |
| (param->IsExprUserfncFuncPtr!=NULL && param->IsExprUserfncFuncPtr != stub_is_expr_userfnc_func && |
448 |
0 |
448 |
| (param->IsExprUserfncFuncPtr!=NULL && param->IsExprUserfncFuncPtr != stub_is_expr_userfnc_func && |
448 |
0 |
448 |
|
| 504 |
448 |
▶ | (param->InitExprArglistFuncPtr==NULL || |
Branch: 1 branch
| Branch | True | False | Total |
| (param->InitExprArglistFuncPtr==NULL || |
448 |
0 |
448 |
|
| 505 |
448 |
▶ | param->PushExprArglistFuncPtr==NULL || |
Branch: 1 branch
| Branch | True | False | Total |
| param->PushExprArglistFuncPtr==NULL || |
448 |
0 |
448 |
|
| 506 |
448 |
▶ | param->FreeExprArglistFuncPtr==NULL || |
Branch: 1 branch
| Branch | True | False | Total |
| param->FreeExprArglistFuncPtr==NULL || |
448 |
0 |
448 |
|
| 507 |
448 |
▶ | param->CallExprUserfncFuncPtr==NULL)) |
Branch: 1 branch
| Branch | True | False | Total |
| param->CallExprUserfncFuncPtr==NULL)) |
0 |
448 |
448 |
|
| 508 |
|
| ) |
| 509 |
|
| { |
| 510 |
0 |
| tmpl_log(TMPL_LOG_ERROR,"tmplpro_exec_tmpl: required callbacks are missing:"); |
| 511 |
0 |
▶ | if (param->GetAbstractValFuncPtr==NULL) tmpl_log(TMPL_LOG_ERROR," GetAbstractValFuncPtr"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (param->GetAbstractValFuncPtr==NULL) tmpl_log(TMPL_LOG_ERROR," GetAbstractValFuncPtr"); |
0 |
0 |
0 |
|
| 512 |
0 |
▶ | if (param->AbstractVal2pstringFuncPtr==NULL) tmpl_log(TMPL_LOG_ERROR," AbstractVal2pstringFuncPtr"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (param->AbstractVal2pstringFuncPtr==NULL) tmpl_log(TMPL_LOG_ERROR," AbstractVal2pstringFuncPtr"); |
0 |
0 |
0 |
|
| 513 |
0 |
▶ | if (param->AbstractVal2abstractArrayFuncPtr==NULL) tmpl_log(TMPL_LOG_ERROR," AbstractVal2abstractArrayFuncPtr"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (param->AbstractVal2abstractArrayFuncPtr==NULL) tmpl_log(TMPL_LOG_ERROR," AbstractVal2abstractArrayFuncPtr"); |
0 |
0 |
0 |
|
| 514 |
0 |
▶ | if (param->GetAbstractMapFuncPtr==NULL) tmpl_log(TMPL_LOG_ERROR," GetAbstractMapFuncPtr"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (param->GetAbstractMapFuncPtr==NULL) tmpl_log(TMPL_LOG_ERROR," GetAbstractMapFuncPtr"); |
0 |
0 |
0 |
|
| 515 |
0 |
▶ | if ((param->IsExprUserfncFuncPtr!=NULL && |
Branch: 1 branch
| Branch | True | False | Total |
| if ((param->IsExprUserfncFuncPtr!=NULL && |
0 |
0 |
0 |
|
| 516 |
0 |
▶ | (param->InitExprArglistFuncPtr==NULL || |
Branch: 1 branch
| Branch | True | False | Total |
| (param->InitExprArglistFuncPtr==NULL || |
0 |
0 |
0 |
|
| 517 |
0 |
▶ | param->PushExprArglistFuncPtr==NULL || |
Branch: 1 branch
| Branch | True | False | Total |
| param->PushExprArglistFuncPtr==NULL || |
0 |
0 |
0 |
|
| 518 |
0 |
▶ | param->FreeExprArglistFuncPtr==NULL || |
Branch: 1 branch
| Branch | True | False | Total |
| param->FreeExprArglistFuncPtr==NULL || |
0 |
0 |
0 |
|
| 519 |
0 |
▶ | param->CallExprUserfncFuncPtr==NULL)) |
Branch: 1 branch
| Branch | True | False | Total |
| param->CallExprUserfncFuncPtr==NULL)) |
0 |
0 |
0 |
|
| 520 |
0 |
| ) tmpl_log(TMPL_LOG_ERROR," one of the Expr callbacks"); |
| 521 |
0 |
| tmpl_log(TMPL_LOG_ERROR,". The library is not initialized properly.\n"); |
| 522 |
0 |
| return ERR_PRO_INVALID_ARGUMENT; |
| 523 |
|
| } |
| 524 |
448 |
▶ | if (param->filters && |
Branch: 1 branch
| Branch | True | False | Total |
| if (param->filters && |
5 |
443 |
448 |
|
| 525 |
5 |
▶ | (param->LoadFileFuncPtr==NULL || |
Branch: 1 branch
| Branch | True | False | Total |
| (param->LoadFileFuncPtr==NULL || |
5 |
0 |
5 |
|
| 526 |
5 |
▶ | param->UnloadFileFuncPtr==NULL)) { |
Branch: 1 branch
| Branch | True | False | Total |
| param->UnloadFileFuncPtr==NULL)) { |
0 |
5 |
5 |
|
| 527 |
0 |
| tmpl_log(TMPL_LOG_ERROR,"tmplpro_exec_tmpl: filters is set but filter callbacks are missing.\n"); |
| 528 |
|
| } |
| 529 |
|
| /* set up stabs */ |
| 530 |
448 |
▶ | if (NULL==param->WriterFuncPtr) param->WriterFuncPtr = stub_write_chars_to_stdout; |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL==param->WriterFuncPtr) param->WriterFuncPtr = stub_write_chars_to_stdout; |
0 |
448 |
448 |
|
| 531 |
448 |
▶ | if (NULL==param->ext_findfile_state) param->ext_findfile_state = param; |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL==param->ext_findfile_state) param->ext_findfile_state = param; |
0 |
448 |
448 |
|
| 532 |
448 |
▶ | if (NULL==param->FindFileFuncPtr) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL==param->FindFileFuncPtr) { |
448 |
0 |
448 |
|
| 533 |
448 |
| param->FindFileFuncPtr = stub_find_file_func; |
| 534 |
448 |
| param->ext_findfile_state = param; |
| 535 |
|
| /*pbuffer_init(¶m->builtin_findfile_buffer);*/ |
| 536 |
|
| } |
| 537 |
448 |
▶ | if (NULL==param->IsExprUserfncFuncPtr) param->IsExprUserfncFuncPtr = stub_is_expr_userfnc_func; |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL==param->IsExprUserfncFuncPtr) param->IsExprUserfncFuncPtr = stub_is_expr_userfnc_func; |
0 |
448 |
448 |
|
| 538 |
448 |
▶ | if (NULL==param->LoadFileFuncPtr) param->LoadFileFuncPtr = stub_load_file_func; |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL==param->LoadFileFuncPtr) param->LoadFileFuncPtr = stub_load_file_func; |
0 |
448 |
448 |
|
| 539 |
448 |
▶ | if (NULL==param->UnloadFileFuncPtr) param->UnloadFileFuncPtr = stub_unload_file_func; |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL==param->UnloadFileFuncPtr) param->UnloadFileFuncPtr = stub_unload_file_func; |
0 |
448 |
448 |
|
| 540 |
448 |
▶ | if (NULL==param->GetAbstractArrayLengthFuncPtr) param->GetAbstractArrayLengthFuncPtr = stub_get_ABSTRACT_ARRAY_length_func; |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL==param->GetAbstractArrayLengthFuncPtr) param->GetAbstractArrayLengthFuncPtr = stub_get_ABSTRACT_ARRAY_length_func; |
0 |
448 |
448 |
|
| 541 |
|
| |
| 542 |
448 |
| Scope_reset(¶m->var_scope_stack, param->param_map_count); |
| 543 |
|
| /* reset other internals */ |
| 544 |
448 |
| param->cur_includes=0; /* internal counter of include depth */ |
| 545 |
448 |
| param->found_syntax_error=0; |
| 546 |
|
| /*masterpath=NULL;*/ |
| 547 |
|
| |
| 548 |
|
| |
| 549 |
|
| /* TODO: hackaround;*/ |
| 550 |
448 |
| debuglevel=param->debug; |
| 551 |
448 |
| tmpl_log_set_level(debuglevel); |
| 552 |
|
| |
| 553 |
448 |
▶ | if (param->scalarref.begin) exitcode = tmplpro_exec_tmpl_scalarref(param, param->scalarref); |
Branch: 1 branch
| Branch | True | False | Total |
| if (param->scalarref.begin) exitcode = tmplpro_exec_tmpl_scalarref(param, param->scalarref); |
216 |
232 |
448 |
|
| 554 |
232 |
▶ | else if (param->filename) exitcode = tmplpro_exec_tmpl_filename(param, param->filename); |
Branch: 1 branch
| Branch | True | False | Total |
| else if (param->filename) exitcode = tmplpro_exec_tmpl_filename(param, param->filename); |
232 |
0 |
232 |
|
| 555 |
|
| else { |
| 556 |
0 |
| tmpl_log(TMPL_LOG_ERROR,"tmplpro_exec_tmpl: neither scalarref nor filename was specified.\n"); |
| 557 |
0 |
| exitcode = ERR_PRO_INVALID_ARGUMENT; |
| 558 |
|
| } |
| 559 |
448 |
▶ | if (param->strict && param->found_syntax_error && 0==exitcode) exitcode = ERR_PRO_TEMPLATE_SYNTAX_ERROR; |
Branch: 3 branches
| Branch | True | False | Total |
| if (param->strict && param->found_syntax_error && 0==exitcode) exitcode = ERR_PRO_TEMPLATE_SYNTAX_ERROR; |
0 |
448 |
448 |
| if (param->strict && param->found_syntax_error && 0==exitcode) exitcode = ERR_PRO_TEMPLATE_SYNTAX_ERROR; |
0 |
0 |
0 |
| if (param->strict && param->found_syntax_error && 0==exitcode) exitcode = ERR_PRO_TEMPLATE_SYNTAX_ERROR; |
0 |
0 |
0 |
|
| 560 |
448 |
| param->htp_errno=exitcode; |
| 561 |
448 |
| return exitcode; |
| 562 |
|
| } |
| 563 |
|
| |
| 564 |
|
| API_IMPL |
| 565 |
|
| PSTRING |
| 566 |
|
| APICALL |
| 567 |
0 |
| tmplpro_tmpl2pstring (struct tmplpro_param *param, int *retvalptr) |
| 568 |
|
| { |
| 569 |
|
| int exitcode; |
| 570 |
|
| PSTRING retval; |
| 571 |
|
| struct builtin_writer_state state; |
| 572 |
0 |
| writer_functype save_writer_func = param->WriterFuncPtr; |
| 573 |
0 |
| ABSTRACT_WRITER* save_writer_state = param->ext_writer_state; |
| 574 |
0 |
| param->WriterFuncPtr = stub_write_chars_to_pbuffer; |
| 575 |
0 |
| param->ext_writer_state = &state; |
| 576 |
0 |
| state.bufptr=¶m->builtin_tmpl2string_buffer; |
| 577 |
0 |
| pbuffer_resize(state.bufptr, 4000); |
| 578 |
0 |
| state.size = 0; |
| 579 |
0 |
| exitcode = tmplpro_exec_tmpl (param); |
| 580 |
0 |
| param->WriterFuncPtr = save_writer_func; |
| 581 |
0 |
| param->ext_writer_state = save_writer_state; |
| 582 |
0 |
▶ | if (NULL!=retvalptr) *retvalptr=exitcode; |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL!=retvalptr) *retvalptr=exitcode; |
0 |
0 |
0 |
|
| 583 |
0 |
| retval.begin = pbuffer_string(state.bufptr); |
| 584 |
0 |
| retval.endnext = retval.begin+state.size; |
| 585 |
0 |
| *((char*) retval.endnext)='\0'; |
| 586 |
0 |
| return retval; |
| 587 |
|
| } |
| 588 |
|
| |
| 589 |
|
| API_IMPL |
| 590 |
|
| void |
| 591 |
|
| APICALL |
| 592 |
448 |
| tmplpro_clear_option_param_map(struct tmplpro_param *param) |
| 593 |
|
| { |
| 594 |
448 |
| param->param_map_count=0; |
| 595 |
448 |
| Scope_reset(¶m->var_scope_stack,param->param_map_count); |
| 596 |
448 |
| } |
| 597 |
|
| |
| 598 |
|
| API_IMPL |
| 599 |
|
| int |
| 600 |
|
| APICALL |
| 601 |
449 |
| tmplpro_push_option_param_map(struct tmplpro_param *param, ABSTRACT_MAP* map, EXPR_int64 flags) |
| 602 |
|
| { |
| 603 |
449 |
| pushScopeMap(¶m->var_scope_stack, map, (int) flags); |
| 604 |
449 |
| return ++(param->param_map_count); |
| 605 |
|
| } |
| 606 |
|
| |
| 607 |
|
| API_IMPL |
| 608 |
|
| int |
| 609 |
|
| APICALL |
| 610 |
0 |
| tmplpro_count_option_param_map(struct tmplpro_param *param) |
| 611 |
|
| { |
| 612 |
0 |
| return param->param_map_count; |
| 613 |
|
| } |
| 614 |
|
| |
| 615 |
|
| |
| 616 |
|
| API_IMPL |
| 617 |
|
| void |
| 618 |
|
| APICALL |
| 619 |
14 |
| tmplpro_procore_init(void) |
| 620 |
|
| { |
| 621 |
14 |
| } |
| 622 |
|
| |
| 623 |
|
| API_IMPL |
| 624 |
|
| void |
| 625 |
|
| APICALL |
| 626 |
0 |
| tmplpro_procore_done(void) |
| 627 |
|
| { |
| 628 |
0 |
| } |
| 629 |
|
| |
| 630 |
|
| /* internal initialization of struct tmplpro_param */ |
| 631 |
|
| API_IMPL |
| 632 |
|
| struct tmplpro_param* |
| 633 |
|
| APICALL |
| 634 |
448 |
| tmplpro_param_init(void) |
| 635 |
|
| { |
| 636 |
448 |
| struct tmplpro_param* param=(struct tmplpro_param*) malloc (sizeof(struct tmplpro_param)); |
| 637 |
448 |
▶ | if (param==NULL) return param; |
Branch: 1 branch
| Branch | True | False | Total |
| if (param==NULL) return param; |
0 |
448 |
448 |
|
| 638 |
|
| /* filling initial struct tmplpro_param with 0 */ |
| 639 |
448 |
| memset (param, 0, sizeof(struct tmplpro_param)); |
| 640 |
|
| /* current level of inclusion */ |
| 641 |
|
| /* param->cur_includes=0; */ |
| 642 |
|
| /* not to use external file loader */ |
| 643 |
|
| /* param->filters=0; |
| 644 |
|
| param->default_escape=HTML_TEMPLATE_OPT_ESCAPE_NO; |
| 645 |
|
| param->masterpath=NULL; *//* we are not included by something *//* |
| 646 |
|
| param->expr_func_map=NULL; |
| 647 |
|
| param->expr_func_arglist=NULL; |
| 648 |
|
| */ |
| 649 |
448 |
| _reset_int_options_set_nonzero_defaults(param); |
| 650 |
448 |
| Scope_init(¶m->var_scope_stack); |
| 651 |
|
| /* no need for them due to memset 0 |
| 652 |
|
| pbuffer_preinit(¶m->builtin_findfile_buffer); |
| 653 |
|
| pbuffer_preinit(¶m->builtin_tmpl2string_buffer); |
| 654 |
|
| pbuffer_preinit(¶m->lowercase_varname_buffer); |
| 655 |
|
| pbuffer_preinit(¶m->uppercase_varname_buffer); |
| 656 |
|
| pbuffer_preinit(¶m->escape_pstring_buffer); |
| 657 |
|
| */ |
| 658 |
448 |
| return param; |
| 659 |
|
| } |
| 660 |
|
| |
| 661 |
|
| API_IMPL |
| 662 |
|
| void |
| 663 |
|
| APICALL |
| 664 |
448 |
| tmplpro_param_free(struct tmplpro_param* param) |
| 665 |
|
| { |
| 666 |
448 |
| pbuffer_free(¶m->builtin_findfile_buffer); |
| 667 |
448 |
| pbuffer_free(¶m->builtin_tmpl2string_buffer); |
| 668 |
448 |
| pbuffer_free(¶m->lowercase_varname_buffer); |
| 669 |
448 |
| pbuffer_free(¶m->uppercase_varname_buffer); |
| 670 |
448 |
| pbuffer_free(¶m->escape_pstring_buffer); |
| 671 |
448 |
| Scope_free(¶m->var_scope_stack); |
| 672 |
448 |
| free(param); |
| 673 |
448 |
| } |
| 674 |
|
| |
| 675 |
|
| API_IMPL |
| 676 |
|
| int |
| 677 |
|
| APICALL |
| 678 |
0 |
| tmplpro_errno(struct tmplpro_param* param) |
| 679 |
|
| { |
| 680 |
0 |
| return param->htp_errno; |
| 681 |
|
| } |
| 682 |
|
| |
| 683 |
|
| API_IMPL |
| 684 |
|
| const char* |
| 685 |
|
| APICALL |
| 686 |
0 |
| tmplpro_errmsg(struct tmplpro_param* param) |
| 687 |
|
| { |
| 688 |
0 |
| return errlist[param->htp_errno]; |
| 689 |
|
| } |
| 690 |
|
| |
| 691 |
|
| API_IMPL |
| 692 |
|
| int |
| 693 |
|
| APICALL |
| 694 |
0 |
| tmplpro_set_log_file(struct tmplpro_param* param, const char* logfilename) |
| 695 |
|
| { |
| 696 |
|
| FILE *file_p; |
| 697 |
0 |
▶ | if (NULL==logfilename) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL==logfilename) { |
0 |
0 |
0 |
|
| 698 |
0 |
▶ | if (tmpl_log_stream!=NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tmpl_log_stream!=NULL) { |
0 |
0 |
0 |
|
| 699 |
0 |
| fclose(tmpl_log_stream); |
| 700 |
0 |
| tmpl_log_stream=NULL; |
| 701 |
|
| } |
| 702 |
0 |
| tmpl_log_set_callback(tmpl_log_default_callback); |
| 703 |
0 |
| return 0; |
| 704 |
|
| } |
| 705 |
0 |
| file_p = fopen(logfilename, "a"); |
| 706 |
0 |
▶ | if (!file_p) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!file_p) { |
0 |
0 |
0 |
|
| 707 |
0 |
| tmpl_log(TMPL_LOG_ERROR,"tmplpro_set_log_file: can't create log file [%s]\n",logfilename); |
| 708 |
0 |
| return ERR_PRO_FILE_NOT_FOUND; |
| 709 |
|
| } else { |
| 710 |
0 |
▶ | if (tmpl_log_stream!=NULL) fclose(tmpl_log_stream); |
Branch: 1 branch
| Branch | True | False | Total |
| if (tmpl_log_stream!=NULL) fclose(tmpl_log_stream); |
0 |
0 |
0 |
|
| 711 |
0 |
| tmpl_log_stream=file_p; |
| 712 |
0 |
| tmpl_log_set_callback(tmpl_log_stream_callback); |
| 713 |
0 |
| return 0; |
| 714 |
|
| } |
| 715 |
|
| } |
| 716 |
|
| |
| 717 |
|
| API_IMPL |
| 718 |
|
| size_t |
| 719 |
|
| APICALL |
| 720 |
0 |
| tmplpro_param_allocated_memory_info(struct tmplpro_param* param) |
| 721 |
|
| { |
| 722 |
|
| return 0L + |
| 723 |
0 |
| pbuffer_size(¶m->builtin_findfile_buffer) + |
| 724 |
0 |
| pbuffer_size(¶m->builtin_tmpl2string_buffer) + |
| 725 |
0 |
| pbuffer_size(¶m->lowercase_varname_buffer) + |
| 726 |
0 |
| pbuffer_size(¶m->uppercase_varname_buffer) + |
| 727 |
0 |
| pbuffer_size(¶m->escape_pstring_buffer) + |
| 728 |
0 |
| (1+curScopeLevel(¶m->var_scope_stack)) * sizeof(struct scope_stack); |
| 729 |
|
| } |
| 730 |
|
| |
| 731 |
|
| #include "tagstack.inc" |
| 732 |
|
| |
| 733 |
|
| /* |
| 734 |
|
| * Local Variables: |
| 735 |
|
| * mode: c |
| 736 |
|
| * End: |
| 737 |
|
| */ |