Commit 8367962468b38845047b4c3ae72d9e75d731b662

Authored by perry.werneck@gmail.com
1 parent 38a5bff1

Ajuste no tratamento de hostname para o novo formato de conexão

@@ -201,6 +201,19 @@ static void net_connected(H3270 *hSession) @@ -201,6 +201,19 @@ static void net_connected(H3270 *hSession)
201 sockstart(hSession); 201 sockstart(hSession);
202 #endif 202 #endif
203 203
  204 + hSession->host.opt = opt;
  205 + Replace(hSession->host.current,strdup(hostname));
  206 +
  207 + Replace(hSession->host.full,
  208 + lib3270_strdup_printf(
  209 + "%s%s:%s",
  210 + opt&LIB3270_CONNECT_OPTION_SSL ? "L:" : "",
  211 + hostname,
  212 + srvc ));
  213 +
  214 + trace("current_host=\"%s\"",hSession->host.current);
  215 +
  216 +
204 set_ssl_state(hSession,LIB3270_SSL_UNSECURE); 217 set_ssl_state(hSession,LIB3270_SSL_UNSECURE);
205 218
206 hSession->ever_3270 = False; 219 hSession->ever_3270 = False;
@@ -231,7 +244,8 @@ static void net_connected(H3270 *hSession) @@ -231,7 +244,8 @@ static void net_connected(H3270 *hSession)
231 hostname = name; 244 hostname = name;
232 } 245 }
233 246
234 - status_changed(hSession,LIB3270_STATUS_RESOLVING); 247 + hSession->cstate = LIB3270_RESOLVING;
  248 + lib3270_st_changed(hSession, LIB3270_STATE_RESOLVING, True);
235 249
236 s = getaddrinfo(hostname, srvc, &hints, &result); 250 s = getaddrinfo(hostname, srvc, &hints, &result);
237 251
@@ -286,15 +300,25 @@ static void net_connected(H3270 *hSession) @@ -286,15 +300,25 @@ static void net_connected(H3270 *hSession)
286 (void) fcntl(hSession->sock, F_SETFD, 1); 300 (void) fcntl(hSession->sock, F_SETFD, 1);
287 #endif 301 #endif
288 302
289 - hSession->ssl_host = 0; 303 + hSession->ever_3270 = False;
  304 + hSession->ssl_host = 0;
290 305
291 -#if defined(HAVE_LIBSSL)  
292 if(opt&LIB3270_CONNECT_OPTION_SSL) 306 if(opt&LIB3270_CONNECT_OPTION_SSL)
293 { 307 {
  308 +#if defined(HAVE_LIBSSL)
294 hSession->ssl_host = 1; 309 hSession->ssl_host = 1;
295 ssl_init(hSession); 310 ssl_init(hSession);
  311 +#else
  312 + lib3270_popup_dialog( hSession,
  313 + LIB3270_NOTIFY_ERROR,
  314 + _( "SSL error" ),
  315 + _( "Unable to connect to secure hosts" ),
  316 + _( "This version of %s was built without support for secure sockets layer (SSL)." ),
  317 + PACKAGE_NAME));
  318 +
  319 + return EINVAL;
  320 +#endif // HAVE_LIBSSL
296 } 321 }
297 -#endif  
298 322
299 /* connect */ 323 /* connect */
300 status_connecting(hSession,1); 324 status_connecting(hSession,1);
@@ -38,6 +38,7 @@ @@ -38,6 +38,7 @@
38 * connection. 38 * connection.
39 */ 39 */
40 40
  41 +#include <malloc.h>
41 #include "globals.h" 42 #include "globals.h"
42 // #include "appres.h" 43 // #include "appres.h"
43 #include "resources.h" 44 #include "resources.h"
@@ -64,7 +65,7 @@ static void try_reconnect(H3270 *session); @@ -64,7 +65,7 @@ static void try_reconnect(H3270 *session);
64 * Returns the hostname part in a newly-malloc'd string. 65 * Returns the hostname part in a newly-malloc'd string.
65 * 'needed' is returned True if anything was actually stripped. 66 * 'needed' is returned True if anything was actually stripped.
66 * Returns NULL if there is a syntax error. 67 * Returns NULL if there is a syntax error.
67 - */ 68 + */ /*
68 static char * 69 static char *
69 split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, 70 split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru,
70 char *non_e, char *secure, char *no_login, char *xluname, 71 char *non_e, char *secure, char *no_login, char *xluname,
@@ -85,18 +86,18 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, @@ -85,18 +86,18 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru,
85 86
86 *needed = False; 87 *needed = False;
87 88
88 - /*  
89 - * Hostname syntax is:  
90 - * Zero or more optional prefixes (A:, S:, P:, N:, L:, C:).  
91 - * An optional LU name separated by '@'.  
92 - * A hostname optionally in square brackets (which quote any colons  
93 - * in the name).  
94 - * An optional port name or number separated from the hostname by a  
95 - * space or colon.  
96 - * No additional white space or colons are allowed.  
97 - */  
98 -  
99 - /* Strip leading whitespace. */ 89 + //
  90 + // Hostname syntax is:
  91 + // Zero or more optional prefixes (A:, S:, P:, N:, L:, C:).
  92 + // An optional LU name separated by '@'.
  93 + // A hostname optionally in square brackets (which quote any colons
  94 + // in the name).
  95 + // An optional port name or number separated from the hostname by a
  96 + // space or colon.
  97 + // No additional white space or colons are allowed.
  98 + //
  99 +
  100 + // Strip leading whitespace.
100 while (*s && isspace(*s)) 101 while (*s && isspace(*s))
101 s++; 102 s++;
102 103
@@ -106,11 +107,11 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, @@ -106,11 +107,11 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru,
106 goto split_fail; 107 goto split_fail;
107 } 108 }
108 109
109 - /* Strip trailing whitespace. */ 110 + // Strip trailing whitespace.
110 while (isspace(*(s + strlen(s) - 1))) 111 while (isspace(*(s + strlen(s) - 1)))
111 *(s + strlen(s) - 1) = '\0'; 112 *(s + strlen(s) - 1) = '\0';
112 113
113 - /* Start with the prefixes. */ 114 + // Start with the prefixes.
114 while (*s && *(s + 1) && isalpha(*s) && *(s + 1) == ':') { 115 while (*s && *(s + 1) && isalpha(*s) && *(s + 1) == ':') {
115 switch (*s) { 116 switch (*s) {
116 case 'a': 117 case 'a':
@@ -160,12 +161,12 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, @@ -160,12 +161,12 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru,
160 *needed = True; 161 *needed = True;
161 s += 2; 162 s += 2;
162 163
163 - /* Allow whitespace around the prefixes. */ 164 + // Allow whitespace around the prefixes.
164 while (*s && isspace(*s)) 165 while (*s && isspace(*s))
165 s++; 166 s++;
166 } 167 }
167 168
168 - /* Process the LU name. */ 169 + // Process the LU name.
169 lbracket = strchr(s, '['); 170 lbracket = strchr(s, '[');
170 at = strchr(s, '@'); 171 at = strchr(s, '@');
171 if (at != CN && lbracket != CN && at > lbracket) 172 if (at != CN && lbracket != CN && at > lbracket)
@@ -203,15 +204,15 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, @@ -203,15 +204,15 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru,
203 *needed = True; 204 *needed = True;
204 } 205 }
205 206
206 - /*  
207 - * Isolate the hostname.  
208 - * At this point, we've found its start, so we can malloc the buffer  
209 - * that will hold the copy.  
210 - */ 207 + //
  208 + // Isolate the hostname.
  209 + // At this point, we've found its start, so we can malloc the buffer
  210 + // that will hold the copy.
  211 + ///
211 if (lbracket != CN) { 212 if (lbracket != CN) {
212 char *rbracket; 213 char *rbracket;
213 214
214 - /* Check for junk before the '['. */ 215 + // Check for junk before the '['.
215 if (lbracket != s) { 216 if (lbracket != s) {
216 popup_system_error(hSession,NULL,_("Hostname syntax error"),"%s",_("Text before '['")); 217 popup_system_error(hSession,NULL,_("Hostname syntax error"),"%s",_("Text before '['"));
217 goto split_fail; 218 goto split_fail;
@@ -219,10 +220,10 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, @@ -219,10 +220,10 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru,
219 220
220 s = r = NewString(lbracket + 1); 221 s = r = NewString(lbracket + 1);
221 222
222 - /*  
223 - * Take whatever is inside square brackets, including  
224 - * whitespace, unmodified -- except for empty strings.  
225 - */ 223 + //
  224 + // Take whatever is inside square brackets, including
  225 + // whitespace, unmodified -- except for empty strings.
  226 + //
226 rbracket = strchr(s, ']'); 227 rbracket = strchr(s, ']');
227 if (rbracket == CN) { 228 if (rbracket == CN) {
228 popup_system_error(hSession,NULL,_("Hostname syntax error"),"%s",_("Missing ']'")); 229 popup_system_error(hSession,NULL,_("Hostname syntax error"),"%s",_("Missing ']'"));
@@ -234,7 +235,7 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, @@ -234,7 +235,7 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru,
234 } 235 }
235 *rbracket = '\0'; 236 *rbracket = '\0';
236 237
237 - /* Skip over any whitespace after the bracketed name. */ 238 + // Skip over any whitespace after the bracketed name.
238 s = rbracket + 1; 239 s = rbracket + 1;
239 while (*s && isspace(*s)) 240 while (*s && isspace(*s))
240 s++; 241 s++;
@@ -244,7 +245,7 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, @@ -244,7 +245,7 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru,
244 } else { 245 } else {
245 char *name_end; 246 char *name_end;
246 247
247 - /* Check for an empty string. */ 248 + // Check for an empty string.
248 if (!*s || *s == ':') { 249 if (!*s || *s == ':') {
249 popup_an_error(hSession,"Empty hostname"); 250 popup_an_error(hSession,"Empty hostname");
250 goto split_fail; 251 goto split_fail;
@@ -252,19 +253,19 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, @@ -252,19 +253,19 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru,
252 253
253 s = r = NewString(s); 254 s = r = NewString(s);
254 255
255 - /* Find the end of the hostname. */ 256 + // Find the end of the hostname.
256 while (*s && !isspace(*s) && *s != ':') 257 while (*s && !isspace(*s) && *s != ':')
257 s++; 258 s++;
258 name_end = s; 259 name_end = s;
259 260
260 - /* If the terminator is whitespace, skip the rest of it. */ 261 + // If the terminator is whitespace, skip the rest of it.
261 while (*s && isspace(*s)) 262 while (*s && isspace(*s))
262 s++; 263 s++;
263 264
264 - /*  
265 - * If there's nothing but whitespace (or nothing) after the  
266 - * name, we're done.  
267 - */ 265 + //
  266 + // If there's nothing but whitespace (or nothing) after the
  267 + // name, we're done.
  268 + //
268 if (*s == '\0') { 269 if (*s == '\0') {
269 *name_end = '\0'; 270 *name_end = '\0';
270 goto split_success; 271 goto split_success;
@@ -273,10 +274,10 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, @@ -273,10 +274,10 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru,
273 *name_end = '\0'; 274 *name_end = '\0';
274 } 275 }
275 276
276 - /*  
277 - * If 'colon' is set, 's' points at it (or where it was). Skip  
278 - * it and any whitespace that follows.  
279 - */ 277 + //
  278 + // If 'colon' is set, 's' points at it (or where it was). Skip
  279 + // it and any whitespace that follows.
  280 + //
280 if (colon) { 281 if (colon) {
281 s++; 282 s++;
282 while (*s && isspace(*s)) 283 while (*s && isspace(*s))
@@ -287,11 +288,11 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, @@ -287,11 +288,11 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru,
287 } 288 }
288 } 289 }
289 290
290 - /*  
291 - * Set the portname and find its end.  
292 - * Note that trailing spaces were already stripped, so the end of the  
293 - * portname must be a NULL.  
294 - */ 291 + //
  292 + // Set the portname and find its end.
  293 + // Note that trailing spaces were already stripped, so the end of the
  294 + // portname must be a NULL.
  295 + //
295 *port = s; 296 *port = s;
296 *needed = True; 297 *needed = True;
297 while (*s && !isspace(*s) && *s != ':') 298 while (*s && !isspace(*s) && *s != ':')
@@ -309,23 +310,25 @@ split_fail: @@ -309,23 +310,25 @@ split_fail:
309 split_success: 310 split_success:
310 return r; 311 return r;
311 } 312 }
  313 +*/
312 314
313 -static int do_connect(H3270 *hSession, const char *n) 315 +static int do_connect(H3270 *hSession)
314 { 316 {
315 - char nb[2048]; /* name buffer */  
316 - char *s; /* temporary */  
317 - char *chost = NULL; /* to whom we will connect */ 317 +// char nb[2048]; // name buffer
  318 +// char *s; // temporary
  319 + char *chost = NULL; // to whom we will connect
318 // char *ps = CN; 320 // char *ps = CN;
319 - char *port = CN; 321 +// char *port = CN;
320 Boolean resolving; 322 Boolean resolving;
321 Boolean pending; 323 Boolean pending;
322 - static Boolean ansi_host;  
323 - Boolean has_colons = False; 324 +// static Boolean ansi_host;
  325 +// Boolean has_colons = False;
324 326
325 if (lib3270_connected(hSession) || hSession->auto_reconnect_inprogress) 327 if (lib3270_connected(hSession) || hSession->auto_reconnect_inprogress)
326 return EBUSY; 328 return EBUSY;
327 329
328 - /* Skip leading blanks. */ 330 + /*
  331 + // Skip leading blanks.
329 while (*n == ' ') 332 while (*n == ' ')
330 n++; 333 n++;
331 334
@@ -334,22 +337,26 @@ static int do_connect(H3270 *hSession, const char *n) @@ -334,22 +337,26 @@ static int do_connect(H3270 *hSession, const char *n)
334 popup_an_error(hSession,_( "Invalid (empty) hostname" )); 337 popup_an_error(hSession,_( "Invalid (empty) hostname" ));
335 return -1; 338 return -1;
336 } 339 }
  340 + */
337 341
338 - /* Save in a modifiable buffer. */ 342 + /*
  343 + // Save in a modifiable buffer.
339 (void) strncpy(nb, n, 2047); 344 (void) strncpy(nb, n, 2047);
340 345
341 - /* Strip trailing blanks. */ 346 + // Strip trailing blanks.
342 s = nb + strlen(nb) - 1; 347 s = nb + strlen(nb) - 1;
343 while (*s == ' ') 348 while (*s == ' ')
344 *s-- = '\0'; 349 *s-- = '\0';
  350 + */
345 351
346 /* Remember this hostname, as the last hostname we connected to. */ 352 /* Remember this hostname, as the last hostname we connected to. */
347 - lib3270_set_host(hSession,nb); 353 + // lib3270_set_host(hSession,nb);
348 354
  355 + /*
349 { 356 {
350 Boolean needed; 357 Boolean needed;
351 358
352 - /* Strip off and remember leading qualifiers. */ 359 + // Strip off and remember leading qualifiers.
353 if ((s = split_host(hSession, nb, &ansi_host, &hSession->std_ds_host, 360 if ((s = split_host(hSession, nb, &ansi_host, &hSession->std_ds_host,
354 &hSession->passthru_host, &hSession->non_tn3270e_host, &hSession->ssl_host, 361 &hSession->passthru_host, &hSession->non_tn3270e_host, &hSession->ssl_host,
355 &hSession->no_login_host, hSession->luname, &port, 362 &hSession->no_login_host, hSession->luname, &port,
@@ -358,35 +365,52 @@ static int do_connect(H3270 *hSession, const char *n) @@ -358,35 +365,52 @@ static int do_connect(H3270 *hSession, const char *n)
358 365
359 chost = s; 366 chost = s;
360 367
361 - /* Default the port. */ 368 + // Default the port.
362 if (port == CN) 369 if (port == CN)
363 port = "telnet"; 370 port = "telnet";
364 } 371 }
365 372
366 - /*  
367 - * Store the original name in globals, even if we fail the connect  
368 - * later:  
369 - * current_host is the hostname part, stripped of qualifiers, luname  
370 - * and port number  
371 - * full_current_host is the entire string, for use in reconnecting  
372 - */  
373 - Replace(hSession->current_host, CN); 373 + //
  374 + // Store the original name in globals, even if we fail the connect
  375 + // later:
  376 + // current_host is the hostname part, stripped of qualifiers, luname
  377 + // and port number
  378 + // full_current_host is the entire string, for use in reconnecting
  379 + //
  380 + //
  381 + // Replace(hSession->current_host, CN);
374 382
375 has_colons = (strchr(chost, ':') != NULL); 383 has_colons = (strchr(chost, ':') != NULL);
376 384
377 - Replace(hSession->qualified_host, 385 + Replace(hSession->host.qualified,
378 xs_buffer("%s%s%s%s:%s", 386 xs_buffer("%s%s%s%s:%s",
379 hSession->ssl_host? "L:": "", 387 hSession->ssl_host? "L:": "",
380 has_colons? "[": "", 388 has_colons? "[": "",
381 chost, 389 chost,
382 has_colons? "]": "", 390 has_colons? "]": "",
383 port)); 391 port));
384 - 392 + */
385 393
386 /* Attempt contact. */ 394 /* Attempt contact. */
387 hSession->ever_3270 = False; 395 hSession->ever_3270 = False;
  396 + hSession->ssl_host = 0;
388 397
389 - if(net_connect(hSession, chost, port, 0, &resolving,&pending) != 0 && !resolving) 398 + if(hSession->host.opt&LIB3270_CONNECT_OPTION_SSL)
  399 + {
  400 +#if defined(HAVE_LIBSSL)
  401 + hSession->ssl_host = 1;
  402 + ssl_init(hSession);
  403 +#else
  404 + popup_system_error(hSession, _( "SSL error" ),
  405 + _( "Unable to connect to secure hosts" ),
  406 + _( "This version of %s was built without support for secure sockets layer (SSL)." ),
  407 + PACKAGE_NAME
  408 + );
  409 +#endif
  410 + }
  411 +
  412 + trace("Conneting to hostname=[%s] service=[%s]",hSession->host.current, hSession->host.srvc);
  413 + if(net_connect(hSession, hSession->host.current, hSession->host.srvc, 0, &resolving,&pending) != 0 && !resolving)
390 { 414 {
391 /* Redundantly signal a disconnect. */ 415 /* Redundantly signal a disconnect. */
392 lib3270_set_disconnected(hSession); 416 lib3270_set_disconnected(hSession);
@@ -457,14 +481,13 @@ int lib3270_connect(H3270 *hSession, const char *n, int wait) @@ -457,14 +481,13 @@ int lib3270_connect(H3270 *hSession, const char *n, int wait)
457 if(PCONNECTED) 481 if(PCONNECTED)
458 return EBUSY; 482 return EBUSY;
459 483
460 - if(!n)  
461 - {  
462 - n = hSession->full_current_host;  
463 - if(!n)  
464 - return EINVAL;  
465 - } 484 + if(n)
  485 + lib3270_set_host(hSession,n);
466 486
467 - rc = do_connect(hSession,n); 487 + if(!hSession->host.full)
  488 + return EINVAL;
  489 +
  490 + rc = do_connect(hSession);
468 if(rc) 491 if(rc)
469 return rc; 492 return rc;
470 493
@@ -489,7 +512,7 @@ int lib3270_connect(H3270 *hSession, const char *n, int wait) @@ -489,7 +512,7 @@ int lib3270_connect(H3270 *hSession, const char *n, int wait)
489 */ 512 */
490 static void try_reconnect(H3270 *session) 513 static void try_reconnect(H3270 *session)
491 { 514 {
492 - lib3270_write_log(session,"3270","Starting auto-reconnect (Host: %s)",session->full_current_host ? session->full_current_host : "-"); 515 + lib3270_write_log(session,"3270","Starting auto-reconnect (Host: %s)",session->host.full ? session->host.full : "-");
493 session->auto_reconnect_inprogress = 0; 516 session->auto_reconnect_inprogress = 0;
494 lib3270_reconnect(session,0); 517 lib3270_reconnect(session,0);
495 } 518 }
@@ -626,26 +649,88 @@ LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n) @@ -626,26 +649,88 @@ LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n)
626 { 649 {
627 CHECK_SESSION_HANDLE(h); 650 CHECK_SESSION_HANDLE(h);
628 651
629 - if(n && n != h->full_current_host) 652 + if(n && n != h->host.full)
630 { 653 {
631 - char *new_hostname = strdup(n); 654 + static const struct _sch
  655 + {
  656 + LIB3270_CONNECT_OPTION opt;
  657 + const char * text;
  658 + const char * srvc;
  659 + } sch[] =
  660 + {
  661 + { LIB3270_CONNECT_OPTION_DEFAULTS, "tn3270://", "telnet" },
  662 + { LIB3270_CONNECT_OPTION_SSL, "tn3270s://", "telnets" },
  663 + { LIB3270_CONNECT_OPTION_DEFAULTS, "telnet://", "telnet" },
  664 + { LIB3270_CONNECT_OPTION_DEFAULTS, "telnets://", "telnets" },
  665 + { LIB3270_CONNECT_OPTION_SSL, "L://", "telnets" },
  666 +
  667 + { LIB3270_CONNECT_OPTION_SSL, "L:", "telnets" } // The compatibility should be the last option
  668 + };
  669 +
  670 + char * str = strdup(n);
  671 + char * hostname = str;
  672 + const char * srvc = "telnet";
  673 + char * ptr;
  674 + char * query = "";
  675 + int f;
  676 +
  677 + trace("%s(%s)",__FUNCTION__,str);
  678 + h->host.opt = LIB3270_CONNECT_OPTION_DEFAULTS;
  679 +
  680 + for(f=0;f < sizeof(sch)/sizeof(sch[0]);f++)
  681 + {
  682 + size_t sz = strlen(sch[f].text);
  683 + if(!strncasecmp(hostname,sch[f].text,sz))
  684 + {
  685 + h->host.opt = sch[f].opt;
  686 + srvc = sch[f].srvc;
  687 + hostname += sz;
  688 + break;
  689 + }
  690 + }
632 691
633 - trace("new hostname is \"%s\"",new_hostname); 692 + trace("SRVC=[%s]",srvc);
634 693
635 - if(h->full_current_host)  
636 - lib3270_free(h->full_current_host); 694 + if(!*hostname)
  695 + return h->host.current;
637 696
638 - h->full_current_host = new_hostname; 697 + ptr = strchr(hostname,':');
  698 + if(ptr)
  699 + {
  700 + *(ptr++) = 0;
  701 + srvc = ptr;
  702 + query = strchr(ptr,'?');
  703 +
  704 + trace("QUERY=[%s]",query);
  705 +
  706 + if(query)
  707 + *(query++) = 0;
  708 + else
  709 + query = "";
  710 + }
639 711
  712 + Replace(h->host.current,strdup(hostname));
  713 + Replace(h->host.srvc,strdup(srvc));
  714 + Replace(h->host.full,
  715 + lib3270_strdup_printf(
  716 + "%s%s:%s%s%s",
  717 + h->host.opt&LIB3270_CONNECT_OPTION_SSL ? "L:" : "",
  718 + hostname,
  719 + srvc,
  720 + *query ? "?" : "",
  721 + query
  722 + ));
  723 +
  724 + free(str);
640 } 725 }
641 726
642 - return h->full_current_host; 727 + return h->host.current;
643 } 728 }
644 729
645 LIB3270_EXPORT const char * lib3270_get_host(H3270 *h) 730 LIB3270_EXPORT const char * lib3270_get_host(H3270 *h)
646 { 731 {
647 CHECK_SESSION_HANDLE(h); 732 CHECK_SESSION_HANDLE(h);
648 - return h->full_current_host; 733 + return h->host.full;
649 } 734 }
650 735
651 LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int wait) 736 LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int wait)
@@ -657,13 +742,13 @@ LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int wait) @@ -657,13 +742,13 @@ LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int wait)
657 if (CONNECTED || HALF_CONNECTED) 742 if (CONNECTED || HALF_CONNECTED)
658 return EBUSY; 743 return EBUSY;
659 744
660 - if (hSession->full_current_host == CN) 745 + if (hSession->host.full == CN)
661 return EINVAL; 746 return EINVAL;
662 747
663 if (hSession->auto_reconnect_inprogress) 748 if (hSession->auto_reconnect_inprogress)
664 return EBUSY; 749 return EBUSY;
665 750
666 - rc = lib3270_connect(hSession,hSession->full_current_host,wait); 751 + rc = lib3270_connect(hSession,hSession->host.full,wait);
667 752
668 if(rc) 753 if(rc)
669 { 754 {
@@ -99,6 +99,13 @@ void lib3270_session_free(H3270 *h) @@ -99,6 +99,13 @@ void lib3270_session_free(H3270 *h)
99 if(h == default_session) 99 if(h == default_session)
100 default_session = NULL; 100 default_session = NULL;
101 101
  102 +
  103 + // Release hostname info
  104 + release_pointer(h->host.current);
  105 + release_pointer(h->host.full);
  106 + release_pointer(h->host.srvc);
  107 + release_pointer(h->host.qualified);
  108 +
102 lib3270_free(h); 109 lib3270_free(h);
103 110
104 } 111 }
@@ -501,7 +501,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -501,7 +501,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
501 *resolving = False; 501 *resolving = False;
502 *pending = False; 502 *pending = False;
503 503
504 - Replace(session->hostname, NewString(host)); 504 +// Replace(session->hostname, NewString(host));
505 505
506 /* get the passthru host and port number */ 506 /* get the passthru host and port number */
507 if (session->passthru_host) 507 if (session->passthru_host)
@@ -656,7 +656,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -656,7 +656,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
656 } 656 }
657 else 657 else
658 { 658 {
659 - char *msg = xs_buffer( _( "Can't connect to %s:%d" ), session->hostname, session->current_port); 659 + char *msg = xs_buffer( _( "Can't connect to %s" ), session->host.current);
660 660
661 lib3270_popup_dialog( session, 661 lib3270_popup_dialog( session,
662 LIB3270_NOTIFY_ERROR, 662 LIB3270_NOTIFY_ERROR,
@@ -778,9 +778,10 @@ static void setup_lus(H3270 *hSession) @@ -778,9 +778,10 @@ static void setup_lus(H3270 *hSession)
778 778
779 static int net_connected(H3270 *hSession) 779 static int net_connected(H3270 *hSession)
780 { 780 {
  781 + /*
781 if(hSession->proxy_type > 0) 782 if(hSession->proxy_type > 0)
782 { 783 {
783 - /* Negotiate with the proxy. */ 784 + // Negotiate with the proxy.
784 trace_dsn(hSession,"Connected to proxy server %s, port %u.\n",hSession->proxy_host, hSession->proxy_port); 785 trace_dsn(hSession,"Connected to proxy server %s, port %u.\n",hSession->proxy_host, hSession->proxy_port);
785 786
786 if (proxy_negotiate(hSession, hSession->proxy_type, hSession->sock, hSession->hostname,hSession->current_port) < 0) 787 if (proxy_negotiate(hSession, hSession->proxy_type, hSession->sock, hSession->hostname,hSession->current_port) < 0)
@@ -789,8 +790,9 @@ static int net_connected(H3270 *hSession) @@ -789,8 +790,9 @@ static int net_connected(H3270 *hSession)
789 return -1; 790 return -1;
790 } 791 }
791 } 792 }
  793 + */
792 794
793 - trace_dsn(hSession,"Connected to %s, port %u%s.\n", hSession->hostname, hSession->current_port,hSession->ssl_host? " via SSL": ""); 795 + trace_dsn(hSession,"Connected to %s%s.\n", hSession->host.current,hSession->ssl_host? " using SSL": "");
794 796
795 #if defined(HAVE_LIBSSL) 797 #if defined(HAVE_LIBSSL)
796 /* Set up SSL. */ 798 /* Set up SSL. */
@@ -847,6 +849,7 @@ LIB3270_EXPORT void lib3270_setup_session(H3270 *hSession) @@ -847,6 +849,7 @@ LIB3270_EXPORT void lib3270_setup_session(H3270 *hSession)
847 check_linemode(hSession,True); 849 check_linemode(hSession,True);
848 850
849 /* write out the passthru hostname and port nubmer */ 851 /* write out the passthru hostname and port nubmer */
  852 + /*
850 if (hSession->passthru_host) 853 if (hSession->passthru_host)
851 { 854 {
852 unsigned char *buffer = (unsigned char *) xs_buffer("%s %d\r\n", hSession->hostname, hSession->current_port); 855 unsigned char *buffer = (unsigned char *) xs_buffer("%s %d\r\n", hSession->hostname, hSession->current_port);
@@ -854,6 +857,7 @@ LIB3270_EXPORT void lib3270_setup_session(H3270 *hSession) @@ -854,6 +857,7 @@ LIB3270_EXPORT void lib3270_setup_session(H3270 *hSession)
854 lib3270_free(buffer); 857 lib3270_free(buffer);
855 trace_ds(hSession,"SENT HOSTNAME %s:%d\n", hSession->hostname, hSession->current_port); 858 trace_ds(hSession,"SENT HOSTNAME %s:%d\n", hSession->hostname, hSession->current_port);
856 } 859 }
  860 + */
857 } 861 }
858 862
859 /** 863 /**
@@ -1036,7 +1040,7 @@ void net_input(H3270 *hSession) @@ -1036,7 +1040,7 @@ void net_input(H3270 *hSession)
1036 1040
1037 if (HALF_CONNECTED) 1041 if (HALF_CONNECTED)
1038 { 1042 {
1039 - popup_a_sockerr(hSession, N_( "%s:%d" ),hSession->hostname, hSession->current_port); 1043 + popup_a_sockerr(hSession, N_( "%s" ),hSession->host.current);
1040 } 1044 }
1041 else if (socket_errno() != SE_ECONNRESET) 1045 else if (socket_errno() != SE_ECONNRESET)
1042 { 1046 {
@@ -22,7 +22,7 @@ static void * mainloop(void *dunno) @@ -22,7 +22,7 @@ static void * mainloop(void *dunno)
22 int main(int numpar, char *param[]) 22 int main(int numpar, char *param[])
23 { 23 {
24 H3270 * h; 24 H3270 * h;
25 - int rc; 25 + int rc = 0;
26 // char line[4096]; 26 // char line[4096];
27 // pthread_t thread; 27 // pthread_t thread;
28 28
@@ -37,7 +37,10 @@ int main(int numpar, char *param[]) @@ -37,7 +37,10 @@ int main(int numpar, char *param[])
37 // pthread_detach(thread); 37 // pthread_detach(thread);
38 38
39 // rc = lib3270_connect_host(h, "fandezhi.efglobe.com", "telnet", LIB3270_CONNECT_OPTION_WAIT); 39 // rc = lib3270_connect_host(h, "fandezhi.efglobe.com", "telnet", LIB3270_CONNECT_OPTION_WAIT);
40 - rc = lib3270_connect_host(h, "127.0.0.1", "9090", LIB3270_CONNECT_OPTION_WAIT); 40 +// rc = lib3270_connect_host(h, "127.0.0.1", "9090", LIB3270_CONNECT_OPTION_WAIT);
  41 +
  42 +// lib3270_set_host_url(h,"tn3270://fandezhi.efglobe.com:9090?lu=default");
  43 + lib3270_set_host(h,"tn3270://fandezhi.efglobe.com");
41 44
42 printf("\nConnect exits with rc=%d\n",rc); 45 printf("\nConnect exits with rc=%d\n",rc);
43 46
@@ -237,6 +237,17 @@ char * lib3270_vsprintf(const char *fmt, va_list args) @@ -237,6 +237,17 @@ char * lib3270_vsprintf(const char *fmt, va_list args)
237 #endif /*]*/ 237 #endif /*]*/
238 } 238 }
239 239
  240 +LIB3270_EXPORT char * lib3270_strdup_printf(const char *fmt, ...)
  241 +{
  242 + va_list args;
  243 + char *r;
  244 +
  245 + va_start(args, fmt);
  246 + r = lib3270_vsprintf(fmt, args);
  247 + va_end(args);
  248 + return r;
  249 +}
  250 +
240 /* 251 /*
241 * Common helper functions to insert strings, through a template, into a new 252 * Common helper functions to insert strings, through a template, into a new
242 * buffer. 253 * buffer.
@@ -280,77 +291,6 @@ xs_error(const char *fmt, ...) @@ -280,77 +291,6 @@ xs_error(const char *fmt, ...)
280 lib3270_free(r); 291 lib3270_free(r);
281 } 292 }
282 293
283 -/* Prettyprinter for strings with unprintable data. */ /*  
284 -void  
285 -fcatv(FILE *f, char *s)  
286 -{  
287 - char c;  
288 -  
289 - while ((c = *s++)) {  
290 - switch (c) {  
291 - case '\n':  
292 - (void) fprintf(f, "\\n");  
293 - break;  
294 - case '\t':  
295 - (void) fprintf(f, "\\t");  
296 - break;  
297 - case '\b':  
298 - (void) fprintf(f, "\\b");  
299 - break;  
300 - default:  
301 - if ((c & 0x7f) < ' ')  
302 - (void) fprintf(f, "\\%03o", c & 0xff);  
303 - else  
304 - fputc(c, f);  
305 - break;  
306 - }  
307 - }  
308 -}  
309 -*/  
310 -  
311 -/* String version of fcatv. */ /*  
312 -char *  
313 -scatv(const char *s, char *buf, size_t len)  
314 -{  
315 - char c;  
316 - char *dst = buf;  
317 -  
318 - while ((c = *s++) && len > 0) {  
319 - char cbuf[5];  
320 - char *t = cbuf;  
321 -  
322 - // Expand this character.  
323 - switch (c) {  
324 - case '\n':  
325 - (void) strcpy(cbuf, "\\n");  
326 - break;  
327 - case '\t':  
328 - (void) strcpy(cbuf, "\\t");  
329 - break;  
330 - case '\b':  
331 - (void) strcpy(cbuf, "\\b");  
332 - break;  
333 - default:  
334 - if ((c & 0x7f) < ' ')  
335 - (void) sprintf(cbuf, "\\%03o", c & 0xff);  
336 - else {  
337 - cbuf[0] = c;  
338 - cbuf[1] = '\0';  
339 - }  
340 - break;  
341 - }  
342 - // Copy as much as will fit.  
343 - while ((c = *t++) && len > 0) {  
344 - *dst++ = c;  
345 - len--;  
346 - }  
347 - }  
348 - if (len > 0)  
349 - *dst = '\0';  
350 -  
351 - return buf;  
352 -}  
353 -*/  
354 294
355 /* 295 /*
356 * Definition resource splitter, for resources of the repeating form: 296 * Definition resource splitter, for resources of the repeating form: