Commit 4041ada31718ecd9e1266ece7268fd319c0a418c

Authored by perry.werneck@gmail.com
1 parent ff35e951

Simplificando opções de conexão

src/include/lib3270.h
@@ -204,18 +204,6 @@ @@ -204,18 +204,6 @@
204 204
205 205
206 /** 206 /**
207 - * Connect options.  
208 - *  
209 - */  
210 - typedef enum _LIB3270_CONNECT_OPTION  
211 - {  
212 - LIB3270_CONNECT_OPTION_DEFAULTS = 0x0000, /**< Default connection options */  
213 - LIB3270_CONNECT_OPTION_SSL = 0x0001, /**< Secure connection */  
214 - LIB3270_CONNECT_OPTION_WAIT = 0x0002, /**< Wait for screen ready */  
215 -  
216 - } LIB3270_CONNECT_OPTION;  
217 -  
218 - /**  
219 * Cursor modes. 207 * Cursor modes.
220 * 208 *
221 * Cursor modes set by library; an application can us it 209 * Cursor modes set by library; an application can us it
@@ -256,9 +244,12 @@ @@ -256,9 +244,12 @@
256 */ 244 */
257 typedef enum lib3270_option 245 typedef enum lib3270_option
258 { 246 {
259 - LIB3270_OPTION_KYBD_AS400 = 0x0001, /**< Prefix every PF with PA1 */ 247 + LIB3270_OPTION_DEFAULTS = 0x0000,
  248 + LIB3270_OPTION_AS400 = 0x0001, /**< Prefix every PF with PA1 */
260 LIB3270_OPTION_TSO = 0x0002, /**< Host is TSO? */ 249 LIB3270_OPTION_TSO = 0x0002, /**< Host is TSO? */
  250 + LIB3270_OPTION_SSL = 0x0004,
261 251
  252 + LIB3270_OPTION_WAIT = 0x8000 /**< Wait for session ready on connect ? */
262 } LIB3270_OPTION; 253 } LIB3270_OPTION;
263 254
264 255
@@ -430,12 +421,12 @@ @@ -430,12 +421,12 @@
430 421
431 422
432 /** 423 /**
433 - * Get connection options. 424 + * Get session options.
434 * 425 *
435 * @param h Session handle. 426 * @param h Session handle.
436 * 427 *
437 */ 428 */
438 - LIB3270_EXPORT LIB3270_CONNECT_OPTION lib3270_get_connect_options(H3270 *h); 429 + LIB3270_EXPORT LIB3270_OPTION lib3270_get_options(H3270 *hSession);
439 430
440 /** 431 /**
441 * Get URL of the hostname for the connect/reconnect operations. 432 * Get URL of the hostname for the connect/reconnect operations.
@@ -465,12 +456,12 @@ @@ -465,12 +456,12 @@
465 * @param hSession Session handle. 456 * @param hSession Session handle.
466 * @param hostname Host name. 457 * @param hostname Host name.
467 * @param srvc Service name (telnet if NULL). 458 * @param srvc Service name (telnet if NULL).
468 - * @param opt Connect options. 459 + * @param opt Session options.
469 * 460 *
470 * @return 0 for success, EAGAIN if auto-reconnect is in progress, EBUSY if connected, ENOTCONN if connection has failed, -1 on unexpected failure. 461 * @return 0 for success, EAGAIN if auto-reconnect is in progress, EBUSY if connected, ENOTCONN if connection has failed, -1 on unexpected failure.
471 * 462 *
472 */ 463 */
473 - LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, const char *srvc, LIB3270_CONNECT_OPTION opt); 464 + LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, const char *srvc, LIB3270_OPTION opt);
474 465
475 466
476 /** 467 /**
@@ -1053,7 +1044,6 @@ @@ -1053,7 +1044,6 @@
1053 1044
1054 LIB3270_EXPORT int lib3270_clear_operator_error(H3270 *hSession); 1045 LIB3270_EXPORT int lib3270_clear_operator_error(H3270 *hSession);
1055 1046
1056 - LIB3270_EXPORT LIB3270_OPTION lib3270_get_options(H3270 *hSession);  
1057 LIB3270_EXPORT void lib3270_set_options(H3270 *hSession, LIB3270_OPTION opt); 1047 LIB3270_EXPORT void lib3270_set_options(H3270 *hSession, LIB3270_OPTION opt);
1058 LIB3270_EXPORT int lib3270_set_color_type(H3270 *hSession, unsigned short colortype); 1048 LIB3270_EXPORT int lib3270_set_color_type(H3270 *hSession, unsigned short colortype);
1059 1049
src/include/lib3270/session.h
@@ -141,7 +141,6 @@ @@ -141,7 +141,6 @@
141 141
142 struct 142 struct
143 { 143 {
144 - LIB3270_CONNECT_OPTION opt; /**< Connect options */  
145 char * current; /**< The hostname part, stripped of qualifiers, luname and port number */ 144 char * current; /**< The hostname part, stripped of qualifiers, luname and port number */
146 char * full; /**< The entire string, for use in reconnecting */ 145 char * full; /**< The entire string, for use in reconnecting */
147 char * srvc; /**< The service name */ 146 char * srvc; /**< The service name */
src/lib3270/connect.c
@@ -175,7 +175,7 @@ static void net_connected(H3270 *hSession) @@ -175,7 +175,7 @@ static void net_connected(H3270 *hSession)
175 } 175 }
176 #endif // WIN32 176 #endif // WIN32
177 177
178 - LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, const char *srvc, LIB3270_CONNECT_OPTION opt) 178 + LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, const char *srvc, LIB3270_OPTION opt)
179 { 179 {
180 CHECK_SESSION_HANDLE(hSession); 180 CHECK_SESSION_HANDLE(hSession);
181 181
@@ -202,20 +202,20 @@ static void net_connected(H3270 *hSession) @@ -202,20 +202,20 @@ static void net_connected(H3270 *hSession)
202 hostname = name; 202 hostname = name;
203 } 203 }
204 204
205 - hSession->host.opt = opt & ~LIB3270_CONNECT_OPTION_WAIT; 205 + hSession->options = opt & ~LIB3270_OPTION_WAIT;
206 Replace(hSession->host.current,strdup(hostname)); 206 Replace(hSession->host.current,strdup(hostname));
207 Replace(hSession->host.srvc,strdup(srvc)); 207 Replace(hSession->host.srvc,strdup(srvc));
208 208
209 Replace(hSession->host.full, 209 Replace(hSession->host.full,
210 lib3270_strdup_printf( 210 lib3270_strdup_printf(
211 "%s%s:%s", 211 "%s%s:%s",
212 - opt&LIB3270_CONNECT_OPTION_SSL ? "tn3270s://" : "tn3270://", 212 + opt&LIB3270_OPTION_SSL ? "tn3270s://" : "tn3270://",
213 hostname, 213 hostname,
214 srvc )); 214 srvc ));
215 215
216 trace("current_host=\"%s\"",hSession->host.current); 216 trace("current_host=\"%s\"",hSession->host.current);
217 217
218 - return lib3270_connect(hSession,opt & LIB3270_CONNECT_OPTION_WAIT); 218 + return lib3270_connect(hSession,opt & LIB3270_OPTION_WAIT);
219 219
220 } 220 }
221 221
@@ -316,7 +316,7 @@ static void net_connected(H3270 *hSession) @@ -316,7 +316,7 @@ static void net_connected(H3270 *hSession)
316 hSession->ever_3270 = False; 316 hSession->ever_3270 = False;
317 hSession->ssl_host = 0; 317 hSession->ssl_host = 0;
318 318
319 - if(hSession->host.opt&LIB3270_CONNECT_OPTION_SSL) 319 + if(hSession->options&LIB3270_OPTION_SSL)
320 { 320 {
321 #if defined(HAVE_LIBSSL) 321 #if defined(HAVE_LIBSSL)
322 hSession->ssl_host = 1; 322 hSession->ssl_host = 1;
src/lib3270/host.c
@@ -500,18 +500,18 @@ LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n) @@ -500,18 +500,18 @@ LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n)
500 { 500 {
501 static const struct _sch 501 static const struct _sch
502 { 502 {
503 - LIB3270_CONNECT_OPTION opt;  
504 - const char * text;  
505 - const char * srvc; 503 + LIB3270_OPTION opt;
  504 + const char * text;
  505 + const char * srvc;
506 } sch[] = 506 } sch[] =
507 { 507 {
508 - { LIB3270_CONNECT_OPTION_DEFAULTS, "tn3270://", "telnet" },  
509 - { LIB3270_CONNECT_OPTION_SSL, "tn3270s://", "telnets" },  
510 - { LIB3270_CONNECT_OPTION_DEFAULTS, "telnet://", "telnet" },  
511 - { LIB3270_CONNECT_OPTION_DEFAULTS, "telnets://", "telnets" },  
512 - { LIB3270_CONNECT_OPTION_SSL, "L://", "telnets" }, 508 + { LIB3270_OPTION_DEFAULTS, "tn3270://", "telnet" },
  509 + { LIB3270_OPTION_SSL, "tn3270s://", "telnets" },
  510 + { LIB3270_OPTION_DEFAULTS, "telnet://", "telnet" },
  511 + { LIB3270_OPTION_DEFAULTS, "telnets://", "telnets" },
  512 + { LIB3270_OPTION_SSL, "L://", "telnets" },
513 513
514 - { LIB3270_CONNECT_OPTION_SSL, "L:", "telnets" } // The compatibility should be the last option 514 + { LIB3270_OPTION_SSL, "L:", "telnets" } // The compatibility should be the last option
515 }; 515 };
516 516
517 char * str = strdup(n); 517 char * str = strdup(n);
@@ -522,16 +522,16 @@ LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n) @@ -522,16 +522,16 @@ LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n)
522 int f; 522 int f;
523 523
524 trace("%s(%s)",__FUNCTION__,str); 524 trace("%s(%s)",__FUNCTION__,str);
525 - h->host.opt = LIB3270_CONNECT_OPTION_DEFAULTS; 525 + h->options = LIB3270_OPTION_DEFAULTS;
526 526
527 for(f=0;f < sizeof(sch)/sizeof(sch[0]);f++) 527 for(f=0;f < sizeof(sch)/sizeof(sch[0]);f++)
528 { 528 {
529 size_t sz = strlen(sch[f].text); 529 size_t sz = strlen(sch[f].text);
530 if(!strncasecmp(hostname,sch[f].text,sz)) 530 if(!strncasecmp(hostname,sch[f].text,sz))
531 { 531 {
532 - h->host.opt = sch[f].opt;  
533 - srvc = sch[f].srvc;  
534 - hostname += sz; 532 + h->options = sch[f].opt;
  533 + srvc = sch[f].srvc;
  534 + hostname += sz;
535 break; 535 break;
536 } 536 }
537 } 537 }
@@ -561,7 +561,7 @@ LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n) @@ -561,7 +561,7 @@ LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n)
561 Replace(h->host.full, 561 Replace(h->host.full,
562 lib3270_strdup_printf( 562 lib3270_strdup_printf(
563 "%s%s:%s%s%s", 563 "%s%s:%s%s%s",
564 - h->host.opt&LIB3270_CONNECT_OPTION_SSL ? "tn3270s://" : "tn3270://", 564 + h->options&LIB3270_OPTION_SSL ? "tn3270s://" : "tn3270://",
565 hostname, 565 hostname,
566 srvc, 566 srvc,
567 *query ? "?" : "", 567 *query ? "?" : "",
@@ -579,19 +579,19 @@ LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n) @@ -579,19 +579,19 @@ LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n)
579 LIB3270_EXPORT const char * lib3270_get_hostname(H3270 *h) 579 LIB3270_EXPORT const char * lib3270_get_hostname(H3270 *h)
580 { 580 {
581 CHECK_SESSION_HANDLE(h); 581 CHECK_SESSION_HANDLE(h);
582 - return h->host.current;  
583 -}  
584 582
585 -LIB3270_EXPORT const char * lib3270_get_srvcname(H3270 *h)  
586 -{  
587 - CHECK_SESSION_HANDLE(h);  
588 - return h->host.srvc; 583 + if(h->host.current)
  584 + return h->host.current;
  585 +
  586 + return "";
589 } 587 }
590 588
591 -LIB3270_EXPORT LIB3270_CONNECT_OPTION lib3270_get_connect_options(H3270 *h) 589 +LIB3270_EXPORT const char * lib3270_get_srvcname(H3270 *h)
592 { 590 {
593 CHECK_SESSION_HANDLE(h); 591 CHECK_SESSION_HANDLE(h);
594 - return h->host.opt; 592 + if(h->host.srvc)
  593 + return h->host.srvc;
  594 + return "telnet";
595 } 595 }
596 596
597 LIB3270_EXPORT const char * lib3270_get_host(H3270 *h) 597 LIB3270_EXPORT const char * lib3270_get_host(H3270 *h)
src/lib3270/kybd.c
@@ -572,14 +572,14 @@ LIB3270_FKEY_ACTION( pfkey ) @@ -572,14 +572,14 @@ LIB3270_FKEY_ACTION( pfkey )
572 572
573 if (hSession->kybdlock) 573 if (hSession->kybdlock)
574 { 574 {
575 - if(hSession->options & LIB3270_OPTION_KYBD_AS400) 575 + if(hSession->options & LIB3270_OPTION_AS400)
576 enq_key(hSession,pa_xlate[0]); 576 enq_key(hSession,pa_xlate[0]);
577 577
578 enq_key(hSession,pf_xlate[key-1]); 578 enq_key(hSession,pf_xlate[key-1]);
579 } 579 }
580 else 580 else
581 { 581 {
582 - if(hSession->options & LIB3270_OPTION_KYBD_AS400) 582 + if(hSession->options & LIB3270_OPTION_AS400)
583 key_AID(hSession,pa_xlate[0]); 583 key_AID(hSession,pa_xlate[0]);
584 584
585 key_AID(hSession,pf_xlate[key-1]); 585 key_AID(hSession,pf_xlate[key-1]);
src/lib3270/options.c
@@ -39,7 +39,7 @@ @@ -39,7 +39,7 @@
39 static const const LIB3270_OPTION_ENTRY options[LIB3270_OPTION_COUNT+1] = 39 static const const LIB3270_OPTION_ENTRY options[LIB3270_OPTION_COUNT+1] =
40 { 40 {
41 { 41 {
42 - LIB3270_OPTION_KYBD_AS400, 42 + LIB3270_OPTION_AS400,
43 "as400", 43 "as400",
44 N_( "Host is AS/400" ), 44 N_( "Host is AS/400" ),
45 NULL 45 NULL
src/pw3270/hostdialog.c
@@ -40,7 +40,7 @@ @@ -40,7 +40,7 @@
40 } host_type[] = 40 } host_type[] =
41 { 41 {
42 { "S390", N_( "IBM S/390" ), LIB3270_OPTION_TSO }, 42 { "S390", N_( "IBM S/390" ), LIB3270_OPTION_TSO },
43 - { "AS400", N_( "IBM AS/400" ), LIB3270_OPTION_KYBD_AS400 }, 43 + { "AS400", N_( "IBM AS/400" ), LIB3270_OPTION_AS400 },
44 { "TSO", N_( "Other (TSO)" ), LIB3270_OPTION_TSO }, 44 { "TSO", N_( "Other (TSO)" ), LIB3270_OPTION_TSO },
45 { "VM/CMS", N_( "Other (VM/CMS)" ), 0 } 45 { "VM/CMS", N_( "Other (VM/CMS)" ), 0 }
46 }; 46 };
@@ -353,22 +353,19 @@ @@ -353,22 +353,19 @@
353 gtk_widget_show_all(GTK_WIDGET(table)); 353 gtk_widget_show_all(GTK_WIDGET(table));
354 #endif 354 #endif
355 355
356 - gchar *uri = get_string_from_config("host","uri","");  
357 -  
358 - if(uri && *uri && lib3270_set_host(v3270_get_session(widget),uri))  
359 { 356 {
360 H3270 *hSession = v3270_get_session(widget); 357 H3270 *hSession = v3270_get_session(widget);
  358 + gchar *uri = get_string_from_config("host","uri","");
  359 +
  360 + if(uri && *uri)
  361 + lib3270_set_host(hSession,uri);
  362 +
  363 + g_free(uri);
  364 +
361 gtk_entry_set_text(host,lib3270_get_hostname(hSession)); 365 gtk_entry_set_text(host,lib3270_get_hostname(hSession));
362 gtk_entry_set_text(port,lib3270_get_srvcname(hSession)); 366 gtk_entry_set_text(port,lib3270_get_srvcname(hSession));
363 - gtk_toggle_button_set_active(sslcheck,(lib3270_get_connect_options(hSession) & LIB3270_CONNECT_OPTION_SSL) ? TRUE : FALSE); 367 + gtk_toggle_button_set_active(sslcheck,(lib3270_get_options(hSession) & LIB3270_OPTION_SSL) ? TRUE : FALSE);
364 } 368 }
365 - else  
366 - {  
367 - gtk_entry_set_text(host,"");  
368 - gtk_entry_set_text(port,"telnet");  
369 - }  
370 -  
371 - g_free(uri);  
372 369
373 /* 370 /*
374 hostname = cfghost; 371 hostname = cfghost;
@@ -427,14 +424,13 @@ @@ -427,14 +424,13 @@
427 set_string_to_config("host","systype",host_type[iHostType].name); 424 set_string_to_config("host","systype",host_type[iHostType].name);
428 set_integer_to_config("host","colortype",colortable[iColorTable].colors); 425 set_integer_to_config("host","colortype",colortable[iColorTable].colors);
429 426
430 - v3270_set_session_options(widget,host_type[iHostType].option);  
431 v3270_set_session_color_type(widget,colortable[iColorTable].colors); 427 v3270_set_session_color_type(widget,colortable[iColorTable].colors);
432 428
433 // if(!lib3270_connect(v3270_get_session(widget),hostname,1)) 429 // if(!lib3270_connect(v3270_get_session(widget),hostname,1))
434 if(!lib3270_connect_host( v3270_get_session(widget), 430 if(!lib3270_connect_host( v3270_get_session(widget),
435 gtk_entry_get_text(host), 431 gtk_entry_get_text(host),
436 gtk_entry_get_text(port), 432 gtk_entry_get_text(port),
437 - gtk_toggle_button_get_active(sslcheck) ? LIB3270_CONNECT_OPTION_SSL : LIB3270_CONNECT_OPTION_DEFAULTS)) 433 + host_type[iHostType].option | (gtk_toggle_button_get_active(sslcheck) ? LIB3270_OPTION_SSL : LIB3270_OPTION_DEFAULTS)))
438 { 434 {
439 again = FALSE; 435 again = FALSE;
440 } 436 }