DEBUG_printf(("cupsDoFileRequest(http=%p, request=%p(%s), resource=\"%s\", "
- "filename=\"%s\")\n", http, request,
+ "filename=\"%s\")", http, request,
request ? ippOpString(request->request.op.operation_id) : "?",
- resource ? resource : "(null)",
- filename ? filename : "(null)"));
+ resource, filename));
if (filename)
{
DEBUG_printf(("cupsDoIORequest(http=%p, request=%p(%s), resource=\"%s\", "
- "infile=%d, outfile=%d)\n", http, request,
+ "infile=%d, outfile=%d)", http, request,
request ? ippOpString(request->request.op.operation_id) : "?",
- resource ? resource : "(null)", infile, outfile));
+ resource, infile, outfile));
/*
* Range check input...
else
length = ippLength(request);
- DEBUG_printf(("cupsDoIORequest: Request length=%ld, total length=%ld",
+ DEBUG_printf(("2cupsDoIORequest: Request length=%ld, total length=%ld",
(long)ippLength(request), (long)length));
/*
while (response == NULL)
{
- DEBUG_puts("cupsDoIORequest: setup...");
+ DEBUG_puts("2cupsDoIORequest: setup...");
/*
* Send the request...
status = cupsSendRequest(http, request, resource, length);
- DEBUG_printf(("cupsDoIORequest: status=%d\n", status));
+ DEBUG_printf(("2cupsDoIORequest: status=%d", status));
if (status == HTTP_CONTINUE && request->state == IPP_DATA && infile >= 0)
{
- DEBUG_puts("cupsDoIORequest: file write...");
+ DEBUG_puts("2cupsDoIORequest: file write...");
/*
* Send the file with the request...
status = http->status;
}
+ DEBUG_printf(("2cupsDoIORequest: status=%d", status));
+
if (status == HTTP_FORBIDDEN || status == HTTP_ERROR ||
- status == HTTP_SERVICE_UNAVAILABLE)
+ status >= HTTP_SERVER_ERROR)
{
_cupsSetHTTPError(status);
break;
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",
+ DEBUG_printf(("cupsDoRequest(http=%p, request=%p(%s), resource=\"%s\")",
http, request,
request ? ippOpString(request->request.op.operation_id) : "?",
- resource ? resource : "(null)"));
+ resource));
return (cupsDoIORequest(http, request, resource, -1, -1));
}
* cupsSendDocument() or cupsSendRequest(). For requests that return
* additional data, use httpRead() after getting a successful response.
*
- * @since CUPS 1.4@
+ * @since CUPS 1.4/Mac OS X 10.6@
*/
ipp_t * /* O - Response or @code NULL@ on HTTP error */
ipp_t *response = NULL; /* IPP response */
- DEBUG_printf(("cupsGetReponse(http=%p, resource=\"%s\")\n", http,
- resource ? resource : "(null)"));
+ DEBUG_printf(("cupsGetResponse(http=%p, resource=\"%s\")", http, resource));
/*
* Connect to the default server as needed...
* Send a 0-length chunk to finish off the request...
*/
- DEBUG_puts("cupsGetResponse: Finishing chunked POST...");
+ DEBUG_puts("2cupsGetResponse: Finishing chunked POST...");
if (httpWrite2(http, "", 0) < 0)
return (NULL);
* Wait for a response from the server...
*/
- DEBUG_printf(("cupsGetResponse: Update loop, http->status=%d...\n",
+ DEBUG_printf(("2cupsGetResponse: Update loop, http->status=%d...",
http->status));
status = http->status;
while (status == HTTP_CONTINUE)
status = httpUpdate(http);
- DEBUG_printf(("cupsGetResponse: status=%d\n", status));
+ DEBUG_printf(("2cupsGetResponse: status=%d", status));
if (status == HTTP_OK)
{
* Delete the response...
*/
- DEBUG_puts("cupsGetResponse: IPP read error!");
+ DEBUG_puts("1cupsGetResponse: IPP read error!");
ippDelete(response);
response = NULL;
* See if we can do authentication...
*/
- int auth_result;
-
- DEBUG_puts("cupsGetResponse: Need authorization...");
+ DEBUG_puts("2cupsGetResponse: Need authorization...");
- if ((auth_result = cupsDoAuthentication(http, "POST", resource)) == 0)
+ if (!cupsDoAuthentication(http, "POST", resource))
httpReconnect(http);
- else if (auth_result < 0)
- http->status = status = HTTP_FORBIDDEN;
+ else
+ status = HTTP_AUTHORIZATION_CANCELED;
}
#ifdef HAVE_SSL
* Force a reconnect with encryption...
*/
- DEBUG_puts("cupsGetResponse: Need encryption...");
+ DEBUG_puts("2cupsGetResponse: Need encryption...");
if (!httpReconnect(http))
httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
attr = ippFindAttribute(response, "status-message", IPP_TAG_TEXT);
- DEBUG_printf(("cupsGetResponse: status-code=%s, status-message=\"%s\"\n",
+ DEBUG_printf(("1cupsGetResponse: status-code=%s, status-message=\"%s\"",
ippErrorString(response->request.status.status_code),
attr ? attr->values[0].string.text : ""));
* This function is used after cupsGetResponse() to read the PPD or document
* files for CUPS_GET_PPD and CUPS_GET_DOCUMENT requests, respectively.
*
- * @since CUPS 1.4@
+ * @since CUPS 1.4/Mac OS X 10.6@
*/
ssize_t /* O - Bytes read, 0 on EOF, -1 on error */
*/
DEBUG_printf(("cupsReadResponseData(http=%p, buffer=%p, "
- "length=" CUPS_LLFMT ")\n", http, buffer, CUPS_LLCAST length));
+ "length=" CUPS_LLFMT ")", http, buffer, CUPS_LLCAST length));
if (!http)
{
* Unlike cupsDoFileRequest(), cupsDoIORequest(), and cupsDoRequest(), the
* request is not freed.
*
- * @since CUPS 1.4@
+ * @since CUPS 1.4/Mac OS X 10.6@
*/
http_status_t /* O - Initial HTTP status */
DEBUG_printf(("cupsSendRequest(http=%p, request=%p(%s), resource=\"%s\", "
- "length=" CUPS_LLFMT ")\n", http, request,
+ "length=" CUPS_LLFMT ")", http, request,
request ? ippOpString(request->request.op.operation_id) : "?",
- resource ? resource : "(null)", CUPS_LLCAST length));
+ resource, CUPS_LLCAST length));
/*
* Range check input...
for (;;)
{
- DEBUG_puts("cupsSendRequest: Setup...");
+ DEBUG_puts("2cupsSendRequest: Setup...");
/*
* Setup the HTTP variables needed...
httpSetField(http, HTTP_FIELD_AUTHORIZATION, http->authstring);
httpSetExpect(http, expect);
- DEBUG_printf(("cupsSendRequest: authstring=\"%s\"\n", http->authstring));
+ DEBUG_printf(("2cupsSendRequest: authstring=\"%s\"", http->authstring));
/*
* Try the request...
*/
- DEBUG_puts("cupsSendRequest: Sending HTTP POST...");
+ DEBUG_puts("2cupsSendRequest: Sending HTTP POST...");
if (httpPost(http, resource))
{
* Send the IPP data...
*/
- DEBUG_puts("cupsSendRequest: Writing IPP request...");
+ DEBUG_puts("2cupsSendRequest: Writing IPP request...");
request->state = IPP_IDLE;
status = HTTP_CONTINUE;
if (!got_status && expect == HTTP_CONTINUE)
{
- DEBUG_puts("cupsSendRequest: Waiting for 100-continue...");
+ DEBUG_puts("2cupsSendRequest: Waiting for 100-continue...");
if (httpWait(http, 1000))
status = httpUpdate(http);
else if (httpCheck(http))
status = httpUpdate(http);
- DEBUG_printf(("cupsSendRequest: status=%d\n", status));
+ DEBUG_printf(("2cupsSendRequest: status=%d", status));
/*
* Process the current HTTP status...
case HTTP_UNAUTHORIZED :
if (!cupsDoAuthentication(http, "POST", resource))
+ {
if (httpReconnect(http))
{
_cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
return (HTTP_SERVICE_UNAVAILABLE);
}
+ }
+ else
+ status = HTTP_AUTHORIZATION_CANCELED;
return (status);
* This function is used after @link cupsSendRequest@ to provide a PPD and
* after @link cupsStartDocument@ to provide a document file.
*
- * @since CUPS 1.4@
+ * @since CUPS 1.4/Mac OS X 10.6@
*/
http_status_t /* O - @code HTTP_CONTINUE@ if OK or HTTP status on error */
const char *buffer, /* I - Bytes to write */
size_t length) /* I - Number of bytes to write */
{
+ int wused; /* Previous bytes in buffer */
+
+
/*
* Get the default connection as needed...
*/
DEBUG_printf(("cupsWriteRequestData(http=%p, buffer=%p, "
- "length=" CUPS_LLFMT ")\n", http, buffer, CUPS_LLCAST length));
+ "length=" CUPS_LLFMT ")", http, buffer, CUPS_LLCAST length));
if (!http)
{
* Then write to the HTTP connection...
*/
+ wused = http->wused;
+
if (httpWrite2(http, buffer, length) < 0)
return (HTTP_ERROR);
* Finally, check if we have any pending data from the server...
*/
- if (httpCheck(http))
- return (httpUpdate(http));
- else
- return (HTTP_CONTINUE);
+ if (length >= HTTP_MAX_BUFFER ||
+ http->wused < wused ||
+ (wused > 0 && http->wused == length))
+ {
+ /*
+ * We've written something to the server, so check for response data...
+ */
+
+ if (_httpWait(http, 0, 1))
+ return (httpUpdate(http));
+ }
+
+ return (HTTP_CONTINUE);
}
cg->last_status_message = _cupsStrAlloc(message);
}
- DEBUG_printf(("_cupsSetError: last_error=%s, last_status_message=\"%s\"\n",
- ippErrorString(cg->last_error),
- cg->last_status_message ? cg->last_status_message : ""));
+ DEBUG_printf(("4_cupsSetError: last_error=%s, last_status_message=\"%s\"",
+ ippErrorString(cg->last_error), cg->last_status_message));
}
break;
case HTTP_UNAUTHORIZED :
+ case HTTP_AUTHORIZATION_CANCELED :
_cupsSetError(IPP_NOT_AUTHORIZED, httpStatus(status), 0);
break;
break;
default :
- DEBUG_printf(("HTTP error %d mapped to IPP_SERVICE_UNAVAILABLE!\n",
- status));
+ DEBUG_printf(("4_cupsSetHTTPError: HTTP error %d mapped to "
+ "IPP_SERVICE_UNAVAILABLE!", status));
_cupsSetError(IPP_SERVICE_UNAVAILABLE, httpStatus(status), 0);
break;
}