From eca304dfd36e2bc5a7b99114d3072f02cbe54a24 Mon Sep 17 00:00:00 2001 From: "Dmitriy A. Gerasimov" <dmitriy.gerasimov@demlabs.net> Date: Mon, 18 Nov 2019 15:11:35 +0700 Subject: [PATCH] [+] Added inheritor for session object --- session/dap_stream_session.c | 25 +++++++++++++++++-------- session/dap_stream_session.h | 7 ++++++- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/session/dap_stream_session.c b/session/dap_stream_session.c index 2ef51d2..c8f432a 100644 --- a/session/dap_stream_session.c +++ b/session/dap_stream_session.c @@ -142,20 +142,29 @@ int dap_stream_session_close(unsigned int id) return stream_session_close2(l_s); } -int stream_session_close2(dap_stream_session_t * s) +int stream_session_close2(dap_stream_session_t * a_session) { // log_it(L_INFO,"Close session"); - HASH_DEL(sessions,s); - free(s); + HASH_DEL(sessions,a_session); + if (a_session->callback_delete) + a_session->callback_delete(a_session, NULL); + if (a_session->_inheritor ) + DAP_DELETE(a_session->_inheritor); + DAP_DELETE(a_session); return 0; } -int dap_stream_session_open(dap_stream_session_t * ss) +/** + * @brief dap_stream_session_open + * @param a_session + * @return + */ +int dap_stream_session_open(dap_stream_session_t * a_session) { int ret; - pthread_mutex_lock(&ss->mutex); - ret=ss->opened; - if(ss->opened==0) ss->opened=1; - pthread_mutex_unlock(&ss->mutex); + pthread_mutex_lock(&a_session->mutex); + ret=a_session->opened; + if(a_session->opened==0) a_session->opened=1; + pthread_mutex_unlock(&a_session->mutex); return ret; } diff --git a/session/dap_stream_session.h b/session/dap_stream_session.h index fd50490..9fdfb91 100755 --- a/session/dap_stream_session.h +++ b/session/dap_stream_session.h @@ -34,6 +34,9 @@ typedef enum stream_session_type {STREAM_SESSION_TYPE_MEDIA=0,STREAM_SESSION_TYPE_VPN} stream_session_type_t; typedef enum stream_session_connection_type {STEAM_SESSION_HTTP = 0, STREAM_SESSION_UDP, STREAM_SESSION_END_TYPE} stream_session_connection_type_t; +typedef struct dap_stream_session dap_stream_session_t; +typedef void (*dap_stream_session_callback_t)( dap_stream_session_t *,void*); + struct dap_stream_session { bool create_empty; unsigned int id; @@ -57,6 +60,8 @@ struct dap_stream_session { struct in_addr tun_client_addr; void * _inheritor; + + dap_stream_session_callback_t callback_delete; }; typedef struct dap_stream_session dap_stream_session_t; @@ -66,6 +71,6 @@ void dap_stream_session_deinit(); dap_stream_session_t * dap_stream_session_pure_new(); dap_stream_session_t * dap_stream_session_new(unsigned int media_id, bool open_preview); dap_stream_session_t * dap_stream_session_id(unsigned int id); -int dap_stream_session_open(dap_stream_session_t * ss); /*Lock for opening for single client , return 0 if ok*/ +int dap_stream_session_open(dap_stream_session_t * a_session); /*Lock for opening for single client , return 0 if ok*/ int dap_stream_session_close(unsigned int id); -- GitLab