diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/Makefile.win32 | 22 | ||||
-rwxr-xr-x | src/hash.c | 6 | ||||
-rw-r--r-- | src/ivy.c | 297 | ||||
-rw-r--r-- | src/ivy.h | 43 | ||||
-rwxr-xr-x | src/ivyargument.c | 125 | ||||
-rwxr-xr-x | src/ivyargument.h | 20 | ||||
-rw-r--r-- | src/ivybind.c | 124 | ||||
-rw-r--r-- | src/ivybind.h | 8 | ||||
-rw-r--r-- | src/ivychannel.h | 4 | ||||
-rw-r--r-- | src/ivyglibloop.c | 4 | ||||
-rwxr-xr-x | src/ivyglutloop.c | 4 | ||||
-rw-r--r-- | src/ivyloop.c | 6 | ||||
-rwxr-xr-x | src/ivyperf.c | 33 | ||||
-rw-r--r-- | src/ivyprobe.c | 23 | ||||
-rw-r--r-- | src/ivysocket.c | 79 | ||||
-rw-r--r-- | src/ivysocket.h | 10 | ||||
-rwxr-xr-x | src/ivytcl.c | 4 | ||||
-rw-r--r-- | src/ivyxtloop.c | 4 | ||||
-rw-r--r-- | src/libIvy.def | 22 | ||||
-rw-r--r-- | src/list.h | 24 |
20 files changed, 571 insertions, 291 deletions
diff --git a/src/Makefile.win32 b/src/Makefile.win32 index 7d91a8f..d3e30d0 100755 --- a/src/Makefile.win32 +++ b/src/Makefile.win32 @@ -46,18 +46,18 @@ REGEXP= -DUSE_PCRE_REGEX -DPCRE_OPT=$(PCRE_OPT) CHANNEL = -DTCL_CHANNEL_INTEGRATION -OBJ = hash.obj ivyloop.obj timer.obj ivysocket.obj ivy.obj ivybind.obj ivyargument.obj getopt.obj +OBJ = hash.obj ivyloop.obj timer.obj ivysocket.obj ivy.obj ivybind.obj ivyargument.obj # WINDOWS add ivyloop.obj if TCL_CHANNEL_INTEGRATION is not set TARGETS = ivyprobe.exe ivyperf.exe -TARGETLIBS=libivy.dll +TARGETLIBS=ivy.dll .c.obj: $(CC) $(CFLAGS) -c $*.c all: static-libs commands shared-libs -static-libs: libivy.lib +static-libs: ivy-static.lib shared-libs: $(TARGETLIBS) @@ -67,28 +67,28 @@ ivybind.obj: ivybind.c $(CC) -c $(CFLAGS) $(REGEXP) $(PCREINC) ivybind.c -ivyprobe.exe: ivyprobe.obj libivy.lib - $(CC) $(CFLAGS) -o $@ ivyprobe.obj libivy.lib wsock32.lib $(PCRELIB) +ivyprobe.exe: ivyprobe.obj getopt.obj ivy.dll + $(CC) $(CFLAGS) -o $@ ivyprobe.obj getopt.obj ivy.lib wsock32.lib $(PCRELIB) ivyprobe.obj : ivyprobe.c $(CC) -c $(CFLAGS) $(REGEXP) $(PCREINC) ivyprobe.c -ivyperf.exe: ivyperf.obj libivy.lib - $(CC) $(CFLAGS) -o $@ ivyperf.obj libivy.lib wsock32.lib $(PCRELIB) +ivyperf.exe: ivyperf.obj getopt.obj ivy.dll + $(CC) $(CFLAGS) -o $@ ivyperf.obj getopt.obj ivy.lib wsock32.lib $(PCRELIB) ivyperf.obj : ivyperf.c $(CC) -c $(CFLAGS) $(REGEXP) $(PCREINC) ivyperf.c -libivy.lib: $(OBJ) +ivy-static.lib: $(OBJ) del /f $@ $(LIBTOOL)$@ $(OBJ) -libivy.dll: $(OBJ) - $(CC) -nologo /LD -o $@ $(OBJ) wsock32.lib $(PCRELIB) +ivy.dll: $(OBJ) + $(CC) -nologo /LD -o $@ $(OBJ) wsock32.lib $(PCRELIB) /link /debug /def:libIvy.def /version:$(MAJOR).$(MINOR) clean: - -del /f $(TARGETS) $(TARGETLIBS) *.obj *.a *.dll *.pdb *~ + -del /f $(TARGETS) $(TARGETLIBS) *.obj *.a *.dll *.lib *.pdb *~ @@ -132,6 +132,7 @@ HASHTABLE hash_create(unsigned long InitialSize, BOOL KeyIsString) // Allocate space for the hash table. table = malloc(sizeof(*table)); + memset( table, 0, sizeof(*table) ); // Minimum size of hash table is 8. if (InitialSize < 8 ) @@ -147,6 +148,8 @@ HASHTABLE hash_create(unsigned long InitialSize, BOOL KeyIsString) table->Rows = malloc(InitialSize * sizeof(struct ROW)); table->KeyIsString = KeyIsString; + memset( table->Rows, 0, InitialSize * sizeof(struct ROW) ); + return table; @@ -465,6 +468,7 @@ extern void hash_usage(void) // Create some data to store p = malloc(sizeof(*p)); + memset ( p, 0 ,sizeof( *p)); p->ID = NumberKey; p->Age = 20; sprintf(p->Name, StringKey); @@ -608,6 +612,8 @@ extern BOOL hash_test(void) printf("HASH strings Tests for %d items\n", max); table = hash_create(max, TRUE); s = malloc(sizeof(*s) * max); + memset ( s, 0 ,sizeof( *s)*max); + for (i = 0; i < max; i++) { sprintf(temp, "Item %d", i); @@ -42,10 +42,6 @@ #define VERSION 4 -#define MAX_MSG_FIELDS 200 - -#define MESSAGE_SEPARATOR '\001' /* TODO remove use Bin args tree */ - #define DEFAULT_DOMAIN 127.255.255.255 /* stringification et concatenation du domaine et du port en 2 temps : @@ -82,6 +78,7 @@ typedef enum { typedef struct _msg_snd *MsgSndPtr; struct _msg_rcv { /* requete d'emission d'un client */ + IvyBindingType type; int id; const char *regexp; /* regexp du message a recevoir */ MsgCallback callback; /* callback a declanche a la reception */ @@ -119,10 +116,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; - /* callback appele sur reception d'un message direct */ static MsgDirectCallback direct_callback = 0; static void *direct_user_data = 0; @@ -165,6 +158,42 @@ static long currentTime() #endif return current; } + + +// fonction de formtage a la printf d'un buffer avec reallocation dynamique +#define MESSAGE_SIZE 4096 /* taille buffer initiale on multiple pas deux a chaque realloc */ + +static int make_message(char ** buffer, int *size, int offset, const char *fmt, va_list ap) +{ + /* Guess we need no more than BUFFER_INIT_SIZE bytes. */ + long n; + if ( *size == 0 || *buffer == NULL ) + { + *size = MESSAGE_SIZE; + *buffer = malloc (MESSAGE_SIZE); + if ( *buffer == NULL ) + return -1; + } + while (1) { + /* Try to print in the allocated space. */ +#ifdef WIN32 + n = _vsnprintf (*buffer + offset, *size - offset, fmt, ap); +#else + n = vsnprintf (*buffer + offset, *size - offset, fmt, ap); +#endif + /* If that worked, return the string size. */ + if (n > -1 && n < *size) + return n; + /* Else try again with more space. */ + if (n > -1) /* glibc 2.1 */ + *size = n+1; /* precisely what is needed */ + else /* glibc 2.0 */ + *size *= 2; /* twice the old size */ + if ((*buffer = realloc (*buffer, *size)) == NULL) + return -1; + } +} + static char *DupArg( int len, void *s) { char *ptr; @@ -178,28 +207,6 @@ static char *DupArg( int len, void *s) ptr[len] = '\0'; return ptr; } -/* - * function split string in multiple string using separator - * empty args when consecutives separators - * the input string is modified separator are replaced with \0 - * */ -static int SplitArg( int len, char *s, const char separator, char **argv ) -{ - char *ptr = s; - char *ptr_end = s + len; - int argc = 0; - while ( ptr < ptr_end ) - { - argv[argc++] = ptr; - while( (ptr < ptr_end) && *ptr != separator ) - ptr++; - if ( *ptr == separator ) - { - *ptr++ = '\0'; - } - } - return argc; -} /* returns < 0 if *p sorts lower than *q */ static int keycmp (IvyClientPtr p, IvyClientPtr q) { @@ -250,7 +257,7 @@ static IvyClientPtr lsort (IvyClientPtr p) static void SortClients() { - //TODO sort client list again priority! + // sort client list again priority! lsort( clients ); } static void MsgSendTo( Client client, MsgType msgtype, int id, int len_arg, const void *arg ) @@ -263,42 +270,21 @@ static void MsgSendTo( Client client, MsgType msgtype, int id, int len_arg, cons header[0] = htons( (unsigned short)msgtype ); header[1] = htons( (unsigned short)id ); header[2] = htons( (unsigned short)len_arg ); - SocketSendBuf( client, (char *)header, sizeof(header) ); + SocketSend( client, (char *)header, sizeof(header) ); if ( len_arg ) { - SocketSendBuf( client, arg, len_arg ); + SocketSend( client, arg, len_arg ); } SocketFlush( client ); } -static void IvyCleanup() -{ - IvyClientPtr clnt,next; - - /* destruction des connexions clients */ - IVY_LIST_EACH_SAFE( clients, clnt, next ) - { - /* on dit au revoir */ - MsgSendTo( clnt->client, Bye, 0, 0, "" ); - SocketClose( clnt->client ); - IVY_LIST_EMPTY( clnt->msg_send ); - } - IVY_LIST_EMPTY( clients ); - - /* destruction des sockets serveur et supervision */ - SocketServerClose( server ); - SocketClose( broadcast ); -} - static int MsgSendCallTo (Client client, const char *message, MsgSndPtr msg ) -{ - //TODO remove this buffer - 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 arglen; - const char *arg; - int index; +{ + static void * buffer = NULL; + static int buf_len = 0; + int len; + IvyArgument args; + int rc = IvyBindingExec( msg->bind, message ); @@ -313,23 +299,31 @@ static int MsgSendCallTo (Client client, const char *message, MsgSndPtr msg ) #ifdef DEBUG printf( "Send matching args count %d\n",rc); #endif - index=0; - while ( index<rc ) { + args = IvyBindingMatch( msg->bind, message ); + /* serialize into buffer */ + len = IvyArgumentSerialize(args, &buf_len, &buffer, 0); - IvyBindingGetMatch( msg->bind, message, index, &arg, &arglen ); -#ifdef DEBUG - printf ("Send matching arg%d '%.*s'\n",index,arglen, arg); -#endif - offset += make_message_var( &buffer, &size, offset, "%.*s%c", - arglen, arg, - MESSAGE_SEPARATOR - ); - ++index; - } - MsgSendTo( client, Msg, msg->id, offset, buffer ); + MsgSendTo( client, Msg, msg->id, len, buffer ); return 1; } +static void IvyCleanup() +{ + IvyClientPtr clnt,next; + /* destruction des connexions clients */ + IVY_LIST_EACH_SAFE( clients, clnt, next ) + { + /* on dit au revoir */ + MsgSendTo( clnt->client, Bye, 0, 0, "" ); + SocketClose( clnt->client ); + IVY_LIST_EMPTY( clnt->msg_send ); + } + IVY_LIST_EMPTY( clients ); + + /* destruction des sockets serveur et supervision */ + SocketServerClose( server ); + SocketClose( broadcast ); +} static int ClientCall (IvyClientPtr clnt, const char *message) { @@ -342,22 +336,6 @@ static int ClientCall (IvyClientPtr clnt, const char *message) return match_count; } -static int CheckRegexp(char *exp) -{ - /* accepte tout par default */ - int i; - int regexp_ok = 1; - if ( *exp =='^' && messages_classes_count !=0 ) - { - regexp_ok = 0; - for ( i = 0 ; i < messages_classes_count; i++ ) - { - if (strncmp( messages_classes[i], exp+1, strlen( messages_classes[i] )) == 0) - return 1; - } - } - return regexp_ok; -} static int CheckConnected( IvyClientPtr clnt ) { @@ -391,13 +369,13 @@ static char* Receive( Client client, void *data, char *message, unsigned int len unsigned short len_args; MsgSndPtr snd; MsgRcvPtr rcv; - int argc = 0; - char *argv[MAX_MSG_FIELDS]; + IvyArgument arguments; int kind_of_msg = Bye; IvyBinding bind; char *ptr_end; void *args =NULL; char *str_regexp; + int adv_buffer; ptr_end = message; @@ -434,9 +412,9 @@ static char* Receive( Client client, void *data, char *message, unsigned int len case AddRegexp: #ifdef DEBUG - printf("Regexp id=%d exp='%.*s'\n", id, len_args, (char*)args); + printf("AddRegexp id=%d exp='%.*s'\n", id, len_args, (char*)args); #endif //DEBUG - if ( !CheckRegexp( args ) ) /* TODO check args limits !!!*/ + if ( !IvyBindingFilter( IvyBindRegexp, len_args, args ) ) { #ifdef DEBUG printf("Warning: regexp '%.*s' illegal, removing from %s\n",len_args,(char*)args,ApplicationName); @@ -445,7 +423,64 @@ static char* Receive( Client client, void *data, char *message, unsigned int len } str_regexp = DupArg( len_args, args ); - bind = IvyBindingCompile( str_regexp ); + bind = IvyBindingCompile( IvyBindRegexp, str_regexp ); + if ( bind != NULL ) + { + IVY_LIST_ADD( clnt->msg_send, snd ) + if ( snd ) + { + snd->id = id; + snd->str_regexp = str_regexp; /* should be Freeed on remove */ + snd->bind = bind; + if ( application_bind_callback ) + { + (*application_bind_callback)( clnt, application_bind_data, IvyAddBind, snd->str_regexp ); + } + } + } + else + { + int offset; + const char *errbuf; + IvyBindingGetCompileError( &offset, &errbuf ); + MsgSendTo( client, Error, offset, strlen(errbuf), errbuf ); + free( str_regexp ); /* not used so Free it */ + } + + break; + case DelRegexp: +#ifdef DEBUG + printf("DelRegexp id=%d\n", id); +#endif //DEBUG + + IVY_LIST_ITER( clnt->msg_send, snd, ( id != snd->id )); + if ( snd ) + { + if ( application_bind_callback ) + { + (*application_bind_callback)( clnt, application_bind_data, IvyRemoveBind, snd->str_regexp ); + } + free( snd->str_regexp ); + IvyBindingFree( snd->bind ); + + IVY_LIST_REMOVE( clnt->msg_send, snd ); + } + break; + case AddBinding: + +#ifdef DEBUG + printf("AddBinding id=%d exp='%.*s'\n", id, len_args, (char*)args); +#endif //DEBUG + if ( !IvyBindingFilter( IvyBindSimple, len_args, args ) ) + { +#ifdef DEBUG + printf("Warning: regexp '%.*s' illegal, removing from %s\n",len_args,(char*)args,ApplicationName); +#endif //DEBUG + return ptr_end; + } + str_regexp = DupArg( len_args, args ); + + bind = IvyBindingCompile( IvyBindSimple, str_regexp ); if ( bind != NULL ) { IVY_LIST_ADD( clnt->msg_send, snd ) @@ -461,17 +496,18 @@ static char* Receive( Client client, void *data, char *message, unsigned int len } } else - { - int offset; - const char *errbuf; - IvyBindingGetCompileError( &offset, &errbuf ); - MsgSendTo( client, Error, offset, strlen(errbuf), errbuf ); + { + int offset; + const char *errbuf; + IvyBindingGetCompileError( &offset, &errbuf ); + MsgSendTo( client, Error, offset, strlen(errbuf), errbuf ); + } free( str_regexp ); - } + break; - case DelRegexp: + case DelBinding: #ifdef DEBUG - printf("Regexp Delete id=%d\n", id); + printf("DelBinding id=%d\n", id); #endif //DEBUG IVY_LIST_ITER( clnt->msg_send, snd, ( id != snd->id )); @@ -528,14 +564,14 @@ static char* Receive( Client client, void *data, char *message, unsigned int len printf("Message id=%d msg='%.*s'\n", id, len_args, (char*)args); #endif //DEBUG rcv = hash_lookup( msg_recv, id ); - if ( rcv ) + if ( rcv && rcv->callback ) { - argc = SplitArg( len_args, args, MESSAGE_SEPARATOR, argv); + arguments = IvyArgumentDeserialize( len_args, args, &adv_buffer ); #ifdef DEBUG - printf("Calling id=%d argc=%d for %s\n", id, argc,rcv->regexp); + printf("Calling id=%d for %s\n", id, rcv->regexp); #endif - if ( rcv->callback ) (*rcv->callback)( clnt, rcv->user_data, argc, argv ); + (*rcv->callback)( clnt, rcv->user_data, arguments ); return ptr_end; } else @@ -668,7 +704,7 @@ static void IvySendHello(unsigned long mask) *((unsigned short *) ptr)++ = htons( lenAppName ); strncpy( ptr, ApplicationName , lenAppName); - SocketSendBroadcastRaw (broadcast, mask, SupervisionPort, packet,len ); + SocketSendBroadcast(broadcast, mask, SupervisionPort, packet,len ); free( packet ); } /* Hello packet Receive */ @@ -811,10 +847,9 @@ void IvySetBindCallback(IvyBindCallback bind_callback, void *bind_data) application_bind_data=bind_data; } -void IvyClasses( int argc, const char **argv) +void IvySetMyMessagesStart( int argc, const char **argv) { - messages_classes_count = argc; - messages_classes = argv; + IvyBindingSetFilter( argc, argv ); } void IvyStart (const char* bus) @@ -938,29 +973,31 @@ void IvyUnbindMsg (MsgRcvPtr msg) } /* demande de reception d'un message */ - -MsgRcvPtr IvyBindMsg (MsgCallback callback, void *user_data, const char *fmt_regex, ... ) +static MsgRcvPtr IvyBind ( IvyBindingType typ, MsgCallback callback, void *user_data, const char *fmt_regex, va_list ap ) { static char *buffer = NULL; static int size = 0; - va_list ap; static int recv_id = 0; IvyClientPtr clnt; MsgRcvPtr msg; int len; + int MsgType = typ == IvyBindRegexp ? AddRegexp : AddBinding; - va_start (ap, fmt_regex ); make_message( &buffer, &size, 0, fmt_regex, ap ); - va_end (ap ); - + /* add Msg to the query list */ msg = malloc(sizeof(struct _msg_rcv)); if (msg) { + msg->type = typ; msg->id = recv_id++; msg->regexp = strdup(buffer); msg->callback = callback; msg->user_data = user_data; - hash_add(msg_recv, msg->id, msg); + if ( !hash_add(msg_recv, msg->id, msg) ) + { + perror("IvyBindMsg can't hash_add Entry already exists!"); + exit(-1); + } } else { @@ -971,11 +1008,35 @@ MsgRcvPtr IvyBindMsg (MsgCallback callback, void *user_data, const char *fmt_reg /* 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, len, msg->regexp); + MsgSendTo( clnt->client, MsgType,msg->id, len, msg->regexp); } return msg; } + +MsgRcvPtr IvyBindMsg (MsgCallback callback, void *user_data, const char *fmt_regex, ... ) +{ + va_list ap; + MsgRcvPtr msg; + + va_start (ap, fmt_regex ); + msg = IvyBind ( IvyBindRegexp, callback, user_data, fmt_regex, ap ); + va_end (ap ); + return msg; + +} + +MsgRcvPtr IvyBindSimpleMsg( MsgCallback callback, void *user_data, const char *fmt_regex, ... ) +{ + va_list ap; + MsgRcvPtr msg; + + va_start (ap, fmt_regex ); + msg = IvyBind ( IvyBindSimple, callback, user_data, fmt_regex, ap ); + va_end (ap ); + return msg; + +} int IvySendMsg(const char *fmt, ...) { IvyClientPtr clnt; @@ -1,4 +1,6 @@ + /* + * \ingroup Ivy * Ivy, C interface * * Copyright (C) 1997-2000 @@ -6,13 +8,17 @@ * * Main functions * - * Authors: François-Régis Colin <fcolin@cena.fr> + * \author Authors: François-Régis Colin <fcolin@cena.fr> * Stéphane Chatty <chatty@cena.fr> * * $Id$ * * Please refer to file version.h for the * copyright notice regarding this software + * \todo + * many things TODO + * \bug + * many introduced */ #ifndef IVY_H @@ -22,6 +28,8 @@ extern "C" { #endif +#include "IvyArgument.h" + /* numero par default du bus */ #define DEFAULT_BUS 2010 @@ -46,7 +54,7 @@ typedef void (*IvyBindCallback)( IvyClientPtr app, void *user_data, IvyBindEvent typedef void (*IvyDieCallback)( IvyClientPtr app, void *user_data, int id ) ; /* callback appele sur reception de messages normaux */ -typedef void (*MsgCallback)( IvyClientPtr app, void *user_data, int argc, char **argv ) ; +typedef void (*MsgCallback)( IvyClientPtr app, void *user_data, IvyArgument args ) ; /* callback appele sur reception de messages directs */ typedef void (*MsgDirectCallback)( IvyClientPtr app, void *user_data, int id, int len, void *msg ) ; @@ -55,20 +63,37 @@ typedef void (*MsgDirectCallback)( IvyClientPtr app, void *user_data, int id, in typedef struct _msg_rcv *MsgRcvPtr; /* filtrage des regexps */ -void IvyClasses( int argc, const char **argv); +void IvySetMyMessagesStart( int argc, const char **argv); +/** + * + * \param AppName + * \param ready + * \param callback + * \param data + * \param die_callback + * \param die_data + */ void IvyInit( - const char *AppName, /* nom de l'application */ - const char *ready, /* ready Message peut etre NULL */ + const char * AppName, /* nom de l'application */ + const char * ready, /* ready Message peut etre NULL */ IvyApplicationCallback callback, /* callback appele sur connection deconnection d'une appli */ - void *data, /* user data passe au callback */ + void * data, /* user data passe au callback */ IvyDieCallback die_callback, /* last change callback before die */ - void *die_data /* user data */ + void * die_data /* user data */ ); +/** + * + * \param priority prioritie de traitement des clients + */ void IvySetApplicationPriority( int priority ); void IvySetBindCallback( IvyBindCallback bind_callback, void *bind_data ); -void IvyStart (const char*); +/** + * + * \param bus + */ +void IvyStart (const char* bus); void IvyStop (); /* query sur les applications connectees */ @@ -82,6 +107,8 @@ char **IvyGetApplicationMessages( IvyClientPtr app); /* demande de reception d'u MsgRcvPtr IvyBindMsg( MsgCallback callback, void *user_data, const char *fmt_regexp, ... ); /* avec sprintf prealable */ void IvyUnbindMsg( MsgRcvPtr id ); +MsgRcvPtr IvyBindSimpleMsg( MsgCallback callback, void *user_data, const char *fmt_regexp, ... ); /* avec sprintf prealable */ + /* emission d'un message d'erreur */ void IvySendError( IvyClientPtr app, int id, const char *fmt, ... ); diff --git a/src/ivyargument.c b/src/ivyargument.c index ac880cf..5333b99 100755 --- a/src/ivyargument.c +++ b/src/ivyargument.c @@ -21,7 +21,14 @@ #include <stdlib.h> #include <memory.h> #include <string.h> - +#ifdef WIN32 +#include <windows.h> +#else +#include <arpa/inet.h> +#include <sys/time.h> +#include <unistd.h> +#include <netdb.h> +#endif #include "list.h" #include "ivyargument.h" @@ -30,48 +37,134 @@ struct _argument { /* childrens */ struct _argument *next; + struct _argument *childrens; /* arg value */ - char *value; + int value_len; + const void *value; }; -IvyArgument IvyArgumentNew( const char * value ) +IvyArgument IvyArgumentNew( int len, const void * value ) { - IvyArgument arg = malloc( sizeof( struct _argument ) ); - arg->value = strdup( value ); + IvyArgument arg = malloc( sizeof( *arg ) ); + arg->value_len = len; + arg->value = value; arg->next = 0; + arg->childrens = 0; return arg; } void IvyArgumentFree( IvyArgument arg ) { - free( arg->value ); free( arg ); } -const char * IvyArgumentGetValue( IvyArgument arg ) +void IvyArgumentGetValue( IvyArgument arg, int * len, const void **val ) { - return arg->value; + *len = arg->value_len; + *val = arg->value; +} +IvyArgument IvyArgumentGetChildrens( IvyArgument arg ) +{ + return arg->childrens; } - IvyArgument IvyArgumentGetNextChild( IvyArgument arg ) { return arg->next; } -IvyArgument IvyAddChild( IvyArgument arg, const char* childvalue ) +IvyArgument IvyAddChildValue( IvyArgument arg, int childvaluelen, const void* childvalue ) { + /* ADD Child to the beginning of the list */ IvyArgument child; - IVY_LIST_ADD( arg->next, child ) + IVY_LIST_ADD( arg->childrens, child ) if ( child ) { - child->value = strdup( childvalue ); - child->next = 0; + child->value_len = childvaluelen; + child->value = childvalue; } return child; } -IvyArgument IvyArgumentDeserialize( int fd ) +void IvyAddChild( IvyArgument arg, IvyArgument child ) +{ + /* ADD Child to the beginning of the list */ + child->next = arg->childrens; + arg->childrens = child; +} +int IvyArgumentGetChildCount( IvyArgument arg ) { - return 0; + IvyArgument p; + int count = 0; + IVY_LIST_EACH( arg->childrens, p ) + { + count++; + } + return count; } -void IvyArgumentSerialize(IvyArgument arg, int fd ) +IvyArgument IvyArgumentDeserialize( int buf_len, void* buffer, int * buf_adv ) { + int i; + void *ptr_end = buffer; + int adv; + unsigned short value_len; + unsigned short nbchild; + IvyArgument arg; + IvyArgument child; + + adv = 0; + arg = IvyArgumentNew( 0, 0); + /* reading value */ + value_len = ntohs( *((unsigned short *) ptr_end)++ ); + if ( value_len ) + { + arg->value_len = value_len; + arg->value = ptr_end; + ((unsigned char *)ptr_end) += value_len; + } + /* reading child */ + nbchild = ntohs( *((unsigned short *) ptr_end)++ ); + if ( nbchild ) + { + for ( i= 0; i < nbchild; i++ ) + { + child = IvyArgumentDeserialize( buf_len - ((unsigned char *)ptr_end - (unsigned char *)buffer) , ptr_end, &adv ); + IvyAddChild( arg, child ); + ((unsigned char *)ptr_end) += adv; + } + } + *buf_adv += (unsigned char *)ptr_end - (unsigned char *)buffer; +#ifdef DEBUG + printf( "IvyArgumentDeserialize value='%.*s' nbchild=%d size=%d\n",arg->value_len, (char*)arg->value, nbchild, *buf_adv); +#endif + return arg; +} +int IvyArgumentSerialize(IvyArgument arg, int *buf_len, void **buffer, int offset) +{ + int nb_child; + IvyArgument child; + void *ptr; + + /* check buffer space */ + if ( (*buf_len - offset) < (2 * sizeof( unsigned short ) + arg->value_len) ) + { + *buf_len += 4096; + *buffer = realloc( *buffer, *buf_len ); + } + ptr = (unsigned char*)(*buffer) + offset; + /* writing value */ + *((unsigned short*)ptr)++ = htons( (unsigned short)arg->value_len ); + if ( arg->value_len ) + { + memcpy( ptr, arg->value, arg->value_len ); + (unsigned char*)ptr += arg->value_len; + } + /* writing child */ + nb_child = IvyArgumentGetChildCount( arg ); + *((unsigned short*)ptr)++ = htons( (unsigned short)nb_child ); + IVY_LIST_EACH ( arg->childrens, child ) + { + (unsigned char*)ptr += IvyArgumentSerialize( child, buf_len, buffer, (unsigned char*)ptr - (unsigned char*)*buffer ); + } +#ifdef DEBUG + printf( "IvyArgumentSerialize value='%.*s' nbchild=%d buff size=%d\n",arg->value_len, (char*)arg->value, nb_child, (unsigned char*)ptr - (unsigned char*)*buffer - offset); +#endif + return (unsigned char*)ptr - (unsigned char*)*buffer - offset; } diff --git a/src/ivyargument.h b/src/ivyargument.h index e54a444..693d34b 100755 --- a/src/ivyargument.h +++ b/src/ivyargument.h @@ -1,7 +1,7 @@ /* * Ivy, C interface * - * Copyright (C) 1997-2000 + * Copyright (C) 1997-2005 * Centre d'Études de la Navigation Aérienne * * Argument message comtent @@ -13,16 +13,22 @@ * Please refer to file version.h for the * copyright notice regarding this software */ - +#ifndef IVY_ARGUMENT_H +#define IVY_ARGUMENT_H /* Module de gestion de la syntaxe des messages Ivy */ typedef struct _argument *IvyArgument; -IvyArgument IvyArgumentNew( const char * expression ); +IvyArgument IvyArgumentNew( int len, const void * value ); void IvyArgumentFree( IvyArgument arg ); -const char * IvyArgumentGetValue( IvyArgument arg ); +int IvyArgumentGetChildCount( IvyArgument arg ); +void IvyArgumentGetValue( IvyArgument arg, int * len, const void **val ); +IvyArgument IvyArgumentGetChildrens( IvyArgument arg ); IvyArgument IvyArgumentGetNextChild( IvyArgument arg ); -IvyArgument IvyAddChild( IvyArgument arg, const char* childvalue ); -IvyArgument IvyArgumentDeserialize( int fd ); -void IvyArgumentSerialize(IvyArgument arg, int fd ); +void IvyAddChild( IvyArgument arg, IvyArgument child ); +IvyArgument IvyAddChildValue( IvyArgument arg, int childvaluelen, const void* childvalue ); + +IvyArgument IvyArgumentDeserialize( int buf_len, void* buffer, int * buf_adv); +int IvyArgumentSerialize(IvyArgument arg, int *buf_len, void **buffer, int offset); +#endif
\ No newline at end of file diff --git a/src/ivybind.c b/src/ivybind.c index 9cd1f58..a9709d1 100644 --- a/src/ivybind.c +++ b/src/ivybind.c @@ -26,6 +26,7 @@ #define OVECSIZE 60 /* must be multiple of 3, for regexp return */ #include <pcre.h> #else +#define MAX_MSG_FIELDS 200 #include <regex.h> #endif @@ -42,9 +43,11 @@ struct _binding { struct _binding *next; + IvyBindingType type; #ifdef USE_PCRE_REGEX pcre *regexp; pcre_extra *inspect; + int nb_match; int ovector[OVECSIZE]; #else regex_t regexp; /* la regexp sous forme machine */ @@ -52,7 +55,17 @@ struct _binding { #endif }; -IvyBinding IvyBindingCompile( const char * expression ) + +/* classes de messages emis par l'application utilise pour le filtrage */ +static int messages_classes_count = 0; +static const char **messages_classes = 0; + +static IvyBinding IvyBindingCompileSimple( IvyBindingType typ, const char * expression ) +{ + //TODO return NULL + return NULL; +} +static IvyBinding IvyBindingCompileRegexp( IvyBindingType typ, const char * expression ) { IvyBinding bind=0; #ifdef USE_PCRE_REGEX @@ -62,6 +75,8 @@ IvyBinding IvyBindingCompile( const char * expression ) { bind = (IvyBinding)malloc( sizeof( struct _binding )); bind->regexp = regexp; + bind->next = NULL; + bind->type = IvyBindRegexp; bind->inspect = pcre_study(regexp,0,&errbuf); if (errbuf!=NULL) { @@ -80,6 +95,7 @@ IvyBinding IvyBindingCompile( const char * expression ) { bind = (IvyBinding)malloc( sizeof( struct _binding )); bind->regexp = regexp; + bind->next = NULL; } else { @@ -90,6 +106,13 @@ IvyBinding IvyBindingCompile( const char * expression ) #endif return bind; } +IvyBinding IvyBindingCompile( IvyBindingType typ, const char * expression ) +{ + if ( typ == IvyBindRegexp ) + return IvyBindingCompileRegexp( typ, expression); + else + return IvyBindingCompileSimple( typ, expression); +} void IvyBindingGetCompileError( int *offset, const char **errmessage ) { #ifdef USE_PCRE_REGEX @@ -109,7 +132,7 @@ void IvyBindingFree( IvyBinding bind ) #endif free ( bind ); } -int IvyBindingExec( IvyBinding bind, const char * message ) +int IvyBindingExecRegexp( IvyBinding bind, const char * message ) { int nb_match = 0; #ifdef USE_PCRE_REGEX @@ -124,6 +147,7 @@ int IvyBindingExec( IvyBinding bind, const char * message ) bind->ovector, OVECSIZE); if (nb_match<1) return 0; /* no match */ + bind->nb_match = nb_match; nb_match--; // firts arg wall string ??? #else @@ -131,8 +155,7 @@ int IvyBindingExec( IvyBinding bind, const char * message ) nb_match = regexec (&bind->regexp, message, MAX_MSG_FIELDS, bind->match, 0) if (nb_match == REG_NOMATCH) return 0; - /* TODO Possible BUG if empty match in middle of regexp */ - for ( index = 0; index < MAX_MSG_FIELDS; index++ ) + for ( index = 1; index < MAX_MSG_FIELDS; index++ ) { if ( bind->match[i].rm_so != -1 ) nb_match++; @@ -140,24 +163,97 @@ int IvyBindingExec( IvyBinding bind, const char * message ) #endif return nb_match; } -void IvyBindingGetMatch( IvyBinding bind, const char *message, int index, const char **arg, int *arglen ) +int IvyBindingExecSimple( IvyBinding bind, const char * message ) +{ + return 0; +} +int IvyBindingExec( IvyBinding bind, const char * message ) +{ + if ( bind->type == IvyBindRegexp ) + return IvyBindingExecRegexp( bind, message); + else + return IvyBindingExecSimple( bind, message); +} +static IvyArgument IvyBindingMatchSimple( IvyBinding bind, const char *message) +{ + //TODO + return NULL; +} +static IvyArgument IvyBindingMatchRegexp( IvyBinding bind, const char *message) { - index++; // firts arg wall string ??? + int index=1;// firts arg wall string ??? + int arglen; + const void* arg; + IvyArgument args; + args = IvyArgumentNew( 0,NULL ); + #ifdef USE_PCRE_REGEX - *arglen = bind->ovector[2*index+1]- bind->ovector[2*index]; - *arg = message + bind->ovector[2*index]; + while ( index<bind->nb_match ) { + arglen = bind->ovector[2*index+1]- bind->ovector[2*index]; + arg = message + bind->ovector[2*index]; + index++; #else /* we don't USE_PCRE_REGEX */ - + for ( index = 1; index < MAX_MSG_FIELDS; index++ ) + { regmatch_t* p; p = &bind->match[index]; if ( p->rm_so != -1 ) { - *arglen = p->rm_eo - p->rm_so; - *arg = message + p->rm_so; + arglen = p->rm_eo - p->rm_so; + arg = message + p->rm_so; } else { // ARG VIDE - *arglen = 0; - *arg = message; + arglen = 0; + arg = NULL; + } +#endif // USE_PCRE_REGEX + IvyAddChildValue( args, arglen, arg ); } + return args; +} +IvyArgument IvyBindingMatch( IvyBinding bind, const char *message) +{ + if ( bind->type == IvyBindRegexp ) + return IvyBindingMatchRegexp( bind, message); + else + return IvyBindingMatchSimple( bind, message); +} -#endif +//filter Expression Bind +void IvyBindingSetFilter( int argc, const char **argv) +{ + messages_classes_count = argc; + messages_classes = argv; +} +int IvyBindingFilter(IvyBindingType typ, int len, const char *exp) +{ + /* TODO check args limits !!!*/ + int i; + /* accepte tout par default */ + int regexp_ok = 1; + // TODO simplify test 3 conditions + if ( typ == IvyBindRegexp ) + { + if ( *exp =='^' && messages_classes_count !=0 ) + { + regexp_ok = 0; + for ( i = 0 ; i < messages_classes_count; i++ ) + { + if (strncmp( messages_classes[i], exp+1, strlen( messages_classes[i] )) == 0) + return 1; + } + } + } + else + { + if ( messages_classes_count !=0 ) + { + regexp_ok = 0; + for ( i = 0 ; i < messages_classes_count; i++ ) + { + if (strncmp( messages_classes[i], exp, strlen( messages_classes[i] )) == 0) + return 1; + } + } + } + return regexp_ok; }
\ No newline at end of file diff --git a/src/ivybind.h b/src/ivybind.h index e5ed821..830079b 100644 --- a/src/ivybind.h +++ b/src/ivybind.h @@ -14,13 +14,17 @@ * Please refer to file version.h for the * copyright notice regarding this software */ +#include "IvyArgument.h" /* Module de gestion de la syntaxe des messages Ivy */ typedef struct _binding *IvyBinding; -IvyBinding IvyBindingCompile( const char * expression ); +typedef enum { IvyBindRegexp, IvyBindSimple } IvyBindingType; +void IvyBindingSetFilter( int argc, const char ** argv ); +int IvyBindingFilter( IvyBindingType typ, int len, const char *exp ); +IvyBinding IvyBindingCompile( IvyBindingType typ, const char * expression ); void IvyBindingGetCompileError( int *erroffset, const char **errmessage ); void IvyBindingFree( IvyBinding bind ); int IvyBindingExec( IvyBinding bind, const char * message ); -void IvyBindingGetMatch( IvyBinding bind, const char *message, int index, const char **arg, int *arglen );
\ No newline at end of file +IvyArgument IvyBindingMatch( IvyBinding bind, const char *message );
\ No newline at end of file diff --git a/src/ivychannel.h b/src/ivychannel.h index fe1d2c7..ff9974d 100644 --- a/src/ivychannel.h +++ b/src/ivychannel.h @@ -42,7 +42,7 @@ extern void IvyChannelInit(void); extern void IvyChannelStop(void); /* fonction appele par le bus pour mise en place des callback sur le canal */ -extern Channel IvyChannelOpen( +extern Channel IvyChannelAdd( IVY_HANDLE fd, void *data, ChannelHandleDelete handle_delete, @@ -50,7 +50,7 @@ extern Channel IvyChannelOpen( ); /* fonction appele par le bus pour fermeture du canal */ -extern void IvyChannelClose( Channel channel ); +extern void IvyChannelRemove( Channel channel ); #ifdef __cplusplus } diff --git a/src/ivyglibloop.c b/src/ivyglibloop.c index 54608df..e1944dd 100644 --- a/src/ivyglibloop.c +++ b/src/ivyglibloop.c @@ -64,7 +64,7 @@ void IvyChannelStop( ) } -Channel IvyChannelOpen(IVY_HANDLE fd, void *data, +Channel IvyChannelAdd(IVY_HANDLE fd, void *data, ChannelHandleDelete handle_delete, ChannelHandleRead handle_read ) { @@ -89,7 +89,7 @@ Channel IvyChannelOpen(IVY_HANDLE fd, void *data, -void IvyChannelClose( Channel channel ) { +void IvyChannelRemove( Channel channel ) { if ( channel->handle_delete ) (*channel->handle_delete)( channel->data ); g_source_remove( channel->id_read ); diff --git a/src/ivyglutloop.c b/src/ivyglutloop.c index 4c02762..3dea326 100755 --- a/src/ivyglutloop.c +++ b/src/ivyglutloop.c @@ -70,7 +70,7 @@ void IvyChannelStop(void) { channel_initialized = 0; } -void IvyChannelClose( Channel channel ) +void IvyChannelRemove( Channel channel ) { if ( channel->handle_delete ) @@ -98,7 +98,7 @@ static void IvyGlutHandleChannelDelete( int source, GLUTInputId id, void *data ) (*channel->handle_delete)(channel->data); } -Channel IvyChannelOpen(IVY_HANDLE fd, void *data, +Channel IvyChannelAdd(IVY_HANDLE fd, void *data, ChannelHandleDelete handle_delete, ChannelHandleRead handle_read ) diff --git a/src/ivyloop.c b/src/ivyloop.c index d90fa6c..278e098 100644 --- a/src/ivyloop.c +++ b/src/ivyloop.c @@ -62,7 +62,7 @@ WSADATA WsaData; #endif void -IvyChannelClose (Channel channel) +IvyChannelRemove (Channel channel) { channel->tobedeleted = 1; } @@ -88,7 +88,7 @@ ChannelDefferedDelete () } } -Channel IvyChannelOpen (IVY_HANDLE fd, void *data, +Channel IvyChannelAdd (IVY_HANDLE fd, void *data, ChannelHandleDelete handle_delete, ChannelHandleRead handle_read ) @@ -131,7 +131,7 @@ IvyChannelHandleExcpt (fd_set *current) if (FD_ISSET (channel->fd, current)) { if (channel->handle_delete) (*channel->handle_delete)(channel->data); -/* IvyChannelClose (channel); */ +/* IvyChannelRemove (channel); */ } } } diff --git a/src/ivyperf.c b/src/ivyperf.c index 11e9522..f0ad069 100755 --- a/src/ivyperf.c +++ b/src/ivyperf.c @@ -52,18 +52,33 @@ static double currentTime() return current; } -void Reply (IvyClientPtr app, void *user_data, int argc, char *argv[]) +void Reply (IvyClientPtr app, void *user_data, IvyArgument args) { - IvySendMsg ("pong ts=%s tr=%f", *argv, currentTime()); + IvyArgument arg; + int len; + void* val; + arg = IvyArgumentGetChildrens( args ); + IvyArgumentGetValue( args , &len, &val); + IvySendMsg ("pong ts=%.*s tr=%f", len, val, currentTime()); } -void Pong (IvyClientPtr app, void *user_data, int argc, char *argv[]) +void Pong (IvyClientPtr app, void *user_data, IvyArgument args) { - double current = currentTime(); - double ts = atof( *argv++ ); - double tr = atof( *argv++ ); - double roundtrip1 = tr-ts; - double roundtrip2 = current - tr; - double roundtrip3 = current - ts; + double current, ts, tr, roundtrip1, roundtrip2, roundtrip3; + IvyArgument arg; + int len; + void* val; + /* TODO bug atof non limite a la longeur de la valeur !!!*/ + + current = currentTime(); + arg = IvyArgumentGetChildrens( args ); + IvyArgumentGetValue( args , &len, &val); + ts = atof( val ); + arg = IvyArgumentGetNextChild( arg ); + IvyArgumentGetValue( args , &len, &val); + tr = atof( val ); + roundtrip1 = tr-ts; + roundtrip2 = current - tr; + roundtrip3 = current - ts; fprintf(stderr,"roundtrip %f %f %f \n", roundtrip1, roundtrip2, roundtrip3 ); } diff --git a/src/ivyprobe.c b/src/ivyprobe.c index 076b97b..c163577 100644 --- a/src/ivyprobe.c +++ b/src/ivyprobe.c @@ -85,12 +85,19 @@ void BindCallback(IvyClientPtr app, void *user_data, IvyBindEvent event, char * IvyGetApplicationName(app),regexp,sevent); } -void Callback (IvyClientPtr app, void *user_data, int argc, char *argv[]) +void Callback (IvyClientPtr app, void *user_data, IvyArgument args) { - int i; - printf ("%s sent %d args:",IvyGetApplicationName(app),argc); - for (i = 0; i < argc; i++) - printf(" '%s'",argv[i]); + IvyArgument arg; + int len; + const void* value; + printf ("%s sent:",IvyGetApplicationName(app)); + arg = IvyArgumentGetChildrens ( args ) ; + while( arg ) + { + IvyArgumentGetValue( arg, &len, &value ); + printf(" '%.*s'",len, (char*)value ); + arg = IvyArgumentGetNextChild( arg ); + } printf("\n"); } @@ -118,7 +125,7 @@ void HandleStdin (Channel channel, IVY_HANDLE fd, void *data) if (!line) { #ifdef WIN32 #else - IvyChannelClose (channel); + IvyChannelRemove (channel); #endif IvyStop(); return; @@ -276,7 +283,7 @@ void ApplicationCallback (IvyClientPtr app, void *user_data, IvyApplicationEvent /* printf("Application(%s): End Messages\n",appname);*/ if (app_count == wait_count) - IvyChannelOpen (0, NULL, NULL, HandleStdin); + IvyChannelAdd (0, NULL, NULL, HandleStdin); break; case IvyApplicationDisconnected: @@ -371,7 +378,7 @@ int main(int argc, char *argv[]) /* use Thread to Read StdIn */ CraeteStdinThread(); #else - IvyChannelOpen (0, NULL, NULL, HandleStdin); + IvyChannelAdd (0, NULL, NULL, HandleStdin); #endif diff --git a/src/ivysocket.c b/src/ivysocket.c index 22a593e..9fac44c 100644 --- a/src/ivysocket.c +++ b/src/ivysocket.c @@ -80,46 +80,6 @@ static Client clients_list = NULL; WSADATA WsaData; #endif -// fonction de formtage a la printf d'un buffer avec reallocation dynamique -int make_message(char ** buffer, int *size, int offset, const char *fmt, va_list ap) -{ - /* Guess we need no more than BUFFER_INIT_SIZE bytes. */ - long n; - if ( *size == 0 || *buffer == NULL ) - { - *size = BUFFER_SIZE; - *buffer = malloc (BUFFER_SIZE); - if ( *buffer == NULL ) - return -1; - } - while (1) { - /* Try to print in the allocated space. */ -#ifdef WIN32 - n = _vsnprintf (*buffer + offset, *size - offset, fmt, ap); -#else - n = vsnprintf (*buffer + offset, *size - offset, fmt, ap); -#endif - /* If that worked, return the string size. */ - if (n > -1 && n < *size) - return n; - /* Else try again with more space. */ - if (n > -1) /* glibc 2.1 */ - *size = n+1; /* precisely what is needed */ - else /* glibc 2.0 */ - *size *= 2; /* twice the old size */ - if ((*buffer = realloc (*buffer, *size)) == NULL) - return -1; - } -} -int make_message_var(char ** buffer, int *size, int offset, const char *fmt, ... ) -{ - va_list ap; - long len; - va_start (ap, fmt ); - len = make_message (buffer,size, offset, fmt, ap ); - va_end (ap ); - return len; -} static void DeleteSocket(void *data) { Client client = (Client )data; @@ -168,11 +128,11 @@ static void HandleSocket (Channel channel, IVY_HANDLE fd, void *data) &len); if (nb < 0) { perror(" Read Socket "); - IvyChannelClose(client->channel ); + IvyChannelRemove(client->channel ); return; } if (nb == 0 ) { - IvyChannelClose(client->channel ); + IvyChannelRemove(client->channel ); return; } client->in_ptr += nb; @@ -226,7 +186,7 @@ static Client CreateClient(int handle) } client->out_ptr = client->out_buffer; client->fd = handle; - client->channel = IvyChannelOpen (client->fd, client, DeleteSocket, HandleSocket ); + client->channel = IvyChannelAdd (client->fd, client, DeleteSocket, HandleSocket ); return client; } @@ -324,7 +284,7 @@ Server SocketServer(unsigned short port, exit(0); } server->fd = fd; - server->channel = IvyChannelOpen(fd, server, DeleteServerSocket, HandleServer ); + server->channel = IvyChannelAdd(fd, server, DeleteServerSocket, HandleServer ); server->create = create; server->handle_delete = handle_delete; server->interpretation = interpretation; @@ -341,7 +301,7 @@ void SocketServerClose (Server server ) { if (!server) return; - IvyChannelClose (server->channel ); + IvyChannelRemove (server->channel ); } char *SocketGetPeerHost (Client client ) @@ -384,7 +344,7 @@ void SocketGetRemoteHost (Client client, char **host, unsigned short *port ) void SocketClose (Client client ) { if (client) - IvyChannelClose (client->channel ); + IvyChannelRemove (client->channel ); } void SocketSetData (Client client, void *data ) { @@ -396,7 +356,7 @@ void *SocketGetData (Client client ) { return client ? client->data : 0; } -void SocketSendBuf (Client client, const char *buffer, int len ) +void SocketSend(Client client, const char *buffer, int len ) { unsigned long usedspace; if (!client) @@ -412,16 +372,6 @@ void SocketSendBuf (Client client, const char *buffer, int len ) client->out_ptr += len; } - -void SocketSendFmt (Client client, const char *fmt, ... ) -{ - va_list ap; - if (!client) - return; - va_start (ap, fmt ); - client->out_ptr += make_message (&client->out_buffer, &client->out_buffer_size, client->out_ptr - client->out_buffer, fmt, ap ); - va_end (ap ); -} void SocketFlush (Client client) { int err; @@ -543,20 +493,7 @@ Client SocketBroadcastCreate ( return client; } -void SocketSendBroadcast (Client client, unsigned long host, unsigned short port, char *fmt, ... ) -{ - va_list ap; - int len; - - if (!client) - return; - - va_start (ap, fmt ); - len = make_message (&client->out_buffer, &client->out_buffer_size, 0, fmt, ap ); - SocketSendBroadcastRaw( client, host, port, client->out_buffer, len ); - va_end (ap ); -} -void SocketSendBroadcastRaw (Client client, unsigned long host, unsigned short port, char *buffer, int len ) +void SocketSendBroadcast(Client client, unsigned long host, unsigned short port, char *buffer, int len ) { struct sockaddr_in remote; int err; diff --git a/src/ivysocket.h b/src/ivysocket.h index f5ac390..b491f0f 100644 --- a/src/ivysocket.h +++ b/src/ivysocket.h @@ -45,10 +45,6 @@ extern "C" { /* General Init */ -/* utility fonction do make vsprintf without buffer limit */ -extern int make_message(char ** buffer, int *size, int offset, const char *fmt, va_list ap); -extern int make_message_var(char ** buffer, int *size, int offset, const char *fmt, ...); - /* Forward def */ typedef struct _client *Client; typedef char* (*SocketInterpretation) (Client client, void *data, char *ligne, unsigned int len); @@ -67,8 +63,7 @@ extern void SocketServerClose( Server server ); /* Client Part */ extern void SocketKeepAlive( Client client,int keepalive ); extern void SocketClose( Client client ); -extern void SocketSendFmt( Client client, const char *fmt, ... ); -extern void SocketSendBuf( Client client, const char *buffer, int len ); +extern void SocketSend( Client client, const char *buffer, int len ); extern void SocketFlush (Client client); extern char *SocketGetPeerHost( Client client ); extern void SocketSetData( Client client, void *data ); @@ -98,8 +93,7 @@ extern int SocketAddMember( Client client, unsigned long host ); extern struct in_addr * SocketGetRemoteAddr( Client client ); extern void SocketGetRemoteHost (Client client, char **host, unsigned short *port ); /* emmission d'un broadcast UDP */ -extern void SocketSendBroadcast( Client client, unsigned long host, unsigned short port, char *fmt, ... ); -extern void SocketSendBroadcastRaw( Client client, unsigned long host, unsigned short port, char *buffer, int len ); +extern void SocketSendBroadcast( Client client, unsigned long host, unsigned short port, char *buffer, int len ); #ifdef __cplusplus } diff --git a/src/ivytcl.c b/src/ivytcl.c index 406bbd9..6c82e54 100755 --- a/src/ivytcl.c +++ b/src/ivytcl.c @@ -99,7 +99,7 @@ IvyHandleFd(ClientData cd, } } -void IvyChannelClose( Channel channel ) +void IvyChannelRemove( Channel channel ) { if ( channel->handle_delete ) @@ -109,7 +109,7 @@ void IvyChannelClose( Channel channel ) } -Channel IvyChannelOpen(HANDLE fd, void *data, +Channel IvyChannelAdd(HANDLE fd, void *data, ChannelHandleDelete handle_delete, ChannelHandleRead handle_read ) diff --git a/src/ivyxtloop.c b/src/ivyxtloop.c index 0406498..6a451a1 100644 --- a/src/ivyxtloop.c +++ b/src/ivyxtloop.c @@ -75,7 +75,7 @@ void IvyChannelInit(void) channel_initialized = 1; } -void IvyChannelClose( Channel channel ) +void IvyChannelRemove( Channel channel ) { if ( channel->handle_delete ) @@ -111,7 +111,7 @@ void IvyXtChannelAppContext( XtAppContext cntx ) app = cntx; } -Channel IvyChannelOpen(IVY_HANDLE fd, void *data, +Channel IvyChannelAdd(IVY_HANDLE fd, void *data, ChannelHandleDelete handle_delete, ChannelHandleRead handle_read ) diff --git a/src/libIvy.def b/src/libIvy.def index 18320c9..acf1786 100644 --- a/src/libIvy.def +++ b/src/libIvy.def @@ -3,7 +3,7 @@ LIBRARY Ivy EXPORTS IvyDefaultApplicationCallback -IvyClasses +IvySetMyMessagesStart IvyInit IvyStart IvyStop @@ -19,13 +19,27 @@ IvyUnbindMsg IvySendError IvySendDieMsg IvySendMsg - +IvySetApplicationPriority +IvySetBindCallback IvyBindDirectMsg IvySendDirectMsg +IvyArgumentNew +IvyArgumentFree +IvyArgumentGetValue +IvyArgumentGetChildrens +IvyArgumentGetNextChild +IvyAddChild +IvyAddChildValue + + IvyMainLoop IvyChannelInit -IvyChannelClose -IvyChannelSetUp +IvyChannelRemove +IvyChannelAdd + +TimerRepeatAfter +TimerModify +TimerRemove @@ -13,11 +13,15 @@ * Please refer to file version.h for the * copyright notice regarding this software */ -#if (__GNUC__ >= 3) +#ifdef WIN32 +#define TYPEOF(p) void* +#else +#if (__GNUC__ >= 2) #define TYPEOF(p) typeof (p) #else #define TYPEOF(p) void * #endif +#endif #define IVY_LIST_ITER( list, p, cond ) \ p = list; \ @@ -57,7 +61,23 @@ memset( p, 0 , sizeof( *p ));\ p->next = list; \ list = p; \ - } + } + +#define IVY_LIST_ADD_END(list, p ) \ + if ((p = (TYPEOF(p)) (malloc( sizeof( *p ))))) \ + { \ + TYPEOF(p) list_end; \ + memset( p, 0 , sizeof( *p ));\ + p->next = 0; \ + if ( list ) \ + {\ + list_end = list; \ + while ( list_end && list_end->next ) \ + list_end = list_end->next;\ + list_end->next = p; \ + } \ + else list = p; \ + } #define IVY_LIST_EACH( list, p ) \ for ( p = list ; p ; p = p -> next ) |