Commit 2bfb60d4a6d2489cdcb43431a8ea817c92750531
1 parent
e68a04bc
Exists in
master
and in
3 other branches
Fixing multi-thread issues
Showing
5 changed files
with
120 additions
and
102 deletions
Show diff stats
src/include/lib3270.h
@@ -452,7 +452,7 @@ | @@ -452,7 +452,7 @@ | ||
452 | * @brief Set host id for the connect/reconnect operations. | 452 | * @brief Set host id for the connect/reconnect operations. |
453 | * | 453 | * |
454 | * @param h Session handle. | 454 | * @param h Session handle. |
455 | - * @param url URL of host to set in the format tn3270://hostname:service or tn3270s://hostname:service . | 455 | + * @param url URL of host to set in the format tn3270://hostname:service or tn3270s://hostname:service |
456 | * | 456 | * |
457 | * @return 0 | 457 | * @return 0 |
458 | * | 458 | * |
@@ -460,6 +460,15 @@ | @@ -460,6 +460,15 @@ | ||
460 | LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *url); | 460 | LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *url); |
461 | 461 | ||
462 | /** | 462 | /** |
463 | + * @brief Get the URL of the predefined tn3270 host. | ||
464 | + * | ||
465 | + * @param hSession Session handle. | ||
466 | + * | ||
467 | + * @return URL of the predefined host in the format tn3270://hostname:service or tn3270s://hostname:service | ||
468 | + */ | ||
469 | + LIB3270_EXPORT const char * lib3270_get_default_host(H3270 *hSession); | ||
470 | + | ||
471 | + /** | ||
463 | * @brief Set URL for the certificate revocation list. | 472 | * @brief Set URL for the certificate revocation list. |
464 | * | 473 | * |
465 | * @param hSession Session handle. | 474 | * @param hSession Session handle. |
src/lib3270/host.c
@@ -265,136 +265,134 @@ LIB3270_EXPORT const char * lib3270_get_url(H3270 *hSession) | @@ -265,136 +265,134 @@ LIB3270_EXPORT const char * lib3270_get_url(H3270 *hSession) | ||
265 | 265 | ||
266 | } | 266 | } |
267 | 267 | ||
268 | +LIB3270_EXPORT const char * lib3270_get_default_host(H3270 *hSession unused) | ||
269 | +{ | ||
270 | +#ifdef LIB3270_DEFAULT_HOST | ||
271 | + return LIB3270_DEFAULT_HOST; | ||
272 | +#else | ||
273 | + return getenv("LIB3270_DEFAULT_HOST"); | ||
274 | +#endif // LIB3270_DEFAULT_HOST | ||
275 | +} | ||
276 | + | ||
268 | LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n) | 277 | LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n) |
269 | { | 278 | { |
270 | FAIL_IF_ONLINE(h); | 279 | FAIL_IF_ONLINE(h); |
271 | 280 | ||
272 | if(!n) | 281 | if(!n) |
273 | - { | ||
274 | -#ifdef LIB3270_DEFAULT_HOST | ||
275 | - n = LIB3270_DEFAULT_HOST; | ||
276 | -#else | ||
277 | - n = getenv("LIB3270_DEFAULT_HOST"); | ||
278 | - if(!n) | ||
279 | - return errno = EINVAL; | ||
280 | -#endif // LIB3270_DEFAULT_HOST | ||
281 | - } | 282 | + n = lib3270_get_default_host(h); |
282 | 283 | ||
283 | - if(!h->host.full || strcmp(n,h->host.full)) | 284 | + if(!n) |
285 | + return errno = ENOENT; | ||
286 | + | ||
287 | + static const struct _sch | ||
288 | + { | ||
289 | + char ssl; | ||
290 | + const char * text; | ||
291 | + const char * srvc; | ||
292 | + } sch[] = | ||
284 | { | 293 | { |
285 | - static const struct _sch | ||
286 | - { | ||
287 | - char ssl; | ||
288 | - const char * text; | ||
289 | - const char * srvc; | ||
290 | - } sch[] = | ||
291 | - { | ||
292 | #ifdef HAVE_LIBSSL | 294 | #ifdef HAVE_LIBSSL |
293 | - { 1, "tn3270s://", "telnets" }, | ||
294 | - { 1, "telnets://", "telnets" }, | ||
295 | - { 1, "L://", "telnets" }, | ||
296 | - { 1, "L:", "telnets" }, | 295 | + { 1, "tn3270s://", "telnets" }, |
296 | + { 1, "telnets://", "telnets" }, | ||
297 | + { 1, "L://", "telnets" }, | ||
298 | + { 1, "L:", "telnets" }, | ||
297 | #endif // HAVE_LIBSSL | 299 | #endif // HAVE_LIBSSL |
298 | 300 | ||
299 | - { 0, "tn3270://", "telnet" }, | ||
300 | - { 0, "telnet://", "telnet" } | 301 | + { 0, "tn3270://", "telnet" }, |
302 | + { 0, "telnet://", "telnet" } | ||
301 | 303 | ||
302 | - }; | 304 | + }; |
303 | 305 | ||
304 | - char * str = strdup(n); | ||
305 | - char * hostname = str; | ||
306 | - const char * srvc = "telnet"; | ||
307 | - char * ptr; | ||
308 | - char * query = ""; | ||
309 | - int f; | 306 | + lib3270_autoptr(char) str = strdup(n); |
307 | + char * hostname = str; | ||
308 | + const char * srvc = "telnet"; | ||
309 | + char * ptr; | ||
310 | + char * query = ""; | ||
311 | + int f; | ||
310 | 312 | ||
311 | - trace("%s(%s)",__FUNCTION__,str); | 313 | + trace("%s(%s)",__FUNCTION__,str); |
312 | 314 | ||
313 | #ifdef HAVE_LIBSSL | 315 | #ifdef HAVE_LIBSSL |
314 | - h->ssl.enabled = 0; | 316 | + h->ssl.enabled = 0; |
315 | #endif // HAVE_LIBSSL | 317 | #endif // HAVE_LIBSSL |
316 | 318 | ||
317 | - for(f=0;f < sizeof(sch)/sizeof(sch[0]);f++) | 319 | + for(f=0;f < sizeof(sch)/sizeof(sch[0]);f++) |
320 | + { | ||
321 | + size_t sz = strlen(sch[f].text); | ||
322 | + if(!strncasecmp(hostname,sch[f].text,sz)) | ||
318 | { | 323 | { |
319 | - size_t sz = strlen(sch[f].text); | ||
320 | - if(!strncasecmp(hostname,sch[f].text,sz)) | ||
321 | - { | ||
322 | #ifdef HAVE_LIBSSL | 324 | #ifdef HAVE_LIBSSL |
323 | - h->ssl.enabled = sch[f].ssl; | 325 | + h->ssl.enabled = sch[f].ssl; |
324 | #endif // HAVE_LIBSSL | 326 | #endif // HAVE_LIBSSL |
325 | - srvc = sch[f].srvc; | ||
326 | - hostname += sz; | ||
327 | - break; | ||
328 | - } | 327 | + srvc = sch[f].srvc; |
328 | + hostname += sz; | ||
329 | + break; | ||
329 | } | 330 | } |
331 | + } | ||
330 | 332 | ||
331 | - if(!*hostname) | ||
332 | - return 0; | 333 | + if(!*hostname) |
334 | + return 0; | ||
333 | 335 | ||
334 | - ptr = strchr(hostname,':'); | ||
335 | - if(ptr) | ||
336 | - { | ||
337 | - *(ptr++) = 0; | ||
338 | - srvc = ptr; | ||
339 | - query = strchr(ptr,'?'); | 336 | + ptr = strchr(hostname,':'); |
337 | + if(ptr) | ||
338 | + { | ||
339 | + *(ptr++) = 0; | ||
340 | + srvc = ptr; | ||
341 | + query = strchr(ptr,'?'); | ||
340 | 342 | ||
341 | - trace("QUERY=[%s]",query); | 343 | + trace("QUERY=[%s]",query); |
342 | 344 | ||
343 | - if(query) | ||
344 | - *(query++) = 0; | ||
345 | - else | ||
346 | - query = ""; | ||
347 | - } | 345 | + if(query) |
346 | + *(query++) = 0; | ||
347 | + else | ||
348 | + query = ""; | ||
349 | + } | ||
348 | 350 | ||
349 | - trace("SRVC=[%s]",srvc); | 351 | + trace("SRVC=[%s]",srvc); |
350 | 352 | ||
351 | - Replace(h->host.current,strdup(hostname)); | ||
352 | - Replace(h->host.srvc,strdup(srvc)); | 353 | + Replace(h->host.current,strdup(hostname)); |
354 | + Replace(h->host.srvc,strdup(srvc)); | ||
353 | 355 | ||
354 | - // Verifica parâmetros | ||
355 | - if(query && *query) | ||
356 | - { | ||
357 | - char *str = strdup(query); | ||
358 | - char *ptr; | 356 | + // Verifica parâmetros |
357 | + if(query && *query) | ||
358 | + { | ||
359 | + lib3270_autoptr(char) str = strdup(query); | ||
360 | + char *ptr; | ||
359 | 361 | ||
360 | #ifdef HAVE_STRTOK_R | 362 | #ifdef HAVE_STRTOK_R |
361 | - char *saveptr = NULL; | ||
362 | - for(ptr = strtok_r(str,"&",&saveptr);ptr;ptr=strtok_r(NULL,"&",&saveptr)) | 363 | + char *saveptr = NULL; |
364 | + for(ptr = strtok_r(str,"&",&saveptr);ptr;ptr=strtok_r(NULL,"&",&saveptr)) | ||
363 | #else | 365 | #else |
364 | - for(ptr = strtok(str,"&");ptr;ptr=strtok(NULL,"&")) | 366 | + for(ptr = strtok(str,"&");ptr;ptr=strtok(NULL,"&")) |
365 | #endif | 367 | #endif |
368 | + { | ||
369 | + char *var = ptr; | ||
370 | + char *val = strchr(ptr,'='); | ||
371 | + if(val) | ||
366 | { | 372 | { |
367 | - char *var = ptr; | ||
368 | - char *val = strchr(ptr,'='); | ||
369 | - if(val) | ||
370 | - { | ||
371 | - *(val++) = 0; | 373 | + *(val++) = 0; |
372 | 374 | ||
373 | - if(lib3270_set_string_property(h, var, val, 0) == 0) | ||
374 | - continue; | 375 | + if(lib3270_set_string_property(h, var, val, 0) == 0) |
376 | + continue; | ||
375 | 377 | ||
376 | - lib3270_write_log(h,"","Can't set attribute \"%s\": %s",var,strerror(errno)); | 378 | + lib3270_write_log(h,"","Can't set attribute \"%s\": %s",var,strerror(errno)); |
377 | 379 | ||
378 | - } | ||
379 | - else | ||
380 | - { | ||
381 | - if(lib3270_set_int_property(h,var,1,0)) | ||
382 | - continue; | ||
383 | - | ||
384 | - lib3270_write_log(h,"","Can't set attribute \"%s\": %s",var,strerror(errno)); | ||
385 | - } | 380 | + } |
381 | + else | ||
382 | + { | ||
383 | + if(lib3270_set_int_property(h,var,1,0)) | ||
384 | + continue; | ||
386 | 385 | ||
386 | + lib3270_write_log(h,"","Can't set attribute \"%s\": %s",var,strerror(errno)); | ||
387 | } | 387 | } |
388 | 388 | ||
389 | - free(str); | ||
390 | } | 389 | } |
391 | 390 | ||
392 | - // Notifica atualização | ||
393 | - update_host(h); | ||
394 | - | ||
395 | - free(str); | ||
396 | } | 391 | } |
397 | 392 | ||
393 | + // Notifica atualização | ||
394 | + update_host(h); | ||
395 | + | ||
398 | return 0; | 396 | return 0; |
399 | } | 397 | } |
400 | 398 |
src/lib3270/iocalls.c
@@ -449,6 +449,9 @@ LIB3270_EXPORT int lib3270_register_io_controller(const LIB3270_IO_CONTROLLER *c | @@ -449,6 +449,9 @@ LIB3270_EXPORT int lib3270_register_io_controller(const LIB3270_IO_CONTROLLER *c | ||
449 | if(cbk->run_task) | 449 | if(cbk->run_task) |
450 | run_task = cbk->run_task; | 450 | run_task = cbk->run_task; |
451 | 451 | ||
452 | + if(cbk->set_poll_state) | ||
453 | + set_poll_state = cbk->set_poll_state; | ||
454 | + | ||
452 | return 0; | 455 | return 0; |
453 | 456 | ||
454 | } | 457 | } |
src/lib3270/properties.c
@@ -350,42 +350,42 @@ | @@ -350,42 +350,42 @@ | ||
350 | 350 | ||
351 | { | 351 | { |
352 | "luname", // Property name. | 352 | "luname", // Property name. |
353 | - N_( "" ), // Property description. | 353 | + N_( "The name of the active LU" ), // Property description. |
354 | lib3270_get_luname, // Get value. | 354 | lib3270_get_luname, // Get value. |
355 | lib3270_set_luname // Set value. | 355 | lib3270_set_luname // Set value. |
356 | }, | 356 | }, |
357 | 357 | ||
358 | { | 358 | { |
359 | "url", // Property name. | 359 | "url", // Property name. |
360 | - N_( "" ), // Property description. | 360 | + N_( "URL of the current host" ), // Property description. |
361 | lib3270_get_url, // Get value. | 361 | lib3270_get_url, // Get value. |
362 | lib3270_set_url // Set value. | 362 | lib3270_set_url // Set value. |
363 | }, | 363 | }, |
364 | 364 | ||
365 | { | 365 | { |
366 | "model", // Property name. | 366 | "model", // Property name. |
367 | - N_( "" ), // Property description. | 367 | + N_( "Model name" ), // Property description. |
368 | lib3270_get_model, // Get value. | 368 | lib3270_get_model, // Get value. |
369 | lib3270_set_model // Set value. | 369 | lib3270_set_model // Set value. |
370 | }, | 370 | }, |
371 | 371 | ||
372 | { | 372 | { |
373 | "host_type", // Property name. | 373 | "host_type", // Property name. |
374 | - N_( "" ), // Property description. | 374 | + N_( "Host type name" ), // Property description. |
375 | lib3270_get_host_type_name, // Get value. | 375 | lib3270_get_host_type_name, // Get value. |
376 | lib3270_set_host_type_by_name // Set value. | 376 | lib3270_set_host_type_by_name // Set value. |
377 | }, | 377 | }, |
378 | 378 | ||
379 | { | 379 | { |
380 | "host_charset", // Property name. | 380 | "host_charset", // Property name. |
381 | - N_( "" ), // Property description. | 381 | + N_( "Host charset" ), // Property description. |
382 | lib3270_get_host_charset, // Get value. | 382 | lib3270_get_host_charset, // Get value. |
383 | lib3270_set_host_charset // Set value. | 383 | lib3270_set_host_charset // Set value. |
384 | }, | 384 | }, |
385 | 385 | ||
386 | { | 386 | { |
387 | "display_charset", // Property name. | 387 | "display_charset", // Property name. |
388 | - N_( "" ), // Property description. | 388 | + N_( "Display charset" ), // Property description. |
389 | lib3270_get_display_charset, // Get value. | 389 | lib3270_get_display_charset, // Get value. |
390 | NULL // Set value. | 390 | NULL // Set value. |
391 | }, | 391 | }, |
@@ -405,10 +405,17 @@ | @@ -405,10 +405,17 @@ | ||
405 | }, | 405 | }, |
406 | 406 | ||
407 | { | 407 | { |
408 | - "crlpath", // Property name. | ||
409 | - N_( "URL for the CRL file" ), // Property description. | ||
410 | - lib3270_get_crl_url, // Get value. | ||
411 | - lib3270_set_crl_url, // Set value. | 408 | + "crlpath", // Property name. |
409 | + N_( "URL for the certificate revocation list" ), // Property description. | ||
410 | + lib3270_get_crl_url, // Get value. | ||
411 | + lib3270_set_crl_url, // Set value. | ||
412 | + }, | ||
413 | + | ||
414 | + { | ||
415 | + "default_host", // Property name. | ||
416 | + N_( "Default host URL" ), // Property description. | ||
417 | + lib3270_get_default_host, // Get value. | ||
418 | + NULL // Set value. | ||
412 | }, | 419 | }, |
413 | 420 | ||
414 | 421 |
src/lib3270/ssl/negotiate.c
@@ -270,10 +270,6 @@ static int background_ssl_negotiation(H3270 *hSession, void *message) | @@ -270,10 +270,6 @@ static int background_ssl_negotiation(H3270 *hSession, void *message) | ||
270 | X509_free(peer); | 270 | X509_free(peer); |
271 | } | 271 | } |
272 | 272 | ||
273 | - | ||
274 | - /* Tell the world that we are (still) connected, now in secure mode. */ | ||
275 | - lib3270_set_connected_initial(hSession); | ||
276 | - | ||
277 | return 0; | 273 | return 0; |
278 | } | 274 | } |
279 | 275 | ||
@@ -300,6 +296,11 @@ int ssl_negotiate(H3270 *hSession) | @@ -300,6 +296,11 @@ int ssl_negotiate(H3270 *hSession) | ||
300 | 296 | ||
301 | 297 | ||
302 | } | 298 | } |
299 | + else | ||
300 | + { | ||
301 | + /* Tell the world that we are (still) connected, now in secure mode. */ | ||
302 | + lib3270_set_connected_initial(hSession); | ||
303 | + } | ||
303 | 304 | ||
304 | non_blocking(hSession,True); | 305 | non_blocking(hSession,True); |
305 | 306 |