http_types.h
来自「AMLOGIC DPF source code」· C头文件 代码 · 共 199 行
H
199 行
/*******************************************************************
*
* Copyright C 2005 by Amlogic, Inc. All Rights Reserved.
*
* Description: Data structure and type declarations for HTTP module.
*
* Author: Eric Knudstrup
* Created: Thu Jun 30 13:27:54 2005
*
*******************************************************************/
#ifndef HTTP_TYPES_H
#define HTTP_TYPES_H
#include <listop.h>
/* Also need to update http_state_str[] when changing
* these enumerations */
/**
* The HTTP parser passes through these states while processing
* the reply.
*/
typedef enum {
HTTP_PARSE_START = 0, /**< Initial state */
HTTP_PARSE_STATUS_PROTO, /**< Parse the status line ("HTTP") */
HTTP_PARSE_REQUEST_URI, /**< Parse URI http://blah.com/blah.html */
HTTP_PARSE_REQUEST_PROTO, /**< Parse HTTP */
HTTP_PARSE_REQUEST_SLASH, /**< Parse / */
HTTP_PARSE_REQUEST_VER, /**< Parse 1.0 */
HTTP_PARSE_STATUS_SLASH, /**< Parse the status line "/" */
HTTP_PARSE_STATUS_VER, /**< Parse the status line "1.1" */
HTTP_PARSE_STATUS_CODE, /**< Parse the status line "200" */
HTTP_PARSE_STATUS_MESSAGE, /**< Parse the status line "OK" */
HTTP_PARSE_HEADER_FIELD, /**< Retrieving header */
HTTP_PARSE_HEADER_INIT_VAL, /**< Initialize value */
HTTP_PARSE_HEADER_VAL, /**< Retrieving header value */
HTTP_PARSE_CONTENT_INIT, /**< Parsing content */
HTTP_PARSE_CONTENT, /**< Parsing content */
HTTP_PARSE_CHUNKED_LEN, /**< Parsing chunked content length. */
HTTP_PARSE_CHUNKED_EOL, /**< Junk after chunked data length */
HTTP_PARSE_CHUNKED_DATA, /**< Parsing chunked data. */
HTTP_PARSE_COMPLETE, /**< All done */
HTTP_PARSE_STATE_MAX /**< NOT REACHED */
} HTTPParserState;
/**
* The parser functions use these to request state changes.
*/
typedef enum {
HTTP_STATUS_COMPLETE = 42 /** No more input needed. */,
HTTP_STATUS_ENOMEM /** Memory error. */,
HTTP_STATUS_ERROR /** Parsing failed. */,
HTTP_STATUS_NEEDMORE /** Need more input */,
HTTP_STATUS_CHANGESTATE /** Proceed to next parser state. */
} HTTPParseStatus;
typedef struct _http_parser_s HTTPParser;
/**
* Determine if a transaction is a response or a request.
*/
typedef enum {
HTTP_MESSAGE_RESPONSE = 1, /**< A response */
HTTP_MESSAGE_REQUEST, /**< A request */
} HTTPMessageType_t;
typedef enum {
HTTP_MESSAGE_FLAG_CHUNKED = (1<<0), /**< Chunked Transfer-Encoding */
HTTP_MESSAGE_FLAG_CONTENT_LENGTH = (1<<1), /**< Content-Length read */
HTTP_MESSAGE_CONNECTION_CLOSE = (1<<2), /**< Connection: close read */
} HTTPMessageFlags_t;
typedef struct http_field_parser HTTPFieldParser;
typedef struct _http_header {
struct _http_header *h_next; /* The headers are created as a linked list */
char *h_name;
HTTPFieldParser *h_parser;
} HTTPFieldValue;
typedef struct {
HTTPFieldValue str_base;
char *str_id;
} HTTPStringHeader;
typedef struct {
HTTPFieldValue int_base;
u32_t int_value;
} HTTPIntHeader;
typedef HTTPParseStatus (*HTTPFieldInitFunc) (HTTPParser *parser, HTTPFieldParser *field_parser);
typedef HTTPParseStatus (*HTTPFieldParseFunc) (HTTPParser *parser, HTTPFieldValue *value);
typedef void (*HTTPFieldFreeFunc) (HTTPFieldValue *field);
/**
* Base message input data structure.
*/
typedef struct {
HTTPParser *r_parser; /**< Parser context that parsed this message */
HTTPMessageType_t r_message_type; /**< RESPONSE or REQUEST */
HTTPMessageFlags_t r_flags; /**< HTTPMessageFlags_t */
unsigned r_content_length; /**< Content-Length */
char *r_content_type; /**< Content-Type */
HTTPFieldValue *r_header; /**< List of headers from remote. */
HTTPParseStatus r_status; /**< Parser completion status */
union {
struct {
char *method; /**< "GET" */
char *resource; /**< "http://foo.com/bar.html" */
} request;
struct {
int r_status_code; /**< Status code returned by server */
char *r_status_message; /**< Status message */
} response;
} t;
unsigned char r_major;
unsigned char r_minor;
} HTTPInputMessage_t;
typedef enum {
HTTP_OUT_DATA_STARTED = (1<<1)
} HTTPOutputFlags_t;
typedef enum {
HTTP_OUT_OK, /**< Data available */
HTTP_OUT_ERROR, /**< Resource error */
HTTP_OUT_COMPLETE, /**< No more data */
HTTP_OUT_ASYNC /**< Data not available. Wait for asynchronous data */
} HTTPOutputCbResult_t;
typedef HTTPOutputCbResult_t (*HTTPOutputCb_t)
(void *context, u8_t **data, unsigned *len);
typedef struct {
unsigned magic;
PBUFStream headers;
struct pbuf *cursor;
HTTPOutputFlags_t flags;
HTTPOutputCb_t out_data_cb;
void *out_ctxt; /* application context */
struct pbuf *data_pbuf;
u8_t *cursor_data;
u32_t cursor_len;
} HTTPOutputMessage_t;
typedef list_t HTTPOutHeaderList_t;
#define http_resp_status_code(r) (r->t.response.r_status_code)
#define http_resp_status_string(r) (r->t.response.r_status_message)
#define http_request_method(r) (r->t.request.method)
#define http_request_resource(r) (r->t.request.resource)
#define http_message_major(r) (r->r_major)
#define http_message_minor(r) (r->r_minor)
#define http_message_has_content_length(r) (r->r_flags&HTTP_MESSAGE_FLAG_CONTENT_LENGTH)
#define IS_RESP_INFORMATION_STATUS(r) ((http_resp_status_code(r)/100) == 1)
#define IS_RESP_SUCCESSFUL_STATUS(r) ((http_resp_status_code(r)/100) == 2)
#define IS_RESP_REDIRECT_STATUS(r) ((http_resp_status_code(r)/100) == 3)
#define IS_RESP_CLIENT_ERROR_STATUS(r) ((http_resp_status_code(r)/100) == 4)
#define IS_RESP_SERVER_ERROR_STATUS(r) ((http_resp_status_code(r)/100) == 5)
/*
* Data content callback. This will be done whenever the
* HTTP code has filled up the buffer in the content descriptor.
*/
typedef struct _http_content_descriptor_s HTTPContentDescriptor;
typedef HTTPParseStatus (*HTTPContentDataCb) (HTTPContentDescriptor *cd);
/** Content callback descriptor */
struct _http_content_descriptor_s {
HTTPContentDataCb data_cb /** User's callback for data content */;
HTTPInputMessage_t *headers /** All of the parsed header information */;
struct pbuf *pbuf; /** Pbuf * if the user didn't give a buffer pointer */
void *buffer /** User's buffer. Can be NULL if the user wants raw data */;
unsigned buffer_len /** Buffer length. */;
unsigned long offset /** Number of bytes in buffer */;
unsigned long bytes_copied /** total number of bytes copied */;
void *context /** User's context */;
};
/*
* Callback the requester uses to initialize the content of the
* message. It is possible that there will be more than one
* type of content per request/reply.
* If this callback returns HTTP_STATUS_NEEDMORE, data will be copied
* into their buffer and the data callback called.
* The content_length in the response should be considered to be a hint.
* It may not even exist.
*/
typedef HTTPParseStatus (*HTTPContentInitCb) (HTTPContentDescriptor *cd);
typedef HTTPParseStatus (*HTTPPreParseFunc) (HTTPParser *parser, void *user_context);
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?