Commit 138676dc01b1b2fc60f3a4776abf4414141bf7e9

Authored by perry.werneck@gmail.com
1 parent 5da4b25d
Exists in master

Movendo dados de reconexão para a estrutura de sessão

latest/src/include/lib3270.h
... ... @@ -72,5 +72,28 @@
72 72 */
73 73 LIB3270_EXPORT void lib3270_register_schange(H3270 *h,LIB3270_STATE_CHANGE tx, void (*func)(H3270 *, int, void *),void *data);
74 74  
  75 + /**
  76 + * Network connect operation, keep main loop running
  77 + *
  78 + * Sets 'reconnect_host', 'current_host' and 'full_current_host' as
  79 + * side-effects.
  80 + *
  81 + * @param h Session handle.
  82 + * @param n Host ID
  83 + * @param wait Non zero to wait for connection to be ok.
  84 + *
  85 + * @return 0 for success, EAGAIN if auto-reconnect is in progress, EBUSY if connected, ENOTCONN if connection has failed, -1 on unexpected failure.
  86 + *
  87 + */
  88 + LIB3270_EXPORT int lib3270_connect(H3270 *h,const char *n, int wait);
  89 +
  90 + /**
  91 + * Reconnect.
  92 + *
  93 + * @param h Session handle.
  94 + * @param wait Non zero to wait for connection to be ok.
  95 + */
  96 + LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int wait);
  97 +
75 98  
76 99 #endif // LIB3270_H_INCLUDED
... ...
latest/src/include/lib3270/api.h
... ... @@ -169,7 +169,12 @@
169 169 int model_num;
170 170 char * termtype;
171 171  
172   - char * current_host;
  172 + char * current_host; /**< the hostname part, stripped of qualifiers, luname and port number */
  173 + char * full_current_host; /**< the entire string, for use in reconnecting */
  174 + char * reconnect_host;
  175 + char * qualified_host;
  176 + char auto_reconnect_inprogress;
  177 +
173 178 unsigned short current_port;
174 179  
175 180 // screen info
... ... @@ -556,8 +561,9 @@
556 561  
557 562 #include <lib3270/actions.h>
558 563  
559   - LIB3270_EXPORT int host_connect(const char *n, int wait);
560   - LIB3270_EXPORT int host_reconnect(int wait);
  564 + #define host_connect(n,wait) lib3270_connect(NULL,n,wait)
  565 + #define host_reconnect(w) lib3270_reconnect(NULL,w)
  566 +
561 567 LIB3270_EXPORT void host_disconnect(H3270 *h, int disable);
562 568  
563 569 #define register_schange(tx,func) lib3270_register_schange(NULL,tx,func,NULL)
... ...
latest/src/lib/host.c
... ... @@ -67,14 +67,14 @@ Boolean passthru_host = False;
67 67 Boolean ssl_host = False;
68 68 Boolean ever_3270 = False;
69 69  
70   -char *full_current_host = CN;
71   -unsigned short current_port;
72   -char *reconnect_host = CN;
73   -char *qualified_host = CN;
  70 +// char *full_current_host = CN;
  71 +//unsigned short current_port;
  72 +//char *reconnect_host = CN;
  73 +//char *qualified_host = CN;
74 74  
75 75 struct host *hosts = (struct host *)NULL;
76 76 static struct host *last_host = (struct host *)NULL;
77   -static Boolean auto_reconnect_inprogress = False;
  77 +// static Boolean auto_reconnect_inprogress = False;
78 78 static int net_sock = -1;
79 79  
80 80 // #if defined(X3270_DISPLAY)
... ... @@ -486,7 +486,7 @@ split_success:
486 486 return r;
487 487 }
488 488  
489   -static int do_connect(const char *n)
  489 +static int do_connect(H3270 *hSession, const char *n)
490 490 {
491 491 char nb[2048]; /* name buffer */
492 492 char *s; /* temporary */
... ... @@ -500,7 +500,7 @@ static int do_connect(const char *n)
500 500 const char *localprocess_cmd = NULL;
501 501 Boolean has_colons = False;
502 502  
503   - if (CONNECTED || auto_reconnect_inprogress)
  503 + if (CONNECTED || hSession->auto_reconnect_inprogress)
504 504 return 0;
505 505  
506 506 /* Skip leading blanks. */
... ... @@ -520,7 +520,7 @@ static int do_connect(const char *n)
520 520 *s-- = '\0';
521 521  
522 522 /* Remember this hostname, as the last hostname we connected to. */
523   - Replace(reconnect_host, NewString(nb));
  523 + Replace(hSession->reconnect_host, NewString(nb));
524 524  
525 525 // #if defined(X3270_DISPLAY)
526 526 // /* Remember this hostname in the recent connection list and file. */
... ... @@ -539,7 +539,7 @@ static int do_connect(const char *n)
539 539 /* Strip off and remember leading qualifiers. */
540 540 if ((s = split_host(nb, &ansi_host, &std_ds_host,
541 541 &passthru_host, &non_tn3270e_host, &ssl_host,
542   - &no_login_host, h3270.luname, &port,
  542 + &no_login_host, hSession->luname, &port,
543 543 &needed)) == CN)
544 544 return -1;
545 545  
... ... @@ -553,7 +553,7 @@ static int do_connect(const char *n)
553 553 Free(s);
554 554 if (!(s = split_host(target_name, &ansi_host,
555 555 &std_ds_host, &passthru_host, &non_tn3270e_host,
556   - &ssl_host, &no_login_host, h3270.luname, &port,
  556 + &ssl_host, &no_login_host, hSession->luname, &port,
557 557 &needed)))
558 558 return -1;
559 559 }
... ... @@ -571,21 +571,25 @@ static int do_connect(const char *n)
571 571 * and port number
572 572 * full_current_host is the entire string, for use in reconnecting
573 573 */
574   - if (n != full_current_host) {
575   - Replace(full_current_host, NewString(n));
  574 + if (n != hSession->full_current_host)
  575 + {
  576 + Replace(hSession->full_current_host, NewString(n));
576 577 }
577   - Replace(h3270.current_host, CN);
  578 +
  579 + Replace(hSession->current_host, CN);
  580 +
578 581 if (localprocess_cmd != CN) {
579 582 if (full_current_host[strlen(OptLocalProcess)] != '\0')
580   - h3270.current_host = NewString(full_current_host + strlen(OptLocalProcess) + 1);
  583 + hSession->current_host = NewString(full_current_host + strlen(OptLocalProcess) + 1);
581 584 else
582   - h3270.current_host = NewString("default shell");
  585 + hSession->current_host = NewString("default shell");
583 586 } else {
584   - h3270.current_host = s;
  587 + hSession->current_host = s;
585 588 }
586 589  
587 590 has_colons = (strchr(chost, ':') != NULL);
588   - Replace(qualified_host,
  591 +
  592 + Replace(hSession->qualified_host,
589 593 xs_buffer("%s%s%s%s:%s",
590 594 ssl_host? "L:": "",
591 595 has_colons? "[": "",
... ... @@ -593,6 +597,7 @@ static int do_connect(const char *n)
593 597 has_colons? "]": "",
594 598 port));
595 599  
  600 +
596 601 /* Attempt contact. */
597 602 ever_3270 = False;
598 603 net_sock = net_connect(chost, port, localprocess_cmd != CN, &resolving,
... ... @@ -648,29 +653,20 @@ static int do_connect(const char *n)
648 653 return 0;
649 654 }
650 655  
651   -/**
652   - * Network connect operation, keep main loop running
653   - *
654   - * Sets 'reconnect_host', 'current_host' and 'full_current_host' as
655   - * side-effects.
656   - *
657   - * @param n Host ID
658   - * @param wait Non zero to wait for connection to be ok.
659   - *
660   - * @return 0 for success, EAGAIN if auto-reconnect is in progress, EBUSY if connected, ENOTCONN if connection has failed, -1 on unexpected failure.
661   - *
662   - */
663   -int host_connect(const char *n, int wait)
  656 +int lib3270_connect(H3270 *h, const char *n, int wait)
664 657 {
  658 + if(!h)
  659 + h = &h3270;
  660 +
665 661 RunPendingEvents(0);
666 662  
667   - if(auto_reconnect_inprogress)
  663 + if(h->auto_reconnect_inprogress)
668 664 return EAGAIN;
669 665  
670 666 if(PCONNECTED)
671 667 return EBUSY;
672 668  
673   - if(do_connect(n))
  669 + if(do_connect(h,n))
674 670 return -1;
675 671  
676 672 if(wait)
... ... @@ -697,9 +693,9 @@ int host_connect(const char *n, int wait)
697 693 */
698 694 static void try_reconnect(H3270 *session)
699 695 {
700   - WriteLog("3270","Starting auto-reconnect (Host: %s)",reconnect_host ? reconnect_host : "-");
701   - auto_reconnect_inprogress = False;
702   - host_reconnect(0);
  696 + WriteLog("3270","Starting auto-reconnect (Host: %s)",session->reconnect_host ? session->reconnect_host : "-");
  697 + session->auto_reconnect_inprogress = False;
  698 + lib3270_reconnect(session,0);
703 699 }
704 700 #endif /*]*/
705 701  
... ... @@ -713,11 +709,11 @@ void host_disconnect(H3270 *h, int failed)
713 709 net_disconnect();
714 710 net_sock = -1;
715 711 #if defined(LIB3270)
716   - Trace("Disconnected (Failed: %d Reconnect: %d in_progress: %d)",failed,toggled(RECONNECT),auto_reconnect_inprogress);
717   - if (toggled(RECONNECT) && !auto_reconnect_inprogress)
  712 + Trace("Disconnected (Failed: %d Reconnect: %d in_progress: %d)",failed,toggled(RECONNECT),h->auto_reconnect_inprogress);
  713 + if (toggled(RECONNECT) && !h->auto_reconnect_inprogress)
718 714 {
719 715 /* Schedule an automatic reconnection. */
720   - auto_reconnect_inprogress = True;
  716 + h->auto_reconnect_inprogress = True;
721 717 (void) AddTimeOut(failed? RECONNECT_ERR_MS: RECONNECT_MS, &h3270, try_reconnect);
722 718 }
723 719 #endif
... ... @@ -1038,26 +1034,27 @@ void lib3270_st_changed(H3270 *h, int tx, int mode)
1038 1034 }
1039 1035 }
1040 1036  
1041   -#if defined(X3270_MENUS) || defined(LIB3270) /*[*/
1042   -
1043   -LIB3270_EXPORT int host_reconnect(int wait)
  1037 +LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int wait)
1044 1038 {
1045 1039 int rc;
1046 1040  
  1041 + if(!h)
  1042 + h = &h3270;
  1043 +
1047 1044 if (CONNECTED || HALF_CONNECTED)
1048 1045 return EBUSY;
1049 1046  
1050   - if (h3270.current_host == CN)
  1047 + if (h->current_host == CN)
1051 1048 return ENOENT;
1052 1049  
1053   - if (auto_reconnect_inprogress)
  1050 + if (h->auto_reconnect_inprogress)
1054 1051 return EBUSY;
1055 1052  
1056   - rc = host_connect(reconnect_host,wait);
  1053 + rc = lib3270_connect(h,h->reconnect_host,wait);
1057 1054  
1058 1055 if(rc)
1059 1056 {
1060   - auto_reconnect_inprogress = False;
  1057 + h->auto_reconnect_inprogress = False;
1061 1058 return rc;
1062 1059 }
1063 1060  
... ... @@ -1071,7 +1068,6 @@ LIB3270_EXPORT int host_reconnect(int wait)
1071 1068  
1072 1069 return 0;
1073 1070 }
1074   -#endif /*]*/
1075 1071  
1076 1072 LIB3270_EXPORT const char * get_connected_lu(H3270 *h)
1077 1073 {
... ...
latest/src/lib/printer.c
... ... @@ -238,7 +238,7 @@ printer_start(const char *lu)
238 238 }
239 239 s = cmdline;
240 240 while ((s = strstr(s, "%H%")) != CN) {
241   - cmd_len += strlen(qualified_host) - 3;
  241 + cmd_len += strlen(h3270.qualified_host) - 3;
242 242 s += 3;
243 243 }
244 244 #if !defined(_WIN32) /*[*/
... ... @@ -273,7 +273,7 @@ printer_start(const char *lu)
273 273 s += 2;
274 274 continue;
275 275 } else if (!strncmp(s+1, "H%", 2)) {
276   - (void) strcat(cmd_text, qualified_host);
  276 + (void) strcat(cmd_text, h3270.qualified_host);
277 277 s += 2;
278 278 continue;
279 279 #if !defined(_WIN32) /*[*/
... ...
latest/src/lib/screen.c
... ... @@ -816,7 +816,7 @@ relabel(H3270 *session, int ignored unused, void *dunno)
816 816 screen_title(profile_name);
817 817 else
818 818 #endif
819   - screen_title(reconnect_host);
  819 + screen_title(session->reconnect_host);
820 820  
821 821 }
822 822 else
... ...