From d00373436ab7f6beaa0bb6a0de954da6dc32ff3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C3=85strand?= Date: Thu, 7 Jan 2010 18:42:47 +0000 Subject: [PATCH] Avoid code duplication in iso_connect/iso_reconnect. git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/rdesktop/trunk@1526 423420c4-83ab-492f-b58f-81f9feb106b5 --- iso.c | 31 +++++++------------------------ mcs.c | 12 ++---------- proto.h | 3 +-- 3 files changed, 10 insertions(+), 36 deletions(-) diff --git a/iso.c b/iso.c index a02e076..7feb24b 100644 --- a/iso.c +++ b/iso.c @@ -174,38 +174,21 @@ iso_recv(uint8 * rdpver) /* Establish a connection up to the ISO layer */ RD_BOOL -iso_connect(char *server, char *username) +iso_connect(char *server, char *username, RD_BOOL reconnect) { uint8 code = 0; if (!tcp_connect(server)) return False; - iso_send_connection_request(username); - - if (iso_recv_msg(&code, NULL) == NULL) - return False; - - if (code != ISO_PDU_CC) + if (reconnect) { - error("expected CC, got 0x%x\n", code); - tcp_disconnect(); - return False; + iso_send_msg(ISO_PDU_CR); + } + else + { + iso_send_connection_request(username); } - - return True; -} - -/* Establish a reconnection up to the ISO layer */ -RD_BOOL -iso_reconnect(char *server) -{ - uint8 code = 0; - - if (!tcp_connect(server)) - return False; - - iso_send_msg(ISO_PDU_CR); if (iso_recv_msg(&code, NULL) == NULL) return False; diff --git a/mcs.c b/mcs.c index 7c9f2eb..54a576f 100644 --- a/mcs.c +++ b/mcs.c @@ -377,16 +377,8 @@ mcs_connect_common(char *server, STREAM mcs_data, char *username, RD_BOOL reconn { unsigned int i; - if (reconnect) - { - if (!iso_reconnect(server)) - return False; - } - else - { - if (!iso_connect(server, username)) - return False; - } + if (!iso_connect(server, username, reconnect)) + return False; mcs_send_connect_initial(mcs_data); if (!mcs_recv_connect_response(mcs_data)) diff --git a/proto.h b/proto.h index 70ee9ad..4dd6130 100644 --- a/proto.h +++ b/proto.h @@ -75,8 +75,7 @@ void ewmh_init(void); STREAM iso_init(int length); void iso_send(STREAM s); STREAM iso_recv(uint8 * rdpver); -RD_BOOL iso_connect(char *server, char *username); -RD_BOOL iso_reconnect(char *server); +RD_BOOL iso_connect(char *server, char *username, RD_BOOL reconnect); void iso_disconnect(void); void iso_reset_state(void); /* licence.c */