From df8fdf4c7031f2d55c891aa16cbd7621e8e3e6d8 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 25 Oct 2019 15:32:04 -0300 Subject: [PATCH] Adding listeners for action group state changes (required for the new UI). --- lib3270.cbp | 5 ++++- src/core/actions/actions.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- src/core/actions/table.c | 6 +++--- src/core/ansi.c | 2 +- src/core/bounds.c | 2 +- src/core/charset/charset.c | 2 +- src/core/charset/convert.c | 2 +- src/core/charset/getset.c | 2 +- src/core/charset/remap.c | 2 +- src/core/charset/utf8.c | 2 +- src/core/charset/view.c | 2 +- src/core/connect.c | 4 ++-- src/core/ctlr.c | 2 +- src/core/cursor.c | 2 +- src/core/ft/ft.c | 2 +- src/core/ft/ft_cut.c | 2 +- src/core/ft/ft_dft.c | 2 +- src/core/ft/ftmessages.c | 2 +- src/core/host.c | 52 +++++++++++++++++++++++++++++++++++----------------- src/core/html.c | 2 +- src/core/init.c | 2 +- src/core/iocalls.c | 18 +++++++++--------- src/core/keyboard/actions.c | 2 +- src/core/keyboard/kybd.c | 2 +- src/core/keyboard/properties.c | 2 +- src/core/linux/connect.c | 34 +++++++++++++++++----------------- src/core/linux/curl.c | 2 +- src/core/linux/event_dispatcher.c | 2 +- src/core/linux/log.c | 2 +- src/core/linux/util.c | 2 +- src/core/log.c | 2 +- src/core/model.c | 6 +++--- src/core/options.c | 4 ++-- src/core/paste.c | 2 +- src/core/print.c | 2 +- src/core/printer.c | 2 +- src/core/properties/boolean.c | 2 +- src/core/properties/get.c | 2 +- src/core/properties/signed.c | 2 +- src/core/properties/string.c | 2 +- src/core/properties/unsigned.c | 2 +- src/core/resources.c | 2 +- src/core/rpq.c | 2 +- src/core/screen.c | 6 +++--- src/core/see.c | 2 +- src/core/session.c | 14 +++++++++----- src/core/sf.c | 2 +- src/core/state.c | 24 ++++++++++++------------ src/core/telnet.c | 34 +++++++++++++++++----------------- src/core/toggles/getset.c | 2 +- src/core/toggles/init.c | 6 +++--- src/core/toggles/listener.c | 2 +- src/core/toggles/table.c | 2 +- src/core/trace_ds.c | 2 +- src/core/util.c | 10 +++++----- src/core/wait.c | 2 +- src/core/windows/connect.c | 2 +- src/core/windows/event_dispatcher.c | 2 +- src/core/windows/http.c | 2 +- src/core/windows/log.c | 2 +- src/core/windows/util.c | 2 +- src/include/internals.h | 882 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/include/lib3270-internals.h | 888 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ src/include/lib3270.h | 1 - src/include/lib3270/actions.h | 41 ++++++++++++++++++++++++++++++++++++++++- src/mkfb/mkfb.c | 2 +- src/selection/actions.c | 4 +++- src/selection/get.c | 2 +- src/selection/selection.c | 29 +++++++++++++++-------------- src/ssl/crl.c | 2 +- src/ssl/linux/init.c | 2 +- src/ssl/linux/ldap.c | 2 +- src/ssl/linux/private.h | 2 +- src/ssl/negotiate.c | 4 ++-- src/ssl/notify.c | 2 +- src/ssl/properties.c | 2 +- src/ssl/state.c | 2 +- src/ssl/windows/init.c | 2 +- src/ssl/windows/private.h | 2 +- src/testprogram/testprogram.c | 11 ++++++++++- 80 files changed, 1178 insertions(+), 1065 deletions(-) create mode 100644 src/include/internals.h delete mode 100644 src/include/lib3270-internals.h diff --git a/lib3270.cbp b/lib3270.cbp index 515988b..ac34580 100644 --- a/lib3270.cbp +++ b/lib3270.cbp @@ -116,6 +116,9 @@ + + @@ -242,8 +245,8 @@ + - diff --git a/src/core/actions/actions.c b/src/core/actions/actions.c index 90feea5..56d9fc6 100644 --- a/src/core/actions/actions.c +++ b/src/core/actions/actions.c @@ -27,10 +27,17 @@ * */ -#include +#include +#include #include #include +struct lib3270_action_callback +{ + LIB3270_LINKED_LIST_HEAD + void (*func)(H3270 *, void *); /**< @brief Function to call */ +}; + /*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ const LIB3270_ACTION * lib3270_action_get_by_name(const char *name) @@ -89,3 +96,40 @@ LIB3270_EXPORT int lib3270_action(H3270 *hSession, const char *name) { return lib3270_action_activate_by_name(name,hSession); } + +LIB3270_INTERNAL void lib3270_notify_actions(H3270 *hSession, LIB3270_ACTION_GROUP group) +{ + + if(group < (sizeof(hSession->listeners.actions)/sizeof(hSession->listeners.actions[0]))) + { + struct lib3270_linked_list_node * node; + + for(node = hSession->listeners.actions[group].first; node; node = node->next) + { + ((struct lib3270_action_callback *) node)->func(hSession,node->userdata); + } + + } + +} + +LIB3270_EXPORT const void * lib3270_register_action_group_listener(H3270 *hSession, LIB3270_ACTION_GROUP group, void (*func)(H3270 *, void *),void *data) +{ + + if(group < (sizeof(hSession->listeners.actions)/sizeof(hSession->listeners.actions[0]))) + { + struct lib3270_action_callback *st = (struct lib3270_action_callback *) lib3270_linked_list_append_node(&hSession->listeners.actions[group], sizeof(struct lib3270_action_callback), data); + st->func = func; + return (void *) st; + } + + return NULL; +} + +LIB3270_EXPORT int lib3270_unregister_action_group_listener(H3270 *hSession, LIB3270_ACTION_GROUP group, const void *id) +{ + if(group < (sizeof(hSession->listeners.actions)/sizeof(hSession->listeners.actions[0]))) + return lib3270_linked_list_delete_node(&hSession->listeners.actions[group], id); + + return errno = EINVAL; +} diff --git a/src/core/actions/table.c b/src/core/actions/table.c index 146ef21..0920f59 100644 --- a/src/core/actions/table.c +++ b/src/core/actions/table.c @@ -32,7 +32,7 @@ * */ -#include +#include #include #include #include @@ -210,7 +210,7 @@ .summary = N_( "Save selected area." ), .activate = save_selected, - .group = LIB3270_ACTION_GROUP_SELECTION, + .group = LIB3270_ACTION_GROUP_SELECTED, .activatable = lib3270_has_selection }, @@ -591,7 +591,7 @@ .summary = N_( "Print selected area." ), .activate = lib3270_print_selected, - .group = LIB3270_ACTION_GROUP_SELECTION, + .group = LIB3270_ACTION_GROUP_SELECTED, .activatable = lib3270_has_selection }, diff --git a/src/core/ansi.c b/src/core/ansi.c index 5b5d22c..5c90bd6 100644 --- a/src/core/ansi.c +++ b/src/core/ansi.c @@ -40,7 +40,7 @@ #pragma GCC diagnostic ignored "-Wstringop-truncation" #endif // _WIN32 -#include +#include #include #if defined(X3270_ANSI) /*[*/ diff --git a/src/core/bounds.c b/src/core/bounds.c index 46f26a1..9da7582 100644 --- a/src/core/bounds.c +++ b/src/core/bounds.c @@ -30,7 +30,7 @@ * */ -#include +#include /*--[ Implement ]------------------------------------------------------------------------------------*/ diff --git a/src/core/charset/charset.c b/src/core/charset/charset.c index 8482a5f..ab3252c 100644 --- a/src/core/charset/charset.c +++ b/src/core/charset/charset.c @@ -35,7 +35,7 @@ * @brief This module handles character sets. */ -#include +#include #include #include #include diff --git a/src/core/charset/convert.c b/src/core/charset/convert.c index 2daf59c..b6b5a8c 100644 --- a/src/core/charset/convert.c +++ b/src/core/charset/convert.c @@ -35,7 +35,7 @@ * @brief This module handles ebc<->asc conversion. */ -#include +#include #include #include #include diff --git a/src/core/charset/getset.c b/src/core/charset/getset.c index d995fb3..d198eef 100644 --- a/src/core/charset/getset.c +++ b/src/core/charset/getset.c @@ -35,7 +35,7 @@ * @brief This module handles get/set the terminal character set. */ -#include +#include #include #include #include diff --git a/src/core/charset/remap.c b/src/core/charset/remap.c index a5bde92..9bc2555 100644 --- a/src/core/charset/remap.c +++ b/src/core/charset/remap.c @@ -35,7 +35,7 @@ * @brief */ -#include +#include #include #include #include diff --git a/src/core/charset/utf8.c b/src/core/charset/utf8.c index ae99cb0..ec1339b 100644 --- a/src/core/charset/utf8.c +++ b/src/core/charset/utf8.c @@ -35,7 +35,7 @@ * @brief 3270 Terminal Emulator UTF-8 conversions */ -#include +#include // #include "api.h" #include "popupsc.h" diff --git a/src/core/charset/view.c b/src/core/charset/view.c index dc839f7..bf7e3d2 100644 --- a/src/core/charset/view.c +++ b/src/core/charset/view.c @@ -35,7 +35,7 @@ * @brief This module shows the charset table. */ -#include +#include #include #include #include diff --git a/src/core/connect.c b/src/core/connect.c index d8c5383..cf44911 100644 --- a/src/core/connect.c +++ b/src/core/connect.c @@ -28,7 +28,7 @@ */ #include -#include +#include #include "telnetc.h" #include #include @@ -83,7 +83,7 @@ if(hSession->auto_reconnect_inprogress || hSession->popups) return errno = EAGAIN; - if(hSession->sock > 0) + if(hSession->connection.sock > 0) return errno = EISCONN; if(!(hSession->host.current && hSession->host.srvc)) diff --git a/src/core/ctlr.c b/src/core/ctlr.c index 29e07db..ad280be 100644 --- a/src/core/ctlr.c +++ b/src/core/ctlr.c @@ -34,7 +34,7 @@ #pragma GCC diagnostic ignored "-Wsign-compare" -#include +#include #include #include diff --git a/src/core/cursor.c b/src/core/cursor.c index 0a2bbfb..adb1929 100644 --- a/src/core/cursor.c +++ b/src/core/cursor.c @@ -32,7 +32,7 @@ */ -#include +#include #include #include #include diff --git a/src/core/ft/ft.c b/src/core/ft/ft.c index f8dcf04..0649780 100644 --- a/src/core/ft/ft.c +++ b/src/core/ft/ft.c @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/core/ft/ft_cut.c b/src/core/ft/ft_cut.c index 4264830..a2b75b1 100644 --- a/src/core/ft/ft_cut.c +++ b/src/core/ft/ft_cut.c @@ -37,7 +37,7 @@ #include -#include +#include #include #include diff --git a/src/core/ft/ft_dft.c b/src/core/ft/ft_dft.c index d3e331d..385bbac 100644 --- a/src/core/ft/ft_dft.c +++ b/src/core/ft/ft_dft.c @@ -42,7 +42,7 @@ #endif // WIN32 #include -#include +#include #if defined(X3270_FT) /*[*/ diff --git a/src/core/ft/ftmessages.c b/src/core/ft/ftmessages.c index 7c816d5..643f439 100644 --- a/src/core/ft/ftmessages.c +++ b/src/core/ft/ftmessages.c @@ -29,7 +29,7 @@ */ #include -#include +#include #include #include #include diff --git a/src/core/host.c b/src/core/host.c index 8eddebc..fc64e3c 100644 --- a/src/core/host.c +++ b/src/core/host.c @@ -38,7 +38,7 @@ #pragma GCC diagnostic ignored "-Wsign-compare" #include -#include +#include #include "resources.h" #include "hostc.h" @@ -122,6 +122,36 @@ int host_disconnect(H3270 *hSession, int failed) } +int lib3270_set_cstate(H3270 *hSession, LIB3270_CSTATE cstate) +{ + if(hSession->connection.state != cstate) + { + // Salve old states. + int connected = lib3270_is_connected(hSession); + int disconnected = lib3270_is_disconnected(hSession); + + // Cstate has changed. + hSession->connection.state = cstate; + + // Do I need to send notifications? + + if(connected != lib3270_is_connected(hSession)) { + // Online state has changed, fire LIB3270_ACTION_GROUP_ONLINE + lib3270_notify_actions(hSession, LIB3270_ACTION_GROUP_ONLINE); + } + + if(disconnected != lib3270_is_disconnected(hSession)) { + // Offline state has changed, fire LIB3270_ACTION_GROUP_OFFLINE + lib3270_notify_actions(hSession, LIB3270_ACTION_GROUP_OFFLINE); + } + + return 1; + } + + return 0; + +} + /** * @brief The host has entered 3270 or ANSI mode, or switched between them. */ @@ -131,14 +161,15 @@ void host_in3270(H3270 *hSession, LIB3270_CSTATE new_cstate) new_cstate == LIB3270_CONNECTED_SSCP || new_cstate == LIB3270_CONNECTED_TN3270E); - hSession->cstate = new_cstate; + lib3270_set_cstate(hSession,new_cstate); hSession->ever_3270 = now3270; lib3270_st_changed(hSession, LIB3270_STATE_3270_MODE, now3270); } void lib3270_set_connected_initial(H3270 *hSession) { - hSession->cstate = LIB3270_CONNECTED_INITIAL; + lib3270_set_cstate(hSession,LIB3270_CONNECTED_INITIAL); + hSession->starting = 1; // Enable autostart lib3270_st_changed(hSession, LIB3270_STATE_CONNECT, True); @@ -150,7 +181,7 @@ void lib3270_set_disconnected(H3270 *hSession) { CHECK_SESSION_HANDLE(hSession); - hSession->cstate = LIB3270_NOT_CONNECTED; + lib3270_set_cstate(hSession,LIB3270_NOT_CONNECTED); hSession->starting = 0; #if defined(HAVE_LIBSSL) @@ -202,19 +233,6 @@ void lib3270_st_changed(H3270 *h, LIB3270_STATE tx, int mode) ((struct lib3270_state_callback *) node)->func(h,mode,node->userdata); } - /* - struct lib3270_state_callback *st; - - CHECK_SESSION_HANDLE(h); - - trace("%s is %d on session %p",state_name[tx],mode,h); - - for(st = h->listeners.state.callbacks[tx];st;st = st->next) - { - st->func(h,mode,st->data); - } - */ - trace("%s ends",__FUNCTION__); } diff --git a/src/core/html.c b/src/core/html.c index 103bbb5..06432f2 100644 --- a/src/core/html.c +++ b/src/core/html.c @@ -39,7 +39,7 @@ #include "3270ds.h" #include - #include + #include #include "utilc.h" struct chr_xlat diff --git a/src/core/init.c b/src/core/init.c index df8a46b..50c735c 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -52,7 +52,7 @@ #endif // _WIN32 #include -#include +#include #ifdef HAVE_SYSLOG #include diff --git a/src/core/iocalls.c b/src/core/iocalls.c index 27eb1a2..9d3d49a 100644 --- a/src/core/iocalls.c +++ b/src/core/iocalls.c @@ -29,7 +29,7 @@ * */ -#include +#include #include #include #include "xioc.h" @@ -301,7 +301,7 @@ static void internal_remove_poll(H3270 *session, void *id) LIB3270_EXPORT void lib3270_remove_poll(H3270 *session, void *id) { - debug("%s(%d,%p)",__FUNCTION__,session->sock,id); + debug("%s(%d,%p)",__FUNCTION__,session->connection.sock,id); remove_poll(session, id); } @@ -309,7 +309,7 @@ LIB3270_EXPORT void lib3270_set_poll_state(H3270 *session, void *id, int enabled { if(id) { - debug("%s: Polling on %d (%p) is %s",__FUNCTION__,session->sock,id,(enabled ? "enabled" : "disabled")); + debug("%s: Polling on %d (%p) is %s",__FUNCTION__,session->connection.sock,id,(enabled ? "enabled" : "disabled")); set_poll_state(session, id, enabled); } } @@ -349,7 +349,7 @@ LIB3270_EXPORT void lib3270_update_poll_fd(H3270 *session, int fd, LIB3270_IO_FL } LIB3270_EXPORT void * lib3270_add_poll_fd(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*call)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata ) { - debug("%s(%d)",__FUNCTION__,session->sock); + debug("%s(%d)",__FUNCTION__,session->connection.sock); return add_poll(session,fd,flag,call,userdata); } @@ -400,10 +400,10 @@ void x_except_on(H3270 *h) if(reading) lib3270_remove_poll(h,h->xio.read); - h->xio.except = lib3270_add_poll_fd(h,h->sock,LIB3270_IO_FLAG_EXCEPTION,net_exception,0); + h->xio.except = lib3270_add_poll_fd(h,h->connection.sock,LIB3270_IO_FLAG_EXCEPTION,net_exception,0); if(reading) - h->xio.read = lib3270_add_poll_fd(h,h->sock,LIB3270_IO_FLAG_READ,net_input,0); + h->xio.read = lib3270_add_poll_fd(h,h->connection.sock,LIB3270_IO_FLAG_READ,net_input,0); debug("%s",__FUNCTION__); } @@ -523,7 +523,7 @@ LIB3270_EXPORT int lib3270_run_task(H3270 *hSession, int(*callback)(H3270 *h, vo int non_blocking(H3270 *hSession, Boolean on) { - if(hSession->sock < 0) + if(hSession->connection.sock < 0) return 0; #ifdef WIN32 @@ -545,7 +545,7 @@ int non_blocking(H3270 *hSession, Boolean on) int f; - if ((f = fcntl(hSession->sock, F_GETFL, 0)) == -1) + if ((f = fcntl(hSession->connection.sock, F_GETFL, 0)) == -1) { lib3270_popup_dialog( hSession, LIB3270_NOTIFY_ERROR, @@ -562,7 +562,7 @@ int non_blocking(H3270 *hSession, Boolean on) else f &= ~O_NDELAY; - if (fcntl(hSession->sock, F_SETFL, f) < 0) + if (fcntl(hSession->connection.sock, F_SETFL, f) < 0) { lib3270_popup_dialog( hSession, LIB3270_NOTIFY_ERROR, diff --git a/src/core/keyboard/actions.c b/src/core/keyboard/actions.c index ccaf55f..cb18be1 100644 --- a/src/core/keyboard/actions.c +++ b/src/core/keyboard/actions.c @@ -38,7 +38,7 @@ struct ta; #define LIB3270_TA struct ta -#include +#include #include #include #include diff --git a/src/core/keyboard/kybd.c b/src/core/keyboard/kybd.c index 003e909..f6f0a73 100644 --- a/src/core/keyboard/kybd.c +++ b/src/core/keyboard/kybd.c @@ -38,7 +38,7 @@ struct ta; #define LIB3270_TA struct ta -#include +#include #include #include #include diff --git a/src/core/keyboard/properties.c b/src/core/keyboard/properties.c index 1042f38..b14a225 100644 --- a/src/core/keyboard/properties.c +++ b/src/core/keyboard/properties.c @@ -27,7 +27,7 @@ * */ -#include +#include #include #include diff --git a/src/core/linux/connect.c b/src/core/linux/connect.c index 619191c..94dfd8b 100644 --- a/src/core/linux/connect.c +++ b/src/core/linux/connect.c @@ -28,7 +28,7 @@ */ #include -#include +#include #include #include #include @@ -46,7 +46,7 @@ // #include // #endif // HAVE_ICONV -#define SOCK_CLOSE(s) close(s->sock); s->sock = -1; +#define SOCK_CLOSE(s) close(s->connection.sock); s->connection.sock = -1; #include @@ -73,7 +73,7 @@ static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG hSession->xio.write = NULL; } - if(getsockopt(hSession->sock, SOL_SOCKET, SO_ERROR, (char *) &err, &len) < 0) + if(getsockopt(hSession->connection.sock, SOL_SOCKET, SO_ERROR, (char *) &err, &len) < 0) { lib3270_disconnect(hSession); lib3270_popup_dialog( @@ -102,8 +102,8 @@ static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG return; } - hSession->xio.except = lib3270_add_poll_fd(hSession,hSession->sock,LIB3270_IO_FLAG_EXCEPTION,net_exception,0); - hSession->xio.read = lib3270_add_poll_fd(hSession,hSession->sock,LIB3270_IO_FLAG_READ,net_input,0); + hSession->xio.except = lib3270_add_poll_fd(hSession,hSession->connection.sock,LIB3270_IO_FLAG_EXCEPTION,net_exception,0); + hSession->xio.read = lib3270_add_poll_fd(hSession,hSession->connection.sock,LIB3270_IO_FLAG_READ,net_input,0); #if defined(HAVE_LIBSSL) if(hSession->ssl.con && hSession->ssl.state == LIB3270_SSL_UNDEFINED) @@ -147,17 +147,17 @@ static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG status_connecting(hSession); - for(rp = result; hSession->sock < 0 && rp != NULL; rp = rp->ai_next) + for(rp = result; hSession->connection.sock < 0 && rp != NULL; rp = rp->ai_next) { - hSession->sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); - if(hSession->sock < 0) + hSession->connection.sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); + if(hSession->connection.sock < 0) { ((struct resolver *) host)->message = strerror(errno); continue; } // Connected! - if(connect(hSession->sock, rp->ai_addr, rp->ai_addrlen)) + if(connect(hSession->connection.sock, rp->ai_addr, rp->ai_addrlen)) { SOCK_CLOSE(hSession); ((struct resolver *) host)->message = strerror(errno); @@ -178,7 +178,7 @@ static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG memset(&host,0,sizeof(host)); // Connect to host - if(lib3270_run_task(hSession, background_connect, &host) || hSession->sock < 0) + if(lib3270_run_task(hSession, background_connect, &host) || hSession->connection.sock < 0) { char buffer[4096]; snprintf(buffer,4095,_( "Can't connect to %s:%s"), hSession->host.current, hSession->host.srvc); @@ -195,7 +195,7 @@ static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG } /* don't share the socket with our children */ - (void) fcntl(hSession->sock, F_SETFD, 1); + (void) fcntl(hSession->connection.sock, F_SETFD, 1); hSession->ever_3270 = False; @@ -212,7 +212,7 @@ static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG // set options for inline out-of-band data and keepalives int optval = 1; - if (setsockopt(hSession->sock, SOL_SOCKET, SO_OOBINLINE, (char *)&optval,sizeof(optval)) < 0) + if (setsockopt(hSession->connection.sock, SOL_SOCKET, SO_OOBINLINE, (char *)&optval,sizeof(optval)) < 0) { int rc = errno; lib3270_popup_dialog( hSession, @@ -226,7 +226,7 @@ static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG } optval = lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_ALIVE) ? 1 : 0; - if (setsockopt(hSession->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0) + if (setsockopt(hSession->connection.sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0) { int rc = errno; @@ -260,10 +260,10 @@ static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG */ // Connecting, set callbacks, wait for connection - hSession->cstate = LIB3270_PENDING; + lib3270_set_cstate(hSession, LIB3270_PENDING); lib3270_st_changed(hSession, LIB3270_STATE_HALF_CONNECT, True); - hSession->xio.write = lib3270_add_poll_fd(hSession,hSession->sock,LIB3270_IO_FLAG_WRITE,net_connected,0); + hSession->xio.write = lib3270_add_poll_fd(hSession,hSession->connection.sock,LIB3270_IO_FLAG_WRITE,net_connected,0); // hSession->ns_write_id = AddOutput(hSession->sock, hSession, net_connected); trace("%s: Connection in progress",__FUNCTION__); @@ -276,7 +276,7 @@ static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG { lib3270_main_iterate(hSession,1); - switch(hSession->cstate) + switch(hSession->connection.state) { case LIB3270_PENDING: case LIB3270_CONNECTED_INITIAL: @@ -297,7 +297,7 @@ static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG break; default: - lib3270_write_log(hSession,"connect", "%s: State changed to unexpected state %d",__FUNCTION__,hSession->cstate); + lib3270_write_log(hSession,"connect", "%s: State changed to unexpected state %d",__FUNCTION__,hSession->connection.state); return errno = EINVAL; } diff --git a/src/core/linux/curl.c b/src/core/linux/curl.c index 3bdf597..68d998e 100644 --- a/src/core/linux/curl.c +++ b/src/core/linux/curl.c @@ -31,7 +31,7 @@ #if defined(HAVE_LIBCURL) -#include +#include #include #include #include diff --git a/src/core/linux/event_dispatcher.c b/src/core/linux/event_dispatcher.c index 01ff8c0..9b9b7d8 100644 --- a/src/core/linux/event_dispatcher.c +++ b/src/core/linux/event_dispatcher.c @@ -32,7 +32,7 @@ * */ -#include +#include #include #include #include diff --git a/src/core/linux/log.c b/src/core/linux/log.c index 0213c5c..6e8001d 100644 --- a/src/core/linux/log.c +++ b/src/core/linux/log.c @@ -27,7 +27,7 @@ * */ -#include +#include #include #include #include diff --git a/src/core/linux/util.c b/src/core/linux/util.c index bb15373..4715b3a 100644 --- a/src/core/linux/util.c +++ b/src/core/linux/util.c @@ -35,7 +35,7 @@ #include #include -#include +#include #include static char * concat(char *path, const char *name, size_t *length) diff --git a/src/core/log.c b/src/core/log.c index d36f485..5435708 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -35,7 +35,7 @@ #include #endif // WIN32 -#include +#include #include #include #include diff --git a/src/core/model.c b/src/core/model.c index dc83dcb..ff16d92 100644 --- a/src/core/model.c +++ b/src/core/model.c @@ -27,7 +27,7 @@ * */ - #include + #include #include "screen.h" #include "ctlrc.h" #include "popupsc.h" @@ -42,7 +42,7 @@ int lib3270_set_oversize(H3270 *hSession, const char *value) { - if(hSession->cstate != LIB3270_NOT_CONNECTED) + if(hSession->connection.state != LIB3270_NOT_CONNECTED) return errno = EISCONN; if(!hSession->extended) @@ -177,7 +177,7 @@ int lib3270_set_model(H3270 *hSession, const char *model) { int model_number; - if(hSession->cstate != LIB3270_NOT_CONNECTED) + if(hSession->connection.state != LIB3270_NOT_CONNECTED) return errno = EISCONN; strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH); diff --git a/src/core/options.c b/src/core/options.c index 4596297..bec0b57 100644 --- a/src/core/options.c +++ b/src/core/options.c @@ -29,7 +29,7 @@ * */ -#include +#include /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ @@ -94,7 +94,7 @@ LIB3270_EXPORT int lib3270_set_color_type(H3270 *hSession, int colortype) { CHECK_SESSION_HANDLE(hSession); - if(hSession->cstate != LIB3270_NOT_CONNECTED) + if(hSession->connection.state != LIB3270_NOT_CONNECTED) return errno = EISCONN; switch(colortype) diff --git a/src/core/paste.c b/src/core/paste.c index fb306b3..834ebfd 100644 --- a/src/core/paste.c +++ b/src/core/paste.c @@ -27,7 +27,7 @@ * */ -#include +#include /* #if defined(X3270_DISPLAY) diff --git a/src/core/print.c b/src/core/print.c index 42f6eac..99db695 100644 --- a/src/core/print.c +++ b/src/core/print.c @@ -35,4 +35,4 @@ * Screen printing functions. */ -#include +#include diff --git a/src/core/printer.c b/src/core/printer.c index b021d7f..0f086d5 100644 --- a/src/core/printer.c +++ b/src/core/printer.c @@ -36,7 +36,7 @@ * Printer session support */ -#include +#include #if (defined(C3270) || defined(X3270_DISPLAY)) && defined(X3270_PRINTER) /*[*/ diff --git a/src/core/properties/boolean.c b/src/core/properties/boolean.c index 0f0d8e1..95e7809 100644 --- a/src/core/properties/boolean.c +++ b/src/core/properties/boolean.c @@ -28,7 +28,7 @@ */ #include - #include + #include #include #include #include diff --git a/src/core/properties/get.c b/src/core/properties/get.c index 4f1c369..2d13632 100644 --- a/src/core/properties/get.c +++ b/src/core/properties/get.c @@ -28,7 +28,7 @@ */ #include - #include + #include #include #include #include diff --git a/src/core/properties/signed.c b/src/core/properties/signed.c index b018c35..7d72ff9 100644 --- a/src/core/properties/signed.c +++ b/src/core/properties/signed.c @@ -28,7 +28,7 @@ */ #include - #include + #include #include #include #include diff --git a/src/core/properties/string.c b/src/core/properties/string.c index d46d3d9..957d98a 100644 --- a/src/core/properties/string.c +++ b/src/core/properties/string.c @@ -28,7 +28,7 @@ */ #include - #include + #include #include #include #include diff --git a/src/core/properties/unsigned.c b/src/core/properties/unsigned.c index 25336a6..becbecd 100644 --- a/src/core/properties/unsigned.c +++ b/src/core/properties/unsigned.c @@ -28,7 +28,7 @@ */ #include - #include + #include #include #include #include diff --git a/src/core/resources.c b/src/core/resources.c index 25dd6a7..a4014d3 100644 --- a/src/core/resources.c +++ b/src/core/resources.c @@ -34,7 +34,7 @@ #include #include -#include +#include #include "utilc.h" #include diff --git a/src/core/rpq.c b/src/core/rpq.c index 0ee36b3..ebd4a63 100644 --- a/src/core/rpq.c +++ b/src/core/rpq.c @@ -37,7 +37,7 @@ * */ -#include +#include #include #if !defined(_WIN32) /*[*/ #include diff --git a/src/core/screen.c b/src/core/screen.c index fb5c370..3b95c47 100644 --- a/src/core/screen.c +++ b/src/core/screen.c @@ -34,7 +34,7 @@ * */ -#include +#include #include #include "3270ds.h" #include "resources.h" @@ -550,7 +550,7 @@ void status_oerr(H3270 *session, int error_type) */ void status_resolving(H3270 *hSession) { - hSession->cstate = LIB3270_RESOLVING; + lib3270_set_cstate(hSession,LIB3270_RESOLVING); lib3270_st_changed(hSession, LIB3270_STATE_RESOLVING, True); mcursor_set(hSession,LIB3270_POINTER_LOCKED); @@ -559,7 +559,7 @@ void status_resolving(H3270 *hSession) void status_connecting(H3270 *hSession) { - hSession->cstate = LIB3270_RESOLVING; + lib3270_set_cstate(hSession,LIB3270_RESOLVING); lib3270_st_changed(hSession, LIB3270_STATE_CONNECTING, True); mcursor_set(hSession,LIB3270_POINTER_LOCKED); diff --git a/src/core/see.c b/src/core/see.c index abb4605..cb7a8ac 100644 --- a/src/core/see.c +++ b/src/core/see.c @@ -36,7 +36,7 @@ * */ -#include +#include #if defined(X3270_TRACE) /*[*/ diff --git a/src/core/session.c b/src/core/session.c index 5dce063..5c88a04 100644 --- a/src/core/session.c +++ b/src/core/session.c @@ -33,7 +33,7 @@ #include #endif // !ANDROID -#include +#include #include "kybdc.h" #include "ansic.h" #include "togglesc.h" @@ -95,6 +95,10 @@ void lib3270_session_free(H3270 *h) for(f=0;flisteners.toggle[f]); + // Release action listeners. + for(f=0;flisteners.actions[f]); + // Release memory #define release_pointer(x) lib3270_free(x); x = NULL; @@ -331,9 +335,9 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char hSession->unlock_delay = 1; hSession->icrnl = 1; hSession->onlcr = 1; - hSession->sock = -1; + hSession->connection.sock = -1; hSession->model_num = -1; - hSession->cstate = LIB3270_NOT_CONNECTED; + hSession->connection.state = LIB3270_NOT_CONNECTED; hSession->oia.status = -1; hSession->kybdlock = KL_NOT_CONNECTED; hSession->aid = AID_NO; @@ -453,7 +457,7 @@ LIB3270_INTERNAL int check_online_session(const H3270 *hSession) { return errno = EINVAL; // Is it connected? - if((int) hSession->cstate < (int)LIB3270_CONNECTED_INITIAL) + if((int) hSession->connection.state < (int)LIB3270_CONNECTED_INITIAL) return errno = ENOTCONN; return 0; @@ -466,7 +470,7 @@ LIB3270_INTERNAL int check_offline_session(const H3270 *hSession) { return errno = EINVAL; // Is it connected? - if((int) hSession->cstate >= (int)LIB3270_CONNECTED_INITIAL) + if((int) hSession->connection.state >= (int)LIB3270_CONNECTED_INITIAL) return errno = EISCONN; return 0; diff --git a/src/core/sf.c b/src/core/sf.c index ee52c2e..6f8aeeb 100644 --- a/src/core/sf.c +++ b/src/core/sf.c @@ -36,7 +36,7 @@ * */ -#include +#include #include #include diff --git a/src/core/state.c b/src/core/state.c index d675f65..ccd46d8 100644 --- a/src/core/state.c +++ b/src/core/state.c @@ -27,63 +27,63 @@ * */ -#include +#include /*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ LIB3270_EXPORT LIB3270_CSTATE lib3270_get_connection_state(const H3270 *h) { - return h->cstate; + return h->connection.state; } LIB3270_EXPORT int lib3270_pconnected(const H3270 *h) { - return (((int) h->cstate) >= (int)LIB3270_RESOLVING); + return (((int) h->connection.state) >= (int)LIB3270_RESOLVING); } LIB3270_EXPORT int lib3270_half_connected(const H3270 *h) { - return (h->cstate == LIB3270_RESOLVING || h->cstate == LIB3270_PENDING); + return (h->connection.state == LIB3270_RESOLVING || h->connection.state == LIB3270_PENDING); } LIB3270_EXPORT int lib3270_is_disconnected(const H3270 *h) { - return ((int) h->cstate == (int)LIB3270_NOT_CONNECTED); + return ((int) h->connection.state == (int)LIB3270_NOT_CONNECTED); } LIB3270_EXPORT int lib3270_in_neither(const H3270 *h) { - return (h->cstate == LIB3270_CONNECTED_INITIAL); + return (h->connection.state == LIB3270_CONNECTED_INITIAL); } LIB3270_EXPORT int lib3270_in_ansi(const H3270 *h) { - return (h->cstate == LIB3270_CONNECTED_ANSI || h->cstate == LIB3270_CONNECTED_NVT); + return (h->connection.state == LIB3270_CONNECTED_ANSI || h->connection.state == LIB3270_CONNECTED_NVT); } LIB3270_EXPORT int lib3270_in_3270(const H3270 *h) { - return (h->cstate == LIB3270_CONNECTED_3270 || h->cstate == LIB3270_CONNECTED_TN3270E || h->cstate == LIB3270_CONNECTED_SSCP); + return (h->connection.state == LIB3270_CONNECTED_3270 || h->connection.state == LIB3270_CONNECTED_TN3270E || h->connection.state == LIB3270_CONNECTED_SSCP); } LIB3270_EXPORT int lib3270_in_sscp(const H3270 *h) { - return (h->cstate == LIB3270_CONNECTED_SSCP); + return (h->connection.state == LIB3270_CONNECTED_SSCP); } LIB3270_EXPORT int lib3270_in_tn3270e(const H3270 *h) { - return (h->cstate == LIB3270_CONNECTED_TN3270E); + return (h->connection.state == LIB3270_CONNECTED_TN3270E); } LIB3270_EXPORT int lib3270_is_connected(const H3270 *h) { - return ((int) h->cstate >= (int)LIB3270_CONNECTED_INITIAL); + return ((int) h->connection.state >= (int)LIB3270_CONNECTED_INITIAL); } LIB3270_EXPORT int lib3270_in_e(const H3270 *h) { - return (h->cstate >= LIB3270_CONNECTED_INITIAL_E); + return (h->connection.state >= LIB3270_CONNECTED_INITIAL_E); } diff --git a/src/core/telnet.c b/src/core/telnet.c index aa83f2a..73fcc83 100644 --- a/src/core/telnet.c +++ b/src/core/telnet.c @@ -55,7 +55,7 @@ #include #endif -#include +#include #include #if defined(_WIN32) @@ -550,17 +550,17 @@ LIB3270_INTERNAL void lib3270_sock_disconnect(H3270 *hSession) hSession->xio.write = 0; } - if(hSession->sock >= 0) + if(hSession->connection.sock >= 0) { - shutdown(hSession->sock, 2); - SOCK_CLOSE(hSession->sock); - hSession->sock = -1; + shutdown(hSession->connection.sock, 2); + SOCK_CLOSE(hSession->connection.sock); + hSession->connection.sock = -1; } + } -/* - * net_disconnect - * Shut down the socket. +/** + * @brief Shut down the socket. */ void net_disconnect(H3270 *session) { @@ -641,7 +641,7 @@ void net_input(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG GNUC_UNUSED for (;;) #endif { - if (hSession->sock < 0) + if (hSession->connection.sock < 0) return; #if defined(X3270_ANSI) @@ -652,9 +652,9 @@ void net_input(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG GNUC_UNUSED if (hSession->ssl.con != NULL) nr = SSL_read(hSession->ssl.con, (char *) buffer, BUFSZ); else - nr = recv(hSession->sock, (char *) buffer, BUFSZ, 0); + nr = recv(hSession->connection.sock, (char *) buffer, BUFSZ, 0); #else - nr = recv(hSession->sock, (char *) buffer, BUFSZ, 0); + nr = recv(hSession->connection.sock, (char *) buffer, BUFSZ, 0); #endif // HAVE_LIBSSL if (nr < 0) @@ -1638,9 +1638,9 @@ LIB3270_INTERNAL int lib3270_sock_send(H3270 *hSession, unsigned const char *buf if(hSession->ssl.con != NULL) rc = SSL_write(hSession->ssl.con, (const char *) buf, len); else - rc = send(hSession->sock, (const char *) buf, len, 0); + rc = send(hSession->connection.sock, (const char *) buf, len, 0); #else - rc = send(hSession->sock, (const char *) buf, len, 0); + rc = send(hSession->connection.sock, (const char *) buf, len, 0); #endif // HAVE_LIBSSL if(rc > 0) @@ -2076,14 +2076,14 @@ static void check_in3270(H3270 *hSession) hSession->hisopts[TELOPT_BINARY] && hSession->hisopts[TELOPT_EOR]) { new_cstate = LIB3270_CONNECTED_3270; - } else if (hSession->cstate == LIB3270_CONNECTED_INITIAL) { + } else if (hSession->connection.state == LIB3270_CONNECTED_INITIAL) { /* Nothing has happened, yet. */ return; } else { new_cstate = LIB3270_CONNECTED_ANSI; } - if (new_cstate != hSession->cstate) { + if (new_cstate != hSession->connection.state) { #if defined(X3270_TN3270E) /*[*/ int was_in_e = IN_E; #endif /*]*/ @@ -2658,7 +2658,7 @@ void net_abort(H3270 *hSession) /* Return the local address for the socket. */ int net_getsockname(const H3270 *session, void *buf, int *len) { - if (session->sock < 0) + if (session->connection.sock < 0) return -1; - return getsockname(session->sock, buf, (socklen_t *)(void *)len); + return getsockname(session->connection.sock, buf, (socklen_t *)(void *)len); } diff --git a/src/core/toggles/getset.c b/src/core/toggles/getset.c index 50c1741..e9b3756 100644 --- a/src/core/toggles/getset.c +++ b/src/core/toggles/getset.c @@ -34,7 +34,7 @@ */ #include -#include +#include #include #include #include "togglesc.h" diff --git a/src/core/toggles/init.c b/src/core/toggles/init.c index 8885515..7533ac2 100644 --- a/src/core/toggles/init.c +++ b/src/core/toggles/init.c @@ -46,7 +46,7 @@ #include #include -#include +#include #include "ansic.h" #include "ctlrc.h" @@ -79,12 +79,12 @@ static void toggle_nop(H3270 GNUC_UNUSED(*session), struct lib3270_toggle GNUC_U static void toggle_keepalive(H3270 *session, struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) { - if(session->sock > 0) + if(session->connection.sock > 0) { // Update keep-alive option int optval = t->value ? 1 : 0; - if (setsockopt(session->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0) + if (setsockopt(session->connection.sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0) { popup_a_sockerr(session, N_( "Can't %s network keep-alive" ), optval ? _( "enable" ) : _( "disable" )); } diff --git a/src/core/toggles/listener.c b/src/core/toggles/listener.c index c7b4540..cec988f 100644 --- a/src/core/toggles/listener.c +++ b/src/core/toggles/listener.c @@ -34,7 +34,7 @@ */ #include -#include +#include #include #include diff --git a/src/core/toggles/table.c b/src/core/toggles/table.c index 004ebdc..2a6f0c1 100644 --- a/src/core/toggles/table.c +++ b/src/core/toggles/table.c @@ -34,7 +34,7 @@ */ #include -#include +#include #include #include "togglesc.h" diff --git a/src/core/trace_ds.c b/src/core/trace_ds.c index 8680a3f..20dcf9f 100644 --- a/src/core/trace_ds.c +++ b/src/core/trace_ds.c @@ -36,7 +36,7 @@ * */ -#include +#include #include #if defined(X3270_TRACE) /*[*/ diff --git a/src/core/util.c b/src/core/util.c index ab8f71f..fe8ad6c 100644 --- a/src/core/util.c +++ b/src/core/util.c @@ -34,7 +34,7 @@ #define _GNU_SOURCE -#include +#include #include "utilc.h" #include "popupsc.h" #include @@ -705,12 +705,12 @@ LIB3270_EXPORT int lib3270_getpeername(H3270 *hSession, struct sockaddr *addr, s memset(addr,0,*addrlen); - if(hSession->sock < 0) { + if(hSession->connection.sock < 0) { errno = ENOTCONN; return -1; } - return getpeername(hSession->sock, addr, addrlen); + return getpeername(hSession->connection.sock, addr, addrlen); } @@ -720,12 +720,12 @@ LIB3270_EXPORT int lib3270_getsockname(H3270 *hSession, struct sockaddr *addr, s memset(addr,0,*addrlen); - if(hSession->sock < 0) { + if(hSession->connection.sock < 0) { errno = ENOTCONN; return -1; } - return getsockname(hSession->sock, addr, addrlen); + return getsockname(hSession->connection.sock, addr, addrlen); } static int xdigit_value(const char scanner) diff --git a/src/core/wait.c b/src/core/wait.c index 74ce1fc..c4d8ed4 100644 --- a/src/core/wait.c +++ b/src/core/wait.c @@ -27,7 +27,7 @@ * */ -#include +#include #include #include #include "kybdc.h" diff --git a/src/core/windows/connect.c b/src/core/windows/connect.c index a8db30f..5c4fd54 100644 --- a/src/core/windows/connect.c +++ b/src/core/windows/connect.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/core/windows/event_dispatcher.c b/src/core/windows/event_dispatcher.c index 3d49ad1..3f53d66 100644 --- a/src/core/windows/event_dispatcher.c +++ b/src/core/windows/event_dispatcher.c @@ -32,7 +32,7 @@ * */ -#include +#include #include #include #include diff --git a/src/core/windows/http.c b/src/core/windows/http.c index 713b596..c80821e 100644 --- a/src/core/windows/http.c +++ b/src/core/windows/http.c @@ -37,7 +37,7 @@ */ #include -#include +#include #include #include #include diff --git a/src/core/windows/log.c b/src/core/windows/log.c index a01c9e4..603b708 100644 --- a/src/core/windows/log.c +++ b/src/core/windows/log.c @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/core/windows/util.c b/src/core/windows/util.c index 63b17fb..5a6c649 100644 --- a/src/core/windows/util.c +++ b/src/core/windows/util.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include "winversc.h" #include diff --git a/src/include/internals.h b/src/include/internals.h new file mode 100644 index 0000000..4b7030e --- /dev/null +++ b/src/include/internals.h @@ -0,0 +1,882 @@ +/* + * "Software G3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral ', conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como private.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) + * + */ + +#ifdef WIN32 + #include + #include +#endif // WIN32 + +#include /* autoconf settings */ +#include /* lib3270 API calls and defs */ +#include +#include +#include +#include + +#if defined(HAVE_LIBSSL) + #include + #include + +#endif // HAVE_LIBSSL + +#if defined(X3270_TN3270E) && !defined(X3270_ANSI) /*[*/ + #define X3270_ANSI 1 /* RFC2355 requires NVT mode */ +#endif /*]*/ + +#if defined(HAVE_VASPRINTF) && !defined(_GNU_SOURCE) /*[*/ + #define _GNU_SOURCE /* vasprintf isn't POSIX */ +#endif /*]*/ + +/* + * gettext stuff + */ +#ifdef ANDROID + #undef HAVE_LIBINTL + #undef HAVE_LIBSSL +#endif + +#ifdef HAVE_LIBINTL + #include + #define _( x ) gettext(x) + #define N_( x ) x +#else + #define _( x ) x + #define N_( x ) x +#endif // HAVE_LIBINTL + +#define action_name(x) #x + +// +// Compiler-specific #defines. +// +// Reference: GLIBC gmacros.h +// +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) + + #define GNUC_UNUSED \ + __attribute__((__unused__)) + +#else + + #define unused + #define GNUC_UNUSED + #define printflike(s, f) + +#endif + +#if defined(_WIN32) || defined(_MSC_VER) + + #include + #include + +#else + + #include /* Unix system calls */ + #include /* System time-related data types */ + +#endif // _WIN32 + +/* + * Prerequisite #includes. + */ +#include /* Unix standard I/O library */ +#include /* Character classes */ +#include /* String manipulations */ +#include /* Basic system data types */ +#include /* C library time functions */ +#include "localdefs.h" /* {s,tcl,c}3270-specific defines */ + +/* + * Cancel out contradictory parts. + */ +#if !defined(X3270_DISPLAY) /*[*/ + #undef X3270_KEYPAD + #undef X3270_MENUS +#endif /*]*/ + +#define RECONNECT_MS 2000 /**< @brief 2 sec before reconnecting to host. */ +#define RECONNECT_ERR_MS 5000 /**< @brief 5 sec before reconnecting to host when failed */ + +/** + * @brief types of internal actions + */ +enum iaction { + IA_STRING, IA_PASTE, IA_REDRAW, + IA_KEYPAD, IA_DEFAULT, IA_KEY, + IA_MACRO, IA_SCRIPT, IA_PEEK, + IA_TYPEAHEAD, IA_FT, IA_COMMAND, IA_KEYMAP, + IA_IDLE +}; + +// Version strings +LIB3270_INTERNAL const char * build; +LIB3270_INTERNAL const char * app_defaults_version; +LIB3270_INTERNAL const char * sccsid; +LIB3270_INTERNAL const char * build_rpq_timestamp; +LIB3270_INTERNAL const char * build_rpq_version; +LIB3270_INTERNAL const char * build_rpq_revision; + +#if defined(X3270_DBCS) /*[*/ + LIB3270_INTERNAL Boolean dbcs; +#endif /*]*/ + + +/** + * @brief toggle names + */ /* +struct toggle_name { + const char *name; + int index; +}; */ + +/// @brief State macros +#define PCONNECTED lib3270_pconnected(hSession) +#define HALF_CONNECTED lib3270_half_connected(hSession) +#define CONNECTED lib3270_is_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) + +/// @brief Naming convention for private actions. +#define PA_PFX "PA-" + +#define GR_BLINK 0x01 +#define GR_REVERSE 0x02 +#define GR_UNDERLINE 0x04 +#define GR_INTENSIFY 0x08 + +#define CS_MASK 0x03 ///< @brief mask for specific character sets */ +#define CS_BASE 0x00 ///< @brief base character set (X'00') */ +#define CS_APL 0x01 ///< @brief APL character set (X'01' or GE) */ +#define CS_LINEDRAW 0x02 ///< @brief DEC line-drawing character set (ANSI) */ +#define CS_DBCS 0x03 ///< @brief DBCS character set (X'F8') */ +#define CS_GE 0x04 ///< @brief cs flag for Graphic Escape */ + +/// @brief Shorthand macros +#define CN ((char *) NULL) +#define PN ((XtPointer) NULL) +#define Replace(var, value) { lib3270_free(var); var = (value); }; + +/// @brief Configuration change masks. +//#define NO_CHANGE 0x0000 /// @brief no change +// #define MODEL_CHANGE 0x0001 /// @brief screen dimensions changed +//#define FONT_CHANGE 0x0002 /// @brief emulator font changed +//#define COLOR_CHANGE 0x0004 /// @brief color scheme or 3278/9 mode changed +//#define SCROLL_CHANGE 0x0008 /// @brief scrollbar snapped on or off +//#define CHARSET_CHANGE 0x0010 /// @brief character set changed +// #define ALL_CHANGE 0xffff /// @brief everything changed + +/* Portability macros */ + +/* Equivalent of setlinebuf */ + +#if defined(_IOLBF) /*[*/ + #define SETLINEBUF(s) setvbuf(s, (char *)NULL, _IOLBF, BUFSIZ) +#else /*][*/ + #define SETLINEBUF(s) setlinebuf(s) +#endif /*]*/ + +/* Motorola version of gettimeofday */ + +#if defined(MOTOROLA) + #define gettimeofday(tp,tz) gettimeofday(tp) +#endif + +/* Default DFT file transfer buffer size. */ +#if defined(X3270_FT) && !defined(DFT_BUF) /*[*/ + #define DFT_BUF (4 * 1024) +#endif /*]*/ + +/* DBCS Preedit Types */ /* +#if defined(X3270_DBCS) + #define PT_ROOT "Root" + #define PT_OVER_THE_SPOT "OverTheSpot" + #define PT_OFF_THE_SPOT "OffTheSpot" + #define PT_ON_THE_SPOT "OnTheSpot" +#endif */ + +/** + * @brief input key type + */ +enum keytype +{ + KT_STD, + KT_GE +}; + +LIB3270_INTERNAL struct _ansictl +{ + char vintr; + char vquit; + char verase; + char vkill; + char veof; + char vwerase; + char vrprnt; + char vlnext; +} ansictl; + +/** + * @brief Extended attributes + */ +struct lib3270_ea +{ + unsigned char cc; ///< @brief EBCDIC or ASCII character code + unsigned char fa; ///< @brief field attribute, it nonzero + unsigned char fg; ///< @brief foreground color (0x00 or 0xf) + unsigned char bg; ///< @brief background color (0x00 or 0xf) + unsigned char gr; ///< @brief ANSI graphics rendition bits + unsigned char cs; ///< @brief character set (GE flag, or 0..2) + unsigned char ic; ///< @brief input control (DBCS) + unsigned char db; ///< @brief DBCS state +}; + +struct lib3270_text +{ + unsigned char chr; ///< @brief ASCII character code + unsigned short attr; ///< @brief Converted character attribute (color & etc) +}; + +#ifndef LIB3270_TA + #define LIB3270_TA void +#endif // !LIB3270_TA + +#define LIB3270_MB_MAX 16 + +#define LIB3270_FULL_MODEL_NAME_LENGTH 13 +#define LIB3270_LU_MAX 32 + +#define LIB3270_TELNET_N_OPTS 256 + +/** + * + * @brief Timeout control structure. + * + */ +typedef struct timeout +{ + LIB3270_LINKED_LIST_HEAD + + unsigned char in_play; + +#if defined(_WIN32) /*[*/ + unsigned long long ts; +#else /*][*/ + struct timeval tv; +#endif /*]*/ + + int (*proc)(H3270 *session); + +} timeout_t; + + +/** + * + * @brief I/O events. + * + */ +typedef struct _input_t +{ + LIB3270_LINKED_LIST_HEAD + + unsigned char enabled; + int fd; + LIB3270_IO_FLAG flag; + + void (*call)(H3270 *, int, LIB3270_IO_FLAG, void *); + +} input_t; + +struct lib3270_state_callback +{ + LIB3270_LINKED_LIST_HEAD + + void (*func)(H3270 *, int, void *); /**< @brief Function to call */ +}; + +struct lib3270_toggle_callback +{ + LIB3270_LINKED_LIST_HEAD + + void (*func)(H3270 *, LIB3270_TOGGLE_ID, char, void *); /**< @brief Function to call */ +}; + +/** + * + * @brief lib3270 session data + * + */ +struct _h3270 +{ + struct lib3270_session_callbacks cbk; ///< @brief Callback table - Always the first one. + + // Session info + char id; ///< @brief Session Identifier. + + // Connection info + struct { + int sock; ///< @brief Network socket. + LIB3270_CSTATE state; ///< @brief Connection state. + } connection; + + // flags + LIB3270_HOST_TYPE host_type; ///< @brief Host type. + + int selected : 1; ///< @brief Has selected region? + int rectsel : 1; ///< @brief Selected region is a rectangle ? + int vcontrol : 1; ///< @brief Visible control ? + int modified_sel : 1; + int mono : 1; ///< @brief Forces monochrome display + int m3279 : 1; + int extended : 1; ///< @brief Extended data stream. + int typeahead : 1; + int numeric_lock : 1; + int oerr_lock : 1; ///< @brief If true, operator errors will lock the keyboard. + int unlock_delay : 1; ///< @brief If true the unlock delay feature is enabled. @see lib3270_set_unlock_delay + int auto_reconnect_inprogress : 1; + unsigned int colors : 5; + int apl_mode : 1; ///< @brief If true enables APL mode. + int icrnl : 1; + int inlcr : 1; + int onlcr : 1; + int bsd_tm : 1; + int syncing : 1; + int reverse : 1; /**< @brief reverse-input mode */ + int dbcs : 1; + int linemode : 1; + int trace_skipping : 1; + int need_tls_follows : 1; + int cut_xfer_in_progress : 1; +// int auto_keymap : 1; + int formatted : 1; /**< @brief Formatted screen flag */ + int starting : 1; /**< @brief Is starting (no first screen)? */ + + struct lib3270_toggle + { + char value; /**< toggle value */ + void (*upcall)(H3270 *, struct lib3270_toggle *, LIB3270_TOGGLE_TYPE); /**< change value */ + } toggle[LIB3270_TOGGLE_COUNT]; + + // Network & Termtype + char * connected_type; + char full_model_name[LIB3270_FULL_MODEL_NAME_LENGTH+1]; + char * model_name; + unsigned int model_num; + char * termtype; + + struct + { + char * url; /**< The host URL, for use in reconnecting */ + char * current; /**< The hostname part, stripped of qualifiers, luname and port number */ + char * srvc; /**< The service name */ + char * qualified; + } host; + + char * termname; + + struct lib3270_charset charset; + + struct + { + LIB3270_MESSAGE status; + unsigned char flag[LIB3270_FLAG_COUNT]; + } oia; + + unsigned short current_port; + + // Misc + H3270FT * ft; /**< @brief Active file transfer data */ + + // screen info + + // Oversize. + struct + { + char * str; + unsigned int rows; + unsigned int cols; + } oversize; + + // Maximum screen size. + struct + { + unsigned int rows; + unsigned int cols; + } max; + + // View size + struct { + unsigned int rows; + unsigned int cols; + } view; + + LIB3270_POINTER pointer; /**< @brief Current pointer. */ + int cursor_addr; + int buffer_addr; + char flipped; + int screen_alt; /**< @brief alternate screen? */ + int is_altbuffer; + + // Screen contents + void * buffer[2]; /**< @brief Internal buffers */ + struct lib3270_ea * ea_buf; /**< @brief 3270 device buffer. ea_buf[-1] is the dummy default field attribute */ + struct lib3270_ea * aea_buf; /**< @brief alternate 3270 extended attribute buffer */ + struct lib3270_text * text; /**< @brief Converted 3270 chars */ + + // host.c + char std_ds_host; + char no_login_host; + char non_tn3270e_host; + char passthru_host; + char ever_3270; + + // ctlr.c + int sscp_start; + unsigned char default_fg; + unsigned char default_bg; + unsigned char default_gr; + unsigned char default_cs; + unsigned char default_ic; + char reply_mode; + int trace_primed : 1; + int ticking : 1; + int mticking : 1; + int crm_nattr; + unsigned char crm_attr[16]; + unsigned char * zero_buf; /**< @brief Empty buffer, for area clears */ + + struct timeval t_start; + void * tick_id; + struct timeval t_want; + + // Telnet.c + unsigned char * ibuf; + int ibuf_size; /**< @brief size of ibuf */ + time_t ns_time; + int ns_brcvd; + int ns_rrcvd; + int ns_bsent; + int ns_rsent; + struct timeval ds_ts; + unsigned short e_xmit_seq; /**< @brief transmit sequence number */ + int response_required; + int ansi_data; + int lnext; + int backslashed; + char plu_name[LIB3270_BIND_PLU_NAME_MAX+1]; + + /* + /// @brief Proxy + struct + { + char * proxy; ///< Proxy server (type:host[:port]) + int type; + char * host; + char * portname; + unsigned short port; + } proxy; + */ + + /// @brief LU + char **curr_lu; + char * try_lu; + char **lus; ///< @brief Array with the LU names to try. + struct + { + char reported[LIB3270_LU_MAX+1]; + char * connected; + char name[LIB3270_LUNAME_LENGTH+1]; + + } lu; + + char reported_type[LIB3270_LU_MAX+1]; + + // TN3270e + enum + { + E_NONE, + E_3270, + E_NVT, + E_SSCP + } tn3270e_submode; + + unsigned long e_funcs; /**< @brief negotiated TN3270E functions */ + int tn3270e_bound; + int tn3270e_negotiated; + + // Line mode + unsigned char * lbuf; /**< @brief line-mode input buffer */ + unsigned char * lbptr; + + // 3270 input buffer + unsigned char * ibptr; + + // Output buffer. + struct + { + unsigned char * buf; ///< @brief 3270 output buffer */ + unsigned char * base; + int length; ///< @brief Length of the output buffer. + unsigned char * ptr; + } output; + + // network input buffer + unsigned char * sbbuf; + + // telnet sub-option buffer + unsigned char * sbptr; + unsigned char telnet_state; + + unsigned char myopts[LIB3270_TELNET_N_OPTS]; + unsigned char hisopts[LIB3270_TELNET_N_OPTS]; + + // kybd.c + unsigned int kybdlock; ///< @brief @brief keyboard lock state. + unsigned char aid; ///< @brief @brief current attention ID. + void * unlock_id; + time_t unlock_delay_time; + unsigned long unlock_delay_ms; ///< @brief Delay before actually unlocking the keyboard after the host permits it. + LIB3270_TA * ta_head; + LIB3270_TA * ta_tail; + + // ft_dft.c + int dft_buffersize; ///< @brief Buffer size (LIMIN, LIMOUT) + + // rpq.c + int rpq_complained : 1; +#if !defined(_WIN32) + int omit_due_space_limit : 1; +#endif + + char * rpq_warnbuf; + int rpq_wbcnt; + + // User data (Usually points to session's widget) + void * user_data; + + // selection + char * paste_buffer; + struct + { + int start; + int end; + } select; + + // ansi.c + int scroll_top; + int scroll_bottom; + int once_cset; + int saved_cursor; + + int held_wrap : 1; + + int insert_mode : 1; + int auto_newline_mode : 1; + + int appl_cursor : 1; + int saved_appl_cursor : 1; + + int wraparound_mode : 1; + int saved_wraparound_mode : 1; + + int rev_wraparound_mode : 1; + int saved_rev_wraparound_mode : 1; + + int allow_wide_mode : 1; + int saved_allow_wide_mode : 1; + + int wide_mode : 1; + int saved_wide_mode : 1; + + int saved_altbuffer : 1; + int ansi_reset : 1; /**< @brief Non zero if the ansi_reset() was called in this session */ + + int ansi_ch; + int cs_to_change; + + /** @brief ANSI Character sets. */ + enum lib3270_ansi_cs + { + LIB3270_ANSI_CS_G0 = 0, + LIB3270_ANSI_CS_G1 = 1, + LIB3270_ANSI_CS_G2 = 2, + LIB3270_ANSI_CS_G3 = 3 + } cset; + enum lib3270_ansi_cs saved_cset; + + /** @brief Character set designations. */ + enum lib3270_ansi_csd + { + LIB3270_ANSI_CSD_LD = 0, + LIB3270_ANSI_CSD_UK = 1, + LIB3270_ANSI_CSD_US = 2 + } csd[4]; + enum lib3270_ansi_csd saved_csd[4]; + + enum lib3270_ansi_state + { + LIB3270_ANSI_STATE_DATA = 0, + LIB3270_ANSI_STATE_ESC = 1, + LIB3270_ANSI_STATE_CSDES = 2, + LIB3270_ANSI_STATE_N1 = 3, + LIB3270_ANSI_STATE_DECP = 4, + LIB3270_ANSI_STATE_TEXT = 5, + LIB3270_ANSI_STATE_TEXT2 = 6, + LIB3270_ANSI_STATE_MBPEND = 7 + } state; + + unsigned char * tabs; + + int pmi; + char pending_mbs[LIB3270_MB_MAX]; + + unsigned char gr; + unsigned char saved_gr; + + unsigned char fg; + unsigned char saved_fg; + + unsigned char bg; + unsigned char saved_bg; + + // xio + struct { + void * read; + void * write; + void * except; + } xio; + + size_t popups; ///< @brief Count open popups. + +#ifdef HAVE_LIBSSL + /// @brief SSL Data. + struct + { + char enabled; + char host; + LIB3270_SSL_STATE state; + unsigned long error; +#ifdef SSL_ENABLE_CRL_CHECK + struct + { + char * prefer; ///< @brief Prefered protocol for CRL. + char * url; ///< @brief URL for CRL download. + X509_CRL * cert; ///< @brief Loaded CRL (can be null). + } crl; +#endif // SSL_ENABLE_CRL_CHECK + SSL * con; + } ssl; +#endif // HAVE_LIBSSL + + struct lib3270_linked_list_head timeouts; + + struct + { + struct lib3270_linked_list_head list; + int changed : 1; + } input; + + // Trace methods. + struct + { + void (*handler)(H3270 *session, void *userdata, const char *fmt, va_list args); + void *userdata; + } trace; + + /// @brief Event Listeners. + struct + { + /// @brief State listeners. + struct lib3270_linked_list_head state[LIB3270_STATE_USER]; + + /// @brief Toggle listeners. + struct lib3270_linked_list_head toggle[LIB3270_TOGGLE_COUNT]; + + /// @brief Action listeners. + struct lib3270_linked_list_head actions[LIB3270_ACTION_GROUP_CUSTOM]; + + } listeners; + + +}; + +#define SELECTION_LEFT 0x01 +#define SELECTION_TOP 0x02 +#define SELECTION_RIGHT 0x04 +#define SELECTION_BOTTOM 0x08 + +#define SELECTION_SINGLE_COL 0x10 +#define SELECTION_SINGLE_ROW 0x20 + +#define SELECTION_ACTIVE 0x80 + +#ifdef _WIN32 +/// @brief Windows Event Log Handler. +LIB3270_INTERNAL HANDLE hEventLog; +LIB3270_INTERNAL HANDLE hModule; +#endif // _WIN32 + +#ifdef HAVE_SYSLOG +/// @brief Windows Event Log Handler. +LIB3270_INTERNAL int use_syslog; +#endif // HAVE_SYSLOG + + +/* Library internal calls */ +LIB3270_INTERNAL int key_ACharacter(H3270 *hSession, unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped); +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_sock_send(H3270 *hSession, unsigned const char *buf, int len); +LIB3270_INTERNAL void lib3270_sock_disconnect(H3270 *hSession); + +LIB3270_INTERNAL int lib3270_default_event_dispatcher(H3270 *hSession, int block); + +LIB3270_INTERNAL void do_select(H3270 *h, unsigned int start, unsigned int end, unsigned int rect); + + +/** + * @brief Called from timer to attempt an automatic reconnection. + */ +LIB3270_INTERNAL int lib3270_check_for_auto_reconnect(H3270 *hSession); + +#if defined(DEBUG) + #define CHECK_SESSION_HANDLE(x) check_session_handle(&x,__FUNCTION__); + LIB3270_INTERNAL void check_session_handle(H3270 **hSession, const char *fname); +#else + #define CHECK_SESSION_HANDLE(x) check_session_handle(&x); + LIB3270_INTERNAL void check_session_handle(H3270 **hSession); +#endif // DEBUG + +LIB3270_INTERNAL int check_online_session(const H3270 *hSession); +LIB3270_INTERNAL int check_offline_session(const H3270 *hSession); + +/// @brief Returns -1 if the session is invalid or not online (sets errno). +#define FAIL_IF_NOT_ONLINE(x) if(check_online_session(x)) return errno; + +/// @brief Returns -1 if the session is invalid or online (sets errno). +#define FAIL_IF_ONLINE(x) if(check_offline_session(x)) return errno; + +LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on); + +#if defined(HAVE_LIBSSL) + + typedef struct _ssl_error_message + { + int error; + const char * title; + const char * text; + const char * description; +#ifdef _WIN32 + DWORD lasterror; +#endif // _WIN32 + } SSL_ERROR_MESSAGE; + + struct ssl_status_msg + { + long id; + LIB3270_NOTIFY icon; + const char * iconName; // Icon name from https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html + const char * message; + const char * description; + }; + + LIB3270_INTERNAL int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE *message); + LIB3270_INTERNAL int ssl_init(H3270 *session); + LIB3270_INTERNAL int ssl_negotiate(H3270 *hSession); + LIB3270_INTERNAL void set_ssl_state(H3270 *session, LIB3270_SSL_STATE state); + LIB3270_INTERNAL const struct ssl_status_msg * ssl_get_status_from_error_code(long id); + + + #if OPENSSL_VERSION_NUMBER >= 0x00907000L + #define INFO_CONST const + #else + #define INFO_CONST + #endif + + LIB3270_INTERNAL void ssl_info_callback(INFO_CONST SSL *s, int where, int ret); + + /** + * @brief Global SSL_CTX object as framework to establish TLS/SSL or DTLS enabled connections. + * + */ + LIB3270_INTERNAL SSL_CTX * ssl_ctx; + + /** + * @brief Index of h3270 handle in SSL session. + * + */ + LIB3270_INTERNAL int ssl_3270_ex_index; + + /** + * @brief Emit popup on ssl error. + * + */ + LIB3270_INTERNAL int popup_ssl_error(H3270 *session, int rc, const char *title, const char *summary, const char *body); + + /** + * @brief Emite popup on SSL error. + * + */ + LIB3270_INTERNAL int notify_ssl_error(H3270 *hSession, int rc, const SSL_ERROR_MESSAGE *message); + +#endif + + /// @brief Clear element at adress. + LIB3270_INTERNAL void clear_chr(H3270 *hSession, int baddr); + + LIB3270_INTERNAL unsigned char get_field_attribute(H3270 *session, int baddr); + + /// @brief Default log writer. + LIB3270_INTERNAL void default_log_writer(H3270 *session, const char *module, int rc, const char *fmt, va_list arg_ptr); + + LIB3270_INTERNAL char * lib3270_get_user_name(); + + /// @brief Query data from URL. + /// + /// @param hSession Handle of the TN3270 Session. + /// @param url The url to get. + /// @param length Pointer to the response lenght (can be NULL). + /// @param error_message Pointer to the error message. + /// + /// @return The data from URL (release it with lib3270_free) or NULL on error. + /// + LIB3270_INTERNAL char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, const char **error_message); + + /// @brief Fire CState change. + LIB3270_INTERNAL int lib3270_set_cstate(H3270 *hSession, LIB3270_CSTATE cstate); + + /// @brief Notify actions. + LIB3270_INTERNAL void lib3270_notify_actions(H3270 *hSession, LIB3270_ACTION_GROUP group); diff --git a/src/include/lib3270-internals.h b/src/include/lib3270-internals.h deleted file mode 100644 index 752cedc..0000000 --- a/src/include/lib3270-internals.h +++ /dev/null @@ -1,888 +0,0 @@ -/* - * "Software G3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral ', conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como private.h e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) - * - */ - -#ifdef WIN32 - #include - #include -#endif // WIN32 - -#include /* autoconf settings */ -#include /* lib3270 API calls and defs */ -#include -#include -#include -// #include "api.h" - -#if defined(HAVE_LIBSSL) - #include - #include - -#endif // HAVE_LIBSSL - -#if defined(X3270_TN3270E) && !defined(X3270_ANSI) /*[*/ - #define X3270_ANSI 1 /* RFC2355 requires NVT mode */ -#endif /*]*/ - -#if defined(HAVE_VASPRINTF) && !defined(_GNU_SOURCE) /*[*/ - #define _GNU_SOURCE /* vasprintf isn't POSIX */ -#endif /*]*/ - -/* - * gettext stuff - */ -#ifdef ANDROID - #undef HAVE_LIBINTL - #undef HAVE_LIBSSL -#endif - -#ifdef HAVE_LIBINTL - #include - #define _( x ) gettext(x) - #define N_( x ) x -#else - #define _( x ) x - #define N_( x ) x -#endif // HAVE_LIBINTL - -#define action_name(x) #x - -/* - * OS-specific #defines. Except for the blocking-connect workarounds, these - * should be replaced with autoconf probes as soon as possible. - */ - -/* - * BLOCKING_CONNECT_ONLY - * Use only blocking sockets. - */ -#if defined(sco) /*[*/ - #define BLOCKING_CONNECT_ONLY 1 -#endif /*]*/ - -#if defined(apollo) /*[*/ - #define BLOCKING_CONNECT_ONLY 1 -#endif /*]*/ - -// -// Compiler-specific #defines. -// -// Reference: GLIBC gmacros.h -// -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) - - #define GNUC_UNUSED \ - __attribute__((__unused__)) - -#else - - #define unused - #define GNUC_UNUSED - #define printflike(s, f) - -#endif - -#if defined(_WIN32) || defined(_MSC_VER) - - #include - #include - -#else - - #include /* Unix system calls */ - #include /* System time-related data types */ - -#endif // _WIN32 - -/* - * Prerequisite #includes. - */ -#include /* Unix standard I/O library */ -#include /* Character classes */ -#include /* String manipulations */ -#include /* Basic system data types */ -#include /* C library time functions */ -#include "localdefs.h" /* {s,tcl,c}3270-specific defines */ - -/* - * Cancel out contradictory parts. - */ -#if !defined(X3270_DISPLAY) /*[*/ - #undef X3270_KEYPAD - #undef X3270_MENUS -#endif /*]*/ - -#define RECONNECT_MS 2000 /**< @brief 2 sec before reconnecting to host. */ -#define RECONNECT_ERR_MS 5000 /**< @brief 5 sec before reconnecting to host when failed */ - -/** - * @brief types of internal actions - */ -enum iaction { - IA_STRING, IA_PASTE, IA_REDRAW, - IA_KEYPAD, IA_DEFAULT, IA_KEY, - IA_MACRO, IA_SCRIPT, IA_PEEK, - IA_TYPEAHEAD, IA_FT, IA_COMMAND, IA_KEYMAP, - IA_IDLE -}; - -// Version strings -LIB3270_INTERNAL const char * build; -LIB3270_INTERNAL const char * app_defaults_version; -LIB3270_INTERNAL const char * sccsid; -LIB3270_INTERNAL const char * build_rpq_timestamp; -LIB3270_INTERNAL const char * build_rpq_version; -LIB3270_INTERNAL const char * build_rpq_revision; - -#if defined(X3270_DBCS) /*[*/ - LIB3270_INTERNAL Boolean dbcs; -#endif /*]*/ - - -/** - * @brief toggle names - */ /* -struct toggle_name { - const char *name; - int index; -}; */ - -/// @brief State macros -#define PCONNECTED lib3270_pconnected(hSession) -#define HALF_CONNECTED lib3270_half_connected(hSession) -#define CONNECTED lib3270_is_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) - -/// @brief Naming convention for private actions. -#define PA_PFX "PA-" - -#define GR_BLINK 0x01 -#define GR_REVERSE 0x02 -#define GR_UNDERLINE 0x04 -#define GR_INTENSIFY 0x08 - -#define CS_MASK 0x03 ///< @brief mask for specific character sets */ -#define CS_BASE 0x00 ///< @brief base character set (X'00') */ -#define CS_APL 0x01 ///< @brief APL character set (X'01' or GE) */ -#define CS_LINEDRAW 0x02 ///< @brief DEC line-drawing character set (ANSI) */ -#define CS_DBCS 0x03 ///< @brief DBCS character set (X'F8') */ -#define CS_GE 0x04 ///< @brief cs flag for Graphic Escape */ - -/// @brief Shorthand macros -#define CN ((char *) NULL) -#define PN ((XtPointer) NULL) -#define Replace(var, value) { lib3270_free(var); var = (value); }; - -/// @brief Configuration change masks. -//#define NO_CHANGE 0x0000 /// @brief no change -// #define MODEL_CHANGE 0x0001 /// @brief screen dimensions changed -//#define FONT_CHANGE 0x0002 /// @brief emulator font changed -//#define COLOR_CHANGE 0x0004 /// @brief color scheme or 3278/9 mode changed -//#define SCROLL_CHANGE 0x0008 /// @brief scrollbar snapped on or off -//#define CHARSET_CHANGE 0x0010 /// @brief character set changed -// #define ALL_CHANGE 0xffff /// @brief everything changed - -/* Portability macros */ - -/* Equivalent of setlinebuf */ - -#if defined(_IOLBF) /*[*/ - #define SETLINEBUF(s) setvbuf(s, (char *)NULL, _IOLBF, BUFSIZ) -#else /*][*/ - #define SETLINEBUF(s) setlinebuf(s) -#endif /*]*/ - -/* Motorola version of gettimeofday */ - -#if defined(MOTOROLA) - #define gettimeofday(tp,tz) gettimeofday(tp) -#endif - -/* Default DFT file transfer buffer size. */ -#if defined(X3270_FT) && !defined(DFT_BUF) /*[*/ - #define DFT_BUF (4 * 1024) -#endif /*]*/ - -/* DBCS Preedit Types */ /* -#if defined(X3270_DBCS) - #define PT_ROOT "Root" - #define PT_OVER_THE_SPOT "OverTheSpot" - #define PT_OFF_THE_SPOT "OffTheSpot" - #define PT_ON_THE_SPOT "OnTheSpot" -#endif */ - -/** - * @brief input key type - */ -enum keytype -{ - KT_STD, - KT_GE -}; - -LIB3270_INTERNAL struct _ansictl -{ - char vintr; - char vquit; - char verase; - char vkill; - char veof; - char vwerase; - char vrprnt; - char vlnext; -} ansictl; - -/** - * @brief Extended attributes - */ -struct lib3270_ea -{ - unsigned char cc; ///< @brief EBCDIC or ASCII character code - unsigned char fa; ///< @brief field attribute, it nonzero - unsigned char fg; ///< @brief foreground color (0x00 or 0xf) - unsigned char bg; ///< @brief background color (0x00 or 0xf) - unsigned char gr; ///< @brief ANSI graphics rendition bits - unsigned char cs; ///< @brief character set (GE flag, or 0..2) - unsigned char ic; ///< @brief input control (DBCS) - unsigned char db; ///< @brief DBCS state -}; - -struct lib3270_text -{ - unsigned char chr; ///< @brief ASCII character code - unsigned short attr; ///< @brief Converted character attribute (color & etc) -}; - -#ifndef LIB3270_TA - #define LIB3270_TA void -#endif // !LIB3270_TA - -#define LIB3270_MB_MAX 16 - -#define LIB3270_FULL_MODEL_NAME_LENGTH 13 -#define LIB3270_LU_MAX 32 - -#define LIB3270_TELNET_N_OPTS 256 - -/** - * - * @brief Timeout control structure. - * - */ -typedef struct timeout -{ - LIB3270_LINKED_LIST_HEAD - - unsigned char in_play; - -#if defined(_WIN32) /*[*/ - unsigned long long ts; -#else /*][*/ - struct timeval tv; -#endif /*]*/ - - int (*proc)(H3270 *session); - -} timeout_t; - - -/** - * - * @brief I/O events. - * - */ -typedef struct _input_t -{ - LIB3270_LINKED_LIST_HEAD - - unsigned char enabled; - int fd; - LIB3270_IO_FLAG flag; - - void (*call)(H3270 *, int, LIB3270_IO_FLAG, void *); - -} input_t; - -struct lib3270_state_callback -{ - LIB3270_LINKED_LIST_HEAD - - void (*func)(H3270 *, int, void *); /**< @brief Function to call */ -}; - -struct lib3270_toggle_callback -{ - LIB3270_LINKED_LIST_HEAD - - void (*func)(H3270 *, LIB3270_TOGGLE_ID, char, void *); /**< @brief Function to call */ -}; - -/** - * - * @brief lib3270 session data - * - */ -struct _h3270 -{ - struct lib3270_session_callbacks cbk; ///< @brief Callback table - Always the first one. - - // Session info - char id; ///< @brief Session Identifier. - - // Connection info - int sock; ///< @brief Network socket. - LIB3270_CSTATE cstate; ///< @brief Connection state. - - // flags - LIB3270_HOST_TYPE host_type; ///< @brief Host type. - - int selected : 1; ///< @brief Has selected region? - int rectsel : 1; ///< @brief Selected region is a rectangle ? - int vcontrol : 1; ///< @brief Visible control ? - int modified_sel : 1; - int mono : 1; ///< @brief Forces monochrome display - int m3279 : 1; - int extended : 1; ///< @brief Extended data stream. - int typeahead : 1; - int numeric_lock : 1; - int oerr_lock : 1; ///< @brief If true, operator errors will lock the keyboard. - int unlock_delay : 1; ///< @brief If true the unlock delay feature is enabled. @see lib3270_set_unlock_delay - int auto_reconnect_inprogress : 1; - unsigned int colors : 5; - int apl_mode : 1; ///< @brief If true enables APL mode. - int icrnl : 1; - int inlcr : 1; - int onlcr : 1; - int bsd_tm : 1; - int syncing : 1; - int reverse : 1; /**< @brief reverse-input mode */ - int dbcs : 1; - int linemode : 1; - int trace_skipping : 1; - int need_tls_follows : 1; - int cut_xfer_in_progress : 1; -// int auto_keymap : 1; - int formatted : 1; /**< @brief Formatted screen flag */ - int starting : 1; /**< @brief Is starting (no first screen)? */ - - struct lib3270_toggle - { - char value; /**< toggle value */ - void (*upcall)(H3270 *, struct lib3270_toggle *, LIB3270_TOGGLE_TYPE); /**< change value */ - } toggle[LIB3270_TOGGLE_COUNT]; - - // Network & Termtype - char * connected_type; - char full_model_name[LIB3270_FULL_MODEL_NAME_LENGTH+1]; - char * model_name; - unsigned int model_num; - char * termtype; - - struct - { - char * url; /**< The host URL, for use in reconnecting */ - char * current; /**< The hostname part, stripped of qualifiers, luname and port number */ - char * srvc; /**< The service name */ - char * qualified; - } host; - - char * termname; - - struct lib3270_charset charset; - - struct - { - LIB3270_MESSAGE status; - unsigned char flag[LIB3270_FLAG_COUNT]; - } oia; - - unsigned short current_port; - - // Misc - H3270FT * ft; /**< @brief Active file transfer data */ - - // screen info - - // Oversize. - struct - { - char * str; - unsigned int rows; - unsigned int cols; - } oversize; - - // Maximum screen size. - struct - { - unsigned int rows; - unsigned int cols; - } max; - - // View size - struct { - unsigned int rows; - unsigned int cols; - } view; - - LIB3270_POINTER pointer; /**< @brief Current pointer. */ - int cursor_addr; - int buffer_addr; - char flipped; - int screen_alt; /**< @brief alternate screen? */ - int is_altbuffer; - - // Screen contents - void * buffer[2]; /**< @brief Internal buffers */ - struct lib3270_ea * ea_buf; /**< @brief 3270 device buffer. ea_buf[-1] is the dummy default field attribute */ - struct lib3270_ea * aea_buf; /**< @brief alternate 3270 extended attribute buffer */ - struct lib3270_text * text; /**< @brief Converted 3270 chars */ - - // host.c - char std_ds_host; - char no_login_host; - char non_tn3270e_host; - char passthru_host; - char ever_3270; - - // ctlr.c - int sscp_start; - unsigned char default_fg; - unsigned char default_bg; - unsigned char default_gr; - unsigned char default_cs; - unsigned char default_ic; - char reply_mode; - int trace_primed : 1; - int ticking : 1; - int mticking : 1; - int crm_nattr; - unsigned char crm_attr[16]; - unsigned char * zero_buf; /**< @brief Empty buffer, for area clears */ - - struct timeval t_start; - void * tick_id; - struct timeval t_want; - - // Telnet.c - unsigned char * ibuf; - int ibuf_size; /**< @brief size of ibuf */ - time_t ns_time; - int ns_brcvd; - int ns_rrcvd; - int ns_bsent; - int ns_rsent; - struct timeval ds_ts; - unsigned short e_xmit_seq; /**< @brief transmit sequence number */ - int response_required; - int ansi_data; - int lnext; - int backslashed; - char plu_name[LIB3270_BIND_PLU_NAME_MAX+1]; - - /* - /// @brief Proxy - struct - { - char * proxy; ///< Proxy server (type:host[:port]) - int type; - char * host; - char * portname; - unsigned short port; - } proxy; - */ - - /// @brief LU - char **curr_lu; - char * try_lu; - char **lus; ///< @brief Array with the LU names to try. - struct - { - char reported[LIB3270_LU_MAX+1]; - char * connected; - char name[LIB3270_LUNAME_LENGTH+1]; - - } lu; - - char reported_type[LIB3270_LU_MAX+1]; - - // TN3270e - enum - { - E_NONE, - E_3270, - E_NVT, - E_SSCP - } tn3270e_submode; - - unsigned long e_funcs; /**< @brief negotiated TN3270E functions */ - int tn3270e_bound; - int tn3270e_negotiated; - - // Line mode - unsigned char * lbuf; /**< @brief line-mode input buffer */ - unsigned char * lbptr; - - // 3270 input buffer - unsigned char * ibptr; - - // Output buffer. - struct - { - unsigned char * buf; ///< @brief 3270 output buffer */ - unsigned char * base; - int length; ///< @brief Length of the output buffer. - unsigned char * ptr; - } output; - - // network input buffer - unsigned char * sbbuf; - - // telnet sub-option buffer - unsigned char * sbptr; - unsigned char telnet_state; - - unsigned char myopts[LIB3270_TELNET_N_OPTS]; - unsigned char hisopts[LIB3270_TELNET_N_OPTS]; - - // kybd.c - unsigned int kybdlock; ///< @brief @brief keyboard lock state. - unsigned char aid; ///< @brief @brief current attention ID. - void * unlock_id; - time_t unlock_delay_time; - unsigned long unlock_delay_ms; ///< @brief Delay before actually unlocking the keyboard after the host permits it. - LIB3270_TA * ta_head; - LIB3270_TA * ta_tail; - - // ft_dft.c - int dft_buffersize; ///< @brief Buffer size (LIMIN, LIMOUT) - - // rpq.c - int rpq_complained : 1; -#if !defined(_WIN32) - int omit_due_space_limit : 1; -#endif - - char * rpq_warnbuf; - int rpq_wbcnt; - - // User data (Usually points to session's widget) - void * user_data; - - // selection - char * paste_buffer; - struct - { - int start; - int end; - } select; - - // ansi.c - int scroll_top; - int scroll_bottom; - int once_cset; - int saved_cursor; - - int held_wrap : 1; - - int insert_mode : 1; - int auto_newline_mode : 1; - - int appl_cursor : 1; - int saved_appl_cursor : 1; - - int wraparound_mode : 1; - int saved_wraparound_mode : 1; - - int rev_wraparound_mode : 1; - int saved_rev_wraparound_mode : 1; - - int allow_wide_mode : 1; - int saved_allow_wide_mode : 1; - - int wide_mode : 1; - int saved_wide_mode : 1; - - int saved_altbuffer : 1; - int ansi_reset : 1; /**< @brief Non zero if the ansi_reset() was called in this session */ - - int ansi_ch; - int cs_to_change; - - /** @brief ANSI Character sets. */ - enum lib3270_ansi_cs - { - LIB3270_ANSI_CS_G0 = 0, - LIB3270_ANSI_CS_G1 = 1, - LIB3270_ANSI_CS_G2 = 2, - LIB3270_ANSI_CS_G3 = 3 - } cset; - enum lib3270_ansi_cs saved_cset; - - /** @brief Character set designations. */ - enum lib3270_ansi_csd - { - LIB3270_ANSI_CSD_LD = 0, - LIB3270_ANSI_CSD_UK = 1, - LIB3270_ANSI_CSD_US = 2 - } csd[4]; - enum lib3270_ansi_csd saved_csd[4]; - - enum lib3270_ansi_state - { - LIB3270_ANSI_STATE_DATA = 0, - LIB3270_ANSI_STATE_ESC = 1, - LIB3270_ANSI_STATE_CSDES = 2, - LIB3270_ANSI_STATE_N1 = 3, - LIB3270_ANSI_STATE_DECP = 4, - LIB3270_ANSI_STATE_TEXT = 5, - LIB3270_ANSI_STATE_TEXT2 = 6, - LIB3270_ANSI_STATE_MBPEND = 7 - } state; - - unsigned char * tabs; - - int pmi; - char pending_mbs[LIB3270_MB_MAX]; - - unsigned char gr; - unsigned char saved_gr; - - unsigned char fg; - unsigned char saved_fg; - - unsigned char bg; - unsigned char saved_bg; - - // xio - struct { - void * read; - void * write; - void * except; - } xio; - - size_t popups; ///< @brief Count open popups. - -#ifdef HAVE_LIBSSL - /// @brief SSL Data. - struct - { - char enabled; - char host; - LIB3270_SSL_STATE state; - unsigned long error; -#ifdef SSL_ENABLE_CRL_CHECK - struct - { - char * prefer; ///< @brief Prefered protocol for CRL. - char * url; ///< @brief URL for CRL download. - X509_CRL * cert; ///< @brief Loaded CRL (can be null). - } crl; -#endif // SSL_ENABLE_CRL_CHECK - SSL * con; - } ssl; -#endif // HAVE_LIBSSL - - struct lib3270_linked_list_head timeouts; - - struct - { - struct lib3270_linked_list_head list; - int changed : 1; - } input; - - // Trace methods. - struct - { - void (*handler)(H3270 *session, void *userdata, const char *fmt, va_list args); - void *userdata; - } trace; - - /// @brief Event Listeners. - struct - { - /// @brief State listeners. - struct lib3270_linked_list_head state[LIB3270_STATE_USER]; - - /// @brief Toggle listeners. - struct lib3270_linked_list_head toggle[LIB3270_TOGGLE_COUNT]; - - } listeners; - - -}; - -#define SELECTION_LEFT 0x01 -#define SELECTION_TOP 0x02 -#define SELECTION_RIGHT 0x04 -#define SELECTION_BOTTOM 0x08 - -#define SELECTION_SINGLE_COL 0x10 -#define SELECTION_SINGLE_ROW 0x20 - -#define SELECTION_ACTIVE 0x80 - -#ifdef _WIN32 -/// @brief Windows Event Log Handler. -LIB3270_INTERNAL HANDLE hEventLog; -LIB3270_INTERNAL HANDLE hModule; -#endif // _WIN32 - -#ifdef HAVE_SYSLOG -/// @brief Windows Event Log Handler. -LIB3270_INTERNAL int use_syslog; -#endif // HAVE_SYSLOG - - -/* Library internal calls */ -LIB3270_INTERNAL int key_ACharacter(H3270 *hSession, unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped); -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_sock_send(H3270 *hSession, unsigned const char *buf, int len); -LIB3270_INTERNAL void lib3270_sock_disconnect(H3270 *hSession); - -LIB3270_INTERNAL int lib3270_default_event_dispatcher(H3270 *hSession, int block); - -LIB3270_INTERNAL void do_select(H3270 *h, unsigned int start, unsigned int end, unsigned int rect); - - -/** - * @brief Called from timer to attempt an automatic reconnection. - */ -LIB3270_INTERNAL int lib3270_check_for_auto_reconnect(H3270 *hSession); - -#if defined(DEBUG) - #define CHECK_SESSION_HANDLE(x) check_session_handle(&x,__FUNCTION__); - LIB3270_INTERNAL void check_session_handle(H3270 **hSession, const char *fname); -#else - #define CHECK_SESSION_HANDLE(x) check_session_handle(&x); - LIB3270_INTERNAL void check_session_handle(H3270 **hSession); -#endif // DEBUG - -LIB3270_INTERNAL int check_online_session(const H3270 *hSession); -LIB3270_INTERNAL int check_offline_session(const H3270 *hSession); - -/// @brief Returns -1 if the session is invalid or not online (sets errno). -#define FAIL_IF_NOT_ONLINE(x) if(check_online_session(x)) return errno; - -/// @brief Returns -1 if the session is invalid or online (sets errno). -#define FAIL_IF_ONLINE(x) if(check_offline_session(x)) return errno; - -LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on); - -#if defined(HAVE_LIBSSL) - - typedef struct _ssl_error_message - { - int error; - const char * title; - const char * text; - const char * description; -#ifdef _WIN32 - DWORD lasterror; -#endif // _WIN32 - } SSL_ERROR_MESSAGE; - - struct ssl_status_msg - { - long id; - LIB3270_NOTIFY icon; - const char * iconName; // Icon name from https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html - const char * message; - const char * description; - }; - - LIB3270_INTERNAL int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE *message); - LIB3270_INTERNAL int ssl_init(H3270 *session); - LIB3270_INTERNAL int ssl_negotiate(H3270 *hSession); - LIB3270_INTERNAL void set_ssl_state(H3270 *session, LIB3270_SSL_STATE state); - LIB3270_INTERNAL const struct ssl_status_msg * ssl_get_status_from_error_code(long id); - - - #if OPENSSL_VERSION_NUMBER >= 0x00907000L - #define INFO_CONST const - #else - #define INFO_CONST - #endif - - LIB3270_INTERNAL void ssl_info_callback(INFO_CONST SSL *s, int where, int ret); - - /** - * @brief Global SSL_CTX object as framework to establish TLS/SSL or DTLS enabled connections. - * - */ - LIB3270_INTERNAL SSL_CTX * ssl_ctx; - - /** - * @brief Index of h3270 handle in SSL session. - * - */ - LIB3270_INTERNAL int ssl_3270_ex_index; - - /** - * @brief Emit popup on ssl error. - * - */ - LIB3270_INTERNAL int popup_ssl_error(H3270 *session, int rc, const char *title, const char *summary, const char *body); - - /** - * @brief Emite popup on SSL error. - * - */ - LIB3270_INTERNAL int notify_ssl_error(H3270 *hSession, int rc, const SSL_ERROR_MESSAGE *message); - -#endif - - /// @brief Clear element at adress. - LIB3270_INTERNAL void clear_chr(H3270 *hSession, int baddr); - - LIB3270_INTERNAL unsigned char get_field_attribute(H3270 *session, int baddr); - - /// @brief Default log writer. - LIB3270_INTERNAL void default_log_writer(H3270 *session, const char *module, int rc, const char *fmt, va_list arg_ptr); - - LIB3270_INTERNAL char * lib3270_get_user_name(); - - /// @brief Query data from URL. - /// - /// @param hSession Handle of the TN3270 Session. - /// @param url The url to get. - /// @param length Pointer to the response lenght (can be NULL). - /// @param error_message Pointer to the error message. - /// - /// @return The data from URL (release it with lib3270_free) or NULL on error. - /// - LIB3270_INTERNAL char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, const char **error_message); diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 63e8811..a386dd4 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -1000,7 +1000,6 @@ LIB3270_EXPORT int lib3270_in_e(const H3270 *h); LIB3270_EXPORT int lib3270_is_ready(const H3270 *h); - LIB3270_EXPORT int lib3270_is_connected(const H3270 *h); LIB3270_EXPORT int lib3270_is_secure(const H3270 *h); LIB3270_EXPORT LIB3270_MESSAGE lib3270_get_lock_status(const H3270 *h); diff --git a/src/include/lib3270/actions.h b/src/include/lib3270/actions.h index 48ca348..0be500b 100644 --- a/src/include/lib3270/actions.h +++ b/src/include/lib3270/actions.h @@ -38,15 +38,28 @@ LIB3270_ACTION_GROUP_NONE, ///< @brief Simple action, no signals os special treatment. LIB3270_ACTION_GROUP_ONLINE, ///< @brief Action requires online state. LIB3270_ACTION_GROUP_OFFLINE, ///< @brief Action requires offline state. - LIB3270_ACTION_GROUP_SELECTION, ///< @brief Action requires an active selection. + LIB3270_ACTION_GROUP_SELECTED, ///< @brief Action requires an active selection. LIB3270_ACTION_GROUP_UNSELECTED, ///< @brief Action fails if there has a selection. + + LIB3270_ACTION_GROUP_CUSTOM ///< @brief Custom group/Number of groups. } LIB3270_ACTION_GROUP; + typedef enum _lib3270_action_type + { + LIB3270_ACTION_TYPE_GENERIC, ///< @brief Generic action. + LIB3270_ACTION_TYPE_NAVIGATION, ///< @brief Cursor and field navigation. + LIB3270_ACTION_CONNECTION, ///< @brief Connection action. + LIB3270_ACTION_CLIPBOARD, ///< @brief Clipboard action. + + LIB3270_ACTION_CUSTOM ///< @brief Custom action/Number of actions. + } LIB3270_ACTION_TYPE; + typedef struct _lib3270_action { LIB3270_PROPERTY_HEAD LIB3270_ACTION_GROUP group; ///< @brief Action group. + LIB3270_ACTION_TYPE type; ///< @brief Action type. int (*activate)(H3270 *hSession); ///< @brief lib3270 associated method. int (*activatable)(const H3270 *hSession); ///< @brief Is the action activatable? @@ -57,6 +70,32 @@ } LIB3270_ACTION; + +/** + * @brief Register an action group listener. + * + * @param hSession TN3270 Session handle. + * @param group The group to listen. + * @param func Callback for group events. + * @param data Argument data for callback. + * + * @return Listener ID (for removal) or NULL if error. + * + */ + LIB3270_EXPORT const void * lib3270_register_action_group_listener(H3270 *hSession, LIB3270_ACTION_GROUP group, void (*func)(H3270 *, void *),void *data); + +/** + * @brief Unregister an action group listener. + * + * @param hSession TN3270 Session handle. + * @param group The group to listen. + * @param id ID of the listener to remove. + * + * @return 0 if ok, error code if not. + * + */ + LIB3270_EXPORT int lib3270_unregister_action_group_listener(H3270 *hSession, LIB3270_ACTION_GROUP group, const void *id); + /** * * @brief Call lib3270 action by name. diff --git a/src/mkfb/mkfb.c b/src/mkfb/mkfb.c index 9b6a507..f55ecd9 100644 --- a/src/mkfb/mkfb.c +++ b/src/mkfb/mkfb.c @@ -384,7 +384,7 @@ main(int argc, char *argv[]) fprintf(t, "/* This file was created automatically from %s by mkfb. */\n\n", filename); if (cmode) { - fprintf(t, "#include \"lib3270-internals.h\"\n"); + fprintf(t, "#include \"internals.h\"\n"); fprintf(t, "static unsigned char fsd[] = {\n"); } else { fprintf(t, "unsigned char common_fallbacks[] = {\n"); diff --git a/src/selection/actions.c b/src/selection/actions.c index 598bf3e..6506768 100644 --- a/src/selection/actions.c +++ b/src/selection/actions.c @@ -27,7 +27,7 @@ * */ - #include + #include #include #include #include @@ -63,6 +63,8 @@ LIB3270_EXPORT int lib3270_unselect(H3270 *hSession) hSession->cbk.set_selection(hSession,0); hSession->cbk.update_selection(hSession,-1,-1); + lib3270_notify_actions(hSession,LIB3270_ACTION_GROUP_UNSELECTED); + } return 0; diff --git a/src/selection/get.c b/src/selection/get.c index 2d23b35..b69b7c9 100644 --- a/src/selection/get.c +++ b/src/selection/get.c @@ -27,7 +27,7 @@ * */ - #include + #include #include #include #include diff --git a/src/selection/selection.c b/src/selection/selection.c index 7e7c58a..262cf5c 100644 --- a/src/selection/selection.c +++ b/src/selection/selection.c @@ -27,7 +27,7 @@ * */ - #include + #include #include #include #include @@ -165,37 +165,38 @@ void toggle_rectselect(H3270 *session, struct lib3270_toggle GNUC_UNUSED(*t), LI update_selected_region(session); } -void do_select(H3270 *h, unsigned int start, unsigned int end, unsigned int rect) +void do_select(H3270 *hSession, unsigned int start, unsigned int end, unsigned int rect) { - if(end > (h->view.rows * h->view.cols)) + if(end > (hSession->view.rows * hSession->view.cols)) return; // Do we really need to change selection? - if( ((int) start) == h->select.start && ((int) end) == h->select.end && h->selected) + if( ((int) start) == hSession->select.start && ((int) end) == hSession->select.end && hSession->selected) return; // Start address is inside the screen? - h->select.start = start; - h->select.end = end; + hSession->select.start = start; + hSession->select.end = end; if(rect) { - h->rectsel = 1; - update_selected_rectangle(h); + hSession->rectsel = 1; + update_selected_rectangle(hSession); } else { - h->rectsel = 0; - update_selected_region(h); + hSession->rectsel = 0; + update_selected_region(hSession); } - if(!h->selected) + if(!hSession->selected) { - h->selected = 1; - h->cbk.set_selection(h,1); + hSession->selected = 1; + hSession->cbk.set_selection(hSession,1); + lib3270_notify_actions(hSession,LIB3270_ACTION_GROUP_SELECTED); } - h->cbk.update_selection(h,start,end); + hSession->cbk.update_selection(hSession,start,end); } diff --git a/src/ssl/crl.c b/src/ssl/crl.c index e24c298..63bcdef 100644 --- a/src/ssl/crl.c +++ b/src/ssl/crl.c @@ -29,7 +29,7 @@ #include -#include +#include #include #include #include diff --git a/src/ssl/linux/init.c b/src/ssl/linux/init.c index 7ddfa07..461f8dc 100644 --- a/src/ssl/linux/init.c +++ b/src/ssl/linux/init.c @@ -50,7 +50,7 @@ #define SSL_ST_OK 3 #endif // !SSL_ST_OK -#include +#include #include #include #include diff --git a/src/ssl/linux/ldap.c b/src/ssl/linux/ldap.c index 2bb3cfe..2762c89 100644 --- a/src/ssl/linux/ldap.c +++ b/src/ssl/linux/ldap.c @@ -34,7 +34,7 @@ */ #include -#include +#include #include #include #include diff --git a/src/ssl/linux/private.h b/src/ssl/linux/private.h index d2e98d7..e3096e7 100644 --- a/src/ssl/linux/private.h +++ b/src/ssl/linux/private.h @@ -38,7 +38,7 @@ #include #include - #include + #include #include #include #include diff --git a/src/ssl/negotiate.c b/src/ssl/negotiate.c index 8bed9b3..43b5d1c 100644 --- a/src/ssl/negotiate.c +++ b/src/ssl/negotiate.c @@ -34,7 +34,7 @@ #include -#include +#include #if defined(HAVE_LIBSSL) @@ -150,7 +150,7 @@ static int background_ssl_negotiation(H3270 *hSession, void *message) } /* Set up the TLS/SSL connection. */ - if(SSL_set_fd(hSession->ssl.con, hSession->sock) != 1) + if(SSL_set_fd(hSession->ssl.con, hSession->connection.sock) != 1) { trace_ssl(hSession,"%s","SSL_set_fd failed!\n"); diff --git a/src/ssl/notify.c b/src/ssl/notify.c index cc130e5..48c689b 100644 --- a/src/ssl/notify.c +++ b/src/ssl/notify.c @@ -34,7 +34,7 @@ #include -#include +#include #include /*--[ Implement ]------------------------------------------------------------------------------------*/ diff --git a/src/ssl/properties.c b/src/ssl/properties.c index eb0140c..0967ad2 100644 --- a/src/ssl/properties.c +++ b/src/ssl/properties.c @@ -27,7 +27,7 @@ * */ -#include +#include #include #if defined(HAVE_LIBSSL) diff --git a/src/ssl/state.c b/src/ssl/state.c index e2ec868..025ca57 100644 --- a/src/ssl/state.c +++ b/src/ssl/state.c @@ -28,7 +28,7 @@ */ #include -#include +#include #include #include #include diff --git a/src/ssl/windows/init.c b/src/ssl/windows/init.c index 1e5de73..9609042 100644 --- a/src/ssl/windows/init.c +++ b/src/ssl/windows/init.c @@ -52,7 +52,7 @@ #define SSL_ST_OK 3 #endif // !SSL_ST_OK -#include +#include #include #include #include diff --git a/src/ssl/windows/private.h b/src/ssl/windows/private.h index 53a5ecd..70fb98f 100644 --- a/src/ssl/windows/private.h +++ b/src/ssl/windows/private.h @@ -41,7 +41,7 @@ #include #include - #include + #include #include #include #include diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c index 0d75e0b..fc31c66 100644 --- a/src/testprogram/testprogram.c +++ b/src/testprogram/testprogram.c @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include #include @@ -24,6 +24,11 @@ static void write_trace(H3270 GNUC_UNUSED(*session), void GNUC_UNUSED(*userdata) } } +static void online_group_state_changed(H3270 GNUC_UNUSED(*hSession), void GNUC_UNUSED(*dunno)) +{ + printf("\n\n%s\n\n",__FUNCTION__); +} + int main(int argc, char *argv[]) { // #pragma GCC diagnostic push @@ -102,6 +107,8 @@ int main(int argc, char *argv[]) printf("\nConnecting to %s\n",lib3270_get_url(h)); + const void * online_listener = lib3270_register_action_group_listener(h,LIB3270_ACTION_GROUP_ONLINE,online_group_state_changed,NULL); + rc = lib3270_reconnect(h,120); printf("\n\nConnect exits with rc=%d (%s)\n\n",rc,strerror(rc)); @@ -139,6 +146,8 @@ int main(int argc, char *argv[]) } + lib3270_unregister_action_group_listener(h,LIB3270_ACTION_GROUP_ONLINE,online_listener); + lib3270_session_free(h); return 0; -- libgit2 0.21.2