comparison http.c @ 6163:2e0ee73855cd libavformat

Add an AVClass to the HTTPContext
author mstorsjo
date Tue, 22 Jun 2010 14:13:55 +0000
parents 4c0017a87855
children 72ea866c62fd
comparison
equal deleted inserted replaced
6162:4c0017a87855 6163:2e0ee73855cd
26 #include "internal.h" 26 #include "internal.h"
27 #include "network.h" 27 #include "network.h"
28 #include "http.h" 28 #include "http.h"
29 #include "os_support.h" 29 #include "os_support.h"
30 #include "httpauth.h" 30 #include "httpauth.h"
31 #include "libavcodec/opt.h"
31 32
32 /* XXX: POST protocol is not completely implemented because ffmpeg uses 33 /* XXX: POST protocol is not completely implemented because ffmpeg uses
33 only a subset of it. */ 34 only a subset of it. */
34 35
35 /* used for protocol handling */ 36 /* used for protocol handling */
36 #define BUFFER_SIZE 1024 37 #define BUFFER_SIZE 1024
37 #define URL_SIZE 4096 38 #define URL_SIZE 4096
38 #define MAX_REDIRECTS 8 39 #define MAX_REDIRECTS 8
39 40
40 typedef struct { 41 typedef struct {
42 const AVClass *class;
41 URLContext *hd; 43 URLContext *hd;
42 unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end; 44 unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end;
43 int line_count; 45 int line_count;
44 int http_code; 46 int http_code;
45 int64_t chunksize; /**< Used if "Transfer-Encoding: chunked" otherwise -1. */ 47 int64_t chunksize; /**< Used if "Transfer-Encoding: chunked" otherwise -1. */
48 HTTPAuthState auth_state; 50 HTTPAuthState auth_state;
49 int init; 51 int init;
50 unsigned char headers[BUFFER_SIZE]; 52 unsigned char headers[BUFFER_SIZE];
51 } HTTPContext; 53 } HTTPContext;
52 54
55 #define OFFSET(x) offsetof(HTTPContext, x)
56 static const AVOption options[] = {
57 {"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 */
58 {NULL}
59 };
60 static const AVClass httpcontext_class = {
61 "HTTP", av_default_item_name, options, LIBAVUTIL_VERSION_INT
62 };
63
53 static int http_connect(URLContext *h, const char *path, const char *hoststr, 64 static int http_connect(URLContext *h, const char *path, const char *hoststr,
54 const char *auth, int *new_location); 65 const char *auth, int *new_location);
55 66
56 void ff_http_set_headers(URLContext *h, const char *headers) 67 void ff_http_set_headers(URLContext *h, const char *headers)
57 { 68 {
150 HTTPContext *s = h->priv_data; 161 HTTPContext *s = h->priv_data;
151 162
152 h->is_streamed = 1; 163 h->is_streamed = 1;
153 164
154 s->filesize = -1; 165 s->filesize = -1;
155 s->chunksize = 0; /* Default to chunked POSTs */
156 av_strlcpy(s->location, uri, URL_SIZE); 166 av_strlcpy(s->location, uri, URL_SIZE);
157 167
158 return 0; 168 return 0;
159 } 169 }
160 static int http_getc(HTTPContext *s) 170 static int http_getc(HTTPContext *s)
520 http_write, 530 http_write,
521 http_seek, 531 http_seek,
522 http_close, 532 http_close,
523 .url_get_file_handle = http_get_file_handle, 533 .url_get_file_handle = http_get_file_handle,
524 .priv_data_size = sizeof(HTTPContext), 534 .priv_data_size = sizeof(HTTPContext),
535 .priv_data_class = &httpcontext_class,
525 }; 536 };