Commit 69af036ae8c489595d3b58780ec2bb70d1321fc8
Committed by
GitHub
Exists in
master
and in
2 other branches
Merge pull request #16 from PerryWerneck/develop
Adjustments in FT API, fixing LGTM warning.
Showing
16 changed files
with
329 additions
and
149 deletions
Show diff stats
.gitignore
lib3270.cbp
@@ -98,6 +98,9 @@ | @@ -98,6 +98,9 @@ | ||
98 | <Unit filename="src/core/ft/ftmessages.c"> | 98 | <Unit filename="src/core/ft/ftmessages.c"> |
99 | <Option compilerVar="CC" /> | 99 | <Option compilerVar="CC" /> |
100 | </Unit> | 100 | </Unit> |
101 | + <Unit filename="src/core/ft/set.c"> | ||
102 | + <Option compilerVar="CC" /> | ||
103 | + </Unit> | ||
101 | <Unit filename="src/core/host.c"> | 104 | <Unit filename="src/core/host.c"> |
102 | <Option compilerVar="CC" /> | 105 | <Option compilerVar="CC" /> |
103 | </Unit> | 106 | </Unit> |
src/core/actions/table.c
@@ -542,7 +542,7 @@ | @@ -542,7 +542,7 @@ | ||
542 | .name = "erase-input", | 542 | .name = "erase-input", |
543 | .type = LIB3270_ACTION_TYPE_GENERIC, | 543 | .type = LIB3270_ACTION_TYPE_GENERIC, |
544 | 544 | ||
545 | - .keys = NULL, | 545 | + .keys = "", |
546 | .icon = "edit-clear", | 546 | .icon = "edit-clear", |
547 | .label = N_("Erase input"), | 547 | .label = N_("Erase input"), |
548 | .summary = N_("Erase all unprotected fields"), | 548 | .summary = N_("Erase all unprotected fields"), |
@@ -598,7 +598,7 @@ | @@ -598,7 +598,7 @@ | ||
598 | .name = "clear", | 598 | .name = "clear", |
599 | .type = LIB3270_ACTION_TYPE_GENERIC, | 599 | .type = LIB3270_ACTION_TYPE_GENERIC, |
600 | 600 | ||
601 | - .keys = NULL, | 601 | + .keys = "<Alt>F1", |
602 | .icon = "edit-clear-all", | 602 | .icon = "edit-clear-all", |
603 | .label = N_("Clear"), | 603 | .label = N_("Clear"), |
604 | .summary = N_( "Clear AID key" ), | 604 | .summary = N_( "Clear AID key" ), |
src/core/ft/ft.c
@@ -258,24 +258,16 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | @@ -258,24 +258,16 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | ||
258 | H3270FT * ftHandle = (H3270FT *) session->ft; | 258 | H3270FT * ftHandle = (H3270FT *) session->ft; |
259 | FILE * ft_local_file = NULL; | 259 | FILE * ft_local_file = NULL; |
260 | int f; | 260 | int f; |
261 | -// unsigned long length = 0L; | ||
262 | 261 | ||
263 | -// trace("%s(%s)",__FUNCTION__,local); | ||
264 | if(!lib3270_is_connected(session)) | 262 | if(!lib3270_is_connected(session)) |
265 | - { | ||
266 | return ft_creation_failed(session,ENOTCONN,message,_( "Disconnected from host." )); | 263 | return ft_creation_failed(session,ENOTCONN,message,_( "Disconnected from host." )); |
267 | - } | ||
268 | 264 | ||
269 | if(ftHandle) | 265 | if(ftHandle) |
270 | - { | ||
271 | return ft_creation_failed(session,EBUSY,message,_( "File transfer is already active in this session." )); | 266 | return ft_creation_failed(session,EBUSY,message,_( "File transfer is already active in this session." )); |
272 | - } | ||
273 | 267 | ||
274 | // Check remote file | 268 | // Check remote file |
275 | if(!*remote) | 269 | if(!*remote) |
276 | - { | ||
277 | return ft_creation_failed(session,EINVAL,message,_( "The remote file name is invalid." )); | 270 | return ft_creation_failed(session,EINVAL,message,_( "The remote file name is invalid." )); |
278 | - } | ||
279 | 271 | ||
280 | // Open local file | 272 | // Open local file |
281 | #ifdef _WIN32 | 273 | #ifdef _WIN32 |
@@ -285,26 +277,24 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | @@ -285,26 +277,24 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | ||
285 | #endif // _WIN32 | 277 | #endif // _WIN32 |
286 | 278 | ||
287 | if(!ft_local_file) | 279 | if(!ft_local_file) |
288 | - { | ||
289 | return ft_creation_failed(session,errno,message,strerror(errno)); | 280 | return ft_creation_failed(session,errno,message,strerror(errno)); |
290 | - } | ||
291 | 281 | ||
292 | // Set options | 282 | // Set options |
293 | - session->dft_buffersize = dft; | ||
294 | - set_dft_buffersize(session); | 283 | + lib3270_set_dft_buffersize(session, dft); |
295 | 284 | ||
296 | // Create & Initialize ft control structure. | 285 | // Create & Initialize ft control structure. |
297 | ftHandle = lib3270_malloc(sizeof(H3270FT)+strlen(local)+strlen(remote)+3); | 286 | ftHandle = lib3270_malloc(sizeof(H3270FT)+strlen(local)+strlen(remote)+3); |
298 | 287 | ||
299 | ftHandle->host = session; | 288 | ftHandle->host = session; |
289 | + session->ft = ftHandle; | ||
300 | 290 | ||
301 | ftHandle->ft_last_cr = 0; | 291 | ftHandle->ft_last_cr = 0; |
292 | + ftHandle->ft_is_cut = 0; | ||
302 | 293 | ||
303 | ftHandle->ascii_flag = (flags & LIB3270_FT_OPTION_ASCII) ? 1 : 0; | 294 | ftHandle->ascii_flag = (flags & LIB3270_FT_OPTION_ASCII) ? 1 : 0; |
304 | ftHandle->cr_flag = (flags & LIB3270_FT_OPTION_CRLF) ? 1 : 0; | 295 | ftHandle->cr_flag = (flags & LIB3270_FT_OPTION_CRLF) ? 1 : 0; |
305 | ftHandle->remap_flag = (flags & LIB3270_FT_OPTION_REMAP) ? 1 : 0; | 296 | ftHandle->remap_flag = (flags & LIB3270_FT_OPTION_REMAP) ? 1 : 0; |
306 | ftHandle->unix_text = (flags & LIB3270_FT_OPTION_UNIX) ? 1 : 0; | 297 | ftHandle->unix_text = (flags & LIB3270_FT_OPTION_UNIX) ? 1 : 0; |
307 | - ftHandle->ft_is_cut = 0; | ||
308 | ftHandle->flags = flags; | 298 | ftHandle->flags = flags; |
309 | ftHandle->local_file = ft_local_file; | 299 | ftHandle->local_file = ft_local_file; |
310 | ftHandle->state = LIB3270_FT_STATE_AWAIT_ACK; | 300 | ftHandle->state = LIB3270_FT_STATE_AWAIT_ACK; |
@@ -332,7 +322,6 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | @@ -332,7 +322,6 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); | ||
332 | ftHandle->remote = ftHandle->local + strlen(ftHandle->local)+1; | 322 | ftHandle->remote = ftHandle->local + strlen(ftHandle->local)+1; |
333 | strcpy((char *) ftHandle->remote,remote); | 323 | strcpy((char *) ftHandle->remote,remote); |
334 | 324 | ||
335 | - session->ft = ftHandle; | ||
336 | 325 | ||
337 | lib3270_reset_ft_callbacks(session); | 326 | lib3270_reset_ft_callbacks(session); |
338 | 327 | ||
@@ -701,3 +690,24 @@ LIB3270_EXPORT LIB3270_FT_STATE lib3270_get_ft_state(H3270 *session) | @@ -701,3 +690,24 @@ LIB3270_EXPORT LIB3270_FT_STATE lib3270_get_ft_state(H3270 *session) | ||
701 | 690 | ||
702 | return ((H3270FT *) session->ft)->state; | 691 | return ((H3270FT *) session->ft)->state; |
703 | } | 692 | } |
693 | + | ||
694 | +LIB3270_EXPORT int lib3270_send(H3270 *hSession, const char *from, const char *to, const char **args) | ||
695 | +{ | ||
696 | + FAIL_IF_NOT_ONLINE(hSession); | ||
697 | + | ||
698 | + if(hSession->ft) | ||
699 | + return EBUSY; | ||
700 | + | ||
701 | + return ENOTSUP; | ||
702 | +} | ||
703 | + | ||
704 | +LIB3270_EXPORT int lib3270_receive(H3270 *hSession, const char *from, const char *to, const char **args) | ||
705 | +{ | ||
706 | + FAIL_IF_NOT_ONLINE(hSession); | ||
707 | + | ||
708 | + if(hSession->ft) | ||
709 | + return EBUSY; | ||
710 | + | ||
711 | + return ENOTSUP; | ||
712 | +} | ||
713 | + |
src/core/ft/ft_dft.c
@@ -42,6 +42,7 @@ | @@ -42,6 +42,7 @@ | ||
42 | #endif // WIN32 | 42 | #endif // WIN32 |
43 | 43 | ||
44 | #include <lib3270.h> | 44 | #include <lib3270.h> |
45 | +#include <lib3270/filetransfer.h> | ||
45 | #include <internals.h> | 46 | #include <internals.h> |
46 | 47 | ||
47 | #if defined(X3270_FT) /*[*/ | 48 | #if defined(X3270_FT) /*[*/ |
@@ -375,7 +376,7 @@ static void dft_get_request(H3270 *hSession) | @@ -375,7 +376,7 @@ static void dft_get_request(H3270 *hSession) | ||
375 | } | 376 | } |
376 | 377 | ||
377 | /* Read a buffer's worth. */ | 378 | /* Read a buffer's worth. */ |
378 | - set_dft_buffersize(hSession); | 379 | + lib3270_set_dft_buffersize(hSession,hSession->dft_buffersize); |
379 | space3270out(hSession,hSession->dft_buffersize); | 380 | space3270out(hSession,hSession->dft_buffersize); |
380 | numbytes = hSession->dft_buffersize - 27; /* always read 5 bytes less than we're allowed */ | 381 | numbytes = hSession->dft_buffersize - 27; /* always read 5 bytes less than we're allowed */ |
381 | bufptr = hSession->output.buf + 17; | 382 | bufptr = hSession->output.buf + 17; |
@@ -589,9 +590,7 @@ void dft_read_modified(H3270 *hSession) | @@ -589,9 +590,7 @@ void dft_read_modified(H3270 *hSession) | ||
589 | } | 590 | } |
590 | } | 591 | } |
591 | 592 | ||
592 | -/** | ||
593 | - * Update the buffersize for generating a Query Reply. | ||
594 | - */ | 593 | +/* |
595 | void set_dft_buffersize(H3270 *hSession) | 594 | void set_dft_buffersize(H3270 *hSession) |
596 | { | 595 | { |
597 | if (hSession->dft_buffersize == 0) | 596 | if (hSession->dft_buffersize == 0) |
@@ -603,6 +602,25 @@ void set_dft_buffersize(H3270 *hSession) | @@ -603,6 +602,25 @@ void set_dft_buffersize(H3270 *hSession) | ||
603 | if (hSession->dft_buffersize < DFT_MIN_BUF) | 602 | if (hSession->dft_buffersize < DFT_MIN_BUF) |
604 | hSession->dft_buffersize = DFT_MIN_BUF; | 603 | hSession->dft_buffersize = DFT_MIN_BUF; |
605 | } | 604 | } |
606 | - | 605 | +*/ |
607 | 606 | ||
608 | #endif /*]*/ | 607 | #endif /*]*/ |
608 | + | ||
609 | + LIB3270_EXPORT int lib3270_set_dft_buffersize(H3270 *hSession, int dft_buffersize) | ||
610 | + { | ||
611 | + CHECK_SESSION_HANDLE(hSession); | ||
612 | + | ||
613 | + hSession->dft_buffersize = dft_buffersize; | ||
614 | + | ||
615 | + if (hSession->dft_buffersize == 0) | ||
616 | + hSession->dft_buffersize = DFT_BUF; | ||
617 | + | ||
618 | + if (hSession->dft_buffersize > DFT_MAX_BUF) | ||
619 | + hSession->dft_buffersize = DFT_MAX_BUF; | ||
620 | + | ||
621 | + if (hSession->dft_buffersize < DFT_MIN_BUF) | ||
622 | + hSession->dft_buffersize = DFT_MIN_BUF; | ||
623 | + | ||
624 | + return 0; | ||
625 | + } | ||
626 | + |
@@ -0,0 +1,100 @@ | @@ -0,0 +1,100 @@ | ||
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 set.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 | +#include <config.h> | ||
31 | +#include <lib3270.h> | ||
32 | +#include <lib3270/filetransfer.h> | ||
33 | +#include <lib3270/log.h> | ||
34 | +#include <internals.h> | ||
35 | + | ||
36 | +/*---[ Implement ]-------------------------------------------------------------------------------------------------------*/ | ||
37 | + | ||
38 | + LIB3270_EXPORT int lib3270_ft_set_lrecl(H3270 *hSession, int lrecl) | ||
39 | + { | ||
40 | + CHECK_SESSION_HANDLE(hSession); | ||
41 | + | ||
42 | + if(!hSession->ft) | ||
43 | + return errno = EINVAL; | ||
44 | + | ||
45 | + hSession->ft->lrecl = lrecl; | ||
46 | + | ||
47 | + return 0; | ||
48 | + } | ||
49 | + | ||
50 | + LIB3270_EXPORT int lib3270_ft_set_blksize(H3270 *hSession, int blksize) | ||
51 | + { | ||
52 | + CHECK_SESSION_HANDLE(hSession); | ||
53 | + | ||
54 | + if(!hSession->ft) | ||
55 | + return errno = EINVAL; | ||
56 | + | ||
57 | + hSession->ft->blksize = blksize; | ||
58 | + | ||
59 | + return 0; | ||
60 | + } | ||
61 | + | ||
62 | + LIB3270_EXPORT int lib3270_ft_set_primspace(H3270 *hSession, int primspace) | ||
63 | + { | ||
64 | + CHECK_SESSION_HANDLE(hSession); | ||
65 | + | ||
66 | + if(!hSession->ft) | ||
67 | + return errno = EINVAL; | ||
68 | + | ||
69 | + hSession->ft->primspace = primspace; | ||
70 | + | ||
71 | + return 0; | ||
72 | + } | ||
73 | + | ||
74 | + LIB3270_EXPORT int lib3270_ft_set_secspace(H3270 *hSession, int secspace) | ||
75 | + { | ||
76 | + CHECK_SESSION_HANDLE(hSession); | ||
77 | + | ||
78 | + if(!hSession->ft) | ||
79 | + return errno = EINVAL; | ||
80 | + | ||
81 | + hSession->ft->secspace = secspace; | ||
82 | + | ||
83 | + return 0; | ||
84 | + } | ||
85 | + | ||
86 | + LIB3270_EXPORT int lib3270_ft_set_options(H3270 *hSession, LIB3270_FT_OPTION options) | ||
87 | + { | ||
88 | + CHECK_SESSION_HANDLE(hSession); | ||
89 | + | ||
90 | + if(!hSession->ft) | ||
91 | + return errno = EINVAL; | ||
92 | + | ||
93 | + hSession->ft->ascii_flag = (options & LIB3270_FT_OPTION_ASCII) ? 1 : 0; | ||
94 | + hSession->ft->cr_flag = (options & LIB3270_FT_OPTION_CRLF) ? 1 : 0; | ||
95 | + hSession->ft->remap_flag = (options & LIB3270_FT_OPTION_REMAP) ? 1 : 0; | ||
96 | + hSession->ft->unix_text = (options & LIB3270_FT_OPTION_UNIX) ? 1 : 0; | ||
97 | + hSession->ft->flags |= options; | ||
98 | + | ||
99 | + return 0; | ||
100 | + } |
src/core/session.c
@@ -217,28 +217,6 @@ static int load(H3270 *session, const char GNUC_UNUSED(*filename)) | @@ -217,28 +217,6 @@ static int load(H3270 *session, const char GNUC_UNUSED(*filename)) | ||
217 | return errno = ENOTSUP; | 217 | return errno = ENOTSUP; |
218 | } | 218 | } |
219 | 219 | ||
220 | -/* | ||
221 | -static void def_message(H3270 *session, LIB3270_NOTIFY GNUC_UNUSED(id), const char *title, const char *msg, const char *text) | ||
222 | -{ | ||
223 | -#ifdef ANDROID | ||
224 | - __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "%s\n",title); | ||
225 | - __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "%s\n",msg); | ||
226 | - __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "%s\n",text); | ||
227 | -#else | ||
228 | - lib3270_write_log(session,"lib3270","%s",title); | ||
229 | - lib3270_write_log(session,"lib3270","%s",msg); | ||
230 | - lib3270_write_log(session,"lib3270","%s",text); | ||
231 | -#endif // ANDROID | ||
232 | -} | ||
233 | -*/ | ||
234 | - | ||
235 | -/* | ||
236 | -static void def_popup(H3270 *hSession, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list args) | ||
237 | -{ | ||
238 | - lib3270_popup_va(hSession,type,title,msg,fmt,args); | ||
239 | -} | ||
240 | -*/ | ||
241 | - | ||
242 | static void def_trace(H3270 GNUC_UNUSED(*session), void GNUC_UNUSED(*userdata), const char *fmt, va_list args) | 220 | static void def_trace(H3270 GNUC_UNUSED(*session), void GNUC_UNUSED(*userdata), const char *fmt, va_list args) |
243 | { | 221 | { |
244 | vfprintf(stdout,fmt,args); | 222 | vfprintf(stdout,fmt,args); |
@@ -481,14 +459,12 @@ void check_session_handle(H3270 **hSession) | @@ -481,14 +459,12 @@ void check_session_handle(H3270 **hSession) | ||
481 | if(*hSession) | 459 | if(*hSession) |
482 | return; | 460 | return; |
483 | 461 | ||
484 | - *hSession = lib3270_get_default_session_handle(); | 462 | +// *hSession = lib3270_get_default_session_handle(); |
485 | 463 | ||
486 | -#if defined(ANDROID) | ||
487 | - __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "%s called with empty session\n", __FUNCTION__); | ||
488 | -#elif defined(DEBUG) | ||
489 | - lib3270_write_log(*hSession, "lib3270", "%s called with empty session from %s",__FUNCTION__,fname); | 464 | +#if defined(DEBUG) |
465 | + lib3270_write_log(NULL, "lib3270", "%s called with empty session from %s",__FUNCTION__,fname); | ||
490 | #else | 466 | #else |
491 | - lib3270_write_log(*hSession, "lib3270", "%s called with empty session",__FUNCTION__); | 467 | + lib3270_write_log(NULL, "lib3270", "%s called with empty session",__FUNCTION__); |
492 | #endif // ANDROID | 468 | #endif // ANDROID |
493 | } | 469 | } |
494 | 470 |
src/core/sf.c
@@ -37,6 +37,7 @@ | @@ -37,6 +37,7 @@ | ||
37 | */ | 37 | */ |
38 | 38 | ||
39 | #include <internals.h> | 39 | #include <internals.h> |
40 | +#include <lib3270/filetransfer.h> | ||
40 | #include <lib3270/trace.h> | 41 | #include <lib3270/trace.h> |
41 | 42 | ||
42 | #include <errno.h> | 43 | #include <errno.h> |
@@ -997,7 +998,7 @@ static void do_qr_charsets(H3270 *hSession) | @@ -997,7 +998,7 @@ static void do_qr_charsets(H3270 *hSession) | ||
997 | #if defined(X3270_FT) /*[*/ | 998 | #if defined(X3270_FT) /*[*/ |
998 | static void do_qr_ddm(H3270 *hSession) | 999 | static void do_qr_ddm(H3270 *hSession) |
999 | { | 1000 | { |
1000 | - set_dft_buffersize(hSession); | 1001 | + lib3270_set_dft_buffersize(hSession,hSession->dft_buffersize); |
1001 | 1002 | ||
1002 | trace_ds(hSession,"> QueryReply(DistributedDataManagement)\n"); | 1003 | trace_ds(hSession,"> QueryReply(DistributedDataManagement)\n"); |
1003 | space3270out(hSession,8); | 1004 | space3270out(hSession,8); |
src/core/telnet.c
@@ -124,19 +124,6 @@ | @@ -124,19 +124,6 @@ | ||
124 | #define E_OPT(n) (1 << (n)) | 124 | #define E_OPT(n) (1 << (n)) |
125 | #endif // X3270_TN3270E | 125 | #endif // X3270_TN3270E |
126 | 126 | ||
127 | -/* | ||
128 | -#if defined(X3270_ANSI) | ||
129 | -static char vintr; | ||
130 | -static char vquit; | ||
131 | -static char verase; | ||
132 | -static char vkill; | ||
133 | -static char veof; | ||
134 | -static char vwerase; | ||
135 | -static char vrprnt; | ||
136 | -static char vlnext; | ||
137 | -#endif | ||
138 | -*/ | ||
139 | - | ||
140 | struct _ansictl ansictl = { 0 }; | 127 | struct _ansictl ansictl = { 0 }; |
141 | 128 | ||
142 | static int telnet_fsm(H3270 *session, unsigned char c); | 129 | static int telnet_fsm(H3270 *session, unsigned char c); |
@@ -2090,27 +2077,23 @@ static void check_linemode(H3270 *hSession, Boolean init) | @@ -2090,27 +2077,23 @@ static void check_linemode(H3270 *hSession, Boolean init) | ||
2090 | } | 2077 | } |
2091 | } | 2078 | } |
2092 | 2079 | ||
2093 | - | ||
2094 | #if defined(X3270_TRACE) | 2080 | #if defined(X3270_TRACE) |
2095 | 2081 | ||
2096 | -/* | ||
2097 | - * nnn | ||
2098 | - * Expands a number to a character string, for displaying unknown telnet | ||
2099 | - * commands and options. | ||
2100 | - */ | 2082 | +/// |
2083 | +/// @brief Expands a number to a character string, for displaying unknown telnet commands and options. | ||
2084 | +/// | ||
2101 | static const char * | 2085 | static const char * |
2102 | nnn(int c) | 2086 | nnn(int c) |
2103 | { | 2087 | { |
2104 | static char buf[64]; | 2088 | static char buf[64]; |
2105 | - | ||
2106 | - (void) sprintf(buf, "%d", c); | 2089 | + memset(buf,0,sizeof(buf)); |
2090 | + (void) snprintf(buf, 63, "%d", c); | ||
2107 | return buf; | 2091 | return buf; |
2108 | } | 2092 | } |
2109 | 2093 | ||
2110 | -/* | ||
2111 | - * cmd | ||
2112 | - * Expands a TELNET command into a character string. | ||
2113 | - */ | 2094 | +/// |
2095 | +/// @brief Expands a TELNET command into a character string. | ||
2096 | +/// | ||
2114 | static const char * cmd(int c) | 2097 | static const char * cmd(int c) |
2115 | { | 2098 | { |
2116 | if (TELCMD_OK(c)) | 2099 | if (TELCMD_OK(c)) |
@@ -2119,20 +2102,17 @@ static const char * cmd(int c) | @@ -2119,20 +2102,17 @@ static const char * cmd(int c) | ||
2119 | return nnn(c); | 2102 | return nnn(c); |
2120 | } | 2103 | } |
2121 | 2104 | ||
2122 | -/*** | ||
2123 | - * | ||
2124 | - * @brief Expands a TELNET option into a character string. | ||
2125 | - */ | 2105 | +/// |
2106 | +/// @brief Expands a TELNET option into a character string. | ||
2107 | +/// | ||
2126 | static const char * opt(unsigned char c) | 2108 | static const char * opt(unsigned char c) |
2127 | { | 2109 | { |
2128 | - if (TELOPT_OK(c)) | ||
2129 | - return TELOPT(c); | ||
2130 | - else if (c == TELOPT_TN3270E) | 2110 | + if (c == TELOPT_TN3270E) |
2131 | return "TN3270E"; | 2111 | return "TN3270E"; |
2132 | -#if defined(HAVE_LIBSSL) /*[*/ | ||
2133 | else if (c == TELOPT_STARTTLS) | 2112 | else if (c == TELOPT_STARTTLS) |
2134 | return "START-TLS"; | 2113 | return "START-TLS"; |
2135 | -#endif /*]*/ | 2114 | + else if (TELOPT_OK(c)) |
2115 | + return TELOPT(c); | ||
2136 | else | 2116 | else |
2137 | return nnn((int)c); | 2117 | return nnn((int)c); |
2138 | } | 2118 | } |
src/core/util.c
@@ -60,7 +60,7 @@ char * lib3270_vsprintf(const char *fmt, va_list args) | @@ -60,7 +60,7 @@ char * lib3270_vsprintf(const char *fmt, va_list args) | ||
60 | #if defined(HAVE_VASPRINTF) | 60 | #if defined(HAVE_VASPRINTF) |
61 | 61 | ||
62 | if(vasprintf(&r, fmt, args) < 0 || !r) | 62 | if(vasprintf(&r, fmt, args) < 0 || !r) |
63 | - lib3270_popup_dialog(lib3270_get_default_session_handle(),LIB3270_NOTIFY_ERROR,_("Internal error"),"Out of memory",NULL); | 63 | + lib3270_write_log(NULL, "lib3270", "Error in vasprintf"); |
64 | 64 | ||
65 | #else | 65 | #else |
66 | 66 | ||
@@ -70,7 +70,7 @@ char * lib3270_vsprintf(const char *fmt, va_list args) | @@ -70,7 +70,7 @@ char * lib3270_vsprintf(const char *fmt, va_list args) | ||
70 | nc = vsnprintf(buf, sizeof(buf), fmt, args); | 70 | nc = vsnprintf(buf, sizeof(buf), fmt, args); |
71 | if(nc < 0) | 71 | if(nc < 0) |
72 | { | 72 | { |
73 | - lib3270_popup_dialog(lib3270_get_default_session_handle(),LIB3270_NOTIFY_ERROR,_("Internal error"),"Out of memory",NULL); | 73 | + lib3270_write_log(NULL, "lib3270", "Error on vsnprintf"); |
74 | } | 74 | } |
75 | else if (nc < sizeof(buf)) | 75 | else if (nc < sizeof(buf)) |
76 | { | 76 | { |
@@ -82,7 +82,11 @@ char * lib3270_vsprintf(const char *fmt, va_list args) | @@ -82,7 +82,11 @@ char * lib3270_vsprintf(const char *fmt, va_list args) | ||
82 | { | 82 | { |
83 | r = lib3270_malloc(nc + 1); | 83 | r = lib3270_malloc(nc + 1); |
84 | if(vsnprintf(r, nc, fmt, args) < 0) | 84 | if(vsnprintf(r, nc, fmt, args) < 0) |
85 | - lib3270_popup_dialog(lib3270_get_default_session_handle(),LIB3270_NOTIFY_ERROR,_("Internal error"),"Out of memory",NULL); | 85 | + { |
86 | + lib3270_write_log(NULL, "lib3270", "Error on vsnprintf"); | ||
87 | + free(r); | ||
88 | + return NULL; | ||
89 | + } | ||
86 | 90 | ||
87 | } | 91 | } |
88 | 92 | ||
@@ -176,8 +180,8 @@ LIB3270_EXPORT void lib3270_autoptr_cleanup_LIB3270_POPUP(LIB3270_POPUP **ptr) | @@ -176,8 +180,8 @@ LIB3270_EXPORT void lib3270_autoptr_cleanup_LIB3270_POPUP(LIB3270_POPUP **ptr) | ||
176 | LIB3270_EXPORT void * lib3270_realloc(void *p, int len) | 180 | LIB3270_EXPORT void * lib3270_realloc(void *p, int len) |
177 | { | 181 | { |
178 | p = realloc(p, len); | 182 | p = realloc(p, len); |
179 | - if(!p) | ||
180 | - lib3270_popup_dialog(lib3270_get_default_session_handle(),LIB3270_NOTIFY_ERROR,_("Internal error"),"Out of memory",NULL); | 183 | + if(p == NULL) |
184 | + perror("realloc"); | ||
181 | return p; | 185 | return p; |
182 | } | 186 | } |
183 | 187 | ||
@@ -190,43 +194,65 @@ LIB3270_EXPORT void * lib3270_calloc(int elsize, int nelem, void *ptr) | @@ -190,43 +194,65 @@ LIB3270_EXPORT void * lib3270_calloc(int elsize, int nelem, void *ptr) | ||
190 | else | 194 | else |
191 | ptr = malloc(sz); | 195 | ptr = malloc(sz); |
192 | 196 | ||
193 | - if(ptr) | ||
194 | - memset(ptr,0,sz); | ||
195 | - else | ||
196 | - lib3270_popup_dialog(lib3270_get_default_session_handle(),LIB3270_NOTIFY_ERROR,_("Internal error"),"Out of memory",NULL); | 197 | + if(!ptr) |
198 | + perror("calloc"); | ||
197 | 199 | ||
200 | + memset(ptr,0,sz); | ||
198 | return ptr; | 201 | return ptr; |
199 | } | 202 | } |
200 | 203 | ||
201 | LIB3270_EXPORT void * lib3270_malloc(int len) | 204 | LIB3270_EXPORT void * lib3270_malloc(int len) |
202 | { | 205 | { |
203 | - char *r; | ||
204 | - | ||
205 | - r = malloc(len); | ||
206 | - if (r == (char *)NULL) | ||
207 | - { | ||
208 | - lib3270_popup_dialog(lib3270_get_default_session_handle(),LIB3270_NOTIFY_ERROR,_("Internal error"),"Out of memory",NULL); | ||
209 | - return 0; | ||
210 | - } | 206 | + char *r = malloc(len); |
207 | + if(r) | ||
208 | + memset(r,0,len); | ||
211 | 209 | ||
212 | - memset(r,0,len); | ||
213 | return r; | 210 | return r; |
214 | } | 211 | } |
215 | 212 | ||
216 | LIB3270_EXPORT void * lib3270_strdup(const char *str) | 213 | LIB3270_EXPORT void * lib3270_strdup(const char *str) |
217 | { | 214 | { |
218 | - char *r; | 215 | + return strdup(str); |
216 | +} | ||
217 | + | ||
218 | +LIB3270_EXPORT char * lib3270_chomp(char *str) | ||
219 | +{ | ||
220 | + | ||
221 | + size_t len = strlen(str); | ||
219 | 222 | ||
220 | - r = strdup(str); | ||
221 | - if (r == (char *)NULL) | 223 | + while(len--) |
222 | { | 224 | { |
223 | - lib3270_popup_dialog(lib3270_get_default_session_handle(),LIB3270_NOTIFY_ERROR,_("Internal error"),"Out of memory",NULL); | ||
224 | - return 0; | 225 | + |
226 | + if(isspace(str[len])) | ||
227 | + { | ||
228 | + str[len] = 0; | ||
229 | + } else { | ||
230 | + break; | ||
231 | + } | ||
225 | } | 232 | } |
226 | 233 | ||
227 | - return r; | 234 | + return str; |
235 | + | ||
228 | } | 236 | } |
229 | 237 | ||
238 | +LIB3270_EXPORT char * lib3270_chug(char *str) | ||
239 | +{ | ||
240 | + | ||
241 | + char *start; | ||
242 | + | ||
243 | + for (start = (char*) str; *start && isspace(*start); start++); | ||
244 | + | ||
245 | + memmove(str, start, strlen ((char *) start) + 1); | ||
246 | + | ||
247 | + return str; | ||
248 | +} | ||
249 | + | ||
250 | +LIB3270_EXPORT char * lib3270_strip(char *str) | ||
251 | +{ | ||
252 | + return lib3270_chomp(lib3270_chug(str)); | ||
253 | +} | ||
254 | + | ||
255 | + | ||
230 | LIB3270_EXPORT const char * lib3270_get_version(void) | 256 | LIB3270_EXPORT const char * lib3270_get_version(void) |
231 | { | 257 | { |
232 | return PACKAGE_VERSION; | 258 | return PACKAGE_VERSION; |
@@ -256,25 +282,19 @@ LIB3270_EXPORT char * lib3270_get_version_info(void) | @@ -256,25 +282,19 @@ LIB3270_EXPORT char * lib3270_get_version_info(void) | ||
256 | void lib3270_popup_an_errno(H3270 *hSession, int errn, const char *fmt, ...) | 282 | void lib3270_popup_an_errno(H3270 *hSession, int errn, const char *fmt, ...) |
257 | { | 283 | { |
258 | va_list args; | 284 | va_list args; |
259 | - char * text; | ||
260 | 285 | ||
261 | va_start(args, fmt); | 286 | va_start(args, fmt); |
262 | - text = lib3270_vsprintf(fmt, args); | 287 | + lib3270_autoptr(char) summary = lib3270_vsprintf(fmt, args); |
288 | + lib3270_autoptr(char) body = lib3270_strdup_printf( _( "The system error was '%s' (rc=%d)" ),strerror(errn),errn); | ||
263 | va_end(args); | 289 | va_end(args); |
264 | 290 | ||
265 | - lib3270_write_log(hSession, "3270", "Error Popup:\n%s\nrc=%d (%s)",text,errn,strerror(errn)); | ||
266 | - | ||
267 | - lib3270_popup_dialog( | ||
268 | - hSession, | ||
269 | - LIB3270_NOTIFY_ERROR, | ||
270 | - _( "Error" ), | ||
271 | - text, | ||
272 | - "%s (rc=%d)", | ||
273 | - strerror(errn), | ||
274 | - errn | ||
275 | - ); | 291 | + LIB3270_POPUP popup = { |
292 | + .type = LIB3270_NOTIFY_ERROR, | ||
293 | + .summary = summary, | ||
294 | + .body = body | ||
295 | + }; | ||
276 | 296 | ||
277 | - lib3270_free(text); | 297 | + lib3270_popup(hSession,&popup,0); |
278 | 298 | ||
279 | } | 299 | } |
280 | 300 |
src/core/windows/util.c
@@ -238,22 +238,6 @@ LIB3270_EXPORT const char * lib3270_win32_local_charset(void) | @@ -238,22 +238,6 @@ LIB3270_EXPORT const char * lib3270_win32_local_charset(void) | ||
238 | #define SECS_BETWEEN_EPOCHS 11644473600ULL | 238 | #define SECS_BETWEEN_EPOCHS 11644473600ULL |
239 | #define SECS_TO_100NS 10000000ULL /* 10^7 */ | 239 | #define SECS_TO_100NS 10000000ULL /* 10^7 */ |
240 | 240 | ||
241 | -/* | ||
242 | -int gettimeofday(struct timeval *tv, struct timezone GNUC_UNUSED(*ignored)) | ||
243 | -{ | ||
244 | - FILETIME t; | ||
245 | - ULARGE_INTEGER u; | ||
246 | - | ||
247 | - GetSystemTimeAsFileTime(&t); | ||
248 | - memcpy(&u, &t, sizeof(ULARGE_INTEGER)); | ||
249 | - | ||
250 | - // Isolate seconds and move epochs. | ||
251 | - tv->tv_sec = (DWORD)((u.QuadPart / SECS_TO_100NS) - SECS_BETWEEN_EPOCHS); | ||
252 | - tv->tv_usec = (u.QuadPart % SECS_TO_100NS) / 10ULL; | ||
253 | - return 0; | ||
254 | -} | ||
255 | -*/ | ||
256 | - | ||
257 | LIB3270_EXPORT char * lib3270_get_installation_path() | 241 | LIB3270_EXPORT char * lib3270_get_installation_path() |
258 | { | 242 | { |
259 | char lpFilename[4096]; | 243 | char lpFilename[4096]; |
src/include/ft_dftc.h
@@ -16,4 +16,4 @@ | @@ -16,4 +16,4 @@ | ||
16 | 16 | ||
17 | LIB3270_INTERNAL void ft_dft_data(H3270 *hSession, unsigned char *data, int length); | 17 | LIB3270_INTERNAL void ft_dft_data(H3270 *hSession, unsigned char *data, int length); |
18 | LIB3270_INTERNAL void dft_read_modified(H3270 *hSession); | 18 | LIB3270_INTERNAL void dft_read_modified(H3270 *hSession); |
19 | -LIB3270_INTERNAL void set_dft_buffersize(H3270 *hSession); | 19 | +//LIB3270_INTERNAL void set_dft_buffersize(H3270 *hSession); |
src/include/lib3270.h
@@ -1404,11 +1404,57 @@ | @@ -1404,11 +1404,57 @@ | ||
1404 | */ | 1404 | */ |
1405 | LIB3270_EXPORT void * lib3270_calloc(int elsize, int nelem, void *ptr); | 1405 | LIB3270_EXPORT void * lib3270_calloc(int elsize, int nelem, void *ptr); |
1406 | 1406 | ||
1407 | + /** | ||
1408 | + * @brief Get a block of memory, fill it with zeros. | ||
1409 | + * | ||
1410 | + * @param len Length of memory block to get. | ||
1411 | + * | ||
1412 | + * @return Pointer to new memory block. | ||
1413 | + * | ||
1414 | + */ | ||
1407 | LIB3270_EXPORT void * lib3270_malloc(int len); | 1415 | LIB3270_EXPORT void * lib3270_malloc(int len); |
1416 | + | ||
1408 | LIB3270_EXPORT void * lib3270_realloc(void *p, int len); | 1417 | LIB3270_EXPORT void * lib3270_realloc(void *p, int len); |
1409 | LIB3270_EXPORT void * lib3270_strdup(const char *str); | 1418 | LIB3270_EXPORT void * lib3270_strdup(const char *str); |
1410 | 1419 | ||
1411 | /** | 1420 | /** |
1421 | + * @brief Removes trailing white space from a string. | ||
1422 | + * | ||
1423 | + * This function doesn't allocate or reallocate any memory; | ||
1424 | + * it modifies in place. Therefore, it cannot be used | ||
1425 | + * on statically allocated strings. | ||
1426 | + * | ||
1427 | + * Reference: <https://git.gnome.org/browse/glib/tree/glib/gstrfuncs.c> | ||
1428 | + * | ||
1429 | + * @see chug() and strip(). | ||
1430 | + * | ||
1431 | + * @return pointer to string. | ||
1432 | + * | ||
1433 | + */ | ||
1434 | + LIB3270_EXPORT char * lib3270_chomp(char *str); | ||
1435 | + | ||
1436 | + /** | ||
1437 | + * @brief Remove the leading white space from the string. | ||
1438 | + * | ||
1439 | + * Removes leading white space from a string, by moving the rest | ||
1440 | + * of the characters forward. | ||
1441 | + * | ||
1442 | + * This function doesn't allocate or reallocate any memory; | ||
1443 | + * it modifies the string in place. Therefore, it cannot be used on | ||
1444 | + * statically allocated strings. | ||
1445 | + * | ||
1446 | + * Reference: <https://git.gnome.org/browse/glib/tree/glib/gstrfuncs.c> | ||
1447 | + * | ||
1448 | + * @see chomp() and strip(). | ||
1449 | + * | ||
1450 | + * @return pointer to string. | ||
1451 | + * | ||
1452 | + */ | ||
1453 | + LIB3270_EXPORT char * lib3270_chug(char *str); | ||
1454 | + | ||
1455 | + LIB3270_EXPORT char * lib3270_strip(char *str); | ||
1456 | + | ||
1457 | + /** | ||
1412 | * @brief Release allocated memory. | 1458 | * @brief Release allocated memory. |
1413 | * | 1459 | * |
1414 | * @param p Memory block to release (can be NULL) | 1460 | * @param p Memory block to release (can be NULL) |
@@ -1425,7 +1471,7 @@ | @@ -1425,7 +1471,7 @@ | ||
1425 | * @return Internal's lib3270 session handle. | 1471 | * @return Internal's lib3270 session handle. |
1426 | * | 1472 | * |
1427 | */ | 1473 | */ |
1428 | - LIB3270_EXPORT H3270 * lib3270_get_default_session_handle(void); | 1474 | + LIB3270_EXPORT H3270 * LIB3270_DEPRECATED(lib3270_get_default_session_handle(void)); |
1429 | 1475 | ||
1430 | /** | 1476 | /** |
1431 | * Get library version. | 1477 | * Get library version. |
src/include/lib3270/filetransfer.h
@@ -106,14 +106,14 @@ | @@ -106,14 +106,14 @@ | ||
106 | { | 106 | { |
107 | struct lib3270_ft_callbacks cbk; ///< @brief Callback table - Always the first one. | 107 | struct lib3270_ft_callbacks cbk; ///< @brief Callback table - Always the first one. |
108 | 108 | ||
109 | - int ft_last_cr : 1; ///< @brief CR was last char in local file | ||
110 | - int remap_flag : 1; ///< @brief Remap ASCII<->EBCDIC | ||
111 | - int cr_flag : 1; ///< @brief Add crlf to each line | ||
112 | - int unix_text : 1; ///< @brief Following the convention for UNIX text files. | ||
113 | - int message_flag : 1; ///< @brief Open Request for msg received | ||
114 | - int ascii_flag : 1; ///< @brief Convert to ascii | ||
115 | - int ft_is_cut : 1; ///< @brief File transfer is CUT-style | ||
116 | - int dft_eof : 1; | 109 | + unsigned int ft_last_cr : 1; ///< @brief CR was last char in local file |
110 | + unsigned int remap_flag : 1; ///< @brief Remap ASCII<->EBCDIC | ||
111 | + unsigned int cr_flag : 1; ///< @brief Add crlf to each line | ||
112 | + unsigned int unix_text : 1; ///< @brief Following the convention for UNIX text files. | ||
113 | + unsigned int message_flag : 1; ///< @brief Open Request for msg received | ||
114 | + unsigned int ascii_flag : 1; ///< @brief Convert to ascii | ||
115 | + unsigned int ft_is_cut : 1; ///< @brief File transfer is CUT-style | ||
116 | + unsigned int dft_eof : 1; | ||
117 | 117 | ||
118 | 118 | ||
119 | H3270 * host; | 119 | H3270 * host; |
@@ -196,6 +196,46 @@ | @@ -196,6 +196,46 @@ | ||
196 | 196 | ||
197 | LIB3270_EXPORT struct lib3270_ft_callbacks * lib3270_get_ft_callbacks(H3270 *session, unsigned short sz); | 197 | LIB3270_EXPORT struct lib3270_ft_callbacks * lib3270_get_ft_callbacks(H3270 *session, unsigned short sz); |
198 | 198 | ||
199 | + LIB3270_EXPORT int lib3270_ft_set_lrecl(H3270 *hSession, int lrecl); | ||
200 | + LIB3270_EXPORT int lib3270_ft_set_blksize(H3270 *hSession, int blksize); | ||
201 | + LIB3270_EXPORT int lib3270_ft_set_primspace(H3270 *hSession, int primspace); | ||
202 | + LIB3270_EXPORT int lib3270_ft_set_secspace(H3270 *hSession, int secspace); | ||
203 | + | ||
204 | + /** | ||
205 | + * @brief Update the buffersize for generating a Query Reply. | ||
206 | + */ | ||
207 | + LIB3270_EXPORT int lib3270_set_dft_buffersize(H3270 *hSession, int dft_buffersize); | ||
208 | + | ||
209 | + LIB3270_EXPORT int lib3270_ft_set_options(H3270 *hSession, LIB3270_FT_OPTION options); | ||
210 | + | ||
211 | + /** | ||
212 | + * @brief Send file. | ||
213 | + * | ||
214 | + * @param from Origin filename | ||
215 | + * @param to Destination filename | ||
216 | + * @param args Null terminated file transfer options. | ||
217 | + * | ||
218 | + * @return 0 if ok, error code if not. | ||
219 | + * | ||
220 | + * @retval EBUSY File transfer is already active. | ||
221 | + * | ||
222 | + */ | ||
223 | + LIB3270_EXPORT int lib3270_send(H3270 *hSession, const char *from, const char *to, const char **args); | ||
224 | + | ||
225 | + /** | ||
226 | + * @brief Receive file. | ||
227 | + * | ||
228 | + * @param from Origin filename | ||
229 | + * @param to Destination filename | ||
230 | + * @param args Null terminated file transfer options. | ||
231 | + * | ||
232 | + * @return 0 if ok, error code if not. | ||
233 | + * | ||
234 | + * @retval EBUSY File transfer is already active. | ||
235 | + * | ||
236 | + */ | ||
237 | + LIB3270_EXPORT int lib3270_receive(H3270 *hSession, const char *from, const char *to, const char **args); | ||
238 | + | ||
199 | /** | 239 | /** |
200 | * @brief Set all FT callbacks to default valides. | 240 | * @brief Set all FT callbacks to default valides. |
201 | * | 241 | * |
src/include/lib3270/session.h
src/network_modules/openssl/main.c