00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdlib.h>
00028
00029 #include <errno.h>
00030 #include <stdio.h>
00031
00032 #include <vlc/vlc.h>
00033 #include <vlc/sout.h>
00034
00035 #ifdef HAVE_UNISTD_H
00036 # include <unistd.h>
00037 #endif
00038
00039 #ifdef WIN32
00040 # include <winsock2.h>
00041 # include <ws2tcpip.h>
00042 # ifndef IN_MULTICAST
00043 # define IN_MULTICAST(a) IN_CLASSD(a)
00044 # endif
00045 #else
00046 # include <sys/socket.h>
00047 #endif
00048
00049 #ifdef HAVE_SLP_H
00050 # include <slp.h>
00051 #endif
00052
00053 #include "announce.h"
00054 #include "network.h"
00055
00056 #define DEFAULT_PORT 1234
00057
00058 #ifdef HAVE_SLP_H
00059
00060
00061
00062 static char * sout_SLPBuildName(char *psz_url,char *psz_name)
00063 {
00064 char *psz_service;
00065 unsigned int i_size;
00066
00067
00068
00069 i_size = 8 + 12 + 12 + 5 + strlen(psz_url) + 1;
00070
00071 psz_service=(char *)malloc(i_size * sizeof(char));
00072
00073 snprintf( psz_service , i_size,
00074 "service:vlc.services.videolan://udp:@%s",
00075 psz_url);
00076
00077
00078 psz_service[i_size]='\0';
00079
00080 return psz_service;
00081
00082 }
00083
00084
00085
00086
00087 static void sout_SLPReport(SLPHandle slp_handle,SLPError slp_error,void* cookie)
00088 {
00089 }
00090 #endif
00091
00092
00093
00094
00095 int sout_SLPReg( sout_instance_t *p_sout, char * psz_url,
00096 char * psz_name)
00097 {
00098 #ifdef HAVE_SLP_H
00099 SLPHandle slp_handle;
00100 SLPError slp_res;
00101 char *psz_service= sout_SLPBuildName(psz_url,psz_name);
00102
00103 if( SLPOpen( NULL, SLP_FALSE, &slp_handle ) != SLP_OK)
00104 {
00105 msg_Warn(p_sout,"Unable to initialize SLP");
00106 return -1;
00107 }
00108
00109 msg_Info(p_sout , "Registering %s (name: %s) in SLP",
00110 psz_service , psz_name);
00111
00112 slp_res = SLPReg ( slp_handle,
00113 psz_service,
00114 SLP_LIFETIME_MAXIMUM,
00115 NULL,
00116 psz_name,
00117 SLP_TRUE,
00118 sout_SLPReport,
00119 NULL );
00120
00121 if( slp_res != SLP_OK )
00122 {
00123 msg_Warn(p_sout,"Error while registering service: %i", slp_res );
00124 return -1;
00125 }
00126
00127 return 0;
00128
00129 #else
00130 return -1;
00131 #endif
00132 }
00133
00134
00135
00136
00137
00138 int sout_SLPDereg( sout_instance_t *p_sout, char * psz_url,
00139 char * psz_name)
00140 {
00141 #ifdef HAVE_SLP_H
00142
00143 SLPHandle slp_handle;
00144 SLPError slp_res;
00145 char *psz_service= sout_SLPBuildName(psz_url,psz_name);
00146
00147 if( SLPOpen( NULL, SLP_FALSE, &slp_handle ) != SLP_OK)
00148 {
00149 msg_Warn(p_sout,"Unable to initialize SLP");
00150 return -1;
00151 }
00152
00153 msg_Info(p_sout , "Unregistering %s from SLP",
00154 psz_service);
00155
00156 slp_res = SLPDereg ( slp_handle,
00157 psz_service,
00158 sout_SLPReport,
00159 NULL );
00160
00161 if( slp_res != SLP_OK )
00162 {
00163 msg_Warn(p_sout,"Error while registering service: %i", slp_res );
00164 return -1;
00165 }
00166
00167 return 0;
00168
00169 #else
00170 return -1;
00171 #endif
00172 }