Changeset 395cdfc1a82b88656241df8bc894d12d8995e63c

Show
Ignore:
Timestamp:
27/05/04 01:15:07 (5 years ago)
Author:
Derk-Jan Hartman <hartman@videolan.org>
git-committer:
Derk-Jan Hartman <hartman@videolan.org> 1085613307 +0000
git-parent:

[56bafe479173d1c136aebf949c177e4c51230679]

git-author:
Derk-Jan Hartman <hartman@videolan.org> 1085613307 +0000
Message:

* misc/sap.c: check for packetsize attribute and increase mtu when it's large.

  • some code cleanup. Please watch coding style people.

* demux/sgimb.c: fix an alloc

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/demux/sgimb.c

    r71e657c r395cdfc  
    329329    if( p_sys->i_packet_size && p_sys->psz_mcast_ip ) 
    330330    { 
    331         char *psz_option = (char *) malloc( 20 )
     331        char *psz_option
    332332        p_sys->i_packet_size += 1000; 
    333         sprintf( psz_option, "mtu=%i", p_sys->i_packet_size ); 
     333        asprintf( &psz_option, "mtu=%i", p_sys->i_packet_size ); 
    334334        playlist_ItemAddOption( p_item, psz_option ); 
    335335        free( psz_option ); 
  • modules/misc/sap.c

    rfdb4685 r395cdfc  
    8585 * Module descriptor 
    8686 *****************************************************************************/ 
    87 #define SAP_ADDR_TEXT N_("SAP multicast address"
    88 #define SAP_ADDR_LONGTEXT N_("SAP multicast address"
    89 #define SAP_IPV4_TEXT N_("IPv4-SAP listening"
     87#define SAP_ADDR_TEXT N_( "SAP multicast address"
     88#define SAP_ADDR_LONGTEXT N_( "SAP multicast address"
     89#define SAP_IPV4_TEXT N_( "IPv4-SAP listening"
    9090#define SAP_IPV4_LONGTEXT N_( \ 
    91       "Set this if you want the SAP module to listen to IPv4 announces"
    92 #define SAP_IPV6_TEXT N_( "IPv6-SAP listening"
    93 #define SAP_IPV6_LONGTEXT N_(
    94       "Set this if you want the SAP module to listen to IPv6 announces"
    95 #define SAP_SCOPE_TEXT N_("IPv6 SAP scope"
     91      "Set this if you want the SAP module to listen to IPv4 announces"
     92#define SAP_IPV6_TEXT N_( "IPv6-SAP listening"
     93#define SAP_IPV6_LONGTEXT N_(
     94      "Set this if you want the SAP module to listen to IPv6 announces"
     95#define SAP_SCOPE_TEXT N_( "IPv6 SAP scope"
    9696#define SAP_SCOPE_LONGTEXT N_( \ 
    97        "Sets the scope for IPv6 announces (default is 8)"
    98 #define SAP_TIMEOUT_TEXT N_("SAP timeout (seconds)"
     97       "Sets the scope for IPv6 announces (default is 8)"
     98#define SAP_TIMEOUT_TEXT N_( "SAP timeout (seconds)"
    9999#define SAP_TIMEOUT_LONGTEXT N_( \ 
    100100       "Sets the time before SAP items get deleted if no new announce " \ 
    101        "is received."
    102 #define SAP_PARSE_TEXT N_("Try to parse the SAP"
     101       "is received."
     102#define SAP_PARSE_TEXT N_( "Try to parse the SAP"
    103103#define SAP_PARSE_LONGTEXT N_( \ 
    104104       "When SAP can it will try to parse the SAP. Normal behavior is " \ 
     
    114114                SAP_ADDR_TEXT, SAP_ADDR_LONGTEXT, VLC_TRUE ); 
    115115    add_bool( "sap-ipv4", 1 , NULL, 
    116                SAP_IPV4_TEXT,SAP_IPV4_LONGTEXT, VLC_TRUE); 
     116               SAP_IPV4_TEXT,SAP_IPV4_LONGTEXT, VLC_TRUE ); 
    117117    add_bool( "sap-ipv6", 0 , NULL, 
    118               SAP_IPV6_TEXT, SAP_IPV6_LONGTEXT, VLC_TRUE); 
     118              SAP_IPV6_TEXT, SAP_IPV6_LONGTEXT, VLC_TRUE ); 
    119119    add_string( "sap-ipv6-scope", "8" , NULL, 
    120120                SAP_SCOPE_TEXT, SAP_SCOPE_LONGTEXT, VLC_TRUE); 
    121121    add_integer( "sap-timeout", 1800, NULL, 
    122                  SAP_TIMEOUT_TEXT, SAP_TIMEOUT_LONGTEXT, VLC_TRUE); 
     122                 SAP_TIMEOUT_TEXT, SAP_TIMEOUT_LONGTEXT, VLC_TRUE ); 
    123123    add_bool( "sap-parse", 1 , NULL, 
    124                SAP_PARSE_TEXT,SAP_PARSE_LONGTEXT, VLC_TRUE); 
     124               SAP_PARSE_TEXT,SAP_PARSE_LONGTEXT, VLC_TRUE ); 
    125125 
    126126    set_capability( "interface", 0 ); 
     
    198198 
    199199#ifdef HAVE_ZLIB_H 
    200 int do_decompress(unsigned char *src, unsigned char **_dst, int slen) { 
    201   int result, dstsize, n; 
    202   unsigned char *dst; 
    203   z_stream d_stream; 
    204  
    205   d_stream.zalloc = (alloc_func)0; 
    206   d_stream.zfree = (free_func)0; 
    207   d_stream.opaque = (voidpf)0; 
    208   result = inflateInit(&d_stream); 
    209   if (result != Z_OK) { 
    210     printf("inflateInit() failed. Result: %d\n", result); 
    211     return(-1); 
    212   } 
    213  
    214   d_stream.next_in = (Bytef *)src; 
    215   d_stream.avail_in = slen; 
    216   n = 0; 
    217   dst = NULL; 
    218   do { 
    219     n++; 
    220     dst = (unsigned char *)realloc(dst, n * 1000); 
    221     d_stream.next_out = (Bytef *)&dst[(n - 1) * 1000]; 
    222     d_stream.avail_out = 1000; 
    223     result = inflate(&d_stream, Z_NO_FLUSH); 
    224     if ((result != Z_OK) && (result != Z_STREAM_END)) { 
    225       printf("Zlib decompression failed. Result: %d\n", result); 
    226       return(-1); 
    227     } 
    228   } while ((d_stream.avail_out == 0) && (d_stream.avail_in != 0) && 
    229            (result != Z_STREAM_END)); 
    230  
    231   dstsize = d_stream.total_out; 
    232   inflateEnd(&d_stream); 
    233  
    234   *_dst = (unsigned char *)realloc(dst, dstsize); 
    235  
    236   return dstsize; 
     200int do_decompress( unsigned char *src, unsigned char **_dst, int slen ) { 
     201    int result, dstsize, n; 
     202    unsigned char *dst; 
     203    z_stream d_stream; 
     204 
     205    d_stream.zalloc = (alloc_func)0; 
     206    d_stream.zfree = (free_func)0; 
     207    d_stream.opaque = (voidpf)0; 
     208    result = inflateInit(&d_stream); 
     209    if( result != Z_OK ) 
     210    { 
     211        printf( "inflateInit() failed. Result: %d\n", result ); 
     212        return( -1 ); 
     213    } 
     214 
     215    d_stream.next_in = (Bytef *)src; 
     216    d_stream.avail_in = slen; 
     217    n = 0; 
     218    dst = NULL; 
     219    do 
     220    { 
     221        n++; 
     222        dst = (unsigned char *)realloc(dst, n * 1000); 
     223        d_stream.next_out = (Bytef *)&dst[(n - 1) * 1000]; 
     224        d_stream.avail_out = 1000; 
     225        result = inflate(&d_stream, Z_NO_FLUSH); 
     226        if( ( result != Z_OK ) && ( result != Z_STREAM_END ) ) 
     227        { 
     228            printf( "Zlib decompression failed. Result: %d\n", result ); 
     229            return( -1 ); 
     230        } 
     231    } 
     232    while( ( d_stream.avail_out == 0 ) && ( d_stream.avail_in != 0 ) && 
     233           ( result != Z_STREAM_END ) ); 
     234 
     235    dstsize = d_stream.total_out; 
     236    inflateEnd( &d_stream ); 
     237 
     238    *_dst = (unsigned char *)realloc( dst, dstsize ); 
     239 
     240    return dstsize; 
    237241} 
    238242#endif 
     
    243247static int Open( vlc_object_t *p_this ) 
    244248{ 
    245     intf_thread_t *p_intf = (intf_thread_t*)p_this; 
     249    intf_thread_t *p_intf = ( intf_thread_t* )p_this; 
    246250    intf_sys_t    *p_sys  = malloc( sizeof( intf_sys_t ) ); 
    247251 
    248252    playlist_t          *p_playlist; 
    249253 
    250     p_sys->i_timeout = config_GetInt(p_intf,"sap-timeout"); 
     254    p_sys->i_timeout = config_GetInt( p_intf,"sap-timeout" ); 
    251255    p_sys->fd[0] = -1; 
    252256    p_sys->fd[1] = -1; 
     
    268272        sock.i_server_port     = 0; 
    269273        sock.i_ttl             = 0; 
    270         p_intf->p_private = (void*) &sock; 
     274        p_intf->p_private = ( void* ) &sock; 
    271275 
    272276        p_network = module_Need( p_intf, "network", "ipv4", VLC_TRUE ); 
     
    348352static void Close( vlc_object_t *p_this ) 
    349353{ 
    350     intf_thread_t *p_intf = (intf_thread_t*)p_this; 
     354    intf_thread_t *p_intf = ( intf_thread_t* )p_this; 
    351355    intf_sys_t    *p_sys  = p_intf->p_sys; 
    352356    int i; 
     
    387391    uint8_t    *p_end; 
    388392     
    389     /* Dirty hack to slow down the startup of the sap interface*/  
    390     msleep(500000);     
     393    /* Dirty hack to slow down the startup of the sap interface */  
     394    msleep( 500000 ); 
    391395 
    392396    /* read SAP packets */ 
     
    410414        { 
    411415           struct sap_announce_t *p_announce; 
    412            mtime_t i_timeout = (mtime_t)1000000*p_sys->i_timeout; 
     416           mtime_t i_timeout = ( mtime_t ) 1000000*p_sys->i_timeout; 
    413417           if( mdate() - p_intf->p_sys->pp_announces[i]->i_last > i_timeout ) 
    414418           { 
    415                msg_Dbg(p_intf,"Time out for %s, deleting (%i/%i)", 
    416                        p_intf->p_sys->pp_announces[i]->psz_name, 
    417                        i , p_intf->p_sys->i_announces ); 
     419               msg_Dbg( p_intf,"Time out for %s, deleting (%i/%i)", 
     420                        p_intf->p_sys->pp_announces[i]->psz_name, 
     421                        i , p_intf->p_sys->i_announces ); 
    418422 
    419423               /* Remove the playlist item */ 
     
    463467        if( i_version != 1 ) 
    464468        { 
    465             msg_Warn( p_intf, "strange sap version %d found", i_version ); 
     469            msg_Dbg( p_intf, "strange sap version %d found", i_version ); 
    466470        } 
    467471        i_address_type = buffer[0] & 0x10; 
     
    469473        if( b_reserved != 0 ) 
    470474        { 
    471             msg_Warn( p_intf, "reserved bit incorrectly set" ); 
     475            msg_Dbg( p_intf, "reserved bit incorrectly set" ); 
    472476        } 
    473477        b_message_type = buffer[0] & 0x04; 
    474478        if( b_message_type != 0 ) 
    475479        { 
    476             msg_Warn( p_intf, "got session deletion packet" ); 
     480            msg_Dbg( p_intf, "got session deletion packet" ); 
    477481        } 
    478482        b_encrypted = buffer[0] & 0x02; 
    479483        if( b_encrypted ) 
    480484        { 
    481             msg_Warn( p_intf, "encrypted packet" ); 
     485            msg_Dbg( p_intf, "encrypted packet" ); 
    482486        } 
    483487        b_compressed = buffer[0] & 0x01; 
     
    494498        { 
    495499#ifdef HAVE_ZLIB_H 
    496             i_decompressed_size = do_decompress( p_sdp, &p_decompressed_buffer, i_read - ( p_sdp - buffer ) ); 
     500            i_decompressed_size = do_decompress( p_sdp, &p_decompressed_buffer, 
     501                                      i_read - ( p_sdp - buffer ) ); 
    497502            if( i_decompressed_size > 0 && i_decompressed_size < MAX_SAP_BUFFER ) 
    498503            { 
     
    542547static void cfield_parse( char *psz_cfield, char **ppsz_uri ) 
    543548{ 
    544  
    545549    char *psz_pos; 
    546550    if( psz_cfield ) 
     
    573577 
    574578    return; 
    575  
    576579} 
    577580 
     
    668671        for( i = 0 ; i< p_intf->p_sys->i_announces ; i++ ) 
    669672        { 
    670             if( !strcmp(p_intf->p_sys->pp_announces[i]->psz_uri, 
    671                         psz_uri ) ) 
     673            if( !strcmp( p_intf->p_sys->pp_announces[i]->psz_uri, 
     674                        psz_uri ) ) 
    672675            { 
    673676                p_intf->p_sys->pp_announces[i]->i_last = mdate(); 
    674                 free(psz_uri); 
     677                free( psz_uri ); 
    675678                return; 
    676679            } 
     
    688691 
    689692        /* Remember it */ 
    690         p_announce = (struct sap_announce_t *)malloc( 
    691                       sizeof(struct sap_announce_t) ); 
     693        p_announce = ( struct sap_announce_t * )malloc( 
     694                      sizeof( struct sap_announce_t ) ); 
    692695        if( p_sd->psz_sessionname ) 
    693696        { 
     
    724727    { 
    725728        int i_group = p_intf->p_sys->i_group; 
     729        int i_packetsize = config_GetInt( p_intf, "mtu" ); 
    726730 
    727731        /* Build what we have to put in psz_item_uri, with the m and 
     
    758762        for( i = 0 ; i< p_sd->i_attributes ; i++ ) 
    759763        { 
    760             if(!strcasecmp( p_sd->pp_attributes[i]->psz_field , "type") && 
    761                 strstr( p_sd->pp_attributes[i]->psz_value, "http") ) 
     764            if( !strcasecmp( p_sd->pp_attributes[i]->psz_field , "type" ) && 
     765                strstr( p_sd->pp_attributes[i]->psz_value, "http" ) ) 
    762766            { 
    763767                b_http = VLC_TRUE; 
    764768            } 
    765             if(!strcasecmp( p_sd->pp_attributes[i]->psz_field , "http-path")
     769            if( !strcasecmp( p_sd->pp_attributes[i]->psz_field , "http-path" )
    766770            { 
    767771                psz_http_path = strdup(  p_sd->pp_attributes[i]->psz_value ); 
    768772            } 
    769             if(!strcasecmp( p_sd->pp_attributes[i]->psz_field , "plgroup")
     773            if( !strcasecmp( p_sd->pp_attributes[i]->psz_field , "plgroup" )
    770774            { 
    771775                int i_group_id; 
     
    779783 
    780784                i_group_id = playlist_GroupToId( p_playlist, 
    781                                  p_sd->pp_attributes[i]->psz_value); 
     785                                 p_sd->pp_attributes[i]->psz_value ); 
    782786                if( i_group_id != 0 ) 
    783787                { 
     
    788792                    playlist_group_t *p_group = 
    789793                            playlist_CreateGroup( p_playlist, 
    790                                        p_sd->pp_attributes[i]->psz_value); 
     794                                       p_sd->pp_attributes[i]->psz_value ); 
    791795                    i_group = p_group->i_id; 
    792796                } 
    793797                vlc_object_release( p_playlist ); 
    794798            } 
     799            if( !strcasecmp( p_sd->pp_attributes[i]->psz_field , "packetsize" ) ) 
     800            { 
     801                i_packetsize = strtol( p_sd->pp_attributes[i]->psz_value, NULL, 10 ); 
     802            } 
    795803        } 
    796804 
     
    798806        if( b_http == VLC_FALSE ) 
    799807        { 
    800             psz_item_uri = malloc( strlen( psz_proto ) + strlen( psz_uri ) + 
    801                                  strlen( psz_port ) + 7 ); 
    802808            if( ismult( psz_uri ) ) 
    803809            { 
    804                 sprintf( psz_item_uri, "%s://@%s:%s", 
     810                asprintf( &psz_item_uri, "%s://@%s:%s", 
    805811                         psz_proto, psz_uri, psz_port ); 
    806812            } 
    807813            else 
    808814            { 
    809                 sprintf( psz_item_uri, "%s://%s:%s", 
     815                asprintf( &psz_item_uri, "%s://%s:%s", 
    810816                         psz_proto, psz_uri, psz_port ); 
    811817            } 
     
    859865 
    860866                    /* Change the name in the item */ 
    861                     if( p_item->input.psz_name ) 
    862                         free( p_item->input.psz_name ); 
    863                     p_item->input.psz_name = strdup( p_sd->psz_sessionname); 
     867                    if( p_item ) 
     868                    { 
     869                        vlc_mutex_lock( &p_item->input.lock ); 
     870                        if( p_item->input.psz_name ) 
     871                            free( p_item->input.psz_name ); 
     872                        p_item->input.psz_name = strdup( p_sd->psz_sessionname ); 
     873                        vlc_mutex_unlock( &p_item->input.lock ); 
     874                    } 
    864875 
    865876                    /* Update the stored name */ 
     
    879890        p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, 
    880891                                      FIND_ANYWHERE ); 
    881         i_id = playlist_Add ( p_playlist, psz_item_uri , 
    882                                p_sd->psz_sessionname, 
    883                                PLAYLIST_CHECK_INSERT, PLAYLIST_END ); 
    884         p_item = playlist_ItemGetById( p_playlist, i_id ); 
     892 
     893        p_item = playlist_ItemNew( p_intf, psz_item_uri, p_sd->psz_sessionname ); 
     894 
    885895        if( p_item ) 
    886896        { 
    887             vlc_mutex_lock( &p_item->input.lock ); 
    888897            playlist_ItemSetGroup( p_item, i_group ); 
    889             vlc_mutex_unlock( &p_item->input.lock ); 
     898            if( i_packetsize > config_GetInt( p_intf, "mtu" ) ) 
     899            { 
     900                char *psz_packetsize_option; 
     901                asprintf( &psz_packetsize_option, "mtu=%i", i_packetsize ); 
     902                playlist_ItemAddOption( p_item, psz_packetsize_option ); 
     903                free( psz_packetsize_option ); 
     904            } 
     905            playlist_AddItem( p_playlist , p_item , PLAYLIST_CHECK_INSERT, PLAYLIST_END ); 
    890906        } 
    891907 
    892908        /* Then remember it */ 
    893909        p_announce = (struct sap_announce_t *)malloc( 
    894                       sizeof(struct sap_announce_t) ); 
     910                      sizeof( struct sap_announce_t ) ); 
    895911        if(  p_sd->psz_sessionname ) 
    896912        { 
     
    935951    if( p_packet[0] != 'v' || p_packet[1] != '=' ) 
    936952    { 
    937         msg_Warn(p_intf, "bad SDP packet"); 
     953        msg_Warn( p_intf, "bad SDP packet" ); 
    938954        return NULL; 
    939955    } 
     
    963979            psz_end = p_packet + strlen( p_packet ); 
    964980        } 
    965         if( psz_end > p_packet && *(psz_end - 1 ) == '\r' ) 
     981        if( psz_end > p_packet && *( psz_end - 1 ) == '\r' ) 
    966982        { 
    967983            psz_end--; 
     
    976992        if( p_packet[1] != '=' ) 
    977993        { 
    978             msg_Warn( p_intf, "invalid packet") ; 
     994            msg_Warn( p_intf, "invalid packet" ) ; 
    979995            free_sd( sd ); 
    980996            return NULL; 
     
    11011117} 
    11021118 
    1103  
    1104  
    11051119/***************************************************************************** 
    1106  * Read: read on a file descriptor, checking b_die periodically 
     1120 * NetRead: read on a file descriptor, checking b_die periodically 
    11071121 ***************************************************************************** 
    1108  * Taken from udp.c 
     1122 * Taken from net.c 
     1123 * Code duplication because of select(). We need a net_Select() but that's  
     1124 * quite difficult. 
    11091125 *****************************************************************************/ 
    11101126static ssize_t NetRead( intf_thread_t *p_intf, 
     
    11201136 
    11211137    /* Initialize file descriptor set */ 
     1138 
    11221139    FD_ZERO( &fds ); 
    11231140    if( fd[0] > 0 ) FD_SET( fd[0], &fds );