From d8c270dcecc20b8084cb0463490ef68c8f88518f Mon Sep 17 00:00:00 2001 From: fcolin Date: Tue, 18 Apr 2006 11:54:14 +0000 Subject: retour au protocol V3 --- src/ivy.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index b8ac7fd..f03a4b1 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -229,6 +229,10 @@ MsgCall (const char *message, MsgSndPtr msg, Client client) static int MsgCall (const char *message, MsgSndPtr msg, Client client) { + static char *buffer = NULL; /* Use satic mem to eliminate multiple call to malloc /free */ + static int size = 0; /* donc non reentrant !!!! */ + int offset = 0; + regmatch_t match[MAX_MATCHING_ARGS+1]; #ifdef GNU_REGEXP regmatch_t* p; @@ -245,7 +249,7 @@ MsgCall (const char *message, MsgSndPtr msg, Client client) // il faut essayer d'envoyer le message en une seule fois sur la socket // pour eviter au maximun de passer dans le select plusieur fois par message du protocole Ivy // pour eviter la latence ( PB detecte par ivyperf ping roudtrip ) - SocketSendBuffered( client, "%d %d" ARG_START ,Msg, msg->id); + offset += make_message_var( &buffer, &size, offset, "%d %d" ARG_START ,Msg, msg->id); #ifdef DEBUG printf( "Send matching args count %ld\n",msg->regexp.re_nsub); @@ -254,7 +258,7 @@ MsgCall (const char *message, MsgSndPtr msg, Client client) #ifdef GNU_REGEXP p = &match[1]; while ( p->rm_so != -1 ) { - SocketSendBuffered( client, "%.*s" ARG_END , p->rm_eo - p->rm_so, + offset += make_message_var( &buffer, &size, offset, "%.*s" ARG_END , p->rm_eo - p->rm_so, message + p->rm_so); ++p; } @@ -266,10 +270,10 @@ MsgCall (const char *message, MsgSndPtr msg, Client client) printf ("Send matching arg%d %.*s\n",i,(int)(match[i].rm_eo - match[i].rm_so), message + match[i].rm_so); #endif - SocketSendBuffered (client, "%.*s" ARG_END ,(int)(match[i].rm_eo - match[i].rm_so), + offset += make_message_var( &buffer, &size, offset, "%.*s" ARG_END ,(int)(match[i].rm_eo - match[i].rm_so), message + match[i].rm_so); } else { - SocketSendBuffered (client, ARG_END); + offset += make_message_var( &buffer, &size, offset, ARG_END ); #ifdef DEBUG printf( "Send matching arg%d VIDE\n",i); #endif //DEBUG @@ -277,8 +281,8 @@ MsgCall (const char *message, MsgSndPtr msg, Client client) } #endif - SocketSendBuffered (client, "\n"); - SocketFlush(client); + offset += make_message_var( &buffer, &size, offset, "\n"); + SocketSendRaw(client, buffer , offset); return 1; } #endif /* USE_PCRE_REGEX */ -- cgit v1.1 From 6bf117656574521545694a1a4e5169755077631e Mon Sep 17 00:00:00 2001 From: fcolin Date: Wed, 19 Apr 2006 08:28:14 +0000 Subject: correction de probleme potentiel en multithread ( Ada rejeu ) ajout d'un warning en cas de client bloquant si la varaiable d'env IVY_DEBUG_SEND est positionne --- src/ivy.c | 101 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 51 insertions(+), 50 deletions(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index f03a4b1..07e262e 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -38,11 +38,12 @@ #include "ivychannel.h" #include "ivysocket.h" #include "list.h" +#include "ivybuffer.h" #include "ivy.h" #define VERSION 3 -#define MAX_MATCHING_ARGS 20 +#define MAX_MATCHING_ARGS 40 #define ARG_START "\002" #define ARG_END "\003" @@ -161,9 +162,9 @@ static char * nextArg( char *s, const char *separator ) if ( end == start ) return NULL; return start; } -static void MsgSendTo( Client client, MsgType msgtype, int id, const char *message ) +static int MsgSendTo( Client client, MsgType msgtype, int id, const char *message ) { - SocketSend( client, "%d %d" ARG_START "%s\n", msgtype, id, message); + return SocketSend( client, "%d %d" ARG_START "%s\n", msgtype, id, message); } static void IvyCleanup() @@ -187,11 +188,11 @@ static void IvyCleanup() #ifdef USE_PCRE_REGEX static int -MsgCall (const char *message, MsgSndPtr msg, Client client) +MsgCall (const char *message, MsgSndPtr msg, IvyClientPtr client) { - static char *buffer = NULL; /* Use satic mem to eliminate multiple call to malloc /free */ - static int size = 0; /* donc non reentrant !!!! */ - int offset = 0; + int waiting = 0; + static IvyBuffer buffer = { NULL, 0, 0 }; /* Use satic mem to eliminate multiple call to malloc /free */ + int err; int ovector[OVECSIZE]; int index; int rc=pcre_exec( @@ -207,32 +208,35 @@ MsgCall (const char *message, MsgSndPtr msg, Client client) #ifdef DEBUG printf( "Sending message id=%d '%s'\n",msg->id,message); #endif + buffer.offset = 0; // il faut essayer d'envoyer le message en une seule fois sur la socket // pour eviter au maximun de passer dans le select plusieur fois par message du protocole Ivy // pour eviter la latence ( PB de perfo detecte par ivyperf ping roudtrip ) - offset += make_message_var( &buffer, &size, offset, "%d %d" ARG_START ,Msg, msg->id); + err = make_message_var( &buffer, "%d %d" ARG_START ,Msg, msg->id); #ifdef DEBUG printf( "Send matching args count %ld\n",msg->regexp.re_nsub); #endif index=1; while ( indexclient, buffer.data , buffer.offset); + if ( waiting ) + fprintf(stderr, "Ivy: Slow client : %s\n", client->app_name ); return 1; } #else /* we don't USE_PCRE_REGEX */ static int -MsgCall (const char *message, MsgSndPtr msg, Client client) +MsgCall (const char *message, MsgSndPtr msg, IvyClientPtr client) { - static char *buffer = NULL; /* Use satic mem to eliminate multiple call to malloc /free */ - static int size = 0; /* donc non reentrant !!!! */ - int offset = 0; - + int waiting = 0; + static IvyBuffer buffer = { NULL, 0, 0 }; /* Use satic mem to eliminate multiple call to malloc /free */ + int err; + regmatch_t match[MAX_MATCHING_ARGS+1]; #ifdef GNU_REGEXP regmatch_t* p; @@ -249,7 +253,8 @@ MsgCall (const char *message, MsgSndPtr msg, Client client) // il faut essayer d'envoyer le message en une seule fois sur la socket // pour eviter au maximun de passer dans le select plusieur fois par message du protocole Ivy // pour eviter la latence ( PB detecte par ivyperf ping roudtrip ) - offset += make_message_var( &buffer, &size, offset, "%d %d" ARG_START ,Msg, msg->id); + buffer.offset = 0; + err = make_message_var( &buffer, "%d %d" ARG_START ,Msg, msg->id); #ifdef DEBUG printf( "Send matching args count %ld\n",msg->regexp.re_nsub); @@ -258,7 +263,7 @@ MsgCall (const char *message, MsgSndPtr msg, Client client) #ifdef GNU_REGEXP p = &match[1]; while ( p->rm_so != -1 ) { - offset += make_message_var( &buffer, &size, offset, "%.*s" ARG_END , p->rm_eo - p->rm_so, + err = make_message_var( &buffer, "%.*s" ARG_END , p->rm_eo - p->rm_so, message + p->rm_so); ++p; } @@ -270,10 +275,10 @@ MsgCall (const char *message, MsgSndPtr msg, Client client) printf ("Send matching arg%d %.*s\n",i,(int)(match[i].rm_eo - match[i].rm_so), message + match[i].rm_so); #endif - offset += make_message_var( &buffer, &size, offset, "%.*s" ARG_END ,(int)(match[i].rm_eo - match[i].rm_so), + buffer.offset += make_message_var( &buffer, "%.*s" ARG_END ,(int)(match[i].rm_eo - match[i].rm_so), message + match[i].rm_so); } else { - offset += make_message_var( &buffer, &size, offset, ARG_END ); + buffer.offset += make_message_var( &buffer, ARG_END ); #ifdef DEBUG printf( "Send matching arg%d VIDE\n",i); #endif //DEBUG @@ -281,8 +286,8 @@ MsgCall (const char *message, MsgSndPtr msg, Client client) } #endif - offset += make_message_var( &buffer, &size, offset, "\n"); - SocketSendRaw(client, buffer , offset); + err = make_message_var( &buffer,"\n"); + SocketSendRaw(client->client, buffer.data , buffer.offset); return 1; } #endif /* USE_PCRE_REGEX */ @@ -294,7 +299,7 @@ ClientCall (IvyClientPtr clnt, const char *message) int match_count = 0; /* recherche dans la liste des requetes recues de ce client */ IVY_LIST_EACH (clnt->msg_send, msg) { - match_count+= MsgCall (message, msg, clnt->client); + match_count+= MsgCall (message, msg, clnt); } return match_count; } @@ -401,9 +406,7 @@ static void Receive( Client client, void *data, char *line ) reg = regcomp(®exp, arg, REGCOMP_OPT|REG_EXTENDED); if ( reg == 0 ) { - IVY_LIST_ADD( clnt->msg_send, snd ) - if ( snd ) - { + IVY_LIST_ADD_START( clnt->msg_send, snd ) snd->id = id; snd->str_regexp = strdup( arg ); snd->regexp = regexp; @@ -411,7 +414,7 @@ static void Receive( Client client, void *data, char *line ) { (*application_bind_callback)( clnt, application_bind_data, id, snd->str_regexp, IvyAddBind ); } - } + IVY_LIST_ADD_END( clnt->msg_send, snd ) } else { @@ -424,9 +427,7 @@ static void Receive( Client client, void *data, char *line ) regexp = pcre_compile(arg, PCRE_OPT,&errbuf,&erroffset,NULL); if ( regexp != NULL ) { - IVY_LIST_ADD( clnt->msg_send, snd ) - if ( snd ) - { + IVY_LIST_ADD_START( clnt->msg_send, snd ) snd->id = id; snd->str_regexp = strdup( arg ); snd->regexp = regexp; @@ -440,7 +441,8 @@ static void Receive( Client client, void *data, char *line ) { (*application_bind_callback)( clnt, application_bind_data, id, snd->str_regexp, IvyAddBind ); } - } + IVY_LIST_ADD_END( clnt->msg_send, snd ) + } else { @@ -564,9 +566,8 @@ static IvyClientPtr SendService( Client client ) { IvyClientPtr clnt; MsgRcvPtr msg; - IVY_LIST_ADD( clients, clnt ) - if ( clnt ) - { + IVY_LIST_ADD_START( clients, clnt ) + clnt->msg_send = 0; clnt->client = client; clnt->app_name = strdup("Unknown"); @@ -577,7 +578,8 @@ static IvyClientPtr SendService( Client client ) MsgSendTo( client, AddRegexp,msg->id,msg->regexp); } MsgSendTo( client, EndRegexp, 0, ""); - } + + IVY_LIST_ADD_END( clients, clnt ) return clnt; } @@ -837,25 +839,24 @@ IvyUnbindMsg (MsgRcvPtr msg) MsgRcvPtr IvyBindMsg (MsgCallback callback, void *user_data, const char *fmt_regex, ... ) { - static char *buffer = NULL; - static int size = 0; + static IvyBuffer buffer = { NULL, 0, 0}; va_list ap; static int recv_id = 0; IvyClientPtr clnt; MsgRcvPtr msg; va_start (ap, fmt_regex ); - make_message( &buffer, &size, 0, fmt_regex, ap ); + buffer.offset = 0; + make_message( &buffer, fmt_regex, ap ); va_end (ap ); /* add Msg to the query list */ - IVY_LIST_ADD( msg_recv, msg ); - if (msg) { + IVY_LIST_ADD_START( msg_recv, msg ) msg->id = recv_id++; - msg->regexp = strdup(buffer); + msg->regexp = strdup(buffer.data); msg->callback = callback; msg->user_data = user_data; - } + IVY_LIST_ADD_END( msg_recv, msg ) /* Send to already connected clients */ /* recherche dans la liste des requetes recues de mes clients */ IVY_LIST_EACH( clients, clnt ) { @@ -868,17 +869,17 @@ int IvySendMsg(const char *fmt, ...) { IvyClientPtr clnt; int match_count = 0; - static char *buffer = NULL; /* Use satic mem to eliminate multiple call to malloc /free */ - static int size = 0; /* donc non reentrant !!!! */ + static IvyBuffer buffer = { NULL, 0, 0}; /* Use satic mem to eliminate multiple call to malloc /free */ va_list ap; va_start( ap, fmt ); - make_message( &buffer, &size, 0, fmt, ap ); + buffer.offset = 0; + make_message( &buffer, fmt, ap ); va_end ( ap ); /* recherche dans la liste des requetes recues de mes clients */ IVY_LIST_EACH (clients, clnt) { - match_count += ClientCall (clnt, buffer); + match_count += ClientCall (clnt, buffer.data); } #ifdef DEBUG if ( match_count == 0 ) printf( "Warning no recipient for %s\n",buffer); @@ -888,14 +889,14 @@ int IvySendMsg(const char *fmt, ...) void IvySendError( IvyClientPtr app, int id, const char *fmt, ... ) { - static char *buffer = NULL; /* Use satic mem to eliminate multiple call to malloc /free */ - static int size = 0; /* donc non reentrant !!!! */ + static IvyBuffer buffer = { NULL, 0, 0}; /* Use satic mem to eliminate multiple call to malloc /free */ va_list ap; va_start( ap, fmt ); - make_message( &buffer, &size, 0, fmt, ap ); + buffer.offset = 0; + make_message( &buffer, fmt, ap ); va_end ( ap ); - MsgSendTo( app->client, Error, id, buffer); + MsgSendTo( app->client, Error, id, buffer.data); } void IvyBindDirectMsg( MsgDirectCallback callback, void *user_data) -- cgit v1.1 From 5165be98a850bad1c2371f8ae8fa1e4cc8b76a15 Mon Sep 17 00:00:00 2001 From: fcolin Date: Wed, 19 Apr 2006 16:30:08 +0000 Subject: Add indication on regexp filtering when classes are used call BindingCallback --- src/ivy.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index 07e262e..6414f72 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -400,6 +400,10 @@ static void Receive( Client client, void *data, char *line ) #ifdef DEBUG printf("Warning: regexp '%s' illegal, removing from %s\n",arg,ApplicationName); #endif //DEBUG + if ( application_bind_callback ) + { + (*application_bind_callback)( clnt, application_bind_data, id, snd->str_regexp, IvyFilterBind ); + } return; } #ifndef USE_PCRE_REGEX -- cgit v1.1 From 97ba3631720cd0393b547894b7d2fafc5e361a5e Mon Sep 17 00:00:00 2001 From: fcolin Date: Wed, 19 Apr 2006 16:53:10 +0000 Subject: correction Filtred Binding + test avec ivyperf --- src/ivy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index 6414f72..12b6ae3 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -402,7 +402,7 @@ static void Receive( Client client, void *data, char *line ) #endif //DEBUG if ( application_bind_callback ) { - (*application_bind_callback)( clnt, application_bind_data, id, snd->str_regexp, IvyFilterBind ); + (*application_bind_callback)( clnt, application_bind_data, id, arg, IvyFilterBind ); } return; } -- cgit v1.1 From 68372c19d14986d372918cd268d5855fd7665fc3 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 20 Apr 2006 08:54:20 +0000 Subject: correction bug sur filtrage regexp --- src/ivy.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 126 insertions(+), 16 deletions(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index 12b6ae3..00362ab 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -118,6 +118,13 @@ static const char *ApplicationName = 0; /* classes de messages emis par l'application utilise pour le filtrage */ static int messages_classes_count = 0; static const char **messages_classes = 0; +/* regexp d'extraction du mot clef des regexp client pour le filtrage des regexp , ca va c'est clair ??? */ +#ifndef USE_PCRE_REGEX + regex_t token_extract; +#else + pcre *token_extract; + pcre_extra *token_inspect; +#endif /* callback appele sur reception d'un message direct */ static MsgDirectCallback direct_callback = 0; @@ -148,19 +155,19 @@ static const char *ready_message = 0; * */ static char * nextArg( char *s, const char *separator ) { - static char *start = NULL; - static char *end = NULL; - if ( s ) - { - end = s; - } - start = end; - - while ( *end && *end != *separator ) - end++; - if ( *end == *separator ) *end++ = '\0'; - if ( end == start ) return NULL; - return start; + static char *start = NULL; + static char *end = NULL; + if ( s ) + { + end = s; + } + start = end; + + while ( *end && *end != *separator ) + end++; + if ( *end == *separator ) *end++ = '\0'; + if ( end == start ) return NULL; + return start; } static int MsgSendTo( Client client, MsgType msgtype, int id, const char *message ) { @@ -303,18 +310,85 @@ ClientCall (IvyClientPtr clnt, const char *message) } return match_count; } +#ifdef USE_PCRE_REGEX +static int ExtractTokenRegexp (const char *exp, char *buffer, int buffersize) +{ +#define TOKEN_OVECSIZE 3*2 /* must be multiple of 3, for regexp return */ + int ovector[TOKEN_OVECSIZE]; + int rc=pcre_exec( + token_extract, + token_inspect, + exp, + strlen(exp), + 0, /* debut */ + 0, /* no other regexp option */ + ovector, + TOKEN_OVECSIZE); + /*if (rc<1) return rc; *//* no match */ + + return pcre_copy_substring(exp, ovector, rc, 1, buffer, buffersize); + + +} + +#else /* we don't USE_PCRE_REGEX */ +static int ExtractTokenRegexp (const char *exp, char *buffer, int buffersize) +{ + int err; + + regmatch_t match[MAX_MATCHING_ARGS+1]; +#ifdef GNU_REGEXP + regmatch_t* p; +#else + unsigned int i; +#endif + memset( match, -1, sizeof(match )); /* work around bug !!!*/ + if (regexec (&msg->regexp, message, MAX_MATCHING_ARGS, match, 0) != 0) + return 0; + +#ifdef GNU_REGEXP + p = &match[1]; + while ( p->rm_so != -1 ) { + err = make_message_var( &buffer, "%.*s" ARG_END , p->rm_eo - p->rm_so, + message + p->rm_so); + ++p; + } +#else + for ( i = 1; i < msg->regexp.re_nsub+1; i ++ ) { + if ( match[i].rm_so != -1 ) { +#ifdef DEBUG + printf ("Send matching arg%d %d %d\n",i,match[i].rm_so , match[i].rm_eo); + printf ("Send matching arg%d %.*s\n",i,(int)(match[i].rm_eo - match[i].rm_so), + message + match[i].rm_so); +#endif + buffer.offset += make_message_var( &buffer, "%.*s" ARG_END ,(int)(match[i].rm_eo - match[i].rm_so), + message + match[i].rm_so); + } else { + buffer.offset += make_message_var( &buffer, ARG_END ); + } + } +#endif + return 1; +} +#endif /* USE_PCRE_REGEX */ + static int CheckRegexp(char *exp) { - /* accepte tout par default */ int i; - int regexp_ok = 1; + int regexp_ok = 1; /* accepte tout par default */ + char token[200]; + if ( *exp =='^' && messages_classes_count !=0 ) { regexp_ok = 0; + + /* extract token */ + int err = ExtractTokenRegexp ( exp, token, sizeof(token)); + if ( err < 1 ) return 1; for ( i = 0 ; i < messages_classes_count; i++ ) { - if (strncmp( messages_classes[i], exp+1, strlen( messages_classes[i] )) == 0) + if (strncmp( messages_classes[i], token, strlen( token )) == 0) return 1; } } @@ -709,6 +783,42 @@ void IvyClasses( int argc, const char **argv) { messages_classes_count = argc; messages_classes = argv; + +#ifndef USE_PCRE_REGEX + regex_t regexp; + int reg; +#else + pcre *regexp; + const char *errbuf; + int erroffset; +#endif + /* compile the token extraction regexp */ +#ifndef USE_PCRE_REGEX + reg = regcomp(&token_extract, "^\\^([a-zA-Z_0-9-]+).*", REGCOMP_OPT|REG_EXTENDED); + if ( reg == 0 ) + { + } + else + { + char errbuf[4096]; + regerror (reg, ®exp, errbuf, 4096); + printf("Error compiling Token Extract regexp: %s\n", errbuf); + } +#else + token_extract = pcre_compile("^\\^([a-zA-Z_0-9-]+).*", PCRE_OPT,&errbuf,&erroffset,NULL); + if ( token_extract != NULL ) + { + token_inspect = pcre_study(token_extract,0,&errbuf); + if (errbuf!=NULL) + { + printf("Error studying Token Extract regexp: %s\n",errbuf); + } + } + else + { + printf("Error compiling Token Extract regexp: %s\n", errbuf); + } +#endif } void IvyStart (const char* bus) -- cgit v1.1 From d20808b04feb328272a35ee2b03f4ae19db23fbe Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 20 Apr 2006 15:51:37 +0000 Subject: cleanup DEBUG code --- src/ivy.c | 143 ++++++++++++++++++++++++++------------------------------------ 1 file changed, 59 insertions(+), 84 deletions(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index 00362ab..dd8aa04 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -39,6 +39,7 @@ #include "ivysocket.h" #include "list.h" #include "ivybuffer.h" +#include "ivydebug.h" #include "ivy.h" #define VERSION 3 @@ -212,17 +213,17 @@ MsgCall (const char *message, MsgSndPtr msg, IvyClientPtr client) ovector, OVECSIZE); if (rc<1) return 0; /* no match */ -#ifdef DEBUG - printf( "Sending message id=%d '%s'\n",msg->id,message); -#endif + + TRACE( "Sending message id=%d '%s'\n",msg->id,message); + buffer.offset = 0; // il faut essayer d'envoyer le message en une seule fois sur la socket // pour eviter au maximun de passer dans le select plusieur fois par message du protocole Ivy // pour eviter la latence ( PB de perfo detecte par ivyperf ping roudtrip ) err = make_message_var( &buffer, "%d %d" ARG_START ,Msg, msg->id); -#ifdef DEBUG - printf( "Send matching args count %ld\n",msg->regexp.re_nsub); -#endif + + TRACE( "Send matching args count %d\n",rc); + index=1; while ( indexregexp, message, MAX_MATCHING_ARGS, match, 0) != 0) return 0; -#ifdef DEBUG - printf( "Sending message id=%d '%s'\n",msg->id,message); -#endif + TRACE( "Sending message id=%d '%s'\n",msg->id,message); + // il faut essayer d'envoyer le message en une seule fois sur la socket // pour eviter au maximun de passer dans le select plusieur fois par message du protocole Ivy // pour eviter la latence ( PB detecte par ivyperf ping roudtrip ) buffer.offset = 0; err = make_message_var( &buffer, "%d %d" ARG_START ,Msg, msg->id); -#ifdef DEBUG - printf( "Send matching args count %ld\n",msg->regexp.re_nsub); -#endif //DEBUG + TRACE( "Send matching args count %ld\n",msg->regexp.re_nsub); #ifdef GNU_REGEXP p = &match[1]; @@ -277,18 +275,17 @@ MsgCall (const char *message, MsgSndPtr msg, IvyClientPtr client) #else for ( i = 1; i < msg->regexp.re_nsub+1; i ++ ) { if ( match[i].rm_so != -1 ) { -#ifdef DEBUG - printf ("Send matching arg%d %d %d\n",i,match[i].rm_so , match[i].rm_eo); - printf ("Send matching arg%d %.*s\n",i,(int)(match[i].rm_eo - match[i].rm_so), + + TRACE("Send matching arg%d %d %d\n",i,match[i].rm_so , match[i].rm_eo); + TRACE ("Send matching arg%d %.*s\n",i,(int)(match[i].rm_eo - match[i].rm_so), message + match[i].rm_so); -#endif + buffer.offset += make_message_var( &buffer, "%.*s" ARG_END ,(int)(match[i].rm_eo - match[i].rm_so), message + match[i].rm_so); } else { buffer.offset += make_message_var( &buffer, ARG_END ); -#ifdef DEBUG - printf( "Send matching arg%d VIDE\n",i); -#endif //DEBUG + + TRACE( "Send matching arg%d VIDE\n",i); } } #endif @@ -356,11 +353,11 @@ static int ExtractTokenRegexp (const char *exp, char *buffer, int buffersize) #else for ( i = 1; i < msg->regexp.re_nsub+1; i ++ ) { if ( match[i].rm_so != -1 ) { -#ifdef DEBUG - printf ("Send matching arg%d %d %d\n",i,match[i].rm_so , match[i].rm_eo); - printf ("Send matching arg%d %.*s\n",i,(int)(match[i].rm_eo - match[i].rm_so), + + TRACE ("Send matching arg%d %d %d\n",i,match[i].rm_so , match[i].rm_eo); + TRACE ("Send matching arg%d %.*s\n",i,(int)(match[i].rm_eo - match[i].rm_so), message + match[i].rm_so); -#endif + buffer.offset += make_message_var( &buffer, "%.*s" ARG_END ,(int)(match[i].rm_eo - match[i].rm_so), message + match[i].rm_so); } else { @@ -376,6 +373,7 @@ static int ExtractTokenRegexp (const char *exp, char *buffer, int buffersize) static int CheckRegexp(char *exp) { int i; + int err; int regexp_ok = 1; /* accepte tout par default */ char token[200]; @@ -384,7 +382,7 @@ static int CheckRegexp(char *exp) regexp_ok = 0; /* extract token */ - int err = ExtractTokenRegexp ( exp, token, sizeof(token)); + err = ExtractTokenRegexp ( exp, token, sizeof(token)); if ( err < 1 ) return 1; for ( i = 0 ; i < messages_classes_count; i++ ) { @@ -455,9 +453,7 @@ static void Receive( Client client, void *data, char *line ) { case Bye: -#ifdef DEBUG - printf("Quitting %s\n", line); -#endif //DEBUG + TRACE("Quitting %s\n", line); SocketClose( client ); break; @@ -466,14 +462,14 @@ static void Receive( Client client, void *data, char *line ) break; case AddRegexp: -#ifdef DEBUG - printf("Regexp id=%d exp='%s'\n", id, arg); -#endif //DEBUG + + TRACE("Regexp id=%d exp='%s'\n", id, arg); + if ( !CheckRegexp( arg ) ) { -#ifdef DEBUG - printf("Warning: regexp '%s' illegal, removing from %s\n",arg,ApplicationName); -#endif //DEBUG + + TRACE("Warning: regexp '%s' illegal, removing from %s\n",arg,ApplicationName); + if ( application_bind_callback ) { (*application_bind_callback)( clnt, application_bind_data, id, arg, IvyFilterBind ); @@ -530,9 +526,8 @@ static void Receive( Client client, void *data, char *line ) #endif break; case DelRegexp: -#ifdef DEBUG - printf("Regexp Delete id=%d\n", id); -#endif //DEBUG + + TRACE("Regexp Delete id=%d\n", id); IVY_LIST_ITER( clnt->msg_send, snd, ( id != snd->id )); if ( snd ) @@ -552,25 +547,24 @@ static void Receive( Client client, void *data, char *line ) } break; case StartRegexp: -#ifdef DEBUG - printf("Regexp Start id=%d Application='%s'\n", id, arg); -#endif //DEBUG + + TRACE("Regexp Start id=%d Application='%s'\n", id, arg); + clnt->app_name = strdup( arg ); clnt->app_port = id; if ( CheckConnected( clnt ) ) { -#ifdef DEBUG - printf("Quitting already connected %s\n", line); -#endif //DEBUG + + TRACE("Quitting already connected %s\n", line); + IvySendError( clnt, 0, "Application already connected" ); SocketClose( client ); } break; case EndRegexp: -#ifdef DEBUG - printf("Regexp End id=%d\n", id); -#endif //DEBUG + TRACE("Regexp End id=%d\n", id); + if ( application_callback ) { (*application_callback)( clnt, application_user_data, IvyApplicationConnected ); @@ -580,17 +574,12 @@ static void Receive( Client client, void *data, char *line ) int count; count = ClientCall( clnt, ready_message ); -#ifdef DEBUG - printf(" Sendind ready message %d\n", count); -#endif //DEBUG - + TRACE(" Sendind ready message %d\n", count); } break; case Msg: -#ifdef DEBUG - printf("Message id=%d msg='%s'\n", id, arg); -#endif //DEBUG + TRACE("Message id=%d msg='%s'\n", id, arg); IVY_LIST_EACH( msg_recv, rcv ) { @@ -602,9 +591,7 @@ static void Receive( Client client, void *data, char *line ) argv[argc++] = arg; arg = nextArg( 0, ARG_END ); } -#ifdef DEBUG - printf("Calling id=%d argc=%d for %s\n", id, argc,rcv->regexp); -#endif + TRACE("Calling id=%d argc=%d for %s\n", id, argc,rcv->regexp); if ( rcv->callback ) (*rcv->callback)( clnt, rcv->user_data, argc, argv ); return; } @@ -613,9 +600,7 @@ static void Receive( Client client, void *data, char *line ) break; case DirectMsg: -#ifdef DEBUG - printf("Direct Message id=%d msg='%s'\n", id, arg); -#endif //DEBUG + TRACE("Direct Message id=%d msg='%s'\n", id, arg); if ( direct_callback) (*direct_callback)( clnt, direct_user_data, id, arg ); @@ -623,9 +608,7 @@ static void Receive( Client client, void *data, char *line ) case Die: -#ifdef DEBUG - printf("Die Message\n"); -#endif //DEBUG + TRACE("Die Message\n"); if ( application_die_callback) (*application_die_callback)( clnt, application_die_user_data, id ); @@ -678,7 +661,7 @@ static void ClientDelete( Client client, void *data ) #ifdef DEBUG /* probably bogus call, but this is for debug only anyway */ SocketGetRemoteHost( client, &remotehost, &remoteport ); - printf("Deconnexion de %s:%hu\n", remotehost, remoteport ); + TRACE("Deconnexion de %s:%hu\n", remotehost, remoteport ); #endif //DEBUG if ( clnt->app_name ) free( clnt->app_name ); @@ -698,7 +681,7 @@ static void *ClientCreate( Client client ) char *remotehost; unsigned short remoteport; SocketGetRemoteHost( client, &remotehost, &remoteport ); - printf("Connexion de %s:%hu\n", remotehost, remoteport ); + TRACE("Connexion de %s:%hu\n", remotehost, remoteport ); #endif //DEBUG return SendService (client); @@ -739,7 +722,7 @@ static void BroadcastReceive( Client client, void *data, char *line ) #ifdef DEBUG SocketGetRemoteHost (client, &remotehost, &remoteport ); - printf(" Broadcast de %s:%hu port %hu\n", remotehost, remoteport, serviceport ); + TRACE(" Broadcast de %s:%hu port %hu\n", remotehost, remoteport, serviceport ); #endif //DEBUG /* connect to the service and send the regexp */ @@ -773,25 +756,18 @@ void IvySetBindCallback(IvyBindCallback bind_callback, void *bind_data application_bind_data=bind_data; } -void IvyDelBindCallback() -{ - application_bind_callback=0; - free(application_bind_data); - application_bind_data=0; -} void IvyClasses( int argc, const char **argv) { - messages_classes_count = argc; - messages_classes = argv; #ifndef USE_PCRE_REGEX - regex_t regexp; int reg; #else - pcre *regexp; const char *errbuf; int erroffset; #endif + messages_classes_count = argc; + messages_classes = argv; + /* compile the token extraction regexp */ #ifndef USE_PCRE_REGEX reg = regcomp(&token_extract, "^\\^([a-zA-Z_0-9-]+).*", REGCOMP_OPT|REG_EXTENDED); @@ -930,9 +906,7 @@ void IvyStart (const char* bus) ++p; } -#ifdef DEBUG - fprintf (stderr,"Listening on TCP:%hu\n",ApplicationPort); -#endif + TRACE ("Listening on TCP:%hu\n",ApplicationPort); } @@ -995,9 +969,7 @@ int IvySendMsg(const char *fmt, ...) IVY_LIST_EACH (clients, clnt) { match_count += ClientCall (clnt, buffer.data); } -#ifdef DEBUG - if ( match_count == 0 ) printf( "Warning no recipient for %s\n",buffer); -#endif + TRACE_IF( match_count == 0, "Warning no recipient for %s\n",buffer.data); return match_count; } @@ -1066,6 +1038,9 @@ void IvyDefaultBindCallback( IvyClientPtr app, void *user_data, int id, char* re case IvyRemoveBind: 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; @@ -1079,22 +1054,22 @@ IvyClientPtr IvyGetApplication( char *name ) return app; } -char *IvyGetApplicationList() +char *IvyGetApplicationList(const char *sep) { - static char applist[4096]; + static char applist[4096]; /* TODO remove that ugly Thing */ IvyClientPtr app; applist[0] = '\0'; IVY_LIST_EACH( clients, app ) { strcat( applist, app->app_name ); - strcat( applist, " " ); + strcat( applist, sep ); } return applist; } char **IvyGetApplicationMessages( IvyClientPtr app ) { - static char *messagelist[200]; + static char *messagelist[200];/* TODO remove that ugly Thing */ MsgSndPtr msg; int msgCount= 0; memset( messagelist, 0 , sizeof( messagelist )); -- cgit v1.1 From a885259e1ffaa6de1d71107d19c815fb7875c86a Mon Sep 17 00:00:00 2001 From: fcolin Date: Fri, 21 Apr 2006 12:13:54 +0000 Subject: Separation du code Regexp dans un module --- src/ivy.c | 290 +++++--------------------------------------------------------- 1 file changed, 23 insertions(+), 267 deletions(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index dd8aa04..6502ea8 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -26,13 +26,6 @@ #include #include -#ifndef USE_PCRE_REGEX -#include -#else -#define OVECSIZE 60 /* must be multiple of 3, for regexp return */ -#include -#endif - #include #include "ivychannel.h" @@ -40,6 +33,7 @@ #include "list.h" #include "ivybuffer.h" #include "ivydebug.h" +#include "ivybind.h" #include "ivy.h" #define VERSION 3 @@ -86,12 +80,7 @@ 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 + IvyBinding binding; /* la regexp sous forme machine */ }; struct _clnt_lst { @@ -116,16 +105,6 @@ static Client broadcast; static const char *ApplicationName = 0; -/* classes de messages emis par l'application utilise pour le filtrage */ -static int messages_classes_count = 0; -static const char **messages_classes = 0; -/* regexp d'extraction du mot clef des regexp client pour le filtrage des regexp , ca va c'est clair ??? */ -#ifndef USE_PCRE_REGEX - regex_t token_extract; -#else - pcre *token_extract; - pcre_extra *token_inspect; -#endif /* callback appele sur reception d'un message direct */ static MsgDirectCallback direct_callback = 0; @@ -194,24 +173,17 @@ static void IvyCleanup() SocketClose( broadcast ); } -#ifdef USE_PCRE_REGEX -static int -MsgCall (const char *message, MsgSndPtr msg, IvyClientPtr client) +static int MsgCall (const char *message, MsgSndPtr msg, IvyClientPtr client) { int waiting = 0; static IvyBuffer buffer = { NULL, 0, 0 }; /* Use satic mem to eliminate multiple call to malloc /free */ int err; - 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); + int arglen; + const char *arg; + + int rc= IvyBindingExec( msg->binding, message ); + if (rc<1) return 0; /* no match */ TRACE( "Sending message id=%d '%s'\n",msg->id,message); @@ -226,8 +198,8 @@ MsgCall (const char *message, MsgSndPtr msg, IvyClientPtr client) index=1; while ( indexbinding, message, index, &arglen, & arg ); + err = make_message_var( &buffer, "%.*s" ARG_END , arglen, arg ); ++index; } err = make_message_var( &buffer, "\n"); @@ -237,65 +209,7 @@ MsgCall (const char *message, MsgSndPtr msg, IvyClientPtr client) return 1; } -#else /* we don't USE_PCRE_REGEX */ -static int -MsgCall (const char *message, MsgSndPtr msg, IvyClientPtr client) -{ - int waiting = 0; - static IvyBuffer buffer = { NULL, 0, 0 }; /* Use satic mem to eliminate multiple call to malloc /free */ - int err; - - regmatch_t match[MAX_MATCHING_ARGS+1]; -#ifdef GNU_REGEXP - regmatch_t* p; -#else - unsigned int i; -#endif - memset( match, -1, sizeof(match )); /* work around bug !!!*/ - if (regexec (&msg->regexp, message, MAX_MATCHING_ARGS, match, 0) != 0) - return 0; - - TRACE( "Sending message id=%d '%s'\n",msg->id,message); - - // il faut essayer d'envoyer le message en une seule fois sur la socket - // pour eviter au maximun de passer dans le select plusieur fois par message du protocole Ivy - // pour eviter la latence ( PB detecte par ivyperf ping roudtrip ) - buffer.offset = 0; - err = make_message_var( &buffer, "%d %d" ARG_START ,Msg, msg->id); - - TRACE( "Send matching args count %ld\n",msg->regexp.re_nsub); - -#ifdef GNU_REGEXP - p = &match[1]; - while ( p->rm_so != -1 ) { - err = make_message_var( &buffer, "%.*s" ARG_END , p->rm_eo - p->rm_so, - message + p->rm_so); - ++p; - } -#else - for ( i = 1; i < msg->regexp.re_nsub+1; i ++ ) { - if ( match[i].rm_so != -1 ) { - - TRACE("Send matching arg%d %d %d\n",i,match[i].rm_so , match[i].rm_eo); - TRACE ("Send matching arg%d %.*s\n",i,(int)(match[i].rm_eo - match[i].rm_so), - message + match[i].rm_so); - - buffer.offset += make_message_var( &buffer, "%.*s" ARG_END ,(int)(match[i].rm_eo - match[i].rm_so), - message + match[i].rm_so); - } else { - buffer.offset += make_message_var( &buffer, ARG_END ); - - TRACE( "Send matching arg%d VIDE\n",i); - } - } -#endif - err = make_message_var( &buffer,"\n"); - SocketSendRaw(client->client, buffer.data , buffer.offset); - return 1; -} -#endif /* USE_PCRE_REGEX */ - static int ClientCall (IvyClientPtr clnt, const char *message) { @@ -307,91 +221,6 @@ ClientCall (IvyClientPtr clnt, const char *message) } return match_count; } -#ifdef USE_PCRE_REGEX -static int ExtractTokenRegexp (const char *exp, char *buffer, int buffersize) -{ -#define TOKEN_OVECSIZE 3*2 /* must be multiple of 3, for regexp return */ - int ovector[TOKEN_OVECSIZE]; - int rc=pcre_exec( - token_extract, - token_inspect, - exp, - strlen(exp), - 0, /* debut */ - 0, /* no other regexp option */ - ovector, - TOKEN_OVECSIZE); - /*if (rc<1) return rc; *//* no match */ - - return pcre_copy_substring(exp, ovector, rc, 1, buffer, buffersize); - - -} - -#else /* we don't USE_PCRE_REGEX */ -static int ExtractTokenRegexp (const char *exp, char *buffer, int buffersize) -{ - int err; - - regmatch_t match[MAX_MATCHING_ARGS+1]; -#ifdef GNU_REGEXP - regmatch_t* p; -#else - unsigned int i; -#endif - memset( match, -1, sizeof(match )); /* work around bug !!!*/ - if (regexec (&msg->regexp, message, MAX_MATCHING_ARGS, match, 0) != 0) - return 0; - -#ifdef GNU_REGEXP - p = &match[1]; - while ( p->rm_so != -1 ) { - err = make_message_var( &buffer, "%.*s" ARG_END , p->rm_eo - p->rm_so, - message + p->rm_so); - ++p; - } -#else - for ( i = 1; i < msg->regexp.re_nsub+1; i ++ ) { - if ( match[i].rm_so != -1 ) { - - TRACE ("Send matching arg%d %d %d\n",i,match[i].rm_so , match[i].rm_eo); - TRACE ("Send matching arg%d %.*s\n",i,(int)(match[i].rm_eo - match[i].rm_so), - message + match[i].rm_so); - - buffer.offset += make_message_var( &buffer, "%.*s" ARG_END ,(int)(match[i].rm_eo - match[i].rm_so), - message + match[i].rm_so); - } else { - buffer.offset += make_message_var( &buffer, ARG_END ); - } - } -#endif - - return 1; -} -#endif /* USE_PCRE_REGEX */ - -static int CheckRegexp(char *exp) -{ - int i; - int err; - int regexp_ok = 1; /* accepte tout par default */ - char token[200]; - - if ( *exp =='^' && messages_classes_count !=0 ) - { - regexp_ok = 0; - - /* extract token */ - err = ExtractTokenRegexp ( exp, token, sizeof(token)); - if ( err < 1 ) return 1; - for ( i = 0 ; i < messages_classes_count; i++ ) - { - if (strncmp( messages_classes[i], token, strlen( token )) == 0) - return 1; - } - } - return regexp_ok; -} static int CheckConnected( IvyClientPtr clnt ) { @@ -428,14 +257,10 @@ static void Receive( Client client, void *data, char *line ) char *argv[MAX_MATCHING_ARGS]; char *arg; int kind_of_msg = Bye; -#ifndef USE_PCRE_REGEX - regex_t regexp; - int reg; -#else - pcre *regexp; + IvyBinding bind; + const char *errbuf; int erroffset; -#endif err = sscanf( line ,"%d %d", &kind_of_msg, &id ); arg = strstr( line , ARG_START ); @@ -465,7 +290,7 @@ static void Receive( Client client, void *data, char *line ) TRACE("Regexp id=%d exp='%s'\n", id, arg); - if ( !CheckRegexp( arg ) ) + if ( !IvyBindingFilter( arg ) ) { TRACE("Warning: regexp '%s' illegal, removing from %s\n",arg,ApplicationName); @@ -476,41 +301,14 @@ static void Receive( Client client, void *data, char *line ) } return; } -#ifndef USE_PCRE_REGEX - reg = regcomp(®exp, arg, REGCOMP_OPT|REG_EXTENDED); - if ( reg == 0 ) - { - IVY_LIST_ADD_START( clnt->msg_send, snd ) - snd->id = id; - snd->str_regexp = strdup( arg ); - snd->regexp = regexp; - if ( application_bind_callback ) - { - (*application_bind_callback)( clnt, application_bind_data, id, snd->str_regexp, IvyAddBind ); - } - IVY_LIST_ADD_END( clnt->msg_send, snd ) - } - else - { - char errbuf[4096]; - regerror (reg, ®exp, errbuf, 4096); - printf("Error compiling '%s', %s\n", arg, errbuf); - MsgSendTo( client, Error, reg, errbuf ); - } -#else - regexp = pcre_compile(arg, PCRE_OPT,&errbuf,&erroffset,NULL); - if ( regexp != NULL ) + + bind = IvyBindingCompile( arg ); + if ( bind != NULL ) { IVY_LIST_ADD_START( clnt->msg_send, 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); - } - + snd->binding = bind; if ( application_bind_callback ) { (*application_bind_callback)( clnt, application_bind_data, id, snd->str_regexp, IvyAddBind ); @@ -520,10 +318,11 @@ static void Receive( Client client, void *data, char *line ) } else { + IvyBindingGetCompileError( & erroffset, & errbuf ); printf("Error compiling '%s', %s\n", arg, errbuf); MsgSendTo( client, Error, erroffset, errbuf ); } -#endif + break; case DelRegexp: @@ -536,13 +335,7 @@ static void Receive( Client client, void *data, char *line ) { (*application_bind_callback)( clnt, application_bind_data, id, snd->str_regexp, IvyRemoveBind ); } -#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 + IvyBindingFree( snd->binding ); IVY_LIST_REMOVE( clnt->msg_send, snd ); } break; @@ -749,52 +542,15 @@ void IvyInit (const char *appname, const char *ready, ready_message = ready; } -void IvySetBindCallback(IvyBindCallback bind_callback, void *bind_data - ) +void IvySetBindCallback( IvyBindCallback bind_callback, void *bind_data ) { application_bind_callback=bind_callback; application_bind_data=bind_data; } -void IvyClasses( int argc, const char **argv) +void IvySetFilter( int argc, const char **argv) { - -#ifndef USE_PCRE_REGEX - int reg; -#else - const char *errbuf; - int erroffset; -#endif - messages_classes_count = argc; - messages_classes = argv; - - /* compile the token extraction regexp */ -#ifndef USE_PCRE_REGEX - reg = regcomp(&token_extract, "^\\^([a-zA-Z_0-9-]+).*", REGCOMP_OPT|REG_EXTENDED); - if ( reg == 0 ) - { - } - else - { - char errbuf[4096]; - regerror (reg, ®exp, errbuf, 4096); - printf("Error compiling Token Extract regexp: %s\n", errbuf); - } -#else - token_extract = pcre_compile("^\\^([a-zA-Z_0-9-]+).*", PCRE_OPT,&errbuf,&erroffset,NULL); - if ( token_extract != NULL ) - { - token_inspect = pcre_study(token_extract,0,&errbuf); - if (errbuf!=NULL) - { - printf("Error studying Token Extract regexp: %s\n",errbuf); - } - } - else - { - printf("Error compiling Token Extract regexp: %s\n", errbuf); - } -#endif + IvyBindingSetFilter( argc, argv ); } void IvyStart (const char* bus) -- cgit v1.1 From 8b42932b4ec978040acf341e69cd7b037721b24f Mon Sep 17 00:00:00 2001 From: fcolin Date: Fri, 21 Apr 2006 12:49:19 +0000 Subject: separation regexp en module ( bug arg num edbute a 1 ) --- src/ivy.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index 6502ea8..5e887d5 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -196,11 +196,10 @@ static int MsgCall (const char *message, MsgSndPtr msg, IvyClientPtr client) TRACE( "Send matching args count %d\n",rc); - index=1; - while ( indexbinding, message, index, &arglen, & arg ); err = make_message_var( &buffer, "%.*s" ARG_END , arglen, arg ); - ++index; } err = make_message_var( &buffer, "\n"); waiting = SocketSendRaw(client->client, buffer.data , buffer.offset); -- cgit v1.1 From 2cf893c0c34d50a68a27e1704b38f2facc10c9bc Mon Sep 17 00:00:00 2001 From: fcolin Date: Fri, 21 Apr 2006 15:51:55 +0000 Subject: suppression de l'indirection sur les fonction channel et renomage ! --- src/ivy.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index 5e887d5..b78d227 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -301,7 +301,7 @@ static void Receive( Client client, void *data, char *line ) return; } - bind = IvyBindingCompile( arg ); + bind = IvyBindingCompile( arg, & erroffset, & errbuf ); if ( bind != NULL ) { IVY_LIST_ADD_START( clnt->msg_send, snd ) @@ -317,7 +317,6 @@ static void Receive( Client client, void *data, char *line ) } else { - IvyBindingGetCompileError( & erroffset, & errbuf ); printf("Error compiling '%s', %s\n", arg, errbuf); MsgSendTo( client, Error, erroffset, errbuf ); } -- cgit v1.1 From 1e48ff652b95379376044b0a7187e1c75fb76d42 Mon Sep 17 00:00:00 2001 From: fcolin Date: Fri, 21 Apr 2006 16:34:15 +0000 Subject: cleanup sur channel et main loop --- src/ivy.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index b78d227..157cf08 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -551,6 +551,12 @@ void IvySetFilter( int argc, const char **argv) IvyBindingSetFilter( argc, argv ); } +void IvyStop (void) +{ + IvyChannelStop(); +} + + void IvyStart (const char* bus) { -- cgit v1.1 From 3d7f9a4339556f458005fbfb3da2072aff4e1d9c Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 11 May 2006 16:42:00 +0000 Subject: correction Bug introduit lors de la separation ivybind ( regexp sans argument ) --- src/ivy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index 157cf08..a0c51c7 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -196,7 +196,7 @@ static int MsgCall (const char *message, MsgSndPtr msg, IvyClientPtr client) TRACE( "Send matching args count %d\n",rc); - for( index=0; index < rc ; index++ ) + for( index=1; index < rc ; index++ ) { IvyBindingMatch( msg->binding, message, index, &arglen, & arg ); err = make_message_var( &buffer, "%.*s" ARG_END , arglen, arg ); -- cgit v1.1 From 7f92954dad8f5a5fdc0ecdda35cb04c16420f172 Mon Sep 17 00:00:00 2001 From: fcolin Date: Fri, 19 May 2006 09:45:06 +0000 Subject: modification du protocol Ivy UDP : ajout de appid et appname dans le mesage Hello --- src/ivy.c | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index a0c51c7..85db2bc 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -16,9 +16,12 @@ * copyright notice regarding this software */ + #include #ifdef WIN32 +#include #else +#include #include #endif #include @@ -104,6 +107,7 @@ static unsigned short SupervisionPort; static Client broadcast; static const char *ApplicationName = 0; +static const char *ApplicationID = 0; /* callback appele sur reception d'un message direct */ @@ -414,7 +418,7 @@ static void Receive( Client client, void *data, char *line ) } -static IvyClientPtr SendService( Client client ) +static IvyClientPtr SendService( Client client, const char *appname ) { IvyClientPtr clnt; MsgRcvPtr msg; @@ -422,7 +426,7 @@ static IvyClientPtr SendService( Client client ) clnt->msg_send = 0; clnt->client = client; - clnt->app_name = strdup("Unknown"); + clnt->app_name = strdup(appname); clnt->app_port = 0; MsgSendTo( client, StartRegexp, ApplicationPort, ApplicationName); IVY_LIST_EACH(msg_recv, msg ) @@ -475,7 +479,7 @@ static void *ClientCreate( Client client ) TRACE("Connexion de %s:%hu\n", remotehost, remoteport ); #endif //DEBUG - return SendService (client); + return SendService (client, "Unknown"); } static void BroadcastReceive( Client client, void *data, char *line ) @@ -484,13 +488,16 @@ static void BroadcastReceive( Client client, void *data, char *line ) int err; int version; unsigned short serviceport; + char appid[2048]; + char appname[2048]; #ifdef DEBUG unsigned short remoteport; char *remotehost = 0; #endif - - err = sscanf (line,"%d %hu", &version, &serviceport); - if ( err != 2 ) { + memset( appid, 0, sizeof( appid ) ); + memset( appname, 0, sizeof( appname ) ); + err = sscanf (line,"%d %hu %s %[^\n]", &version, &serviceport, appid, appname); + if ( err < 2 ) { /* ignore the message */ unsigned short remoteport; char *remotehost; @@ -509,6 +516,7 @@ static void BroadcastReceive( Client client, void *data, char *line ) return; } /* check if we received our own message. SHOULD ALSO TEST THE HOST */ + if ( strcmp( appid , ApplicationID) ==0 ) return; if (serviceport == ApplicationPort) return; #ifdef DEBUG @@ -520,11 +528,33 @@ static void BroadcastReceive( Client client, void *data, char *line ) app = SocketConnectAddr(SocketGetRemoteAddr(client), serviceport, 0, Receive, ClientDelete ); if (app) { IvyClientPtr clnt; - clnt = SendService( app ); + clnt = SendService( app, appname ); SocketSetData( app, clnt); } } +static unsigned long currentTime() +{ +#define MILLISEC 1000 + unsigned long current; +#ifdef WIN32 + current = GetTickCount(); +#else + struct timeval stamp; + gettimeofday( &stamp, NULL ); + current = stamp.tv_sec * MILLISEC + stamp.tv_usec/MILLISEC; +#endif + return current; +} +static const char * GenApplicationUniqueIdentifier() +{ + static char appid[2048]; + long curtime; + curtime = currentTime(); + srandom( curtime ); + sprintf(appid,"%ld:%ld:%d",random(),curtime,ApplicationPort); + return appid; +} void IvyInit (const char *appname, const char *ready, IvyApplicationCallback callback, void *data, IvyDieCallback die_callback, void *die_data @@ -576,7 +606,8 @@ void IvyStart (const char* bus) */ server = SocketServer (ANYPORT, ClientCreate, ClientDelete, Receive); ApplicationPort = SocketServerGetPort (server); - + ApplicationID = GenApplicationUniqueIdentifier(); + /* * Find network list as well as broadcast port * (we accept things like 123.231,123.123:2000 or 123.231 or :2000), @@ -636,7 +667,7 @@ void IvyStart (const char* bus) if ( IN_MULTICAST( mask ) ) SocketAddMember (broadcast , mask ); - SocketSendBroadcast (broadcast, mask, SupervisionPort, "%d %hu\n", VERSION, ApplicationPort); + SocketSendBroadcast (broadcast, mask, SupervisionPort, "%d %hu %s %s\n", VERSION, ApplicationPort, ApplicationID, ApplicationName); numelem = 0; mask = 0xffffffff; } -- cgit v1.1 From 345d453e395dedbb8f148b10bc397e002f1aaa96 Mon Sep 17 00:00:00 2001 From: fcolin Date: Fri, 19 May 2006 10:33:30 +0000 Subject: portage WIN32 random => rand --- src/ivy.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index 85db2bc..7ea05b0 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -7,8 +7,7 @@ * * Main functions * - * Authors: Francois-Regis Colin - * Stephane Chatty + * Authors: Francois-Regis Colin,Stephane Chatty * * $Id$ * @@ -551,8 +550,8 @@ static const char * GenApplicationUniqueIdentifier() static char appid[2048]; long curtime; curtime = currentTime(); - srandom( curtime ); - sprintf(appid,"%ld:%ld:%d",random(),curtime,ApplicationPort); + srand( curtime ); + sprintf(appid,"%ld:%ld:%d",rand(),curtime,ApplicationPort); return appid; } void IvyInit (const char *appname, const char *ready, -- cgit v1.1 From e92664a2d022562844646e42357e63c4e196974d Mon Sep 17 00:00:00 2001 From: fcolin Date: Fri, 19 May 2006 10:35:30 +0000 Subject: suppression warning format --- src/ivy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index 7ea05b0..7feffd0 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -551,7 +551,7 @@ static const char * GenApplicationUniqueIdentifier() long curtime; curtime = currentTime(); srand( curtime ); - sprintf(appid,"%ld:%ld:%d",rand(),curtime,ApplicationPort); + sprintf(appid,"%d:%ld:%d",rand(),curtime,ApplicationPort); return appid; } void IvyInit (const char *appname, const char *ready, -- cgit v1.1 From 442107b69be55cd0ab0d7c8554096d9d20c37d08 Mon Sep 17 00:00:00 2001 From: fcolin Date: Fri, 2 Jun 2006 14:50:40 +0000 Subject: correction d'un petit pb dans la generation de l'appID ( signe - ) --- src/ivy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index 7feffd0..af7cdc9 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -548,10 +548,10 @@ static unsigned long currentTime() static const char * GenApplicationUniqueIdentifier() { static char appid[2048]; - long curtime; + unsigned long curtime; curtime = currentTime(); srand( curtime ); - sprintf(appid,"%d:%ld:%d",rand(),curtime,ApplicationPort); + sprintf(appid,"%d:%lu:%d",rand(),curtime,ApplicationPort); return appid; } void IvyInit (const char *appname, const char *ready, -- cgit v1.1 From 0b7f0c87dd47ec35d788ee1e3a574a8b21d7e331 Mon Sep 17 00:00:00 2001 From: fcolin Date: Tue, 6 Jun 2006 13:59:49 +0000 Subject: ajout test de controle des argument de IvySendMsg. --- src/ivy.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index af7cdc9..5f5a93c 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -750,6 +750,7 @@ int IvySendMsg(const char *fmt, ...) static IvyBuffer buffer = { NULL, 0, 0}; /* Use satic mem to eliminate multiple call to malloc /free */ va_list ap; + if( fmt == 0 || strlen(fmt) == 0 ) return 0; va_start( ap, fmt ); buffer.offset = 0; make_message( &buffer, fmt, ap ); -- cgit v1.1 From 4cdbde3775be5c961d11bb5497d1c97e07c429b2 Mon Sep 17 00:00:00 2001 From: fcolin Date: Fri, 16 Jun 2006 14:36:22 +0000 Subject: correction d'un BUG dans IvyGetMessages ( si nb > 200 ) ajout d'un argument -f a ivyprobe pour passer des regexps dans un fichier --- src/ivy.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index 5f5a93c..e0102c8 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -860,7 +860,8 @@ char *IvyGetApplicationList(const char *sep) char **IvyGetApplicationMessages( IvyClientPtr app ) { - static char *messagelist[200];/* TODO remove that ugly Thing */ +#define MAX_REGEXP 4096 + static char *messagelist[MAX_REGEXP+1];/* TODO remove that ugly Thing */ MsgSndPtr msg; int msgCount= 0; memset( messagelist, 0 , sizeof( messagelist )); @@ -868,6 +869,11 @@ char **IvyGetApplicationMessages( IvyClientPtr app ) IVY_LIST_EACH( app->msg_send, msg ) { messagelist[msgCount++]= msg->str_regexp; + if ( msgCount >= MAX_REGEXP ) + { + fprintf(stderr,"Too Much expression(%d) for buffer\n",msgCount); + break; + } } return messagelist; } -- cgit v1.1 From 25bb709ea9453a6a0d49a7e38ec0150271ccc6bc Mon Sep 17 00:00:00 2001 From: fcolin Date: Fri, 16 Jun 2006 14:40:59 +0000 Subject: *** empty log message *** --- src/ivy.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index e0102c8..51f1215 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -244,6 +244,11 @@ static int CheckConnected( IvyClientPtr clnt ) if ( addr1->s_addr == addr2->s_addr ) return 1; } + /* client different mais applicationID identique */ + if ( (client != clnt) && (clnt->app_id == client->app_id) ) + { + return 1; + } } return 0; -- cgit v1.1 From 91c16c398d72cb2099294d86f4e9cbaf12a3d3da Mon Sep 17 00:00:00 2001 From: fcolin Date: Fri, 16 Jun 2006 14:44:57 +0000 Subject: est ce utilite de verifier le AppID au moment de la connexion ??? en principe le test est realise a la reception du Hello CVS ---------------------------------------------------------------------- --- src/ivy.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index 51f1215..e4cbb04 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -245,10 +245,12 @@ static int CheckConnected( IvyClientPtr clnt ) return 1; } /* client different mais applicationID identique */ + /* TODO est-ce utile ??? verif dans UDP if ( (client != clnt) && (clnt->app_id == client->app_id) ) { return 1; } + */ } return 0; -- cgit v1.1 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 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/ivy.c') 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; } -- cgit v1.1 From 6e308b84f4aa8d08b590538827e64b3be0d3d6e0 Mon Sep 17 00:00:00 2001 From: bustico Date: Wed, 26 Jul 2006 15:34:22 +0000 Subject: ajout de la gestion des pings : répond un pong lors de la reception d'un ping --- src/ivy.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index fd5204b..b9e52ec 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -64,8 +64,9 @@ typedef enum { EndRegexp, /* end of the regexp list */ StartRegexp, /* debut des expressions */ DirectMsg, /* message direct a destination de l'appli */ - Die /* demande de terminaison de l'appli */ - + Die, /* demande de terminaison de l'appli */ + Ping, /* message de controle ivy */ + Pong /* ivy doit renvoyer ce message à la reception d'un ping */ } MsgType; typedef struct _msg_snd *MsgSndPtr; @@ -420,6 +421,18 @@ static void Receive( Client client, void *data, char *line ) exit(0); break; + case Ping: + + TRACE("Ping Message\n"); + MsgSendTo( client, Pong, 0, "" ); + break; + + case Pong: + + TRACE("Pong Message\n"); + printf("Receive unhandled Pong message (ivy-c not able to send ping)\n"); + break; + default: printf("Receive unhandled message %s\n", line); break; -- cgit v1.1 From ff5456022b53f2bc971874621ffa78c0416869c8 Mon Sep 17 00:00:00 2001 From: bustico Date: Fri, 28 Jul 2006 09:09:29 +0000 Subject: modification des messages ping et pong qui utilisent le champ id pour transporter un identifiant --- src/ivy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index b9e52ec..e7866a5 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -424,7 +424,7 @@ static void Receive( Client client, void *data, char *line ) case Ping: TRACE("Ping Message\n"); - MsgSendTo( client, Pong, 0, "" ); + MsgSendTo( client, Pong, id, "" ); break; case Pong: -- cgit v1.1 From 0efdf8c11e50d6aed89ed72760a72e68b701bf9d Mon Sep 17 00:00:00 2001 From: bustico Date: Wed, 20 Sep 2006 09:28:59 +0000 Subject: Ajout de la fonctionnalité pour capter des intervalles numériques de la forme A=((?I10#20)) l'api ne change pas. --- src/ivy.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index e7866a5..f9d5f23 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -30,6 +30,7 @@ #include +#include "intervalRegexp.h" #include "ivychannel.h" #include "ivysocket.h" #include "list.h" @@ -136,6 +137,7 @@ static MsgRcvPtr msg_recv = 0; static IvyClientPtr clients = 0; static const char *ready_message = 0; +static void substituteInterval (IvyBuffer *src); /* * function like strok but do not eat consecutive separator @@ -753,6 +755,8 @@ IvyBindMsg (MsgCallback callback, void *user_data, const char *fmt_regex, ... ) make_message( &buffer, fmt_regex, ap ); va_end (ap ); + substituteInterval (&buffer); + /* add Msg to the query list */ IVY_LIST_ADD_START( msg_recv, msg ) msg->id = recv_id++; @@ -907,3 +911,44 @@ char **IvyGetApplicationMessages( IvyClientPtr app ) } return messagelist; } + +static void substituteInterval (IvyBuffer *src) +{ + // pas de traitement couteux s'il n'y a rien à interpoler + if (strstr (src->data, "(?I") == NULL) { + return; + } else { + IvyBuffer dst = {NULL, 0, 0}; + dst.size = 8192; + dst.data = malloc (dst.size); + + char *curPos = src->data; + char *itvPos; + while ((itvPos = strstr (curPos, "(?I")) != NULL) { + // copie depuis la position courante jusqu'à l'intervalle + int lenCp, min,max; + char withDecimal; + lenCp = itvPos-curPos; + memcpy (&(dst.data[dst.offset]), curPos, lenCp); + curPos=itvPos; + dst.offset += lenCp; + + // extraction des paramètres de l'intervalle + sscanf (itvPos, "(?I%d#%d%c", &min, &max, &withDecimal); + + // printf ("DBG> substituteInterval min=%d max=%d withDecimal=%d\n", + // min, max, (withDecimal != 'i')); + + // generation et copie de l'intervalle + regexpGen (&(dst.data[dst.offset]), dst.size-dst.offset, min, max, (withDecimal != 'i')); + dst.offset = strlen (dst.data); + + // consommation des caractères décrivant intervalle dans la chaine source + curPos = strstr (curPos, ")"); + curPos++; + } + strncat (dst.data, curPos, dst.size-dst.offset); + free (src->data); + src->data = dst.data; + } +} -- cgit v1.1 From 0e1ee0d3f027489c978e27ed5ed3572067234a61 Mon Sep 17 00:00:00 2001 From: fcolin Date: Fri, 22 Sep 2006 08:55:57 +0000 Subject: portage WIN32 --- src/ivy.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index f9d5f23..270711c 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -918,12 +918,13 @@ static void substituteInterval (IvyBuffer *src) if (strstr (src->data, "(?I") == NULL) { return; } else { + char *curPos; + char *itvPos; IvyBuffer dst = {NULL, 0, 0}; dst.size = 8192; dst.data = malloc (dst.size); - char *curPos = src->data; - char *itvPos; + curPos = src->data; while ((itvPos = strstr (curPos, "(?I")) != NULL) { // copie depuis la position courante jusqu'à l'intervalle int lenCp, min,max; -- cgit v1.1 From e761e4e47ad5da0036d4fec4e70319afacd10fd6 Mon Sep 17 00:00:00 2001 From: bustico Date: Fri, 22 Sep 2006 09:41:53 +0000 Subject: ajout du message IvyChangeMessage pour changer la regexp d'un abonnement déjà établi --- src/ivy.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 10 deletions(-) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index 270711c..5231f0d 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -320,16 +320,28 @@ static void Receive( Client client, void *data, char *line ) bind = IvyBindingCompile( arg, & erroffset, & errbuf ); if ( bind != NULL ) { - IVY_LIST_ADD_START( clnt->msg_send, snd ) - snd->id = id; - snd->str_regexp = strdup( arg ); - snd->binding = bind; - if ( application_bind_callback ) - { - (*application_bind_callback)( clnt, application_bind_data, id, snd->str_regexp, IvyAddBind ); - } - IVY_LIST_ADD_END( clnt->msg_send, snd ) - + // On teste si c'est un change regexp : changement de regexp d'une id existante + IVY_LIST_ITER( clnt->msg_send, snd, ( id != snd->id )); + if ( snd ) { + free (snd->str_regexp); + snd->str_regexp = strdup( arg ); + snd->binding = bind; + if ( application_bind_callback ) + { + (*application_bind_callback)( clnt, application_bind_data, id, snd->str_regexp, IvyChangeBind ); + } + } else { + IVY_LIST_ADD_START( clnt->msg_send, snd ) + snd->id = id; + snd->str_regexp = strdup( arg ); + snd->binding = bind; + if ( application_bind_callback ) + { + (*application_bind_callback)( clnt, application_bind_data, id, snd->str_regexp, IvyAddBind ); + } + IVY_LIST_ADD_END( clnt->msg_send, snd ) + + } } else { @@ -771,6 +783,32 @@ IvyBindMsg (MsgCallback callback, void *user_data, const char *fmt_regex, ... ) } return msg; } + +/* changement de regexp d'un bind existant precedement fait avec IvyBindMsg */ +MsgRcvPtr +IvyChangeMsg (MsgRcvPtr msg, const char *fmt_regex, ... ) +{ + static IvyBuffer buffer = { NULL, 0, 0}; + va_list ap; + IvyClientPtr clnt; + + va_start (ap, fmt_regex ); + buffer.offset = 0; + make_message( &buffer, fmt_regex, ap ); + va_end (ap ); + + substituteInterval (&buffer); + + /* change Msg in the query list */ + msg->regexp = strdup(buffer.data); + + /* Send to already connected clients */ + /* recherche dans la liste des requetes recues de mes clients */ + IVY_LIST_EACH( clients, clnt ) { + MsgSendTo( clnt->client, AddRegexp,msg->id,msg->regexp); + } + return msg; +} /* emmission d'un message avec formatage a la printf */ int IvySendMsg(const char *fmt, ...) { @@ -866,6 +904,10 @@ void IvyDefaultBindCallback( IvyClientPtr app, void *user_data, int id, char* re case IvyFilterBind: printf("Application: %s on %s as been filtred regexp %d :%s\n", IvyGetApplicationName( app ), IvyGetApplicationHost(app), id, regexp); break; + case IvyChangeBind: + printf("Application: %s on %s change regexp %d : %s\n", IvyGetApplicationName( app ), IvyGetApplicationHost(app), id, regexp); + break; + break; default: printf("Application: %s unkown event %d\n",IvyGetApplicationName( app ), event); break; -- cgit v1.1