From a1eb3a36064e13c725c6d8f6301b43a431783afd Mon Sep 17 00:00:00 2001 From: jestin Date: Fri, 25 Jun 2004 18:27:39 +0000 Subject: le Makefile peut être utilisé sur Solaris, OSX et Linux. Par dégaut, c'est pour linux. ivy.c corrige un unbindmsg ivyprobe: -n pour le nom de l'agent, -v pour la version de la lib ivytcl: plein de problèmes réglés, d'autres introduits, notamment pour la gestion de la boucle d'évéenents sous windows ... Test.tcl déplacé dans les exemples --- src/ivy.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 2 deletions(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index 870e6fc..1a019c8 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -23,7 +23,12 @@ #include #include +#ifndef USE_PCRE_REGEX #include +#else +#define OVECSIZE 60 /* must be multiple of 3, for regexp return */ +#include +#endif #include @@ -76,7 +81,12 @@ struct _msg_snd { /* requete de reception d'un client */ MsgSndPtr next; int id; char *str_regexp; /* la regexp sous forme inhumaine */ +#ifndef USE_PCRE_REGEX regex_t regexp; /* la regexp sous forme machine */ +#else + pcre *regexp; + pcre_extra *inspect; +#endif }; struct _clnt_lst { @@ -168,6 +178,40 @@ static void IvyCleanup() SocketClose( broadcast ); } +#ifdef USE_PCRE_REGEX +static int +MsgCall (const char *message, MsgSndPtr msg, Client client) +{ + int ovector[OVECSIZE]; + int index; + int rc=pcre_exec( + msg->regexp, + msg->inspect, + message, + strlen(message), + 0, /* debut */ + 0, /* no other regexp option */ + ovector, + OVECSIZE); + if (rc<1) return 0; /* no match */ +#ifdef DEBUG + printf( "Sending message id=%d '%s'\n",msg->id,message); +#endif + SocketSend( client, "%d %d" ARG_START ,Msg, msg->id); +#ifdef DEBUG + printf( "Send matching args count %ld\n",msg->regexp.re_nsub); +#endif + index=1; + while ( indexmsg_send, snd ) + if ( snd ) + { + snd->id = id; + snd->str_regexp = strdup( arg ); + snd->regexp = regexp; + snd->inspect = pcre_study(regexp,0,&errbuf); + if (errbuf!=NULL) + { + printf("Error studying %s, message: %s\n",arg,errbuf); + } + } + } + else + { + printf("Error compiling '%s', %s\n", arg, errbuf); + MsgSendTo( client, Error, erroffset, errbuf ); + } +#endif break; case DelRegexp: - #ifdef DEBUG printf("Regexp Delete id=%d\n", id); #endif //DEBUG @@ -351,12 +425,17 @@ static void Receive( Client client, void *data, char *line ) IVY_LIST_ITER( clnt->msg_send, snd, ( id != snd->id )); if ( snd ) { +#ifndef USE_PCRE_REGEX + free( snd->str_regexp ); +#else free( snd->str_regexp ); + if (snd->inspect!=NULL) pcre_free(snd->inspect); + pcre_free(snd->regexp); +#endif IVY_LIST_REMOVE( clnt->msg_send, snd ); } break; case StartRegexp: - #ifdef DEBUG printf("Regexp Start id=%d Application='%s'\n", id, arg); #endif //DEBUG @@ -701,6 +780,7 @@ IvyUnbindMsg (MsgRcvPtr msg) IVY_LIST_EACH (clients, clnt ) { MsgSendTo( clnt->client, DelRegexp,msg->id, ""); } + IVY_LIST_REMOVE( msg_recv, msg ); } /* demande de reception d'un message */ -- cgit v1.1