sdpplin_t *sdpplin_parse(char *data) { sdpplin_t* desc; sdpplin_stream_t* stream; char* buf; char* decoded; int handled; desc = (sdpplin_t *)calloc( 1, sizeof(sdpplin_t) ); // sunqueen modify if( !desc ) return NULL; buf = (char *)malloc( BUFLEN ); // sunqueen modify if( !buf ) { free( desc ); return NULL; } decoded = (char *)malloc( BUFLEN ); // sunqueen modify if( !decoded ) { free( buf ); free( desc ); return NULL; } desc->stream = NULL; while (data && *data) { handled=0; if (filter(data, "m=", &buf, BUFLEN)) { if ( !desc->stream ) { fprintf(stderr, "sdpplin.c: stream identifier found before stream count, skipping."); continue; } stream=sdpplin_parse_stream(&data); lprintf("got data for stream id %u\n", stream->stream_id); if ( stream->stream_id >= desc->stream_count ) lprintf("stream id %u is greater than stream count %u\n", stream->stream_id, desc->stream_count); else desc->stream[stream->stream_id]=stream; continue; } if(filter(data,"a=Title:buffer;",&buf, BUFLEN)) { desc->title=vlc_b64_decode(buf); if(desc->title) { handled=1; data=nl(data); } } if(filter(data,"a=Author:buffer;",&buf, BUFLEN)) { desc->author=vlc_b64_decode(buf); if(desc->author) { handled=1; data=nl(data); } } if(filter(data,"a=Copyright:buffer;",&buf, BUFLEN)) { desc->copyright=vlc_b64_decode(buf); if(desc->copyright) { handled=1; data=nl(data); } } if(filter(data,"a=Abstract:buffer;",&buf, BUFLEN)) { desc->abstract=vlc_b64_decode(buf); if(desc->abstract) { handled=1; data=nl(data); } } if(filter(data,"a=StreamCount:integer;",&buf, BUFLEN)) { /* This way negative values are mapped to unfeasibly high * values, and will be discarded afterward */ unsigned long tmp = strtoul(buf, NULL, 10); if ( tmp > UINT16_MAX ) lprintf("stream count out of bound: %lu\n", tmp); else desc->stream_count = tmp; desc->stream = (sdpplin_stream_t **)malloc(sizeof(sdpplin_stream_t*)*desc->stream_count); // sunqueen modify handled=1; data=nl(data); } if(filter(data,"a=Flags:integer;",&buf, BUFLEN)) { desc->flags=atoi(buf); handled=1; data=nl(data); } if(!handled) { #ifdef LOG int len=strchr(data,'\n')-data; memcpy(buf, data, len+1); buf[len]=0; printf("libreal: sdpplin: not handled: '%s'\n", buf); #endif data=nl(data); } } free( decoded ); free( buf ); return desc; }
/* Take an url key and splits it into vlc_keystore_entry values */ static int key2values( char* psz_key, vlc_keystore_entry* p_entry ) { vlc_url_t url; int i_ret = VLC_ENOMEM; for ( int inc = 0 ; inc < KEY_MAX ; ++inc ) p_entry->ppsz_values[inc] = NULL; vlc_UrlParse( &url, psz_key ); if ( url.psz_protocol && !( p_entry->ppsz_values[KEY_PROTOCOL] = strdup( url.psz_protocol ) ) ) goto end; if ( url.psz_username && !( p_entry->ppsz_values[KEY_USER] = strdup( url.psz_username ) ) ) goto end; if ( url.psz_host && !( p_entry->ppsz_values[KEY_SERVER] = strdup( url.psz_host ) ) ) goto end; if ( url.i_port && asprintf( &p_entry->ppsz_values[KEY_PORT], "%d", url.i_port) == -1 ) goto end; if ( url.psz_path && !( p_entry->ppsz_values[KEY_PATH] = strdup( url.psz_path ) ) ) goto end; if ( url.psz_option ) { char *p_savetpr; for ( const char *psz_option = strtok_r( url.psz_option, "&", &p_savetpr ); psz_option != NULL; psz_option = strtok_r( NULL, "&", &p_savetpr ) ) { enum vlc_keystore_key key; const char *psz_value; if ( !strncmp( psz_option, "realm=", strlen( "realm=" ) ) ) { key = KEY_REALM; psz_value = psz_option + strlen( "realm=" ); } else if ( !strncmp( psz_option, "authtype=", strlen( "authtype=" ) ) ) { key = KEY_AUTHTYPE; psz_value = psz_option + strlen( "authtype=" ); } else psz_value = NULL; if ( psz_value != NULL ) { p_entry->ppsz_values[key] = vlc_b64_decode( psz_value ); if ( !p_entry->ppsz_values[key] ) goto end; } } } i_ret = VLC_SUCCESS; end: vlc_UrlClean( &url ); if ( i_ret ) { free( p_entry->ppsz_values[KEY_PROTOCOL] ); free( p_entry->ppsz_values[KEY_USER] ); free( p_entry->ppsz_values[KEY_SERVER] ); free( p_entry->ppsz_values[KEY_PORT] ); free( p_entry->ppsz_values[KEY_PATH] ); free( p_entry->ppsz_values[KEY_REALM] ); free ( p_entry->ppsz_values[KEY_AUTHTYPE] ); } return i_ret; }