From 2be8012abe9f2e706593fba960d377ab46cd4a3c Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 26 Dec 2018 09:57:12 -0200 Subject: [PATCH] + Adding "set_luname" method. --- src/include/lib3270.h | 4 +++- src/lib3270/host.c | 13 ++++++++++--- src/lib3270/private.h | 4 ++++ src/lib3270/session.c | 19 +++++++++++++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 4657a8a..3c8617c 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -862,7 +862,9 @@ * @return conected LU name or NULL if not connected. * */ - LIB3270_EXPORT const char * lib3270_get_luname(H3270 *h); + LIB3270_EXPORT const char * lib3270_get_luname(H3270 *hSession); + + LIB3270_EXPORT int lib3270_set_luname(H3270 *hSession, const char *luname); LIB3270_EXPORT int lib3270_has_active_script(H3270 *h); LIB3270_EXPORT int lib3270_get_typeahead(H3270 *h); diff --git a/src/lib3270/host.c b/src/lib3270/host.c index 219d94f..29d3b06 100644 --- a/src/lib3270/host.c +++ b/src/lib3270/host.c @@ -238,9 +238,16 @@ LIB3270_EXPORT const char * lib3270_get_url(H3270 *hSession) return hSession->host.full; } +LIB3270_EXPORT int lib3270_set_luname(H3270 *hSession, const char *luname) +{ + FAIL_IF_ONLINE(hSession); + strncpy(hSession->luname,luname,LIB3270_LUNAME_LENGTH); + return 0; +} + LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n) { - CHECK_SESSION_HANDLE(h); + FAIL_IF_ONLINE(h); if(n && n != h->host.full) { @@ -326,14 +333,14 @@ LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n) if(!(strcasecmp(var,"lu") && strcasecmp(var,"luname"))) { - strncpy(h->luname,val,LIB3270_LUNAME_LENGTH); + lib3270_set_luname(h, val); + // strncpy(h->luname,val,LIB3270_LUNAME_LENGTH); } else { lib3270_write_log(h,"","Ignoring invalid URL attribute \"%s\"",var); } - } } diff --git a/src/lib3270/private.h b/src/lib3270/private.h index 8d88b43..5a120b6 100644 --- a/src/lib3270/private.h +++ b/src/lib3270/private.h @@ -637,10 +637,14 @@ LIB3270_INTERNAL int lib3270_default_event_dispatcher(H3270 *hSession, int block #endif // DEBUG LIB3270_INTERNAL int check_online_session(H3270 *hSession); +LIB3270_INTERNAL int check_offline_session(H3270 *hSession); /// @brief Returns -1 if the session is invalid or not online (sets errno). #define FAIL_IF_NOT_ONLINE(x) if(check_online_session(x)) return -1; +/// @brief Returns -1 if the session is invalid or online (sets errno). +#define FAIL_IF_ONLINE(x) if(check_offline_session(x)) return -1; + LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on); #if defined(HAVE_LIBSSL) /*[*/ diff --git a/src/lib3270/session.c b/src/lib3270/session.c index cb245d1..1cfc42f 100644 --- a/src/lib3270/session.c +++ b/src/lib3270/session.c @@ -408,6 +408,25 @@ LIB3270_INTERNAL int check_online_session(H3270 *hSession) { return 0; } +LIB3270_INTERNAL int check_offline_session(H3270 *hSession) { + + // Is the session valid? + if(!hSession) + { + errno = EINVAL; + return -1; + } + + // Is it connected? + if((int) hSession->cstate >= (int)LIB3270_CONNECTED_INITIAL) + { + errno = EBUSY; + return -1; + } + + return 0; +} + LIB3270_EXPORT H3270 * lib3270_get_default_session_handle(void) { if(default_session) -- libgit2 0.21.2