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 <time.h>
00025 #include <sys/types.h>
00026
00027 #include "readline.h"
00028 #include "hashlib.h"
00029 #include "utils.h"
00030 #include "configparser.h"
00031 #include "cfcgi.h"
00032 #include "template.h"
00033 #include "clientlib.h"
00034
00035
00036
00037
00038
00039
00040
00041 unsigned long long saved_threads[256];
00042 int sclen = 0;
00043 t_string Cgi;
00044 int ThreadsOpenByDefault = -1;
00045
00046 void parse_query_string(t_cf_hash *head,int cl) {
00047 u_char *val = cf_cgi_get(head,"o");
00048 u_char *pos = val;
00049 u_char buff[50];
00050 unsigned long long tid = 0;
00051 int i = 0;
00052 int len;
00053
00054 if(val) {
00055 while((tid = strtoull(pos,(char **)&pos,10)) > 0) {
00056 pos += 1;
00057 saved_threads[sclen++] = tid;
00058 }
00059 }
00060
00061 val = cf_cgi_get(head,"a");
00062 if(val) {
00063 if(cl) {
00064 if(cf_strcmp(val,"open") == 0) {
00065 val = cf_cgi_get(head,"t");
00066 if(val) {
00067 saved_threads[sclen++] = strtoull(val,NULL,10);
00068 }
00069 }
00070 else {
00071 val = cf_cgi_get(head,"t");
00072 if(val) {
00073 tid = strtoull(val,NULL,10);
00074
00075 for(i=0;i<sclen;i++) {
00076 if(tid == saved_threads[i]) {
00077 saved_threads[i] = -1;
00078 break;
00079 }
00080 }
00081 }
00082 }
00083 }
00084 else {
00085 if(cf_strcmp(val,"open") == 0) {
00086 val = cf_cgi_get(head,"t");
00087 if(val) {
00088 tid = strtoull(val,NULL,10);
00089
00090 for(i=0;i<sclen;i++) {
00091 if(tid == saved_threads[i]) {
00092 saved_threads[i] = -1;
00093 break;
00094 }
00095 }
00096 }
00097 }
00098 else {
00099 val = cf_cgi_get(head,"t");
00100 if(val) {
00101 saved_threads[sclen++] = strtoull(val,NULL,10);
00102 }
00103 }
00104
00105 }
00106 }
00107
00108 for(i=0;i<sclen;i++) {
00109 if(saved_threads[i] != -1 && saved_threads[i] != 0) {
00110 str_init(&Cgi);
00111 len = sprintf(buff,"%lld",saved_threads[i]);
00112 str_chars_append(&Cgi,buff,len);
00113 break;
00114 }
00115 }
00116
00117 if(i+1 < sclen) {
00118 for(i++;i<sclen;i++) {
00119 if(saved_threads[i] != -1 && saved_threads[i] != 0) {
00120 len = sprintf(buff,"%%2C%lld",saved_threads[i]);
00121 str_chars_append(&Cgi,buff,len);
00122 }
00123 }
00124 }
00125
00126 }
00127
00128 int execute_filter(t_cf_hash *head,t_configuration *dc,t_configuration *vc,t_cl_thread *thread,int mode) {
00129 if(ThreadsOpenByDefault != -1 && mode == 0) {
00130 int cl = !ThreadsOpenByDefault;
00131 t_name_value *vs = NULL;
00132 t_message *msg;
00133 int i = 0;
00134 u_char buff[500];
00135 u_char *UserName = cf_hash_get(GlobalValues,"UserName",8);
00136
00137 if(UserName) {
00138 vs = cfg_get_value(dc,"UBaseURL");
00139 }
00140 else {
00141 vs = cfg_get_value(dc,"BaseURL");
00142 }
00143
00144 if(!sclen && head) {
00145 parse_query_string(head,cl);
00146 }
00147
00148 tpl_cf_setvar(&thread->messages->tpl,"openclose","1",1,0);
00149
00150 i = sprintf(buff,"t%lld",thread->tid);
00151 tpl_cf_setvar(&thread->messages->tpl,"unanch",buff,i,0);
00152
00153 if(cl) {
00154 for(i=0;i<sclen;i++) {
00155 if(saved_threads[i] == thread->tid) {
00156 tpl_cf_setvar(&thread->messages->tpl,"open","1",1,0);
00157 i = sprintf(buff,"%s?t=%lld&a=close",vs->values[0],thread->tid);
00158 tpl_cf_setvar(&thread->messages->tpl,"link_oc",buff,i,1);
00159
00160 if(Cgi.len) {
00161 tpl_cf_appendvar(&thread->messages->tpl,"link_oc","&o=",7);
00162 tpl_cf_appendvar(&thread->messages->tpl,"link_oc",Cgi.content,Cgi.len);
00163 }
00164
00165 return FLT_DECLINE;
00166 }
00167 }
00168
00169 i = sprintf(buff,"%s?t=%lld&a=open",vs->values[0],thread->tid);
00170 tpl_cf_setvar(&thread->messages->tpl,"link_oc",buff,i,1);
00171
00172 if(Cgi.len) {
00173 tpl_cf_appendvar(&thread->messages->tpl,"link_oc","&o=",7);
00174 tpl_cf_appendvar(&thread->messages->tpl,"link_oc",Cgi.content,Cgi.len);
00175 }
00176
00177 msg = thread->messages->next;
00178
00179
00180 if(msg) {
00181 for(;msg;msg=msg->next) {
00182 msg->may_show = 0;
00183 }
00184 }
00185 }
00186 else {
00187
00188 for(i=0;i<sclen;i++) {
00189 if(thread->tid == saved_threads[i]) {
00190 i = sprintf(buff,"%s?t=%lld&a=open",vs->values[0],thread->tid);
00191 tpl_cf_setvar(&thread->messages->tpl,"link_oc",buff,i,1);
00192
00193 if(Cgi.len) {
00194 tpl_cf_appendvar(&thread->messages->tpl,"link_oc","&o=",7);
00195 tpl_cf_appendvar(&thread->messages->tpl,"link_oc",Cgi.content,Cgi.len);
00196 }
00197
00198 msg = thread->messages->next;
00199
00200
00201 if(msg) {
00202 for(;msg;msg=msg->next) {
00203 msg->may_show = 0;
00204 }
00205 }
00206
00207 return FLT_DECLINE;
00208 }
00209 }
00210
00211
00212 tpl_cf_setvar(&thread->messages->tpl,"open","1",1,0);
00213 i = sprintf(buff,"%s?t=%lld&a=close",vs->values[0],thread->tid);
00214 tpl_cf_setvar(&thread->messages->tpl,"link_oc",buff,i,1);
00215
00216 if(Cgi.len) {
00217 tpl_cf_appendvar(&thread->messages->tpl,"link_oc","&o=",7);
00218 tpl_cf_appendvar(&thread->messages->tpl,"link_oc",Cgi.content,Cgi.len);
00219 }
00220 }
00221
00222 return FLT_OK;
00223 }
00224
00225 return FLT_DECLINE;
00226 }
00227
00228 int get_conf(t_configfile *cfile,t_conf_opt *opt,u_char **args,int argnum) {
00229 int *x = (int *)opt->data;
00230 *x = cf_strcmp(args[0],"yes") == 0 ? 1 : 0;
00231
00232 return 0;
00233 }
00234
00235 t_conf_opt config[] = {
00236 { "ThreadsOpenByDefault", get_conf, &ThreadsOpenByDefault },
00237 { NULL, NULL, NULL }
00238 };
00239
00240 t_handler_config handlers[] = {
00241 { VIEW_HANDLER, execute_filter },
00242 { 0, NULL }
00243 };
00244
00245 t_module_config flt_openclose = {
00246 config,
00247 handlers,
00248 NULL,
00249 NULL,
00250 NULL,
00251 NULL
00252 };
00253
00254