Commit 97a8984f authored by Derk-Jan Hartman's avatar Derk-Jan Hartman

* Patch to reenable sap-timeout functionality (Bug 2007) By Dermot McGahon,...

* Patch to reenable sap-timeout functionality (Bug 2007) By Dermot McGahon, dermot at lincor dot com
  Modified by me.
* also restored some indentation of this file.
parent 7a5f6a89
/***************************************************************************** /*****************************************************************************
* sap.c : SAP interface module * sap.c : SAP interface module
***************************************************************************** *****************************************************************************
* Copyright (C) 2004 VideoLAN * Copyright (C) 2004-2005 VideoLAN
* $Id$ * $Id$
* *
* Authors: Clment Stenac <zorglub@videolan.org> * Authors: Clment Stenac <zorglub@videolan.org>
...@@ -272,7 +272,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -272,7 +272,7 @@ static int Open( vlc_object_t *p_this )
char *psz_addr, *psz_charset; char *psz_addr, *psz_charset;
vlc_value_t val; vlc_value_t val;
p_sys->i_timeout = config_GetInt( p_sd,"sap-timeout" ); p_sys->i_timeout = var_CreateGetInteger( p_sd, "sap-timeout" );
vlc_current_charset( &psz_charset ); 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" );
...@@ -288,24 +288,24 @@ static int Open( vlc_object_t *p_this ) ...@@ -288,24 +288,24 @@ static int Open( vlc_object_t *p_this )
p_sys->pi_fd = NULL; p_sys->pi_fd = NULL;
p_sys->i_fd = 0; p_sys->i_fd = 0;
p_sys->b_strict = config_GetInt( p_sd, "sap-strict"); p_sys->b_strict = var_CreateGetInteger( p_sd, "sap-strict");
p_sys->b_parse = config_GetInt( p_sd, "sap-parse" ); p_sys->b_parse = var_CreateGetInteger( p_sd, "sap-parse" );
if( config_GetInt( p_sd, "sap-cache" ) ) if( var_CreateGetInteger( p_sd, "sap-cache" ) )
{ {
CacheLoad( p_sd ); CacheLoad( p_sd );
} }
if( config_GetInt( p_sd, "sap-ipv4" ) ) if( var_CreateGetInteger( p_sd, "sap-ipv4" ) )
{ {
InitSocket( p_sd, SAP_V4_ADDRESS, SAP_PORT ); InitSocket( p_sd, SAP_V4_ADDRESS, SAP_PORT );
} }
if( config_GetInt( p_sd, "sap-ipv6" ) ) if( var_CreateGetInteger( p_sd, "sap-ipv6" ) )
{ {
/* [ + 8x4+7*':' + ] */ /* [ + 8x4+7*':' + ] */
char psz_address[42]; char psz_address[42];
char c_scope; char c_scope;
char *psz_scope = config_GetPsz( p_sd, "sap-ipv6-scope" ); char *psz_scope = var_CreateGetString( p_sd, "sap-ipv6-scope" );
if( psz_scope == NULL || *psz_scope == '\0') if( psz_scope == NULL || *psz_scope == '\0')
{ {
...@@ -320,7 +320,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -320,7 +320,7 @@ static int Open( vlc_object_t *p_this )
InitSocket( p_sd, psz_address, SAP_PORT ); InitSocket( p_sd, psz_address, SAP_PORT );
} }
psz_addr = config_GetPsz( p_sd, "sap-addr" ); psz_addr = var_CreateGetString( p_sd, "sap-addr" );
if( psz_addr && *psz_addr ) if( psz_addr && *psz_addr )
{ {
InitSocket( p_sd, psz_addr, SAP_PORT ); InitSocket( p_sd, psz_addr, SAP_PORT );
...@@ -328,7 +328,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -328,7 +328,7 @@ static int Open( vlc_object_t *p_this )
if( p_sys->i_fd == 0 ) if( p_sys->i_fd == 0 )
{ {
msg_Err( p_sd, "unable to read on any address"); msg_Err( p_sd, "unable to read on any address" );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -504,10 +504,9 @@ static void CloseDemux( vlc_object_t *p_this ) ...@@ -504,10 +504,9 @@ static void CloseDemux( vlc_object_t *p_this )
static void Run( services_discovery_t *p_sd ) static void Run( services_discovery_t *p_sd )
{ {
int i;
uint8_t *p_buffer; uint8_t *p_buffer;
/* Dirty hack to slow down the startup of the sap interface */ playlist_t *p_playlist;
/* Unneeded now : our node is in no_select mode */
// msleep( 500000 );
/* read SAP packets */ /* read SAP packets */
while( !p_sd->b_die ) while( !p_sd->b_die )
...@@ -525,16 +524,19 @@ static void Run( services_discovery_t *p_sd ) ...@@ -525,16 +524,19 @@ static void Run( services_discovery_t *p_sd )
i_read = net_Select( p_sd, p_sd->p_sys->pi_fd, NULL, i_read = net_Select( p_sd, p_sd->p_sys->pi_fd, NULL,
p_sd->p_sys->i_fd, p_buffer, p_sd->p_sys->i_fd, p_buffer,
MAX_SAP_BUFFER, 500000 ); MAX_SAP_BUFFER, 500000 );
#if 0
/* Check for items that need deletion */ /* Check for items that need deletion */
for( i = 0 ; i< p_sd->p_sys->i_announces ; i++ ) for( i = 0; i < p_sd->p_sys->i_announces; i++ )
{ {
struct sap_announce_t *p_announce; mtime_t i_timeout = ( mtime_t ) 1000000 * p_sd->p_sys->i_timeout;
mtime_t i_timeout = ( mtime_t ) 1000000*p_sys->i_timeout;
if( mdate() - p_sd->p_sys->pp_announces[i]->i_last > i_timeout ) if( mdate() - p_sd->p_sys->pp_announces[i]->i_last > i_timeout )
{ {
msg_Dbg( p_sd,"Time out for %s, deleting (%i/%i)", struct sap_announce_t *p_announce;
p_sd->p_sys->pp_announces[i]->psz_name, p_announce = p_sd->p_sys->pp_announces[i];
msg_Dbg( p_sd, "Time out for %s, deleting (%i/%i)",
p_announce->p_item->input.psz_name,
i , p_sd->p_sys->i_announces ); i , p_sd->p_sys->i_announces );
/* Remove the playlist item */ /* Remove the playlist item */
...@@ -542,28 +544,17 @@ static void Run( services_discovery_t *p_sd ) ...@@ -542,28 +544,17 @@ static void Run( services_discovery_t *p_sd )
FIND_ANYWHERE ); FIND_ANYWHERE );
if( p_playlist ) if( p_playlist )
{ {
int i_pos = playlist_GetPositionById( p_playlist, playlist_Delete( p_playlist, p_announce->p_item->input.i_id );
p_sd->p_sys->pp_announces[i]->i_id );
playlist_Delete( p_playlist, i_pos );
vlc_object_release( p_playlist ); vlc_object_release( p_playlist );
} }
/* Free the p_announce */
p_announce = p_sd->p_sys->pp_announces[i];
if( p_announce->psz_name )
free( p_announce->psz_name );
if( p_announce->psz_uri )
free( p_announce->psz_uri );
/* Remove the sap_announce from the array */ /* Remove the sap_announce from the array */
REMOVE_ELEM( p_sd->p_sys->pp_announces, REMOVE_ELEM( p_sd->p_sys->pp_announces,
p_sd->p_sys->i_announces, i ); p_sd->p_sys->i_announces, i );
free( p_announce ); free( p_announce );
} }
} }
#endif
/* Minimum length is > 6 */ /* Minimum length is > 6 */
if( i_read <= 6 ) if( i_read <= 6 )
...@@ -677,7 +668,7 @@ static int ParseSAP( services_discovery_t *p_sd, uint8_t *p_buffer, int i_read ) ...@@ -677,7 +668,7 @@ static int ParseSAP( services_discovery_t *p_sd, uint8_t *p_buffer, int i_read )
psz_sdp += 4; psz_sdp += 4;
if( i_read <= 9 ) if( i_read <= 9 )
{ {
msg_Warn( p_sd,"too short SAP packet\n" ); msg_Warn( p_sd, "too short SAP packet\n" );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
} }
...@@ -686,7 +677,7 @@ static int ParseSAP( services_discovery_t *p_sd, uint8_t *p_buffer, int i_read ) ...@@ -686,7 +677,7 @@ static int ParseSAP( services_discovery_t *p_sd, uint8_t *p_buffer, int i_read )
psz_sdp += 16; psz_sdp += 16;
if( i_read <= 21 ) if( i_read <= 21 )
{ {
msg_Warn( p_sd,"too short SAP packet\n" ); msg_Warn( p_sd, "too short SAP packet\n" );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
} }
...@@ -873,11 +864,13 @@ sap_announce_t *CreateAnnounce( services_discovery_t *p_sd, uint16_t i_hash, ...@@ -873,11 +864,13 @@ sap_announce_t *CreateAnnounce( services_discovery_t *p_sd, uint16_t i_hash,
p_child = playlist_NodeCreate( p_playlist, VIEW_CATEGORY, p_child = playlist_NodeCreate( p_playlist, VIEW_CATEGORY,
psz_grp, p_sd->p_sys->p_node ); psz_grp, p_sd->p_sys->p_node );
free( psz_grp ); free( psz_grp );
free( psz_value );
} }
else else
{ {
vlc_object_release( p_playlist ); vlc_object_release( p_playlist );
msg_Err( p_sd, "out of memory"); msg_Err( p_sd, "out of memory");
free( psz_value );
free( p_sap ); free( p_sap );
return NULL; return NULL;
} }
...@@ -1060,7 +1053,7 @@ static int ParseConnection( vlc_object_t *p_obj, sdp_t *p_sdp ) ...@@ -1060,7 +1053,7 @@ static int ParseConnection( vlc_object_t *p_obj, sdp_t *p_sdp )
free( psz_proto ); free( psz_proto );
psz_proto = strdup( "rtp" ); psz_proto = strdup( "rtp" );
} }
if( psz_proto && !strncmp( psz_proto, "UDP", 3 ) ) if( psz_proto && !strncasecmp( psz_proto, "UDP", 3 ) )
{ {
free( psz_proto ); free( psz_proto );
psz_proto = strdup( "udp" ); psz_proto = strdup( "udp" );
......
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