+} slap_daemon;
+
+
+
+#ifdef HAVE_SLP
+/*
+ * SLP related functions
+ */
+#include <slp.h>
+
+#define LDAP_SRVTYPE_PREFIX "service:ldap://"
+#define LDAPS_SRVTYPE_PREFIX "service:ldaps://"
+static char** slapd_srvurls = NULL;
+static SLPHandle slapd_hslp = 0;
+
+void slapd_slp_init( const char* urls ) {
+ int i;
+
+ slapd_srvurls = str2charray( urls, " " );
+
+ if( slapd_srvurls == NULL ) return;
+
+ /* find and expand INADDR_ANY URLs */
+ for( i=0; slapd_srvurls[i] != NULL; i++ ) {
+ if( strcmp( slapd_srvurls[i], "ldap:///" ) == 0) {
+ char *host = ldap_pvt_get_fqdn( NULL );
+ if ( host != NULL ) {
+ slapd_srvurls[i] = (char *) realloc( slapd_srvurls[i],
+ strlen( host ) +
+ sizeof( LDAP_SRVTYPE_PREFIX ) );
+ strcpy( slap_strcopy(slapd_srvurls[i],
+ LDAP_SRVTYPE_PREFIX ), host );
+
+ ch_free( host );
+ }
+
+ } else if ( strcmp( slapd_srvurls[i], "ldaps:///" ) == 0) {
+ char *host = ldap_pvt_get_fqdn( NULL );
+ if ( host != NULL ) {
+ slapd_srvurls[i] = (char *) realloc( slapd_srvurls[i],
+ strlen( host ) +
+ sizeof( LDAPS_SRVTYPE_PREFIX ) );
+ strcpy( slap_strcopy(slapd_srvurls[i],
+ LDAPS_SRVTYPE_PREFIX ), host );
+
+ ch_free( host );
+ }
+ }
+ }
+
+ /* open the SLP handle */
+ SLPOpen( "en", 0, &slapd_hslp );
+}
+
+void slapd_slp_deinit() {
+ if( slapd_srvurls == NULL ) return;
+
+ charray_free( slapd_srvurls );
+ slapd_srvurls = NULL;
+
+ /* close the SLP handle */
+ SLPClose( slapd_hslp );
+}
+
+void slapd_slp_regreport(
+ SLPHandle hslp,
+ SLPError errcode,
+ void* cookie )
+{
+ /* empty report */
+}
+
+void slapd_slp_reg() {
+ int i;
+
+ for( i=0; slapd_srvurls[i] != NULL; i++ ) {
+ if( strncmp( slapd_srvurls[i], LDAP_SRVTYPE_PREFIX,
+ sizeof( LDAP_SRVTYPE_PREFIX ) - 1 ) == 0 ||
+ strncmp( slapd_srvurls[i], LDAPS_SRVTYPE_PREFIX,
+ sizeof( LDAPS_SRVTYPE_PREFIX ) - 1 ) == 0 )
+ {
+ SLPReg( slapd_hslp,
+ slapd_srvurls[i],
+ SLP_LIFETIME_MAXIMUM,
+ "ldap",
+ "",
+ 1,
+ slapd_slp_regreport,
+ NULL );
+ }
+ }
+}
+
+void slapd_slp_dereg() {
+ int i;
+
+ for( i=0; slapd_srvurls[i] != NULL; i++ ) {
+ SLPDereg( slapd_hslp,
+ slapd_srvurls[i],
+ slapd_slp_regreport,
+ NULL );
+ }
+}
+#endif /* HAVE_SLP */