Commit 74bc6c32e3b0eacac47a6470b453255b45d07e06

Authored by perry.werneck@gmail.com
1 parent 6ef96717
Exists in master

Mais um lote de funções ajustadas para multi-sessão

latest/src/gtk2/screen.c
... ... @@ -65,7 +65,7 @@
65 65 static int addch(int row, int col, unsigned char c, unsigned short attr);
66 66 static void set_charset(char *dcs);
67 67  
68   - static void erase(void);
  68 + static void erase(H3270 *session);
69 69 static void display(H3270 *session);
70 70  
71 71 static int SetSuspended(int state);
... ... @@ -118,7 +118,7 @@
118 118 set_lu, // void (*lu)(const char *lu);
119 119 set_oia, // void (*set)(OIA_FLAG id, unsigned char on);
120 120  
121   - erase, // void (*erase)(void);
  121 + erase, // void (*erase)(H3270 *session);
122 122 display, // void (*display)(H3270 *session);
123 123 #ifdef HAVE_ALTSCREEN
124 124 view_changed, // void (*set_viewsize)(H3270 *session, unsigned short rows, unsigned short cols);
... ... @@ -337,7 +337,7 @@
337 337 * Erase screen.
338 338 *
339 339 */
340   - static void erase(void)
  340 + static void erase(H3270 *session)
341 341 {
342 342 int f;
343 343  
... ...
latest/src/include/lib3270.h
... ... @@ -112,6 +112,23 @@
112 112  
113 113 } LIB3270_FLAG;
114 114  
  115 + /**
  116 + * connection state
  117 + */
  118 + typedef enum lib3270_cstate
  119 + {
  120 + LIB3270_NOT_CONNECTED, /**< no socket, disconnected */
  121 + LIB3270_RESOLVING, /**< resolving hostname */
  122 + LIB3270_PENDING, /**< connection pending */
  123 + LIB3270_CONNECTED_INITIAL, /**< connected, no mode yet */
  124 + LIB3270_CONNECTED_ANSI, /**< connected in NVT ANSI mode */
  125 + LIB3270_CONNECTED_3270, /**< connected in old-style 3270 mode */
  126 + LIB3270_CONNECTED_INITIAL_E, /**< connected in TN3270E mode, unnegotiated */
  127 + LIB3270_CONNECTED_NVT, /**< connected in TN3270E mode, NVT mode */
  128 + LIB3270_CONNECTED_SSCP, /**< connected in TN3270E mode, SSCP-LU mode */
  129 + LIB3270_CONNECTED_TN3270E /**< connected in TN3270E mode, 3270 mode */
  130 + } LIB3270_CSTATE;
  131 +
115 132 #include <lib3270/api.h>
116 133  
117 134 /**
... ... @@ -191,8 +208,7 @@
191 208 * @return Connection state.
192 209 *
193 210 */
194   - LIB3270_EXPORT enum cstate lib3270_get_connection_state(H3270 *h);
195   -
  211 + LIB3270_EXPORT LIB3270_CSTATE lib3270_get_connection_state(H3270 *h);
196 212  
197 213 /**
198 214 * Set string at current cursor position.
... ... @@ -273,7 +289,17 @@
273 289  
274 290  
275 291 LIB3270_EXPORT LIB3270_STATUS lib3270_get_oia_status(H3270 *h);
  292 +
  293 + /**
  294 + * Get connected LU name
  295 + *
  296 + * @param h Session handle.
  297 + *
  298 + * @return conected LU name or NULL if not connected.
  299 + *
  300 + */
276 301 LIB3270_EXPORT const char * lib3270_get_luname(H3270 *h);
  302 +
277 303 LIB3270_EXPORT const char * lib3270_get_host(H3270 *h);
278 304  
279 305 #define lib3270_has_printer_session(h) (h->oia_flag[LIB3270_FLAG_PRINTER] != 0)
... ...
latest/src/include/lib3270/api.h
... ... @@ -146,19 +146,17 @@
146 146 #define LIB3270_STATE_CHANGE LIB3270_STATE
147 147  
148 148 /** connection state */
149   - enum cstate
150   - {
151   - NOT_CONNECTED, /**< no socket, unknown mode */
152   - RESOLVING, /**< resolving hostname */
153   - PENDING, /**< connection pending */
154   - CONNECTED_INITIAL, /**< connected, no mode yet */
155   - CONNECTED_ANSI, /**< connected in NVT ANSI mode */
156   - CONNECTED_3270, /**< connected in old-style 3270 mode */
157   - CONNECTED_INITIAL_E, /**< connected in TN3270E mode, unnegotiated */
158   - CONNECTED_NVT, /**< connected in TN3270E mode, NVT mode */
159   - CONNECTED_SSCP, /**< connected in TN3270E mode, SSCP-LU mode */
160   - CONNECTED_TN3270E /**< connected in TN3270E mode, 3270 mode */
161   - };
  149 + #define cstate LIB3270_CSTATE
  150 + #define NOT_CONNECTED LIB3270_NOT_CONNECTED
  151 + #define RESOLVING LIB3270_RESOLVING
  152 + #define PENDING LIB3270_PENDING
  153 + #define CONNECTED_INITIAL LIB3270_CONNECTED_INITIAL
  154 + #define CONNECTED_ANSI LIB3270_CONNECTED_ANSI
  155 + #define CONNECTED_3270 LIB3270_CONNECTED_3270
  156 + #define CONNECTED_INITIAL_E LIB3270_CONNECTED_INITIAL_E
  157 + #define CONNECTED_NVT LIB3270_CONNECTED_NVT
  158 + #define CONNECTED_SSCP LIB3270_CONNECTED_SSCP
  159 + #define CONNECTED_TN3270E LIB3270_CONNECTED_TN3270E
162 160  
163 161 typedef enum _LIB3270_STATUS
164 162 {
... ... @@ -204,7 +202,7 @@
204 202 int secure_connection;
205 203 int sock; /**< Network socket */
206 204 int net_sock;
207   - enum cstate cstate; /**< Connection state */
  205 + LIB3270_CSTATE cstate; /**< Connection state */
208 206  
209 207 #if defined(_WIN32) /*[*/
210 208 HANDLE sock_handle;
... ... @@ -278,6 +276,7 @@
278 276 void (*set_timer)(H3270 *session, unsigned char on);
279 277 void (*update_luname)(H3270 *session, const char *name);
280 278 void (*update_status)(H3270 *session, LIB3270_STATUS id);
  279 + void (*erase)(H3270 *session);
281 280  
282 281 };
283 282  
... ... @@ -514,7 +513,7 @@
514 513 void (*lu)(H3270 *session, const char *lu);
515 514 void (*set_oia)(H3270 *session, OIA_FLAG id, unsigned char on);
516 515  
517   - void (*erase)(void);
  516 + void (*erase)(H3270 *session);
518 517 void (*display)(H3270 *session);
519 518 void (*set_viewsize)(H3270 *session, unsigned short rows, unsigned short cols);
520 519  
... ...
latest/src/lib/XtGlue.c
... ... @@ -897,7 +897,7 @@ int LIB3270_EXPORT lib3270_register_io_handlers(const struct lib3270_io_callback
897 897  
898 898 }
899 899  
900   -LIB3270_EXPORT enum cstate lib3270_get_connection_state(H3270 *h)
  900 +LIB3270_EXPORT LIB3270_CSTATE lib3270_get_connection_state(H3270 *h)
901 901 {
902 902 CHECK_SESSION_HANDLE(h);
903 903 return h->cstate;
... ...
latest/src/lib/host.c
... ... @@ -724,251 +724,36 @@ void host_disconnect(H3270 *h, int failed)
724 724 }
725 725  
726 726 /* The host has entered 3270 or ANSI mode, or switched between them. */
727   -void
728   -host_in3270(enum cstate new_cstate)
  727 +void host_in3270(H3270 *session, LIB3270_CSTATE new_cstate)
729 728 {
730 729 Boolean now3270 = (new_cstate == CONNECTED_3270 ||
731 730 new_cstate == CONNECTED_SSCP ||
732 731 new_cstate == CONNECTED_TN3270E);
733 732  
734   - h3270.cstate = new_cstate;
735   - h3270.ever_3270 = now3270;
736   - st_changed(ST_3270_MODE, now3270);
  733 + session->cstate = new_cstate;
  734 + session->ever_3270 = now3270;
  735 + lib3270_st_changed(session, ST_3270_MODE, now3270);
737 736 }
738 737  
739   -void
740   -host_connected(void)
  738 +void host_connected(H3270 *session)
741 739 {
742   - h3270.cstate = CONNECTED_INITIAL;
743   - st_changed(ST_CONNECT, True);
744   -
745   -#if defined(X3270_DISPLAY) /*[*/
746   - if (toggled(RECONNECT) && error_popup_visible())
747   - popdown_an_error();
748   -#endif /*]*/
749   -}
  740 + session->cstate = CONNECTED_INITIAL;
  741 + lib3270_st_changed(session, ST_CONNECT, True);
750 742  
751 743 /*
752 744 #if defined(X3270_DISPLAY)
753   -// Comparison function for the qsort.
754   -static int
755   -host_compare(const void *e1, const void *e2)
756   -{
757   - const struct host *h1 = *(const struct host **)e1;
758   - const struct host *h2 = *(const struct host **)e2;
759   - int r;
760   -
761   - if (h1->connect_time > h2->connect_time)
762   - r = -1;
763   - else if (h1->connect_time < h2->connect_time)
764   - r = 1;
765   - else
766   - r = 0;
767   -#if defined(CFDEBUG)
768   - printf("%s %ld %d %s %ld\n",
769   - h1->name, h1->connect_time,
770   - r,
771   - h2->name, h2->connect_time);
772   -#endif
773   - return r;
774   -}
775   -#endif
776   -
777   -
778   -#if defined(CFDEBUG)
779   -static void
780   -dump_array(const char *when, struct host **array, int nh)
781   -{
782   - int i;
783   -
784   - printf("%s\n", when);
785   - for (i = 0; i < nh; i++) {
786   - printf(" %15s %ld\n", array[i]->name, array[i]->connect_time);
787   - }
788   -}
789   -#endif
790   -
791   -
792   -#if defined(X3270_DISPLAY)
793   -static void
794   -save_recent(const char *hn)
795   -{
796   - char *lcf_name = CN;
797   - FILE *lcf = (FILE *)NULL;
798   - struct host *h;
799   - struct host *rest = (struct host *)NULL;
800   - int n_ent = 0;
801   - struct host *h_array[(MAX_RECENT * 2) + 1];
802   - int nh = 0;
803   - int i, j;
804   - time_t t = time((time_t *)NULL);
805   -
806   - // Allocate a new entry.
807   - if (hn != CN) {
808   - h = (struct host *)Malloc(sizeof(*h));
809   - h->name = NewString(hn);
810   - h->parents = NULL;
811   - h->hostname = NewString(hn);
812   - h->entry_type = RECENT;
813   - h->loginstring = CN;
814   - h->connect_time = t;
815   - h_array[nh++] = h;
816   - }
817   -
818   - // Put the existing entries into the array.
819   - for (h = hosts; h != (struct host *)NULL; h = h->next) {
820   - if (h->entry_type != RECENT)
821   - break;
822   - h_array[nh++] = h;
823   - }
824   -
825   - // Save the ibm_hosts entries for later.
826   - rest = h;
827   - if (rest != (struct host *)NULL)
828   - rest->prev = (struct host *)NULL;
829   -
830   - //
831   - // Read the last-connection file, to capture the any changes made by
832   - // other instances of x3270.
833   - //
834   - if (appres.connectfile_name != CN &&
835   - strcasecmp(appres.connectfile_name, "none")) {
836   - lcf_name = do_subst(appres.connectfile_name, True, True);
837   - lcf = fopen(lcf_name, "r");
838   - }
839   - if (lcf != (FILE *)NULL) {
840   - char buf[1024];
841   -
842   - while (fgets(buf, sizeof(buf), lcf) != CN) {
843   - int sl;
844   - time_t connect_time;
845   - char *ptr;
846   -
847   - // Pick apart the entry.
848   - sl = strlen(buf);
849   - if (buf[sl - 1] == '\n')
850   - buf[sl-- - 1] = '\0';
851   - if (!sl ||
852   - buf[0] == '#' ||
853   - (connect_time = strtoul(buf, &ptr, 10)) == 0L ||
854   - ptr == buf ||
855   - *ptr != ' ' ||
856   - !*(ptr + 1))
857   - continue;
858   -
859   - h = (struct host *)Malloc(sizeof(*h));
860   - h->name = NewString(ptr + 1);
861   - h->parents = NULL;
862   - h->hostname = NewString(ptr + 1);
863   - h->entry_type = RECENT;
864   - h->loginstring = CN;
865   - h->connect_time = connect_time;
866   - h_array[nh++] = h;
867   - if (nh > (MAX_RECENT * 2) + 1)
868   - break;
869   - }
870   - fclose(lcf);
871   - }
872   -
873   - // Sort the array, in reverse order by connect time.
874   -#if defined(CFDEBUG)
875   - dump_array("before", h_array, nh);
876   -#endif
877   - qsort(h_array, nh, sizeof(struct host *), host_compare);
878   -#if defined(CFDEBUG)
879   - dump_array("after", h_array, nh);
880   -#endif
881   -
882   - //
883   - // Filter out duplicate host names, and limit the array to
884   - //MAX_RECENT entries total.
885   - //
886   - hosts = (struct host *)NULL;
887   - last_host = (struct host *)NULL;
888   - for (i = 0; i < nh; i++) {
889   - h = h_array[i];
890   - if (h == (struct host *)NULL)
891   - continue;
892   - h->next = (struct host *)NULL;
893   - if (last_host != (struct host *)NULL)
894   - last_host->next = h;
895   - h->prev = last_host;
896   - last_host = h;
897   - if (hosts == (struct host *)NULL)
898   - hosts = h;
899   - n_ent++;
900   -
901   - // Zap the duplicates.
902   - for (j = i+1; j < nh; j++) {
903   - if (h_array[j] &&
904   - (n_ent >= MAX_RECENT ||
905   - !strcmp(h_array[i]->name, h_array[j]->name))) {
906   -#if defined(CFDEBUG)
907   - printf("%s is a dup of %s\n",
908   - h_array[j]->name, h_array[i]->name);
909   -#endif
910   - Free(h_array[j]->name);
911   - Free(h_array[j]->hostname);
912   - Free(h_array[j]);
913   - h_array[j] = (struct host *)NULL;
914   - }
915   - }
916   - }
917   -
918   - // Re-attach the ibm_hosts entries to the end.
919   - if (rest != (struct host *)NULL) {
920   - if (last_host != (struct host *)NULL) {
921   - last_host->next = rest;
922   - } else {
923   - hosts = rest;
924   - }
925   - rest->prev = last_host;
926   - }
927   -
928   - // If there's been a change, rewrite the file.
929   - if (hn != CN &&
930   - appres.connectfile_name != CN &&
931   - strcasecmp(appres.connectfile_name, "none")) {
932   - lcf = fopen(lcf_name, "w");
933   - if (lcf != (FILE *)NULL) {
934   - fprintf(lcf, "# Created %s# by %s\n", ctime(&t), build);
935   - for (h = hosts; h != (struct host *)NULL; h = h->next) {
936   - if (h->entry_type != RECENT)
937   - break;
938   - (void) fprintf(lcf, "%lu %s\n", h->connect_time,
939   - h->name);
940   - }
941   - fclose(lcf);
942   - }
943   - }
944   - if (lcf_name != CN)
945   - Free(lcf_name);
946   -}
  745 + if (toggled(RECONNECT) && error_popup_visible())
  746 + popdown_an_error();
947 747 #endif
948 748 */
949   -
950   -/* Support for state change callbacks. */
951   -
952   -/*
953   -struct st_callback
954   -{
955   - struct st_callback * next;
956   - H3270 * session;
957   - void * data;
958   - void (*func)(H3270 *, int, void *);
959   -};
960   -
961   -static struct st_callback *st_callbacks[N_ST];
962   -static struct st_callback *st_last[N_ST];
963   -*/
  749 +}
964 750  
965 751 /* Register a function interested in a state change. */
966 752 LIB3270_EXPORT void lib3270_register_schange(H3270 *h,LIB3270_STATE_CHANGE tx, void (*func)(H3270 *, int, void *),void *data)
967 753 {
968 754 struct lib3270_state_callback *st;
969 755  
970   - if(!h)
971   - h = &h3270;
  756 + CHECK_SESSION_HANDLE(h);
972 757  
973 758 st = (struct lib3270_state_callback *)Malloc(sizeof(*st));
974 759  
... ... @@ -1006,8 +791,7 @@ void lib3270_st_changed(H3270 *h, int tx, int mode)
1006 791 {
1007 792 struct lib3270_state_callback *st;
1008 793  
1009   - if(!h)
1010   - h = &h3270;
  794 + CHECK_SESSION_HANDLE(h);
1011 795  
1012 796 for (st = h->st_callbacks[tx];st != (struct lib3270_state_callback *)NULL;st = st->next)
1013 797 {
... ... @@ -1019,8 +803,7 @@ LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int wait)
1019 803 {
1020 804 int rc;
1021 805  
1022   - if(!h)
1023   - h = &h3270;
  806 + CHECK_SESSION_HANDLE(h);
1024 807  
1025 808 if (CONNECTED || HALF_CONNECTED)
1026 809 return EBUSY;
... ...
latest/src/lib/hostc.h
... ... @@ -30,16 +30,11 @@
30 30 };
31 31 extern struct host *hosts;
32 32  
33   -/*
34   - extern void Connect_action(Widget w, XEvent *event, String *params, Cardinal *num_params);
35   - extern void Disconnect_action(Widget w, XEvent *event, String *params, Cardinal *num_params);
36   -*/
37   -
38 33 #define st_changed(tx,mode) lib3270_st_changed(NULL,tx,mode)
39 34  
40 35 LIB3270_INTERNAL void lib3270_st_changed(H3270 *h, int tx, int mode);
41 36 LIB3270_INTERNAL void hostfile_init(void);
42   - LIB3270_INTERNAL void host_connected(void);
43   - LIB3270_INTERNAL void host_in3270(enum cstate);
  37 + LIB3270_INTERNAL void host_connected(H3270 *session);
  38 + LIB3270_INTERNAL void host_in3270(H3270 *session, LIB3270_CSTATE);
44 39  
45 40  
... ...
latest/src/lib/macros.c
... ... @@ -71,8 +71,8 @@
71 71 #define DECLARE_XLAT_STATE(x) { x, #x }
72 72 static const struct _xlat_state
73 73 {
74   - enum cstate state;
75   - const char *ret;
  74 + LIB3270_CSTATE state;
  75 + const char * ret;
76 76 } xlat_state[] =
77 77 {
78 78 DECLARE_XLAT_STATE( NOT_CONNECTED ),
... ... @@ -89,7 +89,7 @@
89 89  
90 90 int f;
91 91  
92   - enum cstate state = lib3270_get_connection_state(h);
  92 + LIB3270_CSTATE state = lib3270_get_connection_state(h);
93 93  
94 94 for(f=0;f < (sizeof(xlat_state)/sizeof(struct _xlat_state)); f++)
95 95 {
... ...
latest/src/lib/screen.c
... ... @@ -144,6 +144,9 @@ int screen_init(H3270 *session)
144 144 if(callbacks->status)
145 145 session->update_status = callbacks->status;
146 146  
  147 + if(callbacks->erase)
  148 + session->erase = callbacks->erase;
  149 +
147 150 if(callbacks->init())
148 151 {
149 152 popup_an_error("Can't initialize terminal.");
... ... @@ -278,15 +281,11 @@ static unsigned short calc_attrs(int baddr, int fa_addr, int fa)
278 281 /* Erase screen */
279 282 void screen_erase(H3270 *session)
280 283 {
281   - /* If the application supplies a callback use it! */
282   - if(callbacks && callbacks->erase)
283   - {
284   - callbacks->erase();
285   - return;
286   - }
287   -
288   - /* No callback, just redraw */
289   - screen_update(session,0,session->rows * session->cols);
  284 + /* If the application supplies a callback use it!, if not just redraw with blanks */
  285 + if(session->erase)
  286 + session->erase(session);
  287 + else
  288 + screen_update(session,0,session->rows * session->cols);
290 289 }
291 290  
292 291 LIB3270_EXPORT void lib3270_get_screen_size(H3270 *h, int *r, int *c)
... ...
latest/src/lib/telnet.c
... ... @@ -798,7 +798,7 @@ static void net_connected(H3270 *session)
798 798 trace_dsn("TLS/SSL tunneled connection complete. Connection is now secure.\n");
799 799  
800 800 /* Tell everyone else again. */
801   - host_connected();
  801 + host_connected(session);
802 802 }
803 803 #endif /*]*/
804 804  
... ... @@ -862,7 +862,7 @@ connection_complete(void)
862 862 return;
863 863 }
864 864 #endif /*]*/
865   - host_connected();
  865 + host_connected(&h3270);
866 866 net_connected(&h3270);
867 867 }
868 868  
... ... @@ -1051,7 +1051,7 @@ void net_input(H3270 *session)
1051 1051 host_disconnect(session,True);
1052 1052 return;
1053 1053 }
1054   - host_connected();
  1054 + host_connected(session);
1055 1055 net_connected(session);
1056 1056 }
1057 1057  
... ... @@ -1188,7 +1188,7 @@ telnet_fsm(unsigned char c)
1188 1188 if (linemode)
1189 1189 cooked_init();
1190 1190 #endif /*]*/
1191   - host_in3270(CONNECTED_ANSI);
  1191 + host_in3270(&h3270,CONNECTED_ANSI);
1192 1192 kybdlock_clr(KL_AWAITING_FIRST, "telnet_fsm");
1193 1193 status_reset(NULL);
1194 1194 ps_process();
... ... @@ -2391,7 +2391,7 @@ do_lnext(char c)
2391 2391 static void
2392 2392 check_in3270(void)
2393 2393 {
2394   - enum cstate new_cstate = NOT_CONNECTED;
  2394 + LIB3270_CSTATE new_cstate = NOT_CONNECTED;
2395 2395 #if defined(X3270_TRACE) /*[*/
2396 2396 static const char *state_name[] = {
2397 2397 "unconnected",
... ... @@ -2480,7 +2480,7 @@ check_in3270(void)
2480 2480 }
2481 2481 #endif /*]*/
2482 2482 trace_dsn("Now operating in %s mode.\n",state_name[new_cstate]);
2483   - host_in3270(new_cstate);
  2483 + host_in3270(&h3270,new_cstate);
2484 2484 }
2485 2485 }
2486 2486  
... ... @@ -3386,7 +3386,7 @@ continue_tls(unsigned char *sbbuf, int len)
3386 3386 trace_dsn("TLS/SSL negotiated connection complete. Connection is now secure.\n");
3387 3387  
3388 3388 /* Tell the world that we are (still) connected, now in secure mode. */
3389   - host_connected();
  3389 + host_connected(&h3270);
3390 3390 }
3391 3391  
3392 3392 #endif /*]*/
... ...
latest/src/plugins/rexx/network.c
... ... @@ -91,8 +91,8 @@
91 91  
92 92 static const struct _xlat_state
93 93 {
94   - enum cstate state;
95   - const gchar *ret;
  94 + LIB3270_CSTATE state;
  95 + const gchar * ret;
96 96 } xlat_state[] =
97 97 {
98 98 DECLARE_XLAT_STATE( NOT_CONNECTED ),
... ... @@ -108,7 +108,7 @@
108 108 };
109 109  
110 110 int f;
111   - enum cstate state;
  111 + LIB3270_CSTATE state;
112 112  
113 113 if(Argc != 0)
114 114 return RXFUNC_BADCALL;
... ...