Commit 8367962468b38845047b4c3ae72d9e75d731b662
1 parent
38a5bff1
Exists in
master
and in
3 other branches
Ajuste no tratamento de hostname para o novo formato de conexão
Showing
6 changed files
with
231 additions
and
168 deletions
Show diff stats
connect.c
... | ... | @@ -201,6 +201,19 @@ static void net_connected(H3270 *hSession) |
201 | 201 | sockstart(hSession); |
202 | 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 | 217 | set_ssl_state(hSession,LIB3270_SSL_UNSECURE); |
205 | 218 | |
206 | 219 | hSession->ever_3270 = False; |
... | ... | @@ -231,7 +244,8 @@ static void net_connected(H3270 *hSession) |
231 | 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 | 250 | s = getaddrinfo(hostname, srvc, &hints, &result); |
237 | 251 | |
... | ... | @@ -286,15 +300,25 @@ static void net_connected(H3270 *hSession) |
286 | 300 | (void) fcntl(hSession->sock, F_SETFD, 1); |
287 | 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 | 306 | if(opt&LIB3270_CONNECT_OPTION_SSL) |
293 | 307 | { |
308 | +#if defined(HAVE_LIBSSL) | |
294 | 309 | hSession->ssl_host = 1; |
295 | 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 | 323 | /* connect */ |
300 | 324 | status_connecting(hSession,1); | ... | ... |
host.c
... | ... | @@ -38,6 +38,7 @@ |
38 | 38 | * connection. |
39 | 39 | */ |
40 | 40 | |
41 | +#include <malloc.h> | |
41 | 42 | #include "globals.h" |
42 | 43 | // #include "appres.h" |
43 | 44 | #include "resources.h" |
... | ... | @@ -64,7 +65,7 @@ static void try_reconnect(H3270 *session); |
64 | 65 | * Returns the hostname part in a newly-malloc'd string. |
65 | 66 | * 'needed' is returned True if anything was actually stripped. |
66 | 67 | * Returns NULL if there is a syntax error. |
67 | - */ | |
68 | + */ /* | |
68 | 69 | static char * |
69 | 70 | split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, |
70 | 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 | 86 | |
86 | 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 | 101 | while (*s && isspace(*s)) |
101 | 102 | s++; |
102 | 103 | |
... | ... | @@ -106,11 +107,11 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, |
106 | 107 | goto split_fail; |
107 | 108 | } |
108 | 109 | |
109 | - /* Strip trailing whitespace. */ | |
110 | + // Strip trailing whitespace. | |
110 | 111 | while (isspace(*(s + strlen(s) - 1))) |
111 | 112 | *(s + strlen(s) - 1) = '\0'; |
112 | 113 | |
113 | - /* Start with the prefixes. */ | |
114 | + // Start with the prefixes. | |
114 | 115 | while (*s && *(s + 1) && isalpha(*s) && *(s + 1) == ':') { |
115 | 116 | switch (*s) { |
116 | 117 | case 'a': |
... | ... | @@ -160,12 +161,12 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, |
160 | 161 | *needed = True; |
161 | 162 | s += 2; |
162 | 163 | |
163 | - /* Allow whitespace around the prefixes. */ | |
164 | + // Allow whitespace around the prefixes. | |
164 | 165 | while (*s && isspace(*s)) |
165 | 166 | s++; |
166 | 167 | } |
167 | 168 | |
168 | - /* Process the LU name. */ | |
169 | + // Process the LU name. | |
169 | 170 | lbracket = strchr(s, '['); |
170 | 171 | at = strchr(s, '@'); |
171 | 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 | 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 | 212 | if (lbracket != CN) { |
212 | 213 | char *rbracket; |
213 | 214 | |
214 | - /* Check for junk before the '['. */ | |
215 | + // Check for junk before the '['. | |
215 | 216 | if (lbracket != s) { |
216 | 217 | popup_system_error(hSession,NULL,_("Hostname syntax error"),"%s",_("Text before '['")); |
217 | 218 | goto split_fail; |
... | ... | @@ -219,10 +220,10 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, |
219 | 220 | |
220 | 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 | 227 | rbracket = strchr(s, ']'); |
227 | 228 | if (rbracket == CN) { |
228 | 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 | 235 | } |
235 | 236 | *rbracket = '\0'; |
236 | 237 | |
237 | - /* Skip over any whitespace after the bracketed name. */ | |
238 | + // Skip over any whitespace after the bracketed name. | |
238 | 239 | s = rbracket + 1; |
239 | 240 | while (*s && isspace(*s)) |
240 | 241 | s++; |
... | ... | @@ -244,7 +245,7 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, |
244 | 245 | } else { |
245 | 246 | char *name_end; |
246 | 247 | |
247 | - /* Check for an empty string. */ | |
248 | + // Check for an empty string. | |
248 | 249 | if (!*s || *s == ':') { |
249 | 250 | popup_an_error(hSession,"Empty hostname"); |
250 | 251 | goto split_fail; |
... | ... | @@ -252,19 +253,19 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, |
252 | 253 | |
253 | 254 | s = r = NewString(s); |
254 | 255 | |
255 | - /* Find the end of the hostname. */ | |
256 | + // Find the end of the hostname. | |
256 | 257 | while (*s && !isspace(*s) && *s != ':') |
257 | 258 | s++; |
258 | 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 | 262 | while (*s && isspace(*s)) |
262 | 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 | 269 | if (*s == '\0') { |
269 | 270 | *name_end = '\0'; |
270 | 271 | goto split_success; |
... | ... | @@ -273,10 +274,10 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, |
273 | 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 | 281 | if (colon) { |
281 | 282 | s++; |
282 | 283 | while (*s && isspace(*s)) |
... | ... | @@ -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 | 296 | *port = s; |
296 | 297 | *needed = True; |
297 | 298 | while (*s && !isspace(*s) && *s != ':') |
... | ... | @@ -309,23 +310,25 @@ split_fail: |
309 | 310 | split_success: |
310 | 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 | 320 | // char *ps = CN; |
319 | - char *port = CN; | |
321 | +// char *port = CN; | |
320 | 322 | Boolean resolving; |
321 | 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 | 327 | if (lib3270_connected(hSession) || hSession->auto_reconnect_inprogress) |
326 | 328 | return EBUSY; |
327 | 329 | |
328 | - /* Skip leading blanks. */ | |
330 | + /* | |
331 | + // Skip leading blanks. | |
329 | 332 | while (*n == ' ') |
330 | 333 | n++; |
331 | 334 | |
... | ... | @@ -334,22 +337,26 @@ static int do_connect(H3270 *hSession, const char *n) |
334 | 337 | popup_an_error(hSession,_( "Invalid (empty) hostname" )); |
335 | 338 | return -1; |
336 | 339 | } |
340 | + */ | |
337 | 341 | |
338 | - /* Save in a modifiable buffer. */ | |
342 | + /* | |
343 | + // Save in a modifiable buffer. | |
339 | 344 | (void) strncpy(nb, n, 2047); |
340 | 345 | |
341 | - /* Strip trailing blanks. */ | |
346 | + // Strip trailing blanks. | |
342 | 347 | s = nb + strlen(nb) - 1; |
343 | 348 | while (*s == ' ') |
344 | 349 | *s-- = '\0'; |
350 | + */ | |
345 | 351 | |
346 | 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 | 357 | Boolean needed; |
351 | 358 | |
352 | - /* Strip off and remember leading qualifiers. */ | |
359 | + // Strip off and remember leading qualifiers. | |
353 | 360 | if ((s = split_host(hSession, nb, &ansi_host, &hSession->std_ds_host, |
354 | 361 | &hSession->passthru_host, &hSession->non_tn3270e_host, &hSession->ssl_host, |
355 | 362 | &hSession->no_login_host, hSession->luname, &port, |
... | ... | @@ -358,35 +365,52 @@ static int do_connect(H3270 *hSession, const char *n) |
358 | 365 | |
359 | 366 | chost = s; |
360 | 367 | |
361 | - /* Default the port. */ | |
368 | + // Default the port. | |
362 | 369 | if (port == CN) |
363 | 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 | 383 | has_colons = (strchr(chost, ':') != NULL); |
376 | 384 | |
377 | - Replace(hSession->qualified_host, | |
385 | + Replace(hSession->host.qualified, | |
378 | 386 | xs_buffer("%s%s%s%s:%s", |
379 | 387 | hSession->ssl_host? "L:": "", |
380 | 388 | has_colons? "[": "", |
381 | 389 | chost, |
382 | 390 | has_colons? "]": "", |
383 | 391 | port)); |
384 | - | |
392 | + */ | |
385 | 393 | |
386 | 394 | /* Attempt contact. */ |
387 | 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 | 415 | /* Redundantly signal a disconnect. */ |
392 | 416 | lib3270_set_disconnected(hSession); |
... | ... | @@ -457,14 +481,13 @@ int lib3270_connect(H3270 *hSession, const char *n, int wait) |
457 | 481 | if(PCONNECTED) |
458 | 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 | 491 | if(rc) |
469 | 492 | return rc; |
470 | 493 | |
... | ... | @@ -489,7 +512,7 @@ int lib3270_connect(H3270 *hSession, const char *n, int wait) |
489 | 512 | */ |
490 | 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 | 516 | session->auto_reconnect_inprogress = 0; |
494 | 517 | lib3270_reconnect(session,0); |
495 | 518 | } |
... | ... | @@ -626,26 +649,88 @@ LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n) |
626 | 649 | { |
627 | 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 | 730 | LIB3270_EXPORT const char * lib3270_get_host(H3270 *h) |
646 | 731 | { |
647 | 732 | CHECK_SESSION_HANDLE(h); |
648 | - return h->full_current_host; | |
733 | + return h->host.full; | |
649 | 734 | } |
650 | 735 | |
651 | 736 | LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int wait) |
... | ... | @@ -657,13 +742,13 @@ LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int wait) |
657 | 742 | if (CONNECTED || HALF_CONNECTED) |
658 | 743 | return EBUSY; |
659 | 744 | |
660 | - if (hSession->full_current_host == CN) | |
745 | + if (hSession->host.full == CN) | |
661 | 746 | return EINVAL; |
662 | 747 | |
663 | 748 | if (hSession->auto_reconnect_inprogress) |
664 | 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 | 753 | if(rc) |
669 | 754 | { | ... | ... |
session.c
... | ... | @@ -99,6 +99,13 @@ void lib3270_session_free(H3270 *h) |
99 | 99 | if(h == default_session) |
100 | 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 | 109 | lib3270_free(h); |
103 | 110 | |
104 | 111 | } | ... | ... |
telnet.c
... | ... | @@ -501,7 +501,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo |
501 | 501 | *resolving = False; |
502 | 502 | *pending = False; |
503 | 503 | |
504 | - Replace(session->hostname, NewString(host)); | |
504 | +// Replace(session->hostname, NewString(host)); | |
505 | 505 | |
506 | 506 | /* get the passthru host and port number */ |
507 | 507 | if (session->passthru_host) |
... | ... | @@ -656,7 +656,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo |
656 | 656 | } |
657 | 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 | 661 | lib3270_popup_dialog( session, |
662 | 662 | LIB3270_NOTIFY_ERROR, |
... | ... | @@ -778,9 +778,10 @@ static void setup_lus(H3270 *hSession) |
778 | 778 | |
779 | 779 | static int net_connected(H3270 *hSession) |
780 | 780 | { |
781 | + /* | |
781 | 782 | if(hSession->proxy_type > 0) |
782 | 783 | { |
783 | - /* Negotiate with the proxy. */ | |
784 | + // Negotiate with the proxy. | |
784 | 785 | trace_dsn(hSession,"Connected to proxy server %s, port %u.\n",hSession->proxy_host, hSession->proxy_port); |
785 | 786 | |
786 | 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 | 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 | 797 | #if defined(HAVE_LIBSSL) |
796 | 798 | /* Set up SSL. */ |
... | ... | @@ -847,6 +849,7 @@ LIB3270_EXPORT void lib3270_setup_session(H3270 *hSession) |
847 | 849 | check_linemode(hSession,True); |
848 | 850 | |
849 | 851 | /* write out the passthru hostname and port nubmer */ |
852 | + /* | |
850 | 853 | if (hSession->passthru_host) |
851 | 854 | { |
852 | 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 | 857 | lib3270_free(buffer); |
855 | 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 | 1040 | |
1037 | 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 | 1045 | else if (socket_errno() != SE_ECONNRESET) |
1042 | 1046 | { | ... | ... |
testprogram.c
... | ... | @@ -22,7 +22,7 @@ static void * mainloop(void *dunno) |
22 | 22 | int main(int numpar, char *param[]) |
23 | 23 | { |
24 | 24 | H3270 * h; |
25 | - int rc; | |
25 | + int rc = 0; | |
26 | 26 | // char line[4096]; |
27 | 27 | // pthread_t thread; |
28 | 28 | |
... | ... | @@ -37,7 +37,10 @@ int main(int numpar, char *param[]) |
37 | 37 | // pthread_detach(thread); |
38 | 38 | |
39 | 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 | 45 | printf("\nConnect exits with rc=%d\n",rc); |
43 | 46 | ... | ... |
util.c
... | ... | @@ -237,6 +237,17 @@ char * lib3270_vsprintf(const char *fmt, va_list args) |
237 | 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 | 252 | * Common helper functions to insert strings, through a template, into a new |
242 | 253 | * buffer. |
... | ... | @@ -280,77 +291,6 @@ xs_error(const char *fmt, ...) |
280 | 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 | 296 | * Definition resource splitter, for resources of the repeating form: | ... | ... |