p_sys->i_timeout = config_GetInt( p_sd,"sap-timeout" );
vlc_current_charset( &psz_charset );
- p_sys->iconvHandle = vlc_iconv_open( psz_charset, "UTF-8");
+ p_sys->iconvHandle = vlc_iconv_open( psz_charset, "UTF-8" );
free( psz_charset );
if( p_sys->iconvHandle == (vlc_iconv_t)(-1) )
{
char *psz_value;
sap_announce_t *p_sap = (sap_announce_t *)malloc(
sizeof(sap_announce_t ) );
- if( !p_sap )
+
+ psz_value = convert_from_utf8( p_sd, p_sdp->psz_sessionname );
+ if( p_sap == NULL || psz_value == NULL )
{
msg_Err( p_sd, "out of memory");
+ FREE( p_sap );
+ FREE( psz_value );
p_sd->b_die = VLC_TRUE;
return NULL;
}
p_sap->p_item = NULL;
/* Create the playlist item here */
- psz_value = convert_from_utf8( p_sd, p_sap->p_sdp->psz_sessionname );
p_item = playlist_ItemNew( p_sd, p_sap->p_sdp->psz_uri, psz_value );
- FREE( psz_value );
+ free( psz_value );
if( !p_item )
{
if( psz_value != NULL )
{
char *psz_grp = convert_from_utf8( p_sd, psz_value );
- free( psz_value );
- p_child = playlist_ChildSearchName( p_sd->p_sys->p_node, psz_grp );
+ if( psz_grp != NULL )
+ {
+ p_child = playlist_ChildSearchName( p_sd->p_sys->p_node,
+ psz_grp );
- if( p_child == NULL )
+ if( p_child == NULL )
+ p_child = playlist_NodeCreate( p_playlist, VIEW_CATEGORY,
+ psz_grp, p_sd->p_sys->p_node );
+ free( psz_grp );
+ }
+ else
{
- p_child = playlist_NodeCreate( p_playlist, VIEW_CATEGORY,
- psz_grp, p_sd->p_sys->p_node );
+ vlc_object_release( p_playlist );
+ msg_Err( p_sd, "out of memory");
+ free( p_sap );
+ return NULL;
}
- free( psz_grp );
}
else
{
#include <vlc/sout.h>
#include <network.h>
+#include "charset.h"
#define SAP_IPV4_ADDR "224.2.127.254" /* Standard port and address for SAP */
#define SAP_PORT 9875
static int announce_SAPAnnounceDel( sap_handler_t *p_sap,
session_descriptor_t *p_session );
+static char *convert_to_utf8( struct sap_handler_t *p_this, char *psz_local );
#define FREE( p ) if( p ) { free( p ); (p) = NULL; }
sap_handler_t *announce_SAPHandlerCreate( announce_handler_t *p_announce )
{
sap_handler_t *p_sap;
+ char *psz_charset;
p_sap = vlc_object_create( p_announce, sizeof( sap_handler_t ) );
vlc_mutex_init( p_sap, &p_sap->object_lock );
+ vlc_current_charset( &psz_charset );
+ p_sap->iconvHandle = vlc_iconv_open( "UTF-8", psz_charset );
+ free( psz_charset );
+ if( p_sap->iconvHandle == (vlc_iconv_t)(-1) )
+ {
+ msg_Warn( p_sap, "Unable to do requested conversion" );
+ }
+
p_sap->pf_add = announce_SAPAnnounceAdd;
p_sap->pf_del = announce_SAPAnnounceDel;
FREE( p_address );
}
+ if( p_sap->iconvHandle != (vlc_iconv_t)(-1) )
+ vlc_iconv_close( p_sap->iconvHandle );
+
/* Free the structure */
vlc_object_destroy( p_sap );
}
{
int64_t i_sdp_id = mdate();
int i_sdp_version = 1 + p_sap->i_sessions + (rand()&0xfff);
+ char *psz_group, *psz_name;
+
+ psz_group = convert_to_utf8( p_sap, p_session->psz_group );
+ psz_name = convert_to_utf8( p_sap, p_session->psz_name );
/* see the lists in modules/stream_out/rtp.c for compliance stuff */
p_session->psz_sdp = (char *)malloc(
"m=video udp\r\n"
"a=tool:"PACKAGE_STRING"\r\n"
"a=type:broadcast\r\n")
- + strlen( p_session->psz_name )
+ + strlen( psz_name )
+ strlen( p_session->psz_uri ) + 300
- + ( p_session->psz_group ?
- strlen( p_session->psz_group ) : 0 ) );
+ + ( psz_group ? strlen( psz_group ) : 0 ) );
- if( !p_session->psz_sdp )
+ if( p_session->psz_sdp == NULL || psz_name == NULL )
{
msg_Err( p_sap, "out of memory" );
+ FREE( psz_name );
+ FREE( psz_group );
return VLC_ENOMEM;
}
sprintf( p_session->psz_sdp,
"a=tool:"PACKAGE_STRING"\r\n"
"a=type:broadcast\r\n",
i_sdp_id, i_sdp_version,
- p_session->psz_name,
+ psz_name,
p_session->psz_uri, p_session->i_ttl,
p_session->i_port, p_session->i_payload );
+ free( psz_name );
- if( p_session->psz_group )
+ if( psz_group )
{
sprintf( p_session->psz_sdp, "%sa=x-plgroup:%s\r\n",
- p_session->psz_sdp,
- p_session->psz_group );
+ p_session->psz_sdp, psz_group );
+ free( psz_group );
}
msg_Dbg( p_sap, "Generated SDP (%i bytes):\n%s", strlen(p_session->psz_sdp),
return VLC_SUCCESS;
}
+
+
+static char *convert_to_utf8( struct sap_handler_t *p_this, char *psz_local )
+{
+ char *psz_unicode, *psz_in, *psz_out;
+ size_t ret, i_in, i_out;
+
+ if( psz_local == NULL )
+ return NULL;
+ if ( p_this->iconvHandle == (vlc_iconv_t)(-1) )
+ return strdup( psz_local );
+
+ psz_in = psz_local;
+ i_in = strlen( psz_local );
+
+ i_out = 6 * i_in;
+ psz_unicode = malloc( i_out + 1 );
+ if( psz_unicode == NULL )
+ return strdup( psz_local );
+ psz_out = psz_unicode;
+
+ ret = vlc_iconv( p_this->iconvHandle,
+ &psz_in, &i_in, &psz_out, &i_out);
+ if( ret == (size_t)(-1) || i_in )
+ {
+ msg_Warn( p_this, "Failed to convert \"%s\" to UTF-8", psz_local );
+ return strdup( psz_local );
+ }
+ *psz_out = '\0';
+ return psz_unicode;
+}