#include "portab.h"
-#ifdef RENDEZVOUS
+#ifdef ZEROCONF
-static char UNUSED id[] = "$Id: rendezvous.c,v 1.3 2004/12/26 00:14:33 alex Exp $";
+static char UNUSED id[] = "$Id: rendezvous.c,v 1.8 2006/05/10 21:24:01 alex Exp $";
#include "imp.h"
#include <assert.h>
typedef struct _service
{
- CHAR Desc[CLIENT_ID_LEN];
+ char Desc[CLIENT_ID_LEN];
#ifdef APPLE
dns_service_discovery_ref Discovery_Ref;
mach_port_t Mach_Port;
#endif
} SERVICE;
-LOCAL SERVICE My_Rendezvous[MAX_RENDEZVOUS];
+static SERVICE My_Rendezvous[MAX_RENDEZVOUS];
-LOCAL VOID Unregister( INT Idx );
+static void Unregister( int Idx );
/* -- Apple API -- */
#define MAX_MACH_MSG_SIZE 512
-LOCAL VOID Registration_Reply_Handler( DNSServiceRegistrationReplyErrorType ErrCode, VOID *Context );
+static void Registration_Reply_Handler( DNSServiceRegistrationReplyErrorType ErrCode, void *Context );
#endif /* Apple */
#ifdef HOWL
-#include <pthread.h>
+static sw_discovery My_Discovery_Session = NULL;
+static sw_salt My_Salt;
-LOCAL sw_discovery My_Discovery_Session = NULL;
-LOCAL pthread_t My_Howl_Thread;
-LOCAL BOOLEAN My_Howl_Thread_Created = FALSE;
-
-LOCAL sw_result HOWL_API Registration_Reply_Handler( sw_discovery Session, sw_discovery_publish_status Status, sw_discovery_oid Id, sw_opaque Extra );
-
-LOCAL VOID* Howl_Thread( VOID *x );
+static sw_result HOWL_API Registration_Reply_Handler( sw_discovery Session, sw_discovery_publish_status Status, sw_discovery_oid Id, sw_opaque Extra );
#endif /* Howl */
-GLOBAL VOID Rendezvous_Init( VOID )
+GLOBAL void Rendezvous_Init( void )
{
/* Initialize structures */
- INT i;
+ int i;
#ifdef HOWL
if( sw_discovery_init( &My_Discovery_Session ) != SW_OKAY )
Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
exit( 1 );
}
+
+ if( sw_discovery_salt( My_Discovery_Session, &My_Salt ) != SW_OKAY )
+ {
+ Log( LOG_EMERG, "Can't initialize Rendezvous (Howl): sw_discovery_salt() failed!" );
+ Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
+ exit( 1 );
+ }
#endif
for( i = 0; i < MAX_RENDEZVOUS; i++ ) My_Rendezvous[i].Desc[0] = '\0';
} /* Rendezvous_Init */
-GLOBAL VOID Rendezvous_Exit( VOID )
+GLOBAL void Rendezvous_Exit( void )
{
/* Clean up & exit module */
- INT i;
+ int i;
for( i = 0; i < MAX_RENDEZVOUS; i++ )
{
}
#ifdef HOWL
- if( My_Howl_Thread_Created )
- {
- Log( LOG_DEBUG, "Rendezvous: Canceling management thread ..." );
- pthread_cancel( My_Howl_Thread );
- }
-
sw_discovery_fina( My_Discovery_Session );
#endif
} /* Rendezvous_Exit */
-GLOBAL BOOLEAN Rendezvous_Register( CHAR *Name, CHAR *Type, UINT Port )
+GLOBAL bool Rendezvous_Register( char *Name, char *Type, UINT16 Port )
{
/* Register new service */
- INT i;
+ int i;
/* Search free port structure */
for( i = 0; i < MAX_RENDEZVOUS; i++ ) if( ! My_Rendezvous[i].Desc[0] ) break;
if( i >= MAX_RENDEZVOUS )
{
Log( LOG_ERR, "Can't register \"%s\" with Rendezvous: limit (%d) reached!", Name, MAX_RENDEZVOUS );
- return FALSE;
+ return false;
}
strlcpy( My_Rendezvous[i].Desc, Name, sizeof( My_Rendezvous[i].Desc ));
{
Log( LOG_ERR, "Can't register \"%s\" with Rendezvous: can't register service!", My_Rendezvous[i].Desc );
My_Rendezvous[i].Desc[0] = '\0';
- return FALSE;
+ return false;
}
/* Get and save the corresponding Mach Port */
/* Here we actually leek a descriptor :-( */
My_Rendezvous[i].Discovery_Ref = 0;
My_Rendezvous[i].Desc[0] = '\0';
- return FALSE;
+ return false;
}
#endif /* Apple */
{
Log( LOG_ERR, "Can't register \"%s\" with Rendezvous: can't register service!", My_Rendezvous[i].Desc );
My_Rendezvous[i].Desc[0] = '\0';
- return FALSE;
+ return false;
}
#endif /* Howl */
Log( LOG_DEBUG, "Rendezvous: Registering \"%s\" ...", My_Rendezvous[i].Desc );
- return TRUE;
+ return true;
} /* Rendezvous_Register */
-GLOBAL BOOLEAN Rendezvous_Unregister( CHAR *Name )
+GLOBAL bool Rendezvous_Unregister( char *Name )
{
/* Unregister service from rendezvous */
- INT i;
- BOOLEAN ok;
+ int i;
+ bool ok;
- ok = FALSE;
+ ok = false;
for( i = 0; i < MAX_RENDEZVOUS; i++ )
{
if( strcmp( Name, My_Rendezvous[i].Desc ) == 0 )
{
Unregister( i );
- ok = TRUE;
+ ok = true;
}
}
} /* Rendezvous_Unregister */
-GLOBAL VOID Rendezvous_UnregisterListeners( VOID )
+GLOBAL void Rendezvous_UnregisterListeners( void )
{
/* Unregister all our listening sockets from Rendezvous */
- INT i;
+ int i;
for( i = 0; i < MAX_RENDEZVOUS; i++ )
{
} /* Rendezvous_UnregisterListeners */
-GLOBAL VOID Rendezvous_Handler( VOID )
+GLOBAL void Rendezvous_Handler( void )
{
/* Handle all Rendezvous stuff; this function must be called
* periodically from the run loop of the main program */
#ifdef APPLE
- INT i;
- CHAR buffer[MAX_MACH_MSG_SIZE];
+ int i;
+ char buffer[MAX_MACH_MSG_SIZE];
mach_msg_return_t result;
mach_msg_header_t *msg;
/* Handle message */
if( result == MACH_MSG_SUCCESS ) DNSServiceDiscovery_handleReply( msg );
#ifdef DEBUG
- else if( result != MACH_RCV_TIMED_OUT ) Log( LOG_DEBUG, "mach_msg(): %ld", (LONG)result );
+ else if( result != MACH_RCV_TIMED_OUT ) Log( LOG_DEBUG, "mach_msg(): %ld", (long)result );
#endif /* Debug */
}
#endif /* Apple */
#ifdef HOWL
- if( My_Discovery_Session != NULL && My_Howl_Thread_Created == FALSE )
- {
- /* Create POSIX thread for sw_discovery_run() */
- Log( LOG_DEBUG, "Rendezvous: Creating management thread ..." );
- pthread_create( &My_Howl_Thread, NULL, Howl_Thread, NULL );
- My_Howl_Thread_Created = TRUE;
- }
+ sw_ulong msecs = 10;
+ sw_salt_step( My_Salt, &msecs );
#endif
} /* Rendezvous_Handler */
-LOCAL VOID Unregister( INT Idx )
+static void Unregister( int Idx )
{
/* Unregister service */
#ifdef APPLE
-LOCAL VOID Registration_Reply_Handler( DNSServiceRegistrationReplyErrorType ErrCode, VOID *Context )
+static void Registration_Reply_Handler( DNSServiceRegistrationReplyErrorType ErrCode, void *Context )
{
SERVICE *s = (SERVICE *)Context;
- CHAR txt[50];
+ char txt[50];
if( ErrCode == kDNSServiceDiscoveryNoError )
{
strcpy( txt, "name conflict!" );
break;
default:
- sprintf( txt, "error code %ld!", (LONG)ErrCode );
+ snprintf(txt, sizeof txt, "error code %ld!",
+ (long)ErrCode);
}
Log( LOG_INFO, "Can't register \"%s\" with Rendezvous: %s", s->Desc, txt );
#ifdef HOWL
-LOCAL sw_result HOWL_API Registration_Reply_Handler( sw_discovery Session, sw_discovery_publish_status Status, UNUSED sw_discovery_oid Id, sw_opaque Extra )
+static sw_result HOWL_API Registration_Reply_Handler( sw_discovery Session, sw_discovery_publish_status Status, UNUSED sw_discovery_oid Id, sw_opaque Extra )
{
SERVICE *s = (SERVICE *)Extra;
- CHAR txt[50];
+ char txt[50];
assert( Session == My_Discovery_Session );
assert( Extra != NULL );
strcpy( txt, "name conflict!" );
break;
default:
- sprintf( txt, "error code %ld!", (LONG)Status );
+ snprintf(txt, sizeof txt, "error code %ld!",
+ (long)Status);
}
Log( LOG_INFO, "Can't register \"%s\" with Rendezvous: %s", s->Desc, txt );
} /* Registration_Reply_Handler */
-LOCAL VOID *Howl_Thread( VOID *x )
-{
- assert( x == NULL );
- sw_discovery_run( My_Discovery_Session );
- pthread_exit( NULL );
-} /* Howl_Thread */
-
-
#endif /* Howl */
-#endif /* RENDEZVOUS */
+#endif /* ZEROCONF */
/* -eof- */