server: proxy: refactor
This commit is contained in:
parent
eb088e0812
commit
9de59051f6
@ -106,7 +106,7 @@ typedef struct channel_data_event_info
|
|||||||
|
|
||||||
/* actual data */
|
/* actual data */
|
||||||
const BYTE* data;
|
const BYTE* data;
|
||||||
int data_len;
|
size_t data_len;
|
||||||
} proxyChannelDataEventInfo;
|
} proxyChannelDataEventInfo;
|
||||||
#define WINPR_PACK_POP
|
#define WINPR_PACK_POP
|
||||||
#include <winpr/pack.h>
|
#include <winpr/pack.h>
|
||||||
|
@ -177,7 +177,7 @@ static BOOL pf_client_pre_connect(freerdp* instance)
|
|||||||
* Also, OrderSupport need to be zeroed, because it is currently not supported.
|
* Also, OrderSupport need to be zeroed, because it is currently not supported.
|
||||||
*/
|
*/
|
||||||
settings->GlyphSupportLevel = GLYPH_SUPPORT_NONE;
|
settings->GlyphSupportLevel = GLYPH_SUPPORT_NONE;
|
||||||
ZeroMemory(instance->settings->OrderSupport, 32);
|
ZeroMemory(settings->OrderSupport, 32);
|
||||||
|
|
||||||
settings->SupportDynamicChannels = TRUE;
|
settings->SupportDynamicChannels = TRUE;
|
||||||
|
|
||||||
|
@ -112,49 +112,46 @@ BOOL pf_context_init_server_context(freerdp_peer* client)
|
|||||||
return freerdp_peer_context_new(client);
|
return freerdp_peer_context_new(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* pf_context_copy_settings copies settings from `src` to `dst`.
|
|
||||||
* when using this function, is_dst_server must be set to TRUE if the destination
|
|
||||||
* settings are server's settings. otherwise, they must be set to FALSE.
|
|
||||||
*/
|
|
||||||
BOOL pf_context_copy_settings(rdpSettings* dst, const rdpSettings* src)
|
BOOL pf_context_copy_settings(rdpSettings* dst, const rdpSettings* src)
|
||||||
{
|
{
|
||||||
rdpSettings* before_copy = freerdp_settings_clone(dst);
|
BOOL rc = FALSE;
|
||||||
|
rdpSettings* before_copy;
|
||||||
|
|
||||||
|
if (!dst || !src)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
before_copy = freerdp_settings_clone(dst);
|
||||||
if (!before_copy)
|
if (!before_copy)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
#define REVERT_STR_VALUE(name) \
|
||||||
|
free(dst->name); \
|
||||||
|
dst->name = NULL; \
|
||||||
|
if (before_copy->name && !(dst->name = _strdup(before_copy->name))) \
|
||||||
|
goto out_fail
|
||||||
|
|
||||||
if (!freerdp_settings_copy(dst, src))
|
if (!freerdp_settings_copy(dst, src))
|
||||||
{
|
{
|
||||||
freerdp_settings_free(before_copy);
|
freerdp_settings_free(before_copy);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(dst->ConfigPath);
|
/* keep original ServerMode value */
|
||||||
free(dst->PrivateKeyContent);
|
|
||||||
free(dst->RdpKeyContent);
|
|
||||||
free(dst->RdpKeyFile);
|
|
||||||
free(dst->PrivateKeyFile);
|
|
||||||
free(dst->CertificateFile);
|
|
||||||
free(dst->CertificateName);
|
|
||||||
free(dst->CertificateContent);
|
|
||||||
|
|
||||||
/* adjust pointer to instance pointer */
|
|
||||||
dst->ServerMode = before_copy->ServerMode;
|
dst->ServerMode = before_copy->ServerMode;
|
||||||
|
|
||||||
/* revert some values that must not be changed */
|
/* revert some values that must not be changed */
|
||||||
dst->ConfigPath = _strdup(before_copy->ConfigPath);
|
REVERT_STR_VALUE(ConfigPath);
|
||||||
dst->PrivateKeyContent = _strdup(before_copy->PrivateKeyContent);
|
REVERT_STR_VALUE(PrivateKeyContent);
|
||||||
dst->RdpKeyContent = _strdup(before_copy->RdpKeyContent);
|
REVERT_STR_VALUE(RdpKeyContent);
|
||||||
dst->RdpKeyFile = _strdup(before_copy->RdpKeyFile);
|
REVERT_STR_VALUE(RdpKeyFile);
|
||||||
dst->PrivateKeyFile = _strdup(before_copy->PrivateKeyFile);
|
REVERT_STR_VALUE(PrivateKeyFile);
|
||||||
dst->CertificateFile = _strdup(before_copy->CertificateFile);
|
REVERT_STR_VALUE(CertificateFile);
|
||||||
dst->CertificateName = _strdup(before_copy->CertificateName);
|
REVERT_STR_VALUE(CertificateName);
|
||||||
dst->CertificateContent = _strdup(before_copy->CertificateContent);
|
REVERT_STR_VALUE(CertificateContent);
|
||||||
|
|
||||||
if (!dst->ServerMode)
|
if (!dst->ServerMode)
|
||||||
{
|
{
|
||||||
/* adjust instance pointer for client's context */
|
/* adjust instance pointer */
|
||||||
dst->instance = before_copy->instance;
|
dst->instance = before_copy->instance;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -168,8 +165,11 @@ BOOL pf_context_copy_settings(rdpSettings* dst, const rdpSettings* src)
|
|||||||
dst->RdpServerRsaKey = NULL;
|
dst->RdpServerRsaKey = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rc = TRUE;
|
||||||
|
|
||||||
|
out_fail:
|
||||||
freerdp_settings_free(before_copy);
|
freerdp_settings_free(before_copy);
|
||||||
return TRUE;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
pClientContext* pf_context_create_client_context(rdpSettings* clientSettings)
|
pClientContext* pf_context_create_client_context(rdpSettings* clientSettings)
|
||||||
@ -203,42 +203,32 @@ proxyData* proxy_data_new(void)
|
|||||||
BYTE temp[16];
|
BYTE temp[16];
|
||||||
proxyData* pdata = calloc(1, sizeof(proxyData));
|
proxyData* pdata = calloc(1, sizeof(proxyData));
|
||||||
|
|
||||||
if (pdata == NULL)
|
if (!pdata)
|
||||||
{
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (!(pdata->abort_event = CreateEvent(NULL, TRUE, FALSE, NULL)))
|
if (!(pdata->abort_event = CreateEvent(NULL, TRUE, FALSE, NULL)))
|
||||||
{
|
goto error;
|
||||||
proxy_data_free(pdata);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(pdata->gfx_server_ready = CreateEvent(NULL, TRUE, FALSE, NULL)))
|
if (!(pdata->gfx_server_ready = CreateEvent(NULL, TRUE, FALSE, NULL)))
|
||||||
{
|
goto error;
|
||||||
proxy_data_free(pdata);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
winpr_RAND((BYTE*)&temp, 16);
|
winpr_RAND((BYTE*)&temp, 16);
|
||||||
if (!(pdata->session_id = winpr_BinToHexString(temp, 16, FALSE)))
|
if (!(pdata->session_id = winpr_BinToHexString(temp, 16, FALSE)))
|
||||||
{
|
goto error;
|
||||||
proxy_data_free(pdata);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(pdata->modules_info = HashTable_New(FALSE)))
|
if (!(pdata->modules_info = HashTable_New(FALSE)))
|
||||||
{
|
goto error;
|
||||||
proxy_data_free(pdata);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* modules_info maps between plugin name to custom data */
|
/* modules_info maps between plugin name to custom data */
|
||||||
pdata->modules_info->hash = HashTable_StringHash;
|
pdata->modules_info->hash = HashTable_StringHash;
|
||||||
pdata->modules_info->keyCompare = HashTable_StringCompare;
|
pdata->modules_info->keyCompare = HashTable_StringCompare;
|
||||||
pdata->modules_info->keyClone = HashTable_StringClone;
|
pdata->modules_info->keyClone = HashTable_StringClone;
|
||||||
pdata->modules_info->keyFree = HashTable_StringFree;
|
pdata->modules_info->keyFree = HashTable_StringFree;
|
||||||
|
|
||||||
return pdata;
|
return pdata;
|
||||||
|
error:
|
||||||
|
proxy_data_free(pdata);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* updates circular pointers between proxyData and pClientContext instances */
|
/* updates circular pointers between proxyData and pClientContext instances */
|
||||||
|
@ -60,11 +60,8 @@ static BOOL pf_server_parse_target_from_routing_token(rdpContext* context, char*
|
|||||||
const char* routing_token = freerdp_nego_get_routing_token(context, &routing_token_length);
|
const char* routing_token = freerdp_nego_get_routing_token(context, &routing_token_length);
|
||||||
pServerContext* ps = (pServerContext*)context;
|
pServerContext* ps = (pServerContext*)context;
|
||||||
|
|
||||||
if (routing_token == NULL)
|
if (!routing_token)
|
||||||
{
|
|
||||||
/* no routing token */
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
if ((routing_token_length <= prefix_len) || (routing_token_length >= TARGET_MAX))
|
if ((routing_token_length <= prefix_len) || (routing_token_length >= TARGET_MAX))
|
||||||
{
|
{
|
||||||
@ -149,7 +146,7 @@ static BOOL pf_server_post_connect(freerdp_peer* peer)
|
|||||||
pc = pf_context_create_client_context(peer->settings);
|
pc = pf_context_create_client_context(peer->settings);
|
||||||
if (pc == NULL)
|
if (pc == NULL)
|
||||||
{
|
{
|
||||||
LOG_ERR(TAG, ps, "[%s]: pf_context_create_client_context failed!");
|
LOG_ERR(TAG, ps, "failed to create client context!");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +157,6 @@ static BOOL pf_server_post_connect(freerdp_peer* peer)
|
|||||||
|
|
||||||
if (!pf_server_get_target_info(peer->context, client_settings, pdata->config))
|
if (!pf_server_get_target_info(peer->context, client_settings, pdata->config))
|
||||||
{
|
{
|
||||||
|
|
||||||
LOG_INFO(TAG, ps, "pf_server_get_target_info failed!");
|
LOG_INFO(TAG, ps, "pf_server_get_target_info failed!");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user