Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

announce.c

00001 /*****************************************************************************
00002  * announce.c : Session announcement
00003  *****************************************************************************
00004  * Copyright (C) 2002 the VideoLAN team
00005  *
00006  * Authors: Clément Stenac <[email protected]>
00007  *          Damien Lucas <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>                                                /* free() */
00028 
00029 #include <errno.h>                                                 /* ENOMEM */
00030 #include <stdio.h>                                              /* sprintf() */
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  * sout_SLPBuildName: Builds a service name according to SLP standard
00061  *****************************************************************************/
00062 static char * sout_SLPBuildName(char *psz_url,char *psz_name)
00063 {
00064     char *psz_service;
00065     unsigned int i_size;
00066 
00067     /* name to build is: service:vlc.services.videolan://$(url) */
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         /* How piggy  ! */
00077 
00078     psz_service[i_size]='\0'; /* Just to make sure */
00079 
00080     return psz_service;
00081 
00082 }
00083 
00084 /*****************************************************************************
00085  * sout_SLPReport: Reporting function. Unused at the moment but needed
00086  *****************************************************************************/
00087 static void sout_SLPReport(SLPHandle slp_handle,SLPError slp_error,void* cookie)
00088 {
00089 }
00090 #endif
00091 
00092 /*****************************************************************************
00093  * sout_SLPReg: Registers the program with SLP
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 /* This function should never be called if this is false */
00130     return -1;
00131 #endif
00132 }
00133 
00134 
00135 /*****************************************************************************
00136  * sout_SLDePReg: Unregisters the program from SLP
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 /* This function should never be called if this is false */
00170     return -1;
00171 #endif
00172 }

Generated on Tue Dec 20 10:14:49 2005 for vlc-0.8.4a by  doxygen 1.4.2