summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsc1999-01-26 08:53:25 +0000
committersc1999-01-26 08:53:25 +0000
commitbc141af57a9ea4b5da4a15eea73e5e4269fc7e65 (patch)
tree53654c22e322e346402b09c8ee804220b8acb1bd
parent4853dbf7e1e3d69064f6af735acc802b5971b5f5 (diff)
downloadivy-c-bc141af57a9ea4b5da4a15eea73e5e4269fc7e65.zip
ivy-c-bc141af57a9ea4b5da4a15eea73e5e4269fc7e65.tar.gz
ivy-c-bc141af57a9ea4b5da4a15eea73e5e4269fc7e65.tar.bz2
ivy-c-bc141af57a9ea4b5da4a15eea73e5e4269fc7e65.tar.xz
A bit of clean up in headers
Changes in IvyStart and IvyInit: - expanded parsing of IvyStart argument to bus addresses like 123.123,123.122:2019 - socket for receiving broadcast handshakes is now in IvyStart (we thus lose the ability to have "passive" agents (agents that listen but don't say hello))
-rw-r--r--src/ivy.c116
-rw-r--r--src/ivy.h16
-rw-r--r--src/ivychannel.h10
-rw-r--r--src/ivyloop.h15
-rw-r--r--src/ivyprobe.c28
-rw-r--r--src/ivysocket.c23
-rw-r--r--src/ivysocket.h23
-rw-r--r--src/ivyxtloop.c12
-rw-r--r--src/ivyxtloop.h16
9 files changed, 148 insertions, 111 deletions
diff --git a/src/ivy.c b/src/ivy.c
index 8b1501e..710c7b5 100644
--- a/src/ivy.c
+++ b/src/ivy.c
@@ -1,19 +1,19 @@
/*
+ *
* Ivy, C interface
*
- * Copyright (C) 1997-1999
- * Centre d'Études de la Navigation Aérienne
+ * Copyright 1997-1999
+ * Centre d'Etudes de la Navigation Aerienne
*
- * Main functions
+ * Main functions
*
- * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr>
- * Stéphane Chatty <chatty@cenatoulouse.dgac.fr>
+ * Authors: Francois-Regis Colin <fcolin@cenatoulouse.dgac.fr>
+ * Stephane Chatty <chatty@cenatoulouse.dgac.fr>
*
* $Id$
- *
- * Please refer to file version.h for the
- * copyright notice regarding this software
*
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
*/
#include <stdlib.h>
@@ -42,9 +42,9 @@
#if 1
/* temporary hack for compatibility */
-static char* DefaultIvyDomains = "143.196.1.255, 143.196.2.255, 143.196.53.255";
+static char* DefaultIvyBus = "143.196.1.255, 143.196.2.255, 143.196.53.255";
#else
-static char* DefaultIvyDomains = "127.0.0.255";
+static char* DefaultIvyBus = "127.255.255.255";
#endif
typedef enum {
@@ -469,7 +469,7 @@ static void ClientDelete( Client client, void *data )
#ifdef DEBUG
/* probably bogus call, but this is for debug only anyway */
- SocketGetRemote( client, &remotehost, &remoteport );
+ SocketGetRemoteHost( client, &remotehost, &remoteport );
printf("Deconnexion de %s:%hu\n", remotehost, remoteport );
#endif //DEBUG
@@ -489,7 +489,7 @@ static void *ClientCreate( Client client )
#ifdef DEBUG
char *remotehost;
unsigned short remoteport;
- SocketGetRemote( client, &remotehost, &remoteport );
+ SocketGetRemoteHost( client, &remotehost, &remoteport );
printf("Connexion de %s:%hu\n", remotehost, remoteport );
#endif //DEBUG
@@ -512,24 +512,25 @@ static void BroadcastReceive( Client client, void *data, char *line )
/* ignore the message */
unsigned short remoteport;
char *remotehost;
- SocketGetRemote( client, &remotehost, &remoteport );
- printf(" Bad supervision message, expected 'version port' from %s:%d\n",remotehost, remoteport);
+ SocketGetRemoteHost (client, &remotehost, &remoteport );
+ printf (" Bad supervision message, expected 'version port' from %s:%d\n",
+ remotehost, remoteport);
return;
}
if ( version != VERSION ) {
/* ignore the message */
unsigned short remoteport;
char *remotehost = 0;
- SocketGetRemote( client, &remotehost, &remoteport );
- printf(" Bad Ivy version number, expected %d and receive %d from %s:%d\n", VERSION, version, remotehost, remoteport);
+ SocketGetRemoteHost (client, &remotehost, &remoteport );
+ fprintf (stderr, "Bad Ivy version, expected %d and got %d from %s:%d\n",
+ VERSION, version, remotehost, remoteport);
return;
}
- /* check if we receive our own message
- should test also the host */
- if ( serviceport == ApplicationPort ) return;
+ /* check if we received our own message. SHOULD ALSO TEST THE HOST */
+ if (serviceport == ApplicationPort) return;
#ifdef DEBUG
- SocketGetRemote( client, &remotehost, &remoteport );
+ SocketGetRemoteHost (client, &remotehost, &remoteport );
printf(" Broadcast de %s:%hu port %hu\n", remotehost, remoteport, serviceport );
#endif //DEBUG
@@ -543,7 +544,7 @@ static void BroadcastReceive( Client client, void *data, char *line )
}
-void IvyInit(const char *appname, unsigned short busnumber, const char *ready,
+void IvyInit(const char *appname, unsigned short port, const char *ready,
IvyApplicationCallback callback, void *data,
IvyDieCallback die_callback, void *die_data
)
@@ -551,16 +552,12 @@ void IvyInit(const char *appname, unsigned short busnumber, const char *ready,
SocketInit();
ApplicationName = appname;
- SupervisionPort = busnumber;
+ SupervisionPort = port;
application_callback = callback;
application_user_data = data;
application_die_callback = die_callback;
application_die_user_data = die_data;
ready_message = ready;
- server = SocketServer( ANYPORT, ClientCreate, ClientDelete, Receive );
- ApplicationPort = SocketServerGetPort(server);
- broadcast = SocketBroadcastCreate( SupervisionPort, 0, BroadcastReceive );
-
}
void IvyClasses( int argc, const char **argv)
@@ -570,39 +567,71 @@ void IvyClasses( int argc, const char **argv)
}
-void IvyStart (const char* domains)
+void IvyStart (const char* bus)
{
-
unsigned long mask = 0xffffffff;
unsigned char elem = 0;
int numdigit = 0;
int numelem = 0;
int error = 0;
+ const char* p = bus; /* used for decoding address list */
+ const char* q; /* used for decoding port number */
+ int port;
- /* find broadcast address list */
+
+ /*
+ * Initialize TCP port
+ */
+ server = SocketServer(ANYPORT, ClientCreate, ClientDelete, Receive );
+ ApplicationPort = SocketServerGetPort(server);
- const char* p = domains;
+ /*
+ * Find network list as well as broadcast port
+ * (we accept things like 123.231,123.123:2000 or 123.231 or :2000),
+ * Initialize UDP port
+ * Send a broadcast handshake on every network
+ */
+
+ /* first, let's find something to parse */
if (!p)
- p = getenv ("IVYDOMAINS");
+ p = getenv ("IVYBUS");
if (!p)
- p = DefaultIvyDomains;
+ p = DefaultIvyBus;
+
+ /* then, let's get a port number */
+ q = strchr (p, ':');
+ if (q && (port = atoi (q+1)))
+ SupervisionPort = port;
+#if 0
+ else
+ SupervisionPort = ;
+#endif
- /* parse broadcast address list
+ /*
+ * Now we have a port number it's time to initialize the UDP port
+ */
+ broadcast = SocketBroadcastCreate (SupervisionPort, 0, BroadcastReceive );
+
+
+ /* then, if we only have a port number, resort to default value for network */
+ if (p == q)
+ p = DefaultIvyBus;
+
+ /* and finally, parse network list and send broadcast handshakes.
This is painful but inet_aton is sloppy.
If someone knows other builtin routines that do that... */
-
for (;;) {
/* address elements are up to 3 digits... */
if (!error && isdigit (*p)) {
if (numdigit < 3 && numelem < 4) {
- elem = 10*elem + *p -'0';
+ elem = 10 * elem + *p -'0';
} else {
error = 1;
}
- /* ... terminated by a point or a comma or the end of string */
- } else if (!error && (*p == '.' || *p == ',' || *p == '\0')) {
- mask = (mask ^ (0xff<< (8*(3 -numelem)))) | (elem << (8*(3 - numelem)));
+ /* ... terminated by a point, a comma or a colon, or the end of string */
+ } else if (!error && (*p == '.' || *p == ',' || *p == ':' || *p == '\0')) {
+ mask = (mask ^ (0xff << (8*(3-numelem)))) | (elem << (8*(3-numelem)));
/* after a point, expect next address element */
if (*p == '.') {
@@ -618,8 +647,8 @@ void IvyStart (const char* domains)
numdigit = 0;
elem = 0;
- /* recover from bad addresses at next comma or at end of string */
- } else if (*p == ',' || *p == '\0') {
+ /* recover from bad addresses at next comma or colon or at end of string */
+ } else if (*p == ',' || *p == ':' || *p == '\0') {
fprintf (stderr, "bad broadcast address\n");
elem = 0;
numelem = 0;
@@ -635,13 +664,16 @@ void IvyStart (const char* domains)
error = 1;
}
- /* end of string */
- if (!*p)
+ /* end of string or colon */
+ if (*p == '\0' || *p == ':')
break;
++p;
}
+#ifdef DEBUG
fprintf (stderr,"Listening on TCP:%hu\n",ApplicationPort);
+#endif
+
}
/* desabonnements */
diff --git a/src/ivy.h b/src/ivy.h
index 923a5ca..ed0ea95 100644
--- a/src/ivy.h
+++ b/src/ivy.h
@@ -1,22 +1,22 @@
/*
* Ivy, C interface
*
- * Copyright (C) 1997-1999
- * Centre d'Études de la Navigation Aérienne
+ * Copyright (C) 1997-1999
+ * Centre d'Études de la Navigation Aérienne
*
* Main functions
*
- * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr>
+ * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr>
* Stéphane Chatty <chatty@cenatoulouse.dgac.fr>
*
* $Id$
*
- * Please refer to file version.h for the
- * copyright notice regarding this software
- *
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
*/
-#ifndef _IVY_H
-#define _IVY_H
+
+#ifndef IVY_H
+#define IVY_H
#ifdef __cplusplus
extern "C" {
diff --git a/src/ivychannel.h b/src/ivychannel.h
index 1da0982..0edf530 100644
--- a/src/ivychannel.h
+++ b/src/ivychannel.h
@@ -1,18 +1,18 @@
/*
* Ivy, C interface
*
- * Copyright (C) 1997-1999
- * Centre d'Études de la Navigation Aérienne
+ * Copyright (C) 1997-1999
+ * Centre d'Études de la Navigation Aérienne
*
* Basic I/O handling
*
- * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr>
+ * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr>
* Stéphane Chatty <chatty@cenatoulouse.dgac.fr>
*
* $Id$
*
- * Please refer to file version.h for the
- * copyright notice regarding this software
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
*
*/
#ifndef _IVYCHANNEL_H
diff --git a/src/ivyloop.h b/src/ivyloop.h
index 8658875..812c67b 100644
--- a/src/ivyloop.h
+++ b/src/ivyloop.h
@@ -1,22 +1,23 @@
/*
* Ivy, C interface
*
- * Copyright (C) 1997-1999
- * Centre d'Études de la Navigation Aérienne
+ * Copyright (C) 1997-1999
+ * Centre d'Études de la Navigation Aérienne
*
* Main loop handling around select
*
- * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr>
+ * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr>
* Stéphane Chatty <chatty@cenatoulouse.dgac.fr>
*
* $Id$
*
- * Please refer to file version.h for the
- * copyright notice regarding this software
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
*
*/
-#ifndef _IVYLOOP_H
-#define _IVYLOOP_H
+
+#ifndef IVYLOOP_H
+#define IVYLOOP_H
#ifdef __cplusplus
extern "C" {
diff --git a/src/ivyprobe.c b/src/ivyprobe.c
index 8021ece..360eae7 100644
--- a/src/ivyprobe.c
+++ b/src/ivyprobe.c
@@ -1,20 +1,20 @@
/*
* Ivy probe
*
- * Copyright (C) 1997-1999
- * Centre d'Études de la Navigation Aérienne
+ * Copyright (C) 1997-1999
+ * Centre d'Études de la Navigation Aérienne
*
* Main and only file
*
- * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr>
+ * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr>
* Stéphane Chatty <chatty@cenatoulouse.dgac.fr>
*
* $Id$
*
- * Please refer to file version.h for the
- * copyright notice regarding this software
- *
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
*/
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -84,20 +84,20 @@ void HandleStdin( Channel channel, HANDLE fd, void *data)
}
}
if ( strcmp(cmd, "dieall-yes-i-am-sure") == 0 )
- {
+ {
arg = IvyGetApplicationList();
arg = strtok( arg, " \n" );
while ( arg )
{
app = IvyGetApplication( arg );
- if ( app )
- IvySendDieMsg( app );
- else printf( "No Application %s!!!\n",arg);
- arg = strtok( NULL, " ");
+ if ( app )
+ IvySendDieMsg( app );
+ else printf( "No Application %s!!!\n",arg);
+ arg = strtok( NULL, " ");
}
- }
-
+ }
+
if ( strcmp(cmd, "bind" ) == 0 )
{
arg = strtok( NULL, "'" );
@@ -156,7 +156,7 @@ void HandleStdin( Channel channel, HANDLE fd, void *data)
}
else
{
- cmd = strtok (buf, "\n");
+ cmd = strtok (buf, "\n");
err = IvySendMsg( cmd );
printf("-> Sent to %d peer%s\n", err, err == 1 ? "" : "s");
}
diff --git a/src/ivysocket.c b/src/ivysocket.c
index f46aed5..3a86fcc 100644
--- a/src/ivysocket.c
+++ b/src/ivysocket.c
@@ -1,20 +1,19 @@
/*
* Ivy, C interface
*
- * Copyright (C) 1997-1999
- * Centre d'Études de la Navigation Aérienne
+ * Copyright 1997-1999
+ * Centre d'Etudes de la Navigation Aerienne
*
- * Sockets
+ * Sockets
*
- * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr>
- * Stéphane Chatty <chatty@cenatoulouse.dgac.fr>
+ * Authors: Francois-Regis Colin <fcolin@cenatoulouse.dgac.fr>
*
* $Id$
- *
- * Please refer to file version.h for the
- * copyright notice regarding this software
*
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
*/
+
#ifdef WIN32
#include <windows.h>
#endif
@@ -276,11 +275,13 @@ char *SocketGetPeerHost( Client client )
if ( host == NULL ) return "can't translate addr";
return host->h_name;
}
+
struct in_addr * SocketGetRemoteAddr( Client client )
{
return &client->from.sin_addr;
}
-void SocketGetRemote( Client client, char **host, unsigned short *port )
+
+void SocketGetRemoteHost (Client client, char **host, unsigned short *port )
{
struct hostent *hostp;
/* extract hostname and port from last message received */
@@ -290,6 +291,7 @@ void SocketGetRemote( Client client, char **host, unsigned short *port )
else *host = hostp->h_name;
*port = ntohs( client->from.sin_port );
}
+
void SocketClose( Client client )
{
(*channel_close)( client->channel );
@@ -302,10 +304,12 @@ void SocketSendRaw( Client client, char *buffer, int len )
if ( err != len )
perror( "*** send ***");
}
+
void SocketSetData( Client client, void *data )
{
client->data = data;
}
+
void SocketSend( Client client, char *fmt, ... )
{
char buffer[4096];
@@ -316,6 +320,7 @@ void SocketSend( Client client, char *fmt, ... )
SocketSendRaw( client, buffer, len );
va_end ( ap );
}
+
void *SocketGetData( Client client )
{
return client->data;
diff --git a/src/ivysocket.h b/src/ivysocket.h
index 04a8b28..6f59a0c 100644
--- a/src/ivysocket.h
+++ b/src/ivysocket.h
@@ -1,22 +1,21 @@
/*
* Ivy, C interface
*
- * Copyright (C) 1997-1999
- * Centre d'Études de la Navigation Aérienne
+ * Copyright 1997-1999
+ * Centre d'Etudes de la Navigation Aerienne
*
- * Sockets
+ * Sockets
*
- * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr>
- * Stéphane Chatty <chatty@cenatoulouse.dgac.fr>
+ * Authors: Francois-Regis Colin <fcolin@cenatoulouse.dgac.fr>
*
* $Id$
- *
- * Please refer to file version.h for the
- * copyright notice regarding this software
*
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
*/
-#ifndef _IVYSOCKET_H
-#define _IVYSOCKET_H
+
+#ifndef IVYSOCKET_H
+#define IVYSOCKET_H
#ifdef __cplusplus
extern "C" {
@@ -39,7 +38,7 @@ extern void SocketInit();
/* Forward def */
typedef struct _client *Client;
-typedef void (*SocketInterpretation)( Client client, void *data, char *ligne);
+typedef void (*SocketInterpretation) (Client client, void *data, char *ligne);
/* Server Part */
typedef struct _server *Server;
@@ -81,7 +80,7 @@ extern Client SocketBroadcastCreate(
);
/* recuperation de l'emetteur du message */
extern struct in_addr * SocketGetRemoteAddr( Client client );
-extern void SocketGetRemote( Client client, char **host, unsigned short *port );
+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, ... );
diff --git a/src/ivyxtloop.c b/src/ivyxtloop.c
index a265e23..df8dedb 100644
--- a/src/ivyxtloop.c
+++ b/src/ivyxtloop.c
@@ -1,20 +1,20 @@
/*
* Ivy, C interface
*
- * Copyright (C) 1997-1999
- * Centre d'Études de la Navigation Aérienne
+ * Copyright (C) 1997-1999
+ * Centre d'Études de la Navigation Aérienne
*
* Main loop based on X Toolkit
*
- * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr>
+ * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr>
* Stéphane Chatty <chatty@cenatoulouse.dgac.fr>
*
* $Id$
*
- * Please refer to file version.h for the
- * copyright notice regarding this software
- *
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
*/
+
#ifdef WIN32
#include <windows.h>
#endif
diff --git a/src/ivyxtloop.h b/src/ivyxtloop.h
index d76e815..7ee6f30 100644
--- a/src/ivyxtloop.h
+++ b/src/ivyxtloop.h
@@ -1,22 +1,22 @@
/*
* Ivy, C interface
*
- * Copyright (C) 1997-1999
- * Centre d'Études de la Navigation Aérienne
+ * Copyright (C) 1997-1999
+ * Centre d'Études de la Navigation Aérienne
*
* Main loop based on X Toolkit
*
- * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr>
+ * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr>
* Stéphane Chatty <chatty@cenatoulouse.dgac.fr>
*
* $Id$
*
- * Please refer to file version.h for the
- * copyright notice regarding this software
- *
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
*/
-#ifndef _IVYXTLOOP_H
-#define _IVYXTLOOP_H
+
+#ifndef IVYXTLOOP_H
+#define IVYXTLOOP_H
#ifdef __cplusplus
extern "C" {