00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "config.h"
00019 #include "defines.h"
00020
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <ctype.h>
00025 #include <time.h>
00026 #include <sys/types.h>
00027
00028 #include "readline.h"
00029 #include "hashlib.h"
00030 #include "utils.h"
00031 #include "configparser.h"
00032 #include "cfcgi.h"
00033 #include "template.h"
00034 #include "clientlib.h"
00035
00036
00037 struct {
00038 u_char *FontColor;
00039 u_char *FontSize;
00040 u_char *FontFamily;
00041 long AutoReload;
00042 u_char *BaseTarget;
00043 u_char *QuoteColorF;
00044 u_char *QuoteColorB;
00045 } Cfg = { NULL, NULL, NULL, 0, NULL, NULL, NULL };
00046
00047 int execute_filter(t_cf_hash *head,t_configuration *dc,t_configuration *vc,t_cf_template *begin,t_cf_template *end) {
00048 t_name_value *ubase = cfg_get_value(dc,"UBaseURL");
00049 t_name_value *cs = cfg_get_value(dc,"ExternCharset");
00050 u_char *UserName = cf_hash_get(GlobalValues,"UserName",8);
00051
00052 cf_set_variable(begin,cs,"ubase",ubase->values[0],strlen(ubase->values[0]),1);
00053
00054 if(UserName) {
00055 t_name_value *ucfg = cfg_get_value(dc,"UserConfig");
00056
00057 tpl_cf_setvar(begin,"authed","1",1,0);
00058 if(ucfg) {
00059 cf_set_variable(begin,cs,"userconfig",ucfg->values[0],strlen(ucfg->values[0]),1);
00060 }
00061
00062 if((Cfg.FontColor && *Cfg.FontColor) || (Cfg.FontSize && *Cfg.FontSize) || (Cfg.FontFamily && *Cfg.FontFamily)) {
00063 tpl_cf_setvar(begin,"font","1",1,0);
00064
00065 if(Cfg.FontColor && *Cfg.FontColor) {
00066 cf_set_variable(begin,cs,"fontcolor",Cfg.FontColor,strlen(Cfg.FontColor),1);
00067 }
00068 if(Cfg.FontSize && *Cfg.FontSize) {
00069 cf_set_variable(begin,cs,"fontsize",Cfg.FontSize,strlen(Cfg.FontSize),1);
00070 }
00071 if(Cfg.FontFamily && *Cfg.FontFamily) {
00072 cf_set_variable(begin,cs,"fontfamily",Cfg.FontFamily,strlen(Cfg.FontFamily),1);
00073 }
00074
00075 }
00076
00077 if(Cfg.AutoReload) {
00078 u_char buff[20];
00079 time_t tm = time(NULL);
00080 int len = 0;
00081 int n = sprintf(buff,"%ld",Cfg.AutoReload);
00082 u_char *time;
00083
00084 tm += (time_t)Cfg.AutoReload;
00085 time = get_time(vc,"DateFormatLoadTime",&len,&tm);
00086
00087 cf_set_variable(begin,cs,"autoreload",buff,n,1);
00088 cf_set_variable(begin,cs,"autoreloadtime",time,len,1);
00089
00090 free(time);
00091 }
00092
00093 return FLT_OK;
00094 }
00095 else {
00096 t_name_value *ucfg = cfg_get_value(dc,"UserRegister");
00097 if(ucfg) {
00098 cf_set_variable(begin,cs,"userconfig",ucfg->values[0],strlen(ucfg->values[0]),1);
00099 }
00100 }
00101
00102 return FLT_DECLINE;
00103 }
00104
00105 int flt_basic_handle_posting(t_cf_hash *head,t_configuration *dc,t_configuration *vc,t_cl_thread *thr,t_cf_template *tpl) {
00106 t_name_value *cs = cfg_get_value(dc,"ExternCharset");
00107 u_char *UserName = cf_hash_get(GlobalValues,"UserName",8);
00108
00109 if(UserName) {
00110 if((Cfg.FontColor && *Cfg.FontColor) || (Cfg.FontSize && *Cfg.FontSize) || (Cfg.FontFamily && *Cfg.FontFamily) || (Cfg.QuoteColorF && *Cfg.QuoteColorF) || (Cfg.QuoteColorB && *Cfg.QuoteColorB)) {
00111 tpl_cf_setvar(tpl,"font","1",1,0);
00112
00113 if(Cfg.FontColor && *Cfg.FontColor) {
00114 cf_set_variable(tpl,cs,"fontcolor",Cfg.FontColor,strlen(Cfg.FontColor),1);
00115 }
00116 if(Cfg.FontSize && *Cfg.FontSize) {
00117 cf_set_variable(tpl,cs,"fontsize",Cfg.FontSize,strlen(Cfg.FontSize),1);
00118 }
00119 if(Cfg.FontFamily && *Cfg.FontFamily) {
00120 cf_set_variable(tpl,cs,"fontfamily",Cfg.FontFamily,strlen(Cfg.FontFamily),1);
00121 }
00122 if(Cfg.QuoteColorF && *Cfg.QuoteColorF) {
00123 cf_set_variable(tpl,cs,"qcolor",Cfg.QuoteColorF,strlen(Cfg.QuoteColorF),1);
00124 }
00125 if(Cfg.QuoteColorB && *Cfg.QuoteColorB) {
00126 cf_set_variable(tpl,cs,"qcolorback",Cfg.QuoteColorB,strlen(Cfg.QuoteColorB),1);
00127 }
00128
00129 }
00130
00131 return FLT_OK;
00132 }
00133
00134 return FLT_DECLINE;
00135 }
00136
00137 int flt_basic_set_target(t_cf_hash *head,t_configuration *dc,t_configuration *vc,t_message *msg,unsigned long long tid,int mode) {
00138 t_name_value *cs = cfg_get_value(dc,"ExternCharset");
00139
00140 if(Cfg.BaseTarget && *Cfg.BaseTarget && mode == 0) {
00141 cf_set_variable(&msg->tpl,cs,"target",Cfg.BaseTarget,strlen(Cfg.BaseTarget),1);
00142 return FLT_OK;
00143 }
00144
00145 return FLT_DECLINE;
00146 }
00147
00148 int flt_basic_handle_command(t_configfile *cfile,t_conf_opt *opt,u_char **args,int argnum) {
00149 if(cf_strcmp(opt->name,"FontColor") == 0) {
00150 if(Cfg.FontColor) free(Cfg.FontColor);
00151 Cfg.FontColor = strdup(args[0]);
00152 }
00153 else if(cf_strcmp(opt->name,"FontSize") == 0) {
00154 if(Cfg.FontSize) free(Cfg.FontSize);
00155 Cfg.FontSize = strdup(args[0]);
00156 }
00157 else if(cf_strcmp(opt->name,"FontFamily") == 0) {
00158 if(Cfg.FontFamily) free(Cfg.FontFamily);
00159 Cfg.FontFamily = strdup(args[0]);
00160 }
00161 else if(cf_strcmp(opt->name,"AutoReload") == 0) {
00162 Cfg.AutoReload = strtol(args[0],NULL,10) * 60L;
00163 }
00164 else if(cf_strcmp(opt->name,"BaseTarget") == 0) {
00165 if(Cfg.BaseTarget) free(Cfg.BaseTarget);
00166 Cfg.BaseTarget = strdup(args[0]);
00167 }
00168 else if(cf_strcmp(opt->name,"QuoteColor") == 0) {
00169 if(Cfg.QuoteColorF) free(Cfg.QuoteColorF);
00170 if(Cfg.QuoteColorB) free(Cfg.QuoteColorB);
00171 Cfg.QuoteColorF = strdup(args[0]);
00172 Cfg.QuoteColorB = strdup(args[1]);
00173 }
00174
00175 return 0;
00176 }
00177
00178 void flt_basic_cleanup(void) {
00179 if(Cfg.FontColor) free(Cfg.FontColor);
00180 if(Cfg.FontSize) free(Cfg.FontSize);
00181 if(Cfg.FontFamily) free(Cfg.FontFamily);
00182 if(Cfg.BaseTarget) free(Cfg.BaseTarget);
00183 if(Cfg.QuoteColorF) free(Cfg.QuoteColorF);
00184 if(Cfg.QuoteColorB) free(Cfg.QuoteColorB);
00185 }
00186
00187 t_conf_opt flt_basic_config[] = {
00188 { "FontColor", flt_basic_handle_command, NULL },
00189 { "FontSize", flt_basic_handle_command, NULL },
00190 { "FontFamily", flt_basic_handle_command, NULL },
00191 { "AutoReload", flt_basic_handle_command, NULL },
00192 { "BaseTarget", flt_basic_handle_command, NULL },
00193 { "QuoteColor", flt_basic_handle_command, NULL },
00194 { NULL, NULL, NULL }
00195 };
00196
00197 t_handler_config flt_basic_handlers[] = {
00198 { VIEW_INIT_HANDLER, execute_filter },
00199 { POSTING_HANDLER, flt_basic_handle_posting },
00200 { VIEW_LIST_HANDLER, flt_basic_set_target },
00201 { 0, NULL }
00202 };
00203
00204 t_module_config flt_basic = {
00205 flt_basic_config,
00206 flt_basic_handlers,
00207 NULL,
00208 NULL,
00209 NULL,
00210 flt_basic_cleanup
00211 };
00212
00213
00214