/*
- * "$Id: request.c 6879 2007-08-29 20:26:50Z mike $"
+ * "$Id: request.c 7460 2008-04-16 02:19:54Z mike $"
*
* IPP utilities for the Common UNIX Printing System (CUPS).
*
* 'cupsDoFileRequest()' - Do an IPP request with a file.
*
* This function sends the IPP request to the specified server, retrying
- * and authenticating as necessary. The request is freed with ippDelete()
+ * and authenticating as necessary. The request is freed with @link ippDelete@
* after receiving a valid IPP response.
*/
ipp_t * /* O - Response data */
-cupsDoFileRequest(http_t *http, /* I - HTTP connection or CUPS_HTTP_DEFAULT */
+cupsDoFileRequest(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
ipp_t *request, /* I - IPP request */
const char *resource, /* I - HTTP resource for POST */
- const char *filename) /* I - File to send or NULL for none */
+ const char *filename) /* I - File to send or @code NULL@ for none */
{
ipp_t *response; /* IPP response data */
int infile; /* Input file */
+ DEBUG_printf(("cupsDoFileRequest(http=%p, request=%p(%s), resource=\"%s\", "
+ "filename=\"%s\")\n", http, request,
+ request ? ippOpString(request->request.op.operation_id) : "?",
+ resource ? resource : "(null)",
+ filename ? filename : "(null)"));
+
if (filename)
{
if ((infile = open(filename, O_RDONLY | O_BINARY)) < 0)
*/
ipp_t * /* O - Response data */
-cupsDoIORequest(http_t *http, /* I - HTTP connection or CUPS_HTTP_DEFAULT */
+cupsDoIORequest(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
ipp_t *request, /* I - IPP request */
const char *resource, /* I - HTTP resource for POST */
int infile, /* I - File to read from or -1 for none */
char buffer[32768]; /* Output buffer */
- DEBUG_printf(("cupsDoIORequest(http=%p, request=%p, resource=\"%s\""
+ DEBUG_printf(("cupsDoIORequest(http=%p, request=%p(%s), resource=\"%s\", "
"infile=%d, outfile=%d)\n", http, request,
+ request ? ippOpString(request->request.op.operation_id) : "?",
resource ? resource : "(null)", infile, outfile));
/*
*/
if (!http)
- http = _cupsConnect();
+ if ((http = _cupsConnect()) == NULL)
+ return (NULL);
/*
* See if we have a file to send...
status = http->status;
}
+ if (status == HTTP_FORBIDDEN)
+ break;
+
if (response)
{
if (outfile >= 0)
*/
ipp_t * /* O - Response data */
-cupsDoRequest(http_t *http, /* I - HTTP connection or CUPS_HTTP_DEFAULT */
+cupsDoRequest(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
ipp_t *request, /* I - IPP request */
const char *resource) /* I - HTTP resource for POST */
{
+ DEBUG_printf(("cupsDoRequest(http=%p, request=%p(%s), resource=\"%s\")\n",
+ http, request,
+ request ? ippOpString(request->request.op.operation_id) : "?",
+ resource ? resource : "(null)"));
+
return (cupsDoFileRequest(http, request, resource, NULL));
}
* @since CUPS 1.4@
*/
-ipp_t * /* O - Response or NULL on HTTP error */
-cupsGetResponse(http_t *http, /* I - HTTP connection or CUPS_HTTP_DEFAULT */
+ipp_t * /* O - Response or @code NULL@ on HTTP error */
+cupsGetResponse(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
const char *resource) /* I - HTTP resource for POST */
{
http_status_t status; /* HTTP status */
ipp_t *response = NULL; /* IPP response */
- DEBUG_printf(("cupsGetReponse(http=%p)\n", http));
+ DEBUG_printf(("cupsGetReponse(http=%p, resource=\"%s\")\n", http,
+ resource ? resource : "(null)"));
/*
* Connect to the default server as needed...
* Wait for a response from the server...
*/
- DEBUG_puts("cupsGetResponse: update...");
+ DEBUG_puts("cupsGetResponse: Update loop...");
while ((status = httpUpdate(http)) == HTTP_CONTINUE)
/* Do nothing but update */;
- DEBUG_printf(("cupsGetResponse: status = %d\n", status));
+ DEBUG_printf(("cupsGetResponse: status=%d\n", status));
if (status == HTTP_OK)
{
* Delete the response...
*/
- DEBUG_puts("IPP read error!");
+ DEBUG_puts("cupsGetResponse: IPP read error!");
ippDelete(response);
response = NULL;
* See if we can do authentication...
*/
+ int auth_result;
+
DEBUG_puts("cupsGetResponse: Need authorization...");
- if (!cupsDoAuthentication(http, "POST", resource))
+ if ((auth_result = cupsDoAuthentication(http, "POST", resource)) == 0)
httpReconnect(http);
+ else if (auth_result < 0)
+ http->status = status = HTTP_FORBIDDEN;
}
#ifdef HAVE_SSL
attr = ippFindAttribute(response, "status-message", IPP_TAG_TEXT);
+ DEBUG_printf(("cupsGetResponse: status-code=%s, status-message=\"%s\"\n",
+ ippErrorString(response->request.status.status_code),
+ attr ? attr->values[0].string.text : ""));
+
_cupsSetError(response->request.status.status_code,
attr ? attr->values[0].string.text :
ippErrorString(response->request.status.status_code));
ssize_t /* O - Bytes read, 0 on EOF, -1 on error */
cupsReadResponseData(
- http_t *http, /* I - HTTP connection or CUPS_HTTP_DEFAULT */
+ http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
char *buffer, /* I - Buffer to use */
size_t length) /* I - Number of bytes to read */
{
* Get the default connection as needed...
*/
+ DEBUG_printf(("cupsReadResponseData(http=%p, buffer=%p, "
+ "length=" CUPS_LLFMT ")\n", http, buffer, CUPS_LLCAST length));
+
if (!http)
{
_cups_globals_t *cg = _cupsGlobals();
*/
http_status_t /* O - Initial HTTP status */
-cupsSendRequest(http_t *http, /* I - HTTP connection or CUPS_HTTP_DEFAULT */
+cupsSendRequest(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
ipp_t *request, /* I - IPP request */
const char *resource, /* I - Resource path */
- size_t length) /* I - Length of data to follow or CUPS_LENGTH_VARIABLE */
+ size_t length) /* I - Length of data to follow or @code CUPS_LENGTH_VARIABLE@ */
{
http_status_t status; /* Status of HTTP request */
int got_status; /* Did we get the status? */
http_status_t expect; /* Expect: header to use */
- DEBUG_printf(("cupsSendRequest(http=%p, request=%p, resource=\"%s\", "
+ DEBUG_printf(("cupsSendRequest(http=%p, request=%p(%s), resource=\"%s\", "
"length=" CUPS_LLFMT ")\n", http, request,
+ request ? ippOpString(request->request.op.operation_id) : "?",
resource ? resource : "(null)", CUPS_LLCAST length));
/*
*/
if (!http)
- http = _cupsConnect();
+ if ((http = _cupsConnect()) == NULL)
+ return (HTTP_SERVICE_UNAVAILABLE);
#ifdef HAVE_SSL
/*
for (;;)
{
- DEBUG_puts("cupsSendRequest: setup...");
+ DEBUG_puts("cupsSendRequest: Setup...");
/*
* Setup the HTTP variables needed...
* Try the request...
*/
- DEBUG_puts("cupsSendRequest: post...");
+ DEBUG_puts("cupsSendRequest: Sending HTTP POST...");
if (httpPost(http, resource))
{
* Send the IPP data...
*/
- DEBUG_puts("cupsSendRequest: ipp write...");
+ DEBUG_puts("cupsSendRequest: Writing IPP request...");
request->state = IPP_IDLE;
status = HTTP_CONTINUE;
if (!got_status && expect == HTTP_CONTINUE)
{
+ DEBUG_puts("cupsSendRequest: Waiting for 100-continue...");
+
if (httpWait(http, 1000))
status = httpUpdate(http);
+ else
+ status = HTTP_EXPECTATION_FAILED;
}
else if (httpCheck(http))
status = httpUpdate(http);
+ DEBUG_printf(("cupsSendRequest: status=%d\n", status));
+
/*
* Process the current HTTP status...
*/
*/
expect = (http_status_t)0;
+ break;
default :
/*
/*
* 'cupsWriteRequestData()' - Write additional data after an IPP request.
*
- * This function is used after cupsSendRequest() or cupsStartDocument()
- * to provide a PPD or document file as needed.
+ * This function is used after @link cupsSendRequest@ to provide a PPD and
+ * after @link cupsStartDocument@ to provide a document file.
*
* @since CUPS 1.4@
*/
-http_status_t /* O - HTTP_CONTINUE if OK or HTTP status on error */
+http_status_t /* O - @code HTTP_CONTINUE@ if OK or HTTP status on error */
cupsWriteRequestData(
- http_t *http, /* I - HTTP connection or CUPS_HTTP_DEFAULT */
+ http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
const char *buffer, /* I - Bytes to write */
size_t length) /* I - Number of bytes to write */
{
* Get the default connection as needed...
*/
+ DEBUG_printf(("cupsWriteRequestData(http=%p, buffer=%p, "
+ "length=" CUPS_LLFMT ")\n", http, buffer, CUPS_LLCAST length));
+
if (!http)
{
_cups_globals_t *cg = _cupsGlobals();
if (message)
cg->last_status_message = strdup(message);
+
+ DEBUG_printf(("_cupsSetError: last_error=%s, last_status_message=\"%s\"\n",
+ ippErrorString(cg->last_error), message ? message : ""));
}
/*
- * End of "$Id: request.c 6879 2007-08-29 20:26:50Z mike $".
+ * End of "$Id: request.c 7460 2008-04-16 02:19:54Z mike $".
*/