From f44554e16d83f180b2145172a87ef3ff5d7d9487 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Mon, 20 Jun 2022 13:02:25 +0200 Subject: [PATCH] Added proxy module callbacks for session init and started (#7976) --- include/freerdp/server/proxy/proxy_modules_api.h | 4 +++- server/proxy/pf_modules.c | 12 ++++++++++++ server/proxy/pf_server.c | 5 ++++- server/proxy/proxy_modules.h | 2 ++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/freerdp/server/proxy/proxy_modules_api.h b/include/freerdp/server/proxy/proxy_modules_api.h index 723b5b6db..50233d01b 100644 --- a/include/freerdp/server/proxy/proxy_modules_api.h +++ b/include/freerdp/server/proxy/proxy_modules_api.h @@ -76,8 +76,10 @@ struct proxy_plugin proxyHookFn ServerChannelsInit; /* 98 custom=freerdp_peer* */ proxyHookFn ServerChannelsFree; /* 99 custom=freerdp_peer* */ proxyHookFn ServerSessionEnd; /* 100 custom=freerdp_peer* */ + proxyHookFn ServerSessionInitialize; /* 101 custom=freerdp_peer* */ + proxyHookFn ServerSessionStarted; /* 102 custom=freerdp_peer* */ - UINT64 reserved4[128 - 101]; /* 101 - 127 */ + UINT64 reserved4[128 - 103]; /* 103 - 127 */ /* proxy filters. a module can set these function pointers to register filters */ proxyFilterFn KeyboardEvent; /* 128 */ diff --git a/server/proxy/pf_modules.c b/server/proxy/pf_modules.c index 5e21c84a6..54b27bb30 100644 --- a/server/proxy/pf_modules.c +++ b/server/proxy/pf_modules.c @@ -105,6 +105,10 @@ static const char* pf_modules_get_hook_type_string(PF_HOOK_TYPE result) return "HOOK_TYPE_SERVER_CHANNELS_FREE"; case HOOK_TYPE_SERVER_SESSION_END: return "HOOK_TYPE_SERVER_SESSION_END"; + case HOOK_TYPE_SERVER_SESSION_INITIALIZE: + return "HOOK_TYPE_SERVER_SESSION_INITIALIZE"; + case HOOK_TYPE_SERVER_SESSION_STARTED: + return "HOOK_TYPE_SERVER_SESSION_STARTED"; case HOOK_LAST: return "HOOK_LAST"; default: @@ -184,6 +188,14 @@ static BOOL pf_modules_proxy_ArrayList_ForEachFkt(void* data, size_t index, va_l ok = IFCALLRESULT(TRUE, plugin->ServerSessionEnd, plugin, pdata, custom); break; + case HOOK_TYPE_SERVER_SESSION_INITIALIZE: + ok = IFCALLRESULT(TRUE, plugin->ServerSessionInitialize, plugin, pdata, custom); + break; + + case HOOK_TYPE_SERVER_SESSION_STARTED: + ok = IFCALLRESULT(TRUE, plugin->ServerSessionStarted, plugin, pdata, custom); + break; + case HOOK_LAST: default: WLog_ERR(TAG, "invalid hook called"); diff --git a/server/proxy/pf_server.c b/server/proxy/pf_server.c index 5beeb626c..a77a4bfe0 100644 --- a/server/proxy/pf_server.c +++ b/server/proxy/pf_server.c @@ -572,12 +572,16 @@ static DWORD WINAPI pf_server_handle_peer(LPVOID arg) pdata = ps->pdata; WINPR_ASSERT(pdata); + pf_modules_run_hook(pdata->module, HOOK_TYPE_SERVER_SESSION_INITIALIZE, pdata, client); + WINPR_ASSERT(client->Initialize); client->Initialize(client); PROXY_LOG_INFO(TAG, ps, "new connection: proxy address: %s, client address: %s", pdata->config->Host, client->hostname); + pf_modules_run_hook(pdata->module, HOOK_TYPE_SERVER_SESSION_STARTED, pdata, client); + while (1) { HANDLE ChannelEvent = INVALID_HANDLE_VALUE; @@ -676,7 +680,6 @@ fail: pf_modules_run_hook(pdata->module, HOOK_TYPE_SERVER_SESSION_END, pdata, client); - PROXY_LOG_INFO(TAG, ps, "freeing server's channels"); WINPR_ASSERT(client->Close); diff --git a/server/proxy/proxy_modules.h b/server/proxy/proxy_modules.h index cc2fe8d92..99e373a2f 100644 --- a/server/proxy/proxy_modules.h +++ b/server/proxy/proxy_modules.h @@ -57,6 +57,8 @@ typedef enum HOOK_TYPE_SERVER_CHANNELS_INIT, HOOK_TYPE_SERVER_CHANNELS_FREE, HOOK_TYPE_SERVER_SESSION_END, + HOOK_TYPE_SERVER_SESSION_INITIALIZE, + HOOK_TYPE_SERVER_SESSION_STARTED, HOOK_LAST } PF_HOOK_TYPE;