/*
- * "$Id: client.c,v 1.91.2.77 2004/02/25 20:01:37 mike Exp $"
+ * "$Id: client.c,v 1.91.2.78 2004/03/02 20:56:02 mike Exp $"
*
* Client routines for the Common UNIX Printing System (CUPS) scheduler.
*
memset(con, 0, sizeof(client_t));
con->http.activity = time(NULL);
+ con->file = -1;
/*
* Accept the client and get the remote address...
* 'CloseClient()' - Close a remote client.
*/
-void
+int /* O - 1 if partial close, 0 if fully closed */
CloseClient(client_t *con) /* I - Client to close */
{
int partial; /* Do partial close for SSL? */
if (con < (Clients + NumClients))
memmove(con, con + 1, (Clients + NumClients - con) * sizeof(client_t));
}
+
+ return (partial);
}
status = HTTP_CONTINUE;
- LogMessage(L_DEBUG2, "ReadClient() %d, used=%d", con->http.fd,
- con->http.used);
+ LogMessage(L_DEBUG2, "ReadClient() %d, used=%d, file=%d", con->http.fd,
+ con->http.used, con->file);
if (con->http.error)
{
- CloseClient(con);
- return (0);
+ LogMessage(L_DEBUG2, "ReadClient: http error seen...");
+ return (CloseClient(con));
}
switch (con->http.state)
if (httpGets(line, sizeof(line) - 1, HTTP(con)) == NULL)
{
- CloseClient(con);
- return (0);
+ LogMessage(L_DEBUG2, "ReadClient: httpGets returned EOF...");
+ return (CloseClient(con));
}
/*
case 1 :
LogMessage(L_ERROR, "Bad request line \"%s\"!", line);
SendError(con, HTTP_BAD_REQUEST);
- CloseClient(con);
- return (0);
+ return (CloseClient(con));
case 2 :
con->http.version = HTTP_0_9;
break;
{
LogMessage(L_ERROR, "Bad request line \"%s\"!", line);
SendError(con, HTTP_BAD_REQUEST);
- CloseClient(con);
- return (0);
+ return (CloseClient(con));
}
if (major < 2)
else
{
SendError(con, HTTP_NOT_SUPPORTED);
- CloseClient(con);
- return (0);
+ return (CloseClient(con));
}
break;
}
LogMessage(L_ERROR, "Bad URI \"%s\" in request!", con->uri);
SendError(con, HTTP_METHOD_NOT_ALLOWED);
- CloseClient(con);
- return (0);
+ return (CloseClient(con));
}
/*
{
LogMessage(L_ERROR, "Bad operation \"%s\"!", operation);
SendError(con, HTTP_BAD_REQUEST);
- CloseClient(con);
- return (0);
+ return (CloseClient(con));
}
con->start = time(NULL);
if (status != HTTP_OK && status != HTTP_CONTINUE)
{
SendError(con, HTTP_BAD_REQUEST);
- CloseClient(con);
- return (0);
+ return (CloseClient(con));
}
break;
*/
if (!SendError(con, HTTP_BAD_REQUEST))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
}
else if (con->operation == HTTP_OPTIONS)
{
best->type != AUTH_NONE)
{
if (!SendHeader(con, HTTP_UNAUTHORIZED, NULL))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
}
if (strcasecmp(con->http.fields[HTTP_FIELD_CONNECTION], "Upgrade") == 0 &&
*/
if (!SendHeader(con, HTTP_SWITCHING_PROTOCOLS, NULL))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
httpPrintf(HTTP(con), "Connection: Upgrade\r\n");
httpPrintf(HTTP(con), "Upgrade: TLS/1.0,HTTP/1.1\r\n");
EncryptClient(con);
#else
if (!SendError(con, HTTP_NOT_IMPLEMENTED))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
#endif /* HAVE_SSL */
}
}
if (!SendHeader(con, HTTP_OK, NULL))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
httpPrintf(HTTP(con), "Allow: GET, HEAD, OPTIONS, POST, PUT\r\n");
httpPrintf(HTTP(con), "Content-Length: 0\r\n");
*/
if (!SendError(con, HTTP_FORBIDDEN))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
}
else
{
*/
if (!SendHeader(con, HTTP_SWITCHING_PROTOCOLS, NULL))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
httpPrintf(HTTP(con), "Connection: Upgrade\r\n");
httpPrintf(HTTP(con), "Upgrade: TLS/1.0,HTTP/1.1\r\n");
status = IsAuthorized(con);
#else
if (!SendError(con, HTTP_NOT_IMPLEMENTED))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
#endif /* HAVE_SSL */
}
LogMessage(L_DEBUG2, "ReadClient: Unauthorized request for %s...\n",
con->uri);
SendError(con, status);
- CloseClient(con);
- return (0);
+ return (CloseClient(con));
}
if (con->http.expect)
else
{
if (!SendError(con, HTTP_NOT_FOUND))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
break;
}
if (!SendCommand(con, con->command, con->options))
{
if (!SendError(con, HTTP_NOT_FOUND))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
}
else
LogRequest(con, HTTP_OK);
*/
if (!SendError(con, HTTP_FORBIDDEN))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
break;
}
sizeof(buf))) == NULL)
{
if (!SendError(con, HTTP_NOT_FOUND))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
break;
}
if (!SendCommand(con, con->command, con->options))
{
if (!SendError(con, HTTP_NOT_FOUND))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
}
else
LogRequest(con, HTTP_OK);
if (!check_if_modified(con, &filestats))
{
if (!SendError(con, HTTP_NOT_MODIFIED))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
}
else
{
snprintf(line, sizeof(line), "%s/%s", type->super, type->type);
if (!SendFile(con, HTTP_OK, filename, line, &filestats))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
}
}
break;
*/
if (!SendError(con, HTTP_REQUEST_TOO_LARGE))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
break;
}
*/
if (!SendError(con, HTTP_BAD_REQUEST))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
break;
}
sizeof(buf))) == NULL)
{
if (!SendError(con, HTTP_NOT_FOUND))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
break;
}
*/
if (!SendError(con, HTTP_UNAUTHORIZED))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
}
}
break;
*/
if (!SendError(con, HTTP_FORBIDDEN))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
break;
}
*/
if (!SendError(con, HTTP_REQUEST_TOO_LARGE))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
break;
}
*/
if (!SendError(con, HTTP_BAD_REQUEST))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
break;
}
if (con->file < 0)
{
if (!SendError(con, HTTP_REQUEST_TOO_LARGE))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
}
break;
case HTTP_DELETE :
case HTTP_TRACE :
SendError(con, HTTP_NOT_IMPLEMENTED);
- CloseClient(con);
- return (0);
+ return (CloseClient(con));
case HTTP_HEAD :
if (strncmp(con->uri, "/printers/", 10) == 0 &&
else
{
if (!SendError(con, HTTP_NOT_FOUND))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
break;
}
*/
if (!SendHeader(con, HTTP_OK, "text/html"))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
if (httpPrintf(HTTP(con), "\r\n") < 0)
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
LogRequest(con, HTTP_OK);
}
*/
if (!SendError(con, HTTP_FORBIDDEN))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
break;
}
sizeof(buf))) == NULL)
{
if (!SendHeader(con, HTTP_NOT_FOUND, "text/html"))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
LogRequest(con, HTTP_NOT_FOUND);
}
else if (!check_if_modified(con, &filestats))
{
if (!SendError(con, HTTP_NOT_MODIFIED))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
LogRequest(con, HTTP_NOT_MODIFIED);
}
snprintf(line, sizeof(line), "%s/%s", type->super, type->type);
if (!SendHeader(con, HTTP_OK, line))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
if (httpPrintf(HTTP(con), "Last-Modified: %s\r\n",
httpGetDateString(filestats.st_mtime)) < 0)
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
if (httpPrintf(HTTP(con), "Content-Length: %lu\r\n",
(unsigned long)filestats.st_size) < 0)
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
LogRequest(con, HTTP_OK);
}
if (httpPrintf(HTTP(con), "\r\n") < 0)
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
con->http.state = HTTP_WAITING;
break;
con->http.data_remaining, con->file);
if ((bytes = httpRead(HTTP(con), line, sizeof(line))) < 0)
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
else if (bytes > 0)
{
con->bytes += bytes;
ClearString(&con->filename);
if (!SendError(con, HTTP_REQUEST_TOO_LARGE))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
}
}
ClearString(&con->filename);
if (!SendError(con, HTTP_REQUEST_TOO_LARGE))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
}
/*
*/
if (!SendError(con, status))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
}
break;
LogMessage(L_ERROR, "ReadClient() %d IPP Read Error!",
con->http.fd);
- if (!SendError(con, HTTP_BAD_REQUEST))
- {
- CloseClient(con);
- return (0);
- }
-
- CloseClient(con);
- return (0);
+ SendError(con, HTTP_BAD_REQUEST);
+ return (CloseClient(con));
}
else if (ipp_state != IPP_DATA)
break;
if (con->file < 0)
{
if (!SendError(con, HTTP_REQUEST_TOO_LARGE))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
}
}
if (con->http.state != HTTP_POST_SEND)
{
if ((bytes = httpRead(HTTP(con), line, sizeof(line))) < 0)
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
else if (bytes > 0)
{
con->bytes += bytes;
ClearString(&con->filename);
if (!SendError(con, HTTP_REQUEST_TOO_LARGE))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
}
}
else if (con->http.state == HTTP_POST_RECV)
- {
- return (0);
- }
+ return (1); /* ??? */
else if (con->http.state != HTTP_POST_SEND)
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
}
if (con->http.state == HTTP_POST_SEND)
}
if (!SendError(con, HTTP_REQUEST_TOO_LARGE))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
}
if (con->command)
if (!SendCommand(con, con->command, con->options))
{
if (!SendError(con, HTTP_NOT_FOUND))
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
}
else
LogRequest(con, HTTP_OK);
}
if (!con->http.keep_alive && con->http.state == HTTP_WAITING)
- {
- CloseClient(con);
- return (0);
- }
+ return (CloseClient(con));
else
return (1);
}
/*
- * End of "$Id: client.c,v 1.91.2.77 2004/02/25 20:01:37 mike Exp $".
+ * End of "$Id: client.c,v 1.91.2.78 2004/03/02 20:56:02 mike Exp $".
*/