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/Makefile.win32 | 15 +++++------ src/ivy.c | 3 +-- src/ivybind.c | 42 ++++++++++++++---------------- src/ivybind.h | 8 +++--- src/ivychannel.h | 11 +++----- src/ivyloop.c | 8 ++---- src/ivyloop.h | 10 ------- src/ivyprobe.c | 76 ++++++++++++------------------------------------------ src/ivysocket.c | 23 +++++++---------- src/libIvy.def | 14 +++++++--- 10 files changed, 74 insertions(+), 136 deletions(-) diff --git a/src/Makefile.win32 b/src/Makefile.win32 index 651110e..aab6ccd 100755 --- a/src/Makefile.win32 +++ b/src/Makefile.win32 @@ -20,7 +20,7 @@ MAJOR=3 MINOR=8 PCREINC = -I "C:\Documents and Settings\fcolin\My Documents\Visual Studio 2005\Projects\pcre-6.4\\" -PCRELIB = "C:\Documents and Settings\fcolin\My Documents\Visual Studio 2005\Projects\pcre-6.4\lib\libpcre.lib" #`pcre-config --libs` +PCRELIB = Debug\pcre.lib #PCREINC = -I "C:\Program Files\GnuWin32\include" #`pcre-config --cflags` #PCRELIB = "C:\Program Files\GnuWin32\lib\libpcre.lib" #`pcre-config --libs` @@ -48,7 +48,7 @@ REGEXP= /DUSE_PCRE_REGEX /DPCRE_OPT=$(PCRE_OPT) # see below CHANNEL = -DTCL_CHANNEL_INTEGRATION -OBJ = ivyloop.obj timer.obj ivysocket.obj ivy.obj ivybind.obj +OBJ = ivyloop.obj timer.obj ivysocket.obj ivy.obj ivybuffer.obj ivybind.obj getopt.obj # WINDOWS add ivyloop.obj if TCL_CHANNEL_INTEGRATION is not set TARGETS = ivyprobe.exe ivyperf.exe @@ -65,21 +65,18 @@ shared-libs: $(TARGETLIBS) commands: $(TARGETS) -ivy.obj: ivy.c - $(CC) $(CFLAGS) $(REGEXP) $(PCREINC) /c ivy.c +ivybind.obj: ivybind.c + $(CC) $(CFLAGS) $(REGEXP) $(PCREINC) /c ivybind.c ivyprobe.exe: ivyprobe.obj libivy.lib - $(CC) $(CFLAGS) -o $@ ivyprobe.obj libivy.lib wsock32.lib $(PCRELIB) + $(CC) $(CFLAGS) /Fe$@ ivyprobe.obj libivy.lib wsock32.lib $(PCRELIB) ivyprobe.obj : ivyprobe.c $(CC) $(CFLAGS) $(REGEXP) $(PCREINC) /c ivyprobe.c ivyperf.exe: ivyperf.obj libivy.lib - $(CC) $(CFLAGS) -o $@ ivyperf.obj libivy.lib wsock32.lib $(PCRELIB) - -ivyperf.obj : ivyperf.c - $(CC) $(CFLAGS) $(REGEXP) $(PCREINC) /c ivyperf.c + $(CC) $(CFLAGS) /Fe$@ ivyperf.obj libivy.lib wsock32.lib $(PCRELIB) libivy.lib: $(OBJ) 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 ); } diff --git a/src/ivybind.c b/src/ivybind.c index 9522ba5..20e174f 100644 --- a/src/ivybind.c +++ b/src/ivybind.c @@ -31,10 +31,10 @@ #ifdef USE_PCRE_REGEX #define OVECSIZE 60 /* must be multiple of 3, for regexp return */ #include -#else +#else /* we don't USE_PCRE_REGEX */ #define MAX_MSG_FIELDS 200 #include -#endif +#endif /* USE_PCRE_REGEX */ #include "list.h" #include "ivybind.h" @@ -43,21 +43,20 @@ static int err_offset; #ifdef USE_PCRE_REGEX static const char *err_buf; -#else +#else /* we don't USE_PCRE_REGEX */ static char err_buf[4096]; -#endif +#endif /* USE_PCRE_REGEX */ struct _binding { - const char *expression; /* regexp*/ #ifdef USE_PCRE_REGEX pcre *regexp; pcre_extra *inspect; int nb_match; int ovector[OVECSIZE]; -#else +#else /* we don't USE_PCRE_REGEX */ regex_t regexp; /* la regexp sous forme machine */ regmatch_t match[MAX_MSG_FIELDS+1]; /* resultat du match */ -#endif +#endif /* USE_PCRE_REGEX */ }; /* classes de messages emis par l'application utilise pour le filtrage */ @@ -66,7 +65,7 @@ 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 ??? */ static IvyBinding token_extract; -IvyBinding IvyBindingCompile( const char * expression ) +IvyBinding IvyBindingCompile( const char * expression, int *erroffset, const char **errmessage ) { IvyBinding bind=0; #ifdef USE_PCRE_REGEX @@ -90,9 +89,11 @@ IvyBinding IvyBindingCompile( const char * expression ) } else { + *erroffset = err_offset; + *errmessage = err_buf; printf("Error compiling '%s', %s\n", expression, err_buf); } -#else +#else /* we don't USE_PCRE_REGEX */ regex_t regexp; int reg; reg = regcomp(®exp, expression, REGCOMP_OPT|REG_EXTENDED); @@ -106,27 +107,23 @@ IvyBinding IvyBindingCompile( const char * expression ) else { regerror (reg, ®exp, err_buf, sizeof(err_buf) ); - err_offset = 0; // TODO unkown offset error + *erroffset = err_offset; + *errmessage = err_buf; printf("Error compiling '%s', %s\n", expression, err_buf); } -#endif +#endif /* USE_PCRE_REGEX */ return bind; } -void IvyBindingGetCompileError( int *offset, const char **errmessage ) -{ - *offset = err_offset; - *errmessage = err_buf; -} void IvyBindingFree( IvyBinding bind ) { #ifdef USE_PCRE_REGEX if (bind->inspect!=NULL) pcre_free(bind->inspect); pcre_free(bind->regexp); -#else +#else /* we don't USE_PCRE_REGEX */ free( bind->regexp ); -#endif +#endif /* USE_PCRE_REGEX */ free ( bind ); } int IvyBindingExec( IvyBinding bind, const char * message ) @@ -147,7 +144,7 @@ int IvyBindingExec( IvyBinding bind, const char * message ) bind->nb_match = nb_match; nb_match--; // firts arg wall string ??? -#else +#else /* we don't USE_PCRE_REGEX */ memset( bind->match, -1, sizeof(bind->match )); /* work around bug !!!*/ nb_match = regexec (&bind->regexp, message, MAX_MSG_FIELDS, bind->match, 0) if (nb_match == REG_NOMATCH) @@ -157,7 +154,7 @@ int IvyBindingExec( IvyBinding bind, const char * message ) if ( bind->match[i].rm_so != -1 ) nb_match++; } -#endif +#endif /* USE_PCRE_REGEX */ return nb_match; } @@ -180,7 +177,7 @@ void IvyBindingMatch( IvyBinding bind, const char *message, int argnum, int *arg *arglen = 0; *arg = NULL; } -#endif // USE_PCRE_REGEX +#endif /* USE_PCRE_REGEX */ } @@ -194,10 +191,9 @@ void IvyBindingSetFilter( int argc, const char **argv) messages_classes = argv; /* compile the token extraction regexp */ - token_extract = IvyBindingCompile("^\\^([a-zA-Z_0-9-]+).*"); + token_extract = IvyBindingCompile("^\\^([a-zA-Z_0-9-]+).*", & erroffset, & errbuf); if ( !token_extract ) { - IvyBindingGetCompileError( & erroffset, & errbuf ); printf("Error compiling Token Extract regexp: %s\n", errbuf); } } diff --git a/src/ivybind.h b/src/ivybind.h index 40f6932..7949a49 100644 --- a/src/ivybind.h +++ b/src/ivybind.h @@ -1,7 +1,7 @@ /* * Ivy, C interface * - * Copyright (C) 1997-2000 + * Copyright (C) 1997-2006 * Centre d'Études de la Navigation Aérienne * * Bind syntax for extracting message comtent @@ -18,12 +18,14 @@ typedef struct _binding *IvyBinding; +/* Mise en place des Filtrages */ void IvyBindingSetFilter( int argc, const char ** argv ); int IvyBindingFilter( const char *expression ); -IvyBinding IvyBindingCompile( const char *expression ); -void IvyBindingGetCompileError( int *erroffset, const char **errmessage ); +/* Creation, Compilation */ +IvyBinding IvyBindingCompile( const char *expression, int *erroffset, const char **errmessage ); void IvyBindingFree( IvyBinding bind ); +/* Execution , extraction */ int IvyBindingExec( IvyBinding bind, const char * message ); void IvyBindingMatch( IvyBinding bind, const char *message, int argnum, int *arglen, const char **arg ); diff --git a/src/ivychannel.h b/src/ivychannel.h index fa498b4..31a17aa 100644 --- a/src/ivychannel.h +++ b/src/ivychannel.h @@ -37,22 +37,19 @@ typedef void (*ChannelHandleDelete)( void *data ); typedef void (*ChannelHandleRead)( Channel channel, HANDLE fd, void *data); /* fonction appele par le bus pour initialisation */ -typedef void (*ChannelInit)(void); +extern void IvyChannelInit(void); /* fonction appele par le bus pour mise en place des callback sur le canal */ -typedef Channel (*ChannelSetUp)( +extern Channel IvyChannelAdd( HANDLE fd, void *data, ChannelHandleDelete handle_delete, ChannelHandleRead handle_read ); -/* fonction appele par le bus pour fermeture du canal */ -typedef void (*ChannelClose)( Channel channel ); +/* fonction appele par le bus pour suppression des callback sur le canal */ +extern void IvyChannelRemove( Channel channel ); -extern ChannelInit channel_init; -extern ChannelClose channel_close; -extern ChannelSetUp channel_setup; #ifdef __cplusplus } diff --git a/src/ivyloop.c b/src/ivyloop.c index cf121e3..cc79176 100644 --- a/src/ivyloop.c +++ b/src/ivyloop.c @@ -49,10 +49,6 @@ struct _channel { ChannelHandleRead handle_read; }; -ChannelInit channel_init = IvyChannelInit; -ChannelSetUp channel_setup = IvyChannelSetUp; -ChannelClose channel_close = IvyChannelClose; - static Channel channels_list = NULL; static int channel_initialized = 0; @@ -65,7 +61,7 @@ WSADATA WsaData; #endif void -IvyChannelClose (Channel channel) +IvyChannelRemove (Channel channel) { channel->tobedeleted = 1; } @@ -91,7 +87,7 @@ ChannelDefferedDelete () } } -Channel IvyChannelSetUp (HANDLE fd, void *data, +Channel IvyChannelAdd (HANDLE fd, void *data, ChannelHandleDelete handle_delete, ChannelHandleRead handle_read ) diff --git a/src/ivyloop.h b/src/ivyloop.h index 0696d40..df99e41 100644 --- a/src/ivyloop.h +++ b/src/ivyloop.h @@ -55,16 +55,6 @@ de la maniere suivante: extern void IvyMainLoop(void(*BeforeSelect)(void),void(*AfterSelect)(void) ); -extern void IvyChannelInit(void); -extern void IvyChannelClose( Channel channel ); -extern Channel IvyChannelSetUp( - HANDLE fd, - void *data, - ChannelHandleDelete handle_delete, - ChannelHandleRead handle_read); - - - #ifdef __cplusplus } #endif diff --git a/src/ivyprobe.c b/src/ivyprobe.c index 10d0667..58f55e3 100644 --- a/src/ivyprobe.c +++ b/src/ivyprobe.c @@ -34,6 +34,7 @@ #include #ifdef WIN32 #include +#include "getopt.h" #ifdef __MINGW32__ #include #include @@ -45,13 +46,6 @@ extern char *optarg; extern int optind; #endif -#ifdef USE_PCRE_REGEX -#define OVECSIZE 60 /* must be multiple of 3, for regexp return */ -#include -#else -#include -#endif - #endif #ifdef XTMAINLOOP @@ -68,6 +62,8 @@ extern int optind; #include "ivyloop.h" #endif #include "ivysocket.h" +#include "ivychannel.h" +#include "ivybind.h" /* to test regexp before passing to BinMsg */ #include "ivy.h" #include "timer.h" #ifdef XTMAINLOOP @@ -97,7 +93,7 @@ void Callback (IvyClientPtr app, void *user_data, int argc, char *argv[]) char * Chop(char *arg) { - int len; + size_t len; if (arg==NULL) return arg; len=strlen(arg)-1; if ((*(arg+len))=='\n') *(arg+len)=0; @@ -115,19 +111,9 @@ void HandleStdin (Channel channel, HANDLE fd, void *data) int err; line = fgets(buf, 4096, stdin); if (!line) { -#ifdef XTMAINLOOP - IvyXtChannelClose (channel); -#endif -#ifdef GLIBMAINLOOP - IvyGlibChannelClose(channel); -#endif -#ifdef GLUTMAINLOOP - IvyGlutChannelClose(channel); -#endif -#ifdef IVYMAINLOOP - IvyChannelClose (channel); + + IvyChannelRemove (channel); IvyStop(); -#endif return; } if (*line == '.') { @@ -156,26 +142,17 @@ void HandleStdin (Channel channel, HANDLE fd, void *data) } else if (strcmp(cmd, "bind") == 0) { arg = strtok (NULL, "'"); + Chop(arg); if (arg) { -#ifdef USE_PCRE_REGEX - pcre *regexp; + IvyBinding bind; const char *errbuf; int erroffset; - Chop(arg); - regexp = pcre_compile(arg, 0,&errbuf,&erroffset,NULL); - if (regexp==NULL) { - printf("Error compiling '%s', %s, not bound\n", arg, errbuf); -#else - regex_t reg; - int err; - Chop(arg); - if (err=regcomp(®,arg,REG_ICASE|REG_EXTENDED)!=0) { - char errbuf[4096]; - regerror (err, ®, errbuf, 4096); - printf("Error compiling '%s', %s, not bound\n", arg, errbuf); -#endif + bind = IvyBindingCompile(arg, & erroffset, & errbuf); + if (bind==NULL) { + printf("Error compiling '%s', %s, not bound\n", arg, errbuf); } else { - IvyBindMsg (Callback, NULL, Chop(arg)); + IvyBindingFree( bind ); + IvyBindMsg (Callback, NULL, arg); } } @@ -250,18 +227,10 @@ void ApplicationCallback (IvyClientPtr app, void *user_data, IvyApplicationEvent 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 */ if (app_count == wait_count) -#ifdef XTMAINLOOP - IvyXtChannelSetUp (0, NULL, NULL, HandleStdin); -#endif -#ifdef GLIBMAINLLOP - IvyGlibChannelSetUp( 0, NULL, NULL, HandleStdin); -#endif -#ifdef GLUTMAINLLOP - IvyGlutChannelSetUp( 0, NULL, NULL, HandleStdin); -#endif -#ifdef IVYMAINLOOP - IvyChannelSetUp (0, NULL, NULL, HandleStdin); + IvyChannelSetUp (0, NULL, NULL, HandleStdin); #endif break; @@ -277,7 +246,7 @@ void ApplicationCallback (IvyClientPtr app, void *user_data, IvyApplicationEvent } -#ifndef XTMAINLOOP +#ifdef IVYMAINLOOP void TimerCall(TimerId id, void *user_data, unsigned long delta) { printf("Timer callback: %d delta %lu ms\n", (int)user_data, delta); @@ -351,21 +320,10 @@ int main(int argc, char *argv[]) IvyBindMsg (Callback, NULL, argv[optind]); if (wait_count == 0) -#ifdef XTMAINLOOP - IvyXtChannelSetUp (0, NULL, NULL, HandleStdin); -#endif -#ifdef GLIBMAINLOOP - IvyGlibChannelSetUp (0, NULL, NULL, HandleStdin); -#endif -#ifdef GLUTMAINLOOP - IvyGlutChannelSetUp (0, NULL, NULL, HandleStdin); -#endif -#ifdef IVYMAINLOOP #ifndef WIN32 /* Stdin not compatible with select , select only accept socket */ IvyChannelSetUp (0, NULL, NULL, HandleStdin); #endif -#endif IvyStart (bus); diff --git a/src/ivysocket.c b/src/ivysocket.c index d38f66a..b31ab4a 100644 --- a/src/ivysocket.c +++ b/src/ivysocket.c @@ -84,13 +84,8 @@ WSADATA WsaData; void SocketInit() { - if (! channel_init ) - { - fprintf (stderr, "Channel management functions not set, exiting.\n"); - exit(-1); - } if ( getenv( "IVY_DEBUG_SEND" )) debug_send = 1; - (*channel_init)(); + IvyChannelInit(); } static void DeleteSocket(void *data) @@ -141,11 +136,11 @@ static void HandleSocket (Channel channel, HANDLE fd, void *data) &len); if (nb < 0) { perror(" Read Socket "); - (*channel_close) (client->channel ); + IvyChannelRemove (client->channel ); return; } if (nb == 0 ) { - (*channel_close) (client->channel ); + IvyChannelRemove (client->channel ); return; } client->ptr += nb; @@ -201,7 +196,7 @@ static void HandleServer(Channel channel, HANDLE fd, void *data) client->terminator = '\n'; client->from = remote2; client->fd = ns; - client->channel = (*channel_setup) (ns, client, DeleteSocket, HandleSocket ); + client->channel = IvyChannelAdd (ns, client, DeleteSocket, HandleSocket ); client->interpretation = server->interpretation; client->ptr = client->buffer; client->handle_delete = server->handle_delete; @@ -272,7 +267,7 @@ Server SocketServer(unsigned short port, IVY_LIST_ADD_START (servers_list, server ); server->fd = fd; - server->channel = (*channel_setup) (fd, server, DeleteServerSocket, HandleServer ); + server->channel = IvyChannelAdd (fd, server, DeleteServerSocket, HandleServer ); server->create = create; server->handle_delete = handle_delete; server->interpretation = interpretation; @@ -291,7 +286,7 @@ void SocketServerClose (Server server ) { if (!server) return; - (*channel_close) (server->channel ); + IvyChannelRemove (server->channel ); } char *SocketGetPeerHost (Client client ) @@ -334,7 +329,7 @@ void SocketGetRemoteHost (Client client, char **host, unsigned short *port ) void SocketClose (Client client ) { if (client) - (*channel_close) (client->channel ); + IvyChannelRemove (client->channel ); } int SocketSendRaw (Client client, char *buffer, int len ) @@ -474,7 +469,7 @@ Client SocketConnectAddr (struct in_addr * addr, unsigned short port, } client->terminator = '\n'; client->fd = handle; - client->channel = (*channel_setup) (handle, client, DeleteSocket, HandleSocket ); + client->channel = IvyChannelAdd (handle, client, DeleteSocket, HandleSocket ); client->interpretation = interpretation; client->ptr = client->buffer; client->data = data; @@ -599,7 +594,7 @@ Client SocketBroadcastCreate (unsigned short port, } client->terminator = '\n'; client->fd = handle; - client->channel = (*channel_setup) (handle, client, DeleteSocket, HandleSocket ); + client->channel = IvyChannelAdd (handle, client, DeleteSocket, HandleSocket ); client->interpretation = interpretation; client->ptr = client->buffer; client->data = data; diff --git a/src/libIvy.def b/src/libIvy.def index 18320c9..67a0756 100644 --- a/src/libIvy.def +++ b/src/libIvy.def @@ -3,7 +3,9 @@ LIBRARY Ivy EXPORTS IvyDefaultApplicationCallback -IvyClasses +IvyDefaultBindCallback + +IvySetFilter IvyInit IvyStart IvyStop @@ -27,5 +29,11 @@ IvySendDirectMsg IvyMainLoop IvyChannelInit -IvyChannelClose -IvyChannelSetUp +IvyChannelRemove +IvyChannelAdd + +IvyBindingCompile +IvyBindingFree + +IvyBindingExec +IvyBindingMatch -- cgit v1.1