/*
- * "$Id: client.c 5898 2006-08-28 18:54:10Z mike $"
+ * "$Id: client.c 5972 2006-09-19 20:44:07Z mike $"
*
* Client routines for the Common UNIX Printing System (CUPS) scheduler.
*
* 'cupsdFlushHeader()' - Flush the header fields to the client.
*/
-void
+int /* I - Bytes written or -1 on error */
cupsdFlushHeader(cupsd_client_t *con) /* I - Client to flush to */
{
- httpFlushWrite(HTTP(con));
+ int bytes = httpFlushWrite(HTTP(con));
con->http.data_encoding = HTTP_ENCODE_LENGTH;
+
+ return (bytes);
}
httpPrintf(HTTP(con), "Upgrade: TLS/1.0,HTTP/1.1\r\n");
httpPrintf(HTTP(con), "Content-Length: 0\r\n");
httpPrintf(HTTP(con), "\r\n");
- cupsdFlushHeader(con);
+
+ if (cupsdFlushHeader(con) < 0)
+ return (cupsdCloseClient(con));
encrypt_client(con);
#else
httpPrintf(HTTP(con), "Allow: GET, HEAD, OPTIONS, POST, PUT\r\n");
httpPrintf(HTTP(con), "Content-Length: 0\r\n");
httpPrintf(HTTP(con), "\r\n");
- cupsdFlushHeader(con);
+
+ if (cupsdFlushHeader(con) < 0)
+ return (cupsdCloseClient(con));
}
else if (!is_path_absolute(con->uri))
{
httpPrintf(HTTP(con), "Upgrade: TLS/1.0,HTTP/1.1\r\n");
httpPrintf(HTTP(con), "Content-Length: 0\r\n");
httpPrintf(HTTP(con), "\r\n");
- cupsdFlushHeader(con);
+
+ if (cupsdFlushHeader(con) < 0)
+ return (cupsdCloseClient(con));
encrypt_client(con);
#else
httpPrintf(HTTP(con), "Content-Length: 0\r\n");
httpPrintf(HTTP(con), "\r\n");
- cupsdFlushHeader(con);
+
+ if (cupsdFlushHeader(con) < 0)
+ return (cupsdCloseClient(con));
}
}
if (httpPrintf(HTTP(con), "\r\n") < 0)
return (cupsdCloseClient(con));
- cupsdFlushHeader(con);
+ if (cupsdFlushHeader(con) < 0)
+ return (cupsdCloseClient(con));
cupsdLogRequest(con, HTTP_OK);
}
if (httpPrintf(HTTP(con), "\r\n") < 0)
return (cupsdCloseClient(con));
- cupsdFlushHeader(con);
+ if (cupsdFlushHeader(con) < 0)
+ return (cupsdCloseClient(con));
con->http.state = HTTP_WAITING;
break;
else if (httpPrintf(HTTP(con), "\r\n") < 0)
return (0);
- cupsdFlushHeader(con);
+ if (cupsdFlushHeader(con) < 0)
+ return (0);
con->http.state = HTTP_WAITING;
* Send the HTTP status header...
*/
- httpFlushWrite(HTTP(con));
-
- con->http.data_encoding = HTTP_ENCODE_FIELDS;
-
- if (httpPrintf(HTTP(con), "HTTP/%d.%d %d %s\r\n", con->http.version / 100,
- con->http.version % 100, code, httpStatus(code)) < 0)
- return (0);
-
if (code == HTTP_CONTINUE)
{
/*
* 100-continue doesn't send any headers...
*/
- if (httpPrintf(HTTP(con), "\r\n") < 0)
- return (0);
- else
- {
- cupsdFlushHeader(con);
- return (1);
- }
+ return (httpPrintf(HTTP(con), "HTTP/%d.%d 100 Continue\r\n\r\n",
+ con->http.version / 100, con->http.version % 100) > 0);
}
+ httpFlushWrite(HTTP(con));
+
+ con->http.data_encoding = HTTP_ENCODE_FIELDS;
+
+ if (httpPrintf(HTTP(con), "HTTP/%d.%d %d %s\r\n", con->http.version / 100,
+ con->http.version % 100, code, httpStatus(code)) < 0)
+ return (0);
if (httpPrintf(HTTP(con), "Date: %s\r\n", httpGetDateString(time(NULL))) < 0)
return (0);
if (ServerHeader)
if (con->response != NULL)
{
- ipp_state = ippWrite(&(con->http), con->response);
+ ipp_state = ippWrite(HTTP(con), con->response);
bytes = ipp_state != IPP_ERROR && ipp_state != IPP_DATA;
}
else if ((bytes = read(con->file, buf, sizeof(buf) - 1)) > 0)
if (!strncasecmp(buf, "Location:", 9))
{
cupsdSendHeader(con, HTTP_SEE_OTHER, NULL);
+ con->sent_header = 2;
+
if (httpPrintf(HTTP(con), "Content-Length: 0\r\n") < 0)
return (0);
}
else if (!strncasecmp(buf, "Status:", 7))
+ {
cupsdSendError(con, (http_status_t)atoi(buf + 7));
+ con->sent_header = 2;
+ }
else
{
cupsdSendHeader(con, HTTP_OK, NULL);
+ con->sent_header = 1;
if (con->http.version == HTTP_1_1)
{
return (0);
}
}
-
- con->sent_header = 1;
}
if (strncasecmp(buf, "Status:", 7))
{
con->got_fields = 1;
- cupsdFlushHeader(con);
+ if (cupsdFlushHeader(con) < 0)
+ {
+ cupsdCloseClient(con);
+ return (0);
+ }
if (con->http.version == HTTP_1_1)
con->http.data_encoding = HTTP_ENCODE_CHUNKED;
httpFlushWrite(HTTP(con));
- if (con->http.data_encoding == HTTP_ENCODE_CHUNKED)
+ if (con->http.data_encoding == HTTP_ENCODE_CHUNKED && con->sent_header == 1)
{
- if (httpPrintf(HTTP(con), "0\r\n\r\n") < 0)
+ if (httpWrite2(HTTP(con), "", 0) < 0)
{
cupsdCloseClient(con);
return (0);
if (httpPrintf(HTTP(con), "\r\n") < 0)
return (0);
- cupsdFlushHeader(con);
+ if (cupsdFlushHeader(con) < 0)
+ return (0);
con->http.data_encoding = HTTP_ENCODE_LENGTH;
con->http.data_remaining = filestats->st_size;
/*
- * End of "$Id: client.c 5898 2006-08-28 18:54:10Z mike $".
+ * End of "$Id: client.c 5972 2006-09-19 20:44:07Z mike $".
*/