Merge remote-tracking branch 'qatar/master'

* qatar/master:
  http: Add the url_shutdown function for https, too
  http: Simplify code by removing a local variable
  http: Clear the old URLContext pointer when closed
  tcp: Try enabling SO_REUSEADDR when listening
  tcp: Check the return values from bind and accept
  avisynth: Make sure the filename passed to avisynth is in the right code page

Conflicts:
	libavformat/http.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2012-06-01 19:52:35 +02:00
commit fbc5e0fae1
3 changed files with 15 additions and 14 deletions

View File

@ -49,10 +49,15 @@ static int avisynth_read_header(AVFormatContext *s)
DWORD id; DWORD id;
AVStream *st; AVStream *st;
AVISynthStream *stream; AVISynthStream *stream;
wchar_t filename_wchar[1024] = { 0 };
char filename_char[1024] = { 0 };
AVIFileInit(); AVIFileInit();
res = AVIFileOpen(&avs->file, s->filename, OF_READ|OF_SHARE_DENY_WRITE, NULL); /* avisynth can't accept UTF-8 filename */
MultiByteToWideChar(CP_UTF8, 0, s->filename, -1, filename_wchar, 1024);
WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wchar, -1, filename_char, 1024, NULL, NULL);
res = AVIFileOpen(&avs->file, filename_char, OF_READ|OF_SHARE_DENY_WRITE, NULL);
if (res != S_OK) if (res != S_OK)
{ {
av_log(s, AV_LOG_ERROR, "AVIFileOpen failed with error %ld", res); av_log(s, AV_LOG_ERROR, "AVIFileOpen failed with error %ld", res);

View File

@ -106,7 +106,6 @@ static int http_open_cnx(URLContext *h)
int port, use_proxy, err, location_changed = 0, redirects = 0, attempts = 0; int port, use_proxy, err, location_changed = 0, redirects = 0, attempts = 0;
HTTPAuthType cur_auth_type, cur_proxy_auth_type; HTTPAuthType cur_auth_type, cur_proxy_auth_type;
HTTPContext *s = h->priv_data; HTTPContext *s = h->priv_data;
URLContext *hd = NULL;
proxy_path = getenv("http_proxy"); proxy_path = getenv("http_proxy");
use_proxy = (proxy_path != NULL) && !getenv("no_proxy") && use_proxy = (proxy_path != NULL) && !getenv("no_proxy") &&
@ -147,12 +146,10 @@ static int http_open_cnx(URLContext *h)
ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL); ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL);
if (!s->hd) { if (!s->hd) {
err = ffurl_open(&hd, buf, AVIO_FLAG_READ_WRITE, err = ffurl_open(&s->hd, buf, AVIO_FLAG_READ_WRITE,
&h->interrupt_callback, NULL); &h->interrupt_callback, NULL);
if (err < 0) if (err < 0)
goto fail; goto fail;
s->hd = hd;
} }
cur_auth_type = s->auth_state.auth_type; cur_auth_type = s->auth_state.auth_type;
@ -163,8 +160,7 @@ static int http_open_cnx(URLContext *h)
if (s->http_code == 401) { if (s->http_code == 401) {
if ((cur_auth_type == HTTP_AUTH_NONE || s->auth_state.stale) && if ((cur_auth_type == HTTP_AUTH_NONE || s->auth_state.stale) &&
s->auth_state.auth_type != HTTP_AUTH_NONE && attempts < 4) { s->auth_state.auth_type != HTTP_AUTH_NONE && attempts < 4) {
ffurl_closep(&hd); ffurl_closep(&s->hd);
s->hd = NULL;
goto redo; goto redo;
} else } else
goto fail; goto fail;
@ -172,8 +168,7 @@ static int http_open_cnx(URLContext *h)
if (s->http_code == 407) { if (s->http_code == 407) {
if ((cur_proxy_auth_type == HTTP_AUTH_NONE || s->proxy_auth_state.stale) && if ((cur_proxy_auth_type == HTTP_AUTH_NONE || s->proxy_auth_state.stale) &&
s->proxy_auth_state.auth_type != HTTP_AUTH_NONE && attempts < 4) { s->proxy_auth_state.auth_type != HTTP_AUTH_NONE && attempts < 4) {
ffurl_closep(&hd); ffurl_closep(&s->hd);
s->hd = NULL;
goto redo; goto redo;
} else } else
goto fail; goto fail;
@ -181,8 +176,7 @@ static int http_open_cnx(URLContext *h)
if ((s->http_code == 301 || s->http_code == 302 || s->http_code == 303 || s->http_code == 307) if ((s->http_code == 301 || s->http_code == 302 || s->http_code == 303 || s->http_code == 307)
&& location_changed == 1) { && location_changed == 1) {
/* url moved, get next */ /* url moved, get next */
ffurl_closep(&hd); ffurl_closep(&s->hd);
s->hd = NULL;
if (redirects++ >= MAX_REDIRECTS) if (redirects++ >= MAX_REDIRECTS)
return AVERROR(EIO); return AVERROR(EIO);
/* Restart the authentication process with the new target, which /* Restart the authentication process with the new target, which
@ -194,9 +188,8 @@ static int http_open_cnx(URLContext *h)
} }
return 0; return 0;
fail: fail:
if (hd) if (s->hd)
ffurl_closep(&hd); ffurl_closep(&s->hd);
s->hd = NULL;
return AVERROR(EIO); return AVERROR(EIO);
} }
@ -676,6 +669,7 @@ URLProtocol ff_https_protocol = {
.url_seek = http_seek, .url_seek = http_seek,
.url_close = http_close, .url_close = http_close,
.url_get_file_handle = http_get_file_handle, .url_get_file_handle = http_get_file_handle,
.url_shutdown = http_shutdown,
.priv_data_size = sizeof(HTTPContext), .priv_data_size = sizeof(HTTPContext),
.priv_data_class = &https_context_class, .priv_data_class = &https_context_class,
.flags = URL_PROTOCOL_FLAG_NETWORK, .flags = URL_PROTOCOL_FLAG_NETWORK,

View File

@ -83,6 +83,8 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
if (listen_socket) { if (listen_socket) {
int fd1; int fd1;
int reuse = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
ret = bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen); ret = bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
if (ret) { if (ret) {
ret = ff_neterrno(); ret = ff_neterrno();