diff --git a/src/core/actions/table.c b/src/core/actions/table.c index f85398b..c272efe 100644 --- a/src/core/actions/table.c +++ b/src/core/actions/table.c @@ -87,7 +87,7 @@ .activate = connect_host, .group = LIB3270_ACTION_GROUP_OFFLINE, - .activatable = lib3270_is_disconnected + .activatable = lib3270_allow_reconnect // lib3270_is_disconnected }, { @@ -472,6 +472,20 @@ .activatable = lib3270_is_connected }, + { + .name = "clear", + .type = LIB3270_ACTION_TYPE_GENERIC, + + .keys = NULL, + .icon = "edit-clear-all", + .label = N_("Clear"), + .summary = N_( "Clear AID key" ), + .activate = lib3270_clear, + + .group = LIB3270_ACTION_GROUP_ONLINE, + .activatable = lib3270_is_connected + }, + // // Keyboard actions // @@ -504,20 +518,6 @@ .activatable = lib3270_is_connected }, - { - .name = "clear", - .type = LIB3270_ACTION_TYPE_GENERIC, - - .keys = NULL, - .icon = NULL, - .label = N_("Clear"), - .summary = N_( "Clear AID key" ), - .activate = lib3270_clear, - - .group = LIB3270_ACTION_GROUP_ONLINE, - .activatable = lib3270_is_connected - }, - { .name = "delete", diff --git a/src/core/connect.c b/src/core/connect.c index 795ec3f..69d38e5 100644 --- a/src/core/connect.c +++ b/src/core/connect.c @@ -70,36 +70,48 @@ #endif // HAVE_LIBSSL - int lib3270_reconnect(H3270 *hSession, int seconds) + int lib3270_allow_reconnect(H3270 *hSession) { - debug("%s",__FUNCTION__); - - FAIL_IF_ONLINE(hSession); - // // Can't reconnect if already reconnecting *OR* there's an open popup - // (to avoid open more than one connect error popup. + // (to avoid open more than one connect error popup). // if(hSession->auto_reconnect_inprogress || hSession->popups) - return errno = EAGAIN; + { + errno = EBUSY; + return 0; + } - if(hSession->connection.sock > 0) - return errno = EISCONN; + // Is the session disconnected? + if(!lib3270_is_disconnected(hSession)) + { + errno = EISCONN; + return 0; + } + // Do I have a defined host? if(!(hSession->host.current && hSession->host.srvc)) { - // No host info, try the default one. - if(lib3270_set_url(hSession,NULL)) - { - int err = errno; - lib3270_write_event_trace(hSession,"Can't set default URL (%s)\n",strerror(err)); - return errno = err; - } - - if(!(hSession->host.current && hSession->host.srvc)) - { - return errno = EINVAL; - } + errno = EINVAL; + return 0; + } + + if(hSession->connection.sock > 0) + { + errno = EISCONN; + return 0; + } + + return 1; + } + + int lib3270_reconnect(H3270 *hSession, int seconds) + { + debug("%s",__FUNCTION__); + + if(!lib3270_allow_reconnect(hSession)) + { + return errno == 0 ? -1 : errno; } #if defined(HAVE_LIBSSL) diff --git a/src/core/host.c b/src/core/host.c index a268bd0..24394be 100644 --- a/src/core/host.c +++ b/src/core/host.c @@ -430,6 +430,9 @@ LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n) // Notifica atualização update_url(h); + // The "reconnect" action is now available. + lib3270_action_group_notify(h, LIB3270_ACTION_GROUP_OFFLINE); + return 0; } diff --git a/src/core/session.c b/src/core/session.c index ccc9edf..201536d 100644 --- a/src/core/session.c +++ b/src/core/session.c @@ -432,6 +432,8 @@ H3270 * lib3270_session_new(const char *model) ft_init(hSession); #endif + lib3270_set_url(hSession,NULL); // Set default URL (if available). + trace("%s finished",__FUNCTION__); errno = 0; diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 7a6a60a..2aacec7 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -621,19 +621,28 @@ * @return Pointer to host URL set (internal data, do not change it) * */ - LIB3270_EXPORT const char * LIB3270_DEPRECATED(lib3270_get_host(const H3270 *h)); + LIB3270_EXPORT const char * LIB3270_DEPRECATED(lib3270_get_host(const H3270 *h)); + /** + * @brief Check if the session can reconnect. + * + * @param hSession Session handle. + * + * @return zero if reconnect is unavailable (sets errno), non zero if available. + * + */ + LIB3270_EXPORT int lib3270_allow_reconnect(H3270 *hSession); /** * @brief Reconnect to host. * - * @param h Session handle. + * @param hSession Session handle. * @param seconds Seconds to wait for connection. * * @return 0 for success, non zero if fails (sets errno). * */ - LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int seconds); + LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int seconds); /** * @brief Connect by URL @@ -1031,6 +1040,8 @@ LIB3270_EXPORT const char ** lib3270_get_lunames(H3270 *hSession); LIB3270_EXPORT int lib3270_is_connected(const H3270 *h); + + LIB3270_EXPORT int lib3270_is_disconnected(const H3270 *h); LIB3270_EXPORT int lib3270_is_unlocked(const H3270 *h); -- libgit2 0.21.2