| 589 | */ |
| 590 | |
| 591 | http_status_t /* O - Initial HTTP status */ |
| 592 | cupsSendRequest(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ |
| 593 | ipp_t *request, /* I - IPP request */ |
| 594 | const char *resource, /* I - Resource path */ |
| 595 | size_t length) /* I - Length of data to follow or @code CUPS_LENGTH_VARIABLE@ */ |
| 596 | { |
| 597 | http_status_t status; /* Status of HTTP request */ |
| 598 | int got_status; /* Did we get the status? */ |
| 599 | ipp_state_t state; /* State of IPP processing */ |
| 600 | http_status_t expect; /* Expect: header to use */ |
| 601 | char date[256]; /* Date: header value */ |
| 602 | int digest; /* Are we using Digest authentication? */ |
| 603 | |
| 604 | |
| 605 | DEBUG_printf(("cupsSendRequest(http=%p, request=%p(%s), resource=\"%s\", length=" CUPS_LLFMT ")", (void *)http, (void *)request, request ? ippOpString(request->request.op.operation_id) : "?", resource, CUPS_LLCAST length)); |
| 606 | |
| 607 | /* |
| 608 | * Range check input... |
| 609 | */ |
| 610 | |
| 611 | if (!request || !resource) |
| 612 | { |
| 613 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0); |
| 614 | |
| 615 | return (HTTP_STATUS_ERROR); |
| 616 | } |
| 617 | |
| 618 | /* |
| 619 | * Get the default connection as needed... |
| 620 | */ |
| 621 | |
| 622 | if (!http && (http = _cupsConnect()) == NULL) |
| 623 | return (HTTP_STATUS_SERVICE_UNAVAILABLE); |
| 624 | |
| 625 | /* |
| 626 | * If the prior request was not flushed out, do so now... |
| 627 | */ |
| 628 | |
| 629 | if (http->state == HTTP_STATE_GET_SEND || |
| 630 | http->state == HTTP_STATE_POST_SEND) |
| 631 | { |
| 632 | DEBUG_puts("2cupsSendRequest: Flush prior response."); |
| 633 | httpFlush(http); |
| 634 | } |
| 635 | else if (http->state != HTTP_STATE_WAITING) |
| 636 | { |
| 637 | DEBUG_printf(("1cupsSendRequest: Unknown HTTP state (%d), " |
| 638 | "reconnecting.", http->state)); |
| 639 | if (httpReconnect2(http, 30000, NULL)) |
| 640 | return (HTTP_STATUS_ERROR); |
| 641 | } |
| 642 | |
| 643 | #ifdef HAVE_TLS |
| 644 | /* |
| 645 | * See if we have an auth-info attribute and are communicating over |
| 646 | * a non-local link. If so, encrypt the link so that we can pass |
| 647 | * the authentication information securely... |
| 648 | */ |
no test coverage detected