summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ivy.c49
-rw-r--r--src/ivyloop.c17
-rw-r--r--src/ivysocket.c26
-rw-r--r--src/list.h15
-rw-r--r--src/timer.c10
5 files changed, 45 insertions, 72 deletions
diff --git a/src/ivy.c b/src/ivy.c
index 362aef2..770d97e 100644
--- a/src/ivy.c
+++ b/src/ivy.c
@@ -62,7 +62,6 @@ typedef enum {
} MsgType;
-
typedef struct _msg_snd *MsgSndPtr;
struct _msg_rcv { /* requete d'emission d'un client */
@@ -73,7 +72,6 @@ struct _msg_rcv { /* requete d'emission d'un client */
void *user_data; /* stokage d'info client */
};
-
struct _msg_snd { /* requete de reception d'un client */
MsgSndPtr next;
int id;
@@ -122,7 +120,6 @@ static *application_die_user_data = 0;
/* liste des messages a recevoir */
static MsgRcvPtr msg_recv = 0;
-
/* liste des clients connectes */
static IvyClientPtr clients = 0;
@@ -157,21 +154,20 @@ static void IvyCleanup()
IvyClientPtr clnt,next;
/* destruction des connexions clients */
- LIST_EACH_SAFE( clients, clnt, next )
+ IVY_LIST_EACH_SAFE( clients, clnt, next )
{
/* on dit au revoir */
MsgSendTo( clnt->client, Bye, 0, "" );
SocketClose( clnt->client );
- LIST_EMPTY( clnt->msg_send );
+ IVY_LIST_EMPTY( clnt->msg_send );
}
- LIST_EMPTY( clients );
+ IVY_LIST_EMPTY( clients );
/* destruction des sockets serveur et supervision */
SocketServerClose( server );
SocketClose( broadcast );
}
-
static int
MsgCall (const char *message, MsgSndPtr msg, Client client)
{
@@ -230,13 +226,12 @@ ClientCall (IvyClientPtr clnt, const char *message)
MsgSndPtr msg;
int match_count = 0;
/* recherche dans la liste des requetes recues de ce client */
- LIST_EACH (clnt->msg_send, msg) {
+ IVY_LIST_EACH (clnt->msg_send, msg) {
match_count+= MsgCall (message, msg, clnt->client);
}
return match_count;
}
-
static int CheckRegexp(char *exp)
{
/* accepte tout par default */
@@ -263,7 +258,7 @@ static int CheckConnected( IvyClientPtr clnt )
if ( clnt->app_port == 0 )
return 0;
/* recherche dans la liste des clients de la presence de clnt */
- LIST_EACH( clients, client )
+ IVY_LIST_EACH( clients, client )
{
/* client different mais port identique */
if ( (client != clnt) && (clnt->app_port == client->app_port) )
@@ -331,7 +326,7 @@ static void Receive( Client client, void *data, char *line )
reg = regcomp(&regexp, arg, REG_ICASE|REG_EXTENDED);
if ( reg == 0 )
{
- LIST_ADD( clnt->msg_send, snd )
+ IVY_LIST_ADD( clnt->msg_send, snd )
if ( snd )
{
snd->id = id;
@@ -353,11 +348,11 @@ static void Receive( Client client, void *data, char *line )
printf("Regexp Delete id=%d\n", id);
#endif //DEBUG
- LIST_ITER( clnt->msg_send, snd, ( id != snd->id ));
+ IVY_LIST_ITER( clnt->msg_send, snd, ( id != snd->id ));
if ( snd )
{
free( snd->str_regexp );
- LIST_REMOVE( clnt->msg_send, snd );
+ IVY_LIST_REMOVE( clnt->msg_send, snd );
}
break;
case StartRegexp:
@@ -402,7 +397,7 @@ static void Receive( Client client, void *data, char *line )
printf("Message id=%d msg='%s'\n", id, arg);
#endif //DEBUG
- LIST_EACH( msg_recv, rcv )
+ IVY_LIST_EACH( msg_recv, rcv )
{
if ( id == rcv->id )
{
@@ -454,7 +449,7 @@ static IvyClientPtr SendService( Client client )
{
IvyClientPtr clnt;
MsgRcvPtr msg;
- LIST_ADD( clients, clnt )
+ IVY_LIST_ADD( clients, clnt )
if ( clnt )
{
clnt->msg_send = 0;
@@ -462,7 +457,7 @@ static IvyClientPtr SendService( Client client )
clnt->app_name = strdup("Unknown");
clnt->app_port = 0;
MsgSendTo( client, StartRegexp, ApplicationPort, ApplicationName);
- LIST_EACH(msg_recv, msg )
+ IVY_LIST_EACH(msg_recv, msg )
{
MsgSendTo( client, AddRegexp,msg->id,msg->regexp);
}
@@ -492,13 +487,13 @@ static void ClientDelete( Client client, void *data )
#endif //DEBUG
if ( clnt->app_name ) free( clnt->app_name );
- LIST_EACH( clnt->msg_send, msg)
+ IVY_LIST_EACH( clnt->msg_send, msg)
{
/*regfree(msg->regexp);*/
free( msg->str_regexp);
}
- LIST_EMPTY( clnt->msg_send );
- LIST_REMOVE( clients, clnt );
+ IVY_LIST_EMPTY( clnt->msg_send );
+ IVY_LIST_REMOVE( clients, clnt );
}
static void *ClientCreate( Client client )
@@ -561,7 +556,6 @@ static void BroadcastReceive( Client client, void *data, char *line )
}
}
-
void IvyInit (const char *appname, const char *ready,
IvyApplicationCallback callback, void *data,
IvyDieCallback die_callback, void *die_data
@@ -583,7 +577,6 @@ void IvyClasses( int argc, const char **argv)
messages_classes = argv;
}
-
void IvyStart (const char* bus)
{
struct in_addr baddr;
@@ -703,7 +696,7 @@ IvyUnbindMsg (MsgRcvPtr msg)
{
IvyClientPtr clnt;
/* Send to already connected clients */
- LIST_EACH (clients, clnt ) {
+ IVY_LIST_EACH (clients, clnt ) {
MsgSendTo( clnt->client, DelRegexp,msg->id, "");
}
}
@@ -716,7 +709,7 @@ _BindMsg (MsgCallback callback, void *user_data, const char *regexp )
IvyClientPtr clnt;
MsgRcvPtr msg;
/* add Msg to the query list */
- LIST_ADD( msg_recv, msg );
+ IVY_LIST_ADD( msg_recv, msg );
if (msg) {
msg->id = recv_id++;
msg->regexp = strdup(regexp);
@@ -725,7 +718,7 @@ _BindMsg (MsgCallback callback, void *user_data, const char *regexp )
}
/* Send to already connected clients */
/* recherche dans la liste des requetes recues de mes clients */
- LIST_EACH( clients, clnt ) {
+ IVY_LIST_EACH( clients, clnt ) {
MsgSendTo( clnt->client, AddRegexp,msg->id,msg->regexp);
}
return msg;
@@ -750,7 +743,7 @@ _SendMsg (const char *message)
int match_count = 0;
/* recherche dans la liste des requetes recues de mes clients */
- LIST_EACH (clients, clnt) {
+ IVY_LIST_EACH (clients, clnt) {
match_count += ClientCall (clnt, message);
}
#ifdef DEBUG
@@ -829,7 +822,7 @@ void IvyDefaultApplicationCallback( IvyClientPtr app, void *user_data, IvyApplic
IvyClientPtr IvyGetApplication( char *name )
{
IvyClientPtr app = 0;
- LIST_ITER( clients, app, strcmp(name, app->app_name) != 0 );
+ IVY_LIST_ITER( clients, app, strcmp(name, app->app_name) != 0 );
return app;
}
@@ -838,7 +831,7 @@ char *IvyGetApplicationList()
static char applist[4096];
IvyClientPtr app;
applist[0] = '\0';
- LIST_EACH( clients, app )
+ IVY_LIST_EACH( clients, app )
{
strcat( applist, app->app_name );
strcat( applist, " " );
@@ -853,7 +846,7 @@ char **IvyGetApplicationMessages( IvyClientPtr app )
int msgCount= 0;
memset( messagelist, 0 , sizeof( messagelist ));
/* recherche dans la liste des requetes recues de ce client */
- LIST_EACH( app->msg_send, msg )
+ IVY_LIST_EACH( app->msg_send, msg )
{
messagelist[msgCount++]= msg->str_regexp;
}
diff --git a/src/ivyloop.c b/src/ivyloop.c
index 07206a9..2ba0608 100644
--- a/src/ivyloop.c
+++ b/src/ivyloop.c
@@ -35,7 +35,6 @@
#include <signal.h>
#endif
-
#include "list.h"
#include "ivychannel.h"
#include "ivyloop.h"
@@ -50,13 +49,10 @@ 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;
@@ -81,14 +77,14 @@ IvyChannelDelete (Channel channel)
(*channel->handle_delete) (channel->data);
FD_CLR (channel->fd, &open_fds);
- LIST_REMOVE (channels_list, channel);
+ IVY_LIST_REMOVE (channels_list, channel);
}
static void
ChannelDefferedDelete ()
{
Channel channel, next;
- LIST_EACH_SAFE (channels_list, channel,next) {
+ IVY_LIST_EACH_SAFE (channels_list, channel,next) {
if (channel->tobedeleted ) {
IvyChannelDelete (channel);
}
@@ -102,7 +98,7 @@ Channel IvyChannelSetUp (HANDLE fd, void *data,
{
Channel channel;
- LIST_ADD (channels_list, channel);
+ IVY_LIST_ADD (channels_list, channel);
if (!channel) {
fprintf(stderr,"NOK Memory Alloc Error\n");
exit(0);
@@ -123,7 +119,7 @@ IvyChannelHandleRead (fd_set *current)
{
Channel channel, next;
- LIST_EACH_SAFE (channels_list, channel, next) {
+ IVY_LIST_EACH_SAFE (channels_list, channel, next) {
if (FD_ISSET (channel->fd, current)) {
(*channel->handle_read)(channel,channel->fd,channel->data);
}
@@ -134,7 +130,7 @@ static void
IvyChannelHandleExcpt (fd_set *current)
{
Channel channel,next;
- LIST_EACH_SAFE (channels_list, channel, next) {
+ IVY_LIST_EACH_SAFE (channels_list, channel, next) {
if (FD_ISSET (channel->fd, current)) {
if (channel->handle_delete)
(*channel->handle_delete)(channel->data);
@@ -164,7 +160,6 @@ void IvyChannelInit (void)
channel_initialized = 1;
}
-
void IvyStop (void)
{
MainLoop = 0;
@@ -177,8 +172,6 @@ void IvyMainLoop(void(*hook)(void))
fd_set exset;
int ready;
-
-
while (MainLoop) {
ChannelDefferedDelete();
if (hook) (*hook)();
diff --git a/src/ivysocket.c b/src/ivysocket.c
index 582d227..3e23a0b 100644
--- a/src/ivysocket.c
+++ b/src/ivysocket.c
@@ -42,7 +42,6 @@
#include "ivysocket.h"
#include "ivyloop.h"
-
#define MAX_BUFFER 2048
struct _server {
@@ -68,17 +67,13 @@ struct _client {
void *data;
};
-
static Server servers_list = NULL;
static Client clients_list = NULL;
-
-
#ifdef WIN32
WSADATA WsaData;
#endif
-
void SocketInit()
{
if (! channel_init )
@@ -96,7 +91,7 @@ static void DeleteSocket(void *data)
(*client->handle_delete) (client, client->data );
shutdown (client->fd, 2 );
close (client->fd );
- LIST_REMOVE (clients_list, client );
+ IVY_LIST_REMOVE (clients_list, client );
}
static void DeleteServerSocket(void *data)
@@ -108,7 +103,7 @@ static void DeleteServerSocket(void *data)
#endif
shutdown (server->fd, 2 );
close (server->fd );
- LIST_REMOVE (servers_list, server);
+ IVY_LIST_REMOVE (servers_list, server);
}
static void HandleSocket (Channel channel, HANDLE fd, void *data)
{
@@ -174,7 +169,7 @@ static void HandleServer(Channel channel, HANDLE fd, void *data)
perror ("*** accept ***");
return;
};
- LIST_ADD (clients_list, client );
+ IVY_LIST_ADD (clients_list, client );
if (!client )
{
fprintf(stderr,"NOK Memory Alloc Error\n");
@@ -247,7 +242,7 @@ Server SocketServer(unsigned short port,
};
- LIST_ADD (servers_list, server );
+ IVY_LIST_ADD (servers_list, server );
if (!server )
{
fprintf(stderr,"NOK Memory Alloc Error\n");
@@ -262,13 +257,11 @@ Server SocketServer(unsigned short port,
return server;
}
-
unsigned short SocketServerGetPort (Server server )
{
return server ? server->port : 0;
}
-
void SocketServerClose (Server server )
{
if (!server)
@@ -366,13 +359,12 @@ void SocketBroadcast ( char *fmt, ... )
va_start (ap, fmt );
len = vsprintf (buffer, fmt, ap );
va_end (ap );
- LIST_EACH (clients_list, client )
+ IVY_LIST_EACH (clients_list, client )
{
SocketSendRaw (client, buffer, len );
}
}
-
/*
Ouverture d'un canal TCP/IP en mode client
*/
@@ -384,7 +376,6 @@ Client SocketConnect (char * host, unsigned short port,
{
struct hostent *rhost;
-
if ((rhost = gethostbyname (host )) == NULL) {
fprintf(stderr, "Erreur %s Calculateur inconnu !\n",host);
return NULL;
@@ -392,7 +383,6 @@ Client SocketConnect (char * host, unsigned short port,
return SocketConnectAddr ((struct in_addr*)(rhost->h_addr), port, data, interpretation, handle_delete);
}
-
Client SocketConnectAddr (struct in_addr * addr, unsigned short port,
void *data,
SocketInterpretation interpretation,
@@ -417,7 +407,7 @@ Client SocketConnectAddr (struct in_addr * addr, unsigned short port,
return NULL;
};
- LIST_ADD (clients_list, client );
+ IVY_LIST_ADD (clients_list, client );
if (!client ) {
fprintf(stderr,"NOK Memory Alloc Error\n");
close (handle );
@@ -437,7 +427,6 @@ Client SocketConnectAddr (struct in_addr * addr, unsigned short port,
return client;
}
-
int SocketWaitForReply (Client client, char *buffer, int size, int delai)
{
fd_set rdset;
@@ -491,7 +480,6 @@ int SocketWaitForReply (Client client, char *buffer, int size, int delai)
return (ptr_nl - buffer);
}
-
/* Socket UDP */
Client SocketBroadcastCreate (unsigned short port,
@@ -540,7 +528,7 @@ Client SocketBroadcastCreate (unsigned short port,
return NULL;
};
- LIST_ADD(clients_list, client );
+ IVY_LIST_ADD(clients_list, client );
if (!client ) {
fprintf(stderr,"NOK Memory Alloc Error\n");
close (handle );
diff --git a/src/list.h b/src/list.h
index 7afbe8b..0c31223 100644
--- a/src/list.h
+++ b/src/list.h
@@ -14,11 +14,11 @@
* copyright notice regarding this software
*/
-#define LIST_ITER( list, p, cond ) \
+#define IVY_LIST_ITER( list, p, cond ) \
p = list; \
while ( p && (cond) ) p = p->next
-#define LIST_REMOVE( list, p ) \
+#define IVY_LIST_REMOVE( list, p ) \
{ \
void *toRemove; \
if ( list == p ) \
@@ -29,7 +29,7 @@
else \
{\
toRemove = p;\
- LIST_ITER( list, p, ( p->next != toRemove ));\
+ IVY_LIST_ITER( list, p, ( p->next != toRemove ));\
if ( p )\
{\
/* somme tricky swapping to use a untyped variable */\
@@ -44,7 +44,7 @@
} \
}
-#define LIST_ADD(list, p ) \
+#define IVY_LIST_ADD(list, p ) \
if ((p = malloc( sizeof( *p ))))\
{ \
memset( p, 0 , sizeof( *p ));\
@@ -52,14 +52,13 @@
list = p; \
}
-#define LIST_EACH( list, p ) \
+#define IVY_LIST_EACH( list, p ) \
for ( p = list ; p ; p = p -> next )
-#define LIST_EACH_SAFE( list, p, next )\
+#define IVY_LIST_EACH_SAFE( list, p, next )\
for ( p = list ; (next = p ? p->next: p ),p ; p = next )
-
-#define LIST_EMPTY( list ) \
+#define IVY_LIST_EMPTY( list ) \
{ \
void *p; \
while( list ) \
diff --git a/src/timer.c b/src/timer.c
index f7a0540..5ccc690 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -79,7 +79,7 @@ static void AdjTimeout(unsigned long current)
{
/* recherche de la plus courte echeance dans la liste */
newTimeout = timers->when ; /* remise a la premiere valeur */
- LIST_EACH( timers , timer )
+ IVY_LIST_EACH( timers , timer )
{
if ( timer->when < newTimeout )
newTimeout = timer->when;
@@ -103,7 +103,7 @@ TimerId TimerRepeatAfter( int count, long time, TimerCb cb, void *user_data )
/* si y a rien a faire et ben on fait rien */
if ( cb == NULL ) return NULL;
- LIST_ADD( timers, timer )
+ IVY_LIST_ADD( timers, timer )
if ( timer )
{
timer->repeat = count;
@@ -121,7 +121,7 @@ void TimerRemove( TimerId timer )
{
unsigned long stamp;
if ( !timer ) return;
- LIST_REMOVE( timers, timer );
+ IVY_LIST_REMOVE( timers, timer );
stamp = currentTime();
AdjTimeout(stamp);
}
@@ -152,7 +152,7 @@ void TimerScan()
stamp = currentTime();
/* recherche des timers echu dans la liste */
- LIST_EACH_SAFE( timers , timer, next )
+ IVY_LIST_EACH_SAFE( timers , timer, next )
{
if ( timer->when <= stamp )
{
@@ -166,7 +166,7 @@ void TimerScan()
}
else
{
- LIST_REMOVE( timers, timer );
+ IVY_LIST_REMOVE( timers, timer );
}
}
}