Commit e0256fd4ebd386113ccf7ab2d87e140b82aeb2d6
1 parent
538f302a
Exists in
master
and in
3 other branches
Removing warnings, adding macro for test online mode in API calls.
Showing
4 changed files
with
42 additions
and
12 deletions
Show diff stats
src/include/lib3270.h
@@ -1035,7 +1035,7 @@ | @@ -1035,7 +1035,7 @@ | ||
1035 | * @param c Pointer to character. | 1035 | * @param c Pointer to character. |
1036 | * @param attr Pointer to attribute. | 1036 | * @param attr Pointer to attribute. |
1037 | * | 1037 | * |
1038 | - * @return 0 if ok or error code. | 1038 | + * @return 0 if ok, -1 if fails (sets errno). |
1039 | * | 1039 | * |
1040 | */ | 1040 | */ |
1041 | LIB3270_EXPORT int lib3270_get_element(H3270 *h, int baddr, unsigned char *c, unsigned short *attr); | 1041 | LIB3270_EXPORT int lib3270_get_element(H3270 *h, int baddr, unsigned char *c, unsigned short *attr); |
src/lib3270/private.h
@@ -633,6 +633,11 @@ LIB3270_INTERNAL int lib3270_default_event_dispatcher(H3270 *hSession, int block | @@ -633,6 +633,11 @@ LIB3270_INTERNAL int lib3270_default_event_dispatcher(H3270 *hSession, int block | ||
633 | LIB3270_INTERNAL void check_session_handle(H3270 **hSession); | 633 | LIB3270_INTERNAL void check_session_handle(H3270 **hSession); |
634 | #endif // DEBUG | 634 | #endif // DEBUG |
635 | 635 | ||
636 | +LIB3270_INTERNAL int check_online_session(H3270 *hSession); | ||
637 | + | ||
638 | +/// @brief Returns -1 if the session is invalid or not online (sets errno). | ||
639 | +#define FAIL_IF_NOT_ONLINE(x) if(check_online_session(x)) return -1; | ||
640 | + | ||
636 | LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on); | 641 | LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on); |
637 | 642 | ||
638 | #if defined(HAVE_LIBSSL) /*[*/ | 643 | #if defined(HAVE_LIBSSL) /*[*/ |
src/lib3270/screen.c
@@ -98,15 +98,18 @@ static void addch(H3270 *session, int baddr, unsigned char c, unsigned short att | @@ -98,15 +98,18 @@ static void addch(H3270 *session, int baddr, unsigned char c, unsigned short att | ||
98 | session->cbk.update(session,baddr,c,attr,baddr == session->cursor_addr); | 98 | session->cbk.update(session,baddr,c,attr,baddr == session->cursor_addr); |
99 | } | 99 | } |
100 | 100 | ||
101 | -LIB3270_EXPORT int lib3270_get_element(H3270 *h, int baddr, unsigned char *c, unsigned short *attr) | 101 | +LIB3270_EXPORT int lib3270_get_element(H3270 *hSession, int baddr, unsigned char *c, unsigned short *attr) |
102 | { | 102 | { |
103 | - CHECK_SESSION_HANDLE(h); | 103 | + FAIL_IF_NOT_ONLINE(hSession); |
104 | 104 | ||
105 | - if(!h->text || baddr < 0 || baddr > (h->rows*h->cols)) | ||
106 | - return EINVAL; | 105 | + if(!hSession->text || baddr < 0 || baddr > (hSession->rows*hSession->cols)) |
106 | + { | ||
107 | + errno = EINVAL; | ||
108 | + return -1; | ||
109 | + } | ||
107 | 110 | ||
108 | - *c = h->text[baddr].chr; | ||
109 | - *attr = h->text[baddr].attr; | 111 | + *c = hSession->text[baddr].chr; |
112 | + *attr = hSession->text[baddr].attr; | ||
110 | 113 | ||
111 | return 0; | 114 | return 0; |
112 | } | 115 | } |
@@ -394,7 +397,7 @@ LIB3270_EXPORT int lib3270_get_cursor_address(H3270 *h) | @@ -394,7 +397,7 @@ LIB3270_EXPORT int lib3270_get_cursor_address(H3270 *h) | ||
394 | */ | 397 | */ |
395 | LIB3270_EXPORT int lib3270_translate_to_address(H3270 *hSession, int row, int col) | 398 | LIB3270_EXPORT int lib3270_translate_to_address(H3270 *hSession, int row, int col) |
396 | { | 399 | { |
397 | - CHECK_SESSION_HANDLE(hSession); | 400 | + FAIL_IF_NOT_ONLINE(hSession); |
398 | 401 | ||
399 | row--; | 402 | row--; |
400 | col--; | 403 | col--; |
@@ -423,7 +426,7 @@ LIB3270_EXPORT int lib3270_translate_to_address(H3270 *hSession, int row, int co | @@ -423,7 +426,7 @@ LIB3270_EXPORT int lib3270_translate_to_address(H3270 *hSession, int row, int co | ||
423 | */ | 426 | */ |
424 | LIB3270_EXPORT int lib3270_set_cursor_address(H3270 *hSession, int baddr) | 427 | LIB3270_EXPORT int lib3270_set_cursor_address(H3270 *hSession, int baddr) |
425 | { | 428 | { |
426 | - CHECK_SESSION_HANDLE(hSession); | 429 | + FAIL_IF_NOT_ONLINE(hSession); |
427 | 430 | ||
428 | trace("%s(%d)",__FUNCTION__,baddr); | 431 | trace("%s(%d)",__FUNCTION__,baddr); |
429 | 432 | ||
@@ -877,10 +880,10 @@ LIB3270_ACTION( testpattern ) | @@ -877,10 +880,10 @@ LIB3270_ACTION( testpattern ) | ||
877 | 880 | ||
878 | static const unsigned char gr[] = { 0, GR_UNDERLINE, GR_BLINK }; | 881 | static const unsigned char gr[] = { 0, GR_UNDERLINE, GR_BLINK }; |
879 | 882 | ||
880 | - int row = 0; | 883 | + unsigned int row = 0; |
881 | int max; | 884 | int max; |
882 | int pos = 0; | 885 | int pos = 0; |
883 | - int grpos = 0; | 886 | + unsigned int grpos = 0; |
884 | int f; | 887 | int f; |
885 | int fg = COLOR_BLUE; | 888 | int fg = COLOR_BLUE; |
886 | 889 | ||
@@ -933,10 +936,13 @@ LIB3270_EXPORT int lib3270_is_protected(H3270 *h, unsigned int baddr) | @@ -933,10 +936,13 @@ LIB3270_EXPORT int lib3270_is_protected(H3270 *h, unsigned int baddr) | ||
933 | { | 936 | { |
934 | unsigned char fa; | 937 | unsigned char fa; |
935 | 938 | ||
936 | - CHECK_SESSION_HANDLE(h); | 939 | + FAIL_IF_NOT_ONLINE(h); |
937 | 940 | ||
938 | if(baddr > (h->rows * h->cols)) | 941 | if(baddr > (h->rows * h->cols)) |
942 | + { | ||
943 | + errno = EINVAL; | ||
939 | return -1; | 944 | return -1; |
945 | + } | ||
940 | 946 | ||
941 | fa = get_field_attribute(h,baddr); | 947 | fa = get_field_attribute(h,baddr); |
942 | 948 |
src/lib3270/session.c
@@ -388,6 +388,25 @@ void check_session_handle(H3270 **hSession) | @@ -388,6 +388,25 @@ void check_session_handle(H3270 **hSession) | ||
388 | #endif // ANDROID | 388 | #endif // ANDROID |
389 | } | 389 | } |
390 | 390 | ||
391 | +LIB3270_INTERNAL int check_online_session(H3270 *hSession) { | ||
392 | + | ||
393 | + // Is the session valid? | ||
394 | + if(!hSession) | ||
395 | + { | ||
396 | + errno = EINVAL; | ||
397 | + return -1; | ||
398 | + } | ||
399 | + | ||
400 | + // Is it connected? | ||
401 | + if((int) hSession->cstate < (int)LIB3270_CONNECTED_INITIAL) | ||
402 | + { | ||
403 | + errno = ENOTCONN; | ||
404 | + return -1; | ||
405 | + } | ||
406 | + | ||
407 | + return 0; | ||
408 | +} | ||
409 | + | ||
391 | LIB3270_EXPORT H3270 * lib3270_get_default_session_handle(void) | 410 | LIB3270_EXPORT H3270 * lib3270_get_default_session_handle(void) |
392 | { | 411 | { |
393 | if(default_session) | 412 | if(default_session) |