| 5372 | */ |
| 5373 | |
| 5374 | static int /* O - 1 on success, 0 on failure */ |
| 5375 | cups_connect(http_t **http, /* IO - Current HTTP connection */ |
| 5376 | const char *url, /* I - URL to connect */ |
| 5377 | char *resource, /* I - Resource path buffer */ |
| 5378 | size_t ressize) /* I - Size of resource path buffer */ |
| 5379 | { |
| 5380 | char scheme[32], /* URL scheme */ |
| 5381 | userpass[256], /* URL username:password */ |
| 5382 | host[256], /* URL host */ |
| 5383 | curhost[256]; /* Current host */ |
| 5384 | int port; /* URL port */ |
| 5385 | http_encryption_t encryption; /* Type of encryption to use */ |
| 5386 | |
| 5387 | |
| 5388 | // Separate the URI... |
| 5389 | if (httpSeparateURI(HTTP_URI_CODING_ALL, url, scheme, sizeof(scheme), userpass, sizeof(userpass), host, sizeof(host), &port, resource, ressize) < HTTP_URI_STATUS_OK) |
| 5390 | return (0); |
| 5391 | |
| 5392 | // Use encryption as needed.. |
| 5393 | if (port == 443 || !strcmp(scheme, "https") || !strcmp(scheme, "ipps")) |
| 5394 | encryption = HTTP_ENCRYPTION_ALWAYS; |
| 5395 | else |
| 5396 | encryption = HTTP_ENCRYPTION_IF_REQUESTED; |
| 5397 | |
| 5398 | if (!*http || strcasecmp(host, httpGetHostname(*http, curhost, sizeof(curhost))) || httpAddrPort(httpGetAddress(*http)) != port || httpIsEncrypted(*http) != (encryption == HTTP_ENCRYPTION_ALWAYS)) |
| 5399 | { |
| 5400 | httpClose(*http); |
| 5401 | *http = httpConnect2(host, port, NULL, AF_UNSPEC, encryption, 1, 5000, NULL); |
| 5402 | } |
| 5403 | |
| 5404 | return (*http != NULL); |
| 5405 | } |
| 5406 | |
| 5407 | |
| 5408 | /* |
no test coverage detected