From 19735bb3c818f78d5ce53d1482b0bd62f63d76e8 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 22 Jun 2006 10:47:46 +0000 Subject: Ajout d'un warning si la variable IVY_DEBUG_FILTER est postionne et que le message n'est pas emit , on controle la table des filtres ajout d'un flag -c a ivyprobe pour la gestion des filtres de regexps --- src/ivy.c | 12 +++++++++++- src/ivybind.c | 17 +++++++++++++++++ src/ivybind.h | 2 ++ src/ivyprobe.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 86 insertions(+), 5 deletions(-) diff --git a/src/ivy.c b/src/ivy.c index e4cbb04..fd5204b 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -93,6 +93,9 @@ struct _clnt_lst { unsigned short app_port; /* port de l'application */ }; +/* flag pour le debug en cas de Filter de regexp */ +int debug_filter = 0; + /* server pour la socket application */ static Server server; @@ -585,6 +588,8 @@ void IvySetBindCallback( IvyBindCallback bind_callback, void *bind_data ) void IvySetFilter( int argc, const char **argv) { IvyBindingSetFilter( argc, argv ); + if ( getenv( "IVY_DEBUG_FILTER" )) debug_filter = 1; + } void IvyStop (void) @@ -749,7 +754,7 @@ IvyBindMsg (MsgCallback callback, void *user_data, const char *fmt_regex, ... ) } return msg; } - +/* emmission d'un message avec formatage a la printf */ int IvySendMsg(const char *fmt, ...) { IvyClientPtr clnt; @@ -768,6 +773,11 @@ int IvySendMsg(const char *fmt, ...) match_count += ClientCall (clnt, buffer.data); } TRACE_IF( match_count == 0, "Warning no recipient for %s\n",buffer.data); + /* si le message n'est pas emit et qu'il y a des filtres alors WARNING */ + if ( match_count == 0 && debug_filter ) + { + IvyBindindFilterCheck( buffer.data ); + } return match_count; } diff --git a/src/ivybind.c b/src/ivybind.c index b0a8db4..c506ab3 100644 --- a/src/ivybind.c +++ b/src/ivybind.c @@ -179,6 +179,10 @@ void IvyBindingMatch( IvyBinding bind, const char *message, int argnum, int *arg } //filter Expression Bind +int IvyBindingGetFilterCount() +{ +return messages_classes_count; +} void IvyBindingSetFilter( int argc, const char **argv) { const char *errbuf; @@ -222,3 +226,16 @@ int IvyBindingFilter(const char *expression) } return regexp_ok; } +/* recherche si le message commence par un mot clef de la table */ +void IvyBindindFilterCheck( const char *message ) +{ + int i; + for ( i = 0 ; i < messages_classes_count; i++ ) + { + if (strcmp( messages_classes[i], message ) == 0) + { + return; + } + } + fprintf(stderr,"*** WARNING *** message '%s' not sent due to missing keyword in filter table!!!\n", message ); +} diff --git a/src/ivybind.h b/src/ivybind.h index aa2ae2a..adfc340 100644 --- a/src/ivybind.h +++ b/src/ivybind.h @@ -19,8 +19,10 @@ typedef struct _binding *IvyBinding; /* Mise en place des Filtrages */ +int IvyBindingGetFilterCount(); void IvyBindingSetFilter( int argc, const char ** argv ); int IvyBindingFilter( const char *expression ); +void IvyBindindFilterCheck( const char *message ); /* Creation, Compilation */ IvyBinding IvyBindingCompile( const char *expression, int *erroffset, const char **errmessage ); diff --git a/src/ivyprobe.c b/src/ivyprobe.c index 40790f6..536447e 100644 --- a/src/ivyprobe.c +++ b/src/ivyprobe.c @@ -74,6 +74,9 @@ XtAppContext cntx; int app_count = 0; int wait_count = 0; int fbindcallback = 0; +int filter_count = 0; +const char *filter[4096]; +char *classes; void DirectCallback(IvyClientPtr app, void *user_data, int id, char *msg ) { @@ -223,9 +226,11 @@ void ApplicationCallback (IvyClientPtr app, void *user_data, IvyApplicationEvent app_count++; printf("%s connected from %s\n", appname, host); /* printf("Application(%s): Begin Messages\n", appname);*/ +/* double usage with -s flag remove it msgList = IvyGetApplicationMessages (app); while (*msgList ) printf("%s subscribes to '%s'\n",appname,*msgList++); +*/ /* printf("Application(%s): End Messages\n",appname);*/ #ifndef WIN32 /* Stdin not compatible with select , select only accept socket */ @@ -244,6 +249,28 @@ void ApplicationCallback (IvyClientPtr app, void *user_data, IvyApplicationEvent break; } } +void IvyPrintBindCallback( IvyClientPtr app, void *user_data, int id, char* regexp, IvyBindEvent event) +{ + switch ( event ) { + case IvyAddBind: + if ( fbindcallback ) + printf("Application: %s on %s add regexp %d : %s\n", + IvyGetApplicationName( app ), IvyGetApplicationHost(app), id, regexp); + break; + case IvyRemoveBind: + if ( fbindcallback ) + printf("Application: %s on %s remove regexp %d :%s\n", + IvyGetApplicationName( app ), IvyGetApplicationHost(app), id, regexp); + break; + case IvyFilterBind: + printf("Application: %s on %s as been filtred regexp %d :%s\n", + IvyGetApplicationName( app ), IvyGetApplicationHost(app), id, regexp); + break; + default: + printf("Application: %s unkown event %d\n",IvyGetApplicationName( app ), event); + break; + } +} #ifdef IVYMAINLOOP @@ -286,7 +313,17 @@ void BindMsgOfFile( const char * regex_file ) } } } - +void BuildFilterRegexp() +{ + char *word=strtok( classes, "," ); + while ( word != NULL && (filter_count < 4096 )) + { + filter[filter_count++] = word; + word = strtok( NULL, ","); + } + if ( filter_count ) + IvySetFilter( filter_count, filter ); +} int main(int argc, char *argv[]) { int c; @@ -298,8 +335,17 @@ int main(int argc, char *argv[]) const char* agentname = DEFAULT_IVYPROBE_NAME; char agentready [1024] = ""; const char* helpmsg = - "[options] [regexps]\n\t-b bus\tdefines the Ivy bus to which to connect to, defaults to 127:2010\n\t-t\ttriggers the timer test\n\t-n name\tchanges the name of the agent, defaults to IVYPROBE\n\t-v\tprints the ivy relase number\n\nregexp is a Perl5 compatible regular expression (see ivyprobe(1) and pcrepattern(3) for more info\nuse .help within ivyprobe\n\t-s bindcall\tactive the interception of regexp's subscribing or unscribing\n"; - while ((c = getopt(argc, argv, "vn:d:b:w:t:sf:")) != EOF) + "[options] [regexps]\n\t-b bus\tdefines the Ivy bus to which to connect to, defaults to 127:2010\n" + "\t-t\ttriggers the timer test\n" + "\t-n name\tchanges the name of the agent, defaults to IVYPROBE\n" + "\t-v\tprints the ivy relase number\n\n" + "regexp is a Perl5 compatible regular expression (see ivyprobe(1) and pcrepattern(3) for more info\n" + "use .help within ivyprobe\n" + "\t-s bindcall\tactive the interception of regexp's subscribing or unscribing\n" + "\t-f regexfile\tread list of regexp's from file one by line\n" + "\t-c msg1,msg2,msg3,...\tfilter the regexp's not beginning with words\n" + ; + while ((c = getopt(argc, argv, "vn:d:b:w:t:sf:c:")) != EOF) switch (c) { case 'b': strcpy (busbuf, optarg); @@ -321,9 +367,11 @@ int main(int argc, char *argv[]) timer_test = 1; break; case 's': - IvySetBindCallback(IvyDefaultBindCallback, NULL); fbindcallback=1; break; + case 'c': + classes= strdup(optarg); + break; default: printf("usage: %s %s",argv[0],helpmsg); exit(1); @@ -343,7 +391,11 @@ int main(int argc, char *argv[]) glutDisplayFunc(display); #endif IvyInit (agentname, agentready, ApplicationCallback,NULL,NULL,NULL); + IvySetBindCallback(IvyPrintBindCallback, NULL); + IvyBindDirectMsg( DirectCallback,NULL); + if ( classes ) + BuildFilterRegexp(); if ( regex_file ) BindMsgOfFile( regex_file ); for (; optind < argc; optind++) -- cgit v1.1