summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
Diffstat (limited to 'stream')
-rw-r--r--stream/asf_streaming.c6
-rw-r--r--stream/cookies.c25
-rw-r--r--stream/http.c43
-rw-r--r--stream/network.c10
-rw-r--r--stream/network.h3
-rw-r--r--stream/stream_udp.c6
-rw-r--r--stream/tcp.c12
-rw-r--r--stream/tv.c57
-rw-r--r--stream/udp.c14
9 files changed, 87 insertions, 89 deletions
diff --git a/stream/asf_streaming.c b/stream/asf_streaming.c
index f81b5dd983..e7ca8468db 100644
--- a/stream/asf_streaming.c
+++ b/stream/asf_streaming.c
@@ -825,8 +825,6 @@ err_out:
}
static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
- URL_t *url;
-
stream->streaming_ctrl = streaming_ctrl_new();
if( stream->streaming_ctrl==NULL ) {
return STREAM_ERROR;
@@ -834,9 +832,7 @@ static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
stream->streaming_ctrl->audio_id_ptr = &stream->opts->audio_id;
stream->streaming_ctrl->video_id_ptr = &stream->opts->video_id;
stream->streaming_ctrl->bandwidth = network_bandwidth;
- url = url_new(stream->url);
- stream->streaming_ctrl->url = check4proxies(url);
- url_free(url);
+ stream->streaming_ctrl->url = url_new_with_proxy(stream->url);
mp_tmsg(MSGT_OPEN, MSGL_INFO, "STREAM_ASF, URL: %s\n", stream->url);
if((!strncmp(stream->url, "http", 4)) && (*file_format!=DEMUXER_TYPE_ASF && *file_format!=DEMUXER_TYPE_UNKNOWN)) {
diff --git a/stream/cookies.c b/stream/cookies.c
index 2680bf1834..62025b157b 100644
--- a/stream/cookies.c
+++ b/stream/cookies.c
@@ -112,44 +112,49 @@ static int parse_line(char **ptr, char *cols[6])
/* Loads a file into RAM */
static char *load_file(const char *filename, off_t * length)
{
- int fd;
- char *buffer;
+ int fd = -1;
+ char *buffer = NULL;
mp_msg(MSGT_NETWORK, MSGL_V, "Loading cookie file: %s\n", filename);
fd = open(filename, O_RDONLY);
if (fd < 0) {
mp_msg(MSGT_NETWORK, MSGL_V, "Could not open");
- return NULL;
+ goto err_out;
}
*length = lseek(fd, 0, SEEK_END);
if (*length < 0) {
mp_msg(MSGT_NETWORK, MSGL_V, "Could not find EOF");
- return NULL;
+ goto err_out;
}
if (*length > SIZE_MAX - 1) {
mp_msg(MSGT_NETWORK, MSGL_V, "File too big, could not malloc.");
- return NULL;
+ goto err_out;
}
lseek(fd, 0, SEEK_SET);
if (!(buffer = malloc(*length + 1))) {
mp_msg(MSGT_NETWORK, MSGL_V, "Could not malloc.");
- return NULL;
+ goto err_out;
}
if (read(fd, buffer, *length) != *length) {
mp_msg(MSGT_NETWORK, MSGL_V, "Read is behaving funny.");
- return NULL;
+ goto err_out;
}
close(fd);
buffer[*length] = 0;
return buffer;
+
+err_out:
+ if (fd != -1) close(fd);
+ free(buffer);
+ return NULL;
}
/* Loads a cookies.txt file into a linked list. */
@@ -164,7 +169,7 @@ static struct cookie_list_type *load_cookies_from(const char *filename,
if (!ptr)
return list;
- while (*ptr > 0) {
+ while (*ptr) {
char *cols[7];
if (parse_line(&ptr, cols)) {
struct cookie_list_type *new;
@@ -178,6 +183,7 @@ static struct cookie_list_type *load_cookies_from(const char *filename,
list = new;
}
}
+ free(ptr);
return list;
}
@@ -253,6 +259,5 @@ cookies_set(HTTP_header_t * http_hdr, const char *domain, const char *url)
if (found_cookies)
http_set_field(http_hdr, buf);
- else
- free(buf);
+ free(buf);
}
diff --git a/stream/http.c b/stream/http.c
index a6d977c10a..1638d80790 100644
--- a/stream/http.c
+++ b/stream/http.c
@@ -223,7 +223,6 @@ static int scast_streaming_start(stream_t *stream) {
static int nop_streaming_start( stream_t *stream ) {
HTTP_header_t *http_hdr = NULL;
char *next_url=NULL;
- URL_t *rd_url=NULL;
int fd,ret;
if( stream==NULL ) return -1;
@@ -253,12 +252,9 @@ static int nop_streaming_start( stream_t *stream ) {
ret=-1;
next_url = http_get_field( http_hdr, "Location" );
- if (next_url != NULL)
- rd_url=url_new(next_url);
-
- if (next_url != NULL && rd_url != NULL) {
+ if (next_url != NULL) {
mp_msg(MSGT_NETWORK,MSGL_STATUS,"Redirected: Using this url instead %s\n",next_url);
- stream->streaming_ctrl->url=check4proxies(rd_url);
+ stream->streaming_ctrl->url=url_new_with_proxy(next_url);
ret=nop_streaming_start(stream); //recursively get streaming started
} else {
mp_msg(MSGT_NETWORK,MSGL_ERR,"Redirection failed\n");
@@ -402,7 +398,7 @@ http_response_parse( HTTP_header_t *http_hdr ) {
// Get the reason phrase
ptr = strstr( hdr_ptr, "\n" );
- if( hdr_ptr==NULL ) {
+ if( ptr==NULL ) {
mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. Unable to get the reason phrase.\n");
return -1;
}
@@ -463,24 +459,20 @@ http_response_parse( HTTP_header_t *http_hdr ) {
char *
http_build_request( HTTP_header_t *http_hdr ) {
- char *ptr, *uri;
+ char *ptr;
int len;
HTTP_field_t *field;
if( http_hdr==NULL ) return NULL;
if( http_hdr->uri==NULL ) return NULL;
if( http_hdr->method==NULL ) http_set_method( http_hdr, "GET");
-
- uri = malloc(strlen(http_hdr->uri) + 1);
- if( uri==NULL ) {
- mp_msg(MSGT_NETWORK,MSGL_ERR,"Memory allocation failed\n");
- return NULL;
- }
- strcpy(uri,http_hdr->uri);
+ if( http_hdr->uri==NULL ) http_set_uri( http_hdr, "/");
+ if( !http_hdr->uri || !http_hdr->method)
+ return NULL;
//**** Compute the request length
// Add the Method line
- len = strlen(http_hdr->method)+strlen(uri)+12;
+ len = strlen(http_hdr->method)+strlen(http_hdr->uri)+12;
// Add the fields
field = http_hdr->first_field;
while( field!=NULL ) {
@@ -508,7 +500,7 @@ http_build_request( HTTP_header_t *http_hdr ) {
//*** Building the request
ptr = http_hdr->buffer;
// Add the method line
- ptr += sprintf( ptr, "%s %s HTTP/1.%d\r\n", http_hdr->method, uri, http_hdr->http_minor_version );
+ ptr += sprintf( ptr, "%s %s HTTP/1.%d\r\n", http_hdr->method, http_hdr->uri, http_hdr->http_minor_version );
field = http_hdr->first_field;
// Add the field
while( field!=NULL ) {
@@ -521,7 +513,6 @@ http_build_request( HTTP_header_t *http_hdr ) {
memcpy( ptr, http_hdr->body, http_hdr->body_size );
}
- free(uri);
return http_hdr->buffer;
}
@@ -726,7 +717,7 @@ static int http_streaming_start(stream_t *stream, int* file_format) {
do
{
redirect = 0;
- if (fd > 0) closesocket(fd);
+ if (fd >= 0) closesocket(fd);
fd = http_send_request( url, 0 );
if( fd<0 ) {
goto err_out;
@@ -856,12 +847,12 @@ static int http_streaming_start(stream_t *stream, int* file_format) {
} while( redirect );
err_out:
- if (fd > 0) closesocket( fd );
+ if (fd >= 0) closesocket( fd );
fd = -1;
http_free( http_hdr );
http_hdr = NULL;
out:
- stream->streaming_ctrl->data = (void*)http_hdr;
+ stream->streaming_ctrl->data = http_hdr;
stream->fd = fd;
return res;
}
@@ -895,16 +886,13 @@ static int fixup_open(stream_t *stream,int seekable) {
static int open_s1(stream_t *stream,int mode, void* opts, int* file_format) {
int seekable=0;
- URL_t *url;
stream->streaming_ctrl = streaming_ctrl_new();
if( stream->streaming_ctrl==NULL ) {
return STREAM_ERROR;
}
stream->streaming_ctrl->bandwidth = network_bandwidth;
- url = url_new(stream->url);
- stream->streaming_ctrl->url = check4proxies(url);
- url_free(url);
+ stream->streaming_ctrl->url = url_new_with_proxy(stream->url);
mp_msg(MSGT_OPEN, MSGL_V, "STREAM_HTTP(1), URL: %s\n", stream->url);
seekable = http_streaming_start(stream, file_format);
@@ -924,16 +912,13 @@ static int open_s1(stream_t *stream,int mode, void* opts, int* file_format) {
static int open_s2(stream_t *stream,int mode, void* opts, int* file_format) {
int seekable=0;
- URL_t *url;
stream->streaming_ctrl = streaming_ctrl_new();
if( stream->streaming_ctrl==NULL ) {
return STREAM_ERROR;
}
stream->streaming_ctrl->bandwidth = network_bandwidth;
- url = url_new(stream->url);
- stream->streaming_ctrl->url = check4proxies(url);
- url_free(url);
+ stream->streaming_ctrl->url = url_new_with_proxy(stream->url);
mp_msg(MSGT_OPEN, MSGL_V, "STREAM_HTTP(2), URL: %s\n", stream->url);
seekable = http_streaming_start(stream, file_format);
diff --git a/stream/network.c b/stream/network.c
index c324017d48..b23ed8ef02 100644
--- a/stream/network.c
+++ b/stream/network.c
@@ -106,7 +106,7 @@ streaming_ctrl_free( streaming_ctrl_t *streaming_ctrl ) {
}
URL_t*
-check4proxies( URL_t *url ) {
+check4proxies( const URL_t *url ) {
URL_t *url_out = NULL;
if( url==NULL ) return NULL;
url_out = url_new( url->url );
@@ -161,6 +161,14 @@ check4proxies( URL_t *url ) {
return url_out;
}
+URL_t *url_new_with_proxy(const char *urlstr)
+{
+ URL_t *url = url_new(urlstr);
+ URL_t *url_with_proxy = check4proxies(url);
+ url_free(url);
+ return url_with_proxy;
+}
+
int
http_send_request( URL_t *url, off_t pos ) {
HTTP_header_t *http_hdr;
diff --git a/stream/network.h b/stream/network.h
index 33b668c516..96d486e910 100644
--- a/stream/network.h
+++ b/stream/network.h
@@ -74,7 +74,8 @@ int http_send_request(URL_t *url, off_t pos);
HTTP_header_t *http_read_response(int fd);
int http_authenticate(HTTP_header_t *http_hdr, URL_t *url, int *auth_retry);
-URL_t* check4proxies(URL_t *url);
+URL_t* check4proxies(const URL_t *url);
+URL_t *url_new_with_proxy(const char *urlstr);
void fixup_network_stream_cache(stream_t *stream);
int http_seek(stream_t *stream, off_t pos);
diff --git a/stream/stream_udp.c b/stream/stream_udp.c
index 5b901cf543..2654a01577 100644
--- a/stream/stream_udp.c
+++ b/stream/stream_udp.c
@@ -61,7 +61,6 @@ udp_streaming_start (stream_t *stream)
static int
udp_stream_open (stream_t *stream, int mode, void *opts, int *file_format)
{
- URL_t *url;
extern int network_bandwidth;
mp_msg (MSGT_OPEN, MSGL_INFO, "STREAM_UDP, URL: %s\n", stream->url);
@@ -70,10 +69,9 @@ udp_stream_open (stream_t *stream, int mode, void *opts, int *file_format)
return STREAM_ERROR;
stream->streaming_ctrl->bandwidth = network_bandwidth;
- url = url_new (stream->url);
- stream->streaming_ctrl->url = check4proxies (url);
+ stream->streaming_ctrl->url = url_new(stream->url);
- if (url->port == 0)
+ if (stream->streaming_ctrl->url->port == 0)
{
mp_msg (MSGT_NETWORK, MSGL_ERR,
"You must enter a port number for UDP streams!\n");
diff --git a/stream/tcp.c b/stream/tcp.c
index 54ebf33e61..be27c490dc 100644
--- a/stream/tcp.c
+++ b/stream/tcp.c
@@ -127,9 +127,9 @@ connect2Server_with_af(char *host, int port, int af,int verb) {
#endif
switch (af) {
- case AF_INET: our_s_addr = (void *) &server_address.four.sin_addr; break;
+ case AF_INET: our_s_addr = &server_address.four.sin_addr; break;
#ifdef HAVE_AF_INET6
- case AF_INET6: our_s_addr = (void *) &server_address.six.sin6_addr; break;
+ case AF_INET6: our_s_addr = &server_address.six.sin6_addr; break;
#endif
default:
mp_tmsg(MSGT_NETWORK,MSGL_ERR, "Unknown address family %d\n", af);
@@ -150,21 +150,21 @@ connect2Server_with_af(char *host, int port, int af,int verb) {
if(verb) mp_tmsg(MSGT_NETWORK,MSGL_STATUS,"Resolving %s for %s...\n", host, af2String(af));
#ifdef HAVE_GETHOSTBYNAME2
- hp=(struct hostent*)gethostbyname2( host, af );
+ hp=gethostbyname2( host, af );
#else
- hp=(struct hostent*)gethostbyname( host );
+ hp=gethostbyname( host );
#endif
if( hp==NULL ) {
if(verb) mp_tmsg(MSGT_NETWORK,MSGL_ERR,"Couldn't resolve name for %s: %s\n", af2String(af), host);
return TCP_ERROR_FATAL;
}
- memcpy( our_s_addr, (void*)hp->h_addr_list[0], hp->h_length );
+ memcpy( our_s_addr, hp->h_addr_list[0], hp->h_length );
}
#if HAVE_WINSOCK2_H
else {
unsigned long addr = inet_addr(host);
- memcpy( our_s_addr, (void*)&addr, sizeof(addr) );
+ memcpy( our_s_addr, &addr, sizeof(addr) );
}
#endif
diff --git a/stream/tv.c b/stream/tv.c
index 922fa5f008..e8346e1b15 100644
--- a/stream/tv.c
+++ b/stream/tv.c
@@ -111,6 +111,11 @@ void tv_start_scan(tvi_handle_t *tvh, int start)
tvh->tv_param->scan=start?1:0;
}
+static int tv_set_freq_float(tvi_handle_t *tvh, float freq)
+{
+ return tv_set_freq(tvh, freq/1000.0*16);
+}
+
static void tv_scan(tvi_handle_t *tvh)
{
unsigned int now;
@@ -134,7 +139,7 @@ static void tv_scan(tvi_handle_t *tvh)
scan=calloc(1,sizeof(tv_scan_t));
tvh->scan=scan;
cl = tvh->chanlist_s[scan->channel_num];
- tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));
+ tv_set_freq_float(tvh, cl.freq);
scan->scan_timer=now+1e6*tvh->tv_param->scan_period;
}
if(scan->scan_timer>now)
@@ -191,12 +196,12 @@ static void tv_scan(tvi_handle_t *tvh)
}
if (!tv_channel_current) tv_channel_current=tv_channel_list;
if (tv_channel_current)
- tv_set_freq(tvh, (unsigned long)(((float)tv_channel_current->freq/1000)*16));
+ tv_set_freq_float(tvh, tv_channel_current->freq);
free(tvh->scan);
tvh->scan=NULL;
}else{
cl = tvh->chanlist_s[scan->channel_num];
- tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));
+ tv_set_freq_float(tvh, cl.freq);
mp_msg(MSGT_TV, MSGL_INFO, "Trying: %s (%.2f). \n",cl.name,1e-3*cl.freq);
}
}
@@ -393,18 +398,17 @@ static int tv_set_norm_i(tvi_handle_t *tvh, int norm)
static void set_norm_and_freq(tvi_handle_t *tvh, tv_channels_t *chan)
{
- float freq = (float)chan->freq/1000;
mp_msg(MSGT_TV, MSGL_INFO, "Selected channel: %s - %s (freq: %.3f)\n",
- chan->number, chan->name, freq);
+ chan->number, chan->name, chan->freq/1000.0);
tv_set_norm_i(tvh, chan->norm);
- tv_set_freq(tvh, (unsigned long)(freq*16));
+ tv_set_freq_float(tvh, chan->freq);
}
static int open_tv(tvi_handle_t *tvh)
{
int i;
const tvi_functions_t *funcs = tvh->functions;
- int tv_fmt_list[] = {
+ static const int tv_fmt_list[] = {
IMGFMT_YV12,
IMGFMT_I420,
IMGFMT_UYVY,
@@ -519,10 +523,11 @@ static int open_tv(tvi_handle_t *tvh)
}
}
- if (tvh->chanlist == -1)
+ if (tvh->chanlist == -1) {
mp_tmsg(MSGT_TV, MSGL_WARN, "Unable to find selected channel list! (%s)\n",
tvh->tv_param->chanlist);
- else
+ return 0;
+ } else
mp_tmsg(MSGT_TV, MSGL_V, "Selected channel list: %s (including %d channels)\n",
chanlists[tvh->chanlist].name, chanlists[tvh->chanlist].count);
@@ -583,7 +588,7 @@ static int open_tv(tvi_handle_t *tvh)
funcs->control(tvh->priv, TVI_CONTROL_TUN_GET_FREQ, &freq);
mp_tmsg(MSGT_TV, MSGL_V, "Selected frequency: %lu (%.3f)\n",
- freq, (float)freq/16);
+ freq, freq/16.0);
}
if (tvh->tv_param->channel) {
@@ -600,8 +605,8 @@ static int open_tv(tvi_handle_t *tvh)
strcpy(tv_channel_last_real, cl.name);
tvh->channel = i;
mp_tmsg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n",
- cl.name, (float)cl.freq/1000);
- tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));
+ cl.name, cl.freq/1000.0);
+ tv_set_freq_float(tvh, cl.freq);
break;
}
}
@@ -900,7 +905,7 @@ int tv_get_freq(tvi_handle_t *tvh, unsigned long *freq)
{
tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_GET_FREQ, freq);
mp_tmsg(MSGT_TV, MSGL_V, "Current frequency: %lu (%.3f)\n",
- *freq, (float)*freq/16);
+ *freq, *freq/16.0);
}
return 1;
}
@@ -916,7 +921,7 @@ int tv_set_freq(tvi_handle_t *tvh, unsigned long freq)
tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_GET_FREQ, &freq);
mp_tmsg(MSGT_TV, MSGL_V, "Current frequency: %lu (%.3f)\n",
- freq, (float)freq/16);
+ freq, freq/16.0);
}
return 1;
}
@@ -958,9 +963,9 @@ int tv_step_channel_real(tvi_handle_t *tvh, int direction)
{
strcpy(tv_channel_last_real, tvh->chanlist_s[tvh->channel].name);
cl = tvh->chanlist_s[--tvh->channel];
- mp_tmsg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n",
- cl.name, (float)cl.freq/1000);
- tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));
+ mp_msg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n",
+ cl.name, cl.freq/1000.0);
+ tv_set_freq_float(tvh, cl.freq);
}
}
@@ -970,9 +975,9 @@ int tv_step_channel_real(tvi_handle_t *tvh, int direction)
{
strcpy(tv_channel_last_real, tvh->chanlist_s[tvh->channel].name);
cl = tvh->chanlist_s[++tvh->channel];
- mp_tmsg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n",
- cl.name, (float)cl.freq/1000);
- tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));
+ mp_msg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n",
+ cl.name, cl.freq/1000.0);
+ tv_set_freq_float(tvh, cl.freq);
}
}
return 1;
@@ -1016,9 +1021,9 @@ int tv_set_channel_real(tvi_handle_t *tvh, char *channel) {
if (!strcasecmp(cl.name, channel))
{
tvh->channel = i;
- mp_tmsg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n",
- cl.name, (float)cl.freq/1000);
- tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));
+ mp_msg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n",
+ cl.name, cl.freq/1000.0);
+ tv_set_freq_float(tvh, cl.freq);
break;
}
}
@@ -1063,9 +1068,9 @@ int tv_last_channel(tvi_handle_t *tvh) {
{
strcpy(tv_channel_last_real, tvh->chanlist_s[tvh->channel].name);
tvh->channel = i;
- mp_tmsg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n",
- cl.name, (float)cl.freq/1000);
- tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));
+ mp_msg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n",
+ cl.name, cl.freq/1000.0);
+ tv_set_freq_float(tvh, cl.freq);
break;
}
}
diff --git a/stream/udp.c b/stream/udp.c
index 53a581e332..c09a7f7e07 100644
--- a/stream/udp.c
+++ b/stream/udp.c
@@ -76,7 +76,7 @@ udp_open_socket (URL_t *url)
if (isalpha (url->hostname[0]))
{
#if !HAVE_WINSOCK2_H
- hp = (struct hostent *) gethostbyname (url->hostname);
+ hp = gethostbyname (url->hostname);
if (!hp)
{
mp_msg (MSGT_NETWORK, MSGL_ERR,
@@ -84,8 +84,8 @@ udp_open_socket (URL_t *url)
closesocket (socket_server_fd);
return -1;
}
- memcpy ((void *) &server_address.sin_addr.s_addr,
- (void *) hp->h_addr_list[0], hp->h_length);
+ memcpy (&server_address.sin_addr.s_addr,
+ hp->h_addr_list[0], hp->h_length);
#else
server_address.sin_addr.s_addr = htonl (INADDR_ANY);
#endif /* HAVE_WINSOCK2_H */
@@ -124,7 +124,7 @@ udp_open_socket (URL_t *url)
#if HAVE_WINSOCK2_H
if (isalpha (url->hostname[0]))
{
- hp = (struct hostent *) gethostbyname (url->hostname);
+ hp = gethostbyname (url->hostname);
if (!hp)
{
mp_msg (MSGT_NETWORK, MSGL_ERR,
@@ -132,13 +132,13 @@ udp_open_socket (URL_t *url)
closesocket (socket_server_fd);
return -1;
}
- memcpy ((void *) &server_address.sin_addr.s_addr,
- (void *) hp->h_addr, hp->h_length);
+ memcpy (&server_address.sin_addr.s_addr,
+ hp->h_addr, hp->h_length);
}
else
{
unsigned int addr = inet_addr (url->hostname);
- memcpy ((void *) &server_address.sin_addr, (void *) &addr, sizeof (addr));
+ memcpy (&server_address.sin_addr, &addr, sizeof (addr));
}
#endif /* HAVE_WINSOCK2_H */