Files

161 lines
4.8 KiB
C
Raw Permalink Normal View History

2026-08-13 11:28:40 +08:00
/*
* HTTP definitions
* Copyright (c) 2010 Josh Allmann
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFORMAT_HTTP_H
#define AVFORMAT_HTTP_H
#include "libavformat/url.h"
#include "libavformat/httpauth.h"
#include "libavformat/internal.h"
#include "libavutil/opt.h"
#define BUFFER_SIZE MAX_URL_SIZE
extern const AVOption http_options[];
#define HTTP_CLASS(flavor) \
static const AVClass flavor ## _context_class = { \
.class_name = # flavor, \
.item_name = av_default_item_name, \
.option = http_options, \
.version = LIBAVUTIL_VERSION_INT, \
}
#if CONFIG_HTTPS_PROTOCOL
HTTP_CLASS(https);
#endif
HTTP_CLASS(http);
typedef enum {
LOWER_PROTO,
READ_HEADERS,
WRITE_REPLY_HEADERS,
FINISH
}HandshakeState;
typedef struct HTTPContext {
const AVClass *clasz;
URLContext *hd;
unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end;
int line_count;
int http_code;
/* Used if "Transfer-Encoding: chunked" otherwise -1. */
uint64_t chunksize;
int chunkend;
uint64_t off, end_off, filesize;
char *location;
HTTPAuthState auth_state;
HTTPAuthState proxy_auth_state;
char *http_proxy;
char *headers;
char *mime_type;
char *http_version;
char *user_agent;
char *referer;
#if FF_API_HTTP_USER_AGENT
char *user_agent_deprecated;
#endif
char *content_type;
/* Set if the server correctly handles Connection: close and will close
* the connection after feeding us the content. */
int willclose;
int seekable; /**< Control seekability, 0 = disable, 1 = enable, -1 = probe. */
int chunked_post;
/* A flag which indicates if the end of chunked encoding has been sent. */
int end_chunked_post;
/* A flag which indicates we have finished to read POST reply. */
int end_header;
/* A flag which indicates if we use persistent connections. */
int multiple_requests;
uint8_t *post_data;
int post_datalen;
int is_akamai;
int is_mediagateway;
char *cookies; ///< holds newline (\n) delimited Set-Cookie header field values (without the "Set-Cookie: " field name)
/* A dictionary containing cookies keyed by cookie name */
AVDictionary *cookie_dict;
int icy;
/* how much data was read since the last ICY metadata packet */
uint64_t icy_data_read;
/* after how many bytes of read data a new metadata packet will be found */
uint64_t icy_metaint;
char *icy_metadata_headers;
char *icy_metadata_packet;
AVDictionary *metadata;
#if CONFIG_ZLIB
int compressed;
z_stream inflate_stream;
uint8_t *inflate_buffer;
#endif /* CONFIG_ZLIB */
AVDictionary *chained_options;
int send_expect_100;
char *method;
int reconnect;
int reconnect_at_eof;
int reconnect_streamed;
int reconnect_delay_max;
int http_always_reconnect;
int listen;
char *resource;
int reply_code;
int is_multi_client;
HandshakeState handshake_step;
int is_connected_server;
int thread_enable; //1:enable; 0:disable
int thread_bufsize;
int wait_eof;
int wait_eof_ok;
void* session;
int average_speed;
int last_speed;
//add for rrsip
char org_url[MAX_URL_SIZE];
} HTTPContext;
#define HTTP_HEADERS_SIZE 4096
/**
* Initialize the authentication state based on another HTTP URLContext.
* This can be used to pre-initialize the authentication parameters if
* they are known beforehand, to avoid having to do an initial failing
* request just to get the parameters.
*
* @param dest URL context whose authentication state gets updated
* @param src URL context whose authentication state gets copied
*/
void ff_http_init_auth_state(URLContext *dest, const URLContext *src);
/**
* Send a new HTTP request, reusing the old connection.
*
* @param h pointer to the resource
* @param uri uri used to perform the request
* @return a negative value if an error condition occurred, 0
* otherwise
*/
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 */