# include <sys/socket.h>
#endif
+#ifdef HAVE_SLP_H
+# include <slp.h>
+#endif
+
#include "announce.h"
#include "network.h"
free( psz_head );
}
+
+
+/*****************************************************************************
+ * sout_SLPBuildName: Builds a service name according to SLP standard
+ *****************************************************************************/
+char * sout_SLPBuildName(char *psz_url,char *psz_name)
+{
+ char *psz_service;
+ unsigned int i_size;
+
+ /* name to build is: service:$(name).videolan://$(url) */
+
+ i_size = 8 + strlen(psz_name) + 12 + strlen(psz_url) + 1;
+
+ psz_service=(char *)malloc(i_size * sizeof(char));
+
+ snprintf( psz_service , i_size,
+ "service:%s.videolan://%s",
+ psz_name,psz_url);
+ psz_service[i_size]='\0'; /* Just to make sure */
+
+ return psz_service;
+
+}
+
+/*****************************************************************************
+ * sout_SLPReport: Reporting function. Unused at the moment but needed
+ *****************************************************************************/
+#ifdef HAVE_SLP_H
+void sout_SLPReport(SLPHandle slp_handle,SLPError slp_error,void* cookie)
+{
+}
+#endif
+
+/*****************************************************************************
+ * sout_SLPReg: Registers the program with SLP
+ *****************************************************************************/
+int sout_SLPReg( sout_instance_t *p_sout, char * psz_url,
+ char * psz_name)
+{
+#ifdef HAVE_SLP_H
+ SLPHandle slp_handle;
+ SLPError slp_res;
+ char *psz_service= sout_SLPBuildName(psz_url,psz_name);
+
+ if( SLPOpen( NULL, SLP_FALSE, &slp_handle ) != SLP_OK)
+ {
+ msg_Warn(p_sout,"Unable to initialize SLP");
+ return -1;
+ }
+
+ msg_Info(p_sout , "Registering %s (name: %s) in SLP",
+ psz_service , psz_name);
+
+ slp_res = SLPReg ( slp_handle,
+ psz_service,
+ SLP_LIFETIME_MAXIMUM,
+ NULL,
+ psz_name,
+ SLP_TRUE,
+ sout_SLPReport,
+ NULL );
+
+ if( slp_res != SLP_OK )
+ {
+ msg_Warn(p_sout,"Error while registering service: %i", slp_res );
+ return -1;
+ }
+
+ return 0;
+
+#else /* This function should never be called if this is false */
+ return -1
+#endif
+}
+
+
+/*****************************************************************************
+ * sout_SLDePReg: Unregisters the program from SLP
+ *****************************************************************************/
+int sout_SLPDereg( sout_instance_t *p_sout, char * psz_url,
+ char * psz_name)
+{
+#ifdef HAVE_SLP_H
+
+ SLPHandle slp_handle;
+ SLPError slp_res;
+ char *psz_service= sout_SLPBuildName(psz_url,psz_name);
+
+ if( SLPOpen( NULL, SLP_FALSE, &slp_handle ) != SLP_OK)
+ {
+ msg_Warn(p_sout,"Unable to initialize SLP");
+ return -1;
+ }
+
+ msg_Info(p_sout , "Unregistering %s from SLP",
+ psz_service);
+
+ slp_res = SLPDereg ( slp_handle,
+ psz_service,
+ sout_SLPReport,
+ NULL );
+
+ if( slp_res != SLP_OK )
+ {
+ msg_Warn(p_sout,"Error while registering service: %i", slp_res );
+ return -1;
+ }
+
+ return 0;
+
+#else /* This function should never be called if this is false */
+ return -1
+#endif
+}