From 306c557512eb093303919fe144b78debbcc8e96f Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 4 Sep 2019 15:46:47 +0200 Subject: [PATCH] Getter for state to string --- libfreerdp/core/nego.c | 64 +++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/libfreerdp/core/nego.c b/libfreerdp/core/nego.c index 9abd9a9e6..cb7fd1cd0 100644 --- a/libfreerdp/core/nego.c +++ b/libfreerdp/core/nego.c @@ -65,29 +65,43 @@ struct rdp_nego rdpTransport* transport; }; -static const char* const NEGO_STATE_STRINGS[] = +static const char* nego_state_string(NEGO_STATE state) { - "NEGO_STATE_INITIAL", - "NEGO_STATE_EXT", - "NEGO_STATE_NLA", - "NEGO_STATE_TLS", - "NEGO_STATE_RDP", - "NEGO_STATE_FAIL", - "NEGO_STATE_FINAL" -}; + static const char* const NEGO_STATE_STRINGS[] = + { + "NEGO_STATE_INITIAL", + "NEGO_STATE_EXT", + "NEGO_STATE_NLA", + "NEGO_STATE_TLS", + "NEGO_STATE_RDP", + "NEGO_STATE_FAIL", + "NEGO_STATE_FINAL", + "NEGO_STATE_INVALID" + }; + if (state >= ARRAYSIZE(NEGO_STATE_STRINGS)) + return NEGO_STATE_STRINGS[ARRAYSIZE(NEGO_STATE_STRINGS) - 1]; + return NEGO_STATE_STRINGS[state]; +} -static const char PROTOCOL_SECURITY_STRINGS[9][4] = +static const char* protocol_security_string(UINT32 security) { - "RDP", - "TLS", - "NLA", - "UNK", - "UNK", - "UNK", - "UNK", - "UNK", - "EXT" -}; + static const char* PROTOCOL_SECURITY_STRINGS[] = + { + "RDP", + "TLS", + "NLA", + "UNK", + "UNK", + "UNK", + "UNK", + "UNK", + "EXT", + "UNK" + }; + if (security >= ARRAYSIZE(PROTOCOL_SECURITY_STRINGS)) + return PROTOCOL_SECURITY_STRINGS[ARRAYSIZE(PROTOCOL_SECURITY_STRINGS) - 1]; + return PROTOCOL_SECURITY_STRINGS[security]; +} static BOOL nego_transport_connect(rdpNego* nego); static BOOL nego_transport_disconnect(rdpNego* nego); @@ -185,7 +199,7 @@ BOOL nego_connect(rdpNego* nego) { do { - WLog_DBG(TAG, "state: %s", NEGO_STATE_STRINGS[nego->state]); + WLog_DBG(TAG, "state: %s", nego_state_string(nego->state)); nego_send(nego); if (nego->state == NEGO_STATE_FAIL) @@ -200,7 +214,7 @@ BOOL nego_connect(rdpNego* nego) while (nego->state != NEGO_STATE_FINAL); } - WLog_DBG(TAG, "Negotiated %s security", PROTOCOL_SECURITY_STRINGS[nego->SelectedProtocol]); + WLog_DBG(TAG, "Negotiated %s security", protocol_security_string(nego->SelectedProtocol)); /* update settings with negotiated protocol security */ settings->RequestedProtocols = nego->RequestedProtocols; settings->SelectedProtocol = nego->SelectedProtocol; @@ -225,7 +239,7 @@ BOOL nego_connect(rdpNego* nego) if (!nego_security_connect(nego)) { WLog_DBG(TAG, "Failed to connect with %s security", - PROTOCOL_SECURITY_STRINGS[nego->SelectedProtocol]); + protocol_security_string(nego->SelectedProtocol)); return FALSE; } @@ -428,7 +442,7 @@ static void nego_attempt_ext(rdpNego* nego) return; } - WLog_DBG(TAG, "state: %s", NEGO_STATE_STRINGS[nego->state]); + WLog_DBG(TAG, "state: %s", nego_state_string(nego->state)); if (nego->state != NEGO_STATE_FINAL) { @@ -473,7 +487,7 @@ static void nego_attempt_nla(rdpNego* nego) return; } - WLog_DBG(TAG, "state: %s", NEGO_STATE_STRINGS[nego->state]); + WLog_DBG(TAG, "state: %s", nego_state_string(nego->state)); if (nego->state != NEGO_STATE_FINAL) {