Commit 958169d3ae1401961253677f934e8c4ec9588c5d

Authored by Perry Werneck
1 parent 26874935

Isolando estrutura de sessão para evitar que alterações na biblioteca causem que…

…bra de compatibilidade binária com o aplicativo principal ou plugins.
Showing 2 changed files with 369 additions and 24 deletions   Show diff stats
host.c
... ... @@ -375,3 +375,26 @@ LIB3270_EXPORT const char * lib3270_get_luname(H3270 *h)
375 375 return h->connected_lu;
376 376 }
377 377  
  378 +LIB3270_EXPORT int lib3270_has_active_script(H3270 *h)
  379 +{
  380 + CHECK_SESSION_HANDLE(h);
  381 + return (h->oia_flag[LIB3270_FLAG_SCRIPT] != 0);
  382 +}
  383 +
  384 +LIB3270_EXPORT int lib3270_get_typeahead(H3270 *h)
  385 +{
  386 + CHECK_SESSION_HANDLE(h);
  387 + return (h->oia_flag[LIB3270_FLAG_TYPEAHEAD] != 0);
  388 +}
  389 +
  390 +LIB3270_EXPORT int lib3270_get_undera(H3270 *h)
  391 +{
  392 + CHECK_SESSION_HANDLE(h);
  393 + return (h->oia_flag[LIB3270_FLAG_UNDERA] != 0);
  394 +}
  395 +
  396 +LIB3270_EXPORT int lib3270_get_oia_box_solid(H3270 *h)
  397 +{
  398 + CHECK_SESSION_HANDLE(h);
  399 + return (h->oia_flag[LIB3270_FLAG_BOXSOLID] != 0);
  400 +}
... ...
private.h
... ... @@ -24,15 +24,13 @@
24 24 *
25 25 * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
26 26 * erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça)
27   - * licinio@bb.com.br (Licínio Luis Branco)
28   - * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
29   - * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda)
30 27 *
31 28 */
32 29  
33 30 /* Autoconf settings. */
34 31 #include <lib3270/config.h> /* autoconf settings */
35 32 #include <lib3270.h> /* lib3270 API calls and defs */
  33 +#include <lib3270/charset.h>
36 34 #include "api.h"
37 35  
38 36 #if defined(X3270_TN3270E) && !defined(X3270_ANSI) /*[*/
... ... @@ -148,20 +146,19 @@ struct toggle_name {
148 146 /* Naming convention for private actions. */
149 147 #define PA_PFX "PA-"
150 148  
151   -/* Shorthand macros */
152   -
  149 +/// @brief Shorthand macros
153 150 #define CN ((char *) NULL)
154 151 #define PN ((XtPointer) NULL)
155 152 #define Replace(var, value) { lib3270_free(var); var = (value); };
156 153  
157   -/* Configuration change masks. */
158   -#define NO_CHANGE 0x0000 /* no change */
159   -#define MODEL_CHANGE 0x0001 /* screen dimensions changed */
160   -#define FONT_CHANGE 0x0002 /* emulator font changed */
161   -#define COLOR_CHANGE 0x0004 /* color scheme or 3278/9 mode changed */
162   -#define SCROLL_CHANGE 0x0008 /* scrollbar snapped on or off */
163   -#define CHARSET_CHANGE 0x0010 /* character set changed */
164   -#define ALL_CHANGE 0xffff /* everything changed */
  154 +/// @brief Configuration change masks.
  155 +#define NO_CHANGE 0x0000 /// @brief no change
  156 +#define MODEL_CHANGE 0x0001 /// @brief screen dimensions changed
  157 +#define FONT_CHANGE 0x0002 /// @brief emulator font changed
  158 +#define COLOR_CHANGE 0x0004 /// @brief color scheme or 3278/9 mode changed
  159 +#define SCROLL_CHANGE 0x0008 /// @brief scrollbar snapped on or off
  160 +#define CHARSET_CHANGE 0x0010 /// @brief character set changed
  161 +#define ALL_CHANGE 0xffff /// @brief everything changed
165 162  
166 163 /* Portability macros */
167 164  
... ... @@ -186,7 +183,7 @@ struct toggle_name {
186 183  
187 184 /* DBCS Preedit Types */
188 185 #if defined(X3270_DBCS) /*[*/
189   - #define PT_ROOT "Root"
  186 + #define PT_ROOT "Root"
190 187 #define PT_OVER_THE_SPOT "OverTheSpot"
191 188 #define PT_OFF_THE_SPOT "OffTheSpot"
192 189 #define PT_ON_THE_SPOT "OnTheSpot"
... ... @@ -211,7 +208,7 @@ LIB3270_INTERNAL struct _ansictl
211 208 char vlnext;
212 209 } ansictl;
213 210  
214   -/** extended attributes */
  211 +/** @brief Extended attributes */
215 212 struct lib3270_ea
216 213 {
217 214 unsigned char cc; ///< @brief EBCDIC or ASCII character code
... ... @@ -230,21 +227,346 @@ struct lib3270_text
230 227 unsigned short attr; ///< @brief Converted character attribute (color & etc)
231 228 };
232 229  
  230 +#ifndef HEADER_SSL_H
  231 + #define SSL void
  232 +#endif // !HEADER_SSL_H
  233 +
  234 +#ifndef LIB3270_TA
  235 + #define LIB3270_TA void
  236 +#endif // !LIB3270_TA
  237 +
  238 +#define LIB3270_MB_MAX 16
  239 +#define LIB3270_DEFAULT_CGEN 0x02b90000
  240 +#define LIB3270_DEFAULT_CSET 0x00000025
  241 +
  242 +#define LIB3270_LUNAME_LENGTH 16
  243 +#define LIB3270_FULL_MODEL_NAME_LENGTH 13
  244 +#define LIB3270_LU_MAX 32
233 245  
  246 +#define LIB3270_TELNET_N_OPTS 256
234 247  
235 248  
236   -/* default charset translation tables */
237   -// LIB3270_INTERNAL const unsigned short ebc2asc0[256];
238   -// LIB3270_INTERNAL const unsigned short asc2ft0[256];
  249 +/** @brief lib3270 session data */
  250 +struct _h3270
  251 +{
  252 + unsigned short sz; /**< Struct size */
  253 +
  254 + // Connection info
  255 + int sock; /**< Network socket */
  256 + LIB3270_CSTATE cstate; /**< Connection state */
  257 +
  258 + // flags
  259 + LIB3270_OPTION options; /**< Session options */
  260 +
  261 + int bgthread : 1; /**< Running on a background thread ? */
  262 + int selected : 1; /**< Has selected region? */
  263 + int rectsel : 1; /**< Selected region is a rectangle ? */
  264 + int vcontrol : 1; /**< Visible control ? */
  265 + int modified_sel : 1;
  266 + int mono : 1; /**< Forces monochrome display */
  267 + int m3279 : 1;
  268 + int extended : 1;
  269 + int typeahead : 1;
  270 + int numeric_lock : 1;
  271 + int oerr_lock : 1;
  272 + int unlock_delay : 1;
  273 + int auto_reconnect_inprogress : 1;
  274 + unsigned int colors : 5;
  275 + int apl_mode : 1;
  276 + int icrnl : 1;
  277 + int inlcr : 1;
  278 + int onlcr : 1;
  279 + int bsd_tm : 1;
  280 + int syncing : 1;
  281 + int reverse : 1; /**< reverse-input mode */
  282 + int dbcs : 1;
  283 + int linemode : 1;
  284 + int trace_skipping : 1;
  285 + int need_tls_follows : 1;
  286 + int cut_xfer_in_progress : 1;
  287 +// int auto_keymap : 1;
  288 + int formatted : 1; /**< Formatted screen flag */
  289 + int starting : 1; /**< Is starting (no first screen)? */
  290 +
  291 + char * oversize;
  292 +
  293 + LIB3270_SSL_STATE secure;
  294 +
  295 + struct lib3270_toggle
  296 + {
  297 + char value; /**< toggle value */
  298 + void (*upcall)(H3270 *, struct lib3270_toggle *, LIB3270_TOGGLE_TYPE); /**< change value */
  299 + } toggle[LIB3270_TOGGLE_COUNT];
  300 +
  301 + // Network & Termtype
  302 + char * connected_type;
  303 + char * connected_lu;
  304 + char luname[LIB3270_LUNAME_LENGTH+1];
  305 +
  306 + char full_model_name[LIB3270_FULL_MODEL_NAME_LENGTH+1];
  307 + char * model_name;
  308 + int model_num;
  309 + char * termtype;
  310 +
  311 + struct
  312 + {
  313 + char * current; /**< The hostname part, stripped of qualifiers, luname and port number */
  314 + char * full; /**< The entire string, for use in reconnecting */
  315 + char * srvc; /**< The service name */
  316 + char * qualified;
  317 + } host;
  318 +
  319 + char * proxy; /**< Proxy server (type:host[:port]) */
  320 + char * termname;
  321 +
  322 + struct lib3270_charset charset;
  323 +
  324 + LIB3270_MESSAGE oia_status;
  325 +
  326 + unsigned char oia_flag[LIB3270_FLAG_COUNT];
  327 +
  328 + unsigned short current_port;
  329 +
  330 + // Misc
  331 + void * ft; /**< Active file transfer data */
  332 +
  333 + // screen info
  334 + int ov_rows;
  335 + int ov_cols;
  336 + int maxROWS;
  337 + int maxCOLS;
  338 + unsigned short rows;
  339 + unsigned short cols;
  340 + int cursor_addr;
  341 + int buffer_addr;
  342 + char flipped;
  343 + int screen_alt; /**< alternate screen? */
  344 + int is_altbuffer;
  345 +
  346 + // Screen contents
  347 + void * buffer[2]; /**< Internal buffers */
  348 + struct lib3270_ea * ea_buf; /**< 3270 device buffer. ea_buf[-1] is the dummy default field attribute */
  349 + struct lib3270_ea * aea_buf; /**< alternate 3270 extended attribute buffer */
  350 + struct lib3270_text * text; /**< Converted 3270 chars */
  351 +
  352 + // host.c
  353 + char std_ds_host;
  354 + char no_login_host;
  355 + char non_tn3270e_host;
  356 + char passthru_host;
  357 + char ssl_host;
  358 + char ever_3270;
  359 +
  360 + // ctlr.c
  361 + int sscp_start;
  362 + unsigned char default_fg;
  363 + unsigned char default_bg;
  364 + unsigned char default_gr;
  365 + unsigned char default_cs;
  366 + unsigned char default_ic;
  367 + char reply_mode;
  368 + int trace_primed : 1;
  369 + int ticking : 1;
  370 + int mticking : 1;
  371 + int crm_nattr;
  372 + unsigned char crm_attr[16];
  373 + unsigned char * zero_buf; /**< empty buffer, for area clears */
  374 +
  375 + struct timeval t_start;
  376 + void * tick_id;
  377 + struct timeval t_want;
  378 +
  379 + // Telnet.c
  380 + unsigned char * ibuf;
  381 + int ibuf_size; /**< size of ibuf */
  382 + unsigned char * obuf; /**< 3270 output buffer */
  383 + unsigned char * obptr;
  384 + time_t ns_time;
  385 + int ns_brcvd;
  386 + int ns_rrcvd;
  387 + int ns_bsent;
  388 + int ns_rsent;
  389 + struct timeval ds_ts;
  390 + unsigned long e_funcs; /**< negotiated TN3270E functions */
  391 + unsigned short e_xmit_seq; /**< transmit sequence number */
  392 + int response_required;
  393 + int tn3270e_bound;
  394 + int tn3270e_negotiated;
  395 + int ansi_data;
  396 + int lnext;
  397 + int backslashed;
  398 + char plu_name[LIB3270_BIND_PLU_NAME_MAX+1];
  399 + char **lus;
  400 + char **curr_lu;
  401 + char * try_lu;
  402 + int proxy_type;
  403 + char * proxy_host;
  404 + char * proxy_portname;
  405 + unsigned short proxy_port;
  406 + char reported_lu[LIB3270_LU_MAX+1];
  407 + char reported_type[LIB3270_LU_MAX+1];
  408 +
  409 + enum
  410 + {
  411 + E_NONE,
  412 + E_3270,
  413 + E_NVT,
  414 + E_SSCP
  415 + } tn3270e_submode;
  416 +
  417 + unsigned char * lbuf; /**< line-mode input buffer */
  418 + unsigned char * lbptr;
  419 +
  420 +
  421 + // 3270 input buffer
  422 + unsigned char * ibptr;
  423 + unsigned char * obuf_base;
  424 + int obuf_size;
  425 +// unsigned char * netrbuf;
  426 +
  427 + // network input buffer
  428 + unsigned char * sbbuf;
  429 +
  430 + // telnet sub-option buffer
  431 + unsigned char * sbptr;
  432 + unsigned char telnet_state;
  433 +// char ttype_tmpval[13];
  434 +
  435 + unsigned char myopts[LIB3270_TELNET_N_OPTS];
  436 + unsigned char hisopts[LIB3270_TELNET_N_OPTS];
  437 +
  438 + // kybd.c
  439 + unsigned int kybdlock; ///< @brief keyboard lock state
  440 + unsigned char aid; ///< @brief current attention ID
  441 + void * unlock_id;
  442 + time_t unlock_delay_time;
  443 + unsigned long unlock_delay_ms; ///< @brief Delay before actually unlocking the keyboard after the host permits it.
  444 + LIB3270_TA * ta_head;
  445 + LIB3270_TA * ta_tail;
  446 +
  447 + // ft_dft.c
  448 + int dft_buffersize; ///< @brief Buffer size (LIMIN, LIMOUT)
  449 +
  450 + // rpq.c
  451 + int rpq_complained : 1;
  452 +#if !defined(_WIN32)
  453 + int omit_due_space_limit : 1;
  454 +#endif
239 455  
  456 + char * rpq_warnbuf;
  457 + int rpq_wbcnt;
  458 +
  459 + // User data (Usually points to session's widget)
  460 + void * user_data;
  461 +
  462 + // selection
  463 + char * paste_buffer;
  464 + struct
  465 + {
  466 + int start;
  467 + int end;
  468 + } select;
  469 +
  470 + // ansi.c
  471 + int scroll_top;
  472 + int scroll_bottom;
  473 + int once_cset;
  474 + int saved_cursor;
  475 +
  476 + int held_wrap : 1;
  477 +
  478 + int insert_mode : 1;
  479 + int auto_newline_mode : 1;
  480 +
  481 + int appl_cursor : 1;
  482 + int saved_appl_cursor : 1;
  483 +
  484 + int wraparound_mode : 1;
  485 + int saved_wraparound_mode : 1;
  486 +
  487 + int rev_wraparound_mode : 1;
  488 + int saved_rev_wraparound_mode : 1;
  489 +
  490 + int allow_wide_mode : 1;
  491 + int saved_allow_wide_mode : 1;
  492 +
  493 + int wide_mode : 1;
  494 + int saved_wide_mode : 1;
  495 +
  496 + int saved_altbuffer : 1;
  497 + int ansi_reset : 1; /**< Non zero if the ansi_reset() was called in this session */
  498 +
  499 + int ansi_ch;
  500 + int cs_to_change;
  501 +
  502 + /** ANSI Character sets. */
  503 + enum lib3270_ansi_cs
  504 + {
  505 + LIB3270_ANSI_CS_G0 = 0,
  506 + LIB3270_ANSI_CS_G1 = 1,
  507 + LIB3270_ANSI_CS_G2 = 2,
  508 + LIB3270_ANSI_CS_G3 = 3
  509 + } cset;
  510 + enum lib3270_ansi_cs saved_cset;
  511 +
  512 + /** Character set designations. */
  513 + enum lib3270_ansi_csd
  514 + {
  515 + LIB3270_ANSI_CSD_LD = 0,
  516 + LIB3270_ANSI_CSD_UK = 1,
  517 + LIB3270_ANSI_CSD_US = 2
  518 + } csd[4];
  519 + enum lib3270_ansi_csd saved_csd[4];
  520 +
  521 + enum lib3270_ansi_state
  522 + {
  523 + LIB3270_ANSI_STATE_DATA = 0,
  524 + LIB3270_ANSI_STATE_ESC = 1,
  525 + LIB3270_ANSI_STATE_CSDES = 2,
  526 + LIB3270_ANSI_STATE_N1 = 3,
  527 + LIB3270_ANSI_STATE_DECP = 4,
  528 + LIB3270_ANSI_STATE_TEXT = 5,
  529 + LIB3270_ANSI_STATE_TEXT2 = 6,
  530 + LIB3270_ANSI_STATE_MBPEND = 7
  531 + } state;
  532 +
  533 + unsigned char * tabs;
  534 +
  535 + int pmi;
  536 + char pending_mbs[LIB3270_MB_MAX];
  537 +
  538 + unsigned char gr;
  539 + unsigned char saved_gr;
  540 +
  541 + unsigned char fg;
  542 + unsigned char saved_fg;
  543 +
  544 + unsigned char bg;
  545 + unsigned char saved_bg;
  546 +
  547 + // xio
  548 + void * ns_read_id;
  549 + void * ns_write_id;
  550 + void * ns_exception_id;
  551 +
  552 + // SSL Data (Always defined to mantain the same structure size)
  553 + unsigned long ssl_error;
  554 + SSL * ssl_con;
  555 +
  556 + // Callbacks.
  557 + struct lib3270_state_callback * st_callbacks[LIB3270_STATE_USER];
  558 + struct lib3270_state_callback * st_last[LIB3270_STATE_USER];
  559 + struct lib3270_session_callbacks cbk;
  560 +
  561 +};
240 562  
241 563 /* Library internal calls */
242   -LIB3270_INTERNAL void key_ACharacter(H3270 *hSession, unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped);
243   -LIB3270_INTERNAL void lib3270_initialize(void);
244   -LIB3270_INTERNAL int cursor_move(H3270 *session, int baddr);
  564 +LIB3270_INTERNAL void key_ACharacter(H3270 *hSession, unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped);
  565 +LIB3270_INTERNAL void lib3270_initialize(void);
  566 +LIB3270_INTERNAL int cursor_move(H3270 *session, int baddr);
245 567  
246   -LIB3270_INTERNAL void toggle_rectselect(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE_TYPE tt);
247   -LIB3270_INTERNAL void remove_input_calls(H3270 *session);
  568 +LIB3270_INTERNAL void toggle_rectselect(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE_TYPE tt);
  569 +LIB3270_INTERNAL void remove_input_calls(H3270 *session);
248 570  
249 571 LIB3270_INTERNAL int lib3270_sock_send(H3270 *hSession, unsigned const char *buf, int len);
250 572 LIB3270_INTERNAL void lib3270_sock_disconnect(H3270 *hSession);
... ... @@ -259,7 +581,7 @@ LIB3270_INTERNAL int lib3270_default_event_dispatcher(H3270 *hSession, int block
259 581 LIB3270_INTERNAL void check_session_handle(H3270 **hSession);
260 582 #endif // DEBUG
261 583  
262   -LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on);
  584 +LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on);
263 585  
264 586 #if defined(HAVE_LIBSSL) /*[*/
265 587  
... ...