From 69991adda77ab35606b2c043d708857bfbe93a88 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Tue, 7 Aug 2012 10:59:06 +0000 Subject: [PATCH] Ajustando macros e chamadas da GSource para tratar o handle de sessao --- src/lib3270/api.h | 20 ++++++++++---------- src/lib3270/ctlr.c | 15 ++++++++------- src/lib3270/ft.c | 12 ++++++------ src/lib3270/host.c | 56 ++++++++++++++++++++++++++++---------------------------- src/lib3270/kybd.c | 50 +++++++++++++++++++++++++------------------------- src/lib3270/screen.c | 30 ++++++++++-------------------- src/lib3270/telnet.c | 397 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/pw3270/v3270/iocallback.c | 5 +---- 8 files changed, 288 insertions(+), 297 deletions(-) diff --git a/src/lib3270/api.h b/src/lib3270/api.h index 4663319..5f22fcd 100644 --- a/src/lib3270/api.h +++ b/src/lib3270/api.h @@ -242,16 +242,16 @@ LOCAL_EXTERN int RegisterFTCallbacks(const struct filetransfer_callbacks *cbk); */ - #define PCONNECTED lib3270_pconnected(NULL) - #define HALF_CONNECTED lib3270_half_connected(NULL) - #define CONNECTED lib3270_connected(NULL) - - #define IN_NEITHER lib3270_in_neither(NULL) - #define IN_ANSI lib3270_in_ansi(NULL) - #define IN_3270 lib3270_in_3270(NULL) - #define IN_SSCP lib3270_in_sscp(NULL) - #define IN_TN3270E lib3270_in_tn3270e(NULL) - #define IN_E lib3270_in_e(NULL) + #define PCONNECTED lib3270_pconnected(hSession) + #define HALF_CONNECTED lib3270_half_connected(hSession) + #define CONNECTED lib3270_connected(hSession) + + #define IN_NEITHER lib3270_in_neither(hSession) + #define IN_ANSI lib3270_in_ansi(hSession) + #define IN_3270 lib3270_in_3270(hSession) + #define IN_SSCP lib3270_in_sscp(hSession) + #define IN_TN3270E lib3270_in_tn3270e(hSession) + #define IN_E lib3270_in_e(hSession) #ifndef LIB3270 diff --git a/src/lib3270/ctlr.c b/src/lib3270/ctlr.c index 6f87307..eb774dc 100644 --- a/src/lib3270/ctlr.c +++ b/src/lib3270/ctlr.c @@ -155,26 +155,27 @@ void ctlr_reinit(H3270 *session, unsigned cmask) /** * Get current 3270 model. * - * @param session selected 3270 session. + * @param hSession selected 3270 session. * @return Current model number. */ -int lib3270_get_model(H3270 *session) +int lib3270_get_model(H3270 *hSession) { - return session->model_num; + return hSession->model_num; } /** * Deal with the relationships between model numbers and rows/cols. * - * @param model New model (updates model name) + * @param hSession Session handle. + * @param model New model (updates model name) */ -int lib3270_set_model(H3270 *session, int model) +int lib3270_set_model(H3270 *hSession, int model) { if(CONNECTED) return EBUSY; - ctlr_set_rows_cols(session,model,session->ov_cols,session->ov_rows); - ctlr_reinit(session,MODEL_CHANGE); + ctlr_set_rows_cols(hSession,model,hSession->ov_cols,hSession->ov_rows); + ctlr_reinit(hSession,MODEL_CHANGE); return 0; } diff --git a/src/lib3270/ft.c b/src/lib3270/ft.c index 1e6ad23..e8ac46d 100644 --- a/src/lib3270/ft.c +++ b/src/lib3270/ft.c @@ -514,17 +514,17 @@ void ft_aborting(H3270FT *h) } /* Process a disconnect abort. */ -static void ft_connected(H3270 *session, int ignored, void *dunno) +static void ft_connected(H3270 *hSession, int ignored, void *dunno) { - if (!CONNECTED && lib3270_get_ft_state(session) != LIB3270_FT_STATE_NONE) - ft_complete(get_ft_handle(session),_("Host disconnected, transfer cancelled")); + if (!CONNECTED && lib3270_get_ft_state(hSession) != LIB3270_FT_STATE_NONE) + ft_complete(get_ft_handle(hSession),_("Host disconnected, transfer cancelled")); } /* Process an abort from no longer being in 3270 mode. */ -static void ft_in3270(H3270 *session, int ignored, void *dunno) +static void ft_in3270(H3270 *hSession, int ignored, void *dunno) { - if (!IN_3270 && lib3270_get_ft_state(session) != LIB3270_FT_STATE_NONE) - ft_complete(get_ft_handle(session),_("Not in 3270 mode, transfer cancelled")); + if (!IN_3270 && lib3270_get_ft_state(hSession) != LIB3270_FT_STATE_NONE) + ft_complete(get_ft_handle(hSession),_("Not in 3270 mode, transfer cancelled")); } LIB3270_EXPORT LIB3270_FT_STATE lib3270_get_ft_state(H3270 *session) diff --git a/src/lib3270/host.c b/src/lib3270/host.c index 9c8c780..9371c71 100644 --- a/src/lib3270/host.c +++ b/src/lib3270/host.c @@ -605,15 +605,15 @@ static int do_connect(H3270 *hSession, const char *n) * @return 0 if the connection was ok, non zero on error. * */ -int lib3270_connect(H3270 *h, const char *n, int wait) +int lib3270_connect(H3270 *hSession, const char *n, int wait) { int rc; - CHECK_SESSION_HANDLE(h); + CHECK_SESSION_HANDLE(hSession); - lib3270_main_iterate(h,0); + lib3270_main_iterate(hSession,0); - if(h->auto_reconnect_inprogress) + if(hSession->auto_reconnect_inprogress) return EAGAIN; if(PCONNECTED) @@ -621,12 +621,12 @@ int lib3270_connect(H3270 *h, const char *n, int wait) if(!n) { - n = h->full_current_host; + n = hSession->full_current_host; if(!n) return EINVAL; } - rc = do_connect(h,n); + rc = do_connect(hSession,n); if(rc) return rc; @@ -634,7 +634,7 @@ int lib3270_connect(H3270 *h, const char *n, int wait) { while(!IN_ANSI && !IN_3270) { - lib3270_main_iterate(h,1); + lib3270_main_iterate(hSession,1); if(!PCONNECTED) { @@ -661,22 +661,22 @@ LIB3270_EXPORT void lib3270_disconnect(H3270 *h) host_disconnect(h,0); } -void host_disconnect(H3270 *h, int failed) +void host_disconnect(H3270 *hSession, int failed) { - CHECK_SESSION_HANDLE(h); + CHECK_SESSION_HANDLE(hSession); if (CONNECTED || HALF_CONNECTED) { // Disconecting, disable input - remove_input_calls(h); - net_disconnect(h); + remove_input_calls(hSession); + net_disconnect(hSession); - trace("Disconnected (Failed: %d Reconnect: %d in_progress: %d)",failed,lib3270_get_toggle(h,LIB3270_TOGGLE_RECONNECT),h->auto_reconnect_inprogress); - if (lib3270_get_toggle(h,LIB3270_TOGGLE_RECONNECT) && !h->auto_reconnect_inprogress) + trace("Disconnected (Failed: %d Reconnect: %d in_progress: %d)",failed,lib3270_get_toggle(hSession,LIB3270_TOGGLE_RECONNECT),hSession->auto_reconnect_inprogress); + if (lib3270_get_toggle(hSession,LIB3270_TOGGLE_RECONNECT) && !hSession->auto_reconnect_inprogress) { /* Schedule an automatic reconnection. */ - h->auto_reconnect_inprogress = 1; - (void) AddTimeOut(failed ? RECONNECT_ERR_MS: RECONNECT_MS, h, try_reconnect); + hSession->auto_reconnect_inprogress = 1; + (void) AddTimeOut(failed ? RECONNECT_ERR_MS: RECONNECT_MS, hSession, try_reconnect); } /* @@ -684,24 +684,24 @@ void host_disconnect(H3270 *h, int failed) * in sync. */ #if defined(X3270_TRACE) /*[*/ - if (IN_ANSI && lib3270_get_toggle(h,LIB3270_TOGGLE_SCREEN_TRACE)) - trace_ansi_disc(h); + if (IN_ANSI && lib3270_get_toggle(hSession,LIB3270_TOGGLE_SCREEN_TRACE)) + trace_ansi_disc(hSession); #endif /*]*/ - lib3270_set_disconnected(h); + lib3270_set_disconnected(hSession); } } /* The host has entered 3270 or ANSI mode, or switched between them. */ -void host_in3270(H3270 *session, LIB3270_CSTATE new_cstate) +void host_in3270(H3270 *hSession, LIB3270_CSTATE new_cstate) { Boolean now3270 = (new_cstate == CONNECTED_3270 || new_cstate == CONNECTED_SSCP || new_cstate == CONNECTED_TN3270E); - session->cstate = new_cstate; - session->ever_3270 = now3270; - lib3270_st_changed(session, LIB3270_STATE_3270_MODE, now3270); + hSession->cstate = new_cstate; + hSession->ever_3270 = now3270; + lib3270_st_changed(hSession, LIB3270_STATE_3270_MODE, now3270); } void lib3270_set_connected(H3270 *hSession) @@ -805,26 +805,26 @@ LIB3270_EXPORT const char * lib3270_get_host(H3270 *h) return h->full_current_host; } -LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int wait) +LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int wait) { int rc; - CHECK_SESSION_HANDLE(h); + CHECK_SESSION_HANDLE(hSession); if (CONNECTED || HALF_CONNECTED) return EBUSY; - if (h->full_current_host == CN) + if (hSession->full_current_host == CN) return EINVAL; - if (h->auto_reconnect_inprogress) + if (hSession->auto_reconnect_inprogress) return EBUSY; - rc = lib3270_connect(h,h->full_current_host,wait); + rc = lib3270_connect(hSession,hSession->full_current_host,wait); if(rc) { - h->auto_reconnect_inprogress = 0; + hSession->auto_reconnect_inprogress = 0; return rc; } diff --git a/src/lib3270/kybd.c b/src/lib3270/kybd.c index 571d097..7a8c83a 100644 --- a/src/lib3270/kybd.c +++ b/src/lib3270/kybd.c @@ -456,15 +456,15 @@ void kybd_connect(H3270 *session, int connected, void *dunno) /* * Called when we switch between 3270 and ANSI modes. */ -void kybd_in3270(H3270 *session, int in3270 unused, void *dunno) +void kybd_in3270(H3270 *hSession, int in3270 unused, void *dunno) { - if (session->kybdlock & KL_DEFERRED_UNLOCK) - RemoveTimeOut(session->unlock_id); - lib3270_kybdlock_clear(session,~KL_AWAITING_FIRST); + if (hSession->kybdlock & KL_DEFERRED_UNLOCK) + RemoveTimeOut(hSession->unlock_id); + lib3270_kybdlock_clear(hSession,~KL_AWAITING_FIRST); /* There might be a macro pending. */ if (CONNECTED) - ps_process(session); + ps_process(hSession); } /* @@ -1113,19 +1113,19 @@ LIB3270_ACTION( previousfield ) * Deferred keyboard unlock. */ -static void defer_unlock(H3270 *session) +static void defer_unlock(H3270 *hSession) { // trace("%s",__FUNCTION__); - lib3270_kybdlock_clear(session,KL_DEFERRED_UNLOCK); - status_reset(session); + lib3270_kybdlock_clear(hSession,KL_DEFERRED_UNLOCK); + status_reset(hSession); if(CONNECTED) - ps_process(session); + ps_process(hSession); } /* * Reset keyboard lock. */ -void do_reset(H3270 *session, Boolean explicit) +void do_reset(H3270 *hSession, Boolean explicit) { /* * If explicit (from the keyboard) and there is typeahead or @@ -1134,12 +1134,12 @@ void do_reset(H3270 *session, Boolean explicit) if (explicit #if defined(X3270_FT) /*[*/ - || lib3270_get_ft_state(session) != LIB3270_FT_STATE_NONE + || lib3270_get_ft_state(hSession) != LIB3270_FT_STATE_NONE #endif /*]*/ ) { Boolean half_reset = False; - if (flush_ta(session)) + if (flush_ta(hSession)) half_reset = True; if (half_reset) @@ -1147,7 +1147,7 @@ void do_reset(H3270 *session, Boolean explicit) } /* Always clear insert mode. */ - lib3270_set_toggle(session,LIB3270_TOGGLE_INSERT,0); + lib3270_set_toggle(hSession,LIB3270_TOGGLE_INSERT,0); /* Otherwise, if not connect, reset is a no-op. */ if (!CONNECTED) @@ -1157,8 +1157,8 @@ void do_reset(H3270 *session, Boolean explicit) * Remove any deferred keyboard unlock. We will either unlock the * keyboard now, or want to defer further into the future. */ - if (session->kybdlock & KL_DEFERRED_UNLOCK) - RemoveTimeOut(session->unlock_id); + if (hSession->kybdlock & KL_DEFERRED_UNLOCK) + RemoveTimeOut(hSession->unlock_id); /* * If explicit (from the keyboard), unlock the keyboard now. @@ -1166,21 +1166,21 @@ void do_reset(H3270 *session, Boolean explicit) */ if (explicit #if defined(X3270_FT) /*[*/ - || lib3270_get_ft_state(session) != LIB3270_FT_STATE_NONE + || lib3270_get_ft_state(hSession) != LIB3270_FT_STATE_NONE #endif /*]*/ - || (!session->unlock_delay) // && !sms_in_macro()) - || (session->unlock_delay_time != 0 && (time(NULL) - session->unlock_delay_time) > 1)) { - lib3270_kybdlock_clear(session,-1); - } else if (session->kybdlock & + || (!hSession->unlock_delay) // && !sms_in_macro()) + || (hSession->unlock_delay_time != 0 && (time(NULL) - hSession->unlock_delay_time) > 1)) { + lib3270_kybdlock_clear(hSession,-1); + } else if (hSession->kybdlock & (KL_DEFERRED_UNLOCK | KL_OIA_TWAIT | KL_OIA_LOCKED | KL_AWAITING_FIRST)) { - lib3270_kybdlock_clear(session,~KL_DEFERRED_UNLOCK); - kybdlock_set(session,KL_DEFERRED_UNLOCK); - session->unlock_id = AddTimeOut(UNLOCK_MS, session, defer_unlock); + lib3270_kybdlock_clear(hSession,~KL_DEFERRED_UNLOCK); + kybdlock_set(hSession,KL_DEFERRED_UNLOCK); + hSession->unlock_id = AddTimeOut(UNLOCK_MS, hSession, defer_unlock); } /* Clean up other modes. */ - status_reset(session); - mcursor_normal(session); + status_reset(hSession); + mcursor_normal(hSession); } diff --git a/src/lib3270/screen.c b/src/lib3270/screen.c index 70677d8..eb521e7 100644 --- a/src/lib3270/screen.c +++ b/src/lib3270/screen.c @@ -538,51 +538,41 @@ void status_lu(H3270 *session, const char *lu) } -static void status_connect(H3270 *session, int connected, void *dunno) +static void status_connect(H3270 *hSession, int connected, void *dunno) { LIB3270_STATUS id = LIB3270_STATUS_USER; - ctlr_erase(session,1); + ctlr_erase(hSession,1); if (connected) { - set_status(session,OIA_FLAG_BOXSOLID,IN_3270 && !IN_SSCP); + set_status(hSession,OIA_FLAG_BOXSOLID,IN_3270 && !IN_SSCP); - if (session->kybdlock & KL_AWAITING_FIRST) + if (hSession->kybdlock & KL_AWAITING_FIRST) id = LIB3270_STATUS_AWAITING_FIRST; else id = LIB3270_STATUS_CONNECTED; -/* -#if defined(HAVE_LIBSSL) - set_status(session,OIA_FLAG_SECURE,session->secure_connection); -#endif -*/ - } else { - set_status(session,OIA_FLAG_BOXSOLID,False); -/* - set_status(session,OIA_FLAG_SECURE,False); -*/ - + set_status(hSession,OIA_FLAG_BOXSOLID,False); id = LIB3270_STATUS_DISCONNECTED; } - status_changed(session,id); + status_changed(hSession,id); } -static void status_3270_mode(H3270 *session, int ignored unused, void *dunno) +static void status_3270_mode(H3270 *hSession, int ignored unused, void *dunno) { Boolean oia_boxsolid = (IN_3270 && !IN_SSCP); - CHECK_SESSION_HANDLE(session); + CHECK_SESSION_HANDLE(hSession); if(oia_boxsolid) - set_status(session,OIA_FLAG_UNDERA,True); - set_status(session,OIA_FLAG_BOXSOLID,oia_boxsolid); + set_status(hSession,OIA_FLAG_UNDERA,True); + set_status(hSession,OIA_FLAG_BOXSOLID,oia_boxsolid); } diff --git a/src/lib3270/telnet.c b/src/lib3270/telnet.c index f11c071..d9c3741 100644 --- a/src/lib3270/telnet.c +++ b/src/lib3270/telnet.c @@ -1009,43 +1009,46 @@ LIB3270_EXPORT void lib3270_data_recv(H3270 *hSession, size_t nr, const unsigned #endif // X3270_ANSI } - -/* - * net_input - * Called by the toolkit whenever there is input available on the - * socket. Reads the data, processes the special telnet commands - * and calls process_ds to process the 3270 data stream. +/** + * net_input. + * + * Called by the toolkit whenever there is input available on the + * socket. Reads the data, processes the special telnet commands + * and calls process_ds to process the 3270 data stream. + * + * @param hSession Session handle + * */ -void net_input(H3270 *session) +void net_input(H3270 *hSession) { // register unsigned char * cp; int nr; unsigned char buffer[BUFSZ]; - CHECK_SESSION_HANDLE(session); + CHECK_SESSION_HANDLE(hSession); #if defined(_WIN32) for (;;) #endif { - if (session->sock < 0) + if (hSession->sock < 0) return; #if defined(X3270_ANSI) - session->ansi_data = 0; + hSession->ansi_data = 0; #endif #if defined(_WIN32) - ResetEvent(session->sockEvent); + ResetEvent(hSession->sockEvent); #endif #if defined(HAVE_LIBSSL) - if (session->ssl_con != NULL) - nr = SSL_read(session->ssl_con, (char *) buffer, BUFSZ); + if (hSession->ssl_con != NULL) + nr = SSL_read(hSession->ssl_con, (char *) buffer, BUFSZ); else - nr = recv(session->sock, (char *) buffer, BUFSZ, 0); + nr = recv(hSession->sock, (char *) buffer, BUFSZ, 0); #else - nr = recv(session->sock, (char *) buffer, BUFSZ, 0); + nr = recv(hSession->sock, (char *) buffer, BUFSZ, 0); #endif // HAVE_LIBSSL if (nr < 0) @@ -1054,7 +1057,7 @@ void net_input(H3270 *session) return; #if defined(HAVE_LIBSSL) /*[*/ - if(session->ssl_con != NULL) + if(hSession->ssl_con != NULL) { unsigned long e; char err_buf[120]; @@ -1065,55 +1068,55 @@ void net_input(H3270 *session) else strcpy(err_buf, _( "unknown error" ) ); - trace_dsn(session,"RCVD SSL_read error %ld (%s)\n", e,err_buf); + trace_dsn(hSession,"RCVD SSL_read error %ld (%s)\n", e,err_buf); - session->message( session,LIB3270_NOTIFY_ERROR,_( "SSL Error" ),_( "SSL Read error" ),err_buf ); + hSession->message(hSession,LIB3270_NOTIFY_ERROR,_( "SSL Error" ),_( "SSL Read error" ),err_buf ); - host_disconnect(session,True); + host_disconnect(hSession,True); return; } #endif /*]*/ if (HALF_CONNECTED && socket_errno() == SE_EAGAIN) { - connection_complete(session); + connection_complete(hSession); return; } - trace_dsn(session,"RCVD socket error %d\n", errno); + trace_dsn(hSession,"RCVD socket error %d\n", errno); if (HALF_CONNECTED) { - popup_a_sockerr(session, N_( "%s:%d" ),session->hostname, session->current_port); + popup_a_sockerr(hSession, N_( "%s:%d" ),hSession->hostname, hSession->current_port); } else if (socket_errno() != SE_ECONNRESET) { - popup_a_sockerr(session, N_( "Socket read error" ) ); + popup_a_sockerr(hSession, N_( "Socket read error" ) ); } - host_disconnect(session,True); + host_disconnect(hSession,True); return; } else if (nr == 0) { /* Host disconnected. */ - trace_dsn(session,"RCVD disconnect\n"); - host_disconnect(session,False); + trace_dsn(hSession,"RCVD disconnect\n"); + host_disconnect(hSession,False); return; } /* Process the data. */ if (HALF_CONNECTED) { - if (non_blocking(session,False) < 0) + if (non_blocking(hSession,False) < 0) { - host_disconnect(session,True); + host_disconnect(hSession,True); return; } - lib3270_set_connected(session); - net_connected(session); + lib3270_set_connected(hSession); + net_connected(hSession); } - lib3270_data_recv(session, nr, buffer); + lib3270_data_recv(hSession, nr, buffer); /* trace_netdata('<', session->netrbuf, nr); @@ -1201,65 +1204,64 @@ static void next_lu(H3270 *hSession) * Telnet finite-state machine. * Returns 0 for okay, -1 for errors. */ -static int telnet_fsm(H3270 *session, unsigned char c) +static int telnet_fsm(H3270 *hSession, unsigned char c) { #if defined(X3270_ANSI) /*[*/ char *see_chr; int sl; #endif /*]*/ - switch (session->telnet_state) + switch (hSession->telnet_state) { case TNS_DATA: /* normal data processing */ if (c == IAC) { /* got a telnet command */ - session->telnet_state = TNS_IAC; + hSession->telnet_state = TNS_IAC; #if defined(X3270_ANSI) /*[*/ - if (session->ansi_data) { - trace_dsn(session,"\n"); - session->ansi_data = 0; + if (hSession->ansi_data) { + trace_dsn(hSession,"\n"); + hSession->ansi_data = 0; } #endif /*]*/ break; } if (IN_NEITHER) { /* now can assume ANSI mode */ #if defined(X3270_ANSI)/*[*/ - if (session->linemode) - cooked_init(session); + if (hSession->linemode) + cooked_init(hSession); #endif /*]*/ - host_in3270(session,CONNECTED_ANSI); - lib3270_kybdlock_clear(session,KL_AWAITING_FIRST); - status_reset(session); - ps_process(session); + host_in3270(hSession,CONNECTED_ANSI); + lib3270_kybdlock_clear(hSession,KL_AWAITING_FIRST); + status_reset(hSession); + ps_process(hSession); } if (IN_ANSI && !IN_E) { #if defined(X3270_ANSI) /*[*/ - if (!session->ansi_data) { - trace_dsn(session,"<.. "); - session->ansi_data = 4; + if (!hSession->ansi_data) { + trace_dsn(hSession,"<.. "); + hSession->ansi_data = 4; } see_chr = ctl_see((int) c); - session->ansi_data += (sl = strlen(see_chr)); - if (session->ansi_data >= TRACELINE) { - trace_dsn(session," ...\n... "); - session->ansi_data = 4 + sl; + hSession->ansi_data += (sl = strlen(see_chr)); + if (hSession->ansi_data >= TRACELINE) { + trace_dsn(hSession," ...\n... "); + hSession->ansi_data = 4 + sl; } - trace_dsn(session,"%s",see_chr); - if (!session->syncing) + trace_dsn(hSession,"%s",see_chr); + if (!hSession->syncing) { - if (session->linemode && session->onlcr && c == '\n') - ansi_process(session,(unsigned int) '\r'); - ansi_process(session,(unsigned int) c); -// sms_store(c); + if (hSession->linemode && hSession->onlcr && c == '\n') + ansi_process(hSession,(unsigned int) '\r'); + ansi_process(hSession,(unsigned int) c); } #endif /*]*/ } else { - store3270in(session,c); + store3270in(hSession,c); } break; case TNS_IAC: /* process a telnet command */ if (c != EOR && c != IAC) { - trace_dsn(session,"RCVD %s ", cmd(c)); + trace_dsn(hSession,"RCVD %s ", cmd(c)); } switch (c) @@ -1268,91 +1270,91 @@ static int telnet_fsm(H3270 *session, unsigned char c) if (IN_ANSI && !IN_E) { #if defined(X3270_ANSI) /*[*/ - if (!session->ansi_data) + if (!hSession->ansi_data) { - trace_dsn(session,"<.. "); - session->ansi_data = 4; + trace_dsn(hSession,"<.. "); + hSession->ansi_data = 4; } see_chr = ctl_see((int) c); - session->ansi_data += (sl = strlen(see_chr)); - if (session->ansi_data >= TRACELINE) + hSession->ansi_data += (sl = strlen(see_chr)); + if (hSession->ansi_data >= TRACELINE) { - trace_dsn(session," ...\n ..."); - session->ansi_data = 4 + sl; + trace_dsn(hSession," ...\n ..."); + hSession->ansi_data = 4 + sl; } - trace_dsn(session,"%s",see_chr); - ansi_process(session,(unsigned int) c); + trace_dsn(hSession,"%s",see_chr); + ansi_process(hSession,(unsigned int) c); #endif /*]*/ } else { - store3270in(session,c); + store3270in(hSession,c); } - session->telnet_state = TNS_DATA; + hSession->telnet_state = TNS_DATA; break; case EOR: /* eor, process accumulated input */ - if (IN_3270 || (IN_E && session->tn3270e_negotiated)) + if (IN_3270 || (IN_E && hSession->tn3270e_negotiated)) { - session->ns_rrcvd++; - if (process_eor(session)) + hSession->ns_rrcvd++; + if (process_eor(hSession)) return -1; } else - Warning(session, _( "EOR received when not in 3270 mode, ignored." )); + Warning(hSession, _( "EOR received when not in 3270 mode, ignored." )); - trace_dsn(session,"RCVD EOR\n"); - session->ibptr = session->ibuf; - session->telnet_state = TNS_DATA; + trace_dsn(hSession,"RCVD EOR\n"); + hSession->ibptr = hSession->ibuf; + hSession->telnet_state = TNS_DATA; break; case WILL: - session->telnet_state = TNS_WILL; + hSession->telnet_state = TNS_WILL; break; case WONT: - session->telnet_state = TNS_WONT; + hSession->telnet_state = TNS_WONT; break; case DO: - session->telnet_state = TNS_DO; + hSession->telnet_state = TNS_DO; break; case DONT: - session->telnet_state = TNS_DONT; + hSession->telnet_state = TNS_DONT; break; case SB: - session->telnet_state = TNS_SB; - if (session->sbbuf == (unsigned char *)NULL) - session->sbbuf = (unsigned char *)lib3270_malloc(1024); - session->sbptr = session->sbbuf; + hSession->telnet_state = TNS_SB; + if (hSession->sbbuf == (unsigned char *)NULL) + hSession->sbbuf = (unsigned char *)lib3270_malloc(1024); + hSession->sbptr = hSession->sbbuf; break; case DM: - trace_dsn(session,"\n"); - if (session->syncing) + trace_dsn(hSession,"\n"); + if (hSession->syncing) { - session->syncing = 0; - x_except_on(session); + hSession->syncing = 0; + x_except_on(hSession); } - session->telnet_state = TNS_DATA; + hSession->telnet_state = TNS_DATA; break; case GA: case NOP: - trace_dsn(session,"\n"); - session->telnet_state = TNS_DATA; + trace_dsn(hSession,"\n"); + hSession->telnet_state = TNS_DATA; break; default: - trace_dsn(session,"???\n"); - session->telnet_state = TNS_DATA; + trace_dsn(hSession,"???\n"); + hSession->telnet_state = TNS_DATA; break; } break; case TNS_WILL: /* telnet WILL DO OPTION command */ - trace_dsn(session,"%s\n", opt(c)); + trace_dsn(hSession,"%s\n", opt(c)); switch (c) { case TELOPT_SGA: case TELOPT_BINARY: @@ -1362,54 +1364,54 @@ static int telnet_fsm(H3270 *session, unsigned char c) #if defined(X3270_TN3270E) /*[*/ case TELOPT_TN3270E: #endif /*]*/ - if (c != TELOPT_TN3270E || !session->non_tn3270e_host) { - if (!session->hisopts[c]) { - session->hisopts[c] = 1; + if (c != TELOPT_TN3270E || !hSession->non_tn3270e_host) { + if (!hSession->hisopts[c]) { + hSession->hisopts[c] = 1; do_opt[2] = c; - net_rawout(session,do_opt, sizeof(do_opt)); - trace_dsn(session,"SENT %s %s\n", + net_rawout(hSession,do_opt, sizeof(do_opt)); + trace_dsn(hSession,"SENT %s %s\n", cmd(DO), opt(c)); /* * For UTS, volunteer to do EOR when * they do. */ - if (c == TELOPT_EOR && !session->myopts[c]) { - session->myopts[c] = 1; + if (c == TELOPT_EOR && !hSession->myopts[c]) { + hSession->myopts[c] = 1; will_opt[2] = c; - net_rawout(session,will_opt,sizeof(will_opt)); - trace_dsn(session,"SENT %s %s\n",cmd(WILL), opt(c)); + net_rawout(hSession,will_opt,sizeof(will_opt)); + trace_dsn(hSession,"SENT %s %s\n",cmd(WILL), opt(c)); } - check_in3270(session); - check_linemode(session,False); + check_in3270(hSession); + check_linemode(hSession,False); } break; } default: dont_opt[2] = c; - net_rawout(session,dont_opt, sizeof(dont_opt)); - trace_dsn(session,"SENT %s %s\n", cmd(DONT), opt(c)); + net_rawout(hSession,dont_opt, sizeof(dont_opt)); + trace_dsn(hSession,"SENT %s %s\n", cmd(DONT), opt(c)); break; } - session->telnet_state = TNS_DATA; + hSession->telnet_state = TNS_DATA; break; case TNS_WONT: /* telnet WONT DO OPTION command */ - trace_dsn(session,"%s\n", opt(c)); - if (session->hisopts[c]) + trace_dsn(hSession,"%s\n", opt(c)); + if (hSession->hisopts[c]) { - session->hisopts[c] = 0; + hSession->hisopts[c] = 0; dont_opt[2] = c; - net_rawout(session, dont_opt, sizeof(dont_opt)); - trace_dsn(session,"SENT %s %s\n", cmd(DONT), opt(c)); - check_in3270(session); - check_linemode(session,False); + net_rawout(hSession, dont_opt, sizeof(dont_opt)); + trace_dsn(hSession,"SENT %s %s\n", cmd(DONT), opt(c)); + check_in3270(hSession); + check_linemode(hSession,False); } - session->telnet_state = TNS_DATA; + hSession->telnet_state = TNS_DATA; break; case TNS_DO: /* telnet PLEASE DO OPTION command */ - trace_dsn(session,"%s\n", opt(c)); + trace_dsn(hSession,"%s\n", opt(c)); switch (c) { case TELOPT_BINARY: case TELOPT_EOR: @@ -1423,24 +1425,24 @@ static int telnet_fsm(H3270 *session, unsigned char c) #if defined(HAVE_LIBSSL) /*[*/ case TELOPT_STARTTLS: #endif /*]*/ - if (c == TELOPT_TN3270E && session->non_tn3270e_host) + if (c == TELOPT_TN3270E && hSession->non_tn3270e_host) goto wont; - if (c == TELOPT_TM && !session->bsd_tm) + if (c == TELOPT_TM && !hSession->bsd_tm) goto wont; - trace("session->myopts[c]=%d",session->myopts[c]); - if (!session->myopts[c]) + trace("hSession->myopts[c]=%d",hSession->myopts[c]); + if (!hSession->myopts[c]) { if (c != TELOPT_TM) - session->myopts[c] = 1; + hSession->myopts[c] = 1; will_opt[2] = c; - net_rawout(session, will_opt, sizeof(will_opt)); - trace_dsn(session,"SENT %s %s\n", cmd(WILL), opt(c)); - check_in3270(session); - check_linemode(session,False); + net_rawout(hSession, will_opt, sizeof(will_opt)); + trace_dsn(hSession,"SENT %s %s\n", cmd(WILL), opt(c)); + check_in3270(hSession); + check_linemode(hSession,False); } if (c == TELOPT_NAWS) - send_naws(session); + send_naws(hSession); #if defined(HAVE_LIBSSL) /*[*/ if (c == TELOPT_STARTTLS) { static unsigned char follows_msg[] = { @@ -1452,82 +1454,82 @@ static int telnet_fsm(H3270 *session, unsigned char c) * Send IAC SB STARTTLS FOLLOWS IAC SE * to announce that what follows is TLS. */ - net_rawout(session, follows_msg, sizeof(follows_msg)); - trace_dsn(session,"SENT %s %s FOLLOWS %s\n", + net_rawout(hSession, follows_msg, sizeof(follows_msg)); + trace_dsn(hSession,"SENT %s %s FOLLOWS %s\n", cmd(SB), opt(TELOPT_STARTTLS), cmd(SE)); - session->need_tls_follows = 1; + hSession->need_tls_follows = 1; } #endif /*]*/ break; default: wont: wont_opt[2] = c; - net_rawout(session, wont_opt, sizeof(wont_opt)); - trace_dsn(session,"SENT %s %s\n", cmd(WONT), opt(c)); + net_rawout(hSession, wont_opt, sizeof(wont_opt)); + trace_dsn(hSession,"SENT %s %s\n", cmd(WONT), opt(c)); break; } - session->telnet_state = TNS_DATA; + hSession->telnet_state = TNS_DATA; break; case TNS_DONT: /* telnet PLEASE DON'T DO OPTION command */ - trace_dsn(session,"%s\n", opt(c)); - if (session->myopts[c]) { - session->myopts[c] = 0; + trace_dsn(hSession,"%s\n", opt(c)); + if (hSession->myopts[c]) { + hSession->myopts[c] = 0; wont_opt[2] = c; - net_rawout(session, wont_opt, sizeof(wont_opt)); - trace_dsn(session,"SENT %s %s\n", cmd(WONT), opt(c)); - check_in3270(session); - check_linemode(session,False); + net_rawout(hSession, wont_opt, sizeof(wont_opt)); + trace_dsn(hSession,"SENT %s %s\n", cmd(WONT), opt(c)); + check_in3270(hSession); + check_linemode(hSession,False); } - session->telnet_state = TNS_DATA; + hSession->telnet_state = TNS_DATA; break; case TNS_SB: /* telnet sub-option string command */ if (c == IAC) - session->telnet_state = TNS_SB_IAC; + hSession->telnet_state = TNS_SB_IAC; else - *session->sbptr++ = c; + *hSession->sbptr++ = c; break; case TNS_SB_IAC: /* telnet sub-option string command */ - *session->sbptr++ = c; + *hSession->sbptr++ = c; if (c == SE) { - session->telnet_state = TNS_DATA; - if (session->sbbuf[0] == TELOPT_TTYPE && session->sbbuf[1] == TELQUAL_SEND) + hSession->telnet_state = TNS_DATA; + if (hSession->sbbuf[0] == TELOPT_TTYPE && hSession->sbbuf[1] == TELQUAL_SEND) { int tt_len, tb_len; char *tt_out; - trace_dsn(session,"%s %s\n", opt(session->sbbuf[0]),telquals[session->sbbuf[1]]); + trace_dsn(hSession,"%s %s\n", opt(hSession->sbbuf[0]),telquals[hSession->sbbuf[1]]); - if (session->lus != (char **)NULL && session->try_lu == CN) + if (hSession->lus != (char **)NULL && hSession->try_lu == CN) { /* None of the LUs worked. */ popup_an_error(NULL,"Cannot connect to specified LU"); return -1; } - tt_len = strlen(session->termtype); - if (session->try_lu != CN && *session->try_lu) + tt_len = strlen(hSession->termtype); + if (hSession->try_lu != CN && *hSession->try_lu) { - tt_len += strlen(session->try_lu) + 1; - session->connected_lu = session->try_lu; + tt_len += strlen(hSession->try_lu) + 1; + hSession->connected_lu = hSession->try_lu; } else - session->connected_lu = CN; + hSession->connected_lu = CN; - status_lu(session,session->connected_lu); + status_lu(hSession,hSession->connected_lu); tb_len = 4 + tt_len + 2; tt_out = lib3270_malloc(tb_len + 1); (void) sprintf(tt_out, "%c%c%c%c%s%s%s%c%c", IAC, SB, TELOPT_TTYPE, TELQUAL_IS, - session->termtype, - (session->try_lu != CN && *session->try_lu) ? "@" : "", - (session->try_lu != CN && *session->try_lu) ? session->try_lu : "", + hSession->termtype, + (hSession->try_lu != CN && *hSession->try_lu) ? "@" : "", + (hSession->try_lu != CN && *hSession->try_lu) ? hSession->try_lu : "", IAC, SE); - net_rawout(session, (unsigned char *)tt_out, tb_len); + net_rawout(hSession, (unsigned char *)tt_out, tb_len); - trace_dsn(session,"SENT %s %s %s %.*s %s\n", + trace_dsn(hSession,"SENT %s %s %s %.*s %s\n", cmd(SB), opt(TELOPT_TTYPE), telquals[TELQUAL_IS], tt_len, tt_out + 4, @@ -1535,24 +1537,24 @@ static int telnet_fsm(H3270 *session, unsigned char c) lib3270_free(tt_out); /* Advance to the next LU name. */ - next_lu(session); + next_lu(hSession); } #if defined(X3270_TN3270E) /*[*/ - else if (session->myopts[TELOPT_TN3270E] && session->sbbuf[0] == TELOPT_TN3270E) + else if (hSession->myopts[TELOPT_TN3270E] && hSession->sbbuf[0] == TELOPT_TN3270E) { - if (tn3270e_negotiate(session)) + if (tn3270e_negotiate(hSession)) return -1; } #endif /*]*/ #if defined(HAVE_LIBSSL) /*[*/ - else if (session->need_tls_follows && session->myopts[TELOPT_STARTTLS] && session->sbbuf[0] == TELOPT_STARTTLS) + else if (hSession->need_tls_follows && hSession->myopts[TELOPT_STARTTLS] && hSession->sbbuf[0] == TELOPT_STARTTLS) { - continue_tls(session,session->sbbuf, session->sbptr - session->sbbuf); + continue_tls(hSession,hSession->sbbuf, hSession->sbptr - hSession->sbbuf); } #endif /*]*/ } else { - session->telnet_state = TNS_SB; + hSession->telnet_state = TNS_SB; } break; } @@ -2405,18 +2407,19 @@ static void do_lnext(H3270 *hSession, char c) #endif /*]*/ - -/* - * check_in3270 - * Check for switches between NVT, SSCP-LU and 3270 modes. +/** + * Check for switches between NVT, SSCP-LU and 3270 modes. + * + * @param hSession Session handle. + * */ -static void -check_in3270(H3270 *session) +static void check_in3270(H3270 *hSession) { LIB3270_CSTATE new_cstate = NOT_CONNECTED; #if defined(X3270_TRACE) /*[*/ - static const char *state_name[] = { + static const char *state_name[] = + { "unconnected", "resolving", "pending", @@ -2431,10 +2434,10 @@ check_in3270(H3270 *session) #endif /*]*/ #if defined(X3270_TN3270E) /*[*/ - if (session->myopts[TELOPT_TN3270E]) { - if (!session->tn3270e_negotiated) + if (hSession->myopts[TELOPT_TN3270E]) { + if (!hSession->tn3270e_negotiated) new_cstate = CONNECTED_INITIAL_E; - else switch (session->tn3270e_submode) { + else switch (hSession->tn3270e_submode) { case E_NONE: new_cstate = CONNECTED_INITIAL_E; break; @@ -2450,20 +2453,20 @@ check_in3270(H3270 *session) } } else #endif /*]*/ - if (session->myopts[TELOPT_BINARY] && - session->myopts[TELOPT_EOR] && - session->myopts[TELOPT_TTYPE] && - session->hisopts[TELOPT_BINARY] && - session->hisopts[TELOPT_EOR]) { + if (hSession->myopts[TELOPT_BINARY] && + hSession->myopts[TELOPT_EOR] && + hSession->myopts[TELOPT_TTYPE] && + hSession->hisopts[TELOPT_BINARY] && + hSession->hisopts[TELOPT_EOR]) { new_cstate = CONNECTED_3270; - } else if (session->cstate == CONNECTED_INITIAL) { + } else if (hSession->cstate == CONNECTED_INITIAL) { /* Nothing has happened, yet. */ return; } else { new_cstate = CONNECTED_ANSI; } - if (new_cstate != session->cstate) { + if (new_cstate != hSession->cstate) { #if defined(X3270_TN3270E) /*[*/ int was_in_e = IN_E; #endif /*]*/ @@ -2474,37 +2477,37 @@ check_in3270(H3270 *session) * TN3270E mode, reset the LU list so we can try again * in the new mode. */ - if (session->lus != (char **)NULL && was_in_e != IN_E) { - session->curr_lu = session->lus; - session->try_lu = *session->curr_lu; + if (hSession->lus != (char **)NULL && was_in_e != IN_E) { + hSession->curr_lu = hSession->lus; + hSession->try_lu = *hSession->curr_lu; } #endif /*]*/ /* Allocate the initial 3270 input buffer. */ - if(new_cstate >= CONNECTED_INITIAL && !(session->ibuf_size && session->ibuf)) + if(new_cstate >= CONNECTED_INITIAL && !(hSession->ibuf_size && hSession->ibuf)) { - session->ibuf = (unsigned char *) lib3270_malloc(BUFSIZ); - session->ibuf_size = BUFSIZ; - session->ibptr = session->ibuf; + hSession->ibuf = (unsigned char *) lib3270_malloc(BUFSIZ); + hSession->ibuf_size = BUFSIZ; + hSession->ibptr = hSession->ibuf; } #if defined(X3270_ANSI) /*[*/ /* Reinitialize line mode. */ - if ((new_cstate == CONNECTED_ANSI && session->linemode) || + if ((new_cstate == CONNECTED_ANSI && hSession->linemode) || new_cstate == CONNECTED_NVT) - cooked_init(session); + cooked_init(hSession); #endif /*]*/ #if defined(X3270_TN3270E) /*[*/ /* If we fell out of TN3270E, remove the state. */ - if (!session->myopts[TELOPT_TN3270E]) { - session->tn3270e_negotiated = 0; - session->tn3270e_submode = E_NONE; - session->tn3270e_bound = 0; + if (!hSession->myopts[TELOPT_TN3270E]) { + hSession->tn3270e_negotiated = 0; + hSession->tn3270e_submode = E_NONE; + hSession->tn3270e_bound = 0; } #endif /*]*/ - trace_dsn(session,"Now operating in %s mode.\n",state_name[new_cstate]); - host_in3270(session,new_cstate); + trace_dsn(hSession,"Now operating in %s mode.\n",state_name[new_cstate]); + host_in3270(hSession,new_cstate); } } diff --git a/src/pw3270/v3270/iocallback.c b/src/pw3270/v3270/iocallback.c index 4c2ad99..992cb13 100644 --- a/src/pw3270/v3270/iocallback.c +++ b/src/pw3270/v3270/iocallback.c @@ -111,6 +111,7 @@ static void * AddSource(int source, H3270 *session, gushort events, void (*fn)(H src->fn = fn; src->poll.fd = (int) source; src->poll.events = events; + src->session = session; g_source_attach((GSource *) src,NULL); g_source_add_poll((GSource *) src,&src->poll); @@ -329,10 +330,6 @@ void v3270_register_io_handlers(v3270Class *cls) static_AddExcept, -// #if !defined(_WIN32) -// static_AddOutput, -// #endif - #ifdef G_THREADS_ENABLED static_CallAndWait, #else -- libgit2 0.21.2