Commit 7a361dd77bc0cac45dd87e166f7f49c37b273017

Authored by Perry Werneck
1 parent 6f187def

Tracing connection state changes.

src/core/host.c
@@ -127,6 +127,13 @@ int lib3270_set_cstate(H3270 *hSession, LIB3270_CSTATE cstate) @@ -127,6 +127,13 @@ int lib3270_set_cstate(H3270 *hSession, LIB3270_CSTATE cstate)
127 { 127 {
128 if(hSession->connection.state != cstate) 128 if(hSession->connection.state != cstate)
129 { 129 {
  130 + trace_dsn(
  131 + hSession,
  132 + "Connection state changes from %s to %s.\n",
  133 + lib3270_connection_state_get_name(hSession->connection.state),
  134 + lib3270_connection_state_get_name(cstate)
  135 + );
  136 +
130 // Salve old states. 137 // Salve old states.
131 int connected = lib3270_is_connected(hSession); 138 int connected = lib3270_is_connected(hSession);
132 int disconnected = lib3270_is_disconnected(hSession); 139 int disconnected = lib3270_is_disconnected(hSession);
src/core/telnet.c
@@ -745,7 +745,6 @@ void net_input(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG GNUC_UNUSED @@ -745,7 +745,6 @@ void net_input(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG GNUC_UNUSED
745 745
746 } 746 }
747 747
748 -  
749 /* 748 /*
750 * set16 749 * set16
751 * Put a 16-bit value in a buffer. 750 * Put a 16-bit value in a buffer.
@@ -786,8 +785,6 @@ static void send_naws(H3270 *hSession) @@ -786,8 +785,6 @@ static void send_naws(H3270 *hSession)
786 trace_dsn(hSession,"SENT %s NAWS %d %d %s\n", cmd(SB), XMIT_COLS, XMIT_ROWS, cmd(SE)); 785 trace_dsn(hSession,"SENT %s NAWS %d %d %s\n", cmd(SB), XMIT_COLS, XMIT_ROWS, cmd(SE));
787 } 786 }
788 787
789 -  
790 -  
791 /// 788 ///
792 /// @brief Advance 'try_lu' to the next desired LU name. 789 /// @brief Advance 'try_lu' to the next desired LU name.
793 /// 790 ///
@@ -797,11 +794,11 @@ static void next_lu(H3270 *hSession) @@ -797,11 +794,11 @@ static void next_lu(H3270 *hSession)
797 hSession->lu.curr = (char **)NULL; 794 hSession->lu.curr = (char **)NULL;
798 } 795 }
799 796
800 -/*  
801 - * telnet_fsm  
802 - * Telnet finite-state machine.  
803 - * Returns 0 for okay, -1 for errors.  
804 - */ 797 +///
  798 +/// @brief Telnet finite-state machine.
  799 +///
  800 +/// @return 0 for okay, -1 for errors.
  801 +///
805 static int telnet_fsm(H3270 *hSession, unsigned char c) 802 static int telnet_fsm(H3270 *hSession, unsigned char c)
806 { 803 {
807 #if defined(X3270_ANSI) /*[*/ 804 #if defined(X3270_ANSI) /*[*/
@@ -2043,18 +2040,9 @@ static void do_lnext(H3270 *hSession, char c) @@ -2043,18 +2040,9 @@ static void do_lnext(H3270 *hSession, char c)
2043 #endif /*]*/ 2040 #endif /*]*/
2044 2041
2045 2042
2046 -/**  
2047 - * Check for switches between NVT, SSCP-LU and 3270 modes.  
2048 - *  
2049 - * @param hSession Session handle.  
2050 - *  
2051 - */  
2052 -static void check_in3270(H3270 *hSession) 2043 +const char * lib3270_connection_state_get_name(const LIB3270_CSTATE cstate)
2053 { 2044 {
2054 - LIB3270_CSTATE new_cstate = LIB3270_NOT_CONNECTED;  
2055 -  
2056 -#if defined(X3270_TRACE) /*[*/  
2057 - static const char *state_name[] = 2045 + static const char *state_names[] =
2058 { 2046 {
2059 "unconnected", 2047 "unconnected",
2060 "resolving", 2048 "resolving",
@@ -2067,7 +2055,23 @@ static void check_in3270(H3270 *hSession) @@ -2067,7 +2055,23 @@ static void check_in3270(H3270 *hSession)
2067 "TN3270E SSCP-LU", 2055 "TN3270E SSCP-LU",
2068 "TN3270E 3270" 2056 "TN3270E 3270"
2069 }; 2057 };
2070 -#endif /*]*/ 2058 +
  2059 + if(cstate > (sizeof(state_names)/sizeof(state_names[0])))
  2060 + return "unknown";
  2061 +
  2062 + return state_names[cstate];
  2063 +}
  2064 +
  2065 +/**
  2066 + * Check for switches between NVT, SSCP-LU and 3270 modes.
  2067 + *
  2068 + * @param hSession Session handle.
  2069 + *
  2070 + */
  2071 +static void check_in3270(H3270 *hSession)
  2072 +{
  2073 + LIB3270_CSTATE new_cstate = LIB3270_NOT_CONNECTED;
  2074 +
2071 2075
2072 #if defined(X3270_TN3270E) /*[*/ 2076 #if defined(X3270_TN3270E) /*[*/
2073 if (hSession->myopts[TELOPT_TN3270E]) { 2077 if (hSession->myopts[TELOPT_TN3270E]) {
@@ -2142,7 +2146,7 @@ static void check_in3270(H3270 *hSession) @@ -2142,7 +2146,7 @@ static void check_in3270(H3270 *hSession)
2142 hSession->tn3270e_bound = 0; 2146 hSession->tn3270e_bound = 0;
2143 } 2147 }
2144 #endif 2148 #endif
2145 - trace_dsn(hSession,"Now operating in %s mode.\n",state_name[new_cstate]); 2149 + trace_dsn(hSession,"Now operating in %s mode.\n",lib3270_connection_state_get_name(new_cstate));
2146 host_in3270(hSession,new_cstate); 2150 host_in3270(hSession,new_cstate);
2147 } 2151 }
2148 } 2152 }
src/include/lib3270.h
@@ -668,6 +668,8 @@ @@ -668,6 +668,8 @@
668 */ 668 */
669 LIB3270_EXPORT LIB3270_CSTATE lib3270_get_connection_state(const H3270 *h); 669 LIB3270_EXPORT LIB3270_CSTATE lib3270_get_connection_state(const H3270 *h);
670 670
  671 + LIB3270_EXPORT const char * lib3270_connection_state_get_name(const LIB3270_CSTATE cstate);
  672 +
671 /** 673 /**
672 * @brief Pretend that a sequence of keys was entered at the keyboard. 674 * @brief Pretend that a sequence of keys was entered at the keyboard.
673 * 675 *