Changeset 395cdfc1a82b88656241df8bc894d12d8995e63c
- Timestamp:
- 27/05/04 01:15:07 (5 years ago)
- git-parent:
- Files:
-
- modules/demux/sgimb.c (modified) (1 diff)
- modules/misc/sap.c (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/demux/sgimb.c
r71e657c r395cdfc 329 329 if( p_sys->i_packet_size && p_sys->psz_mcast_ip ) 330 330 { 331 char *psz_option = (char *) malloc( 20 );331 char *psz_option; 332 332 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 ); 334 334 playlist_ItemAddOption( p_item, psz_option ); 335 335 free( psz_option ); modules/misc/sap.c
rfdb4685 r395cdfc 85 85 * Module descriptor 86 86 *****************************************************************************/ 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" ) 90 90 #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" ) 96 96 #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)" ) 99 99 #define SAP_TIMEOUT_LONGTEXT N_( \ 100 100 "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" ) 103 103 #define SAP_PARSE_LONGTEXT N_( \ 104 104 "When SAP can it will try to parse the SAP. Normal behavior is " \ … … 114 114 SAP_ADDR_TEXT, SAP_ADDR_LONGTEXT, VLC_TRUE ); 115 115 add_bool( "sap-ipv4", 1 , NULL, 116 SAP_IPV4_TEXT,SAP_IPV4_LONGTEXT, VLC_TRUE );116 SAP_IPV4_TEXT,SAP_IPV4_LONGTEXT, VLC_TRUE ); 117 117 add_bool( "sap-ipv6", 0 , NULL, 118 SAP_IPV6_TEXT, SAP_IPV6_LONGTEXT, VLC_TRUE );118 SAP_IPV6_TEXT, SAP_IPV6_LONGTEXT, VLC_TRUE ); 119 119 add_string( "sap-ipv6-scope", "8" , NULL, 120 120 SAP_SCOPE_TEXT, SAP_SCOPE_LONGTEXT, VLC_TRUE); 121 121 add_integer( "sap-timeout", 1800, NULL, 122 SAP_TIMEOUT_TEXT, SAP_TIMEOUT_LONGTEXT, VLC_TRUE );122 SAP_TIMEOUT_TEXT, SAP_TIMEOUT_LONGTEXT, VLC_TRUE ); 123 123 add_bool( "sap-parse", 1 , NULL, 124 SAP_PARSE_TEXT,SAP_PARSE_LONGTEXT, VLC_TRUE );124 SAP_PARSE_TEXT,SAP_PARSE_LONGTEXT, VLC_TRUE ); 125 125 126 126 set_capability( "interface", 0 ); … … 198 198 199 199 #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; 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 { 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; 237 241 } 238 242 #endif … … 243 247 static int Open( vlc_object_t *p_this ) 244 248 { 245 intf_thread_t *p_intf = ( intf_thread_t*)p_this;249 intf_thread_t *p_intf = ( intf_thread_t* )p_this; 246 250 intf_sys_t *p_sys = malloc( sizeof( intf_sys_t ) ); 247 251 248 252 playlist_t *p_playlist; 249 253 250 p_sys->i_timeout = config_GetInt( p_intf,"sap-timeout");254 p_sys->i_timeout = config_GetInt( p_intf,"sap-timeout" ); 251 255 p_sys->fd[0] = -1; 252 256 p_sys->fd[1] = -1; … … 268 272 sock.i_server_port = 0; 269 273 sock.i_ttl = 0; 270 p_intf->p_private = ( void*) &sock;274 p_intf->p_private = ( void* ) &sock; 271 275 272 276 p_network = module_Need( p_intf, "network", "ipv4", VLC_TRUE ); … … 348 352 static void Close( vlc_object_t *p_this ) 349 353 { 350 intf_thread_t *p_intf = ( intf_thread_t*)p_this;354 intf_thread_t *p_intf = ( intf_thread_t* )p_this; 351 355 intf_sys_t *p_sys = p_intf->p_sys; 352 356 int i; … … 387 391 uint8_t *p_end; 388 392 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 ); 391 395 392 396 /* read SAP packets */ … … 410 414 { 411 415 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; 413 417 if( mdate() - p_intf->p_sys->pp_announces[i]->i_last > i_timeout ) 414 418 { 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 ); 418 422 419 423 /* Remove the playlist item */ … … 463 467 if( i_version != 1 ) 464 468 { 465 msg_ Warn( p_intf, "strange sap version %d found", i_version );469 msg_Dbg( p_intf, "strange sap version %d found", i_version ); 466 470 } 467 471 i_address_type = buffer[0] & 0x10; … … 469 473 if( b_reserved != 0 ) 470 474 { 471 msg_ Warn( p_intf, "reserved bit incorrectly set" );475 msg_Dbg( p_intf, "reserved bit incorrectly set" ); 472 476 } 473 477 b_message_type = buffer[0] & 0x04; 474 478 if( b_message_type != 0 ) 475 479 { 476 msg_ Warn( p_intf, "got session deletion packet" );480 msg_Dbg( p_intf, "got session deletion packet" ); 477 481 } 478 482 b_encrypted = buffer[0] & 0x02; 479 483 if( b_encrypted ) 480 484 { 481 msg_ Warn( p_intf, "encrypted packet" );485 msg_Dbg( p_intf, "encrypted packet" ); 482 486 } 483 487 b_compressed = buffer[0] & 0x01; … … 494 498 { 495 499 #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 ) ); 497 502 if( i_decompressed_size > 0 && i_decompressed_size < MAX_SAP_BUFFER ) 498 503 { … … 542 547 static void cfield_parse( char *psz_cfield, char **ppsz_uri ) 543 548 { 544 545 549 char *psz_pos; 546 550 if( psz_cfield ) … … 573 577 574 578 return; 575 576 579 } 577 580 … … 668 671 for( i = 0 ; i< p_intf->p_sys->i_announces ; i++ ) 669 672 { 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 ) ) 672 675 { 673 676 p_intf->p_sys->pp_announces[i]->i_last = mdate(); 674 free( psz_uri);677 free( psz_uri ); 675 678 return; 676 679 } … … 688 691 689 692 /* 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 ) ); 692 695 if( p_sd->psz_sessionname ) 693 696 { … … 724 727 { 725 728 int i_group = p_intf->p_sys->i_group; 729 int i_packetsize = config_GetInt( p_intf, "mtu" ); 726 730 727 731 /* Build what we have to put in psz_item_uri, with the m and … … 758 762 for( i = 0 ; i< p_sd->i_attributes ; i++ ) 759 763 { 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" ) ) 762 766 { 763 767 b_http = VLC_TRUE; 764 768 } 765 if( !strcasecmp( p_sd->pp_attributes[i]->psz_field , "http-path"))769 if( !strcasecmp( p_sd->pp_attributes[i]->psz_field , "http-path" ) ) 766 770 { 767 771 psz_http_path = strdup( p_sd->pp_attributes[i]->psz_value ); 768 772 } 769 if( !strcasecmp( p_sd->pp_attributes[i]->psz_field , "plgroup"))773 if( !strcasecmp( p_sd->pp_attributes[i]->psz_field , "plgroup" ) ) 770 774 { 771 775 int i_group_id; … … 779 783 780 784 i_group_id = playlist_GroupToId( p_playlist, 781 p_sd->pp_attributes[i]->psz_value );785 p_sd->pp_attributes[i]->psz_value ); 782 786 if( i_group_id != 0 ) 783 787 { … … 788 792 playlist_group_t *p_group = 789 793 playlist_CreateGroup( p_playlist, 790 p_sd->pp_attributes[i]->psz_value );794 p_sd->pp_attributes[i]->psz_value ); 791 795 i_group = p_group->i_id; 792 796 } 793 797 vlc_object_release( p_playlist ); 794 798 } 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 } 795 803 } 796 804 … … 798 806 if( b_http == VLC_FALSE ) 799 807 { 800 psz_item_uri = malloc( strlen( psz_proto ) + strlen( psz_uri ) +801 strlen( psz_port ) + 7 );802 808 if( ismult( psz_uri ) ) 803 809 { 804 sprintf(psz_item_uri, "%s://@%s:%s",810 asprintf( &psz_item_uri, "%s://@%s:%s", 805 811 psz_proto, psz_uri, psz_port ); 806 812 } 807 813 else 808 814 { 809 sprintf(psz_item_uri, "%s://%s:%s",815 asprintf( &psz_item_uri, "%s://%s:%s", 810 816 psz_proto, psz_uri, psz_port ); 811 817 } … … 859 865 860 866 /* 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 } 864 875 865 876 /* Update the stored name */ … … 879 890 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, 880 891 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 885 895 if( p_item ) 886 896 { 887 vlc_mutex_lock( &p_item->input.lock );888 897 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 ); 890 906 } 891 907 892 908 /* Then remember it */ 893 909 p_announce = (struct sap_announce_t *)malloc( 894 sizeof( struct sap_announce_t) );910 sizeof( struct sap_announce_t ) ); 895 911 if( p_sd->psz_sessionname ) 896 912 { … … 935 951 if( p_packet[0] != 'v' || p_packet[1] != '=' ) 936 952 { 937 msg_Warn( p_intf, "bad SDP packet");953 msg_Warn( p_intf, "bad SDP packet" ); 938 954 return NULL; 939 955 } … … 963 979 psz_end = p_packet + strlen( p_packet ); 964 980 } 965 if( psz_end > p_packet && *( psz_end - 1 ) == '\r' )981 if( psz_end > p_packet && *( psz_end - 1 ) == '\r' ) 966 982 { 967 983 psz_end--; … … 976 992 if( p_packet[1] != '=' ) 977 993 { 978 msg_Warn( p_intf, "invalid packet" ) ;994 msg_Warn( p_intf, "invalid packet" ) ; 979 995 free_sd( sd ); 980 996 return NULL; … … 1101 1117 } 1102 1118 1103 1104 1105 1119 /***************************************************************************** 1106 * Read: read on a file descriptor, checking b_die periodically1120 * NetRead: read on a file descriptor, checking b_die periodically 1107 1121 ***************************************************************************** 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. 1109 1125 *****************************************************************************/ 1110 1126 static ssize_t NetRead( intf_thread_t *p_intf, … … 1120 1136 1121 1137 /* Initialize file descriptor set */ 1138 1122 1139 FD_ZERO( &fds ); 1123 1140 if( fd[0] > 0 ) FD_SET( fd[0], &fds );
