Changeset 5deafc168b81ecbd650b150bfc8a1bb86cf24eab

Show
Ignore:
Timestamp:
21/01/04 17:56:16 (5 years ago)
Author:
Laurent Aimar <fenrir@videolan.org>
git-committer:
Laurent Aimar <fenrir@videolan.org> 1074704176 +0000
git-parent:

[83c6d1f77c2dd0b9dd283c0027208f82b9d2c36c]

git-author:
Laurent Aimar <fenrir@videolan.org> 1074704176 +0000
Message:
  • all: use net_*.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/access/mms/mms.c

    rd5791c9 r5deafc1  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001, 2002 VideoLAN 
    5  * $Id: mms.c,v 1.34 2003/05/15 22:27:36 massiot Exp $ 
     5 * $Id: mms.c,v 1.35 2004/01/21 16:56:16 fenrir Exp $ 
    66 * 
    77 * Authors: Laurent Aimar <fenrir@via.ecp.fr> 
     
    7070                  "force selection of all streams", 
    7171                  "force selection of all streams", VLC_TRUE ); 
    72 #if 0 
    73         add_string( "mms-stream", NULL, NULL, 
    74                     "streams selection", 
    75                     "force this stream selection", VLC_TRUE ); 
    76 #endif 
    7772        add_integer( "mms-maxbitrate", 0, NULL, 
    7873                     "max bitrate", 
     
    9085    input_thread_t  *p_input = (input_thread_t*)p_this; 
    9186 
    92     int i_err; 
    93  
    94  
     87    /* First set ipv4/ipv6 */ 
     88    var_Create( p_input, "ipv4", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); 
     89    var_Create( p_input, "ipv6", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); 
     90 
     91    /* mms-caching */ 
     92    var_Create( p_input, "mms-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); 
     93 
     94    /* use specified method */ 
    9595    if( *p_input->psz_access ) 
    9696    { 
     
    109109    } 
    110110 
    111  
    112     i_err = E_( MMSTUOpen )( p_input ); 
    113  
    114     if( i_err ) 
    115     { 
    116         i_err = E_( MMSHOpen )( p_input ); 
    117     } 
    118  
    119     return i_err; 
     111    if( E_( MMSTUOpen )( p_input ) ) 
     112    { 
     113        /* try mmsh if mmstu failed */ 
     114        return E_( MMSHOpen )( p_input ); 
     115    } 
     116    return VLC_SUCCESS; 
    120117} 
    121118 
  • modules/access/mms/mmsh.c

    r217c4d9 r5deafc1  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001, 2002 VideoLAN 
    5  * $Id: mmsh.c,v 1.6 2003/08/26 00:51:19 fenrir Exp $ 
     5 * $Id: mmsh.c,v 1.7 2004/01/21 16:56:16 fenrir Exp $ 
    66 * 
    77 * Authors: Laurent Aimar <fenrir@via.ecp.fr> 
     
    3636#include <vlc/input.h> 
    3737 
    38 #ifdef HAVE_ERRNO_H 
    39 #   include <errno.h> 
    40 #endif 
    41 #ifdef HAVE_FCNTL_H 
    42 #   include <fcntl.h> 
    43 #endif 
    44 #ifdef HAVE_SYS_TIME_H 
    45 #    include <sys/time.h> 
    46 #endif 
    47  
    48 #ifdef HAVE_UNISTD_H 
    49 #   include <unistd.h> 
    50 #endif 
    51  
    52 #if defined( UNDER_CE ) 
    53 #   include <winsock.h> 
    54 #elif defined( WIN32 ) 
    55 #   include <winsock2.h> 
    56 #   include <ws2tcpip.h> 
    57 #   ifndef IN_MULTICAST 
    58 #       define IN_MULTICAST(a) IN_CLASSD(a) 
    59 #   endif 
    60 #else 
    61 #   include <sys/socket.h> 
    62 #endif 
    63  
    6438#include "network.h" 
    6539#include "asf.h" 
     
    7246 * Local prototypes 
    7347 *****************************************************************************/ 
    74 int  E_( MMSHOpen )  ( input_thread_t * ); 
    75 void E_( MMSHClose ) ( input_thread_t * ); 
    76  
    77 static ssize_t Read        ( input_thread_t * p_input, byte_t * p_buffer, 
    78                              size_t i_len ); 
    79 static void    Seek        ( input_thread_t *, off_t ); 
    80  
    81 /**************************************************************************** 
    82  **************************************************************************** 
    83  *******************                                      ******************* 
    84  *******************       Main functions                 ******************* 
    85  *******************                                      ******************* 
    86  **************************************************************************** 
    87  ****************************************************************************/ 
     48int  E_(MMSHOpen)  ( input_thread_t * ); 
     49void E_(MMSHClose) ( input_thread_t * ); 
     50static ssize_t Read( input_thread_t *, byte_t *, size_t ); 
     51static void    Seek( input_thread_t *, off_t ); 
     52 
     53static ssize_t NetFill( input_thread_t *, access_sys_t *, int ); 
     54 
     55static int  mmsh_start     ( input_thread_t *, off_t ); 
     56static void mmsh_stop      ( input_thread_t * ); 
     57static int  mmsh_get_packet( input_thread_t *, chunk_t * ); 
     58 
     59static http_answer_t *http_answer_parse( uint8_t *, int ); 
     60static void           http_answer_free ( http_answer_t * ); 
     61static http_field_t  *http_field_find  ( http_field_t *, char * ); 
     62 
     63static int chunk_parse( chunk_t *, uint8_t *, int ); 
    8864 
    8965/**************************************************************************** 
     
    9975    chunk_t         ck; 
    10076 
     77    vlc_value_t     val; 
     78 
    10179    /* init p_sys */ 
    10280    p_input->p_access_data = p_sys = malloc( sizeof( access_sys_t ) ); 
    10381    p_sys->i_proto = MMS_PROTO_HTTP; 
    10482 
    105     p_sys->p_socket = NULL
     83    p_sys->fd       = -1
    10684    p_sys->i_request_context = 1; 
    10785    p_sys->i_buffer = 0; 
     
    129107    } 
    130108 
    131     if( ( p_sys->p_socket = NetOpenTCP( p_input, p_sys->p_url ) ) == NULL ) 
     109    if( ( p_sys->fd = net_OpenTCP( p_input, p_sys->p_url->psz_host, 
     110                                            p_sys->p_url->i_port ) ) < 0 ) 
    132111    { 
    133112        msg_Err( p_input, "cannot connect" ); 
     
    147126                  GUID_PRINT( p_sys->guid ) ); 
    148127    p += sprintf( p, "Connection: Close\r\n\r\n" ); 
    149     NetWrite( p_input, p_sys->p_socket, p_sys->buffer,  p - p_sys->buffer ); 
    150  
     128 
     129    net_Write( p_input, p_sys->fd, p_sys->buffer,  p - p_sys->buffer ); 
    151130 
    152131    if( NetFill ( p_input, p_sys, BUFFER_SIZE ) <= 0 ) 
     
    155134        goto exit_error; 
    156135    } 
    157     NetClose( p_input, p_sys->p_socket ); 
    158     p_sys->p_socket = NULL; 
     136    net_Close( p_sys->fd ); p_sys->fd = -1; 
    159137 
    160138    p_ans = http_answer_parse( p_sys->buffer, p_sys->i_buffer ); 
     
    301279    vlc_mutex_unlock( &p_input->stream.stream_lock ); 
    302280 
    303     /* Update default_pts to a suitable value for ftp access */ 
    304     p_input->i_pts_delay = config_GetInt( p_input, "mms-caching" ) * 1000
    305  
    306  
    307     return( VLC_SUCCESS )
     281    /* Update default_pts to a suitable value for mms access */ 
     282    var_Get( p_input, "mms-caching", &val )
     283    p_input->i_pts_delay = val.i_int * 1000; 
     284 
     285    return VLC_SUCCESS
    308286 
    309287exit_error: 
    310288    E_( url_free )( p_sys->p_url ); 
    311289 
    312     if( p_sys->p_socket
    313     { 
    314         NetClose( p_input, p_sys->p_socket ); 
     290    if( p_sys->fd > 0
     291    { 
     292        net_Close( p_sys->fd ); 
    315293    } 
    316294    free( p_sys ); 
    317     return( VLC_EGENERIC )
     295    return VLC_EGENERIC
    318296} 
    319297 
     
    331309    free( p_sys ); 
    332310} 
    333  
    334 static int mmsh_get_packet( input_thread_t * p_input, 
    335                             chunk_t *p_ck ) 
    336 { 
    337     access_sys_t *p_sys = p_input->p_access_data; 
    338  
    339     int i_mov = p_sys->i_buffer - p_sys->i_buffer_pos; 
    340  
    341     if( p_sys->i_buffer_pos > BUFFER_SIZE / 2 ) 
    342     { 
    343         if( i_mov > 0 ) 
    344         { 
    345             memmove( &p_sys->buffer[0], 
    346                      &p_sys->buffer[p_sys->i_buffer_pos], 
    347                      i_mov ); 
    348         } 
    349  
    350         p_sys->i_buffer     = i_mov; 
    351         p_sys->i_buffer_pos = 0; 
    352     } 
    353  
    354     if( NetFill( p_input, p_sys, 12 ) < 12 ) 
    355     { 
    356         msg_Warn( p_input, "cannot fill buffer" ); 
    357         return VLC_EGENERIC; 
    358     } 
    359  
    360     chunk_parse( p_ck, &p_sys->buffer[p_sys->i_buffer_pos], 
    361                  p_sys->i_buffer - p_sys->i_buffer_pos ); 
    362  
    363     if( p_ck->i_type == 0x4524 )   // Transfer complete 
    364     { 
    365         msg_Warn( p_input, "EOF" ); 
    366         return VLC_EGENERIC; 
    367     } 
    368     else if( p_ck->i_type != 0x4824 && p_ck->i_type != 0x4424 ) 
    369     { 
    370         msg_Err( p_input, "invalid chunk FATAL" ); 
    371         return VLC_EGENERIC; 
    372     } 
    373  
    374     if( p_ck->i_data < p_ck->i_size2 - 8 ) 
    375     { 
    376         if( NetFill( p_input, p_sys, p_ck->i_size2 - 8 - p_ck->i_data ) <= 0 ) 
    377         { 
    378             msg_Warn( p_input, "cannot fill buffer" ); 
    379             return VLC_EGENERIC; 
    380         } 
    381         chunk_parse( p_ck, &p_sys->buffer[p_sys->i_buffer_pos], 
    382                      p_sys->i_buffer - p_sys->i_buffer_pos ); 
    383     } 
    384  
    385     if( p_sys->i_packet_sequence != 0 && 
    386         p_ck->i_sequence != p_sys->i_packet_sequence ) 
    387     { 
    388         msg_Warn( p_input, "packet lost ?" ); 
    389     } 
    390  
    391     p_sys->i_packet_sequence = p_ck->i_sequence + 1; 
    392     p_sys->i_packet_used   = 0; 
    393     p_sys->i_packet_length = p_ck->i_data; 
    394     p_sys->p_packet        = p_ck->p_data; 
    395  
    396     p_sys->i_buffer_pos += 12 + p_ck->i_data; 
    397  
    398     return VLC_SUCCESS; 
    399 } 
    400  
    401311 
    402312/***************************************************************************** 
     
    438348    p_sys->i_packet_used += i_offset; 
    439349 
    440  
    441350    p_input->stream.p_selected_area->i_tell = i_pos; 
    442351    vlc_mutex_unlock( &p_input->stream.stream_lock ); 
    443  
    444352} 
    445353 
     
    499407} 
    500408 
    501  
    502 /****************************************************************************/ 
    503 /****************************************************************************/ 
    504 /****************************************************************************/ 
    505 /****************************************************************************/ 
    506 /****************************************************************************/ 
    507  
    508 static int mmsh_start( input_thread_t *p_input, 
    509                        off_t i_pos ) 
     409/***************************************************************************** 
     410 * NetFill: 
     411 *****************************************************************************/ 
     412static ssize_t NetFill( input_thread_t *p_input, access_sys_t *p_sys, int i_size ) 
     413
     414    int i_try   = 0; 
     415    int i_total = 0; 
     416 
     417    i_size = __MIN( i_size, BUFFER_SIZE - p_sys->i_buffer ); 
     418    if( i_size <= 0 ) 
     419    { 
     420        return 0; 
     421    } 
     422 
     423    for( ;; ) 
     424    { 
     425        int i_read; 
     426 
     427        i_read = net_Read( p_input, p_sys->fd, 
     428                          &p_sys->buffer[p_sys->i_buffer], i_size, VLC_FALSE ); 
     429 
     430        if( i_read == 0 ) 
     431        { 
     432            if( i_try++ > 2 ) 
     433            { 
     434                break; 
     435            } 
     436            msg_Dbg( p_input, "another try %d/2", i_try ); 
     437            continue; 
     438        } 
     439 
     440        if( i_read < 0 || p_input->b_die || p_input->b_error ) 
     441        { 
     442            break; 
     443        } 
     444        i_total += i_read; 
     445 
     446        p_sys->i_buffer += i_read; 
     447        if( i_total >= i_size ) 
     448        { 
     449            break; 
     450        } 
     451    } 
     452 
     453    p_sys->buffer[p_sys->i_buffer] = '\0'; 
     454 
     455    return i_total; 
     456
     457 
     458 
     459/***************************************************************************** 
     460 * 
     461 *****************************************************************************/ 
     462static int mmsh_start( input_thread_t *p_input, off_t i_pos ) 
    510463{ 
    511464    access_sys_t *p_sys = p_input->p_access_data; 
     
    517470    msg_Dbg( p_input, "starting stream" ); 
    518471 
    519     if( ( p_sys->p_socket = NetOpenTCP( p_input, p_sys->p_url ) ) == NULL ) 
     472    if( ( p_sys->fd = net_OpenTCP( p_input, p_sys->p_url->psz_host, 
     473                                            p_sys->p_url->i_port ) ) < 0 ) 
    520474    { 
    521475        /* should not occur */ 
     
    575529    p += sprintf( p, "Connection: Close\r\n\r\n" ); 
    576530 
    577  
    578     NetWrite( p_input, p_sys->p_socket, p_sys->buffer,  p - p_sys->buffer ); 
     531    net_Write( p_input, p_sys->fd, p_sys->buffer,  p - p_sys->buffer ); 
    579532 
    580533    msg_Dbg( p_input, "filling buffer" ); 
     
    589542 
    590543        p = &p_sys->buffer[p_sys->i_buffer]; 
    591         i_read = 
    592             NetRead( p_input, p_sys->p_socket, 
    593                      &p_sys->buffer[p_sys->i_buffer], 
    594                       1024 ); 
     544        i_read = net_Read( p_input, p_sys->fd, &p_sys->buffer[p_sys->i_buffer], 1024, VLC_FALSE ); 
    595545 
    596546        if( i_read == 0 ) 
     
    652602} 
    653603 
     604/***************************************************************************** 
     605 * 
     606 *****************************************************************************/ 
    654607static void mmsh_stop( input_thread_t *p_input ) 
    655608{ 
     
    657610 
    658611    msg_Dbg( p_input, "closing stream" ); 
    659     NetClose( p_input, p_sys->p_socket ); 
    660     p_sys->p_socket = NULL; 
    661 
    662  
    663 static ssize_t NetFill( input_thread_t *p_input, 
    664                         access_sys_t   *p_sys, int i_size ) 
    665 
    666     int i_try   = 0; 
    667     int i_total = 0; 
    668  
    669     i_size = __MIN( i_size, BUFFER_SIZE - p_sys->i_buffer ); 
    670     if( i_size <= 0 ) 
    671     { 
    672         return 0; 
    673     } 
    674  
    675     for( ;; ) 
    676     { 
    677         int i_read; 
    678  
    679         i_read = NetRead( p_input, p_sys->p_socket, 
    680                           &p_sys->buffer[p_sys->i_buffer], i_size ); 
    681  
    682         if( i_read == 0 ) 
    683         { 
    684             if( i_try++ > 2 ) 
    685             { 
    686                 break; 
    687             } 
    688             msg_Dbg( p_input, "another try %d/2", i_try ); 
    689             continue; 
    690         } 
    691  
    692         if( i_read < 0 || p_input->b_die || p_input->b_error ) 
    693         { 
    694             break; 
    695         } 
    696         i_total += i_read; 
    697  
    698         p_sys->i_buffer += i_read; 
    699         if( i_total >= i_size ) 
    700         { 
    701             break; 
    702         } 
    703     } 
    704  
    705     p_sys->buffer[p_sys->i_buffer] = '\0'; 
    706  
    707     return i_total; 
    708 
    709  
    710 /**************************************************************************** 
    711  * NetOpenTCP: 
    712  ****************************************************************************/ 
    713 static input_socket_t * NetOpenTCP( input_thread_t *p_input, url_t *p_url ) 
    714 
    715     input_socket_t   *p_socket; 
    716     char             *psz_network; 
    717     module_t         *p_network; 
    718     network_socket_t socket_desc; 
    719  
    720  
    721     p_socket = malloc( sizeof( input_socket_t ) ); 
    722     memset( p_socket, 0, sizeof( input_socket_t ) ); 
    723  
    724     psz_network = ""; 
    725     if( config_GetInt( p_input, "ipv4" ) ) 
    726     { 
    727         psz_network = "ipv4"; 
    728     } 
    729     else if( config_GetInt( p_input, "ipv6" ) ) 
    730     { 
    731         psz_network = "ipv6"; 
    732     } 
    733  
    734     msg_Dbg( p_input, "waiting for connection..." ); 
    735  
    736     socket_desc.i_type = NETWORK_TCP; 
    737     socket_desc.psz_server_addr = p_url->psz_host; 
    738     socket_desc.i_server_port   = p_url->i_port; 
    739     socket_desc.psz_bind_addr   = ""; 
    740     socket_desc.i_bind_port     = 0; 
    741     socket_desc.i_ttl           = 0; 
    742     p_input->p_private = (void*)&socket_desc; 
    743     if( !( p_network = module_Need( p_input, "network", psz_network ) ) ) 
    744     { 
    745         msg_Err( p_input, "failed to connect with server" ); 
    746         return NULL; 
    747     } 
    748     module_Unneed( p_input, p_network ); 
    749     p_socket->i_handle = socket_desc.i_handle; 
    750     p_input->i_mtu     = socket_desc.i_mtu; 
    751  
    752     msg_Dbg( p_input, 
    753              "connection with \"%s:%d\" successful", 
    754              p_url->psz_host, 
    755              p_url->i_port ); 
    756  
    757     return p_socket; 
    758 
    759  
    760 /***************************************************************************** 
    761  * Read: read on a file descriptor, checking b_die periodically 
    762  *****************************************************************************/ 
    763 static ssize_t NetRead( input_thread_t *p_input, 
    764                         input_socket_t *p_socket, 
    765                         byte_t *p_buffer, size_t i_len ) 
    766 
    767     struct timeval  timeout; 
    768     fd_set          fds; 
    769     ssize_t         i_recv; 
    770     int             i_ret; 
    771  
    772     /* Initialize file descriptor set */ 
    773     FD_ZERO( &fds ); 
    774     FD_SET( p_socket->i_handle, &fds ); 
    775  
    776     /* We'll wait 1 second if nothing happens */ 
    777     timeout.tv_sec  = 1; 
    778     timeout.tv_usec = 0; 
    779  
    780     /* Find if some data is available */ 
    781     while( ( i_ret = select( p_socket->i_handle + 1, &fds, 
    782                              NULL, NULL, &timeout )) == 0 || 
    783 #ifdef HAVE_ERRNO_H 
    784            ( i_ret < 0 && errno == EINTR ) 
    785 #endif 
    786          ) 
    787     { 
    788         FD_ZERO( &fds ); 
    789         FD_SET( p_socket->i_handle, &fds ); 
    790         timeout.tv_sec  = 1; 
    791         timeout.tv_usec = 0; 
    792  
    793         if( p_input->b_die || p_input->b_error ) 
    794         { 
    795             return 0; 
    796         } 
    797     } 
    798  
    799     if( i_ret < 0 ) 
    800     { 
    801         msg_Err( p_input, "network select error (%s)", strerror(errno) ); 
    802         return -1; 
    803     } 
    804  
    805     i_recv = recv( p_socket->i_handle, p_buffer, i_len, 0 ); 
    806  
    807     if( i_recv < 0 ) 
    808     { 
    809         msg_Err( p_input, "recv failed (%s)", strerror(errno) ); 
    810     } 
    811  
    812     return i_recv; 
    813 
    814  
    815 static ssize_t NetWrite( input_thread_t *p_input, 
    816                          input_socket_t *p_socket, 
    817                          byte_t *p_buffer, size_t i_len ) 
    818 
    819     struct timeval  timeout; 
    820     fd_set          fds; 
    821     ssize_t         i_send; 
    822     int             i_ret; 
    823  
    824     /* Initialize file descriptor set */ 
    825     FD_ZERO( &fds ); 
    826     FD_SET( p_socket->i_handle, &fds ); 
    827  
    828     /* We'll wait 1 second if nothing happens */ 
    829     timeout.tv_sec  = 1; 
    830     timeout.tv_usec = 0; 
    831  
    832     /* Find if some data is available */ 
    833     while( ( i_ret = select( p_socket->i_handle + 1, NULL, &fds, NULL, &timeout ) ) == 0 || 
    834 #ifdef HAVE_ERRNO_H 
    835            ( i_ret < 0 && errno == EINTR ) 
    836 #endif 
    837          ) 
    838     { 
    839         FD_ZERO( &fds ); 
    840         FD_SET( p_socket->i_handle, &fds ); 
    841         timeout.tv_sec  = 1; 
    842         timeout.tv_usec = 0; 
    843  
    844         if( p_input->b_die || p_input->b_error ) 
    845         { 
    846             return 0; 
    847         } 
    848     } 
    849  
    850     if( i_ret < 0 ) 
    851     { 
    852         msg_Err( p_input, "network select error (%s)", strerror(errno) ); 
    853         return -1; 
    854     } 
    855  
    856     i_send = send( p_socket->i_handle, p_buffer, i_len, 0 ); 
    857  
    858     if( i_send < 0 ) 
    859     { 
    860         msg_Err( p_input, "send failed (%s)", strerror(errno) ); 
    861     } 
    862  
    863     return i_send; 
    864 
    865  
    866 static void NetClose( input_thread_t *p_input, input_socket_t *p_socket ) 
    867 
    868 #if defined( WIN32 ) || defined( UNDER_CE ) 
    869     closesocket( p_socket->i_handle ); 
    870 #else 
    871     close( p_socket->i_handle ); 
    872 #endif 
    873  
    874     free( p_socket ); 
    875 
    876  
     612    net_Close( p_sys->fd ); p_sys->fd = -1; 
     613
     614 
     615/***************************************************************************** 
     616 * 
     617 *****************************************************************************/ 
     618static int mmsh_get_packet( input_thread_t * p_input, chunk_t *p_ck ) 
     619
     620    access_sys_t *p_sys = p_input->p_access_data; 
     621 
     622    int i_mov = p_sys->i_buffer - p_sys->i_buffer_pos; 
     623 
     624    if( p_sys->i_buffer_pos > BUFFER_SIZE / 2 ) 
     625    { 
     626        if( i_mov > 0 ) 
     627        { 
     628            memmove( &p_sys->buffer[0], 
     629                     &p_sys->buffer[p_sys->i_buffer_pos], 
     630                     i_mov ); 
     631        } 
     632 
     633        p_sys->i_buffer     = i_mov; 
     634        p_sys->i_buffer_pos = 0; 
     635    } 
     636 
     637    if( NetFill( p_input, p_sys, 12 ) < 12 ) 
     638    { 
     639        msg_Warn( p_input, "cannot fill buffer" ); 
     640        return VLC_EGENERIC; 
     641    } 
     642 
     643    chunk_parse( p_ck, &p_sys->buffer[p_sys->i_buffer_pos], 
     644                 p_sys->i_buffer - p_sys->i_buffer_pos ); 
     645 
     646    if( p_ck->i_type == 0x4524 )   // Transfer complete 
     647    { 
     648        msg_Warn( p_input, "EOF" ); 
     649        return VLC_EGENERIC; 
     650    } 
     651    else if( p_ck->i_type != 0x4824 && p_ck->i_type != 0x4424 ) 
     652    { 
     653        msg_Err( p_input, "invalid chunk FATAL" ); 
     654        return VLC_EGENERIC; 
     655    } 
     656 
     657    if( p_ck->i_data < p_ck->i_size2 - 8 ) 
     658    { 
     659        if( NetFill( p_input, p_sys, p_ck->i_size2 - 8 - p_ck->i_data ) <= 0 ) 
     660        { 
     661            msg_Warn( p_input, "cannot fill buffer" ); 
     662            return VLC_EGENERIC; 
     663        } 
     664        chunk_parse( p_ck, &p_sys->buffer[p_sys->i_buffer_pos], 
     665                     p_sys->i_buffer - p_sys->i_buffer_pos ); 
     666    } 
     667 
     668    if( p_sys->i_packet_sequence != 0 && 
     669        p_ck->i_sequence != p_sys->i_packet_sequence ) 
     670    { 
     671        msg_Warn( p_input, "packet lost ?" ); 
     672    } 
     673 
     674    p_sys->i_packet_sequence = p_ck->i_sequence + 1; 
     675    p_sys->i_packet_used   = 0; 
     676    p_sys->i_packet_length = p_ck->i_data; 
     677    p_sys->p_packet        = p_ck->p_data; 
     678 
     679    p_sys->i_buffer_pos += 12 + p_ck->i_data; 
     680 
     681    return VLC_SUCCESS; 
     682
     683 
     684/***************************************************************************** 
     685 * 
     686 *****************************************************************************/ 
    877687static int http_next_line( uint8_t **pp_data, int *pi_data ) 
    878688{ 
     
    899709} 
    900710 
     711/***************************************************************************** 
     712 * 
     713 *****************************************************************************/ 
    901714static http_answer_t *http_answer_parse( uint8_t *p_data, int i_data ) 
    902715{ 
     
    982795} 
    983796 
     797/***************************************************************************** 
     798 * 
     799 *****************************************************************************/ 
    984800static void http_answer_free( http_answer_t *ans ) 
    985801{ 
     
    1002818} 
    1003819 
     820/***************************************************************************** 
     821 * 
     822 *****************************************************************************/ 
    1004823static http_field_t *http_field_find( http_field_t *p_field, char *psz_name ) 
    1005824{ 
     
    1018837} 
    1019838 
     839/***************************************************************************** 
     840 * 
     841 *****************************************************************************/ 
    1020842static int chunk_parse( chunk_t *ck, uint8_t *p_data, int i_data ) 
    1021843{ 
  • modules/access/mms/mmsh.h

    r217c4d9 r5deafc1  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001, 2002 VideoLAN 
    5  * $Id: mmsh.h,v 1.4 2003/08/26 00:51:19 fenrir Exp $ 
     5 * $Id: mmsh.h,v 1.5 2004/01/21 16:56:16 fenrir Exp $ 
    66 * 
    77 * Authors: Laurent Aimar <fenrir@via.ecp.fr> 
     
    3737} chunk_t; 
    3838 
    39 static int chunk_parse( chunk_t *, uint8_t *, int ); 
    40  
    4139#define BUFFER_SIZE 150000 
    4240struct access_sys_t 
     
    4442    int             i_proto; 
    4543 
    46     input_socket_t  *p_socket
     44    int             fd
    4745    url_t           *p_url; 
    4846 
     
    6967}; 
    7068 
    71 static input_socket_t * NetOpenTCP  ( input_thread_t *, url_t * ); 
    72 static ssize_t          NetRead     ( input_thread_t *, input_socket_t *, byte_t *, size_t ); 
    73 static ssize_t          NetWrite    ( input_thread_t *, input_socket_t *, byte_t *, size_t ); 
    74 static void             NetClose    ( input_thread_t *, input_socket_t * ); 
    75  
    76  
    77 static ssize_t NetFill( input_thread_t *, access_sys_t *, int ); 
    78  
    7969typedef struct http_field_s 
    8070{ 
     
    9989} http_answer_t; 
    10090 
    101 static http_answer_t    *http_answer_parse  ( uint8_t *, int ); 
    102 static void              http_answer_free   ( http_answer_t * ); 
    103 /* static char             *http_field_get_value   ( http_answer_t *, char * ); */ 
    104 static http_field_t     *http_field_find    ( http_field_t *, char * ); 
    10591 
    106 static int  mmsh_start( input_thread_t *, off_t ); 
    107 static void mmsh_stop ( input_thread_t * ); 
  • modules/access/mms/mmstu.c

    r0d39f13 r5deafc1  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001, 2002 VideoLAN 
    5  * $Id: mmstu.c,v 1.6 2003/07/31 23:44:49 fenrir Exp $ 
     5 * $Id: mmstu.c,v 1.7 2004/01/21 16:56:16 fenrir Exp $ 
    66 * 
    77 * Authors: Laurent Aimar <fenrir@via.ecp.fr> 
     
    8282static void    Seek        ( input_thread_t *, off_t ); 
    8383 
    84 static int    MMSOpen( input_thread_t  *, url_t *, int, char * ); 
     84static int    MMSOpen( input_thread_t  *, url_t *, int ); 
    8585 
    8686static int    MMSStart  ( input_thread_t  *, uint32_t ); 
     
    9696 
    9797static int     mms_ReceivePacket( input_thread_t * ); 
    98  
    99 //static void mms_ParseURL( url_t *p_url, char *psz_url ); 
    100  
    10198 
    10299 
     
    120117int  E_( MMSTUOpen )  ( input_thread_t *p_input ) 
    121118{ 
    122     access_sys_t    *p_sys; 
    123     int         i_proto; 
    124     char        *psz_network
    125     int         i_status
     119    access_sys_t   *p_sys; 
     120    int             i_proto; 
     121    int             i_status
     122    vlc_value_t val
    126123 
    127124    /* *** allocate p_sys_data *** */ 
     
    131128 
    132129    /* *** Parse URL and get server addr/port and path *** */ 
    133     //mms_ParseURL( &p_sys->url, p_input->psz_name ); 
    134130    p_sys->p_url = E_( url_new )( p_input->psz_name ); 
    135131 
     
    138134        E_( url_free )( p_sys->p_url ); 
    139135        msg_Err( p_input, "invalid server name" ); 
    140         return( -1 )
     136        return VLC_EGENERIC
    141137    } 
    142138    if( p_sys->p_url->i_port <= 0 ) 
     
    144140        p_sys->p_url->i_port = 1755; 
    145141    } 
    146 #if 0 
    147     if( p_sys->url.i_bind_port == 0 ) 
    148     { 
    149         p_sys->url.i_bind_port = 7000;   /* default port */ 
    150     } 
    151 #endif 
    152142 
    153143    /* *** connect to this server *** */ 
    154     /* 1: look at  requested protocol (udp/tcp) */ 
     144    /* look at  requested protocol (udp/tcp) */ 
    155145    i_proto = MMS_PROTO_AUTO; 
    156146    if( *p_input->psz_access ) 
     
    165155        } 
    166156    } 
    167     /* 2: look at ip version ipv4/ipv6 */ 
    168     psz_network = ""; 
    169     if( config_GetInt( p_input, "ipv4" ) ) 
    170     { 
    171         psz_network = "ipv4"; 
    172     } 
    173     else if( config_GetInt( p_input, "ipv6" ) ) 
    174     { 
    175         psz_network = "ipv6"; 
    176     } 
    177     /* 3: connect */ 
     157 
     158    /* connect */ 
    178159    if( i_proto == MMS_PROTO_AUTO ) 
    179160    {   /* first try with TCP */ 
    180         i_status = 
    181             MMSOpen( p_input, p_sys->p_url, MMS_PROTO_TCP, psz_network ); 
    182         if( i_status < 0 ) 
     161        if( ( i_status = MMSOpen( p_input, p_sys->p_url, MMS_PROTO_TCP ) ) ) 
    183162        {   /* then with UDP */ 
    184             i_status = 
    185              MMSOpen( p_input, p_sys->p_url, MMS_PROTO_UDP, psz_network ); 
     163            i_status = MMSOpen( p_input, p_sys->p_url, MMS_PROTO_UDP ); 
    186164        } 
    187165    } 
    188166    else 
    189167    { 
    190  
    191         i_status = 
    192             MMSOpen( p_input, p_sys->p_url, i_proto, psz_network ); 
    193     } 
    194  
    195     if( i_status < 0 ) 
     168        i_status = MMSOpen( p_input, p_sys->p_url, i_proto ); 
     169    } 
     170 
     171    if( i_status ) 
    196172    { 
    197173        msg_Err( p_input, "cannot connect to server" ); 
    198174        E_( url_free )( p_sys->p_url ); 
    199         return( -1 ); 
    200     } 
     175        return VLC_EGENERIC; 
     176    } 
     177 
    201178    msg_Dbg( p_input, "connected to %s:%d", p_sys->p_url->psz_host, p_sys->p_url->i_port ); 
    202  
    203179 
    204180    /* *** set exported functions *** */ 
     
    242218        MMSClose( p_input ); 
    243219        E_( url_free )( p_sys->p_url ); 
    244         return( -1 )
     220        return VLC_EGENERIC
    245221    } 
    246222 
    247223    /* Update default_pts to a suitable value for mms access */ 
    248     p_input->i_pts_delay = config_GetInt( p_input, "mms-caching" ) * 1000; 
    249  
    250     return( 0 ); 
     224    var_Get( p_input, "mms-caching", &val ); 
     225    p_input->i_pts_delay = val.i_int * 1000; 
     226 
     227    return VLC_SUCCESS; 
    251228} 
    252229 
     
    420397 * MMSOpen : Open a connection with the server over mmst or mmsu 
    421398 ****************************************************************************/ 
    422 static int MMSOpen( input_thread_t  *p_input, 
    423                     url_t *p_url, 
    424                     int  i_proto, 
    425                     char *psz_network ) /* "", "ipv4", "ipv6" */ 
     399static int MMSOpen( input_thread_t  *p_input, url_t *p_url, int  i_proto ) 
    426400{ 
    427     module_t    *p_network; 
    428401    access_sys_t    *p_sys = p_input->p_access_data; 
    429  
    430     network_socket_t    socket_desc; 
    431     int b_udp = ( i_proto == MMS_PROTO_UDP ) ? 1 : 0; 
     402    int             b_udp = ( i_proto == MMS_PROTO_UDP ) ? 1 : 0; 
    432403 
    433404    var_buffer_t buffer; 
     
    445416    /* *** Open a TCP connection with server *** */ 
    446417    msg_Dbg( p_input, "waiting for connection..." ); 
    447     socket_desc.i_type = NETWORK_TCP; 
    448     socket_desc.psz_server_addr = p_url->psz_host; 
    449     socket_desc.i_server_port   = p_url->i_port; 
    450     socket_desc.psz_bind_addr   = ""; 
    451     socket_desc.i_bind_port     = 0; 
    452     socket_desc.i_ttl           = 0; 
    453     p_input->p_private = (void*)&socket_desc; 
    454     if( !( p_network = module_Need( p_input, "network", psz_network ) ) ) 
     418    p_sys->socket_tcp.i_handle = net_OpenTCP( p_input, p_url->psz_host, p_url->i_port ); 
     419    if( p_sys->socket_tcp.i_handle < 0 ) 
    455420    { 
    456421        msg_Err( p_input, "failed to open a connection (tcp)" ); 
    457         return( -1 ); 
    458     } 
    459     module_Unneed( p_input, p_network ); 
    460     p_sys->socket_tcp.i_handle = socket_desc.i_handle; 
    461     p_input->i_mtu    = 0; /*socket_desc.i_mtu;*/ 
     422        return VLC_EGENERIC; 
     423    } 
     424    p_input->i_mtu = 0; 
    462425    msg_Dbg( p_input, 
    463426             "connection(tcp) with \"%s:%d\" successful", 
     
    476439 
    477440            msg_Err( p_input, "for udp you have to provide bind address (mms://<server_addr>@<bind_addr/<path> (FIXME)" ); 
    478 #if defined( UNDER_CE ) 
    479             CloseHandle( (HANDLE)p_sys->socket_tcp.i_handle ); 
    480 #elif defined( WIN32 ) 
    481             closesocket( p_sys->socket_tcp.i_handle ); 
    482 #else 
    483             close( p_sys->socket_tcp.i_handle ); 
    484 #endif 
    485             return( -1 ); 
     441            net_Close( p_sys->socket_tcp.i_handle ); 
     442            return VLC_EGENERIC; 
    486443        } 
    487444        p_sys->psz_bind_addr = inet_ntoa( name.sin_addr ); 
    488445 
    489         socket_desc.i_type = NETWORK_UDP; 
    490         socket_desc.psz_server_addr = ""; 
    491         socket_desc.i_server_port   = 0; 
    492         socket_desc.psz_bind_addr   = p_sys->psz_bind_addr; 
    493         socket_desc.i_bind_port     = 7000; //p_url->i_bind_port; FIXME 
    494         socket_desc.i_ttl           = 0; 
    495         p_input->p_private = (void*)&socket_desc; 
    496         if( !( p_network = module_Need( p_input, "network", psz_network ) ) ) 
     446        p_sys->socket_udp.i_handle = net_OpenUDP( p_input, p_sys->psz_bind_addr, 7000, "", 0 ); 
     447        if( p_sys->socket_udp.i_handle < 0 ) 
    497448        { 
    498449            msg_Err( p_input, "failed to open a connection (udp)" ); 
    499 #if defined( UNDER_CE ) 
    500             CloseHandle( (HANDLE)p_sys->socket_tcp.i_handle ); 
    501 #elif defined( WIN32 ) 
    502             closesocket( p_sys->socket_tcp.i_handle ); 
    503 #else 
    504             close( p_sys->socket_tcp.i_handle ); 
    505 #endif 
    506             return( -1 ); 
    507         } 
    508         module_Unneed( p_input, p_network ); 
    509         p_sys->socket_udp.i_handle = socket_desc.i_handle; 
    510         p_input->i_mtu    = 0;/*socket_desc.i_mtu;  FIXME */ 
    511  
     450            net_Close( p_sys->socket_tcp.i_handle ); 
     451            return VLC_EGENERIC; 
     452        } 
    512453        msg_Dbg( p_input, 
    513454                 "connection(udp) at \"%s:%d\" successful", 
    514                  p_sys->psz_bind_addr, 
    515                  7000 ); 
     455                 p_sys->psz_bind_addr, 7000 ); 
    516456    } 
    517457    else 
     
    565505        var_buffer_free( &buffer ); 
    566506        MMSClose( p_input ); 
    567         return( -1 )
     507        return VLC_EGENERIC
    568508    } 
    569509 
     
    632572        var_buffer_free( &buffer ); 
    633573        MMSClose( p_input ); 
    634         return( -1 )
     574        return VLC_EGENERIC
    635575    } 
    636576    else if( p_sys->i_command != 0x02 ) 
     
    661601        var_buffer_free( &buffer ); 
    662602        MMSClose( p_input ); 
    663         return( -1 )
     603        return VLC_EGENERIC
    664604    } 
    665605    if( p_sys->i_command != 0x06 ) 
     
    688628        var_buffer_free( &buffer ); 
    689629        MMSClose( p_input ); 
    690         return( -1 )
     630        return VLC_EGENERIC
    691631    } 
    692632 
     
    757697            var_buffer_free( &buffer ); 
    758698            MMSClose( p_input ); 
    759             return( -1 )
     699            return VLC_EGENERIC
    760700        } 
    761701        if( p_sys->i_header >= p_sys->i_header_size ) 
     
    835775        var_buffer_free( &buffer ); 
    836776        MMSClose( p_input ); 
    837         return( -1 )
     777        return VLC_EGENERIC
    838778    } 
    839779    mms_CommandSend( p_input, 0x33, 
     
    850790        var_buffer_free( &buffer ); 
    851791        MMSClose( p_input ); 
    852         return( -1 )
     792        return VLC_EGENERIC
    853793    } 
    854794 
     
    858798    msg_Info( p_input, "connection sucessful" ); 
    859799 
    860     return( 0 )
     800    return VLC_SUCCESS
    861801} 
    862802 
     
    934874                     0x00000001, 
    935875                     NULL, 0 ); 
     876 
    936877    /* *** close sockets *** */ 
    937 #if defined( UNDER_CE ) 
    938     CloseHandle( (HANDLE)p_sys->socket_tcp.i_handle ); 
    939 #elif defined( WIN32 ) 
    940     closesocket( p_sys->socket_tcp.i_handle ); 
    941 #else 
    942     close( p_sys-&