summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>2013-10-21 16:22:14 +0000
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>2013-10-21 16:22:14 +0000
commit43dcaf3bb6740864c59a2909317d5213dfd8955f (patch)
treea9745628a12c8ed69b6c5d66907121e8f27c4132
parentb0f269389e87634e85c0a4752239e859b732188f (diff)
downloadcups-43dcaf3bb6740864c59a2909317d5213dfd8955f.tar.gz
Fix some state transition breakage.
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@11347 a1ca3aef-8c08-0410-bb20-df032aa958be
-rw-r--r--scheduler/client.c58
1 files changed, 30 insertions, 28 deletions
diff --git a/scheduler/client.c b/scheduler/client.c
index 3705cefe9..f1b2dcc77 100644
--- a/scheduler/client.c
+++ b/scheduler/client.c
@@ -556,24 +556,6 @@ cupsdCloseClient(cupsd_client_t *con) /* I - Client to close */
}
-#if 0
-/*
- * 'cupsdFlushHeader()' - Flush the header fields to the client.
- */
-
-int /* I - Bytes written or -1 on error */
-cupsdFlushHeader(cupsd_client_t *con) /* I - Client to flush to */
-{
- int bytes = httpFlushWrite(con->http);
-
- // TODO: Need to use httpSendResponse
- con->http->data_encoding = HTTP_ENCODING_LENGTH;
-
- return (bytes);
-}
-#endif /* 0 */
-
-
/*
* 'cupsdReadClient()' - Read data from a client.
*/
@@ -614,6 +596,22 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */
con->request ? ippStateString(ippGetState(con->request)) : "",
con->file);
+ if (httpGetState(con->http) == HTTP_STATE_GET_SEND ||
+ httpGetState(con->http) == HTTP_STATE_POST_SEND ||
+ httpGetState(con->http) == HTTP_STATE_STATUS)
+ {
+ /*
+ * If we get called in the wrong state, then something went wrong with the
+ * connection and we need to shut it down...
+ */
+
+ cupsdLogClient(con, CUPSD_LOG_DEBUG, "Closing on unexpected HTTP read state %s.",
+ httpStateString(httpGetState(con->http)));
+ cupsdCloseClient(con);
+ return;
+ }
+
+
#ifdef HAVE_SSL
if (con->auto_ssl)
{
@@ -2263,17 +2261,22 @@ cupsdSendError(cupsd_client_t *con, /* I - Connection */
_httpStatus(con->language, code), redirect,
_httpStatus(con->language, code), text);
- /*
- * Send an error message back to the client. If the error code is a
- * 400 or 500 series, make sure the message contains some text, too!
- */
+ /*
+ * Send an error message back to the client. If the error code is a
+ * 400 or 500 series, make sure the message contains some text, too!
+ */
+
+ size_t length = strlen(message); /* Length of message */
- httpSetLength(con->http, strlen(message));
+ httpSetLength(con->http, length);
if (!cupsdSendHeader(con, code, "text/html", auth_type))
return (0);
- if (httpPrintf(con->http, "%s", message) < 0)
+ if (httpWrite2(con->http, message, length) < 0)
+ return (0);
+
+ if (httpFlushWrite(con->http) < 0)
return (0);
}
else
@@ -2498,7 +2501,7 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */
* connection and we need to shut it down...
*/
- cupsdLogClient(con, CUPSD_LOG_DEBUG, "Closing on unexpected HTTP state %s.",
+ cupsdLogClient(con, CUPSD_LOG_DEBUG, "Closing on unexpected HTTP write state %s.",
httpStateString(httpGetState(con->http)));
cupsdCloseClient(con);
return;
@@ -2718,7 +2721,7 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */
httpFlushWrite(con->http);
- if (httpIsChunked(con->http) && con->sent_header == 1)
+ if (httpIsChunked(con->http) && (!con->pipe_pid || con->sent_header == 1))
{
if (httpWrite2(con->http, "", 0) < 0)
{
@@ -3956,8 +3959,7 @@ write_file(cupsd_client_t *con, /* I - Client connection */
if (!cupsdSendHeader(con, code, type, CUPSD_AUTH_NONE))
return (0);
- cupsdAddSelect(httpGetFd(con->http), (cupsd_selfunc_t)cupsdReadClient,
- (cupsd_selfunc_t)cupsdWriteClient, con);
+ cupsdAddSelect(httpGetFd(con->http), NULL, (cupsd_selfunc_t)cupsdWriteClient, con);
cupsdLogClient(con, CUPSD_LOG_DEBUG, "Sending file.");