]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/http.c
avutil: Add missing test programs to Makefile.
[ffmpeg] / libavformat / http.c
index 61ae3f438ceec058a9414eb0369c0c2bbcfab805..aa8c6657dbbf1b126f7e6881a61d2d35d3235ee9 100644 (file)
@@ -54,11 +54,14 @@ typedef struct {
 
 #define OFFSET(x) offsetof(HTTPContext, x)
 static const AVOption options[] = {
-{"chunksize", "use chunked transfer-encoding for posts, -1 disables it, 0 enables it", OFFSET(chunksize), FF_OPT_TYPE_INT64, 0, -1, 0 }, /* Default to 0, for chunked POSTs */
+{"chunksize", "use chunked transfer-encoding for posts, -1 disables it, 0 enables it", OFFSET(chunksize), FF_OPT_TYPE_INT64, {.dbl = 0}, -1, 0 }, /* Default to 0, for chunked POSTs */
 {NULL}
 };
 static const AVClass httpcontext_class = {
-    "HTTP", av_default_item_name, options, LIBAVUTIL_VERSION_INT
+    .class_name     = "HTTP",
+    .item_name      = av_default_item_name,
+    .option         = options,
+    .version        = LIBAVUTIL_VERSION_INT,
 };
 
 static int http_connect(URLContext *h, const char *path, const char *hoststr,
@@ -70,7 +73,7 @@ void ff_http_set_headers(URLContext *h, const char *headers)
     int len = strlen(headers);
 
     if (len && strcmp("\r\n", headers + len - 2))
-        av_log(NULL, AV_LOG_ERROR, "No trailing CRLF found in HTTP header.\n");
+        av_log(h, AV_LOG_ERROR, "No trailing CRLF found in HTTP header.\n");
 
     av_strlcpy(s->headers, headers, sizeof(s->headers));
 }
@@ -124,7 +127,7 @@ static int http_open_cnx(URLContext *h)
         port = 80;
 
     ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
-    err = ffurl_open(&hd, buf, URL_RDWR);
+    err = ffurl_open(&hd, buf, AVIO_FLAG_READ_WRITE);
     if (err < 0)
         goto fail;
 
@@ -134,7 +137,7 @@ static int http_open_cnx(URLContext *h)
         goto fail;
     if (s->http_code == 401) {
         if (cur_auth_type == HTTP_AUTH_NONE && s->auth_state.auth_type != HTTP_AUTH_NONE) {
-            url_close(hd);
+            ffurl_close(hd);
             goto redo;
         } else
             goto fail;
@@ -142,7 +145,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)
         && location_changed == 1) {
         /* url moved, get next */
-        url_close(hd);
+        ffurl_close(hd);
         if (redirects++ >= MAX_REDIRECTS)
             return AVERROR(EIO);
         location_changed = 0;
@@ -151,7 +154,7 @@ static int http_open_cnx(URLContext *h)
     return 0;
  fail:
     if (hd)
-        url_close(hd);
+        ffurl_close(hd);
     s->hd = NULL;
     return AVERROR(EIO);
 }
@@ -232,7 +235,7 @@ static int process_line(URLContext *h, char *line, int line_count,
          * don't abort until all headers have been parsed. */
         if (s->http_code >= 400 && s->http_code < 600 && s->http_code != 401) {
             end += strspn(end, SPACE_CHARS);
-            av_log(NULL, AV_LOG_WARNING, "HTTP error %d %s\n",
+            av_log(h, AV_LOG_WARNING, "HTTP error %d %s\n",
                    s->http_code, end);
             return -1;
         }
@@ -296,7 +299,7 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
 
 
     /* send http header */
-    post = h->flags & URL_WRONLY;
+    post = h->flags & AVIO_FLAG_WRITE;
     authstr = ff_http_auth_create_response(&s->auth_state, auth, path,
                                         post ? "POST" : "GET");
 
@@ -451,13 +454,13 @@ static int http_close(URLContext *h)
     HTTPContext *s = h->priv_data;
 
     /* signal end of chunked encoding if used */
-    if ((h->flags & URL_WRONLY) && s->chunksize != -1) {
+    if ((h->flags & AVIO_FLAG_WRITE) && s->chunksize != -1) {
         ret = ffurl_write(s->hd, footer, sizeof(footer) - 1);
         ret = ret > 0 ? 0 : ret;
     }
 
     if (s->hd)
-        url_close(s->hd);
+        ffurl_close(s->hd);
     return ret;
 }
 
@@ -493,7 +496,7 @@ static int64_t http_seek(URLContext *h, int64_t off, int whence)
         s->off = old_off;
         return -1;
     }
-    url_close(old_hd);
+    ffurl_close(old_hd);
     return off;
 }
 
@@ -501,17 +504,17 @@ static int
 http_get_file_handle(URLContext *h)
 {
     HTTPContext *s = h->priv_data;
-    return url_get_file_handle(s->hd);
+    return ffurl_get_file_handle(s->hd);
 }
 
 URLProtocol ff_http_protocol = {
-    "http",
-    http_open,
-    http_read,
-    http_write,
-    http_seek,
-    http_close,
+    .name                = "http",
+    .url_open            = http_open,
+    .url_read            = http_read,
+    .url_write           = http_write,
+    .url_seek            = http_seek,
+    .url_close           = http_close,
     .url_get_file_handle = http_get_file_handle,
-    .priv_data_size = sizeof(HTTPContext),
-    .priv_data_class = &httpcontext_class,
+    .priv_data_size      = sizeof(HTTPContext),
+    .priv_data_class     = &httpcontext_class,
 };