]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fix some state transition stuff in the scheduler now that we are using
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Thu, 21 Feb 2013 04:00:35 +0000 (04:00 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Thu, 21 Feb 2013 04:00:35 +0000 (04:00 +0000)
HTTP_STATE_STATUS.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@10877 7a7537e8-13f0-0310-91df-b6672ffda945

scheduler/client.c

index 0fecf3786b7e1257b15400f42109900e045a9ea8..b08ea4e9d60c1ce2da799723b3e4aa79d86070fb 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   Client routines for the CUPS scheduler.
  *
- *   Copyright 2007-2012 by Apple Inc.
+ *   Copyright 2007-2013 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   This file contains Kerberos support code, copyright 2006 by
@@ -654,7 +654,7 @@ cupsdFlushHeader(cupsd_client_t *con)       /* I - Client to flush to */
 {
   int bytes = httpFlushWrite(HTTP(con));
 
-  con->http.data_encoding = HTTP_ENCODE_LENGTH;
+  con->http.data_encoding = HTTP_ENCODING_LENGTH;
 
   return (bytes);
 }
@@ -697,7 +697,7 @@ cupsdReadClient(cupsd_client_t *con)        /* I - Client to read from */
                  "file=%d",
                  con->http.fd, con->http.error, con->http.used,
                  http_states[con->http.state + 1],
-                 con->http.data_encoding == HTTP_ENCODE_CHUNKED ?
+                 con->http.data_encoding == HTTP_ENCODING_CHUNKED ?
                      "CHUNKED" : "LENGTH",
                  CUPS_LLCAST con->http.data_remaining,
                  con->request,
@@ -734,7 +734,7 @@ cupsdReadClient(cupsd_client_t *con)        /* I - Client to read from */
 
   switch (con->http.state)
   {
-    case HTTP_WAITING :
+    case HTTP_STATE_WAITING :
        /*
         * See if we've received a request line...
        */
@@ -743,12 +743,12 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
        {
          if (con->http.error && con->http.error != EPIPE)
            cupsdLogMessage(CUPSD_LOG_DEBUG,
-                           "[Client %d] HTTP_WAITING Closing for error %d "
+                           "[Client %d] HTTP_STATE_WAITING Closing for error %d "
                            "(%s)", con->http.fd, con->http.error,
                            strerror(con->http.error));
          else
            cupsdLogMessage(CUPSD_LOG_DEBUG,
-                           "[Client %d] HTTP_WAITING Closing on EOF",
+                           "[Client %d] HTTP_STATE_WAITING Closing on EOF",
                            con->http.fd);
 
          cupsdCloseClient(con);
@@ -771,10 +771,10 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
         con->http.activity        = time(NULL);
         con->http.version         = HTTP_1_0;
        con->http.keep_alive      = HTTP_KEEPALIVE_OFF;
-       con->http.data_encoding   = HTTP_ENCODE_LENGTH;
+       con->http.data_encoding   = HTTP_ENCODING_LENGTH;
        con->http.data_remaining  = 0;
        con->http._data_remaining = 0;
-       con->operation            = HTTP_WAITING;
+       con->operation            = HTTP_STATE_WAITING;
        con->bytes                = 0;
        con->file                 = -1;
        con->file_ready           = 0;
@@ -924,19 +924,19 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
        */
 
         if (!strcmp(operation, "GET"))
-         con->http.state = HTTP_GET;
+         con->http.state = HTTP_STATE_GET;
         else if (!strcmp(operation, "PUT"))
-         con->http.state = HTTP_PUT;
+         con->http.state = HTTP_STATE_PUT;
         else if (!strcmp(operation, "POST"))
-         con->http.state = HTTP_POST;
+         con->http.state = HTTP_STATE_POST;
         else if (!strcmp(operation, "DELETE"))
-         con->http.state = HTTP_DELETE;
+         con->http.state = HTTP_STATE_DELETE;
         else if (!strcmp(operation, "TRACE"))
-         con->http.state = HTTP_TRACE;
+         con->http.state = HTTP_STATE_TRACE;
         else if (!strcmp(operation, "OPTIONS"))
-         con->http.state = HTTP_OPTIONS;
+         con->http.state = HTTP_STATE_OPTIONS;
         else if (!strcmp(operation, "HEAD"))
-         con->http.state = HTTP_HEAD;
+         con->http.state = HTTP_STATE_HEAD;
        else
        {
          cupsdLogMessage(CUPSD_LOG_ERROR,
@@ -962,13 +962,13 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
           cupsdSetBusyState();
         }
 
-    case HTTP_OPTIONS :
-    case HTTP_DELETE :
-    case HTTP_GET :
-    case HTTP_HEAD :
-    case HTTP_POST :
-    case HTTP_PUT :
-    case HTTP_TRACE :
+    case HTTP_STATE_OPTIONS :
+    case HTTP_STATE_DELETE :
+    case HTTP_STATE_GET :
+    case HTTP_STATE_HEAD :
+    case HTTP_STATE_POST :
+    case HTTP_STATE_PUT :
+    case HTTP_STATE_TRACE :
        /*
         * Parse incoming parameters until the status changes...
        */
@@ -1098,7 +1098,7 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
        return;
       }
     }
-    else if (con->operation == HTTP_OPTIONS)
+    else if (con->operation == HTTP_STATE_OPTIONS)
     {
      /*
       * Do OPTIONS command...
@@ -1234,7 +1234,7 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
       }
 
       if (con->http.expect &&
-          (con->operation == HTTP_POST || con->operation == HTTP_PUT))
+          (con->operation == HTTP_STATE_POST || con->operation == HTTP_STATE_PUT))
       {
         if (con->http.expect == HTTP_CONTINUE)
        {
@@ -1274,7 +1274,7 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
 
       switch (con->http.state)
       {
-       case HTTP_GET_SEND :
+       case HTTP_STATE_GET_SEND :
             if ((!strncmp(con->uri, "/ppd/", 5) ||
                 !strncmp(con->uri, "/printers/", 10)) &&
                !strcmp(con->uri + strlen(con->uri) - 4, ".ppd"))
@@ -1517,7 +1517,7 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
            }
             break;
 
-       case HTTP_POST_RECV :
+       case HTTP_STATE_POST_RECV :
            /*
            * See if the POST request includes a Content-Length field, and if
            * so check the length against any limits that are set...
@@ -1541,7 +1541,7 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
             }
            else if (con->http.data_remaining < 0 ||
                     (!con->http.fields[HTTP_FIELD_CONTENT_LENGTH][0] &&
-                     con->http.data_encoding == HTTP_ENCODE_LENGTH))
+                     con->http.data_encoding == HTTP_ENCODING_LENGTH))
            {
             /*
              * Negative content lengths are invalid!
@@ -1676,7 +1676,7 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
            }
            break;
 
-       case HTTP_PUT_RECV :
+       case HTTP_STATE_PUT_RECV :
           /*
            * Validate the resource name...
            */
@@ -1763,13 +1763,13 @@ cupsdReadClient(cupsd_client_t *con)    /* I - Client to read from */
            fcntl(con->file, F_SETFD, fcntl(con->file, F_GETFD) | FD_CLOEXEC);
            break;
 
-       case HTTP_DELETE :
-       case HTTP_TRACE :
+       case HTTP_STATE_DELETE :
+       case HTTP_STATE_TRACE :
             cupsdSendError(con, HTTP_NOT_IMPLEMENTED, CUPSD_AUTH_NONE);
            cupsdCloseClient(con);
            return;
 
-       case HTTP_HEAD :
+       case HTTP_STATE_HEAD :
             if (!strncmp(con->uri, "/printers/", 10) &&
                !strcmp(con->uri + strlen(con->uri) - 4, ".ppd"))
            {
@@ -1984,19 +1984,19 @@ cupsdReadClient(cupsd_client_t *con)    /* I - Client to read from */
 
   switch (con->http.state)
   {
-    case HTTP_PUT_RECV :
+    case HTTP_STATE_PUT_RECV :
         do
        {
           if ((bytes = httpRead2(HTTP(con), line, sizeof(line))) < 0)
          {
            if (con->http.error && con->http.error != EPIPE)
              cupsdLogMessage(CUPSD_LOG_DEBUG,
-                             "[Client %d] HTTP_PUT_RECV Closing for error "
+                             "[Client %d] HTTP_STATE_PUT_RECV Closing for error "
                              "%d (%s)", con->http.fd, con->http.error,
                              strerror(con->http.error));
            else
              cupsdLogMessage(CUPSD_LOG_DEBUG,
-                             "[Client %d] HTTP_PUT_RECV Closing on EOF",
+                             "[Client %d] HTTP_STATE_PUT_RECV Closing on EOF",
                              con->http.fd);
 
            cupsdCloseClient(con);
@@ -2026,9 +2026,9 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
            }
          }
         }
-       while (con->http.state == HTTP_PUT_RECV && data_ready(con));
+       while (con->http.state == HTTP_STATE_PUT_RECV && data_ready(con));
 
-        if (con->http.state == HTTP_WAITING)
+        if (con->http.state == HTTP_STATE_STATUS)
        {
         /*
          * End of file, see how big it is...
@@ -2074,7 +2074,7 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
        }
         break;
 
-    case HTTP_POST_RECV :
+    case HTTP_STATE_POST_RECV :
         do
        {
           if (con->request && con->file < 0)
@@ -2095,7 +2095,7 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
            }
            else if (ipp_state != IPP_DATA)
            {
-              if (con->http.state == HTTP_POST_SEND)
+              if (con->http.state == HTTP_STATE_POST_SEND)
              {
                cupsdSendError(con, HTTP_BAD_REQUEST, CUPSD_AUTH_NONE);
                cupsdCloseClient(con);
@@ -2115,7 +2115,7 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
            }
          }
 
-          if (con->file < 0 && con->http.state != HTTP_POST_SEND)
+          if (con->file < 0 && con->http.state != HTTP_STATE_POST_SEND)
          {
            /*
            * Create a file as needed for the request data...
@@ -2144,18 +2144,18 @@ cupsdReadClient(cupsd_client_t *con)    /* I - Client to read from */
             fcntl(con->file, F_SETFD, fcntl(con->file, F_GETFD) | FD_CLOEXEC);
          }
 
-         if (con->http.state != HTTP_POST_SEND)
+         if (con->http.state != HTTP_STATE_POST_SEND)
          {
             if ((bytes = httpRead2(HTTP(con), line, sizeof(line))) < 0)
            {
              if (con->http.error && con->http.error != EPIPE)
                cupsdLogMessage(CUPSD_LOG_DEBUG,
-                               "[Client %d] HTTP_POST_SEND Closing for "
+                               "[Client %d] HTTP_STATE_POST_SEND Closing for "
                                "error %d (%s)", con->http.fd, con->http.error,
                                strerror(con->http.error));
              else
                cupsdLogMessage(CUPSD_LOG_DEBUG,
-                               "[Client %d] HTTP_POST_SEND Closing on EOF",
+                               "[Client %d] HTTP_STATE_POST_SEND Closing on EOF",
                                con->http.fd);
 
              cupsdCloseClient(con);
@@ -2185,9 +2185,9 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
                }
              }
            }
-           else if (con->http.state == HTTP_POST_RECV)
+           else if (con->http.state == HTTP_STATE_POST_RECV)
               return;
-           else if (con->http.state != HTTP_POST_SEND)
+           else if (con->http.state != HTTP_STATE_POST_SEND)
            {
              cupsdLogMessage(CUPSD_LOG_DEBUG,
                              "[Client %d] Closing on unexpected state %s.",
@@ -2197,9 +2197,9 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
            }
          }
         }
-       while (con->http.state == HTTP_POST_RECV && data_ready(con));
+       while (con->http.state == HTTP_STATE_POST_RECV && data_ready(con));
 
-       if (con->http.state == HTTP_POST_SEND)
+       if (con->http.state == HTTP_STATE_POST_SEND)
        {
          if (con->file >= 0)
          {
@@ -2278,7 +2278,7 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
         break; /* Anti-compiler-warning-code */
   }
 
-  if (con->http.state == HTTP_WAITING)
+  if (con->http.state == HTTP_STATE_WAITING)
   {
     if (!con->http.keep_alive)
     {
@@ -2550,7 +2550,7 @@ cupsdSendHeader(
 
   httpFlushWrite(HTTP(con));
 
-  con->http.data_encoding = HTTP_ENCODE_FIELDS;
+  con->http.data_encoding = HTTP_ENCODING_FIELDS;
 
   if (httpPrintf(HTTP(con), "HTTP/%d.%d %d %s\r\n", con->http.version / 100,
                  con->http.version % 100, code, httpStatus(code)) < 0)
@@ -2730,22 +2730,22 @@ cupsdWriteClient(cupsd_client_t *con)   /* I - Client connection */
                  "error=%d, "
                  "used=%d, "
                  "state=%s, "
-                 "data_encoding=HTTP_ENCODE_%s, "
+                 "data_encoding=HTTP_ENCODING_%s, "
                  "data_remaining=" CUPS_LLFMT ", "
                  "response=%p(%s), "
                  "pipe_pid=%d, "
                  "file=%d",
                  con->http.fd, con->http.error, con->http.used,
                  http_states[con->http.state + 1],
-                 con->http.data_encoding == HTTP_ENCODE_CHUNKED ?
+                 con->http.data_encoding == HTTP_ENCODING_CHUNKED ?
                      "CHUNKED" : "LENGTH",
                  CUPS_LLCAST con->http.data_remaining,
                  con->response,
                  con->response ? ipp_states[con->response->state] : "",
                  con->pipe_pid, con->file);
 
-  if (con->http.state != HTTP_GET_SEND &&
-      con->http.state != HTTP_POST_SEND)
+  if (con->http.state != HTTP_STATE_GET_SEND &&
+      con->http.state != HTTP_STATE_POST_SEND)
   {
    /*
     * If we get called in the wrong state, then something went wrong with the
@@ -2886,7 +2886,7 @@ cupsdWriteClient(cupsd_client_t *con)     /* I - Client connection */
            }
 
            if (con->http.version == HTTP_1_1)
-             con->http.data_encoding = HTTP_ENCODE_CHUNKED;
+             con->http.data_encoding = HTTP_ENCODING_CHUNKED;
           }
          else
            field_col = 0;
@@ -2914,12 +2914,12 @@ cupsdWriteClient(cupsd_client_t *con)   /* I - Client connection */
        return;
       }
 
-      if (con->http.data_encoding == HTTP_ENCODE_CHUNKED)
+      if (con->http.data_encoding == HTTP_ENCODING_CHUNKED)
         httpFlushWrite(HTTP(con));
 
       con->bytes += con->header_used;
 
-      if (con->http.state == HTTP_WAITING)
+      if (con->http.state == HTTP_STATE_WAITING)
        bytes = 0;
       else
         bytes = con->header_used;
@@ -2929,7 +2929,7 @@ cupsdWriteClient(cupsd_client_t *con)     /* I - Client connection */
   }
 
   if (bytes <= 0 ||
-      (con->http.state != HTTP_GET_SEND && con->http.state != HTTP_POST_SEND))
+      (con->http.state != HTTP_STATE_GET_SEND && con->http.state != HTTP_STATE_POST_SEND))
   {
     if (!con->sent_header && con->pipe_pid)
       cupsdSendError(con, HTTP_SERVER_ERROR, CUPSD_AUTH_NONE);
@@ -2939,7 +2939,7 @@ cupsdWriteClient(cupsd_client_t *con)     /* I - Client connection */
 
       httpFlushWrite(HTTP(con));
 
-      if (con->http.data_encoding == HTTP_ENCODE_CHUNKED && con->sent_header == 1)
+      if (con->http.data_encoding == HTTP_ENCODING_CHUNKED && con->sent_header == 1)
       {
        if (httpWrite2(HTTP(con), "", 0) < 0)
        {
@@ -2953,7 +2953,7 @@ cupsdWriteClient(cupsd_client_t *con)     /* I - Client connection */
       }
     }
 
-    con->http.state = HTTP_WAITING;
+    con->http.state = HTTP_STATE_WAITING;
 
     cupsdAddSelect(con->http.fd, (cupsd_selfunc_t)cupsdReadClient, NULL, con);
 
@@ -3683,7 +3683,7 @@ pipe_command(cupsd_client_t *con, /* I - Client connection */
       commptr ++;
   }
 
-  if (*commptr == '?' && con->operation == HTTP_GET && !con->query_string)
+  if (*commptr == '?' && con->operation == HTTP_STATE_GET && !con->query_string)
   {
     commptr ++;
     cupsdSetStringf(&(con->query_string), "QUERY_STRING=%s", commptr);
@@ -3888,7 +3888,7 @@ pipe_command(cupsd_client_t *con, /* I - Client connection */
     envp[envc ++] = http_referer;
   }
 
-  if (con->operation == HTTP_GET)
+  if (con->operation == HTTP_STATE_GET)
   {
     envp[envc ++] = "REQUEST_METHOD=GET";
 
@@ -4194,7 +4194,7 @@ write_file(cupsd_client_t *con,           /* I - Client connection */
   if (cupsdFlushHeader(con) < 0)
     return (0);
 
-  con->http.data_encoding  = HTTP_ENCODE_LENGTH;
+  con->http.data_encoding  = HTTP_ENCODING_LENGTH;
   con->http.data_remaining = filestats->st_size;
 
   if (con->http.data_remaining <= INT_MAX)