mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
修复内存失效的问题
This commit is contained in:
parent
2e74d5c957
commit
bda57b57f2
@ -22,9 +22,9 @@ extern "C" {
|
|||||||
typedef void* mk_sock_info;
|
typedef void* mk_sock_info;
|
||||||
|
|
||||||
//SockInfo::get_peer_ip()
|
//SockInfo::get_peer_ip()
|
||||||
API_EXPORT const char* API_CALL mk_sock_info_peer_ip(const mk_sock_info ctx);
|
API_EXPORT const char* API_CALL mk_sock_info_peer_ip(const mk_sock_info ctx, char *buf);
|
||||||
//SockInfo::get_local_ip()
|
//SockInfo::get_local_ip()
|
||||||
API_EXPORT const char* API_CALL mk_sock_info_local_ip(const mk_sock_info ctx);
|
API_EXPORT const char* API_CALL mk_sock_info_local_ip(const mk_sock_info ctx, char *buf);
|
||||||
//SockInfo::get_peer_port()
|
//SockInfo::get_peer_port()
|
||||||
API_EXPORT uint16_t API_CALL mk_sock_info_peer_port(const mk_sock_info ctx);
|
API_EXPORT uint16_t API_CALL mk_sock_info_peer_port(const mk_sock_info ctx);
|
||||||
//SockInfo::get_local_port()
|
//SockInfo::get_local_port()
|
||||||
@ -33,14 +33,14 @@ API_EXPORT uint16_t API_CALL mk_sock_info_local_port(const mk_sock_info ctx);
|
|||||||
#ifndef SOCK_INFO_API_RENAME
|
#ifndef SOCK_INFO_API_RENAME
|
||||||
#define SOCK_INFO_API_RENAME
|
#define SOCK_INFO_API_RENAME
|
||||||
//mk_tcp_session对象转换成mk_sock_info对象后再获取网络相关信息
|
//mk_tcp_session对象转换成mk_sock_info对象后再获取网络相关信息
|
||||||
#define mk_tcp_session_peer_ip(x) mk_sock_info_peer_ip(mk_tcp_session_get_sock_info(x))
|
#define mk_tcp_session_peer_ip(x,buf) mk_sock_info_peer_ip(mk_tcp_session_get_sock_info(x),buf)
|
||||||
#define mk_tcp_session_local_ip(x) mk_sock_info_local_ip(mk_tcp_session_get_sock_info(x))
|
#define mk_tcp_session_local_ip(x,buf) mk_sock_info_local_ip(mk_tcp_session_get_sock_info(x),buf)
|
||||||
#define mk_tcp_session_peer_port(x) mk_sock_info_peer_port(mk_tcp_session_get_sock_info(x))
|
#define mk_tcp_session_peer_port(x) mk_sock_info_peer_port(mk_tcp_session_get_sock_info(x))
|
||||||
#define mk_tcp_session_local_port(x) mk_sock_info_local_port(mk_tcp_session_get_sock_info(x))
|
#define mk_tcp_session_local_port(x) mk_sock_info_local_port(mk_tcp_session_get_sock_info(x))
|
||||||
|
|
||||||
//mk_tcp_client对象转换成mk_sock_info对象后再获取网络相关信息
|
//mk_tcp_client对象转换成mk_sock_info对象后再获取网络相关信息
|
||||||
#define mk_tcp_client_peer_ip(x) mk_sock_info_peer_ip(mk_tcp_client_get_sock_info(x))
|
#define mk_tcp_client_peer_ip(x,buf) mk_sock_info_peer_ip(mk_tcp_client_get_sock_info(x),buf)
|
||||||
#define mk_tcp_client_local_ip(x) mk_sock_info_local_ip(mk_tcp_client_get_sock_info(x))
|
#define mk_tcp_client_local_ip(x,buf) mk_sock_info_local_ip(mk_tcp_client_get_sock_info(x),buf)
|
||||||
#define mk_tcp_client_peer_port(x) mk_sock_info_peer_port(mk_tcp_client_get_sock_info(x))
|
#define mk_tcp_client_peer_port(x) mk_sock_info_peer_port(mk_tcp_client_get_sock_info(x))
|
||||||
#define mk_tcp_client_local_port(x) mk_sock_info_local_port(mk_tcp_client_get_sock_info(x))
|
#define mk_tcp_client_local_port(x) mk_sock_info_local_port(mk_tcp_client_get_sock_info(x))
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,21 +8,24 @@
|
|||||||
* may be found in the AUTHORS file in the root of the source tree.
|
* may be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "string.h"
|
||||||
#include "mk_tcp.h"
|
#include "mk_tcp.h"
|
||||||
#include "mk_tcp_private.h"
|
#include "mk_tcp_private.h"
|
||||||
#include "Http/WebSocketClient.h"
|
#include "Http/WebSocketClient.h"
|
||||||
#include "Http/WebSocketSession.h"
|
#include "Http/WebSocketSession.h"
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
|
|
||||||
API_EXPORT const char* API_CALL mk_sock_info_peer_ip(const mk_sock_info ctx){
|
API_EXPORT const char* API_CALL mk_sock_info_peer_ip(const mk_sock_info ctx, char *buf){
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
SockInfo *sock = (SockInfo *)ctx;
|
SockInfo *sock = (SockInfo *)ctx;
|
||||||
return sock->get_peer_ip().c_str();
|
strcpy(buf,sock->get_peer_ip().c_str());
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
API_EXPORT const char* API_CALL mk_sock_info_local_ip(const mk_sock_info ctx){
|
API_EXPORT const char* API_CALL mk_sock_info_local_ip(const mk_sock_info ctx, char *buf){
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
SockInfo *sock = (SockInfo *)ctx;
|
SockInfo *sock = (SockInfo *)ctx;
|
||||||
return sock->get_local_ip().c_str();
|
strcpy(buf,sock->get_peer_ip().c_str());
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
API_EXPORT uint16_t API_CALL mk_sock_info_peer_port(const mk_sock_info ctx){
|
API_EXPORT uint16_t API_CALL mk_sock_info_peer_port(const mk_sock_info ctx){
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
|
@ -47,12 +47,13 @@ void API_CALL on_mk_media_changed(int regist,
|
|||||||
void API_CALL on_mk_media_publish(const mk_media_info url_info,
|
void API_CALL on_mk_media_publish(const mk_media_info url_info,
|
||||||
const mk_publish_auth_invoker invoker,
|
const mk_publish_auth_invoker invoker,
|
||||||
const mk_sock_info sender) {
|
const mk_sock_info sender) {
|
||||||
|
char ip[64];
|
||||||
log_printf(LOG_LEV,
|
log_printf(LOG_LEV,
|
||||||
"client info, local: %s:%d, peer: %s:%d\n"
|
"client info, local: %s:%d, peer: %s:%d\n"
|
||||||
"%s/%s/%s/%s, url params: %s",
|
"%s/%s/%s/%s, url params: %s",
|
||||||
mk_sock_info_local_ip(sender),
|
mk_sock_info_local_ip(sender,ip),
|
||||||
mk_sock_info_local_port(sender),
|
mk_sock_info_local_port(sender),
|
||||||
mk_sock_info_peer_ip(sender),
|
mk_sock_info_peer_ip(sender,ip + 32),
|
||||||
mk_sock_info_peer_port(sender),
|
mk_sock_info_peer_port(sender),
|
||||||
mk_media_info_get_schema(url_info),
|
mk_media_info_get_schema(url_info),
|
||||||
mk_media_info_get_vhost(url_info),
|
mk_media_info_get_vhost(url_info),
|
||||||
@ -75,12 +76,13 @@ void API_CALL on_mk_media_play(const mk_media_info url_info,
|
|||||||
const mk_auth_invoker invoker,
|
const mk_auth_invoker invoker,
|
||||||
const mk_sock_info sender) {
|
const mk_sock_info sender) {
|
||||||
|
|
||||||
|
char ip[64];
|
||||||
log_printf(LOG_LEV,
|
log_printf(LOG_LEV,
|
||||||
"client info, local: %s:%d, peer: %s:%d\n"
|
"client info, local: %s:%d, peer: %s:%d\n"
|
||||||
"%s/%s/%s/%s, url params: %s",
|
"%s/%s/%s/%s, url params: %s",
|
||||||
mk_sock_info_local_ip(sender),
|
mk_sock_info_local_ip(sender,ip),
|
||||||
mk_sock_info_local_port(sender),
|
mk_sock_info_local_port(sender),
|
||||||
mk_sock_info_peer_ip(sender),
|
mk_sock_info_peer_ip(sender,ip + 32),
|
||||||
mk_sock_info_peer_port(sender),
|
mk_sock_info_peer_port(sender),
|
||||||
mk_media_info_get_schema(url_info),
|
mk_media_info_get_schema(url_info),
|
||||||
mk_media_info_get_vhost(url_info),
|
mk_media_info_get_vhost(url_info),
|
||||||
@ -99,12 +101,13 @@ void API_CALL on_mk_media_play(const mk_media_info url_info,
|
|||||||
*/
|
*/
|
||||||
void API_CALL on_mk_media_not_found(const mk_media_info url_info,
|
void API_CALL on_mk_media_not_found(const mk_media_info url_info,
|
||||||
const mk_sock_info sender) {
|
const mk_sock_info sender) {
|
||||||
|
char ip[64];
|
||||||
log_printf(LOG_LEV,
|
log_printf(LOG_LEV,
|
||||||
"client info, local: %s:%d, peer: %s:%d\n"
|
"client info, local: %s:%d, peer: %s:%d\n"
|
||||||
"%s/%s/%s/%s, url params: %s",
|
"%s/%s/%s/%s, url params: %s",
|
||||||
mk_sock_info_local_ip(sender),
|
mk_sock_info_local_ip(sender,ip),
|
||||||
mk_sock_info_local_port(sender),
|
mk_sock_info_local_port(sender),
|
||||||
mk_sock_info_peer_ip(sender),
|
mk_sock_info_peer_ip(sender,ip + 32),
|
||||||
mk_sock_info_peer_port(sender),
|
mk_sock_info_peer_port(sender),
|
||||||
mk_media_info_get_schema(url_info),
|
mk_media_info_get_schema(url_info),
|
||||||
mk_media_info_get_vhost(url_info),
|
mk_media_info_get_vhost(url_info),
|
||||||
@ -139,14 +142,15 @@ void API_CALL on_mk_http_request(const mk_parser parser,
|
|||||||
int *consumed,
|
int *consumed,
|
||||||
const mk_sock_info sender) {
|
const mk_sock_info sender) {
|
||||||
|
|
||||||
|
char ip[64];
|
||||||
log_printf(LOG_LEV,
|
log_printf(LOG_LEV,
|
||||||
"client info, local: %s:%d, peer: %s:%d\n"
|
"client info, local: %s:%d, peer: %s:%d\n"
|
||||||
"%s %s?%s %s\n"
|
"%s %s?%s %s\n"
|
||||||
"User-Agent: %s\n"
|
"User-Agent: %s\n"
|
||||||
"%s",
|
"%s",
|
||||||
mk_sock_info_local_ip(sender),
|
mk_sock_info_local_ip(sender,ip),
|
||||||
mk_sock_info_local_port(sender),
|
mk_sock_info_local_port(sender),
|
||||||
mk_sock_info_peer_ip(sender),
|
mk_sock_info_peer_ip(sender,ip + 32),
|
||||||
mk_sock_info_peer_port(sender),
|
mk_sock_info_peer_port(sender),
|
||||||
mk_parser_get_method(parser),
|
mk_parser_get_method(parser),
|
||||||
mk_parser_get_url(parser),
|
mk_parser_get_url(parser),
|
||||||
@ -193,14 +197,15 @@ void API_CALL on_mk_http_access(const mk_parser parser,
|
|||||||
const mk_http_access_path_invoker invoker,
|
const mk_http_access_path_invoker invoker,
|
||||||
const mk_sock_info sender) {
|
const mk_sock_info sender) {
|
||||||
|
|
||||||
|
char ip[64];
|
||||||
log_printf(LOG_LEV,
|
log_printf(LOG_LEV,
|
||||||
"client info, local: %s:%d, peer: %s:%d, path: %s ,is_dir: %d\n"
|
"client info, local: %s:%d, peer: %s:%d, path: %s ,is_dir: %d\n"
|
||||||
"%s %s?%s %s\n"
|
"%s %s?%s %s\n"
|
||||||
"User-Agent: %s\n"
|
"User-Agent: %s\n"
|
||||||
"%s",
|
"%s",
|
||||||
mk_sock_info_local_ip(sender),
|
mk_sock_info_local_ip(sender, ip),
|
||||||
mk_sock_info_local_port(sender),
|
mk_sock_info_local_port(sender),
|
||||||
mk_sock_info_peer_ip(sender),
|
mk_sock_info_peer_ip(sender, ip + 32),
|
||||||
mk_sock_info_peer_port(sender),
|
mk_sock_info_peer_port(sender),
|
||||||
path,(int)is_dir,
|
path,(int)is_dir,
|
||||||
mk_parser_get_method(parser),
|
mk_parser_get_method(parser),
|
||||||
@ -224,14 +229,16 @@ void API_CALL on_mk_http_access(const mk_parser parser,
|
|||||||
void API_CALL on_mk_http_before_access(const mk_parser parser,
|
void API_CALL on_mk_http_before_access(const mk_parser parser,
|
||||||
char *path,
|
char *path,
|
||||||
const mk_sock_info sender) {
|
const mk_sock_info sender) {
|
||||||
|
|
||||||
|
char ip[64];
|
||||||
log_printf(LOG_LEV,
|
log_printf(LOG_LEV,
|
||||||
"client info, local: %s:%d, peer: %s:%d, path: %s\n"
|
"client info, local: %s:%d, peer: %s:%d, path: %s\n"
|
||||||
"%s %s?%s %s\n"
|
"%s %s?%s %s\n"
|
||||||
"User-Agent: %s\n"
|
"User-Agent: %s\n"
|
||||||
"%s",
|
"%s",
|
||||||
mk_sock_info_local_ip(sender),
|
mk_sock_info_local_ip(sender,ip),
|
||||||
mk_sock_info_local_port(sender),
|
mk_sock_info_local_port(sender),
|
||||||
mk_sock_info_peer_ip(sender),
|
mk_sock_info_peer_ip(sender,ip + 32),
|
||||||
mk_sock_info_peer_port(sender),
|
mk_sock_info_peer_port(sender),
|
||||||
path,
|
path,
|
||||||
mk_parser_get_method(parser),
|
mk_parser_get_method(parser),
|
||||||
@ -252,12 +259,13 @@ void API_CALL on_mk_http_before_access(const mk_parser parser,
|
|||||||
void API_CALL on_mk_rtsp_get_realm(const mk_media_info url_info,
|
void API_CALL on_mk_rtsp_get_realm(const mk_media_info url_info,
|
||||||
const mk_rtsp_get_realm_invoker invoker,
|
const mk_rtsp_get_realm_invoker invoker,
|
||||||
const mk_sock_info sender) {
|
const mk_sock_info sender) {
|
||||||
|
char ip[64];
|
||||||
log_printf(LOG_LEV,
|
log_printf(LOG_LEV,
|
||||||
"client info, local: %s:%d, peer: %s:%d\n"
|
"client info, local: %s:%d, peer: %s:%d\n"
|
||||||
"%s/%s/%s/%s, url params: %s",
|
"%s/%s/%s/%s, url params: %s",
|
||||||
mk_sock_info_local_ip(sender),
|
mk_sock_info_local_ip(sender,ip),
|
||||||
mk_sock_info_local_port(sender),
|
mk_sock_info_local_port(sender),
|
||||||
mk_sock_info_peer_ip(sender),
|
mk_sock_info_peer_ip(sender,ip + 32),
|
||||||
mk_sock_info_peer_port(sender),
|
mk_sock_info_peer_port(sender),
|
||||||
mk_media_info_get_schema(url_info),
|
mk_media_info_get_schema(url_info),
|
||||||
mk_media_info_get_vhost(url_info),
|
mk_media_info_get_vhost(url_info),
|
||||||
@ -286,13 +294,14 @@ void API_CALL on_mk_rtsp_auth(const mk_media_info url_info,
|
|||||||
const mk_rtsp_auth_invoker invoker,
|
const mk_rtsp_auth_invoker invoker,
|
||||||
const mk_sock_info sender) {
|
const mk_sock_info sender) {
|
||||||
|
|
||||||
|
char ip[64];
|
||||||
log_printf(LOG_LEV,
|
log_printf(LOG_LEV,
|
||||||
"client info, local: %s:%d, peer: %s:%d\n"
|
"client info, local: %s:%d, peer: %s:%d\n"
|
||||||
"%s/%s/%s/%s, url params: %s\n"
|
"%s/%s/%s/%s, url params: %s\n"
|
||||||
"realm: %s, user_name: %s, must_no_encrypt: %d",
|
"realm: %s, user_name: %s, must_no_encrypt: %d",
|
||||||
mk_sock_info_local_ip(sender),
|
mk_sock_info_local_ip(sender,ip),
|
||||||
mk_sock_info_local_port(sender),
|
mk_sock_info_local_port(sender),
|
||||||
mk_sock_info_peer_ip(sender),
|
mk_sock_info_peer_ip(sender,ip + 32),
|
||||||
mk_sock_info_peer_port(sender),
|
mk_sock_info_peer_port(sender),
|
||||||
mk_media_info_get_schema(url_info),
|
mk_media_info_get_schema(url_info),
|
||||||
mk_media_info_get_vhost(url_info),
|
mk_media_info_get_vhost(url_info),
|
||||||
@ -339,11 +348,13 @@ void API_CALL on_mk_shell_login(const char *user_name,
|
|||||||
const char *passwd,
|
const char *passwd,
|
||||||
const mk_auth_invoker invoker,
|
const mk_auth_invoker invoker,
|
||||||
const mk_sock_info sender) {
|
const mk_sock_info sender) {
|
||||||
|
|
||||||
|
char ip[64];
|
||||||
log_printf(LOG_LEV,"client info, local: %s:%d, peer: %s:%d\n"
|
log_printf(LOG_LEV,"client info, local: %s:%d, peer: %s:%d\n"
|
||||||
"user_name: %s, passwd: %s",
|
"user_name: %s, passwd: %s",
|
||||||
mk_sock_info_local_ip(sender),
|
mk_sock_info_local_ip(sender,ip),
|
||||||
mk_sock_info_local_port(sender),
|
mk_sock_info_local_port(sender),
|
||||||
mk_sock_info_peer_ip(sender),
|
mk_sock_info_peer_ip(sender,ip + 32),
|
||||||
mk_sock_info_peer_port(sender),
|
mk_sock_info_peer_port(sender),
|
||||||
user_name, passwd);
|
user_name, passwd);
|
||||||
//允许登录shell
|
//允许登录shell
|
||||||
@ -364,6 +375,7 @@ void API_CALL on_mk_flow_report(const mk_media_info url_info,
|
|||||||
uint64_t total_seconds,
|
uint64_t total_seconds,
|
||||||
int is_player,
|
int is_player,
|
||||||
const mk_sock_info sender) {
|
const mk_sock_info sender) {
|
||||||
|
char ip[64];
|
||||||
log_printf(LOG_LEV,"%s/%s/%s/%s, url params: %s,"
|
log_printf(LOG_LEV,"%s/%s/%s/%s, url params: %s,"
|
||||||
"total_bytes: %d, total_seconds: %d, is_player: %d, peer_ip:%s, peer_port:%d",
|
"total_bytes: %d, total_seconds: %d, is_player: %d, peer_ip:%s, peer_port:%d",
|
||||||
mk_media_info_get_schema(url_info),
|
mk_media_info_get_schema(url_info),
|
||||||
@ -371,7 +383,11 @@ void API_CALL on_mk_flow_report(const mk_media_info url_info,
|
|||||||
mk_media_info_get_app(url_info),
|
mk_media_info_get_app(url_info),
|
||||||
mk_media_info_get_stream(url_info),
|
mk_media_info_get_stream(url_info),
|
||||||
mk_media_info_get_params(url_info),
|
mk_media_info_get_params(url_info),
|
||||||
(int)total_bytes, (int)total_seconds, (int)is_player,mk_sock_info_peer_ip(sender), (int)mk_sock_info_peer_port(sender));
|
(int)total_bytes,
|
||||||
|
(int)total_seconds,
|
||||||
|
(int)is_player,
|
||||||
|
mk_sock_info_peer_ip(sender,ip),
|
||||||
|
(int)mk_sock_info_peer_port(sender));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int flag = 1;
|
static int flag = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user