Changeset 133d57fe883de115e7d10ce29411a3f7097f79ad

Show
Ignore:
Timestamp:
03/12/06 14:52:04 (2 years ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1165153924 +0000
git-parent:

[fbf4c8060d35617e39b50ae739307152d02ed951]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1165153924 +0000
Message:

Don't write R/O memory + clean up

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/playlist/services_discovery.c

    rfbf4c80 r133d57f  
    2929int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist,  const char *psz_modules ) 
    3030{ 
    31     if( psz_modules && *psz_modules ) 
     31    const char *psz_parser = psz_modules ?: ""; 
     32    int retval = VLC_SUCCESS; 
     33 
     34    for (;;) 
    3235    { 
    33         const char *psz_parser = psz_modules; 
    34         char *psz_next
     36        while( *psz_parser == ' ' || *psz_parser == ':' || *psz_parser == ',' ) 
     37            psz_parser++
    3538 
    36         while( psz_parser && *psz_parser ) 
     39        if( *psz_parser == '\0' ) 
     40            break; 
     41 
     42        const char *psz_next = strchr( psz_parser, ':' ); 
     43        if( psz_next == NULL ) 
     44            psz_next = psz_parser + strlen( psz_parser ); 
     45 
     46        char psz_plugin[psz_next - psz_parser + 1]; 
     47        memcpy (psz_plugin, psz_parser, sizeof (psz_plugin) - 1); 
     48        psz_plugin[sizeof (psz_plugin) - 1] = '\0'; 
     49        psz_parser = psz_next; 
     50 
     51        /* Perform the addition */ 
     52        msg_Dbg( p_playlist, "Add services_discovery %s", psz_plugin ); 
     53        services_discovery_t *p_sd = vlc_object_create( p_playlist, 
     54                                                        VLC_OBJECT_SD ); 
     55        if( p_sd == NULL ) 
     56            return VLC_ENOMEM; 
     57 
     58        p_sd->pf_run = NULL; 
     59        p_sd->p_module = module_Need( p_sd, "services_discovery", psz_plugin, 0 ); 
     60 
     61        if( p_sd->p_module == NULL ) 
    3762        { 
    38             while( *psz_parser == ' ' || *psz_parser == ':' || *psz_parser == ',' ) 
    39                 psz_parser++; 
     63            msg_Err( p_playlist, "no suitable services discovery module" ); 
     64            vlc_object_destroy( p_sd ); 
     65            retval = VLC_EGENERIC; 
     66            continue; 
     67        } 
     68        p_sd->psz_module = strdup( psz_plugin ); 
     69        p_sd->b_die = VLC_FALSE; 
    4070 
    41             if( (psz_next = strchr( psz_parser, ':' ) ) ) 
    42                 *psz_next++ = '\0'; 
     71        PL_LOCK; 
     72        TAB_APPEND( p_playlist->i_sds, p_playlist->pp_sds, p_sd ); 
     73        PL_UNLOCK; 
    4374 
    44             if( *psz_parser == '\0' ) 
    45                 break; 
    46             msg_Dbg( p_playlist, "Add services_discovery %s", psz_parser ); 
    47             /* Perform the addition */ 
    48             { 
    49                 services_discovery_t *p_sd = vlc_object_create( p_playlist, 
    50                                                                 VLC_OBJECT_SD ); 
    51                 p_sd->pf_run = NULL; 
    52                 p_sd->p_module = module_Need( p_sd, "services_discovery", psz_parser, 0 ); 
    53  
    54                 if( p_sd->p_module == NULL ) 
    55                 { 
    56                     msg_Err( p_playlist, "no suitable services discovery module" ); 
    57                     vlc_object_destroy( p_sd ); 
    58                     return VLC_EGENERIC; 
    59                 } 
    60                 p_sd->psz_module = strdup( psz_parser ); 
    61                 p_sd->b_die = VLC_FALSE; 
    62  
    63                 PL_LOCK; 
    64                 TAB_APPEND( p_playlist->i_sds, p_playlist->pp_sds, p_sd ); 
    65                 PL_UNLOCK; 
    66  
    67                 if( !p_sd->pf_run ) { 
    68                     psz_parser = psz_next; 
    69                     continue; 
    70                 } 
    71  
    72                 if( vlc_thread_create( p_sd, "services_discovery", RunSD, 
    73                                        VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) ) 
    74                 { 
    75                     msg_Err( p_sd, "cannot create services discovery thread" ); 
    76                     vlc_object_destroy( p_sd ); 
    77                     return VLC_EGENERIC; 
    78                 } 
    79             } 
    80             psz_parser = psz_next; 
     75        if ((p_sd->pf_run != NULL) 
     76         && vlc_thread_create( p_sd, "services_discovery", RunSD, 
     77                               VLC_THREAD_PRIORITY_LOW, VLC_FALSE)) 
     78        { 
     79            msg_Err( p_sd, "cannot create services discovery thread" ); 
     80            vlc_object_destroy( p_sd ); 
     81            retval = VLC_EGENERIC; 
     82            continue; 
    8183        } 
    8284    } 
    83     return VLC_SUCCESS; 
     85 
     86    return retval; 
    8487} 
    8588