Commit 1c9cd360b3957f1381fac2033dbbaaa75a4d29bb

Authored by Perry Werneck
Committed by GitHub
2 parents 795c8ff9 339372a7
Exists in master and in 2 other branches develop, macos

Merge pull request #14 from PerryWerneck/develop

Bug fixes and updates.
lib3270.cbp
... ... @@ -255,7 +255,6 @@
255 255 </Unit>
256 256 <Unit filename="src/include/3270ds.h" />
257 257 <Unit filename="src/include/X11keysym.h" />
258   - <Unit filename="src/include/action_table.h" />
259 258 <Unit filename="src/include/ansic.h" />
260 259 <Unit filename="src/include/arpa_telnet.h" />
261 260 <Unit filename="src/include/array.h" />
... ... @@ -271,7 +270,6 @@
271 270 <Unit filename="src/include/hostc.h" />
272 271 <Unit filename="src/include/internals.h" />
273 272 <Unit filename="src/include/kybdc.h" />
274   - <Unit filename="src/include/lib3270++.h" />
275 273 <Unit filename="src/include/lib3270.h" />
276 274 <Unit filename="src/include/lib3270/actions.h" />
277 275 <Unit filename="src/include/lib3270/charset.h" />
... ...
locale/pt_BR.po
... ... @@ -6,7 +6,7 @@ msgstr &quot;&quot;
6 6 "Project-Id-Version: pw3270 5.0\n"
7 7 "Report-Msgid-Bugs-To: \n"
8 8 "POT-Creation-Date: 2020-10-17 11:58-0300\n"
9   -"PO-Revision-Date: 2020-09-03 18:36-0300\n"
  9 +"PO-Revision-Date: 2020-11-04 20:42-0300\n"
10 10 "Last-Translator: Perry Werneck <perry.werneck@gmail.com>\n"
11 11 "Language-Team: Português <>\n"
12 12 "Language: pt_BR\n"
... ... @@ -16,8 +16,7 @@ msgstr &quot;&quot;
16 16 "X-Poedit-Language: Portuguese\n"
17 17 "X-Poedit-Country: BRAZIL\n"
18 18 "X-Poedit-SourceCharset: utf-8\n"
19   -"Plural-Forms: nplurals=4; plural= (n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != "
20   -"11) ? 2 : 3;\n"
  19 +"Plural-Forms: nplurals=2; plural=(n != 1);\n"
21 20 "X-Generator: Gtranslator 2.91.7\n"
22 21  
23 22 #: src/core/ctlr.c:187
... ... @@ -898,12 +897,10 @@ msgid &quot;Keyboard lock status&quot;
898 897 msgstr "Estado de bloqueio do teclado"
899 898  
900 899 #: src/core/windows/ldap.c:193
901   -#, fuzzy
902 900 msgid "LDAP Search did not produce any attributes."
903 901 msgstr "Pesquisa LDAP não produziu nenhum atributo."
904 902  
905 903 #: src/core/windows/ldap.c:201
906   -#, fuzzy
907 904 msgid "LDAPSearch did not produce any values."
908 905 msgstr "Pesquisa LDAP não produziu nenhum valor."
909 906  
... ...
src/core/actions/table.c
... ... @@ -48,7 +48,7 @@
48 48  
49 49 static int connect_host(H3270 *hSession)
50 50 {
51   - return lib3270_reconnect(hSession,0);
  51 + return hSession->cbk.reconnect(hSession,0);
52 52 }
53 53  
54 54 static int select_up(H3270 *hSession)
... ...
src/core/ansi.c
... ... @@ -59,7 +59,7 @@
59 59 #include "screenc.h"
60 60 #include "telnetc.h"
61 61 #include "trace_dsc.h"
62   -#include "utf8c.h"
  62 +//#include "utf8c.h"
63 63 #if defined(X3270_DBCS) /*[*/
64 64 #include "widec.h"
65 65 #endif /*]*/
... ...
src/core/charset/utf8.c
... ... @@ -39,7 +39,7 @@
39 39 // #include "api.h"
40 40  
41 41 #include "popupsc.h"
42   -#include "utf8c.h"
  42 +//#include "utf8c.h"
43 43  
44 44 // char *locale_codeset = CN;
45 45  
... ... @@ -350,6 +350,7 @@ static char *utf8_tab[U_MAX][96] = {
350 350 * character set.
351 351 * Returns 0 if the lookup fails.
352 352 */
  353 + /*
353 354 unsigned char utf8_lookup(char GNUC_UNUSED(*mbs), enum ulfail *fail, int GNUC_UNUSED(*consumed))
354 355 {
355 356 if (fail != NULL)
... ... @@ -357,3 +358,4 @@ unsigned char utf8_lookup(char GNUC_UNUSED(*mbs), enum ulfail *fail, int GNUC_UN
357 358  
358 359 return 0;
359 360 }
  361 +*/
... ...
src/core/connect.c
... ... @@ -49,36 +49,10 @@
49 49 lib3270_set_url(hSession,url);
50 50 }
51 51  
52   - return lib3270_reconnect(hSession, seconds);
  52 + return hSession->cbk.reconnect(hSession, seconds);
53 53  
54 54 }
55 55  
56   -/*
57   - void connection_failed(H3270 *hSession, const char *message)
58   - {
59   - lib3270_disconnect(hSession);
60   -
61   - lib3270_autoptr(char) summary = lib3270_strdup_printf(
62   - _( "Can't connect to %s:%s"),
63   - hSession->host.current,
64   - hSession->host.srvc
65   - );
66   -
67   - LIB3270_POPUP popup = {
68   - .name = "CantConnect",
69   -// .title = _( "Connection failed" ),
70   - .type = LIB3270_NOTIFY_INFO,
71   - .summary = summary,
72   - .body = message,
73   - .label = _("Try again")
74   - };
75   -
76   - if(hSession->cbk.popup(hSession,&popup,!hSession->auto_reconnect_inprogress) == 0)
77   - lib3270_activate_auto_reconnect(hSession,1000);
78   -
79   - }
80   -*/
81   -
82 56 int lib3270_allow_reconnect(const H3270 *hSession)
83 57 {
84 58 //
... ... @@ -103,7 +77,8 @@
103 77 // Do I have a defined host?
104 78 if(!(hSession->host.current && hSession->host.srvc && *hSession->host.current && *hSession->host.srvc))
105 79 {
106   - errno = EINVAL;
  80 + debug("%s('%s')",__FUNCTION__,hSession->host.url);
  81 + errno = ENODATA;
107 82 return 0;
108 83 }
109 84  
... ...
src/core/ctlr.c
... ... @@ -46,7 +46,7 @@
46 46 #include <stdlib.h>
47 47 #include "3270ds.h"
48 48 #include "screen.h"
49   -#include "resources.h"
  49 +//#include "resources.h"
50 50  
51 51 #include "ctlrc.h"
52 52 #include "ftc.h"
... ... @@ -205,7 +205,7 @@ void ctlr_set_rows_cols(H3270 *session, int mn, int ovc, int ovr)
205 205 // popup_an_error(session,"Invalid %s %dx%d:\nToo big",ResOversize, ovc, ovr);
206 206  
207 207 }
208   - else if (ovc > 0 && ovc < session->max.cols)
  208 + else if (ovc < session->max.cols)
209 209 {
210 210  
211 211 lib3270_popup_dialog(
... ... @@ -219,7 +219,7 @@ void ctlr_set_rows_cols(H3270 *session, int mn, int ovc, int ovr)
219 219  
220 220 // popup_an_error(session,"Invalid %s cols (%d):\nLess than model %d cols (%d)",ResOversize, ovc, session->model_num, session->maxCOLS);
221 221 }
222   - else if (ovr > 0 && ovr < session->max.rows)
  222 + else if (ovr < session->max.rows)
223 223 {
224 224  
225 225 lib3270_popup_dialog(
... ...
src/core/host.c
... ... @@ -43,7 +43,7 @@
43 43  
44 44 #include <internals.h>
45 45 #include <stdlib.h>
46   -#include "resources.h"
  46 +//#include "resources.h"
47 47  
48 48 #include "hostc.h"
49 49 #include "statusc.h"
... ... @@ -74,7 +74,7 @@ static int check_for_auto_reconnect(H3270 *hSession, void GNUC_UNUSED(*userdata)
74 74 {
75 75 lib3270_write_log(hSession,"3270","Starting auto-reconnect on %s",lib3270_get_url(hSession));
76 76 hSession->auto_reconnect_inprogress = 0; // Reset "in-progress" to allow reconnection.
77   - if(lib3270_reconnect(hSession,0))
  77 + if(hSession->cbk.reconnect(hSession,0))
78 78 lib3270_write_log(hSession,"3270","Auto-reconnect fails: %s",strerror(errno));
79 79 }
80 80  
... ...
src/core/iocalls.c
... ... @@ -465,9 +465,10 @@ LIB3270_EXPORT int lib3270_run_task(H3270 *hSession, int(*callback)(H3270 *h, vo
465 465 CHECK_SESSION_HANDLE(hSession);
466 466  
467 467 hSession->cbk.set_timer(hSession,1);
  468 + hSession->tasks++;
468 469 rc = run_task(hSession,callback,parm);
469 470 hSession->cbk.set_timer(hSession,0);
470   -
  471 + hSession->tasks--;
471 472 return rc;
472 473  
473 474 }
... ...
src/core/keyboard/actions.c
... ... @@ -57,7 +57,7 @@ struct ta;
57 57  
58 58 #include <fcntl.h>
59 59 #include "3270ds.h"
60   -#include "resources.h"
  60 +//#include "resources.h"
61 61  
62 62 #include "ansic.h"
63 63 #include "ctlrc.h"
... ... @@ -71,7 +71,7 @@ struct ta;
71 71 #include "telnetc.h"
72 72 #include "togglesc.h"
73 73 #include "trace_dsc.h"
74   -#include "utf8c.h"
  74 +//#include "utf8c.h"
75 75 #include "utilc.h"
76 76 #if defined(X3270_DBCS) /*[*/
77 77 #include "widec.h"
... ...
src/core/keyboard/kybd.c
... ... @@ -58,7 +58,7 @@ struct ta;
58 58  
59 59 #include <fcntl.h>
60 60 #include "3270ds.h"
61   -#include "resources.h"
  61 +//#include "resources.h"
62 62  
63 63 #include "ansic.h"
64 64 #include "ctlrc.h"
... ... @@ -72,7 +72,7 @@ struct ta;
72 72 #include "telnetc.h"
73 73 #include "togglesc.h"
74 74 #include "trace_dsc.h"
75   -#include "utf8c.h"
  75 +//#include "utf8c.h"
76 76 #include "utilc.h"
77 77 #if defined(X3270_DBCS) /*[*/
78 78 #include "widec.h"
... ... @@ -110,11 +110,13 @@ static void kybdlock_set(H3270 *session, unsigned int bits);
110 110  
111 111 /* Composite key mappings. */
112 112  
  113 +/*
113 114 struct akeysym
114 115 {
115 116 KeySym keysym;
116 117 enum keytype keytype;
117 118 };
  119 +*/
118 120  
119 121 #define ak_eq(k1, k2) (((k1).keysym == (k2).keysym) && \
120 122 ((k1).keytype == (k2).keytype))
... ...
src/core/linux/connect.c
... ... @@ -89,7 +89,7 @@
89 89  
90 90 case 1:
91 91 // Got response.
92   - if(pfd.revents && POLLOUT) {
  92 + if(pfd.revents & POLLOUT) {
93 93 debug("%s: Connection complete",__FUNCTION__);
94 94 return 0;
95 95 }
... ... @@ -194,15 +194,23 @@
194 194  
195 195 if(hSession->network.module->getsockopt(hSession, SOL_SOCKET, SO_ERROR, (char *) &err, &len) < 0)
196 196 {
197   - int err = errno;
  197 + lib3270_autoptr(char) body = lib3270_strdup_printf(
  198 + _("The System error was '%s' (rc=%d)"),
  199 + strerror(errno),
  200 + errno
  201 + );
  202 +
198 203 lib3270_disconnect(hSession);
199   - lib3270_popup_dialog(
200   - hSession,
201   - LIB3270_NOTIFY_ERROR,
202   - _( "Network error" ),
203   - _( "Unable to get connection state." ),
204   - _( "The system error was %s" ), strerror(err)
205   - );
  204 +
  205 + LIB3270_POPUP popup = {
  206 + .type = LIB3270_NOTIFY_ERROR,
  207 + .title = _( "Network error" ),
  208 + .summary = _( "Unable to get connection state." ),
  209 + .body = body
  210 + };
  211 +
  212 + lib3270_popup(hSession,&popup,0);
  213 +
206 214 return;
207 215 }
208 216 else if(err)
... ...
src/core/paste.c
... ... @@ -44,7 +44,7 @@
44 44 #include <fcntl.h>
45 45  
46 46 #include "3270ds.h"
47   -#include "resources.h"
  47 +//#include "resources.h"
48 48  
49 49 //#include "actionsc.h"
50 50 #include "ansic.h"
... ... @@ -69,7 +69,7 @@
69 69 #include "telnetc.h"
70 70 #include "togglesc.h"
71 71 #include "trace_dsc.h"
72   -#include "utf8c.h"
  72 +//#include "utf8c.h"
73 73 #include "utilc.h"
74 74 #if defined(X3270_DBCS) /*[*/
75 75 #include "widec.h"
... ...
src/core/printer.c
... ... @@ -58,7 +58,7 @@
58 58 #include "3270ds.h"
59 59 #include "appres.h"
60 60 #include "objects.h"
61   -#include "resources.h"
  61 +//#include "resources.h"
62 62  
63 63 #include "charsetc.h"
64 64 #include "ctlrc.h"
... ...
src/core/properties/unsigned.c
... ... @@ -198,3 +198,8 @@ int lib3270_set_uint_property(H3270 *hSession, const char *name, unsigned int va
198 198  
199 199 }
200 200  
  201 +LIB3270_EXPORT unsigned int lib3270_get_task_count(const H3270 *h)
  202 +{
  203 + return h->tasks;
  204 +}
  205 +
... ...
src/core/screen.c
... ... @@ -37,7 +37,7 @@
37 37 #include <internals.h>
38 38 #include <signal.h>
39 39 #include "3270ds.h"
40   -#include "resources.h"
  40 +//#include "resources.h"
41 41 #include "ctlrc.h"
42 42 #include "hostc.h"
43 43 #include "kybdc.h"
... ...
src/core/see.c
... ... @@ -47,9 +47,9 @@
47 47 #include "3270ds.h"
48 48  
49 49 // #include "tablesc.h"
50   -#if !defined(PR3287) /*[*/
51   -#include "utf8c.h"
52   -#endif /*]*/
  50 +//#if !defined(PR3287) /*[*/
  51 +//#include "utf8c.h"
  52 +//#endif /*]*/
53 53 #include "seec.h"
54 54  
55 55 const char *
... ...
src/core/session.c
... ... @@ -67,10 +67,25 @@ void lib3270_session_free(H3270 *h)
67 67 if(!h)
68 68 return;
69 69  
70   - // Terminate session
71 70 if(lib3270_is_connected(h))
  71 + {
  72 + // Connected, disconnect
  73 + lib3270_disconnect(h);
  74 + }
  75 + else if(lib3270_get_connection_state(h) == LIB3270_CONNECTING)
  76 + {
  77 + // Connecting, disconnect
  78 + debug("%s: Stopping while connecting",__FUNCTION__);
72 79 lib3270_disconnect(h);
73 80  
  81 + }
  82 +
  83 + // Do we have pending tasks?
  84 + if(h->tasks)
  85 + {
  86 + lib3270_write_log(h,LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME),"Destroying session with %u active task(s)",h->tasks);
  87 + }
  88 +
74 89 shutdown_toggles(h);
75 90  
76 91 // Release network module
... ... @@ -290,6 +305,7 @@ void lib3270_reset_callbacks(H3270 *hSession)
290 305 hSession->cbk.update_luname = default_update_luname;
291 306 hSession->cbk.update_url = default_update_url;
292 307 hSession->cbk.action = default_action;
  308 + hSession->cbk.reconnect = lib3270_reconnect;
293 309  
294 310 lib3270_set_popup_handler(hSession, NULL);
295 311  
... ... @@ -536,15 +552,19 @@ LIB3270_EXPORT char lib3270_get_session_id(H3270 *hSession)
536 552  
537 553 struct lib3270_session_callbacks * lib3270_get_session_callbacks(H3270 *hSession, const char *revision, unsigned short sz)
538 554 {
539   - if(revision && strcasecmp(revision,"20200803") < 0)
  555 + #define REQUIRED_REVISION "20201117"
  556 +
  557 + if(revision && strcasecmp(revision,REQUIRED_REVISION) < 0)
540 558 {
541   - debug("%s: Revision test was %d",__FUNCTION__,strcasecmp(revision,"20200803"));
542 559 errno = EINVAL;
  560 + lib3270_write_log(hSession,PACKAGE_NAME,"Invalid revision %s when setting callback table",revision);
543 561 return NULL;
544 562 }
545 563  
546 564 if(sz != sizeof(struct lib3270_session_callbacks))
547 565 {
  566 +
  567 + lib3270_write_log(hSession,PACKAGE_NAME,"Invalid callback table (sz=%u expected=%u)",sz,(unsigned int) sizeof(struct lib3270_session_callbacks));
548 568 errno = EINVAL;
549 569 return NULL;
550 570 }
... ...
src/core/telnet.c
... ... @@ -92,8 +92,8 @@
92 92 #include "kybdc.h"
93 93 // #include "macrosc.h"
94 94 #include "popupsc.h"
95   -#include "proxyc.h"
96   -#include "resolverc.h"
  95 +// #include "proxyc.h"
  96 +//#include "resolverc.h"
97 97 #include "statusc.h"
98 98 // #include "tablesc.h"
99 99 #include "telnetc.h"
... ...
src/core/toggles/init.c
... ... @@ -100,7 +100,7 @@ static void toggle_connect(H3270 *hSession, const struct lib3270_toggle *toggle,
100 100 {
101 101 if(tt != LIB3270_TOGGLE_TYPE_INITIAL && lib3270_is_disconnected(hSession) && toggle->value)
102 102 {
103   - if(lib3270_reconnect(hSession,0))
  103 + if(hSession->cbk.reconnect(hSession,0))
104 104 lib3270_write_log(hSession,"3270","Auto-connect fails: %s",strerror(errno));
105 105 }
106 106  
... ...
src/core/trace_ds.c
... ... @@ -53,7 +53,7 @@
53 53 #include <stdarg.h>
54 54 #include <fcntl.h>
55 55 #include "3270ds.h"
56   -#include "resources.h"
  56 +//#include "resources.h"
57 57  
58 58 // #include "charsetc.h"
59 59 #include "ctlrc.h"
... ...
src/include/action_table.h
... ... @@ -1,95 +0,0 @@
1   -/*
2   - * "Software PW3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
3   - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
4   - * aplicativos mainframe. Registro no INPI sob o nome G3270.
5   - *
6   - * Copyright (C) <2008> <Banco do Brasil S.A.>
7   - *
8   - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
9   - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
10   - * Free Software Foundation.
11   - *
12   - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
13   - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
14   - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
15   - * obter mais detalhes.
16   - *
17   - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
18   - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
19   - * St, Fifth Floor, Boston, MA 02110-1301 USA
20   - *
21   - * Este programa está nomeado como actions.h e possui - linhas de código.
22   - *
23   - * Contatos:
24   - *
25   - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
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   - *
30   - */
31   -
32   - #error Deprecated
33   -
34   - /*
35   - * Action call table.
36   - *
37   - * Usually this definitions are used to declare lib3270's action table but,
38   - * if you redefine the creation macros it can be used to build a callback
39   - * table for g_object_connect calls.
40   - *
41   - */
42   -
43   - /* Keyboard actions */
44   - DECLARE_LIB3270_KEY_ACTION( enter, "Send an \"Enter\" action." )
45   -
46   - DECLARE_LIB3270_FKEY_ACTION( pfkey, "" )
47   - DECLARE_LIB3270_FKEY_ACTION( pakey, "" )
48   -
49   - /* Cursor movement */
50   - DECLARE_LIB3270_CURSOR_ACTION( up, "Cursor up 1 position." )
51   - DECLARE_LIB3270_CURSOR_ACTION( down, "Cursor down 1 position." )
52   - DECLARE_LIB3270_CURSOR_ACTION( left, "Cursor left 1 position." )
53   - DECLARE_LIB3270_CURSOR_ACTION( right, "Cursor right 1 position." )
54   -
55   - DECLARE_LIB3270_ACTION( newline, "Cursor to first field on next line or any lines after that." )
56   -
57   - /* Misc actions */
58   - DECLARE_LIB3270_ACTION( kybdreset, "" )
59   - DECLARE_LIB3270_ACTION( clear, "Clear AID key" )
60   - DECLARE_LIB3270_ACTION( eraseinput, "" )
61   -
62   - DECLARE_LIB3270_ACTION( select_field, "" )
63   - DECLARE_LIB3270_ACTION( select_all, "" )
64   - DECLARE_LIB3270_ACTION( unselect, "" )
65   - DECLARE_LIB3270_ACTION( reselect, "" )
66   -
67   - DECLARE_LIB3270_ACTION( eraseeof, "Erase End Of Field Key." )
68   - DECLARE_LIB3270_ACTION( eraseeol, "Erase End Of Line Key." )
69   - DECLARE_LIB3270_ACTION( erase, "" )
70   - DECLARE_LIB3270_ACTION( delete, "" )
71   - DECLARE_LIB3270_ACTION( dup, "DUP key" )
72   - DECLARE_LIB3270_ACTION( fieldmark, "FM key" )
73   -
74   - DECLARE_LIB3270_ACTION( backspace, "3270-style backspace." )
75   -
76   - DECLARE_LIB3270_ACTION( previousword, "Cursor to previous word." )
77   - DECLARE_LIB3270_ACTION( nextword, "Cursor to next unprotected word." )
78   - DECLARE_LIB3270_ACTION( fieldend, "Move the cursor to the first blank after the last nonblank in the field." )
79   -
80   - DECLARE_LIB3270_ACTION( firstfield, "Move to first unprotected field on screen." )
81   - DECLARE_LIB3270_ACTION( nextfield, "" )
82   - DECLARE_LIB3270_ACTION( previousfield, "Tab backward to previous field." )
83   -
84   - DECLARE_LIB3270_ACTION( attn, "ATTN key, per RFC 2355. Sends IP, regardless." )
85   - DECLARE_LIB3270_ACTION( break, "" )
86   - DECLARE_LIB3270_ACTION( pastenext, "" )
87   -
88   - DECLARE_LIB3270_ACTION( deleteword, "Backspaces the cursor until it hits the front of a word (does a ^W)." )
89   - DECLARE_LIB3270_ACTION( deletefield, "Delete field key (does a ^U)." )
90   - DECLARE_LIB3270_ACTION( sysreq, "" )
91   -
92   - DECLARE_LIB3270_ACTION( testpattern, "" )
93   - DECLARE_LIB3270_ACTION( charsettable, "" )
94   -
95   -
src/include/hostc.h
... ... @@ -35,12 +35,7 @@
35 35 * @brief Global declarations for host.c.
36 36 */
37 37  
38   -// #include "api.h"
39   -
40   -
41   -/**
42   - * @brief Signal a state change.
43   - */
  38 + /// @brief Signal a state change.
44 39 LIB3270_INTERNAL void lib3270_st_changed(H3270 *h, LIB3270_STATE tx, int mode);
45 40  
46 41 LIB3270_INTERNAL void host_in3270(H3270 *session, LIB3270_CSTATE);
... ...
src/include/internals.h
... ... @@ -128,16 +128,6 @@ enum iaction {
128 128 IA_IDLE
129 129 };
130 130  
131   -// Version strings
132   -/*
133   -LIB3270_INTERNAL const char * build;
134   -LIB3270_INTERNAL const char * app_defaults_version;
135   -LIB3270_INTERNAL const char * sccsid;
136   -LIB3270_INTERNAL const char * build_rpq_timestamp;
137   -LIB3270_INTERNAL const char * build_rpq_version;
138   -LIB3270_INTERNAL const char * build_rpq_revision;
139   -*/
140   -
141 131 #if defined(X3270_DBCS) /*[*/
142 132 LIB3270_INTERNAL Boolean dbcs;
143 133 #endif /*]*/
... ... @@ -334,41 +324,40 @@ struct _h3270
334 324 // flags
335 325 LIB3270_HOST_TYPE host_type; ///< @brief Host type.
336 326  
337   - int selected : 1; ///< @brief Has selected region?
338   - int has_copy : 1; ///< @brief Has copy?
339   - int rectsel : 1; ///< @brief Selected region is a rectangle ?
340   - int vcontrol : 1; ///< @brief Visible control ?
341   - int modified_sel : 1;
342   - int mono : 1; ///< @brief Forces monochrome display
343   - int m3279 : 1;
344   - int extended : 1; ///< @brief Extended data stream.
345   - int typeahead : 1;
346   - int numeric_lock : 1;
347   - int oerr_lock : 1; ///< @brief If true, operator errors will lock the keyboard.
348   - int unlock_delay : 1; ///< @brief If true the unlock delay feature is enabled. @see lib3270_set_unlock_delay
349   - int auto_reconnect_inprogress : 1;
  327 + unsigned int selected : 1; ///< @brief Has selected region?
  328 + unsigned int has_copy : 1; ///< @brief Has copy?
  329 + unsigned int rectsel : 1; ///< @brief Selected region is a rectangle ?
  330 + unsigned int vcontrol : 1; ///< @brief Visible control ?
  331 + unsigned int modified_sel : 1;
  332 + unsigned int mono : 1; ///< @brief Forces monochrome display
  333 + unsigned int m3279 : 1;
  334 + unsigned int extended : 1; ///< @brief Extended data stream.
  335 + unsigned int typeahead : 1;
  336 + unsigned int numeric_lock : 1;
  337 + unsigned int oerr_lock : 1; ///< @brief If true, operator errors will lock the keyboard.
  338 + unsigned int unlock_delay : 1; ///< @brief If true the unlock delay feature is enabled. @see lib3270_set_unlock_delay
  339 + unsigned int auto_reconnect_inprogress : 1;
350 340 unsigned int colors : 5;
351   - int apl_mode : 1; ///< @brief If true enables APL mode.
352   - int icrnl : 1;
353   - int inlcr : 1;
354   - int onlcr : 1;
355   - int bsd_tm : 1;
356   - int syncing : 1;
357   - int reverse : 1; /**< @brief reverse-input mode */
358   - int dbcs : 1;
359   - int linemode : 1;
360   - int trace_skipping : 1;
361   - int need_tls_follows : 1;
362   - int cut_xfer_in_progress : 1;
363   -// int auto_keymap : 1;
364   - int formatted : 1; /**< @brief Formatted screen flag */
365   - int starting : 1; /**< @brief Is starting (no first screen)? */
  341 + unsigned int apl_mode : 1; ///< @brief If true enables APL mode.
  342 + unsigned int icrnl : 1;
  343 + unsigned int inlcr : 1;
  344 + unsigned int onlcr : 1;
  345 + unsigned int bsd_tm : 1;
  346 + unsigned int syncing : 1;
  347 + unsigned int reverse : 1; ///< @brief reverse-input mode
  348 + unsigned int dbcs : 1;
  349 + unsigned int linemode : 1;
  350 + unsigned int trace_skipping : 1;
  351 + unsigned int need_tls_follows : 1;
  352 + unsigned int cut_xfer_in_progress : 1;
  353 + unsigned int formatted : 1; ///< @brief Formatted screen flag
  354 + unsigned int starting : 1; ///< @brief Is starting (no first screen)?
366 355  
367 356 struct lib3270_toggle
368 357 {
369   - char value; /**< toggle value */
370   - void (*upcall)(H3270 *, const struct lib3270_toggle *, LIB3270_TOGGLE_TYPE); /**< change value */
371   - } toggle[LIB3270_TOGGLE_COUNT];
  358 + char value; ///< toggle value
  359 + void (*upcall)(H3270 *, const struct lib3270_toggle *, LIB3270_TOGGLE_TYPE); ///< change value
  360 + } toggle[LIB3270_TOGGLE_COUNT];
372 361  
373 362 // Network & Termtype
374 363 char * connected_type;
... ... @@ -451,9 +440,9 @@ struct _h3270
451 440 unsigned char default_cs;
452 441 unsigned char default_ic;
453 442 char reply_mode;
454   - int trace_primed : 1;
455   - int ticking : 1;
456   - int mticking : 1;
  443 + unsigned int trace_primed : 1;
  444 + unsigned int ticking : 1;
  445 + unsigned int mticking : 1;
457 446 int crm_nattr;
458 447 unsigned char crm_attr[16];
459 448 unsigned char * zero_buf; /**< @brief Empty buffer, for area clears */
... ... @@ -543,9 +532,9 @@ struct _h3270
543 532 int dft_buffersize; ///< @brief Buffer size (LIMIN, LIMOUT)
544 533  
545 534 // rpq.c
546   - int rpq_complained : 1;
  535 + unsigned int rpq_complained : 1;
547 536 #if !defined(_WIN32)
548   - int omit_due_space_limit : 1;
  537 + unsigned int omit_due_space_limit : 1;
549 538 #endif
550 539  
551 540 char * rpq_warnbuf;
... ... @@ -568,28 +557,28 @@ struct _h3270
568 557 int once_cset;
569 558 int saved_cursor;
570 559  
571   - int held_wrap : 1;
  560 + unsigned int held_wrap : 1;
572 561  
573   - int insert_mode : 1;
574   - int auto_newline_mode : 1;
  562 + unsigned int insert_mode : 1;
  563 + unsigned int auto_newline_mode : 1;
575 564  
576   - int appl_cursor : 1;
577   - int saved_appl_cursor : 1;
  565 + unsigned int appl_cursor : 1;
  566 + unsigned int saved_appl_cursor : 1;
578 567  
579   - int wraparound_mode : 1;
580   - int saved_wraparound_mode : 1;
  568 + unsigned int wraparound_mode : 1;
  569 + unsigned int saved_wraparound_mode : 1;
581 570  
582   - int rev_wraparound_mode : 1;
583   - int saved_rev_wraparound_mode : 1;
  571 + unsigned int rev_wraparound_mode : 1;
  572 + unsigned int saved_rev_wraparound_mode : 1;
584 573  
585   - int allow_wide_mode : 1;
586   - int saved_allow_wide_mode : 1;
  574 + unsigned int allow_wide_mode : 1;
  575 + unsigned int saved_allow_wide_mode : 1;
587 576  
588   - int wide_mode : 1;
589   - int saved_wide_mode : 1;
  577 + unsigned int wide_mode : 1;
  578 + unsigned int saved_wide_mode : 1;
590 579  
591   - int saved_altbuffer : 1;
592   - int ansi_reset : 1; /**< @brief Non zero if the ansi_reset() was called in this session */
  580 + unsigned int saved_altbuffer : 1;
  581 + unsigned int ansi_reset : 1; /**< @brief Non zero if the ansi_reset() was called in this session */
593 582  
594 583 int ansi_ch;
595 584 int cs_to_change;
... ... @@ -663,8 +652,8 @@ struct _h3270
663 652  
664 653 struct
665 654 {
666   - int host : 1; ///< @brief Non zero if host requires SSL.
667   - int download_crl : 1; ///< @brief Non zero to download CRL.
  655 + unsigned int host : 1; ///< @brief Non zero if host requires SSL.
  656 + unsigned int download_crl : 1; ///< @brief Non zero to download CRL.
668 657 LIB3270_SSL_STATE state;
669 658 int error;
670 659 const LIB3270_SSL_MESSAGE * message; ///< @brief Pointer to SSL messages for current state.
... ... @@ -685,6 +674,7 @@ struct _h3270
685 674  
686 675 } listeners;
687 676  
  677 + unsigned int tasks;
688 678  
689 679 };
690 680  
... ...
src/include/kybdc.h
... ... @@ -74,7 +74,7 @@
74 74 #define KYBDLOCK_IS_OERR(hSession) (hSession->kybdlock && !(hSession->kybdlock & ~KL_OERR_MASK))
75 75  
76 76 /* other functions */
77   - LIB3270_INTERNAL void add_xk(KeySym key, KeySym assoc);
  77 + //LIB3270_INTERNAL void add_xk(KeySym key, KeySym assoc);
78 78 LIB3270_INTERNAL void clear_xks(void);
79 79 LIB3270_INTERNAL void do_reset(H3270 *session, Boolean explicit);
80 80  
... ...
src/include/lib3270++.h
... ... @@ -1,437 +0,0 @@
1   -/*
2   - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
3   - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
4   - * aplicativos mainframe. Registro no INPI sob o nome G3270.
5   - *
6   - * Copyright (C) <2008> <Banco do Brasil S.A.>
7   - *
8   - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
9   - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
10   - * Free Software Foundation.
11   - *
12   - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
13   - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
14   - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
15   - * obter mais detalhes.
16   - *
17   - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
18   - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
19   - * St, Fifth Floor, Boston, MA 02110-1301 USA
20   - *
21   - * Este programa está nomeado como lib3270++.h e possui - linhas de código.
22   - *
23   - * Contatos:
24   - *
25   - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
26   - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
27   - *
28   - */
29   -
30   -#ifndef LIB3270_HPP_INCLUDED
31   -
32   - #define LIB3270_HPP_INCLUDED 1
33   -
34   - #include <iostream>
35   - #include <cstdarg>
36   - #include <vector>
37   - #include <functional>
38   - #include <lib3270.h>
39   -
40   - #if defined(_WIN32)
41   -
42   - #define TN3270_PUBLIC __declspec (dllexport)
43   - #define TN3270_PRIVATE
44   -
45   - #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
46   -
47   - #define TN3270_PUBLIC
48   - #define TN3270_PRIVATE
49   -
50   - #elif defined(__GNUC__)
51   -
52   - #define TN3270_PUBLIC __attribute__((visibility("default")))
53   - #define TN3270_PRIVATE __attribute__((visibility("hidden")))
54   -
55   - #else
56   -
57   - #error Unable to set visibility attribute
58   -
59   - #endif
60   -
61   -#ifdef __cplusplus
62   -
63   - #include <string>
64   -
65   - namespace TN3270 {
66   -
67   - class Host;
68   - class Controller;
69   -
70   - #define DEFAULT_TIMEOUT 5
71   -
72   - class TN3270_PUBLIC Event {
73   - public:
74   - enum Type : uint8_t {
75   - All, ///< @brief All events (undefined).
76   - Popup, ///< @brief Popup message.
77   - Trace, ///< @brief Trace message.
78   - Message, ///< @brief Generic message.
79   - Connection ///< @brief Connect/Disconnect event.
80   - };
81   -
82   - private:
83   - Type type;
84   -
85   - protected:
86   - Event(enum Type type);
87   -
88   - public:
89   - virtual ~Event();
90   -
91   - /// @brief Check event type
92   - inline bool is(Event::Type type) const noexcept {
93   - return this->type == type;
94   - }
95   -
96   - /// @brief Check event type
97   - inline bool operator==(Event::Type type) const noexcept {
98   - return this->type == type;
99   - }
100   -
101   - inline operator Event::Type() const noexcept {
102   - return this->type;
103   - }
104   -
105   - /// @brief Get event description.
106   - virtual std::string toString() const = 0;
107   -
108   - };
109   -
110   - enum ProgramMessage : uint8_t {
111   - MESSAGE_NONE = LIB3270_MESSAGE_NONE, ///< @brief No message
112   - MESSAGE_SYSWAIT = LIB3270_MESSAGE_SYSWAIT, ///< @brief --
113   - MESSAGE_TWAIT = LIB3270_MESSAGE_TWAIT, ///< @brief --
114   - MESSAGE_CONNECTED = LIB3270_MESSAGE_CONNECTED, ///< @brief Connected
115   - MESSAGE_DISCONNECTED = LIB3270_MESSAGE_DISCONNECTED, ///< @brief Disconnected from host
116   - MESSAGE_AWAITING_FIRST = LIB3270_MESSAGE_AWAITING_FIRST, ///< @brief --
117   - MESSAGE_MINUS = LIB3270_MESSAGE_MINUS, ///< @brief --
118   - MESSAGE_PROTECTED = LIB3270_MESSAGE_PROTECTED, ///< @brief --
119   - MESSAGE_NUMERIC = LIB3270_MESSAGE_NUMERIC, ///< @brief --
120   - MESSAGE_OVERFLOW = LIB3270_MESSAGE_OVERFLOW, ///< @brief --
121   - MESSAGE_INHIBIT = LIB3270_MESSAGE_INHIBIT, ///< @brief --
122   - MESSAGE_KYBDLOCK = LIB3270_MESSAGE_KYBDLOCK, ///< @brief Keyboard is locked
123   -
124   - MESSAGE_X = LIB3270_MESSAGE_X, ///< @brief --
125   - MESSAGE_RESOLVING = LIB3270_MESSAGE_RESOLVING, ///< @brief Resolving hostname (running DNS query)
126   - MESSAGE_CONNECTING = LIB3270_MESSAGE_CONNECTING ///< @brief Connecting to host
127   -
128   - };
129   -
130   - /// @brief connection state.
131   - enum ConnectionState : uint8_t {
132   - DISCONNECTED = LIB3270_NOT_CONNECTED, ///< @brief disconnected
133   - RESOLVING = LIB3270_RESOLVING, ///< @brief resolving hostname
134   - PENDING = LIB3270_PENDING, ///< @brief connection pending
135   - CONNECTED_INITIAL = LIB3270_CONNECTED_INITIAL, ///< @brief connected, no mode yet
136   - CONNECTED_ANSI = LIB3270_CONNECTED_ANSI, ///< @brief connected in NVT ANSI mode
137   - CONNECTED_3270 = LIB3270_CONNECTED_3270, ///< @brief connected in old-style 3270 mode
138   - CONNECTED_INITIAL_E = LIB3270_CONNECTED_INITIAL_E, ///< @brief connected in TN3270E mode, unnegotiated
139   - CONNECTED_NVT = LIB3270_CONNECTED_NVT, ///< @brief connected in TN3270E mode, NVT mode
140   - CONNECTED_SSCP = LIB3270_CONNECTED_SSCP, ///< @brief connected in TN3270E mode, SSCP-LU mode
141   - CONNECTED_TN3270E = LIB3270_CONNECTED_TN3270E, ///< @brief connected in TN3270E mode, 3270 mode
142   - };
143   -
144   - /// @brief PF Keys
145   - enum PFKey : uint8_t {
146   - PF_1,
147   - PF_2,
148   - PF_3,
149   - PF_4,
150   - PF_5,
151   - PF_6,
152   - PF_7,
153   - PF_8,
154   - PF_9,
155   - PF_10,
156   - PF_11,
157   - PF_12
158   - };
159   -
160   - /// @brief PF Keys
161   - enum PAKey : uint8_t {
162   - PA_1,
163   - PA_2,
164   - PA_3
165   - };
166   -
167   - /// @brief Actions keys
168   - enum Action : uint8_t {
169   - ENTER, ///< Enter key
170   - ERASE,
171   - ERASE_EOF,
172   - ERASE_EOL,
173   - ERASE_INPUT
174   - };
175   -
176   - /// @brief TN3270 Session.
177   - class TN3270_PUBLIC Session {
178   - protected:
179   - Session();
180   -
181   - /// @brief Write information to log file.
182   - void info(const char *fmt, ...) const;
183   -
184   - /// @brief Write warning to log file.
185   - void warning(const char *fmt, ...) const;
186   -
187   - /// @brief Write error to log file.
188   - void error(const char *fmt, ...) const;
189   -
190   - /// @brief Fire event.
191   - void fire(const Event &event);
192   -
193   - public:
194   -
195   - /// @brief Create a tn3270 session.
196   - static Session * create(const char *id = nullptr);
197   -
198   - virtual ~Session();
199   -
200   - // Connect/disconnect
201   - virtual void connect(const char *url) = 0;
202   - virtual void disconnect() = 0;
203   -
204   - // Wait for session state.
205   - virtual void waitForReady(time_t timeout = DEFAULT_TIMEOUT) = 0;
206   -
207   - // Gets
208   - virtual std::string toString(int baddr = 0, size_t len = -1, char lf = '\n') const = 0;
209   - virtual std::string toString(int row, int col, size_t sz, char lf = '\n') const = 0;
210   -
211   - inline operator std::string() const {
212   - return toString();
213   - }
214   -
215   - // Get properties.
216   - virtual void getProperty(const char *name, int &value) const = 0;
217   - virtual void getProperty(const char *name, std::string &value) const = 0;
218   - virtual void getProperty(const char *name, bool &value) const = 0;
219   -
220   - virtual std::string getVersion() const = 0;
221   - virtual std::string getRevision() const = 0;
222   -
223   - virtual ProgramMessage getProgramMessage() const = 0;
224   - inline operator ProgramMessage() const {
225   - return getProgramMessage();
226   - }
227   -
228   - virtual ConnectionState getConnectionState() const = 0;
229   - inline operator ConnectionState() const {
230   - return getConnectionState();
231   - }
232   -
233   - inline bool operator==(ConnectionState state) const noexcept {
234   - return this->getConnectionState() == state;
235   - }
236   -
237   - // Set contents.
238   -
239   - /// @brief Set field at current posicion, jumps to next writable field.
240   - virtual Session & push(const char *text) = 0;
241   - inline Session & push(const std::string &text) {
242   - return push(text.c_str());
243   - }
244   -
245   - /// @brief Set cursor address.
246   - virtual TN3270::Session & setCursorPosition(unsigned short addr) = 0;
247   -
248   - /// @brief Set cursor position.
249   - virtual TN3270::Session & setCursorPosition(unsigned short row, unsigned short col) = 0;
250   -
251   - virtual Session & push(int baddr, const std::string &text) = 0;
252   - virtual Session & push(int row, int col, const std::string &text) = 0;
253   - virtual Session & push(const PFKey key) = 0;
254   - virtual Session & push(const PAKey key) = 0;
255   - virtual Session & push(const Action action) = 0;
256   -
257   - // Get contents.
258   - virtual Session & pop(int baddr, std::string &text) = 0;
259   - virtual Session & pop(int row, int col, std::string &text) = 0;
260   - virtual Session & pop(std::string &text) = 0;
261   -
262   - /// @brief Insert event listener.
263   - void insert(Event::Type type, std::function <void(const Event &event)> listener);
264   -
265   - // Misc
266   -
267   - /// @brief Execute action by name.
268   - virtual Session & action(const char *action_name) = 0;
269   -
270   - };
271   -
272   - /// @brief TN3270 Host
273   - class TN3270_PUBLIC Host : public std::basic_streambuf<char, std::char_traits<char> > {
274   - private:
275   -
276   - /// @brief Connection with the host
277   - Session *session;
278   -
279   - /// @brief How much seconds we wait for the terminal to be ready?
280   - time_t timeout;
281   -
282   - protected:
283   -
284   - /// @brief Writes characters to the associated file from the put area
285   - int sync() override;
286   -
287   - /// @brief Writes characters to the associated output sequence from the put area.
288   - int overflow(int c) override;
289   -
290   - /// @brief Write information to log file.
291   - void info(const char *fmt, ...) const;
292   -
293   - /// @brief Write warning to log file.
294   - void warning(const char *fmt, ...) const;
295   -
296   - /// @brief Write error to log file.
297   - void error(const char *fmt, ...) const;
298   -
299   - public:
300   - Host(const char *id = nullptr, const char *url = nullptr, time_t timeout = DEFAULT_TIMEOUT);
301   - ~Host();
302   -
303   - inline bool operator==(ConnectionState state) const noexcept {
304   - return session->getConnectionState() == state;
305   - }
306   -
307   - void connect(const char *url, bool sync = true);
308   -
309   - inline ProgramMessage getProgramMessage() const {
310   - return session->getProgramMessage();
311   - }
312   -
313   - inline operator bool() const {
314   - return isReady();
315   - }
316   -
317   - inline operator ProgramMessage() const {
318   - return getProgramMessage();
319   - }
320   -
321   - inline ConnectionState getConnectionState() const {
322   - return session->getConnectionState();
323   - }
324   -
325   - bool isReady() const;
326   - bool isConnected() const;
327   -
328   - inline operator ConnectionState() const {
329   - return getConnectionState();
330   - }
331   -
332   - /// @brief Set cursor address.
333   - inline void setCursorPosition(unsigned short addr) {
334   - session->setCursorPosition(addr);
335   - }
336   -
337   - /// @brief Set cursor position.
338   - inline void setCursorPosition(unsigned short row, unsigned short col) {
339   - session->setCursorPosition(row,col);
340   - }
341   -
342   - // Get properties
343   -
344   - /// @brief Get lib3270 version.
345   - inline std::string getVersion() const {
346   - return session->getVersion();
347   - }
348   -
349   - /// @brief Get lib3270 revision.
350   - std::string getRevision() const {
351   - return session->getRevision();
352   - }
353   -
354   - // Set contents.
355   -
356   - /// @brief Set field at current posicion, jumps to next writable field.
357   - inline Host & push(const char *text) {
358   - session->push(text);
359   - return *this;
360   - };
361   -
362   - inline Host & push(const std::string &text) {
363   - session->push(text);
364   - return *this;
365   -
366   - }
367   -
368   - inline Host & push(int baddr, const std::string &text) {
369   - session->push(baddr,text);
370   - return *this;
371   - }
372   -
373   - inline Host & push(int row, int col, const std::string &text) {
374   - session->push(row,col,text);
375   - return *this;
376   - }
377   -
378   - inline Host & push(const PFKey key) {
379   - session->push(key);
380   - return *this;
381   - }
382   -
383   - inline Host & push(const PAKey key) {
384   - session->push(key);
385   - return *this;
386   - }
387   -
388   - Host & push(const Action action);
389   -
390   - // Get contents.
391   -
392   - Host & pop(int baddr, std::string &text);
393   - Host & pop(int row, int col, std::string &text);
394   - Host & pop(std::string &text);
395   -
396   - std::string toString() const;
397   - std::string toString(int baddr, size_t len = -1, char lf = '\n') const;
398   - std::string toString(int row, int col, size_t sz, char lf = '\n') const;
399   -
400   - // Event listeners
401   - inline Host & insert(Event::Type type, std::function <void(const Event &event)> listener) noexcept {
402   - session->insert(type, listener);
403   - return *this;
404   - }
405   -
406   -
407   - };
408   -
409   - }
410   -
411   - TN3270_PUBLIC const char * toCharString(const TN3270::ProgramMessage programMessage) noexcept;
412   - TN3270_PUBLIC const char * toCharString(const TN3270::ConnectionState connectionState) noexcept;
413   -
414   - template <typename T>
415   - inline TN3270_PUBLIC TN3270::Session & operator<<(TN3270::Session& session, const T value) {
416   - return session.push(value);
417   - }
418   -
419   - template <typename T>
420   - inline TN3270_PUBLIC TN3270::Session & operator>>(TN3270::Session& session, const T value) {
421   - return session.pop(value);
422   - }
423   -
424   - template <typename T>
425   - inline TN3270_PUBLIC TN3270::Host & operator<<(TN3270::Host& host, const T value) {
426   - return host.push(value);
427   - }
428   -
429   - inline std::ostream & operator<<(std::ostream &stream, const TN3270::Host& host) {
430   - stream << host.toString();
431   - return stream;
432   - }
433   -
434   -
435   -#endif
436   -
437   -#endif // LIB3270_H_INCLUDED
src/include/lib3270.h
... ... @@ -546,6 +546,10 @@
546 546 *
547 547 * @return zero if reconnect is unavailable (sets errno), non zero if available.
548 548 *
  549 + * @retval ENODATA Invalid or empty hostname.
  550 + * @retval EBUSY Auto reconnect in progress.
  551 + * @retval EISCONN Session is connected.
  552 + *
549 553 */
550 554 LIB3270_EXPORT int lib3270_allow_reconnect(const H3270 *hSession);
551 555  
... ... @@ -557,6 +561,11 @@
557 561 *
558 562 * @return 0 for success, non zero if fails (sets errno).
559 563 *
  564 + * @retval ENODATA Invalid or empty hostname.
  565 + * @retval EBUSY Auto reconnect in progress.
  566 + * @retval EISCONN Session is connected.
  567 + * @retval -1 Unexpected error.
  568 + *
560 569 */
561 570 LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int seconds);
562 571  
... ...
src/include/lib3270/properties.h
... ... @@ -275,6 +275,16 @@
275 275 */
276 276 LIB3270_EXPORT const char * lib3270_service_get_name(const H3270 *h);
277 277  
  278 + /**
  279 + * @brief Check if there's an active task.
  280 + *
  281 + * @param h Session handle.
  282 + *
  283 + * @return Number of background tasks.
  284 + *
  285 + */
  286 + LIB3270_EXPORT unsigned int lib3270_get_task_count(const H3270 *h);
  287 +
278 288 #ifdef __cplusplus
279 289 }
280 290 #endif
... ...
src/include/lib3270/session.h
... ... @@ -79,6 +79,7 @@
79 79  
80 80 int (*action)(H3270 *hSession, const char *name);
81 81  
  82 + int (*reconnect)(H3270 *hSession,int seconds);
82 83 };
83 84  
84 85 /**
... ...
src/include/localdefs.h
... ... @@ -33,50 +33,23 @@
33 33 /* These first definitions were cribbed from X11 -- but no X code is used. */
34 34 #define False 0
35 35 #define True 1
36   -//typedef void *XtPointer;
37   -// typedef void *Widget;
38   -// typedef void *XEvent;
  36 +
39 37 #ifdef __APPLE__
40 38 typedef unsigned char Boolean;
41 39 #else
42 40 typedef char Boolean;
43 41 #endif
  42 +
44 43 typedef char *String;
45   -// typedef unsigned int Cardinal;
46   -typedef unsigned long KeySym;
  44 +//typedef unsigned long KeySym;
47 45 #define Bool int
48 46  
49   -/*
50   -typedef void (*XtActionProc)(
51   - Widget // widget,
52   - XEvent* // event,
53   - String* // params,
54   - Cardinal* // num_param
55   -);
56   -*/
57   -
58   -/*
59   -typedef struct _XtActionsRec{
60   - String string;
61   - XtActionProc proc;
62   -} XtActionsRec;
63   -*/
64   -
65   -#define XtNumber(n) (sizeof(n)/sizeof((n)[0]))
66   -#define NoSymbol 0L
  47 +//#define XtNumber(n) (sizeof(n)/sizeof((n)[0]))
  48 +//#define NoSymbol 0L
67 49  
68 50 /* These are local functions with similar semantics to X functions. */
69   -
70   -// void * Malloc(size_t);
71   -// void Free(void *);
72   -// void * Calloc(size_t, size_t);
73   -// void * Realloc(void *, size_t);
74   -
75   -// #define Malloc(x) lib3270_malloc(x)
76   -// #define Free(x) lib3270_free(x)
77 51 #define Calloc(e,n) lib3270_calloc(e,n,NULL)
78 52 #define Realloc(x,n) lib3270_realloc(x,n)
79 53  
80 54 #define NewString(x) strdup(x)
81   -//extern char *NewString(const char *);
82 55  
... ...
src/include/networking.h
... ... @@ -142,7 +142,7 @@
142 142 /// @retval 0 The session is offline.
143 143 int (*is_connected)(const H3270 *hSession);
144 144  
145   - /// @brief get socket name.
  145 + /// @brief Get socket name.
146 146 ///
147 147 /// @return On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
148 148 ///
... ... @@ -150,6 +150,14 @@
150 150 /// @retval -1 Error (errno is set).
151 151 int (*getsockname)(const H3270 *hSession, struct sockaddr *addr, socklen_t *addrlen);
152 152  
  153 + /// @brief Get name of connected peer socket.
  154 + ///
  155 + /// @return On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
  156 + ///
  157 + /// @retval 0 Success.
  158 + /// @retval -1 Error (errno is set).
  159 + int (*getpeername)(const H3270 *hSession, struct sockaddr *addr, socklen_t *addrlen);
  160 +
153 161 /// @brief Set socket options.
154 162 int (*setsockopt)(H3270 *hSession, int level, int optname, const void *optval, size_t optlen);
155 163  
... ...
src/include/proxyc.h
... ... @@ -1,22 +0,0 @@
1   -/*
2   - * Copyright 2007 by Paul Mattes.
3   - * Permission to use, copy, modify, and distribute this software and its
4   - * documentation for any purpose and without fee is hereby granted,
5   - * provided that the above copyright notice appear in all copies and that
6   - * both that copyright notice and this permission notice appear in
7   - * supporting documentation.
8   - *
9   - * x3270, c3270, wc3270, s3270 and tcl3270 are distributed in the hope that
10   - * they will be useful, but WITHOUT ANY WARRANTY; without even the implied
11   - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   - * file LICENSE for more details.
13   - */
14   -
15   -/*
16   - * proxyc.h
17   - * Declarations for proxy.c.
18   - */
19   -
20   -LIB3270_INTERNAL int proxy_setup(H3270 *session, char **phost, char **pport);
21   -LIB3270_INTERNAL int proxy_negotiate(H3270 *session, int type, int fd, char *host, unsigned short port);
22   -LIB3270_INTERNAL const char * proxy_type_name(int type);
src/include/resolverc.h
... ... @@ -1,22 +0,0 @@
1   -/*
2   - * Copyright 2007 by Paul Mattes.
3   - * Permission to use, copy, modify, and distribute this software and its
4   - * documentation for any purpose and without fee is hereby granted,
5   - * provided that the above copyright notice appear in all copies and that
6   - * both that copyright notice and this permission notice appear in
7   - * supporting documentation.
8   - *
9   - * x3270, c3270, wc3270, s3270, tcl3270, pr3287 and wpr3287 are distributed in
10   - * the hope that they will be useful, but WITHOUT ANY WARRANTY; without even
11   - * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12   - * See the file LICENSE for more details.
13   - */
14   -
15   -/*
16   - * resolverc.h
17   - * Hostname resolution.
18   - */
19   -
20   -// LIB3270_INTERNAL int resolve_host_and_port(H3270 *session, const char *host, char *portname, unsigned short *pport,struct sockaddr *sa, socklen_t *sa_len, char *errmsg, int em_size);
21   -
22   -
src/include/resources.h
... ... @@ -18,6 +18,8 @@
18 18 * x3270/c3270/s3270/tcl3270 resource and option names.
19 19 */
20 20  
  21 +#error Deprecated
  22 +
21 23 /* Resources. */
22 24 #define ResActiveIcon "activeIcon"
23 25 #define ResAdVersion "adVersion"
... ...
src/include/shlobj_missing.h
1 1 /* IShellLinkDataList, missing from mingw's <shlobj.h>. */
2 2  
  3 +#error Deprecated
  4 +
3 5 LIB3270_INTERNAL const GUID IID_IShellLinkDataList;
4 6  
5 7 #define INTERFACE IShellLinkDataList
... ...
src/include/statusc.h
... ... @@ -30,9 +30,6 @@
30 30 LIB3270_INTERNAL void status_compose(int on, unsigned char c, enum keytype keytype);
31 31 LIB3270_INTERNAL void status_ctlr_done(H3270 *session);
32 32  
33   -// LIB3270_INTERNAL void status_timing(H3270 *session, struct timeval *t0, struct timeval *t1);
34   -// LIB3270_INTERNAL void status_untiming(H3270 *session);
35   -
36 33 LIB3270_INTERNAL void status_lu(H3270 *session, const char *);
37 34 LIB3270_INTERNAL void status_oerr(H3270 *session, int error_type);
38 35 LIB3270_INTERNAL void status_reset(H3270 *session);
... ...
src/include/telnetc.h
... ... @@ -62,4 +62,3 @@ LIB3270_INTERNAL void space3270out(H3270 *hSession, int n);
62 62 #define trace_netdata(direction, buf, len) /* */
63 63 #endif // X3270_TRACE
64 64  
65   -// LIB3270_INTERNAL int net_getsockname(const H3270 *h3270, void *buf, int *len);
... ...
src/include/utf8c.h
... ... @@ -18,15 +18,17 @@
18 18 * UTF-8 conversions
19 19 */
20 20  
  21 + /*
21 22 enum ulfail {
22   - ULFAIL_NOUTF8, /* not using UTF-8 */
23   - ULFAIL_INCOMPLETE, /* incomplete sequence */
24   - ULFAIL_INVALID /* invalid sequence */
  23 + ULFAIL_NOUTF8, // not using UTF-8
  24 + ULFAIL_INCOMPLETE, // incomplete sequence
  25 + ULFAIL_INVALID // invalid sequence
25 26 };
  27 +*/
26 28  
27 29 // LIB3270_INTERNAL char *locale_codeset;
28 30  
29 31 // LIB3270_INTERNAL void set_codeset(char *codeset_name);
30 32 // LIB3270_INTERNAL Boolean utf8_set_display_charsets(char *cslist, char *csname);
31   - LIB3270_INTERNAL char *utf8_expand(unsigned char c);
32   - LIB3270_INTERNAL unsigned char utf8_lookup(char *mbs, enum ulfail *fail, int *consumed);
  33 +// LIB3270_INTERNAL char *utf8_expand(unsigned char c);
  34 +// LIB3270_INTERNAL unsigned char utf8_lookup(char *mbs, enum ulfail *fail, int *consumed);
... ...
src/include/xl.h
... ... @@ -17,9 +17,11 @@
17 17 * DBCS translation table structure.
18 18 */
19 19  
  20 + /*
20 21 typedef struct {
21 22 unsigned n;
22 23 unsigned short *data;
23 24 } xl_t;
24 25  
25 26 #define XL_SIZE(e) ((sizeof(e)/sizeof(e[0]))/3)
  27 +*/
... ...
src/mkactions/mkactions.c
... ... @@ -1,215 +0,0 @@
1   -/*
2   - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
3   - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
4   - * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob o nome G3270.
5   - *
6   - * Copyright (C) <2008> <Banco do Brasil S.A.>
7   - *
8   - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
9   - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
10   - * Free Software Foundation.
11   - *
12   - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
13   - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
14   - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
15   - * obter mais detalhes.
16   - *
17   - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
18   - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
19   - * St, Fifth Floor, Boston, MA 02110-1301 USA
20   - *
21   - * Este programa está nomeado como mkfb.c e possui - linhas de código.
22   - *
23   - * Contatos:
24   - *
25   - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
26   - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
27   - *
28   - */
29   -
30   -/**
31   - * @brief Utility to create the actions definition files.
32   - *
33   - */
34   -
35   -#include <getopt.h>
36   -#include <stdio.h>
37   -
38   -#define DECLARE_LIB3270_ACTION( name, description ) \
39   - { \
40   - description, \
41   - NULL, \
42   - "LIB3270_EXPORT int lib3270_" # name "(H3270 *hSession);" \
43   - },
44   -
45   -#define DECLARE_LIB3270_CLEAR_SELECTION_ACTION( name, description ) \
46   - { \
47   - description, \
48   - NULL, \
49   - "LIB3270_EXPORT int lib3270_" # name "(H3270 *hSession);" \
50   - },
51   -
52   -#define DECLARE_LIB3270_KEY_ACTION( name, description ) \
53   - { \
54   - description, \
55   - NULL, \
56   - "LIB3270_EXPORT int lib3270_" # name "(H3270 *hSession);" \
57   - },
58   -
59   -#define DECLARE_LIB3270_CURSOR_ACTION( name, description ) \
60   - { \
61   - description, \
62   - NULL, \
63   - "LIB3270_EXPORT int lib3270_cursor_" # name "(H3270 *hSession);" \
64   - },
65   -
66   -#define DECLARE_LIB3270_FKEY_ACTION( name, description ) \
67   - { \
68   - description, \
69   - "keycode\tNumber of the " #name " to activate.", \
70   - "LIB3270_EXPORT int lib3270_" # name "(H3270 *hSession, int keycode);" \
71   - },
72   -
73   -
74   -static struct {
75   - const char *description;
76   - const char *args;
77   - const char *prototype;
78   -} actions[] = {
79   - #include <lib3270/action_table.h>
80   -};
81   -
82   -
83   -int main(int argc, char *argv[]) {
84   -
85   - enum _format {
86   - FORMAT_HEADER
87   - } format = FORMAT_HEADER;
88   -
89   - size_t ix;
90   -
91   - char * outfile = "actions.h";
92   -
93   - //#pragma GCC diagnostic push
94   - //#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
95   - static struct option options[] = {
96   - { "outfile", required_argument, 0, 'o' },
97   - { 0, 0, 0, 0}
98   -
99   - };
100   - //#pragma GCC diagnostic pop
101   -
102   - int long_index =0;
103   - int opt;
104   - while((opt = getopt_long(argc, argv, "o:", options, &long_index )) != -1) {
105   -
106   - switch(opt) {
107   - case 'o': // Pidfile
108   - outfile = optarg;
109   - break;
110   - }
111   -
112   - }
113   -
114   - FILE *out = fopen(outfile,"w");
115   -
116   - fprintf(out,"%s\n",
117   - "/*\n"
118   - " * Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270\n"
119   - " * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a\n"
120   - " * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob o nome G3270.\n"
121   - " *\n"
122   - " * Copyright (C) <2008> <Banco do Brasil S.A.>\n"
123   - " *\n"
124   - " * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob\n"
125   - " * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela\n"
126   - " * Free Software Foundation.\n"
127   - " *\n"
128   - " * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER\n"
129   - " * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO\n"
130   - " * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para\n"
131   - " * obter mais detalhes.\n"
132   - " *\n"
133   - " * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este\n"
134   - " * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin\n"
135   - " * St, Fifth Floor, Boston, MA 02110-1301 USA\n"
136   - " *\n"
137   - " * Contatos:\n"
138   - " *\n"
139   - " * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)\n"
140   - " * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)\n"
141   - " *\n"
142   - " */\n\n"
143   - "#ifndef LIB3270_ACTIONS_H_INCLUDED\n"
144   - "\n"
145   - "\n #define LIB3270_ACTIONS_H_INCLUDED 1\n\n"
146   - "#ifdef __cplusplus\n"
147   - " extern \"C\" {\n"
148   - "#endif\n\n"
149   - );
150   -
151   - if(format == FORMAT_HEADER)
152   - {
153   -
154   - for(ix = 0; ix < (sizeof(actions)/sizeof(actions[0])); ix++)
155   - {
156   - fprintf(out,
157   - "/**\n"
158   - " *\n"
159   - " * @brief %s\n"
160   - " *\n"
161   - " * @param hSession\tTN3270 Session handle.\n",
162   - actions[ix].description
163   - );
164   -
165   - if(actions[ix].args) {
166   - fprintf(out," * @param %s\n", actions[ix].args);
167   - }
168   -
169   - fprintf(out,
170   - " *\n"
171   - " * @return 0 if Ok, non zero if not (sets errno)\n"
172   - );
173   -
174   - fprintf(out," *\n */\n %s\n\n",actions[ix].prototype);
175   - }
176   -
177   - fprintf(out,
178   - "\n"
179   - "\n typedef struct _lib3270_action_entry"
180   - "\n {"
181   - "\n const char *name;"
182   - "\n const char *description;"
183   - "\n int (*call)(H3270 *hSession);"
184   - "\n } LIB3270_ACTION_ENTRY;"
185   - "\n\n"
186   - "/**\n"
187   - " *\n"
188   - " * @brief Get lib3270 action table.\n"
189   - " *\n"
190   - " * @return Array with all the supported actions.\n"
191   - " */\n"
192   - " LIB3270_EXPORT const LIB3270_ACTION_ENTRY * lib3270_get_actions();\n"
193   - "\n"
194   - "/**\n"
195   - " *\n"
196   - " * @brief Call lib3270 action by name.\n"
197   - " *\n"
198   - " * @param hSession\tTN3270 Session handle.\n"
199   - " * @param name\tName of the action to call.\n"
200   - " *\n"
201   - " */\n"
202   - " LIB3270_EXPORT int lib3270_action(H3270 *hSession, const char *name);\n\n"
203   - "#ifdef __cplusplus\n"
204   - " }\n"
205   - "#endif\n"
206   - "\n#endif // LIB3270_ACTIONS_H_INCLUDED"
207   - );
208   - }
209   -
210   - fclose(out);
211   -
212   - return 0;
213   -}
214   -
215   -
src/mkactions/mkactions.cbp
... ... @@ -1,45 +0,0 @@
1   -<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2   -<CodeBlocks_project_file>
3   - <FileVersion major="1" minor="6" />
4   - <Project>
5   - <Option title="LIB3270 Action Table Generator" />
6   - <Option pch_mode="2" />
7   - <Option compiler="gcc" />
8   - <Build>
9   - <Target title="Debug">
10   - <Option output=".bin/Debug/mkactions" prefix_auto="1" extension_auto="1" />
11   - <Option object_output=".obj/Debug/" />
12   - <Option type="1" />
13   - <Option compiler="gcc" />
14   - <Compiler>
15   - <Add option="-g" />
16   - </Compiler>
17   - </Target>
18   - <Target title="Release">
19   - <Option output=".bin/Release/mkactions" prefix_auto="1" extension_auto="1" />
20   - <Option object_output=".obj/Release/" />
21   - <Option type="1" />
22   - <Option compiler="gcc" />
23   - <Compiler>
24   - <Add option="-O2" />
25   - </Compiler>
26   - <Linker>
27   - <Add option="-s" />
28   - </Linker>
29   - </Target>
30   - </Build>
31   - <Compiler>
32   - <Add option="-Wall" />
33   - <Add directory="../../include" />
34   - </Compiler>
35   - <Unit filename="mkactions.c">
36   - <Option compilerVar="CC" />
37   - </Unit>
38   - <Extensions>
39   - <code_completion />
40   - <envvars />
41   - <debugger />
42   - <lib_finder disable_auto="1" />
43   - </Extensions>
44   - </Project>
45   -</CodeBlocks_project_file>
src/network_modules/default/main.c
... ... @@ -92,6 +92,10 @@ static int unsecure_network_getsockname(const H3270 *hSession, struct sockaddr *
92 92 return getsockname(hSession->network.context->sock, addr, addrlen);
93 93 }
94 94  
  95 +static int unsecure_network_getpeername(const H3270 *hSession, struct sockaddr *addr, socklen_t *addrlen) {
  96 + return getpeername(hSession->network.context->sock, addr, addrlen);
  97 +}
  98 +
95 99 static void * unsecure_network_add_poll(H3270 *hSession, LIB3270_IO_FLAG flag, void(*call)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata) {
96 100 return lib3270_add_poll_fd(hSession,hSession->network.context->sock,flag,call,userdata);
97 101 }
... ... @@ -166,6 +170,7 @@ void lib3270_set_default_network_module(H3270 *hSession) {
166 170 .non_blocking = unsecure_network_non_blocking,
167 171 .is_connected = unsecure_network_is_connected,
168 172 .getsockname = unsecure_network_getsockname,
  173 + .getpeername = unsecure_network_getpeername,
169 174 .setsockopt = unsecure_network_setsockopt,
170 175 .getsockopt = unsecure_network_getsockopt,
171 176 .reset = unsecure_network_reset
... ...
src/network_modules/openssl/crl.c
... ... @@ -27,7 +27,7 @@
27 27 *
28 28 */
29 29  
30   -/// @brief Get CRL infro from X509 cert.
  30 +/// @brief Get CRL info from X509 cert.
31 31 ///
32 32 /// References:
33 33 ///
... ... @@ -35,6 +35,7 @@
35 35  
36 36  
37 37 #include "private.h"
  38 +#include <utilc.h>
38 39  
39 40 /*--[ Implement ]------------------------------------------------------------------------------------*/
40 41  
... ... @@ -79,7 +80,13 @@ LIB3270_STRING_ARRAY * lib3270_openssl_get_crls_from_peer(H3270 *hSession, X509
79 80 #endif // OpenSSL 1.1.0+
80 81  
81 82 if(data && length > 0)
82   - lib3270_string_array_append_with_length(uris,(char *) data, (size_t) length);
  83 + {
  84 + lib3270_autoptr(char) uri = lib3270_malloc( ((size_t) length) + 1);
  85 + strncpy(uri,(char *) data, (size_t) length);
  86 +
  87 + lib3270_autoptr(char) unescaped = lib3270_unescape(uri);
  88 + lib3270_string_array_append(uris,unescaped);
  89 + }
83 90  
84 91 }
85 92  
... ...
src/network_modules/openssl/main.c
... ... @@ -186,6 +186,10 @@ static int openssl_network_getsockname(const H3270 *hSession, struct sockaddr *a
186 186 return getsockname(hSession->network.context->sock, addr, addrlen);
187 187 }
188 188  
  189 +static int openssl_network_getpeername(const H3270 *hSession, struct sockaddr *addr, socklen_t *addrlen) {
  190 + return getpeername(hSession->network.context->sock, addr, addrlen);
  191 +}
  192 +
189 193 static void * openssl_network_add_poll(H3270 *hSession, LIB3270_IO_FLAG flag, void(*call)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata) {
190 194 return lib3270_add_poll_fd(hSession,hSession->network.context->sock,flag,call,userdata);
191 195 }
... ... @@ -346,6 +350,7 @@ void lib3270_set_libssl_network_module(H3270 *hSession) {
346 350 .non_blocking = openssl_network_non_blocking,
347 351 .is_connected = openssl_network_is_connected,
348 352 .getsockname = openssl_network_getsockname,
  353 + .getpeername = openssl_network_getpeername,
349 354 .setsockopt = openssl_network_setsockopt,
350 355 .getsockopt = openssl_network_getsockopt,
351 356 .getcert = openssl_network_getcert,
... ...
src/network_modules/openssl/start.c
... ... @@ -34,6 +34,7 @@
34 34  
35 35 #include "private.h"
36 36 #include <lib3270/properties.h>
  37 + #include <utilc.h>
37 38  
38 39 static int import_crl(H3270 *hSession, SSL_CTX * ssl_ctx, LIB3270_NET_CONTEXT * context, const char *url) {
39 40  
... ... @@ -103,25 +104,26 @@
103 104  
104 105 if(X509_STORE_add_crl(store, x509_crl)) {
105 106 trace_ssl(hSession,"CRL was added to context cert store\n");
106   - } else {
107   - trace_ssl(hSession,"CRL was not added to context cert store\n");
  107 + return 0;
108 108 }
109 109  
110   - return 0;
  110 + trace_ssl(hSession,"CRL was not added to context cert store\n");
  111 +
  112 + return -1;
111 113  
112 114 }
113 115  
114   - static void download_crl_from_peer(H3270 *hSession, SSL_CTX * ctx_context, LIB3270_NET_CONTEXT * context, X509 *peer) {
  116 + static int download_crl_from_peer(H3270 *hSession, SSL_CTX * ctx_context, LIB3270_NET_CONTEXT * context, X509 *peer) {
115 117  
116 118 debug("%s peer=%p",__FUNCTION__,(void *) peer);
117 119  
118 120 if(!peer)
119   - return;
  121 + return -1;
120 122  
121 123 lib3270_autoptr(LIB3270_STRING_ARRAY) uris = lib3270_openssl_get_crls_from_peer(hSession, peer);
122 124 if(!uris) {
123 125 trace_ssl(hSession,"Can't get distpoints from peer certificate\n");
124   - return;
  126 + return -1;
125 127 }
126 128  
127 129 size_t ix;
... ... @@ -134,11 +136,11 @@
134 136  
135 137 if(!import_crl(hSession,ctx_context,context,uris->str[ix])) {
136 138 trace_ssl(hSession,"Got CRL from %s\n",uris->str[ix]);
137   - return;
  139 + return 0;
138 140 }
139 141  
140 142 }
141   - return;
  143 + return -1;
142 144  
143 145 }
144 146  
... ... @@ -152,10 +154,9 @@
152 154 if(strncasecmp(prefer,uris->str[ix],length))
153 155 continue;
154 156  
155   - debug("Trying %s",uris->str[ix]);
156 157 if(!import_crl(hSession,ctx_context,context,uris->str[ix])) {
157 158 trace_ssl(hSession,"Got CRL from %s\n",uris->str[ix]);
158   - return;
  159 + return 0;
159 160 }
160 161  
161 162 }
... ... @@ -168,13 +169,34 @@
168 169  
169 170 if(!import_crl(hSession,ctx_context,context,uris->str[ix])) {
170 171 trace_ssl(hSession,"Got CRL from %s\n",uris->str[ix]);
171   - return;
  172 + return 0;
172 173 }
173 174  
174 175 }
175 176  
  177 + return -1;
  178 +
176 179 }
177 180  
  181 +int x509_store_ctx_error_callback(int ok, X509_STORE_CTX GNUC_UNUSED(*ctx))
  182 +{
  183 + debug("%s(%d)",__FUNCTION__,ok);
  184 +
  185 +/*
  186 + 55 {
  187 + 56 if (!ok) {
  188 + 57 Category::getInstance("OpenSSL").error(
  189 + 58 "path validation failure at depth(%d): %s",
  190 + 59 X509_STORE_CTX_get_error_depth(ctx),
  191 + 60 X509_verify_cert_error_string(X509_STORE_CTX_get_error(ctx))
  192 + 61 );
  193 + 62 }
  194 + 63 return ok;
  195 + 64 }
  196 +*/
  197 + return ok;
  198 +}
  199 +
178 200 int openssl_network_start_tls(H3270 *hSession) {
179 201  
180 202 SSL_CTX * ctx_context = (SSL_CTX *) lib3270_openssl_get_context(hSession);
... ... @@ -199,7 +221,8 @@
199 221  
200 222 SSL_set_ex_data(context->con,lib3270_openssl_get_ex_index(hSession),(char *) hSession);
201 223 // SSL_set_verify(context->con, SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL);
202   - SSL_set_verify(context->con, 0, NULL);
  224 +// SSL_set_verify(context->con, SSL_VERIFY_PEER, NULL);
  225 + SSL_set_verify(context->con, SSL_VERIFY_NONE, NULL);
203 226  
204 227 if(SSL_set_fd(context->con, context->sock) != 1)
205 228 {
... ... @@ -295,13 +318,40 @@
295 318  
296 319 // CRL download is enabled and verification has failed; look for CRL file.
297 320  
  321 +
298 322 trace_ssl(hSession,"CRL Validation has failed, requesting CRL download\n");
299 323 set_ssl_state(hSession,LIB3270_SSL_VERIFYING);
300 324  
  325 + int rc_download = -1;
  326 +
301 327 if(context->crl.url) {
302   - import_crl(hSession, ctx_context,context,context->crl.url);
  328 + rc_download = import_crl(hSession, ctx_context,context,context->crl.url);
303 329 } else {
304   - download_crl_from_peer(hSession, ctx_context, context, peer);
  330 + rc_download = download_crl_from_peer(hSession, ctx_context, context, peer);
  331 + }
  332 +
  333 + debug("Download rc=%d",rc_download);
  334 +
  335 + if(!rc_download)
  336 + {
  337 + // Got CRL, verify it!
  338 + // Reference: https://stackoverflow.com/questions/10510850/how-to-verify-the-certificate-for-the-ongoing-ssl-session
  339 +
  340 + X509_STORE_CTX *csc = X509_STORE_CTX_new();
  341 + X509_STORE_CTX_set_verify_cb(csc, x509_store_ctx_error_callback);
  342 + X509_STORE_CTX_init(csc, SSL_CTX_get_cert_store(ctx_context), peer, NULL);
  343 +
  344 + if(X509_verify_cert(csc) != 1)
  345 + rv = X509_STORE_CTX_get_error(csc);
  346 + else
  347 + rv = X509_V_OK;
  348 +
  349 + trace_ssl(hSession, "X509_verify_cert error code was %d\n", rv);
  350 +
  351 + SSL_set_verify_result(context->con, rv);
  352 +
  353 + X509_STORE_CTX_free(csc);
  354 +
305 355 }
306 356  
307 357 }
... ... @@ -313,6 +363,7 @@
313 363  
314 364 // Get validation message.
315 365 hSession->ssl.message = lib3270_openssl_message_from_id(verify_result);
  366 + debug("Verify message: %s",hSession->ssl.message->summary);
316 367  
317 368 // Trace cypher
318 369 if(lib3270_get_toggle(hSession,LIB3270_TOGGLE_SSL_TRACE))
... ... @@ -331,7 +382,7 @@
331 382  
332 383 // Check results.
333 384 if(hSession->ssl.message)
334   - trace_ssl(hSession,"%s",hSession->ssl.message->summary);
  385 + trace_ssl(hSession,"%s\n",hSession->ssl.message->summary);
335 386 else
336 387 trace_ssl(hSession,"TLS/SSL verify result was %ld\n", verify_result);
337 388  
... ...
src/network_modules/tools.c
... ... @@ -263,3 +263,16 @@ int lib3270_socket_set_non_blocking(H3270 *hSession, int sock, const unsigned ch
263 263  
264 264 return EINVAL;
265 265 }
  266 +
  267 + LIB3270_EXPORT int lib3270_getpeername(H3270 *hSession, struct sockaddr *addr, socklen_t *addrlen)
  268 + {
  269 + FAIL_IF_NOT_ONLINE(hSession);
  270 + return hSession->network.module->getpeername(hSession, addr, addrlen);
  271 + }
  272 +
  273 + LIB3270_EXPORT int lib3270_getsockname(H3270 *hSession, struct sockaddr *addr, socklen_t *addrlen)
  274 + {
  275 + FAIL_IF_NOT_ONLINE(hSession);
  276 + return hSession->network.module->getsockname(hSession, addr, addrlen);
  277 + }
  278 +
... ...