From 1762b1c59c186f54a756c7b72bea7fd8c5115fda Mon Sep 17 00:00:00 2001 From: fcolin Date: Tue, 8 Feb 2011 16:38:55 +0000 Subject: change Filter API --- src/Makefile | 17 ++++++++--- src/ivy.c | 13 ++++++++- src/ivy.h | 2 ++ src/ivybind.c | 92 ++++++++++++++++++++++++++++++++++++++++++++--------------- src/ivybind.h | 7 +++++ 5 files changed, 103 insertions(+), 28 deletions(-) diff --git a/src/Makefile b/src/Makefile index 54ecbcf..b9acb58 100644 --- a/src/Makefile +++ b/src/Makefile @@ -17,7 +17,7 @@ # change this in version.h too !!!! MAJOR=3 -MINOR=11 +MINOR=12 PERHAPS64 := $(shell getconf LONG_BIT | perl -ne "print /64/ ? '64' : '';") LIB = /lib$(PERHAPS64) @@ -41,6 +41,7 @@ export XTINC = -I$(X11_PREFIX)/include XTLIB = -L$(X11_PREFIX)$(LIB) -lXt -lX11 -lSM -lICE +HAVE_GLIB = $(shell pkg-config --exists glib-2.0 && echo 'yes') GLIBINC = `pkg-config --cflags glib-2.0` GLIBLIB = `pkg-config --libs glib-2.0` GLUTINC = -I/usr/include -I. @@ -121,9 +122,17 @@ XTOBJ = ivyxtloop.o ivysocket.o ivy.o ivybuffer.o ivyfifo.o ivybind.o intervalRe GLIBOBJ = ivyglibloop.o ivysocket.o ivy.o ivybuffer.o ivyfifo.o ivybind.o intervalRegexp.o param.o GLUTOBJ = ivyglutloop.o ivysocket.o ivy.o ivybuffer.o ivyfifo.o ivybind.o intervalRegexp.o param.o TCLOBJ = ivytcl.o timer.o ivysocket.o givy.o ivybuffer.o ivyfifo.o ivybind.o intervalRegexp.o param.o - # WINDOWS add ivyloop.o if TCL_CHANNEL_INTEGRATION is not set -TARGETLIBS=libivy.so.$(MAJOR).$(MINOR) libgivy.so.$(MAJOR).$(MINOR) libxtivy.so.$(MAJOR).$(MINOR) libglibivy.so.$(MAJOR).$(MINOR) libtclivy.so.$(MAJOR).$(MINOR) + +TARGETLIBS=libivy.so.$(MAJOR).$(MINOR) libgivy.so.$(MAJOR).$(MINOR) libxtivy.so.$(MAJOR).$(MINOR) libtclivy.so.$(MAJOR).$(MINOR) +STATICTARGETLIBS=libivy.a libgivy.a libxtivy.a libtclivy.a + +ifeq ($(HAVE_GLIB),yes) + TARGETLIBS += libglibivy.so.$(MAJOR).$(MINOR) + STATICTARGETLIBS += libglibivy.a +endif + + # not yet need Modified Glut ivyglutprobe .c.o: @@ -136,7 +145,7 @@ libomp: libivy_omp.a libivy_omp.so.$(MAJOR).$(MINOR) omp: libomp @(cd $(TOOLS_DIR) && $(MAKE) omp) -static-libs: libivy.a libgivy.a libxtivy.a libglibivy.a libtclivy.a +static-libs: $(STATICTARGETLIBS) # not yet need Modified Glut libglutivy.a shared-libs: $(TARGETLIBS) diff --git a/src/ivy.c b/src/ivy.c index 7964200..d784f50 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -915,7 +915,8 @@ void IvyTerminate() if ( ApplicationName ) free((void *) ApplicationName ); if ( ready_message ) - free((void *) ready_message ); + free((void *) ready_message ); + IvyBindingTerminate(); } void IvySetBindCallback( IvyBindCallback bind_callback, void *bind_data ) @@ -930,6 +931,16 @@ void IvySetFilter( int argc, const char **argv) if ( getenv( "IVY_DEBUG_FILTER" )) debug_filter = 1; } +void IvyAddFilter( const char *arg) +{ + IvyBindingAddFilter( arg ); + if ( getenv( "IVY_DEBUG_FILTER" )) debug_filter = 1; + +} +void IvyRemoveFilter( const char *arg) +{ + IvyBindingRemoveFilter( arg ); +} void IvyStop (void) { diff --git a/src/ivy.h b/src/ivy.h index 286ea7a..50bc301 100644 --- a/src/ivy.h +++ b/src/ivy.h @@ -61,6 +61,8 @@ typedef struct _msg_rcv *MsgRcvPtr; /* filtrage des regexps */ void IvySetFilter( int argc, const char **argv); +void IvyAddFilter( const char *arg); +void IvyRemoveFilter( const char *arg); void IvyInit( const char *AppName, /* nom de l'application */ diff --git a/src/ivybind.c b/src/ivybind.c index bbf422e..27d5705 100644 --- a/src/ivybind.c +++ b/src/ivybind.c @@ -62,10 +62,15 @@ struct _binding { }; /* classes de messages emis par l'application utilise pour le filtrage */ -static int messages_classes_count = 0; -static const char **messages_classes = 0; +typedef struct _filtred_word * FiltredWordPtr; +struct _filtred_word { /* requete d'emission d'un client */ + FiltredWordPtr next; + const char *word; /* entete de regexp a conserver */ +}; + +static FiltredWordPtr messages_classes =0 ; /* regexp d'extraction du mot clef des regexp client pour le filtrage des regexp , ca va c'est clair ??? */ -static IvyBinding token_extract; +static IvyBinding token_extract =0; IvyBinding IvyBindingCompile( const char * expression, int *erroffset, const char **errmessage ) { @@ -213,35 +218,62 @@ void IvyBindingMatch( IvyBinding bind, const char *message, int argnum, int *arg } /*filter Expression Bind */ -int IvyBindingGetFilterCount() + +void IvyBindingSetFilter( int argc, const char **argv) { -return messages_classes_count; + int i; + for ( i = 0 ; i < argc; i++ ) + { + IvyBindingAddFilter( argv[i] ); + } + } -void IvyBindingSetFilter( int argc, const char **argv) + +void IvyBindingAddFilter( const char *arg) { const char *errbuf; int erroffset; + if ( arg ) + { + FiltredWordPtr word=0; + IVY_LIST_ADD_START( messages_classes, word ); + word->word = strdup(arg); + IVY_LIST_ADD_END( messages_classes, word ); - messages_classes_count = argc; - messages_classes = argv; + } /* compile the token extraction regexp */ - - token_extract = IvyBindingCompile("^\\^([a-zA-Z_0-9-]+).*", & erroffset, & errbuf); if ( !token_extract ) { - printf("Error compiling Token Extract regexp: %s\n", errbuf); + token_extract = IvyBindingCompile("^\\^([a-zA-Z_0-9-]+).*", & erroffset, & errbuf); + if ( !token_extract ) + { + printf("Error compiling Token Extract regexp: %s\n", errbuf); + } + } +} +void IvyBindingRemoveFilter( const char *arg) +{ + FiltredWordPtr word=0; + FiltredWordPtr next=0; + IVY_LIST_EACH_SAFE( messages_classes, word, next ) + { + if ( strcmp( arg, word->word) == 0 ) + { + free( (void*)word->word ); + IVY_LIST_REMOVE( messages_classes, word ); + } } } int IvyBindingFilter(const char *expression) { - int i; + FiltredWordPtr word=0; int err; int regexp_ok = 1; /* accepte tout par default */ int tokenlen; const char *token; - if ( *expression =='^' && messages_classes_count !=0 ) + if ( *expression =='^' && messages_classes !=0 ) { regexp_ok = 0; @@ -249,27 +281,41 @@ int IvyBindingFilter(const char *expression) err = IvyBindingExec( token_extract, expression ); if ( err < 1 ) return 1; IvyBindingMatch( token_extract, expression , 1, &tokenlen, &token ); - for ( i = 0 ; i < messages_classes_count; i++ ) - { - if (strncmp( messages_classes[i], token, tokenlen ) == 0) { - return 1; } + + IVY_LIST_ITER( messages_classes, word, strncmp( word->word, token, tokenlen ) != 0); + + if (word) { + return 1; + } /* else { */ /*printf ("DBG> %s eliminé [%s]\n", token, 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) + FiltredWordPtr word=0; + IVY_LIST_ITER( messages_classes, word, strcmp( word->word, message ) != 0); + + if (word) { return; - } } + fprintf(stderr,"*** WARNING *** message '%s' not sent due to missing keyword in filter table!!!\n", message ); } +void IvyBindingTerminate() +{ + FiltredWordPtr word=0; + FiltredWordPtr next=0; + + IVY_LIST_EACH_SAFE( messages_classes, word, next ) + { + free((void*) word->word ); + } + IVY_LIST_EMPTY( messages_classes ); + messages_classes = 0; +} \ No newline at end of file diff --git a/src/ivybind.h b/src/ivybind.h index e815771..4c69b5b 100644 --- a/src/ivybind.h +++ b/src/ivybind.h @@ -25,6 +25,8 @@ extern "C" { /* Mise en place des Filtrages */ int IvyBindingGetFilterCount(); void IvyBindingSetFilter( int argc, const char ** argv ); +void IvyBindingAddFilter( const char * argv ); +void IvyBindingRemoveFilter( const char * arg ); int IvyBindingFilter( const char *expression ); void IvyBindindFilterCheck( const char *message ); @@ -37,6 +39,11 @@ int IvyBindingExec( IvyBinding _bind, const char * message ); /* Get Argument */ void IvyBindingMatch( IvyBinding _bind, const char *message, int argnum, int *arglen, const char **arg ); +/* +Liberation de memoire en fin d'execution +*/ +void IvyBindingTerminate(); + #ifdef __cplusplus } #endif -- cgit v1.1