From 958169d3ae1401961253677f934e8c4ec9588c5d Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 20 Apr 2016 14:38:58 -0300 Subject: [PATCH] Isolando estrutura de sessão para evitar que alterações na biblioteca causem quebra de compatibilidade binária com o aplicativo principal ou plugins. --- host.c | 23 +++++++++++++++++++++++ private.h | 370 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------ 2 files changed, 369 insertions(+), 24 deletions(-) diff --git a/host.c b/host.c index b371c54..992fe19 100644 --- a/host.c +++ b/host.c @@ -375,3 +375,26 @@ LIB3270_EXPORT const char * lib3270_get_luname(H3270 *h) return h->connected_lu; } +LIB3270_EXPORT int lib3270_has_active_script(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return (h->oia_flag[LIB3270_FLAG_SCRIPT] != 0); +} + +LIB3270_EXPORT int lib3270_get_typeahead(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return (h->oia_flag[LIB3270_FLAG_TYPEAHEAD] != 0); +} + +LIB3270_EXPORT int lib3270_get_undera(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return (h->oia_flag[LIB3270_FLAG_UNDERA] != 0); +} + +LIB3270_EXPORT int lib3270_get_oia_box_solid(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return (h->oia_flag[LIB3270_FLAG_BOXSOLID] != 0); +} diff --git a/private.h b/private.h index 1c6ec61..cb2edf7 100644 --- a/private.h +++ b/private.h @@ -24,15 +24,13 @@ * * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) * erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda) * */ /* Autoconf settings. */ #include /* autoconf settings */ #include /* lib3270 API calls and defs */ +#include #include "api.h" #if defined(X3270_TN3270E) && !defined(X3270_ANSI) /*[*/ @@ -148,20 +146,19 @@ struct toggle_name { /* Naming convention for private actions. */ #define PA_PFX "PA-" -/* Shorthand macros */ - +/// @brief Shorthand macros #define CN ((char *) NULL) #define PN ((XtPointer) NULL) #define Replace(var, value) { lib3270_free(var); var = (value); }; -/* Configuration change masks. */ -#define NO_CHANGE 0x0000 /* no change */ -#define MODEL_CHANGE 0x0001 /* screen dimensions changed */ -#define FONT_CHANGE 0x0002 /* emulator font changed */ -#define COLOR_CHANGE 0x0004 /* color scheme or 3278/9 mode changed */ -#define SCROLL_CHANGE 0x0008 /* scrollbar snapped on or off */ -#define CHARSET_CHANGE 0x0010 /* character set changed */ -#define ALL_CHANGE 0xffff /* everything changed */ +/// @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 */ @@ -186,7 +183,7 @@ struct toggle_name { /* DBCS Preedit Types */ #if defined(X3270_DBCS) /*[*/ - #define PT_ROOT "Root" + #define PT_ROOT "Root" #define PT_OVER_THE_SPOT "OverTheSpot" #define PT_OFF_THE_SPOT "OffTheSpot" #define PT_ON_THE_SPOT "OnTheSpot" @@ -211,7 +208,7 @@ LIB3270_INTERNAL struct _ansictl char vlnext; } ansictl; -/** extended attributes */ +/** @brief Extended attributes */ struct lib3270_ea { unsigned char cc; ///< @brief EBCDIC or ASCII character code @@ -230,21 +227,346 @@ struct lib3270_text unsigned short attr; ///< @brief Converted character attribute (color & etc) }; +#ifndef HEADER_SSL_H + #define SSL void +#endif // !HEADER_SSL_H + +#ifndef LIB3270_TA + #define LIB3270_TA void +#endif // !LIB3270_TA + +#define LIB3270_MB_MAX 16 +#define LIB3270_DEFAULT_CGEN 0x02b90000 +#define LIB3270_DEFAULT_CSET 0x00000025 + +#define LIB3270_LUNAME_LENGTH 16 +#define LIB3270_FULL_MODEL_NAME_LENGTH 13 +#define LIB3270_LU_MAX 32 +#define LIB3270_TELNET_N_OPTS 256 -/* default charset translation tables */ -// LIB3270_INTERNAL const unsigned short ebc2asc0[256]; -// LIB3270_INTERNAL const unsigned short asc2ft0[256]; +/** @brief lib3270 session data */ +struct _h3270 +{ + unsigned short sz; /**< Struct size */ + + // Connection info + int sock; /**< Network socket */ + LIB3270_CSTATE cstate; /**< Connection state */ + + // flags + LIB3270_OPTION options; /**< Session options */ + + int bgthread : 1; /**< Running on a background thread ? */ + int selected : 1; /**< Has selected region? */ + int rectsel : 1; /**< Selected region is a rectangle ? */ + int vcontrol : 1; /**< Visible control ? */ + int modified_sel : 1; + int mono : 1; /**< Forces monochrome display */ + int m3279 : 1; + int extended : 1; + int typeahead : 1; + int numeric_lock : 1; + int oerr_lock : 1; + int unlock_delay : 1; + int auto_reconnect_inprogress : 1; + unsigned int colors : 5; + int apl_mode : 1; + int icrnl : 1; + int inlcr : 1; + int onlcr : 1; + int bsd_tm : 1; + int syncing : 1; + int reverse : 1; /**< 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; /**< Formatted screen flag */ + int starting : 1; /**< Is starting (no first screen)? */ + + char * oversize; + + LIB3270_SSL_STATE secure; + + 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 * connected_lu; + char luname[LIB3270_LUNAME_LENGTH+1]; + + char full_model_name[LIB3270_FULL_MODEL_NAME_LENGTH+1]; + char * model_name; + int model_num; + char * termtype; + + struct + { + char * current; /**< The hostname part, stripped of qualifiers, luname and port number */ + char * full; /**< The entire string, for use in reconnecting */ + char * srvc; /**< The service name */ + char * qualified; + } host; + + char * proxy; /**< Proxy server (type:host[:port]) */ + char * termname; + + struct lib3270_charset charset; + + LIB3270_MESSAGE oia_status; + + unsigned char oia_flag[LIB3270_FLAG_COUNT]; + + unsigned short current_port; + + // Misc + void * ft; /**< Active file transfer data */ + + // screen info + int ov_rows; + int ov_cols; + int maxROWS; + int maxCOLS; + unsigned short rows; + unsigned short cols; + int cursor_addr; + int buffer_addr; + char flipped; + int screen_alt; /**< alternate screen? */ + int is_altbuffer; + + // Screen contents + void * buffer[2]; /**< Internal buffers */ + struct lib3270_ea * ea_buf; /**< 3270 device buffer. ea_buf[-1] is the dummy default field attribute */ + struct lib3270_ea * aea_buf; /**< alternate 3270 extended attribute buffer */ + struct lib3270_text * text; /**< Converted 3270 chars */ + + // host.c + char std_ds_host; + char no_login_host; + char non_tn3270e_host; + char passthru_host; + char ssl_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; /**< empty buffer, for area clears */ + + struct timeval t_start; + void * tick_id; + struct timeval t_want; + + // Telnet.c + unsigned char * ibuf; + int ibuf_size; /**< size of ibuf */ + unsigned char * obuf; /**< 3270 output buffer */ + unsigned char * obptr; + time_t ns_time; + int ns_brcvd; + int ns_rrcvd; + int ns_bsent; + int ns_rsent; + struct timeval ds_ts; + unsigned long e_funcs; /**< negotiated TN3270E functions */ + unsigned short e_xmit_seq; /**< transmit sequence number */ + int response_required; + int tn3270e_bound; + int tn3270e_negotiated; + int ansi_data; + int lnext; + int backslashed; + char plu_name[LIB3270_BIND_PLU_NAME_MAX+1]; + char **lus; + char **curr_lu; + char * try_lu; + int proxy_type; + char * proxy_host; + char * proxy_portname; + unsigned short proxy_port; + char reported_lu[LIB3270_LU_MAX+1]; + char reported_type[LIB3270_LU_MAX+1]; + + enum + { + E_NONE, + E_3270, + E_NVT, + E_SSCP + } tn3270e_submode; + + unsigned char * lbuf; /**< line-mode input buffer */ + unsigned char * lbptr; + + + // 3270 input buffer + unsigned char * ibptr; + unsigned char * obuf_base; + int obuf_size; +// unsigned char * netrbuf; + + // network input buffer + unsigned char * sbbuf; + + // telnet sub-option buffer + unsigned char * sbptr; + unsigned char telnet_state; +// char ttype_tmpval[13]; + + unsigned char myopts[LIB3270_TELNET_N_OPTS]; + unsigned char hisopts[LIB3270_TELNET_N_OPTS]; + + // kybd.c + unsigned int kybdlock; ///< @brief keyboard lock state + unsigned char aid; ///< @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; /**< Non zero if the ansi_reset() was called in this session */ + + int ansi_ch; + int cs_to_change; + + /** 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; + + /** 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 + void * ns_read_id; + void * ns_write_id; + void * ns_exception_id; + + // SSL Data (Always defined to mantain the same structure size) + unsigned long ssl_error; + SSL * ssl_con; + + // Callbacks. + struct lib3270_state_callback * st_callbacks[LIB3270_STATE_USER]; + struct lib3270_state_callback * st_last[LIB3270_STATE_USER]; + struct lib3270_session_callbacks cbk; + +}; /* Library internal calls */ -LIB3270_INTERNAL void key_ACharacter(H3270 *hSession, unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped); -LIB3270_INTERNAL void lib3270_initialize(void); -LIB3270_INTERNAL int cursor_move(H3270 *session, int baddr); +LIB3270_INTERNAL void key_ACharacter(H3270 *hSession, unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped); +LIB3270_INTERNAL void lib3270_initialize(void); +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 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); @@ -259,7 +581,7 @@ LIB3270_INTERNAL int lib3270_default_event_dispatcher(H3270 *hSession, int block LIB3270_INTERNAL void check_session_handle(H3270 **hSession); #endif // DEBUG -LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on); +LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on); #if defined(HAVE_LIBSSL) /*[*/ -- libgit2 0.21.2