Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

flt_category.c

Go to the documentation of this file.
00001 
00009 /* {{{ Initial comments */
00010 /*
00011  * $LastChangedDate: 2004-04-01 18:34:17 +0200 (Thu, 01 Apr 2004) $
00012  * $LastChangedRevision: 50 $
00013  * $LastChangedBy: ckruse $
00014  *
00015  */
00016 /* }}} */
00017 
00018 /* {{{ Includes */
00019 #include "config.h"
00020 #include "defines.h"
00021 
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <ctype.h>
00026 #include <time.h>
00027 #include <sys/types.h>
00028 
00029 #include "readline.h"
00030 #include "hashlib.h"
00031 #include "utils.h"
00032 #include "configparser.h"
00033 #include "cfcgi.h"
00034 #include "template.h"
00035 #include "clientlib.h"
00036 #include "hashlib.h"
00037 /* }}} */
00038 
00039 t_cf_hash *Cats = NULL;
00040 
00041 void parse_list(u_char *vips,t_cf_hash *hash) {
00042   if(vips) {
00043     u_char *ptr = vips;
00044     u_char *pos = ptr,*pre = ptr;
00045 
00046     while((pos = strstr(pos,",")) != NULL) {
00047       *pos = 0;
00048 
00049       cf_hash_set(hash,pre,pos-pre,"1",1);
00050 
00051       pre    = pos+1;
00052       *pos++ = ',';
00053     }
00054 
00055     cf_hash_set(hash,pre,strlen(pre),"1",1); /* argh! This sucks */
00056   }
00057 }
00058 
00059 int execute_filter(t_cf_hash *head,t_configuration *dc,t_configuration *vc,t_message *msg,unsigned long long tid,int mode) {
00060   if(Cats && mode == 0) {
00061     if(cf_hash_get(Cats,msg->category,strlen(msg->category))) {
00062       return FLT_OK;
00063     }
00064 
00065     msg->may_show = 0;
00066     delete_subtree(msg);
00067     return FLT_OK;
00068   }
00069 
00070   return FLT_DECLINE;
00071 }
00072 
00073 int flt_cat_handle_command(t_configfile *cf,t_conf_opt *opt,u_char **args,int argnum) {
00074   if(!Cats) Cats = cf_hash_new(NULL);
00075 
00076   parse_list(args[0],Cats);
00077 
00078   return 0;
00079 }
00080 
00081 void flt_cat_finish(void) {
00082   if(Cats) {
00083     cf_hash_destroy(Cats);
00084     Cats = NULL;
00085   }
00086 }
00087 
00088 t_conf_opt config[] = {
00089   { "ShowCategories", flt_cat_handle_command, NULL },
00090   { NULL,             NULL,                   NULL }
00091 };
00092 
00093 t_handler_config handlers[] = {
00094   { VIEW_LIST_HANDLER, execute_filter },
00095   { 0, NULL }
00096 };
00097 
00098 t_module_config flt_category = {
00099   config,
00100   handlers,
00101   NULL,
00102   NULL,
00103   NULL,
00104   flt_cat_finish
00105 };
00106 
00107 /* eof */

Generated on Sun Apr 25 16:37:38 2004 for Classic Forum by doxygen 1.3.5