Commit 0b463e02526cc0245dead44f734e4e7b9b632629
1 parent
d25fb3a6
Exists in
master
and in
5 other branches
Implementando opção de "override" desconexão de socket, movendo mensagems do SSL…
… do log de debug para o trace padrão
Showing
6 changed files
with
46 additions
and
33 deletions
Show diff stats
android/src/br/com/bb/pw3270/lib3270.java
| ... | ... | @@ -81,6 +81,7 @@ public class lib3270 |
| 81 | 81 | { |
| 82 | 82 | outData.write(data,0,len); |
| 83 | 83 | outData.flush(); |
| 84 | + return len; | |
| 84 | 85 | } catch( Exception e ) |
| 85 | 86 | { |
| 86 | 87 | String msg = e.getLocalizedMessage(); |
| ... | ... | @@ -315,12 +316,14 @@ public class lib3270 |
| 315 | 316 | |
| 316 | 317 | public void pfkey(int id) |
| 317 | 318 | { |
| 318 | - Log.i(TAG,"PF "+id); | |
| 319 | + Log.d(TAG,"PF"+id); | |
| 320 | + sendPFkey(id); | |
| 319 | 321 | } |
| 320 | 322 | |
| 321 | 323 | public void xmit() |
| 322 | 324 | { |
| 323 | - Log.i(TAG,"XMIT"); | |
| 325 | + Log.d(TAG,"XMIT"); | |
| 326 | + sendEnter(); | |
| 324 | 327 | } |
| 325 | 328 | |
| 326 | 329 | /*---[ External methods ]------------------------------------------------*/ | ... | ... |
src/include/lib3270/session.h
| ... | ... | @@ -274,6 +274,7 @@ |
| 274 | 274 | |
| 275 | 275 | // Session based callbacks |
| 276 | 276 | int (*write)(H3270 *hSession, unsigned const char *buf, int len); |
| 277 | + int (*disconnect)(H3270 *hSession); | |
| 277 | 278 | |
| 278 | 279 | void (*configure)(H3270 *session, unsigned short rows, unsigned short cols); |
| 279 | 280 | void (*update)(H3270 *session, int baddr, unsigned char c, unsigned short attr, unsigned char cursor); | ... | ... |
src/lib3270/globals.h
| ... | ... | @@ -354,4 +354,5 @@ LIB3270_INTERNAL int cursor_move(H3270 *session, int baddr); |
| 354 | 354 | LIB3270_INTERNAL void toggle_rectselect(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE_TYPE tt); |
| 355 | 355 | LIB3270_INTERNAL void remove_input_calls(H3270 *session); |
| 356 | 356 | |
| 357 | -LIB3270_INTERNAL int lib3270_send(H3270 *hSession, unsigned const char *buf, int len); | |
| 357 | +LIB3270_INTERNAL int lib3270_sock_send(H3270 *hSession, unsigned const char *buf, int len); | |
| 358 | +LIB3270_INTERNAL void lib3270_sock_disconnect(H3270 *hSession); | ... | ... |
src/lib3270/session.c
| ... | ... | @@ -167,7 +167,8 @@ static void lib3270_session_init(H3270 *hSession, const char *model) |
| 167 | 167 | hSession->sz = sizeof(H3270); |
| 168 | 168 | |
| 169 | 169 | // Default calls |
| 170 | - hSession->write = lib3270_send; | |
| 170 | + hSession->write = lib3270_sock_send; | |
| 171 | + hSession->disconnect = lib3270_sock_disconnect; | |
| 171 | 172 | hSession->update = update_char; |
| 172 | 173 | hSession->update_model = update_model; |
| 173 | 174 | hSession->update_cursor = update_cursor; | ... | ... |
src/lib3270/telnet.c
| ... | ... | @@ -380,8 +380,7 @@ static void set_ssl_state(H3270 *session, LIB3270_SSL_STATE state) |
| 380 | 380 | if(state == session->secure) |
| 381 | 381 | return; |
| 382 | 382 | |
| 383 | - trace_dsn("SSL state changes to %d",(int) state); | |
| 384 | - trace("SSL state changes to %d",(int) state); | |
| 383 | + trace_dsn("SSL state changes to %d\n",(int) state); | |
| 385 | 384 | |
| 386 | 385 | session->update_ssl(session,session->secure = state); |
| 387 | 386 | } |
| ... | ... | @@ -931,12 +930,11 @@ static void connection_complete(H3270 *session) |
| 931 | 930 | net_connected(session); |
| 932 | 931 | } |
| 933 | 932 | |
| 934 | -/* | |
| 935 | - * net_disconnect | |
| 936 | - * Shut down the socket. | |
| 937 | - */ | |
| 938 | -void net_disconnect(H3270 *session) | |
| 933 | + | |
| 934 | +LIB3270_INTERNAL void lib3270_sock_disconnect(H3270 *session) | |
| 939 | 935 | { |
| 936 | + trace("%s",__FUNCTION__); | |
| 937 | + | |
| 940 | 938 | #if defined(HAVE_LIBSSL) |
| 941 | 939 | if(session->ssl_con != NULL) |
| 942 | 940 | { |
| ... | ... | @@ -946,14 +944,23 @@ void net_disconnect(H3270 *session) |
| 946 | 944 | } |
| 947 | 945 | #endif |
| 948 | 946 | |
| 949 | - set_ssl_state(session,LIB3270_SSL_UNSECURE); | |
| 950 | - | |
| 951 | 947 | if(session->sock >= 0) |
| 952 | 948 | { |
| 953 | 949 | shutdown(session->sock, 2); |
| 954 | 950 | SOCK_CLOSE(session->sock); |
| 955 | 951 | session->sock = -1; |
| 956 | 952 | } |
| 953 | +} | |
| 954 | + | |
| 955 | +/* | |
| 956 | + * net_disconnect | |
| 957 | + * Shut down the socket. | |
| 958 | + */ | |
| 959 | +void net_disconnect(H3270 *session) | |
| 960 | +{ | |
| 961 | + set_ssl_state(session,LIB3270_SSL_UNSECURE); | |
| 962 | + | |
| 963 | + session->disconnect(session); | |
| 957 | 964 | |
| 958 | 965 | trace_dsn("SENT disconnect\n"); |
| 959 | 966 | |
| ... | ... | @@ -1990,7 +1997,7 @@ void net_exception(H3270 *session) |
| 1990 | 1997 | * |
| 1991 | 1998 | */ |
| 1992 | 1999 | |
| 1993 | -LIB3270_INTERNAL int lib3270_send(H3270 *hSession, unsigned const char *buf, int len) | |
| 2000 | +LIB3270_INTERNAL int lib3270_sock_send(H3270 *hSession, unsigned const char *buf, int len) | |
| 1994 | 2001 | { |
| 1995 | 2002 | int rc; |
| 1996 | 2003 | |
| ... | ... | @@ -3249,6 +3256,8 @@ static void ssl_init(H3270 *session) |
| 3249 | 3256 | /* Callback for tracing protocol negotiation. */ |
| 3250 | 3257 | static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) |
| 3251 | 3258 | { |
| 3259 | + H3270 *hSession = &h3270; // TODO: Find a better way! | |
| 3260 | + | |
| 3252 | 3261 | switch(where) |
| 3253 | 3262 | { |
| 3254 | 3263 | case SSL_CB_CONNECT_LOOP: |
| ... | ... | @@ -3257,12 +3266,11 @@ static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) |
| 3257 | 3266 | |
| 3258 | 3267 | case SSL_CB_CONNECT_EXIT: |
| 3259 | 3268 | |
| 3260 | - trace("%s: SSL_CB_CONNECT_EXIT",__FUNCTION__); | |
| 3269 | + trace_dsn("%s: SSL_CB_CONNECT_EXIT\n",__FUNCTION__); | |
| 3261 | 3270 | |
| 3262 | 3271 | if (ret == 0) |
| 3263 | 3272 | { |
| 3264 | 3273 | trace_dsn("SSL_connect: failed in %s\n",SSL_state_string_long(s)); |
| 3265 | - lib3270_write_log(&h3270,"SSL","connect failed in %s (Alert: %s)",SSL_state_string_long(s),SSL_alert_type_string_long(ret)); | |
| 3266 | 3274 | } |
| 3267 | 3275 | else if (ret < 0) |
| 3268 | 3276 | { |
| ... | ... | @@ -3297,7 +3305,7 @@ static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) |
| 3297 | 3305 | |
| 3298 | 3306 | trace_dsn("SSL Connect error in %s\nState: %s\nAlert: %s\n",err_buf,SSL_state_string_long(s),SSL_alert_type_string_long(ret)); |
| 3299 | 3307 | |
| 3300 | - show_3270_popup_dialog( &h3270, // H3270 *session, | |
| 3308 | + show_3270_popup_dialog( hSession, // H3270 *session, | |
| 3301 | 3309 | PW3270_DIALOG_CRITICAL, // PW3270_DIALOG type, |
| 3302 | 3310 | _( "SSL Connect error" ), // Title |
| 3303 | 3311 | err_buf, // Message |
| ... | ... | @@ -3310,28 +3318,28 @@ static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) |
| 3310 | 3318 | |
| 3311 | 3319 | |
| 3312 | 3320 | default: |
| 3313 | - lib3270_write_log(NULL,"SSL","Current state is \"%s\"",SSL_state_string_long(s)); | |
| 3321 | + trace_dsn("SSL Current state is \"%s\"\n",SSL_state_string_long(s)); | |
| 3314 | 3322 | } |
| 3315 | 3323 | |
| 3316 | - trace("%s: state=%04x where=%04x ret=%d",__FUNCTION__,SSL_state(s),where,ret); | |
| 3324 | +// trace("%s: state=%04x where=%04x ret=%d",__FUNCTION__,SSL_state(s),where,ret); | |
| 3317 | 3325 | |
| 3318 | 3326 | #ifdef DEBUG |
| 3319 | 3327 | if(where & SSL_CB_EXIT) |
| 3320 | 3328 | { |
| 3321 | - trace("%s: SSL_CB_EXIT ret=%d",__FUNCTION__,ret); | |
| 3329 | + trace("%s: SSL_CB_EXIT ret=%d\n",__FUNCTION__,ret); | |
| 3322 | 3330 | } |
| 3323 | 3331 | #endif |
| 3324 | 3332 | |
| 3325 | 3333 | if(where & SSL_CB_ALERT) |
| 3326 | - lib3270_write_log(NULL,"SSL","ALERT: %s",SSL_alert_type_string_long(ret)); | |
| 3334 | + trace_dsn("SSL ALERT: %s\n",SSL_alert_type_string_long(ret)); | |
| 3327 | 3335 | |
| 3328 | 3336 | if(where & SSL_CB_HANDSHAKE_DONE) |
| 3329 | 3337 | { |
| 3330 | - trace("%s: SSL_CB_HANDSHAKE_DONE state=%04x",__FUNCTION__,SSL_state(s)); | |
| 3338 | + trace_dsn("%s: SSL_CB_HANDSHAKE_DONE state=%04x\n",__FUNCTION__,SSL_state(s)); | |
| 3331 | 3339 | if(SSL_state(s) == 0x03) |
| 3332 | - set_ssl_state(&h3270,LIB3270_SSL_SECURE); | |
| 3340 | + set_ssl_state(hSession,LIB3270_SSL_SECURE); | |
| 3333 | 3341 | else |
| 3334 | - set_ssl_state(&h3270,LIB3270_SSL_UNSECURE); | |
| 3342 | + set_ssl_state(hSession,LIB3270_SSL_UNSECURE); | |
| 3335 | 3343 | } |
| 3336 | 3344 | } |
| 3337 | 3345 | |
| ... | ... | @@ -3367,7 +3375,7 @@ static void continue_tls(unsigned char *sbbuf, int len) |
| 3367 | 3375 | /* Set up the TLS/SSL connection. */ |
| 3368 | 3376 | if(SSL_set_fd(h3270.ssl_con, h3270.sock) != 1) |
| 3369 | 3377 | { |
| 3370 | - trace_dsn("Can't set fd!\n"); | |
| 3378 | + trace_dsn("SSL_set_fd failed!\n"); | |
| 3371 | 3379 | } |
| 3372 | 3380 | |
| 3373 | 3381 | //#if defined(_WIN32) | ... | ... |
src/lib3270/trace_ds.c
| ... | ... | @@ -173,11 +173,10 @@ trace_ds_s(char *s, Boolean can_break) |
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | -void | |
| 177 | -trace_ds(const char *fmt, ...) | |
| 176 | +void trace_ds(const char *fmt, ...) | |
| 178 | 177 | { |
| 179 | - char tdsbuf[4096]; | |
| 180 | - va_list args; | |
| 178 | + char * text; | |
| 179 | + va_list args; | |
| 181 | 180 | |
| 182 | 181 | if (!lib3270_get_toggle(&h3270,DS_TRACE)) |
| 183 | 182 | return; |
| ... | ... | @@ -185,9 +184,10 @@ trace_ds(const char *fmt, ...) |
| 185 | 184 | va_start(args, fmt); |
| 186 | 185 | |
| 187 | 186 | /* print out remainder of message */ |
| 188 | - (void) vsprintf(tdsbuf, fmt, args); | |
| 189 | - trace_ds_s(tdsbuf, True); | |
| 187 | + text = lib3270_vsprintf(fmt,args); | |
| 188 | + trace_ds_s(text, True); | |
| 190 | 189 | va_end(args); |
| 190 | + lib3270_free(text); | |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | void |
| ... | ... | @@ -223,8 +223,7 @@ trace_event(const char *fmt, ...) |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | /* Conditional data stream trace, without line splitting. */ |
| 226 | -void | |
| 227 | -trace_dsn(const char *fmt, ...) | |
| 226 | +void trace_dsn(const char *fmt, ...) | |
| 228 | 227 | { |
| 229 | 228 | va_list args; |
| 230 | 229 | ... | ... |