diff --git a/android/src/br/com/bb/pw3270/lib3270.java b/android/src/br/com/bb/pw3270/lib3270.java index 706c3e7..84f0b23 100644 --- a/android/src/br/com/bb/pw3270/lib3270.java +++ b/android/src/br/com/bb/pw3270/lib3270.java @@ -81,6 +81,7 @@ public class lib3270 { outData.write(data,0,len); outData.flush(); + return len; } catch( Exception e ) { String msg = e.getLocalizedMessage(); @@ -315,12 +316,14 @@ public class lib3270 public void pfkey(int id) { - Log.i(TAG,"PF "+id); + Log.d(TAG,"PF"+id); + sendPFkey(id); } public void xmit() { - Log.i(TAG,"XMIT"); + Log.d(TAG,"XMIT"); + sendEnter(); } /*---[ External methods ]------------------------------------------------*/ diff --git a/src/include/lib3270/session.h b/src/include/lib3270/session.h index 0a1d097..1173b17 100644 --- a/src/include/lib3270/session.h +++ b/src/include/lib3270/session.h @@ -274,6 +274,7 @@ // Session based callbacks int (*write)(H3270 *hSession, unsigned const char *buf, int len); + int (*disconnect)(H3270 *hSession); void (*configure)(H3270 *session, unsigned short rows, unsigned short cols); void (*update)(H3270 *session, int baddr, unsigned char c, unsigned short attr, unsigned char cursor); diff --git a/src/lib3270/globals.h b/src/lib3270/globals.h index 99dea63..04aa810 100644 --- a/src/lib3270/globals.h +++ b/src/lib3270/globals.h @@ -354,4 +354,5 @@ LIB3270_INTERNAL int cursor_move(H3270 *session, int baddr); LIB3270_INTERNAL void toggle_rectselect(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE_TYPE tt); LIB3270_INTERNAL void remove_input_calls(H3270 *session); -LIB3270_INTERNAL int lib3270_send(H3270 *hSession, unsigned const char *buf, int len); +LIB3270_INTERNAL int lib3270_sock_send(H3270 *hSession, unsigned const char *buf, int len); +LIB3270_INTERNAL void lib3270_sock_disconnect(H3270 *hSession); diff --git a/src/lib3270/session.c b/src/lib3270/session.c index dd2db41..ca1160e 100644 --- a/src/lib3270/session.c +++ b/src/lib3270/session.c @@ -167,7 +167,8 @@ static void lib3270_session_init(H3270 *hSession, const char *model) hSession->sz = sizeof(H3270); // Default calls - hSession->write = lib3270_send; + hSession->write = lib3270_sock_send; + hSession->disconnect = lib3270_sock_disconnect; hSession->update = update_char; hSession->update_model = update_model; hSession->update_cursor = update_cursor; diff --git a/src/lib3270/telnet.c b/src/lib3270/telnet.c index 22e2914..cbb7a1c 100644 --- a/src/lib3270/telnet.c +++ b/src/lib3270/telnet.c @@ -380,8 +380,7 @@ static void set_ssl_state(H3270 *session, LIB3270_SSL_STATE state) if(state == session->secure) return; - trace_dsn("SSL state changes to %d",(int) state); - trace("SSL state changes to %d",(int) state); + trace_dsn("SSL state changes to %d\n",(int) state); session->update_ssl(session,session->secure = state); } @@ -931,12 +930,11 @@ static void connection_complete(H3270 *session) net_connected(session); } -/* - * net_disconnect - * Shut down the socket. - */ -void net_disconnect(H3270 *session) + +LIB3270_INTERNAL void lib3270_sock_disconnect(H3270 *session) { + trace("%s",__FUNCTION__); + #if defined(HAVE_LIBSSL) if(session->ssl_con != NULL) { @@ -946,14 +944,23 @@ void net_disconnect(H3270 *session) } #endif - set_ssl_state(session,LIB3270_SSL_UNSECURE); - if(session->sock >= 0) { shutdown(session->sock, 2); SOCK_CLOSE(session->sock); session->sock = -1; } +} + +/* + * net_disconnect + * Shut down the socket. + */ +void net_disconnect(H3270 *session) +{ + set_ssl_state(session,LIB3270_SSL_UNSECURE); + + session->disconnect(session); trace_dsn("SENT disconnect\n"); @@ -1990,7 +1997,7 @@ void net_exception(H3270 *session) * */ -LIB3270_INTERNAL int lib3270_send(H3270 *hSession, unsigned const char *buf, int len) +LIB3270_INTERNAL int lib3270_sock_send(H3270 *hSession, unsigned const char *buf, int len) { int rc; @@ -3249,6 +3256,8 @@ static void ssl_init(H3270 *session) /* Callback for tracing protocol negotiation. */ static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) { + H3270 *hSession = &h3270; // TODO: Find a better way! + switch(where) { case SSL_CB_CONNECT_LOOP: @@ -3257,12 +3266,11 @@ static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) case SSL_CB_CONNECT_EXIT: - trace("%s: SSL_CB_CONNECT_EXIT",__FUNCTION__); + trace_dsn("%s: SSL_CB_CONNECT_EXIT\n",__FUNCTION__); if (ret == 0) { trace_dsn("SSL_connect: failed in %s\n",SSL_state_string_long(s)); - lib3270_write_log(&h3270,"SSL","connect failed in %s (Alert: %s)",SSL_state_string_long(s),SSL_alert_type_string_long(ret)); } else if (ret < 0) { @@ -3297,7 +3305,7 @@ static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) 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)); - show_3270_popup_dialog( &h3270, // H3270 *session, + show_3270_popup_dialog( hSession, // H3270 *session, PW3270_DIALOG_CRITICAL, // PW3270_DIALOG type, _( "SSL Connect error" ), // Title err_buf, // Message @@ -3310,28 +3318,28 @@ static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) default: - lib3270_write_log(NULL,"SSL","Current state is \"%s\"",SSL_state_string_long(s)); + trace_dsn("SSL Current state is \"%s\"\n",SSL_state_string_long(s)); } - trace("%s: state=%04x where=%04x ret=%d",__FUNCTION__,SSL_state(s),where,ret); +// trace("%s: state=%04x where=%04x ret=%d",__FUNCTION__,SSL_state(s),where,ret); #ifdef DEBUG if(where & SSL_CB_EXIT) { - trace("%s: SSL_CB_EXIT ret=%d",__FUNCTION__,ret); + trace("%s: SSL_CB_EXIT ret=%d\n",__FUNCTION__,ret); } #endif if(where & SSL_CB_ALERT) - lib3270_write_log(NULL,"SSL","ALERT: %s",SSL_alert_type_string_long(ret)); + trace_dsn("SSL ALERT: %s\n",SSL_alert_type_string_long(ret)); if(where & SSL_CB_HANDSHAKE_DONE) { - trace("%s: SSL_CB_HANDSHAKE_DONE state=%04x",__FUNCTION__,SSL_state(s)); + trace_dsn("%s: SSL_CB_HANDSHAKE_DONE state=%04x\n",__FUNCTION__,SSL_state(s)); if(SSL_state(s) == 0x03) - set_ssl_state(&h3270,LIB3270_SSL_SECURE); + set_ssl_state(hSession,LIB3270_SSL_SECURE); else - set_ssl_state(&h3270,LIB3270_SSL_UNSECURE); + set_ssl_state(hSession,LIB3270_SSL_UNSECURE); } } @@ -3367,7 +3375,7 @@ static void continue_tls(unsigned char *sbbuf, int len) /* Set up the TLS/SSL connection. */ if(SSL_set_fd(h3270.ssl_con, h3270.sock) != 1) { - trace_dsn("Can't set fd!\n"); + trace_dsn("SSL_set_fd failed!\n"); } //#if defined(_WIN32) diff --git a/src/lib3270/trace_ds.c b/src/lib3270/trace_ds.c index 217cdc6..2e99906 100644 --- a/src/lib3270/trace_ds.c +++ b/src/lib3270/trace_ds.c @@ -173,11 +173,10 @@ trace_ds_s(char *s, Boolean can_break) } } -void -trace_ds(const char *fmt, ...) +void trace_ds(const char *fmt, ...) { - char tdsbuf[4096]; - va_list args; + char * text; + va_list args; if (!lib3270_get_toggle(&h3270,DS_TRACE)) return; @@ -185,9 +184,10 @@ trace_ds(const char *fmt, ...) va_start(args, fmt); /* print out remainder of message */ - (void) vsprintf(tdsbuf, fmt, args); - trace_ds_s(tdsbuf, True); + text = lib3270_vsprintf(fmt,args); + trace_ds_s(text, True); va_end(args); + lib3270_free(text); } void @@ -223,8 +223,7 @@ trace_event(const char *fmt, ...) } /* Conditional data stream trace, without line splitting. */ -void -trace_dsn(const char *fmt, ...) +void trace_dsn(const char *fmt, ...) { va_list args; -- libgit2 0.21.2