Update MediaClient
This commit is contained in:
222
ONVIF/include/http/http.h
Normal file
222
ONVIF/include/http/http.h
Normal file
@@ -0,0 +1,222 @@
|
||||
/***************************************************************************************
|
||||
*
|
||||
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
*
|
||||
* By downloading, copying, installing or using the software you agree to this license.
|
||||
* If you do not agree to this license, do not download, install,
|
||||
* copy or use the software.
|
||||
*
|
||||
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
|
||||
*
|
||||
* Redistribution and use in binary forms, with or without modification, are permitted.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed
|
||||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the License.
|
||||
*
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __H_HTTP_H__
|
||||
#define __H_HTTP_H__
|
||||
|
||||
#include "sys_buf.h"
|
||||
#include "ppstack.h"
|
||||
|
||||
#ifdef HTTPS
|
||||
#include "openssl/ssl.h"
|
||||
#endif
|
||||
|
||||
/***************************************************************************************/
|
||||
typedef enum http_request_msg_type
|
||||
{
|
||||
HTTP_MT_NULL = 0,
|
||||
HTTP_MT_GET,
|
||||
HTTP_MT_HEAD,
|
||||
HTTP_MT_MPOST,
|
||||
HTTP_MT_MSEARCH,
|
||||
HTTP_MT_NOTIFY,
|
||||
HTTP_MT_POST,
|
||||
HTTP_MT_SUBSCRIBE,
|
||||
HTTP_MT_UNSUBSCRIBE,
|
||||
} HTTP_MT;
|
||||
|
||||
/***************************************************************************************/
|
||||
typedef enum http_content_type
|
||||
{
|
||||
CTT_NULL = 0,
|
||||
CTT_SDP,
|
||||
CTT_TXT,
|
||||
CTT_HTM,
|
||||
CTT_XML,
|
||||
CTT_BIN,
|
||||
CTT_JPG,
|
||||
CTT_RTSP_TUNNELLED,
|
||||
CTT_MULTIPART,
|
||||
CTT_FLV
|
||||
} HTTPCTT;
|
||||
|
||||
#define ctt_is_string(type) (type == CTT_XML || type == CTT_HTM || type == CTT_TXT || type == CTT_SDP)
|
||||
|
||||
|
||||
typedef struct _http_msg_content
|
||||
{
|
||||
uint32 msg_type;
|
||||
uint32 msg_sub_type;
|
||||
HDRV first_line;
|
||||
|
||||
PPSN_CTX hdr_ctx;
|
||||
PPSN_CTX ctt_ctx;
|
||||
|
||||
int hdr_len;
|
||||
int ctt_len;
|
||||
HTTPCTT ctt_type;
|
||||
char boundary[256];
|
||||
|
||||
char * msg_buf;
|
||||
int buf_offset;
|
||||
|
||||
uint32 remote_ip;
|
||||
uint16 remote_port;
|
||||
} HTTPMSG;
|
||||
|
||||
/*************************************************************************/
|
||||
typedef struct http_client
|
||||
{
|
||||
uint32 pass_through : 1; // pass through received data flag
|
||||
uint32 https : 1; // https flag
|
||||
uint32 resv : 30;
|
||||
|
||||
SOCKET cfd; // client socket
|
||||
uint32 rip; // remote ip, network byte order
|
||||
uint32 rport; // remote port
|
||||
|
||||
char rcv_buf[2052]; // static receiving buffer
|
||||
char * dyn_recv_buf; // dynamic receiving buffer
|
||||
int rcv_dlen; // received data length
|
||||
int hdr_len; // http header length
|
||||
int ctt_len; // context length
|
||||
HTTPCTT ctt_type; // context type
|
||||
char * rbuf; // pointer to rcv_buf or dyn_recv_buf
|
||||
int mlen; // sizeof(rcv_buf) or size of dyn_recv_buf
|
||||
|
||||
void * p_srv; // pointer to HTTPSRV
|
||||
int use_count; // use count
|
||||
|
||||
void * userdata; // user data
|
||||
void * userdata_mutex; // user data mutex
|
||||
uint32 protocol; // protocol, rtsp over http, websocket etc
|
||||
|
||||
#ifdef HTTPS
|
||||
SSL * ssl; // https SSL
|
||||
void * ssl_mutex; // https SSL mutex
|
||||
#endif
|
||||
} HTTPCLN;
|
||||
|
||||
typedef struct http_req
|
||||
{
|
||||
uint32 need_auth : 1; // need auth flag
|
||||
uint32 https : 1; // https flag
|
||||
uint32 resv : 30;
|
||||
|
||||
SOCKET cfd; // client socket
|
||||
uint32 port; // server port
|
||||
char host[256]; // server host
|
||||
char url[256]; // the request url
|
||||
|
||||
char action[256]; // action
|
||||
char rcv_buf[2052]; // static receiving buffer
|
||||
char * dyn_recv_buf; // dynamic receiving buffer
|
||||
int rcv_dlen; // received data length
|
||||
int hdr_len; // http header length
|
||||
int ctt_len; // context length
|
||||
char boundary[256]; // boundary, for CTT_MULTIPART
|
||||
char * rbuf; // pointer to rcv_buf or dyn_recv_buf
|
||||
int mlen; // sizeof(rcv_buf) or size of dyn_recv_buf
|
||||
|
||||
HTTPMSG * rx_msg; // rx message
|
||||
|
||||
int auth_mode; // 0 - baisc; 1 - digest
|
||||
HD_AUTH_INFO auth_info; // http auth information
|
||||
|
||||
#ifdef HTTPS
|
||||
SSL * ssl; // https SSL
|
||||
void * ssl_mutex; // https SSL mutex
|
||||
#endif
|
||||
} HTTPREQ;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* If rx_msg is NULL, the callback should call the http_free_used_cln function to delete p_cln
|
||||
* If the callback is responsible for deleting rx_msg, it returns TRUE, otherwise it returns FALSE
|
||||
*/
|
||||
typedef BOOL (*http_msg_cb)(void * p_srv, HTTPCLN * p_cln, HTTPMSG * rx_msg, void * userdata);
|
||||
|
||||
/*
|
||||
* Raw data received by http
|
||||
* p_srv : HTTPSRV
|
||||
* p_cln : http client user agent
|
||||
* buff : data buffer
|
||||
* buflen : data buffer length
|
||||
*
|
||||
*/
|
||||
typedef void (*http_data_cb)(void * p_srv, HTTPCLN * p_cln, char * buff, int buflen, void * userdata);
|
||||
|
||||
/*
|
||||
* http new connection callback
|
||||
* p_srv : HTTPSRV
|
||||
* addr : http client connection address, network byte order
|
||||
* port : http client connection port, host byte order
|
||||
*
|
||||
* Return TRUE, accept the new connection, return FALSE, reject the new connection
|
||||
*/
|
||||
typedef BOOL (*http_conn_cb)(void * p_srv, uint32 addr, int port, void * userdata);
|
||||
|
||||
typedef struct http_srv_s
|
||||
{
|
||||
uint32 r_flag : 1; // data receiving flag
|
||||
uint32 https : 1; // https flag
|
||||
uint32 resv : 30;
|
||||
|
||||
SOCKET sfd; // server socket
|
||||
|
||||
char host[128]; // local server address
|
||||
int sport; // server port
|
||||
uint32 saddr; // server address, network byte order
|
||||
uint32 max_cln_nums; // max client number
|
||||
|
||||
PPSN_CTX * cln_fl; // client free list
|
||||
PPSN_CTX * cln_ul; // client used list
|
||||
|
||||
uint32 rx_num; // data receiving thread numbers
|
||||
pthread_t * rx_tid; // data receiving thread id
|
||||
|
||||
void * mutex_cb; // cabllback mutex
|
||||
http_msg_cb msg_cb; // http message callback
|
||||
http_data_cb data_cb; // http data callback
|
||||
http_conn_cb conn_cb; // http connection callback
|
||||
void * msg_user; // http message callback user data
|
||||
void * data_user; // http data callback user data
|
||||
void * conn_user; // http connection callback user data
|
||||
|
||||
#ifdef EPOLL
|
||||
int ep_fd; // epoll fd
|
||||
struct epoll_event * ep_events; // epoll events
|
||||
int ep_event_num; // epoll event number
|
||||
#endif
|
||||
|
||||
#ifdef HTTPS
|
||||
char cert_file[256]; // cert file name
|
||||
char key_file[256]; // key file name
|
||||
SSL_CTX * ssl_ctx; // ssl context
|
||||
#endif
|
||||
} HTTPSRV;
|
||||
|
||||
|
||||
|
||||
#endif // __H_HTTP_H__
|
||||
|
||||
|
||||
|
||||
|
||||
46
ONVIF/include/http/http_cln.h
Normal file
46
ONVIF/include/http/http_cln.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/***************************************************************************************
|
||||
*
|
||||
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
*
|
||||
* By downloading, copying, installing or using the software you agree to this license.
|
||||
* If you do not agree to this license, do not download, install,
|
||||
* copy or use the software.
|
||||
*
|
||||
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
|
||||
*
|
||||
* Redistribution and use in binary forms, with or without modification, are permitted.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed
|
||||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the License.
|
||||
*
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef HTTP_CLN_H
|
||||
#define HTTP_CLN_H
|
||||
|
||||
#include "http.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
BOOL http_get_digest_params(char * p, int len, HD_AUTH_INFO * p_auth);
|
||||
BOOL http_get_digest_info(HTTPMSG * rx_msg, HD_AUTH_INFO * auth_info);
|
||||
BOOL http_calc_auth_digest(HD_AUTH_INFO * auth_info, const char * method);
|
||||
int http_build_auth_msg(HTTPREQ * p_http, const char * method, char * buff, int buflen);
|
||||
int http_cln_auth_set(HTTPREQ * p_http, const char * user, const char * pass);
|
||||
BOOL http_cln_ssl_conn(HTTPREQ * p_http, int timeout);
|
||||
BOOL http_cln_rx(HTTPREQ * p_http);
|
||||
int http_cln_tx(HTTPREQ * p_http, const char * p_data, int len);
|
||||
BOOL http_cln_rx_timeout(HTTPREQ * p_http, int timeout);
|
||||
void http_cln_free_req(HTTPREQ * p_http);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
70
ONVIF/include/http/http_parse.h
Normal file
70
ONVIF/include/http/http_parse.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/***************************************************************************************
|
||||
*
|
||||
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
*
|
||||
* By downloading, copying, installing or using the software you agree to this license.
|
||||
* If you do not agree to this license, do not download, install,
|
||||
* copy or use the software.
|
||||
*
|
||||
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
|
||||
*
|
||||
* Redistribution and use in binary forms, with or without modification, are permitted.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed
|
||||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the License.
|
||||
*
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef HTTP_PARSE_H
|
||||
#define HTTP_PARSE_H
|
||||
|
||||
#include "sys_inc.h"
|
||||
#include "http.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***********************************************************************/
|
||||
HT_API BOOL http_msg_buf_init(int num);
|
||||
HT_API void http_msg_buf_deinit();
|
||||
|
||||
/***********************************************************************/
|
||||
HT_API BOOL http_is_http_msg(char * msg_buf);
|
||||
HT_API int http_pkt_find_end(char * p_buf);
|
||||
HT_API void http_headl_parse(char * pline, int llen, HTTPMSG * p_msg);
|
||||
HT_API int http_line_parse(char * p_buf, int max_len, char sep_char, PPSN_CTX * p_ctx);
|
||||
HT_API BOOL http_get_headline_uri(HTTPMSG * rx_msg, char * p_uri, int size);
|
||||
HT_API int http_ctt_parse(HTTPMSG * p_msg);
|
||||
HT_API int http_msg_parse(char * msg_buf, int msg_buf_len, HTTPMSG * msg);
|
||||
HT_API int http_msg_parse_part1(char * p_buf, int buf_len, HTTPMSG * msg);
|
||||
HT_API int http_msg_parse_part2(char * p_buf, int buf_len, HTTPMSG * msg);
|
||||
HT_API HDRV * http_find_headline(HTTPMSG * msg, const char * head);
|
||||
HT_API HDRV * http_find_headline_next(HTTPMSG * msg, const char * head, HDRV * hrv);
|
||||
HT_API char * http_get_headline(HTTPMSG * msg, const char * head);
|
||||
HT_API HDRV * http_find_ctt_headline(HTTPMSG * msg, const char * head);
|
||||
HT_API char * http_get_ctt(HTTPMSG * msg);
|
||||
HT_API BOOL http_get_auth_digest_info(HTTPMSG * rx_msg, HD_AUTH_INFO * p_auth);
|
||||
|
||||
HT_API HTTPMSG * http_get_msg_buf(int size);
|
||||
HT_API void http_msg_ctx_init(HTTPMSG * msg);
|
||||
HT_API void http_free_msg_buf(HTTPMSG * msg);
|
||||
HT_API uint32 http_idle_msg_buf_num();
|
||||
|
||||
/***********************************************************************/
|
||||
HT_API void http_free_msg(HTTPMSG * msg);
|
||||
HT_API void http_free_msg_content(HTTPMSG * msg);
|
||||
HT_API void http_free_msg_ctx(HTTPMSG * msg, int type);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
51
ONVIF/include/http/http_srv.h
Normal file
51
ONVIF/include/http/http_srv.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/***************************************************************************************
|
||||
*
|
||||
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
*
|
||||
* By downloading, copying, installing or using the software you agree to this license.
|
||||
* If you do not agree to this license, do not download, install,
|
||||
* copy or use the software.
|
||||
*
|
||||
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
|
||||
*
|
||||
* Redistribution and use in binary forms, with or without modification, are permitted.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed
|
||||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the License.
|
||||
*
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef HTTP_SRV_H
|
||||
#define HTTP_SRV_H
|
||||
|
||||
#include "sys_inc.h"
|
||||
#include "http.h"
|
||||
#include "http_parse.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************************/
|
||||
HT_API int http_srv_init(HTTPSRV * p_srv, const char * saddr, uint16 sport, int cln_num, BOOL https, const char * cert_file, const char * key_file);
|
||||
HT_API void http_srv_deinit(HTTPSRV * p_srv);
|
||||
HT_API void http_set_msg_cb(HTTPSRV * p_srv, http_msg_cb cb, void * p_userdata);
|
||||
HT_API void http_set_data_cb(HTTPSRV * p_srv, http_data_cb cb, void * p_userdata);
|
||||
HT_API void http_set_conn_cb(HTTPSRV * p_srv, http_conn_cb cb, void * p_userdata);
|
||||
HT_API int http_srv_cln_tx(HTTPCLN * p_user, const char * p_data, int len);
|
||||
|
||||
/***************************************************************************************/
|
||||
HT_API uint32 http_cln_index(HTTPSRV * p_srv, HTTPCLN * p_cln);
|
||||
HT_API HTTPCLN* http_get_cln_by_index(HTTPSRV * p_srv, unsigned long index);
|
||||
HT_API HTTPCLN* http_get_idle_cln(HTTPSRV * p_srv);
|
||||
HT_API void http_free_used_cln(HTTPSRV * p_srv, HTTPCLN * p_cln);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user