| OLD | NEW |
| 1 /* | 1 /* |
| 2 * HTTP protocol for ffmpeg client | 2 * HTTP protocol for ffmpeg client |
| 3 * Copyright (c) 2000, 2001 Fabrice Bellard | 3 * Copyright (c) 2000, 2001 Fabrice Bellard |
| 4 * | 4 * |
| 5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
| 6 * | 6 * |
| 7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 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 #include "libavcodec/opt.h" |
| 32 | 32 |
| 33 /* XXX: POST protocol is not completely implemented because ffmpeg uses | 33 /* XXX: POST protocol is not completely implemented because ffmpeg uses |
| 34 only a subset of it. */ | 34 only a subset of it. */ |
| 35 | 35 |
| 36 /* used for protocol handling */ | 36 /* used for protocol handling */ |
| 37 #define BUFFER_SIZE 1024 | 37 #define BUFFER_SIZE 1024 |
| 38 #define URL_SIZE 4096 | |
| 39 #define MAX_REDIRECTS 8 | 38 #define MAX_REDIRECTS 8 |
| 40 | 39 |
| 41 typedef struct { | 40 typedef struct { |
| 42 const AVClass *class; | 41 const AVClass *class; |
| 43 URLContext *hd; | 42 URLContext *hd; |
| 44 unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end; | 43 unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end; |
| 45 int line_count; | 44 int line_count; |
| 46 int http_code; | 45 int http_code; |
| 47 int64_t chunksize; /**< Used if "Transfer-Encoding: chunked" otherwise
-1. */ | 46 int64_t chunksize; /**< Used if "Transfer-Encoding: chunked" otherwise
-1. */ |
| 48 int64_t off, filesize; | 47 int64_t off, filesize; |
| 49 char location[URL_SIZE]; | 48 char location[MAX_URL_SIZE]; |
| 50 HTTPAuthState auth_state; | 49 HTTPAuthState auth_state; |
| 51 unsigned char headers[BUFFER_SIZE]; | 50 unsigned char headers[BUFFER_SIZE]; |
| 52 int willclose; /**< Set if the server correctly handles Connection:
close and will close the connection after feeding us the content. */ | 51 int willclose; /**< Set if the server correctly handles Connection:
close and will close the connection after feeding us the content. */ |
| 53 } HTTPContext; | 52 } HTTPContext; |
| 54 | 53 |
| 55 #define OFFSET(x) offsetof(HTTPContext, x) | 54 #define OFFSET(x) offsetof(HTTPContext, x) |
| 56 static const AVOption options[] = { | 55 static const AVOption options[] = { |
| 57 {"chunksize", "use chunked transfer-encoding for posts, -1 disables it, 0 enable
s it", OFFSET(chunksize), FF_OPT_TYPE_INT64, 0, -1, 0 }, /* Default to 0, for ch
unked POSTs */ | 56 {"chunksize", "use chunked transfer-encoding for posts, -1 disables it, 0 enable
s it", OFFSET(chunksize), FF_OPT_TYPE_INT64, 0, -1, 0 }, /* Default to 0, for ch
unked POSTs */ |
| 58 {NULL} | 57 {NULL} |
| 59 }; | 58 }; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 return AVERROR(EIO); | 154 return AVERROR(EIO); |
| 156 } | 155 } |
| 157 | 156 |
| 158 static int http_open(URLContext *h, const char *uri, int flags) | 157 static int http_open(URLContext *h, const char *uri, int flags) |
| 159 { | 158 { |
| 160 HTTPContext *s = h->priv_data; | 159 HTTPContext *s = h->priv_data; |
| 161 | 160 |
| 162 h->is_streamed = 1; | 161 h->is_streamed = 1; |
| 163 | 162 |
| 164 s->filesize = -1; | 163 s->filesize = -1; |
| 165 av_strlcpy(s->location, uri, URL_SIZE); | 164 av_strlcpy(s->location, uri, sizeof(s->location)); |
| 166 | 165 |
| 167 return http_open_cnx(h); | 166 return http_open_cnx(h); |
| 168 } | 167 } |
| 169 static int http_getc(HTTPContext *s) | 168 static int http_getc(HTTPContext *s) |
| 170 { | 169 { |
| 171 int len; | 170 int len; |
| 172 if (s->buf_ptr >= s->buf_end) { | 171 if (s->buf_ptr >= s->buf_end) { |
| 173 len = url_read(s->hd, s->buffer, BUFFER_SIZE); | 172 len = url_read(s->hd, s->buffer, BUFFER_SIZE); |
| 174 if (len < 0) { | 173 if (len < 0) { |
| 175 return AVERROR(EIO); | 174 return AVERROR(EIO); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 "http", | 506 "http", |
| 508 http_open, | 507 http_open, |
| 509 http_read, | 508 http_read, |
| 510 http_write, | 509 http_write, |
| 511 http_seek, | 510 http_seek, |
| 512 http_close, | 511 http_close, |
| 513 .url_get_file_handle = http_get_file_handle, | 512 .url_get_file_handle = http_get_file_handle, |
| 514 .priv_data_size = sizeof(HTTPContext), | 513 .priv_data_size = sizeof(HTTPContext), |
| 515 .priv_data_class = &httpcontext_class, | 514 .priv_data_class = &httpcontext_class, |
| 516 }; | 515 }; |
| OLD | NEW |