Commit 220421475a0f276989e4b56933472b670e8e50e6
1 parent
5fa8530b
Exists in
master
and in
5 other branches
Mais ajustes para multi-sessão
Showing
2 changed files
with
32 additions
and
65 deletions
Show diff stats
src/include/lib3270/session.h
src/lib3270/telnet.c
| ... | ... | @@ -275,7 +275,7 @@ static unsigned char will_opt[] = { IAC, WILL, '_' }; |
| 275 | 275 | static unsigned char wont_opt[] = { IAC, WONT, '_' }; |
| 276 | 276 | |
| 277 | 277 | #if defined(X3270_TN3270E) /*[*/ |
| 278 | -static unsigned char functions_req[] = { IAC, SB, TELOPT_TN3270E, TN3270E_OP_FUNCTIONS }; | |
| 278 | +static const unsigned char functions_req[] = { IAC, SB, TELOPT_TN3270E, TN3270E_OP_FUNCTIONS }; | |
| 279 | 279 | #endif /*]*/ |
| 280 | 280 | |
| 281 | 281 | #if defined(X3270_TRACE) /*[*/ |
| ... | ... | @@ -327,7 +327,7 @@ static const char *trsp_flag[2] = { "POSITIVE-RESPONSE", "NEGATIVE-RESPONSE" }; |
| 327 | 327 | // #endif |
| 328 | 328 | |
| 329 | 329 | #if defined(HAVE_LIBSSL) /*[*/ |
| 330 | -static Boolean need_tls_follows = False; | |
| 330 | +// static Boolean need_tls_follows = False; | |
| 331 | 331 | static void ssl_init(H3270 *session); |
| 332 | 332 | #if OPENSSL_VERSION_NUMBER >= 0x00907000L /*[*/ |
| 333 | 333 | #define INFO_CONST const |
| ... | ... | @@ -335,7 +335,7 @@ static void ssl_init(H3270 *session); |
| 335 | 335 | #define INFO_CONST |
| 336 | 336 | #endif /*]*/ |
| 337 | 337 | static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret); |
| 338 | -static void continue_tls(unsigned char *sbbuf, int len); | |
| 338 | +static void continue_tls(H3270 *hSession, unsigned char *sbbuf, int len); | |
| 339 | 339 | #endif /*]*/ |
| 340 | 340 | |
| 341 | 341 | // #if !defined(_WIN32) /*[*/ |
| ... | ... | @@ -897,7 +897,7 @@ LIB3270_EXPORT void lib3270_setup_session(H3270 *hSession) |
| 897 | 897 | #endif /*]*/ |
| 898 | 898 | |
| 899 | 899 | #if defined(HAVE_LIBSSL) /*[*/ |
| 900 | - need_tls_follows = False; | |
| 900 | + hSession->need_tls_follows = 0; | |
| 901 | 901 | #endif /*]*/ |
| 902 | 902 | hSession->telnet_state = TNS_DATA; |
| 903 | 903 | hSession->ibptr = hSession->ibuf; |
| ... | ... | @@ -1471,7 +1471,7 @@ static int telnet_fsm(H3270 *session, unsigned char c) |
| 1471 | 1471 | cmd(SB), |
| 1472 | 1472 | opt(TELOPT_STARTTLS), |
| 1473 | 1473 | cmd(SE)); |
| 1474 | - need_tls_follows = True; | |
| 1474 | + session->need_tls_follows = 1; | |
| 1475 | 1475 | } |
| 1476 | 1476 | #endif /*]*/ |
| 1477 | 1477 | break; |
| ... | ... | @@ -1559,9 +1559,9 @@ static int telnet_fsm(H3270 *session, unsigned char c) |
| 1559 | 1559 | } |
| 1560 | 1560 | #endif /*]*/ |
| 1561 | 1561 | #if defined(HAVE_LIBSSL) /*[*/ |
| 1562 | - else if (need_tls_follows && session->myopts[TELOPT_STARTTLS] && session->sbbuf[0] == TELOPT_STARTTLS) | |
| 1562 | + else if (session->need_tls_follows && session->myopts[TELOPT_STARTTLS] && session->sbbuf[0] == TELOPT_STARTTLS) | |
| 1563 | 1563 | { |
| 1564 | - continue_tls(session->sbbuf, session->sbptr - session->sbbuf); | |
| 1564 | + continue_tls(session,session->sbbuf, session->sbptr - session->sbbuf); | |
| 1565 | 1565 | } |
| 1566 | 1566 | #endif /*]*/ |
| 1567 | 1567 | |
| ... | ... | @@ -2851,43 +2851,6 @@ static void tn3270e_nak(H3270 *hSession, enum pds rv) |
| 2851 | 2851 | trace_dsn(hSession,"SENT TN3270E(RESPONSE NEGATIVE-RESPONSE %u) %s\n",h_in->seq_number[0] << 8 | h_in->seq_number[1], neg); |
| 2852 | 2852 | net_rawout(hSession, rsp_buf, rsp_len); |
| 2853 | 2853 | } |
| 2854 | - | |
| 2855 | -/* | |
| 2856 | -#if defined(X3270_TRACE) | |
| 2857 | -// Add a dummy TN3270E header to the output buffer. | |
| 2858 | -Boolean | |
| 2859 | -net_add_dummy_tn3270e(void) | |
| 2860 | -{ | |
| 2861 | - tn3270e_header *h; | |
| 2862 | - | |
| 2863 | - if (!IN_E || h3270.tn3270e_submode == E_NONE) | |
| 2864 | - return False; | |
| 2865 | - | |
| 2866 | - space3270out(&h3270,EH_SIZE); | |
| 2867 | - h = (tn3270e_header *)h3270.obptr; | |
| 2868 | - | |
| 2869 | - switch (h3270.tn3270e_submode) { | |
| 2870 | - case E_NONE: | |
| 2871 | - break; | |
| 2872 | - case E_NVT: | |
| 2873 | - h->data_type = TN3270E_DT_NVT_DATA; | |
| 2874 | - break; | |
| 2875 | - case E_SSCP: | |
| 2876 | - h->data_type = TN3270E_DT_SSCP_LU_DATA; | |
| 2877 | - break; | |
| 2878 | - case E_3270: | |
| 2879 | - h->data_type = TN3270E_DT_3270_DATA; | |
| 2880 | - break; | |
| 2881 | - } | |
| 2882 | - h->request_flag = 0; | |
| 2883 | - h->response_flag = TN3270E_RSF_NO_RESPONSE; | |
| 2884 | - h->seq_number[0] = 0; | |
| 2885 | - h->seq_number[1] = 0; | |
| 2886 | - h3270.obptr += EH_SIZE; | |
| 2887 | - return True; | |
| 2888 | -} | |
| 2889 | -#endif | |
| 2890 | -*/ | |
| 2891 | 2854 | #endif /*]*/ |
| 2892 | 2855 | |
| 2893 | 2856 | #if defined(X3270_TRACE) /*[*/ |
| ... | ... | @@ -3276,68 +3239,71 @@ static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) |
| 3276 | 3239 | } |
| 3277 | 3240 | } |
| 3278 | 3241 | |
| 3279 | -/* Process a STARTTLS subnegotiation. */ | |
| 3280 | -static void continue_tls(unsigned char *sbbuf, int len) | |
| 3242 | +/** | |
| 3243 | + * Process a STARTTLS subnegotiation. | |
| 3244 | + */ | |
| 3245 | +static void continue_tls(H3270 *hSession, unsigned char *sbbuf, int len) | |
| 3281 | 3246 | { |
| 3282 | 3247 | int rv; |
| 3283 | 3248 | |
| 3284 | 3249 | /* Whatever happens, we're not expecting another SB STARTTLS. */ |
| 3285 | - need_tls_follows = False; | |
| 3250 | + hSession->need_tls_follows = 0; | |
| 3286 | 3251 | |
| 3287 | 3252 | /* Make sure the option is FOLLOWS. */ |
| 3288 | - if (len < 2 || sbbuf[1] != TLS_FOLLOWS) { | |
| 3253 | + if (len < 2 || sbbuf[1] != TLS_FOLLOWS) | |
| 3254 | + { | |
| 3289 | 3255 | /* Trace the junk. */ |
| 3290 | - trace_dsn(&h3270,"%s ? %s\n", opt(TELOPT_STARTTLS), cmd(SE)); | |
| 3291 | - popup_an_error(NULL,"TLS negotiation failure"); | |
| 3292 | - net_disconnect(&h3270); | |
| 3256 | + trace_dsn(hSession,"%s ? %s\n", opt(TELOPT_STARTTLS), cmd(SE)); | |
| 3257 | + popup_an_error(hSession,_( "TLS negotiation failure")); | |
| 3258 | + net_disconnect(hSession); | |
| 3293 | 3259 | return; |
| 3294 | 3260 | } |
| 3295 | 3261 | |
| 3296 | 3262 | /* Trace what we got. */ |
| 3297 | - trace_dsn(&h3270,"%s FOLLOWS %s\n", opt(TELOPT_STARTTLS), cmd(SE)); | |
| 3263 | + trace_dsn(hSession,"%s FOLLOWS %s\n", opt(TELOPT_STARTTLS), cmd(SE)); | |
| 3298 | 3264 | |
| 3299 | 3265 | /* Initialize the SSL library. */ |
| 3300 | - ssl_init(&h3270); | |
| 3301 | - if(h3270.ssl_con == NULL) | |
| 3266 | + ssl_init(hSession); | |
| 3267 | + if(hSession->ssl_con == NULL) | |
| 3302 | 3268 | { |
| 3303 | 3269 | /* Failed. */ |
| 3304 | - net_disconnect(&h3270); | |
| 3270 | + net_disconnect(hSession); | |
| 3305 | 3271 | return; |
| 3306 | 3272 | } |
| 3307 | 3273 | |
| 3308 | 3274 | /* Set up the TLS/SSL connection. */ |
| 3309 | - if(SSL_set_fd(h3270.ssl_con, h3270.sock) != 1) | |
| 3275 | + if(SSL_set_fd(hSession->ssl_con, hSession->sock) != 1) | |
| 3310 | 3276 | { |
| 3311 | - trace_dsn(&h3270,"SSL_set_fd failed!\n"); | |
| 3277 | + trace_dsn(hSession,"SSL_set_fd failed!\n"); | |
| 3312 | 3278 | } |
| 3313 | 3279 | |
| 3314 | 3280 | //#if defined(_WIN32) |
| 3315 | 3281 | // /* Make the socket blocking for SSL. */ |
| 3316 | -// (void) WSAEventSelect(h3270.sock, h3270.sock_handle, 0); | |
| 3282 | +// (void) WSAEventSelect(hSession->sock, hSession->sock_handle, 0); | |
| 3317 | 3283 | // (void) non_blocking(False); |
| 3318 | 3284 | //#endif |
| 3319 | 3285 | |
| 3320 | - rv = SSL_connect(h3270.ssl_con); | |
| 3286 | + rv = SSL_connect(hSession->ssl_con); | |
| 3321 | 3287 | |
| 3322 | 3288 | //#if defined(_WIN32) |
| 3323 | 3289 | // // Make the socket non-blocking again for event processing |
| 3324 | -// (void) WSAEventSelect(h3270.sock, h3270.sock_handle, FD_READ | FD_CONNECT | FD_CLOSE); | |
| 3290 | +// (void) WSAEventSelect(hSession->sock, hSession->sock_handle, FD_READ | FD_CONNECT | FD_CLOSE); | |
| 3325 | 3291 | //#endif |
| 3326 | 3292 | |
| 3327 | 3293 | if (rv != 1) |
| 3328 | 3294 | { |
| 3329 | - trace_dsn(&h3270,"continue_tls: SSL_connect failed\n"); | |
| 3330 | - net_disconnect(&h3270); | |
| 3295 | + trace_dsn(hSession,"continue_tls: SSL_connect failed\n"); | |
| 3296 | + net_disconnect(hSession); | |
| 3331 | 3297 | return; |
| 3332 | 3298 | } |
| 3333 | 3299 | |
| 3334 | -// h3270.secure_connection = True; | |
| 3300 | +// hSession->secure_connection = True; | |
| 3335 | 3301 | |
| 3336 | 3302 | /* Success. */ |
| 3337 | -// trace_dsn(&h3270,"TLS/SSL negotiated connection complete. Connection is now secure.\n"); | |
| 3303 | +// trace_dsn(hSession,"TLS/SSL negotiated connection complete. Connection is now secure.\n"); | |
| 3338 | 3304 | |
| 3339 | 3305 | /* Tell the world that we are (still) connected, now in secure mode. */ |
| 3340 | - lib3270_set_connected(&h3270); | |
| 3306 | + lib3270_set_connected(hSession); | |
| 3341 | 3307 | } |
| 3342 | 3308 | |
| 3343 | 3309 | #endif /*]*/ | ... | ... |