00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "config.h"
00018 #include "defines.h"
00019
00020 #include <dlfcn.h>
00021 #include <stdlib.h>
00022 #include <stdio.h>
00023 #include <time.h>
00024
00025 #include <string.h>
00026
00027 #include "utils.h"
00028 #include "hashlib.h"
00029 #include "template.h"
00030
00031
00032 #ifndef DOXYGEN
00033
00034
00035
00036
00037
00038
00039
00040
00041 void tpl_cf_cleanup_var(void *data) {
00042 t_cf_tpl_variable *v = (t_cf_tpl_variable *)data;
00043
00044 str_cleanup(v->data);
00045 free(v->data);
00046 }
00047 #endif
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 int tpl_cf_init(t_cf_template *tpl,const u_char *fname) {
00059 if((tpl->tpl = dlopen(fname,RTLD_LAZY)) == NULL) {
00060 fprintf(stderr,"%s\n",dlerror());
00061 return -1;
00062 }
00063
00064 str_init(&tpl->parsed);
00065
00066 tpl->varlist = cf_hash_new(tpl_cf_cleanup_var);
00067
00068 return 0;
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 void tpl_cf_setvar(t_cf_template *tpl,u_char *vname,const u_char *value,int len,int escapehtml) {
00083 t_cf_tpl_variable var;
00084
00085 var.data = fo_alloc(NULL,1,sizeof(t_string),FO_ALLOC_CALLOC);
00086 var.escape_html = escapehtml;
00087
00088 str_char_set(var.data,value,len);
00089
00090 cf_hash_set(tpl->varlist,vname,strlen(vname),&var,sizeof(t_cf_tpl_variable));
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 int tpl_cf_appendvar(t_cf_template *tpl,u_char *vname,const u_char *value,int len) {
00105 t_cf_tpl_variable *var = (t_cf_tpl_variable *)cf_hash_get(tpl->varlist,vname,strlen(vname));
00106
00107 if(var) {
00108 str_chars_append(var->data,value,len);
00109 return 0;
00110 }
00111
00112 return -1;
00113 }
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 void tpl_cf_freevar(t_cf_template *tpl,u_char *vname) {
00125 cf_hash_entry_delete(tpl->varlist,vname,strlen(vname));
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 void tpl_cf_parse(t_cf_template *tpl) {
00137 void *pa = dlsym(tpl->tpl,"parse");
00138
00139 if(pa) {
00140 t_parse x = (t_parse)pa;
00141 x(tpl);
00142 }
00143 }
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 void tpl_cf_parse_to_mem(t_cf_template *tpl) {
00155 void *pa = dlsym(tpl->tpl,"parse_to_mem");
00156
00157 if(pa) {
00158 t_parse_mem x = (t_parse_mem)pa;
00159 x(tpl);
00160 }
00161 }
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 void tpl_cf_finish(t_cf_template *tpl) {
00172 dlclose(tpl->tpl);
00173 str_cleanup(&tpl->parsed);
00174 cf_hash_destroy(tpl->varlist);
00175 }
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 const t_cf_tpl_variable *tpl_cf_getvar(t_cf_template *tpl,u_char *name) {
00188 t_cf_tpl_variable *var = (t_cf_tpl_variable *)cf_hash_get(tpl->varlist,name,strlen(name));
00189
00190 return (const t_cf_tpl_variable *)var;
00191 }
00192
00193