X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=src%2Fngircd%2Frendezvous.c;h=2d9ae6993d08b1c5666a5fda10161016f111c57e;hb=a988bbc86aed404b7bcfdbceafc030ea4bc5ecab;hp=720f5dfe57d3368f5300c13d3bfec725a060f8cb;hpb=292879aca48e7b28d592cff99361ba73e01d0aa8;p=ngircd-alex.git diff --git a/src/ngircd/rendezvous.c b/src/ngircd/rendezvous.c index 720f5dfe..2d9ae699 100644 --- a/src/ngircd/rendezvous.c +++ b/src/ngircd/rendezvous.c @@ -18,10 +18,10 @@ #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 @@ -62,7 +62,7 @@ static char UNUSED id[] = "$Id: rendezvous.c,v 1.3 2004/12/26 00:14:33 alex Exp 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; @@ -72,10 +72,10 @@ typedef struct _service #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 -- */ @@ -84,7 +84,7 @@ LOCAL VOID Unregister( INT Idx ); #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 */ @@ -93,24 +93,19 @@ LOCAL VOID Registration_Reply_Handler( DNSServiceRegistrationReplyErrorType ErrC #ifdef HOWL -#include +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 ) @@ -119,17 +114,24 @@ GLOBAL VOID Rendezvous_Init( VOID ) 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++ ) { @@ -137,29 +139,27 @@ GLOBAL VOID Rendezvous_Exit( VOID ) } #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 ) +/** + * Register ZeroConf service + */ +GLOBAL bool Rendezvous_Register( char *Name, char *Type, UINT16 Port ) { - /* Register new service */ + int i; - INT i; + if (Conf_NoZeroConf) + return; /* 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 )); @@ -170,7 +170,7 @@ GLOBAL BOOLEAN Rendezvous_Register( CHAR *Name, CHAR *Type, UINT Port ) { 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 */ @@ -181,7 +181,7 @@ GLOBAL BOOLEAN Rendezvous_Register( CHAR *Name, CHAR *Type, UINT 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 */ @@ -190,29 +190,29 @@ GLOBAL BOOLEAN Rendezvous_Register( CHAR *Name, CHAR *Type, UINT Port ) { 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; } } @@ -220,11 +220,11 @@ GLOBAL BOOLEAN Rendezvous_Unregister( CHAR *Name ) } /* 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++ ) { @@ -233,14 +233,14 @@ GLOBAL VOID Rendezvous_UnregisterListeners( VOID ) } /* 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; @@ -255,24 +255,19 @@ GLOBAL VOID Rendezvous_Handler( VOID ) /* 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 */ @@ -298,10 +293,10 @@ LOCAL VOID Unregister( INT Idx ) #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 ) { @@ -319,7 +314,8 @@ LOCAL VOID Registration_Reply_Handler( DNSServiceRegistrationReplyErrorType ErrC 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 ); @@ -335,10 +331,10 @@ LOCAL VOID Registration_Reply_Handler( DNSServiceRegistrationReplyErrorType ErrC #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 ); @@ -356,7 +352,8 @@ LOCAL sw_result HOWL_API Registration_Reply_Handler( sw_discovery Session, sw_di 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 ); @@ -366,18 +363,10 @@ LOCAL sw_result HOWL_API Registration_Reply_Handler( sw_discovery Session, sw_di } /* 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- */