Changeset 5c8acc49f87cb734a2d072cf1b3f5c0f067b5ade

Show
Ignore:
Timestamp:
27/07/05 18:30:19 (3 years ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1122481819 +0000
git-parent:

[0f55beac49400edec7c44f7a178976641a0770bf]

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

Put correct owner address in SAP-generated SDP

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/stream_output.h

    rc4a2920 r5c8acc4  
    258258{ 
    259259    int i_type; 
    260  
    261     /* For SAP */ 
    262     char *psz_address; /* If we use a custom address */ 
    263260}; 
    264261 
     
    292289    int i_current_session; 
    293290 
    294     int (*pf_add)  ( sap_handler_t*, session_descriptor_t *,announce_method_t*); 
     291    int (*pf_add)  ( sap_handler_t*, session_descriptor_t *); 
    295292    int (*pf_del)  ( sap_handler_t*, session_descriptor_t *); 
    296293 
  • include/vlc_symbols.h

    rc4a2920 r5c8acc4  
    9393    int * (*__net_ListenTCP_inner) (vlc_object_t *, const char *, int); 
    9494    int (*__net_Accept_inner) (vlc_object_t *, int *, mtime_t); 
    95     int (*__net_OpenUDP_inner) (vlc_object_t *p_this, char *psz_bind, int i_bind, char *psz_server, int i_server); 
     95    int (*__net_OpenUDP_inner) (vlc_object_t *p_this, const char *psz_bind, int i_bind, const char *psz_server, int i_server); 
    9696    void (*net_Close_inner) (int fd); 
    9797    int (*__net_Read_inner) (vlc_object_t *p_this, int fd, v_socket_t *, uint8_t *p_data, int i_data, vlc_bool_t b_retry); 
  • modules/stream_out/standard.c

    r3220fe6 r5c8acc4  
    362362        vlc_UrlClean( &url ); 
    363363 
    364         /* FIXME: Free p_method */ 
    365         if( p_method->psz_address) free( p_method->psz_address ); 
    366364        free( p_method ); 
    367365    } 
  • src/stream_output/announce.c

    rc4a2920 r5c8acc4  
    200200 
    201201    p_method = (announce_method_t *)malloc( sizeof(announce_method_t) ); 
    202  
    203     if( p_method ) 
    204     { 
    205         p_method->i_type = i_type; 
    206         if( i_type == METHOD_TYPE_SAP ) 
    207             /* Default value */ 
    208             p_method->psz_address = NULL; 
    209     } 
     202    if( p_method == NULL ) 
     203        return NULL; 
     204 
     205    p_method->i_type = i_type; 
    210206    return p_method; 
    211207} 
     
    287283        /* this will set p_session->p_sap for later deletion */ 
    288284        msg_Dbg( p_announce, "adding SAP session"); 
    289         p_announce->p_sap->pf_add( p_announce->p_sap, p_session, p_method ); 
     285        p_announce->p_sap->pf_add( p_announce->p_sap, p_session ); 
    290286    } 
    291287    else if( p_method->i_type == METHOD_TYPE_SLP ) 
  • src/stream_output/sap.c

    rd20e734 r5c8acc4  
    6666{ 
    6767    char *psz_address; 
     68    char psz_machine[NI_MAXNUMERICHOST]; 
    6869    int i_port; 
    6970    int i_rfd; /* Read socket */ 
     
    8485static void RunThread( vlc_object_t *p_this); 
    8586static int CalculateRate( sap_handler_t *p_sap, sap_address_t *p_address ); 
    86 static int SDPGenerate( sap_handler_t *p_sap, session_descriptor_t *p_session ); 
     87static char *SDPGenerate( sap_handler_t *p_sap, 
     88                          const session_descriptor_t *p_session, 
     89                          const sap_address_t *p_addr ); 
    8790 
    8891static int announce_SendSAPAnnounce( sap_handler_t *p_sap, 
     
    9194 
    9295static int announce_SAPAnnounceAdd( sap_handler_t *p_sap, 
    93                              session_descriptor_t *p_session, 
    94                              announce_method_t *p_method ); 
     96                             session_descriptor_t *p_session ); 
    9597 
    9698static int announce_SAPAnnounceDel( sap_handler_t *p_sap, 
     
    126128    free( psz_charset ); 
    127129    if( p_sap->iconvHandle == (vlc_iconv_t)(-1) ) 
    128     { 
    129130        msg_Warn( p_sap, "Unable to do requested conversion" ); 
    130     } 
    131131 
    132132    p_sap->pf_add = announce_SAPAnnounceAdd; 
     
    253253/* Add a SAP announce */ 
    254254static int announce_SAPAnnounceAdd( sap_handler_t *p_sap, 
    255                              session_descriptor_t *p_session, 
    256                              announce_method_t *p_method ) 
     255                             session_descriptor_t *p_session ) 
    257256{ 
    258257    int i; 
    259     char *psz_type = "application/sdp"; 
     258    const char *psz_type = "application/sdp"; 
    260259    int i_header_size; 
    261260    char *psz_head; 
    262     vlc_bool_t b_found = VLC_FALSE, b_ipv6 = VLC_FALSE; 
     261    vlc_bool_t b_ipv6 = VLC_FALSE; 
    263262    sap_session_t *p_sap_session; 
    264263    mtime_t i_hash; 
     264    char psz_buf[NI_MAXNUMERICHOST], *ptr; 
     265    const char *psz_addr; 
     266    struct addrinfo hints, *res; 
     267         
    265268 
    266269    vlc_mutex_lock( &p_sap->object_lock ); 
    267270 
    268     /* If needed, build the SDP */ 
    269     if( !p_session->psz_sdp ) 
    270     { 
    271         if ( SDPGenerate( p_sap, p_session ) != VLC_SUCCESS ) 
    272         { 
    273             vlc_mutex_unlock( &p_sap->object_lock ); 
    274             return VLC_EGENERIC; 
    275         } 
    276     } 
    277  
    278     if( p_method->psz_address == NULL ) 
    279     { 
    280         /* Determine SAP multicast address automatically */ 
    281         char psz_buf[NI_MAXNUMERICHOST], *ptr; 
    282         const char *psz_addr; 
    283         struct addrinfo hints, *res; 
    284  
    285         if( p_session->psz_uri == NULL ) 
    286         { 
    287             msg_Err( p_sap, "*FIXME* Unexpected NULL URI for SAP announce" ); 
    288             msg_Err( p_sap, "This should not happen. VLC needs fixing." ); 
    289             vlc_mutex_unlock( &p_sap->object_lock ); 
    290             return VLC_EGENERIC; 
    291         } 
    292  
    293         /* Canonicalize IP address (e.g. 224.00.010.1 => 224.0.10.1) */ 
    294         memset( &hints, 0, sizeof( hints ) ); 
    295         hints.ai_socktype = SOCK_DGRAM; 
    296         hints.ai_flags = AI_NUMERICHOST; 
    297  
    298         i = vlc_getaddrinfo( (vlc_object_t *)p_sap, p_session->psz_uri, 0, 
    299                              &hints, &res ); 
    300         if( i == 0 ) 
    301         { 
    302             i = vlc_getnameinfo( res->ai_addr, res->ai_addrlen, psz_buf, 
    303                                  sizeof( psz_buf ), NULL, NI_NUMERICHOST ); 
    304             vlc_freeaddrinfo( res ); 
    305         } 
    306  
    307         if( i ) 
    308         { 
    309             msg_Err( p_sap, "Invalid URI for SAP announce : %s : %s", 
    310                      p_session->psz_uri, vlc_gai_strerror( i ) ); 
    311             vlc_mutex_unlock( &p_sap->object_lock ); 
    312             return VLC_EGENERIC; 
    313         } 
    314  
    315         /* Remove interface specification if present */ 
    316         ptr = strchr( psz_buf, '%' ); 
    317         if( ptr != NULL ) 
    318             *ptr = '\0'; 
    319  
    320         if( strchr( psz_buf, ':' ) != NULL ) 
    321         { 
    322             b_ipv6 = VLC_TRUE; 
    323  
    324             /* See RFC3513 for list of valid IPv6 scopes */ 
    325             if( ( tolower( psz_buf[0] ) == 'f' ) 
    326              && ( tolower( psz_buf[1] ) == 'f' ) 
    327              && isxdigit( psz_buf[2] ) && isxdigit( psz_buf[3] ) ) 
    328             { 
    329                 /* Multicast IPv6 */ 
    330                 psz_buf[2] = '0'; /* force flags to zero */ 
    331                 /* keep scope in psz_addr[3] */ 
    332                 memcpy( &psz_buf[4], "::2:7ffe", sizeof( "::2:7ffe" ) ); 
    333                 psz_addr = psz_buf; 
    334             } 
    335             else 
    336                 /* Unicast IPv6 - assume global scope */ 
    337                 psz_addr = "ff0e::2:7ffe"; 
     271    if( p_session->psz_uri == NULL ) 
     272    { 
     273        msg_Err( p_sap, "*FIXME* Unexpected NULL URI for SAP announce" ); 
     274        msg_Err( p_sap, "This should not happen. VLC needs fixing." ); 
     275        vlc_mutex_unlock( &p_sap->object_lock ); 
     276        return VLC_EGENERIC; 
     277    } 
     278 
     279    /* Determine SAP multicast address automatically (FIXME: gruik) */ 
     280    /* Canonicalize IP address (e.g. 224.00.010.1 => 224.0.10.1) */ 
     281    memset( &hints, 0, sizeof( hints ) ); 
     282    hints.ai_socktype = SOCK_DGRAM; 
     283    hints.ai_flags = AI_NUMERICHOST; 
     284 
     285    i = vlc_getaddrinfo( (vlc_object_t *)p_sap, p_session->psz_uri, 0, 
     286                         &hints, &res ); 
     287    if( i == 0 ) 
     288    { 
     289        i = vlc_getnameinfo( res->ai_addr, res->ai_addrlen, psz_buf, 
     290                             sizeof( psz_buf ), NULL, NI_NUMERICHOST ); 
     291        vlc_freeaddrinfo( res ); 
     292    } 
     293 
     294    if( i ) 
     295    { 
     296        msg_Err( p_sap, "Invalid URI for SAP announce : %s : %s", 
     297                 p_session->psz_uri, vlc_gai_strerror( i ) ); 
     298        vlc_mutex_unlock( &p_sap->object_lock ); 
     299        return VLC_EGENERIC; 
     300    } 
     301 
     302    /* Remove interface specification if present */ 
     303    ptr = strchr( psz_buf, '%' ); 
     304    if( ptr != NULL ) 
     305        *ptr = '\0'; 
     306 
     307    if( strchr( psz_buf, ':' ) != NULL ) 
     308    { 
     309        b_ipv6 = VLC_TRUE; 
     310 
     311        /* See RFC3513 for list of valid IPv6 scopes */ 
     312        if( ( tolower( psz_buf[0] ) == 'f' ) 
     313         && ( tolower( psz_buf[1] ) == 'f' ) 
     314         && isxdigit( psz_buf[2] ) && isxdigit( psz_buf[3] ) ) 
     315        { 
     316            /* Multicast IPv6 */ 
     317            psz_buf[2] = '0'; /* force flags to zero */ 
     318            /* keep scope in psz_addr[3] */ 
     319            memcpy( &psz_buf[4], "::2:7ffe", sizeof( "::2:7ffe" ) ); 
     320            psz_addr = psz_buf; 
    338321        } 
    339322        else 
    340         { 
    341             /* See RFC2365 for IPv4 scopes */ 
    342             if( memcmp( psz_buf, "224.0.0.", 8 ) == 0 ) 
    343                 psz_addr = "224.0.0.255"; 
    344             else 
    345             if( memcmp( psz_buf, "239.255.", 8 ) == 0 ) 
    346                 psz_addr = "239.255.255.255"; 
    347             else 
    348             if( ( memcmp( psz_buf, "239.19", 6 ) == 0 ) 
    349              && ( ( psz_buf[6] >= '2' ) && ( psz_buf[6] <= '5' ) ) ) 
    350                 psz_addr = "239.195.255.255"; 
    351             else 
    352                 /* assume global scope */ 
    353                 psz_addr = "224.2.127.254"; 
    354         } 
    355  
    356         p_method->psz_address = strdup( psz_addr ); 
     323            /* Unicast IPv6 - assume global scope */ 
     324            psz_addr = "ff0e::2:7ffe"; 
    357325    } 
    358326    else 
    359         b_ipv6 = (strchr( p_method->psz_address, ':' ) != NULL); 
    360  
    361     msg_Dbg( p_sap, "using SAP address: %s", p_method->psz_address); 
     327    { 
     328        /* See RFC2365 for IPv4 scopes */ 
     329        if( memcmp( psz_buf, "224.0.0.", 8 ) == 0 ) 
     330            psz_addr = "224.0.0.255"; 
     331        else 
     332        if( memcmp( psz_buf, "239.255.", 8 ) == 0 ) 
     333            psz_addr = "239.255.255.255"; 
     334        else 
     335        if( ( memcmp( psz_buf, "239.19", 6 ) == 0 ) 
     336         && ( ( psz_buf[6] >= '2' ) && ( psz_buf[6] <= '5' ) ) ) 
     337            psz_addr = "239.195.255.255"; 
     338        else 
     339            /* assume global scope */ 
     340            psz_addr = "224.2.127.254"; 
     341    } 
     342 
     343    msg_Dbg( p_sap, "using SAP address: %s", psz_addr); 
    362344 
    363345    /* XXX: Check for dupes */ 
    364346    p_sap_session = (sap_session_t*)malloc(sizeof(sap_session_t)); 
    365  
    366     p_sap_session->psz_sdp = strdup( p_session->psz_sdp ); 
    367     p_sap_session->i_last = 0; 
     347    p_sap_session->p_address = NULL; 
    368348 
    369349    /* Add the address to the buffer */ 
    370     for( i = 0; i< p_sap->i_addresses; i++) 
    371     { 
    372         if( !strcmp( p_method->psz_address, 
    373              p_sap->pp_addresses[i]->psz_address ) ) 
     350    for( i = 0; i < p_sap->i_addresses; i++) 
     351    { 
     352        if( !strcmp( psz_addr, p_sap->pp_addresses[i]->psz_address ) ) 
    374353        { 
    375354            p_sap_session->p_address = p_sap->pp_addresses[i]; 
    376             b_found = VLC_TRUE; 
    377355            break; 
    378356        } 
    379357    } 
    380     if( b_found == VLC_FALSE ) 
     358 
     359    if( p_sap_session->p_address == NULL ) 
    381360    { 
    382361        sap_address_t *p_address = (sap_address_t *) 
     
    387366            return VLC_ENOMEM; 
    388367        } 
    389         p_address->psz_address = strdup( p_method->psz_address ); 
     368        p_address->psz_address = strdup( psz_addr ); 
    390369        p_address->i_port  =  9875; 
    391         p_address->i_wfd = net_OpenUDP( p_sap, "", 0, 
    392                                         p_address->psz_address, 
     370        p_address->i_wfd = net_OpenUDP( p_sap, "", 0, psz_addr, 
    393371                                        p_address->i_port ); 
    394372        if( p_address->i_wfd != -1 ) 
     373        { 
    395374            net_StopRecv( p_address->i_wfd ); 
     375            net_GetSockAddress( p_sap, p_address->i_wfd, 
     376                                p_address->psz_machine, NULL ); 
     377        } 
    396378 
    397379        if( p_sap->b_control == VLC_TRUE ) 
    398380        { 
    399             p_address->i_rfd = net_OpenUDP( p_sap, p_method->psz_address, 
    400                                             p_address->i_port, 
    401                                             "", 0 ); 
     381            p_address->i_rfd = net_OpenUDP( p_sap, psz_addr, 
     382                                            p_address->i_port, "", 0 ); 
    402383            if( p_address->i_rfd != -1 ) 
    403384                net_StopSend( p_address->i_rfd ); 
     
    430411    } 
    431412 
     413 
    432414    /* Build the SAP Headers */ 
    433415    i_header_size = ( b_ipv6 ? 20 : 8 ) + strlen( psz_type ) + 1; 
    434416    psz_head = (char *) malloc( i_header_size * sizeof( char ) ); 
    435     if( ! psz_head
     417    if( psz_head == NULL
    436418    { 
    437419        msg_Err( p_sap, "out of memory" ); 
     
    484466        strncpy( psz_head + 8, psz_type, 15 ); 
    485467    } 
     468 
     469    /* If needed, build the SDP */ 
     470    if( p_session->psz_sdp == NULL ) 
     471    { 
     472        p_session->psz_sdp = SDPGenerate( p_sap, p_session, 
     473                                          p_sap_session->p_address ); 
     474        if( p_session->psz_sdp == NULL ) 
     475        { 
     476            vlc_mutex_unlock( &p_sap->object_lock ); 
     477            return VLC_ENOMEM; 
     478        } 
     479    } 
     480 
     481    p_sap_session->psz_sdp = strdup( p_session->psz_sdp ); 
     482    p_sap_session->i_last = 0; 
    486483 
    487484    psz_head[ i_header_size-1 ] = '\0'; 
     
    571568                           p_session->psz_data, 
    572569                           p_session->i_length ); 
    573         if( i_ret != p_session->i_length ) 
     570        if( i_ret != (int)p_session->i_length ) 
    574571        { 
    575572            msg_Warn( p_sap, "SAP send failed on address %s (%i %i)", 
     
    588585} 
    589586 
    590 static int SDPGenerate( sap_handler_t *p_sap, session_descriptor_t *p_session ) 
     587static char *SDPGenerate( sap_handler_t *p_sap, 
     588                          const session_descriptor_t *p_session, 
     589                          const sap_address_t *p_addr ) 
    591590{ 
    592591    int64_t i_sdp_id = mdate(); 
    593592    int     i_sdp_version = 1 + p_sap->i_sessions + (rand()&0xfff); 
    594     char *psz_group, *psz_name, psz_uribuf[NI_MAXNUMERICHOST], *psz_uri; 
     593    char *psz_group, *psz_name, psz_uribuf[NI_MAXNUMERICHOST], *psz_uri, 
     594         *psz_sdp; 
    595595    char ipv; 
    596596 
    597597    psz_group = convert_to_utf8( p_sap, p_session->psz_group ); 
    598598    psz_name = convert_to_utf8( p_sap, p_session->psz_name ); 
     599    if( psz_name == NULL ) 
     600    { 
     601        FREE( psz_group ); 
     602        return NULL; 
     603    } 
    599604 
    600605    /* FIXME: really check that psz_uri is a real IP address 
     
    619624 
    620625    /* see the lists in modules/stream_out/rtp.c for compliance stuff */ 
    621     p_session->psz_sdp = (char *)malloc( 
    622                             sizeof("v=0\r\n" 
    623                                    "o=- 45383436098 45398  IN IP4 127.0.0.1\r\n" /* FIXME */ 
    624                                    "s=\r\n" 
    625                                    "t=0 0\r\n" 
    626                                    "c=IN IP4 /\r\n" 
    627                                    "m=video  udp\r\n" 
    628                                    "a=tool:"PACKAGE_STRING"\r\n" 
    629                                    "a=type:broadcast\r\n") 
    630                            + strlen( psz_name ) 
    631                            + strlen( psz_uri ) + 300 
    632                            + ( psz_group ? strlen( psz_group ) : 0 ) ); 
    633  
    634     if( p_session->psz_sdp == NULL || psz_name == NULL ) 
    635     { 
    636         msg_Err( p_sap, "out of memory" ); 
    637         FREE( psz_name ); 
    638         FREE( psz_group ); 
    639         return VLC_ENOMEM; 
    640     } 
    641  
    642     sprintf( p_session->psz_sdp, 
     626    if( asprintf( &psz_sdp, 
    643627                            "v=0\r\n" 
    644                             "o=- "I64Fd" %d IN IP4 127.0.0.1\r\n" 
     628                            "o=- "I64Fd" %d IN IP%c %s\r\n" 
    645629                            "s=%s\r\n" 
    646630                            "t=0 0\r\n" 
     
    650634                            "a=type:broadcast\r\n", 
    651635                            i_sdp_id, i_sdp_version, 
     636                            ipv, p_addr->psz_machine, 
    652637                            psz_name, ipv, 
    653638                            psz_uri, p_session->i_ttl, 
    654                             p_session->i_port, p_session->i_payload ); 
     639                            p_session->i_port, p_session->i_payload ) == -1 ) 
     640    { 
     641        free( psz_name ); 
     642        FREE( psz_group ); 
     643        return NULL; 
     644    } 
     645     
    655646    free( psz_name ); 
    656647 
    657648    if( psz_group ) 
    658649    { 
    659         sprintf( p_session->psz_sdp, "%sa=x-plgroup:%s\r\n", 
    660                                      p_session->psz_sdp, psz_group ); 
     650        /* FIXME: this is illegal use of sprintf */ 
     651        sprintf( psz_sdp, "%sa=x-plgroup:%s\r\n", psz_sdp, psz_group ); 
    661652        free( psz_group ); 
    662653    } 
    663654 
    664     msg_Dbg( p_sap, "Generated SDP (%i bytes):\n%s", strlen(p_session->psz_sdp), 
    665                     p_session->psz_sdp ); 
    666     return VLC_SUCCESS
     655    msg_Dbg( p_sap, "Generated SDP (%i bytes):\n%s", strlen(psz_sdp), 
     656             psz_sdp ); 
     657    return psz_sdp
    667658} 
    668659