--- prj/xinetd/config.h.in:1.1.1.2 Tue Oct 11 18:07:17 2005 +++ prj/xinetd/config.h.in Thu Mar 16 00:02:45 2006 @@ -106,6 +106,8 @@ #undef HAVE_HOWL +#undef HAVE_BONJOUR + /* OS specific */ #undef solaris --- prj/xinetd/configure.in:1.1.1.2 Thu Mar 31 01:15:28 2005 +++ prj/xinetd/configure.in Thu Mar 16 00:02:45 2006 @@ -65,6 +65,9 @@ ]) ]) +# check for library dns_sd; if present check for dns_sd.h; if present define HAVE_BONJOUR + HAVE_MDNS +AC_CHECK_LIB(dns_sd, main, [LIBS="-ldns_sd $LIBS"; AC_CHECK_HEADER(dns_sd.h, [AC_DEFINE(HAVE_BONJOUR) AC_DEFINE(HAVE_MDNS)] ) ]) + XINETD_CHECK_TYPE(uint16_t, unsigned short) XINETD_CHECK_TYPE(uint32_t, unsigned int) XINETD_CHECK_TYPE(uint64_t, unsigned long long) --- prj/xinetd/xinetd/main.c:1.1.1.2 Thu Mar 31 01:15:28 2005 +++ prj/xinetd/xinetd/main.c Thu Mar 16 00:02:45 2006 @@ -51,6 +51,7 @@ #ifdef HAVE_MDNS xinetd_mdns_init(); #endif + init_services() ; /* Do the chdir after reading the config file. Relative path names @@ -80,7 +81,10 @@ #ifdef HAVE_DNSREGISTRATION "rendezvous " #endif -#if !defined(LIBWRAP) && !defined(HAVE_LOADAVG) && !defined(HAVE_MDNS) && !defined(HAVE_HOWL) && !defined(HAVE_DNSREGISTRATION) +#ifdef HAVE_BONJOUR + "bonjour " +#endif +#if !defined(LIBWRAP) && !defined(HAVE_LOADAVG) && !defined(HAVE_MDNS) && !defined(HAVE_HOWL) && !defined(HAVE_DNSREGISTRATION) && !defined(HAVE_BONJOUR) "no " #endif "options compiled in." @@ -126,6 +130,7 @@ for ( ;; ) { fd_set read_mask ; + int n_active ; unsigned u ; @@ -168,12 +173,18 @@ continue ; } -#ifdef HAVE_MDNS - if( xinetd_mdns_poll() == 0 ) +#if defined(HAVE_MDNS) && defined(HAVE_HOWL) + if( xinetd_mdns_poll(&read_mask) == 0 ) /* can pass any value as its ignored by howl*/ if ( --n_active == 0 ) continue ; #endif +#if HAVE_BONJOUR + n_active-=xinetd_mdns_poll(&read_mask); /* poll fds */ + if ( n_active == 0 ) + continue; +#endif + for ( u = 0 ; u < pset_count( SERVICES( ps ) ) ; u++ ) { struct service *sp ; @@ -260,10 +271,10 @@ const char *func = "quit_program" ; destroy_global_access_list() ; - + for ( u = 0 ; u < pset_count( SERVICES( ps ) ) ; u++ ) { scp = SVC_CONF( SP(pset_pointer(SERVICES(ps), u)) ); - + /* This is essentially the same as the following function, * Except we forcibly deactivate them, rather than just * send signals. @@ -309,3 +320,4 @@ quit_program() ; } +/* kate: space-indent on; indent-width 3; mixed-indent off; indent-mode cstyle; folding-markers on; line-numbers off; */ --- prj/xinetd/xinetd/sconf.h:1.1.1.2 Wed Oct 5 19:15:33 2005 +++ prj/xinetd/xinetd/sconf.h Thu Mar 16 00:02:45 2006 @@ -33,6 +33,10 @@ #include "builtins.h" #include "attr.h" +#ifdef HAVE_BONJOUR +#include +#endif + /* * Service types */ @@ -150,10 +154,14 @@ 0: never X: X minutes */ #ifdef HAVE_MDNS - char *sc_mdns_name; - boolean_e sc_mdns; - void *mdns_state; + char *sc_mdns_name; /* name to publish */ + boolean_e sc_mdns; /* enable/disable publication */ + void *mdns_state; /* state information when HAVE_DNSREGISTRATION */ #endif +#ifdef HAVE_BONJOUR + DNSServiceRef sc_dnssdRef; /* registration reference */ +#endif + #ifdef LIBWRAP char *sc_libwrap; #endif @@ -216,6 +224,7 @@ #define SC_DENY_TIME( scp ) (scp)->sc_deny_time #define SC_MDNS_NAME( scp ) (scp)->sc_mdns_name #define SC_MDNS( scp ) (scp)->sc_mdns +#define SC_BONJOUR_REF( scp ) (scp)->sc_dnssdRef #define SC_PER_SOURCE( scp ) (scp)->sc_per_source #define SC_LIBWRAP( scp ) (scp)->sc_libwrap /* --- prj/xinetd/xinetd/state.h:1.1.1.2 Thu Mar 31 01:15:28 2005 +++ prj/xinetd/xinetd/state.h Thu Mar 16 00:02:45 2006 @@ -89,3 +89,4 @@ #endif /* STATE_H */ +/* kate: space-indent on; indent-width 3; mixed-indent off; indent-mode cstyle; folding-markers on; line-numbers off; */ --- prj/xinetd/xinetd/xinetd.conf.man:1.1.1.2 Wed Oct 5 19:15:33 2005 +++ prj/xinetd/xinetd/xinetd.conf.man Thu Mar 16 00:02:45 2006 @@ -518,8 +518,8 @@ .TP .B mdns Takes either "yes" or "no". On systems that support mdns registration -of services (currently only Mac OS X), this will enable or disable -registration of the service. This defaults to "yes". +of services (Mac OS X, or system with either Howl or Bonjour), this will +enable or disable registration of the service. This defaults to "yes". .TP .B umask Sets the inherited umask for the service. Expects an octal value. --- prj/xinetd/xinetd/xmdns.c:1.1.1.1 Fri Apr 8 23:23:07 2005 +++ prj/xinetd/xinetd/xmdns.c Thu Mar 16 00:02:45 2006 @@ -18,6 +18,10 @@ #include #endif +#ifdef HAVE_BONJOUR +#include +#endif + extern struct program_state ps ; #ifdef HAVE_DNSREGISTRATION @@ -49,9 +53,25 @@ } #endif +#ifdef HAVE_BONJOUR +static void MyRegisterCallback(DNSServiceRef service, DNSServiceFlags flags, DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain, void *context) { + if (errorCode != kDNSServiceErr_NoError) { + if (debug.on) + msg(LOG_DEBUG, "bonjour_callback", "Error (%d) for service %s.%s%s (%s) registration via Bonjour", errorCode, name, regtype, domain, context==NULL ? "?" : (char*)context); + } + else + msg(LOG_NOTICE, "bonjour_callback", "Service %s.%s%s (%s) registered via Bonjour", name, regtype, domain, context==NULL ? "?" : (char*)context); +} +#endif + int xinetd_mdns_deregister(struct service_config *scp) { +#ifdef HAVE_BONJOUR + if( (!scp) || ( SC_BONJOUR_REF(scp) == NULL) ) + return 0; +#else if( (!scp) || (scp->mdns_state == NULL) ) return 0; +#endif if( debug.on ) msg(LOG_DEBUG, "xinetd_mdns_deregister", "Deregistering service: %s", SC_ID(scp)); @@ -67,13 +87,26 @@ return -1; return 0; #endif + +#ifdef HAVE_BONJOUR + msg(LOG_NOTICE, "xinetd_mdns_deregister", "Deregistering service: %s %d (%s) via Bonjour", SC_MDNS_NAME(scp), SC_PORT(scp), SC_ID(scp)); + DNSServiceRefDeallocate(SC_BONJOUR_REF(scp)); + FD_CLR(DNSServiceRefSockFD(SC_BONJOUR_REF(scp)), &ps.rws.socket_mask); + scp->mdns_state=NULL; + return 0; +#endif } int xinetd_mdns_register(struct service_config *scp) { - if( ps.rws.mdns_state == NULL ) +#ifdef HAVE_BONJOUR + DNSServiceErrorType error; +#endif + +if( ps.rws.mdns_state == NULL ) return -1; xinetd_mdns_deregister(scp); + /* construct regtype */ if( SC_MDNS_NAME(scp) ) free(SC_MDNS_NAME(scp)); if( asprintf(&SC_MDNS_NAME(scp), "_%s._%s", SC_NAME(scp), SC_PROTONAME(scp)) < 0 ) @@ -88,14 +121,47 @@ #ifdef HAVE_HOWL sw_discovery_publish(*(sw_discovery *)ps.rws.mdns_state, 0, SC_ID(scp), SC_MDNS_NAME(scp), NULL, NULL, SC_PORT(scp), NULL, 0, howl_callback, NULL, (sw_discovery_oid *)scp->mdns_state); - return 0; #endif +#ifdef HAVE_BONJOUR + error=DNSServiceRegister( + &SC_BONJOUR_REF(scp), + 0, + 0, /* all interfaces */ + "", /* name */ + SC_MDNS_NAME(scp), /* type */ + "", /* default domain */ + NULL, /* default host */ + htons(SC_PORT(scp)), + 0, + NULL, + MyRegisterCallback, + SC_ID(scp) + ); + if (error != kDNSServiceErr_NoError) + { + if (debug.on) + msg(LOG_DEBUG, "xinetd_mdns_register", "Registering service %s %d (%s) FAILED error=%d", SC_MDNS_NAME(scp), SC_PORT(scp), SC_ID(scp), error); + } + else + { + msg(LOG_NOTICE, "xinetd_mdns_register", "Registering service %s %d (%s) via Bonjour", SC_MDNS_NAME(scp), SC_PORT(scp), SC_ID(scp)); + FD_SET(DNSServiceRefSockFD(SC_BONJOUR_REF(scp)), &ps.rws.socket_mask ); + /* ensure that ps.rws.mask_max is bumped to the higest possible value */ + if (DNSServiceRefSockFD(SC_BONJOUR_REF(scp)) > ps.rws.mask_max) + ps.rws.mask_max= DNSServiceRefSockFD(SC_BONJOUR_REF(scp)); + + } + /* return error; */ +#endif return 0; } +/* initialization */ int xinetd_mdns_init(void) { -#ifdef HAVE_DNSREGISTRATION +#if defined(HAVE_DNSREGISTRATION) || defined (HAVE_BONJOUR) + if ( debug.on ) + msg(LOG_DEBUG, "xinetd_mdns_init", "Setting ps.rws.mdns_state to non-NULL value"); ps.rws.mdns_state = (char *)1; return 0; #endif @@ -114,6 +180,12 @@ #endif } +/* called just before the app is quitting, so do housekeeping now */ +void xinetd_mdns_quit(void) +{ + /* nothing to do */ +} + int xinetd_mdns_svc_init(struct service_config *scp) { #ifdef HAVE_DNSREGISTRATION // scp->mdns_state = malloc(sizeof(dns_service_discovery_ref)); @@ -122,7 +194,6 @@ #ifdef HAVE_HOWL scp->mdns_state = malloc(sizeof(sw_discovery_oid)); #endif - if( !scp->mdns_state ) return -1; return 0; @@ -137,11 +208,44 @@ return 0; } -int xinetd_mdns_poll(void) { +int xinetd_mdns_poll(fd_set* fds) { #ifdef HAVE_HOWL if( sw_discovery_read_socket(*(sw_discovery *)ps.rws.mdns_state) == SW_OKAY ) return 0; + else + return -1; +#endif + +#ifdef HAVE_BONJOUR + DNSServiceErrorType error; + unsigned u; + int nDid = 0; + for ( u = 0 ; u < pset_count( SERVICES( ps ) ) ; u++ ) { + struct service *sp; + struct service_config *scp; + + sp = SP( pset_pointer( SERVICES( ps ), u ) ) ; + scp = SVC_CONF(sp); + + if (FD_ISSET(DNSServiceRefSockFD(SC_BONJOUR_REF(scp)), fds)) + { + error=DNSServiceProcessResult(SC_BONJOUR_REF(scp)); + if (error != kDNSServiceErr_NoError) + { + if ( debug.on ) + msg(LOG_DEBUG, "xinetd_mdns_poll", "Bonjour ServiceProcessResult FAILED error=%d", error); + } + else + { + if ( debug.on ) + msg(LOG_DEBUG, "xinetd_mdns_poll", "Bonjour ServiceProcessResult OK"); + nDid++; /* processed */ + } + } + } + return nDid; #endif - return -1; } #endif /* HAVE_MDNS */ + +/* kate: space-indent on; indent-width 3; mixed-indent off; indent-mode cstyle; folding-markers on; line-numbers off; */ --- prj/xinetd/xinetd/xmdns.h:1.1.1.1 Thu Mar 31 01:15:52 2005 +++ prj/xinetd/xinetd/xmdns.h Thu Mar 16 00:02:45 2006 @@ -5,8 +5,9 @@ int xinetd_mdns_deregister(struct service_config *scp) ; int xinetd_mdns_register(struct service_config *scp) ; int xinetd_mdns_init(void) ; +int xinetd_mdns_term(void) ; int xinetd_mdns_svc_init(struct service_config *scp) ; int xinetd_mdns_svc_free(struct service_config *scp) ; -int xinetd_mdns_poll(void) ; +int xinetd_mdns_poll(fd_set *fds) ; #endif /* _XMDNS_H_ */