Commit a58ef7adb543ce822e7040d46ac738befe3418e4

Authored by Perry Werneck
1 parent 83226739

Fixing status of "reconnect" action.

src/core/actions/table.c
... ... @@ -87,7 +87,7 @@
87 87 .activate = connect_host,
88 88  
89 89 .group = LIB3270_ACTION_GROUP_OFFLINE,
90   - .activatable = lib3270_is_disconnected
  90 + .activatable = lib3270_allow_reconnect // lib3270_is_disconnected
91 91 },
92 92  
93 93 {
... ... @@ -472,6 +472,20 @@
472 472 .activatable = lib3270_is_connected
473 473 },
474 474  
  475 + {
  476 + .name = "clear",
  477 + .type = LIB3270_ACTION_TYPE_GENERIC,
  478 +
  479 + .keys = NULL,
  480 + .icon = "edit-clear-all",
  481 + .label = N_("Clear"),
  482 + .summary = N_( "Clear AID key" ),
  483 + .activate = lib3270_clear,
  484 +
  485 + .group = LIB3270_ACTION_GROUP_ONLINE,
  486 + .activatable = lib3270_is_connected
  487 + },
  488 +
475 489 //
476 490 // Keyboard actions
477 491 //
... ... @@ -504,20 +518,6 @@
504 518 .activatable = lib3270_is_connected
505 519 },
506 520  
507   - {
508   - .name = "clear",
509   - .type = LIB3270_ACTION_TYPE_GENERIC,
510   -
511   - .keys = NULL,
512   - .icon = NULL,
513   - .label = N_("Clear"),
514   - .summary = N_( "Clear AID key" ),
515   - .activate = lib3270_clear,
516   -
517   - .group = LIB3270_ACTION_GROUP_ONLINE,
518   - .activatable = lib3270_is_connected
519   - },
520   -
521 521  
522 522 {
523 523 .name = "delete",
... ...
src/core/connect.c
... ... @@ -70,36 +70,48 @@
70 70  
71 71 #endif // HAVE_LIBSSL
72 72  
73   - int lib3270_reconnect(H3270 *hSession, int seconds)
  73 + int lib3270_allow_reconnect(H3270 *hSession)
74 74 {
75   - debug("%s",__FUNCTION__);
76   -
77   - FAIL_IF_ONLINE(hSession);
78   -
79 75 //
80 76 // Can't reconnect if already reconnecting *OR* there's an open popup
81   - // (to avoid open more than one connect error popup.
  77 + // (to avoid open more than one connect error popup).
82 78 //
83 79 if(hSession->auto_reconnect_inprogress || hSession->popups)
84   - return errno = EAGAIN;
  80 + {
  81 + errno = EBUSY;
  82 + return 0;
  83 + }
85 84  
86   - if(hSession->connection.sock > 0)
87   - return errno = EISCONN;
  85 + // Is the session disconnected?
  86 + if(!lib3270_is_disconnected(hSession))
  87 + {
  88 + errno = EISCONN;
  89 + return 0;
  90 + }
88 91  
  92 + // Do I have a defined host?
89 93 if(!(hSession->host.current && hSession->host.srvc))
90 94 {
91   - // No host info, try the default one.
92   - if(lib3270_set_url(hSession,NULL))
93   - {
94   - int err = errno;
95   - lib3270_write_event_trace(hSession,"Can't set default URL (%s)\n",strerror(err));
96   - return errno = err;
97   - }
98   -
99   - if(!(hSession->host.current && hSession->host.srvc))
100   - {
101   - return errno = EINVAL;
102   - }
  95 + errno = EINVAL;
  96 + return 0;
  97 + }
  98 +
  99 + if(hSession->connection.sock > 0)
  100 + {
  101 + errno = EISCONN;
  102 + return 0;
  103 + }
  104 +
  105 + return 1;
  106 + }
  107 +
  108 + int lib3270_reconnect(H3270 *hSession, int seconds)
  109 + {
  110 + debug("%s",__FUNCTION__);
  111 +
  112 + if(!lib3270_allow_reconnect(hSession))
  113 + {
  114 + return errno == 0 ? -1 : errno;
103 115 }
104 116  
105 117 #if defined(HAVE_LIBSSL)
... ...
src/core/host.c
... ... @@ -430,6 +430,9 @@ LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n)
430 430 // Notifica atualização
431 431 update_url(h);
432 432  
  433 + // The "reconnect" action is now available.
  434 + lib3270_action_group_notify(h, LIB3270_ACTION_GROUP_OFFLINE);
  435 +
433 436 return 0;
434 437 }
435 438  
... ...
src/core/session.c
... ... @@ -432,6 +432,8 @@ H3270 * lib3270_session_new(const char *model)
432 432 ft_init(hSession);
433 433 #endif
434 434  
  435 + lib3270_set_url(hSession,NULL); // Set default URL (if available).
  436 +
435 437 trace("%s finished",__FUNCTION__);
436 438  
437 439 errno = 0;
... ...
src/include/lib3270.h
... ... @@ -621,19 +621,28 @@
621 621 * @return Pointer to host URL set (internal data, do not change it)
622 622 *
623 623 */
624   - LIB3270_EXPORT const char * LIB3270_DEPRECATED(lib3270_get_host(const H3270 *h));
  624 + LIB3270_EXPORT const char * LIB3270_DEPRECATED(lib3270_get_host(const H3270 *h));
625 625  
  626 + /**
  627 + * @brief Check if the session can reconnect.
  628 + *
  629 + * @param hSession Session handle.
  630 + *
  631 + * @return zero if reconnect is unavailable (sets errno), non zero if available.
  632 + *
  633 + */
  634 + LIB3270_EXPORT int lib3270_allow_reconnect(H3270 *hSession);
626 635  
627 636 /**
628 637 * @brief Reconnect to host.
629 638 *
630   - * @param h Session handle.
  639 + * @param hSession Session handle.
631 640 * @param seconds Seconds to wait for connection.
632 641 *
633 642 * @return 0 for success, non zero if fails (sets errno).
634 643 *
635 644 */
636   - LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int seconds);
  645 + LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int seconds);
637 646  
638 647 /**
639 648 * @brief Connect by URL
... ... @@ -1031,6 +1040,8 @@
1031 1040 LIB3270_EXPORT const char ** lib3270_get_lunames(H3270 *hSession);
1032 1041  
1033 1042 LIB3270_EXPORT int lib3270_is_connected(const H3270 *h);
  1043 +
  1044 +
1034 1045 LIB3270_EXPORT int lib3270_is_disconnected(const H3270 *h);
1035 1046  
1036 1047 LIB3270_EXPORT int lib3270_is_unlocked(const H3270 *h);
... ...