Commit 9d86ce78 authored by Andrey Utkin's avatar Andrey Utkin Committed by Michael Niedermayer

avformat/http: Introduce ff_http_averror()

int ff_http_averror(int status_code, int default_averror)

This helper function returns AVERROR_ value from 3-digit HTTP status
code.

Second argument, default_averror, is used if no specific AVERROR_ is
available. It is introduced because in different places of code
different return codes are used - -1, AVERROR(EIO), AVERROR_INVALIDDATA.
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent d4e62eba
......@@ -272,6 +272,23 @@ int ff_http_do_new_request(URLContext *h, const char *uri)
return ret;
}
int ff_http_averror(int status_code, int default_averror)
{
switch (status_code) {
case 400: return AVERROR_HTTP_BAD_REQUEST;
case 401: return AVERROR_HTTP_UNAUTHORIZED;
case 403: return AVERROR_HTTP_FORBIDDEN;
case 404: return AVERROR_HTTP_NOT_FOUND;
default: break;
}
if (status_code >= 400 && status_code <= 499)
return AVERROR_HTTP_OTHER_4XX;
else if (status_code >= 500)
return AVERROR_HTTP_SERVER_ERROR;
else
return default_averror;
}
static int http_open(URLContext *h, const char *uri, int flags,
AVDictionary **options)
{
......
......@@ -47,4 +47,6 @@ void ff_http_init_auth_state(URLContext *dest, const URLContext *src);
*/
int ff_http_do_new_request(URLContext *h, const char *uri);
int ff_http_averror(int status_code, int default_averror);
#endif /* AVFORMAT_HTTP_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment