Commit e23ba242 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

* convert SAP announce name & group from locale to UTF-8

* fix bug in previous SAP commit
parent 65484e2a
......@@ -322,6 +322,9 @@ struct sap_handler_t
int (*pf_add) ( sap_handler_t*, session_descriptor_t *,announce_method_t*);
int (*pf_del) ( sap_handler_t*, session_descriptor_t *);
/* private data, not in p_sys as there is one kind of sap_handler_t */
vlc_iconv_t iconvHandle;
};
/* The main announce handler object */
......
......@@ -274,7 +274,7 @@ static int Open( vlc_object_t *p_this )
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) )
{
......@@ -812,9 +812,13 @@ sap_announce_t *CreateAnnounce( services_discovery_t *p_sd, uint16_t i_hash,
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;
}
......@@ -824,9 +828,8 @@ sap_announce_t *CreateAnnounce( services_discovery_t *p_sd, uint16_t i_hash,
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 )
{
......@@ -853,16 +856,24 @@ sap_announce_t *CreateAnnounce( services_discovery_t *p_sd, uint16_t i_hash,
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
{
......
......@@ -32,6 +32,7 @@
#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
......@@ -62,6 +63,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
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; }
......@@ -75,6 +77,7 @@ static int announce_SAPAnnounceDel( sap_handler_t *p_sap,
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 ) );
......@@ -86,6 +89,14 @@ sap_handler_t *announce_SAPHandlerCreate( announce_handler_t *p_announce )
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;
......@@ -144,6 +155,9 @@ void announce_SAPHandlerDestroy( sap_handler_t *p_sap )
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 );
}
......@@ -478,6 +492,10 @@ static int SDPGenerate( sap_handler_t *p_sap, session_descriptor_t *p_session )
{
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(
......@@ -489,14 +507,15 @@ static int SDPGenerate( sap_handler_t *p_sap, session_descriptor_t *p_session )
"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,
......@@ -509,15 +528,16 @@ static int SDPGenerate( sap_handler_t *p_sap, session_descriptor_t *p_session )
"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),
......@@ -582,3 +602,34 @@ static int CalculateRate( sap_handler_t *p_sap, sap_address_t *p_address )
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;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment