| 553 | */ |
| 554 | |
| 555 | int /* O - -1 on error, 0 on success */ |
| 556 | httpEncryption(http_t *http, /* I - HTTP connection */ |
| 557 | http_encryption_t e) /* I - New encryption preference */ |
| 558 | { |
| 559 | DEBUG_printf(("httpEncryption(http=%p, e=%d)", (void *)http, e)); |
| 560 | |
| 561 | #ifdef HAVE_TLS |
| 562 | if (!http) |
| 563 | return (0); |
| 564 | |
| 565 | if (http->mode == _HTTP_MODE_CLIENT) |
| 566 | { |
| 567 | http->encryption = e; |
| 568 | |
| 569 | if ((http->encryption == HTTP_ENCRYPTION_ALWAYS && !http->tls) || |
| 570 | (http->encryption == HTTP_ENCRYPTION_NEVER && http->tls)) |
| 571 | return (httpReconnect2(http, 30000, NULL)); |
| 572 | else if (http->encryption == HTTP_ENCRYPTION_REQUIRED && !http->tls) |
| 573 | return (http_tls_upgrade(http)); |
| 574 | else |
| 575 | return (0); |
| 576 | } |
| 577 | else |
| 578 | { |
| 579 | if (e == HTTP_ENCRYPTION_NEVER && http->tls) |
| 580 | return (-1); |
| 581 | |
| 582 | http->encryption = e; |
| 583 | if (e != HTTP_ENCRYPTION_IF_REQUESTED && !http->tls) |
| 584 | return (_httpTLSStart(http)); |
| 585 | else |
| 586 | return (0); |
| 587 | } |
| 588 | #else |
| 589 | if (e == HTTP_ENCRYPTION_ALWAYS || e == HTTP_ENCRYPTION_REQUIRED) |
| 590 | return (-1); |
| 591 | else |
| 592 | return (0); |
| 593 | #endif /* HAVE_TLS */ |
| 594 | } |
| 595 | |
| 596 | |
| 597 | /* |