]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Save work - almost have "make check" working again (some logging and cups-driverd
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Tue, 15 Oct 2013 17:49:31 +0000 (17:49 +0000)
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Tue, 15 Oct 2013 17:49:31 +0000 (17:49 +0000)
issues to work out...)

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@11329 a1ca3aef-8c08-0410-bb20-df032aa958be

cups/http.c
scheduler/client.c
scheduler/client.h
scheduler/ipp.c
systemv/lpstat.c

index f3e449b7af8de45de9f0a7219211b17494443d40..0e1ff586419a8e60a52b2cfeaad52030ed071c1f 100644 (file)
@@ -3949,13 +3949,17 @@ httpWriteResponse(http_t        *http,  /* I - HTTP connection */
   }
 
 #ifdef HAVE_SSL
-  if (status == HTTP_STATUS_UPGRADE_REQUIRED)
+  if (status == HTTP_STATUS_UPGRADE_REQUIRED ||
+      status == HTTP_STATUS_SWITCHING_PROTOCOLS)
   {
     if (!http->fields[HTTP_FIELD_CONNECTION][0])
       httpSetField(http, HTTP_FIELD_CONNECTION, "Upgrade");
 
     if (!http->fields[HTTP_FIELD_UPGRADE][0])
       httpSetField(http, HTTP_FIELD_UPGRADE, "TLS/1.2,TLS/1.1,TLS/1.0");
+
+    if (!http->fields[HTTP_FIELD_CONTENT_LENGTH][0])
+      httpSetField(http, HTTP_FIELD_CONTENT_LENGTH, "0");
   }
 #endif /* HAVE_SSL */
 
@@ -4014,8 +4018,8 @@ httpWriteResponse(http_t        *http,    /* I - HTTP connection */
 
     if (http->cookie)
     {
-      if (httpPrintf(http, "Set-Cookie: %s path=/%s\r\n", http->cookie,
-                     http->tls ? " secure" : "") < 1)
+      if (httpPrintf(http, "Set-Cookie: %s path=/ httponly%s\r\n",
+                    http->cookie, http->tls ? " secure" : "") < 1)
       {
        http->status = HTTP_STATUS_ERROR;
        return (-1);
@@ -4035,7 +4039,8 @@ httpWriteResponse(http_t        *http,    /* I - HTTP connection */
     return (-1);
   }
 
-  if (status == HTTP_STATUS_CONTINUE)
+  if (status == HTTP_STATUS_CONTINUE ||
+      status == HTTP_STATUS_SWITCHING_PROTOCOLS)
   {
    /*
     * Restore the old data_encoding and data_length values...
index 90bede95d0147ff7585e89bff74c5324105450a6..a6a4ebc0f8fe56ad4f2240370e40e0ca6e002a47 100644 (file)
@@ -951,6 +951,7 @@ cupsdReadClient(cupsd_client_t *con)        /* I - Client to read from */
         * Do encryption stuff...
        */
 
+#  if 0
        if (!cupsdSendHeader(con, HTTP_STATUS_SWITCHING_PROTOCOLS, NULL, CUPSD_AUTH_NONE))
        {
          cupsdCloseClient(con);
@@ -968,6 +969,14 @@ cupsdReadClient(cupsd_client_t *con)       /* I - Client to read from */
          return;
        }
 
+#else
+       if (!cupsdSendHeader(con, HTTP_STATUS_SWITCHING_PROTOCOLS, NULL, CUPSD_AUTH_NONE))
+       {
+         cupsdCloseClient(con);
+         return;
+       }
+#  endif /* 0 */
+
         if (!cupsdStartTLS(con))
         {
          cupsdCloseClient(con);
@@ -982,6 +991,7 @@ cupsdReadClient(cupsd_client_t *con)        /* I - Client to read from */
 #endif /* HAVE_SSL */
       }
 
+#if 0
       if (!cupsdSendHeader(con, HTTP_STATUS_OK, NULL, CUPSD_AUTH_NONE))
       {
        cupsdCloseClient(con);
@@ -997,6 +1007,17 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
        cupsdCloseClient(con);
        return;
       }
+#else
+      httpSetField(con->http, HTTP_FIELD_ALLOW,
+                  "GET, HEAD, OPTIONS, POST, PUT");
+      httpSetField(con->http, HTTP_FIELD_CONTENT_LENGTH, "0");
+
+      if (!cupsdSendHeader(con, HTTP_STATUS_OK, NULL, CUPSD_AUTH_NONE))
+      {
+       cupsdCloseClient(con);
+       return;
+      }
+#endif /* 0 */
     }
     else if (!is_path_absolute(con->uri))
     {
@@ -1023,6 +1044,7 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
         * Do encryption stuff...
        */
 
+#  if 0
        if (!cupsdSendHeader(con, HTTP_STATUS_SWITCHING_PROTOCOLS, NULL,
                             CUPSD_AUTH_NONE))
        {
@@ -1040,6 +1062,14 @@ cupsdReadClient(cupsd_client_t *con)     /* I - Client to read from */
          cupsdCloseClient(con);
          return;
        }
+#  else
+       if (!cupsdSendHeader(con, HTTP_STATUS_SWITCHING_PROTOCOLS, NULL,
+                            CUPSD_AUTH_NONE))
+       {
+         cupsdCloseClient(con);
+         return;
+       }
+#  endif /* 0 */
 
         if (!cupsdStartTLS(con))
         {
@@ -1083,21 +1113,14 @@ cupsdReadClient(cupsd_client_t *con)    /* I - Client to read from */
          * Send 417-expectation-failed header...
          */
 
+         httpSetField(con->http, HTTP_FIELD_CONTENT_LENGTH, "0");
+
          if (!cupsdSendHeader(con, HTTP_STATUS_EXPECTATION_FAILED, NULL,
                               CUPSD_AUTH_NONE))
          {
            cupsdCloseClient(con);
            return;
          }
-
-         httpPrintf(con->http, "Content-Length: 0\r\n");
-         httpPrintf(con->http, "\r\n");
-
-         if (cupsdFlushHeader(con) < 0)
-          {
-           cupsdCloseClient(con);
-           return;
-         }
        }
       }
 
@@ -1670,6 +1693,7 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
                  return;
                }
 
+               cupsdLogRequest(con, HTTP_STATUS_NOT_FOUND);
                break;
              }
            }
@@ -1693,6 +1717,7 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
                  return;
                }
 
+               cupsdLogRequest(con, HTTP_STATUS_NOT_FOUND);
                break;
              }
            }
@@ -1704,21 +1729,7 @@ cupsdReadClient(cupsd_client_t *con)     /* I - Client to read from */
                return;
              }
 
-             if (httpPrintf(con->http, "\r\n") < 0)
-             {
-               cupsdCloseClient(con);
-               return;
-             }
-
-             if (cupsdFlushHeader(con) < 0)
-             {
-               cupsdCloseClient(con);
-               return;
-             }
-
-//           con->http->state = HTTP_STATE_WAITING;
-             DEBUG_puts("cupsdReadClient: Set state to HTTP_STATE_WAITING "
-                        "after HEAD.");
+              cupsdLogRequest(con, HTTP_STATUS_OK);
              break;
            }
 
@@ -1740,18 +1751,6 @@ cupsdReadClient(cupsd_client_t *con)     /* I - Client to read from */
                return;
              }
 
-             if (httpPrintf(con->http, "\r\n") < 0)
-             {
-               cupsdCloseClient(con);
-               return;
-             }
-
-             if (cupsdFlushHeader(con) < 0)
-             {
-               cupsdCloseClient(con);
-               return;
-             }
-
               cupsdLogRequest(con, HTTP_STATUS_OK);
            }
             else if ((!strncmp(con->uri, "/admin/conf/", 12) &&
@@ -1775,6 +1774,7 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
                return;
              }
 
+              cupsdLogRequest(con, HTTP_STATUS_FORBIDDEN);
              break;
            }
            else if ((filename = get_file(con, &filestats, buf,
@@ -1811,21 +1811,11 @@ cupsdReadClient(cupsd_client_t *con)    /* I - Client to read from */
              else
                snprintf(line, sizeof(line), "%s/%s", type->super, type->type);
 
-              if (!cupsdSendHeader(con, HTTP_STATUS_OK, line, CUPSD_AUTH_NONE))
-             {
-               cupsdCloseClient(con);
-               return;
-             }
-
-             if (httpPrintf(con->http, "Last-Modified: %s\r\n",
-                            httpGetDateString(filestats.st_mtime)) < 0)
-             {
-               cupsdCloseClient(con);
-               return;
-             }
+             httpSetField(con->http, HTTP_FIELD_LAST_MODIFIED,
+                          httpGetDateString(filestats.st_mtime));
+             httpSetLength(con->http, filestats.st_size);
 
-             if (httpPrintf(con->http, "Content-Length: %lu\r\n",
-                            (unsigned long)filestats.st_size) < 0)
+              if (!cupsdSendHeader(con, HTTP_STATUS_OK, line, CUPSD_AUTH_NONE))
              {
                cupsdCloseClient(con);
                return;
@@ -1833,22 +1823,6 @@ cupsdReadClient(cupsd_client_t *con)     /* I - Client to read from */
 
               cupsdLogRequest(con, HTTP_STATUS_OK);
            }
-
-            if (httpPrintf(con->http, "\r\n") < 0)
-           {
-             cupsdCloseClient(con);
-             return;
-           }
-
-           if (cupsdFlushHeader(con) < 0)
-            {
-             cupsdCloseClient(con);
-             return;
-           }
-
-//            con->http->state = HTTP_STATE_WAITING;
-           DEBUG_puts("cupsdReadClient: Set state to HTTP_STATE_WAITING "
-                      "after HEAD.");
             break;
 
        default :
@@ -2202,7 +2176,8 @@ cupsdSendCommand(
   else
     fd = -1;
 
-  con->pipe_pid = pipe_command(con, fd, &(con->file), command, options, root);
+  con->pipe_pid    = pipe_command(con, fd, &(con->file), command, options, root);
+  con->pipe_status = HTTP_STATUS_OK;
 
   if (fd >= 0)
     close(fd);
@@ -2272,29 +2247,9 @@ cupsdSendError(cupsd_client_t *con,      /* I - Connection */
   if (code >= HTTP_STATUS_BAD_REQUEST && con->type != CUPSD_AUTH_NEGOTIATE)
     httpSetKeepAlive(con->http, HTTP_KEEPALIVE_OFF);
 
- /*
-  * 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!
-  */
-
-  if (!cupsdSendHeader(con, code, NULL, auth_type))
-    return (0);
-
-#ifdef HAVE_SSL
-  if (code == HTTP_STATUS_UPGRADE_REQUIRED)
-    if (httpPrintf(con->http, "Connection: Upgrade\r\n") < 0)
-      return (0);
-
-  if (httpPrintf(con->http, "Upgrade: TLS/1.2,TLS/1.1,TLS/1.0\r\n") < 0)
-    return (0);
-#endif /* HAVE_SSL */
-
   if (httpGetVersion(con->http) >= HTTP_VERSION_1_1 &&
       httpGetKeepAlive(con->http) == HTTP_KEEPALIVE_OFF)
-  {
-    if (httpPrintf(con->http, "Connection: close\r\n") < 0)
-      return (0);
-  }
+    httpSetField(con->http, HTTP_FIELD_CONNECTION, "close");
 
   if (code >= HTTP_STATUS_BAD_REQUEST)
   {
@@ -2360,25 +2315,26 @@ cupsdSendError(cupsd_client_t *con,     /* I - Connection */
             _httpStatus(con->language, code), redirect,
             _httpStatus(con->language, code), text);
 
-    if (httpPrintf(con->http, "Content-Type: text/html; charset=utf-8\r\n") < 0)
-      return (0);
-    if (httpPrintf(con->http, "Content-Length: %d\r\n",
-                   (int)strlen(message)) < 0)
-      return (0);
-    if (httpPrintf(con->http, "\r\n") < 0)
+    /*
+     * 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!
+     */
+
+    httpSetLength(con->http, strlen(message));
+
+    if (!cupsdSendHeader(con, code, "text/html", auth_type))
       return (0);
+    
     if (httpPrintf(con->http, "%s", message) < 0)
       return (0);
   }
-  else if (httpPrintf(con->http, "\r\n") < 0)
-    return (0);
-
-  if (cupsdFlushHeader(con) < 0)
-    return (0);
-
-//  con->http->state = HTTP_STATE_WAITING;
+  else
+  {
+    httpSetField(con->http, HTTP_FIELD_CONTENT_LENGTH, "0");
 
-  DEBUG_puts("cupsdSendError: Set state to HTTP_STATE_WAITING.");
+    if (!cupsdSendHeader(con, code, NULL, auth_type))
+      return (0);
+  }
 
   return (1);
 }
@@ -2408,9 +2364,7 @@ cupsdSendHeader(
     * 100-continue doesn't send any headers...
     */
 
-    return (httpPrintf(con->http, "HTTP/%d.%d 100 Continue\r\n\r\n",
-                      httpGetVersion(con->http) / 100,
-                      httpGetVersion(con->http) % 100) > 0);
+    return (!httpWriteResponse(con->http, HTTP_STATUS_CONTINUE));
   }
   else if (code == HTTP_STATUS_CUPS_WEBIF_DISABLED)
   {
@@ -2422,32 +2376,11 @@ cupsdSendHeader(
     code = HTTP_STATUS_OK;
   }
 
-  httpFlushWrite(con->http);
-
-//  con->http->data_encoding = HTTP_ENCODING_FIELDS;
-
-  if (httpPrintf(con->http, "HTTP/%d.%d %d %s\r\n", httpGetVersion(con->http) / 100,
-                 httpGetVersion(con->http) % 100, code, httpStatus(code)) < 0)
-    return (0);
-  if (httpPrintf(con->http, "Date: %s\r\n", httpGetDateString(time(NULL))) < 0)
-    return (0);
   if (ServerHeader)
-    if (httpPrintf(con->http, "Server: %s\r\n", ServerHeader) < 0)
-      return (0);
-  if (httpGetKeepAlive(con->http) && httpGetVersion(con->http) >= HTTP_VERSION_1_0)
-  {
-    if (httpPrintf(con->http, "Connection: Keep-Alive\r\n") < 0)
-      return (0);
-    if (httpPrintf(con->http, "Keep-Alive: timeout=%d\r\n",
-                   KeepAliveTimeout) < 0)
-      return (0);
-  }
-  else if (httpPrintf(con->http, "Connection: close\r\n") < 0)
-    return (0);
+    httpSetField(con->http, HTTP_FIELD_SERVER, ServerHeader);
 
   if (code == HTTP_STATUS_METHOD_NOT_ALLOWED)
-    if (httpPrintf(con->http, "Allow: GET, HEAD, OPTIONS, POST, PUT\r\n") < 0)
-      return (0);
+    httpSetField(con->http, HTTP_FIELD_ALLOW, "GET, HEAD, OPTIONS, POST, PUT");
 
   if (code == HTTP_STATUS_UNAUTHORIZED)
   {
@@ -2530,31 +2463,22 @@ cupsdSendHeader(
     {
       cupsdLogClient(con, CUPSD_LOG_DEBUG, "WWW-Authenticate: %s", auth_str);
 
-      if (httpPrintf(con->http, "WWW-Authenticate: %s\r\n", auth_str) < 0)
-        return (0);
+      httpSetField(con->http, HTTP_FIELD_WWW_AUTHENTICATE, auth_str);
     }
   }
 
   if (con->language && strcmp(con->language->language, "C"))
-  {
-    if (httpPrintf(con->http, "Content-Language: %s\r\n",
-                   con->language->language) < 0)
-      return (0);
-  }
+    httpSetField(con->http, HTTP_FIELD_CONTENT_LANGUAGE, con->language->language);
 
   if (type)
   {
     if (!strcmp(type, "text/html"))
-    {
-      if (httpPrintf(con->http,
-                     "Content-Type: text/html; charset=utf-8\r\n") < 0)
-        return (0);
-    }
-    else if (httpPrintf(con->http, "Content-Type: %s\r\n", type) < 0)
-      return (0);
+      httpSetField(con->http, HTTP_FIELD_CONTENT_TYPE, "text/html; charset=utf-8");
+    else
+      httpSetField(con->http, HTTP_FIELD_CONTENT_TYPE, type);
   }
 
-  return (1);
+  return (!httpWriteResponse(con->http, code));
 }
 
 
@@ -2735,46 +2659,49 @@ cupsdWriteClient(cupsd_client_t *con)   /* I - Client connection */
            * Handle redirection and CGI status codes...
            */
 
-            if (!_cups_strncasecmp(con->header, "Location:", 9))
+           http_field_t field;         /* HTTP field */
+           char        *value = strchr(con->header, ':');
+                                       /* Value of field */
+
+           if (value)
            {
-             if (!cupsdSendHeader(con, HTTP_STATUS_SEE_OTHER, NULL, CUPSD_AUTH_NONE))
-             {
-               cupsdCloseClient(con);
-               return;
-             }
+             *value++ = '\0';
+             while (isspace(*value & 255))
+               value ++;
+           }
 
-             con->sent_header = 2;
+           field = httpFieldValue(con->header);
 
-             if (httpPrintf(con->http, "Content-Length: 0\r\n") < 0)
-               return;
+           if (field != HTTP_FIELD_UNKNOWN && value)
+           {
+             httpSetField(con->http, field, value);
+
+             if (field == HTTP_FIELD_LOCATION)
+             {
+               con->pipe_status = HTTP_STATUS_SEE_OTHER;
+               con->sent_header = 2;
+             }
+             else
+               con->sent_header = 1;
            }
-           else if (!_cups_strncasecmp(con->header, "Status:", 7))
+           else if (!_cups_strcasecmp(con->header, "Status") && value)
            {
-             cupsdSendError(con, (http_status_t)atoi(con->header + 7),
-                            CUPSD_AUTH_NONE);
+             con->pipe_status = (http_status_t)atoi(value);
              con->sent_header = 2;
            }
-           else
+           else if (!_cups_strcasecmp(con->header, "Set-Cookie") && value)
            {
-             if (!cupsdSendHeader(con, HTTP_STATUS_OK, NULL, CUPSD_AUTH_NONE))
-             {
-               cupsdCloseClient(con);
-               return;
-             }
+             char *sep = strchr(value, ';');
+                                       /* Separator between name=value and the rest */
 
-             con->sent_header = 1;
+             if (sep)
+               *sep = '\0';
 
-             if (httpGetVersion(con->http) == HTTP_VERSION_1_1)
-             {
-               if (httpPrintf(con->http, "Transfer-Encoding: chunked\r\n") < 0)
-                 return;
-             }
-            }
+             httpSetCookie(con->http, value);
+             con->sent_header = 1;
+           }
          }
 
-         if (_cups_strncasecmp(con->header, "Status:", 7))
-           httpPrintf(con->http, "%s\r\n", con->header);
-
          /*
          * Update buffer...
          */
@@ -2794,15 +2721,15 @@ cupsdWriteClient(cupsd_client_t *con)   /* I - Client connection */
          {
            con->got_fields = 1;
 
-            if (cupsdFlushHeader(con) < 0)
+           if (httpGetVersion(con->http) == HTTP_VERSION_1_1 &&
+               !httpGetField(con->http, HTTP_FIELD_CONTENT_LENGTH)[0])
+             httpSetLength(con->http, 0);
+
+            if (!cupsdSendHeader(con, con->pipe_status, NULL, CUPSD_AUTH_NONE))
            {
              cupsdCloseClient(con);
              return;
            }
-
-           if (httpGetVersion(con->http) == HTTP_VERSION_1_1)
-             httpSetLength(con->http, 0);
-//           con->http->data_encoding = HTTP_ENCODING_CHUNKED;
           }
          else
            field_col = 0;
@@ -2812,10 +2739,7 @@ cupsdWriteClient(cupsd_client_t *con)    /* I - Client connection */
       }
 
       if (!con->got_fields)
-      {
-//        con->http->activity = time(NULL);
         return;
-      }
     }
 
     if (con->header_used > 0)
@@ -2866,8 +2790,6 @@ cupsdWriteClient(cupsd_client_t *con)     /* I - Client connection */
       }
     }
 
-//    con->http->state = HTTP_STATE_WAITING;
-
     cupsdAddSelect(httpGetFd(con->http), (cupsd_selfunc_t)cupsdReadClient, NULL, con);
 
     cupsdLogClient(con, CUPSD_LOG_DEBUG, "Waiting for request.");
@@ -2919,8 +2841,6 @@ cupsdWriteClient(cupsd_client_t *con)     /* I - Client connection */
       cupsdSetBusyState();
     }
   }
-
-//  con->http->activity = time(NULL);
 }
 
 
@@ -4063,23 +3983,14 @@ write_file(cupsd_client_t *con,         /* I - Client connection */
 
   con->pipe_pid = 0;
 
-  if (!cupsdSendHeader(con, code, type, CUPSD_AUTH_NONE))
-    return (0);
+  httpSetLength(con->http, filestats->st_size);
 
-  if (httpPrintf(con->http, "Last-Modified: %s\r\n",
-                 httpGetDateString(filestats->st_mtime)) < 0)
-    return (0);
-  if (httpPrintf(con->http, "Content-Length: " CUPS_LLFMT "\r\n",
-                 CUPS_LLCAST filestats->st_size) < 0)
-    return (0);
-  if (httpPrintf(con->http, "\r\n") < 0)
-    return (0);
+  httpSetField(con->http, HTTP_FIELD_LAST_MODIFIED,
+              httpGetDateString(filestats->st_mtime));
 
-  if (cupsdFlushHeader(con) < 0)
+  if (!cupsdSendHeader(con, code, type, CUPSD_AUTH_NONE))
     return (0);
 
-  httpSetLength(con->http, filestats->st_size);
-
   cupsdAddSelect(httpGetFd(con->http), (cupsd_selfunc_t)cupsdReadClient,
                  (cupsd_selfunc_t)cupsdWriteClient, con);
 
index ade341b92e49b7e216309064b0405db549a517f5..6217eac9c233adf6e7c1227d58dbb9ade18da9a4 100644 (file)
@@ -46,6 +46,7 @@ struct cupsd_client_s
   int                  file;           /* Input/output file */
   int                  file_ready;     /* Input ready on file/pipe? */
   int                  pipe_pid;       /* Pipe process ID (or 0 if not a pipe) */
+  http_status_t                pipe_status;    /* HTTP status from pipe process */
   int                  sent_header,    /* Non-zero if sent HTTP header */
                        got_fields,     /* Non-zero if all fields seen */
                        header_used;    /* Number of header bytes used */
@@ -121,7 +122,6 @@ extern void cupsdAcceptClient(cupsd_listener_t *lis);
 extern void    cupsdCloseAllClients(void);
 extern int     cupsdCloseClient(cupsd_client_t *con);
 extern void    cupsdDeleteAllListeners(void);
-extern int     cupsdFlushHeader(cupsd_client_t *con);
 extern void    cupsdPauseListening(void);
 extern int     cupsdProcessIPPRequest(cupsd_client_t *con);
 extern void    cupsdReadClient(cupsd_client_t *con);
index 635ebb268be405e3b3519f290516ca19f4b28f2c..4e57f4a656628956cecd3da5d0421a2585b4cd13 100644 (file)
@@ -644,73 +644,54 @@ cupsdProcessIPPRequest(
                    uri ? uri->values[0].string.text : "no URI",
                    con->http->hostname);
 
-    if (cupsdSendHeader(con, HTTP_OK, "application/ipp", CUPSD_AUTH_NONE))
-    {
 #ifdef CUPSD_USE_CHUNKING
-     /*
-      * Because older versions of CUPS (1.1.17 and older) and some IPP
-      * clients do not implement chunking properly, we cannot use
-      * chunking by default.  This may become the default in future
-      * CUPS releases, or we might add a configuration directive for
-      * it.
-      */
-
-      if (con->http->version == HTTP_1_1)
-      {
-        cupsdLogMessage(CUPSD_LOG_DEBUG,
-                        "[Client %d] Transfer-Encoding: chunked",
-                        con->number);
-
-       if (httpPrintf(HTTP(con), "Transfer-Encoding: chunked\r\n\r\n") < 0)
-         return (0);
+   /*
+    * Because older versions of CUPS (1.1.17 and older) and some IPP
+    * clients do not implement chunking properly, we cannot use
+    * chunking by default.  This may become the default in future
+    * CUPS releases, or we might add a configuration directive for
+    * it.
+    */
 
-       if (cupsdFlushHeader(con) < 0)
-         return (0);
+    if (con->http->version == HTTP_1_1)
+    {
+      cupsdLogMessage(CUPSD_LOG_DEBUG,
+                     "[Client %d] Transfer-Encoding: chunked",
+                     con->number);
 
-       con->http->data_encoding = HTTP_ENCODE_CHUNKED;
-      }
-      else
+      cupsdSetLength(con->http, 0);
+    }
+    else
 #endif /* CUPSD_USE_CHUNKING */
-      {
-        size_t length;                 /* Length of response */
-
-
-       length = ippLength(con->response);
-
-       if (con->file >= 0 && !con->pipe_pid)
-       {
-         struct stat   fileinfo;       /* File information */
-
-          if (!fstat(con->file, &fileinfo))
-           length += fileinfo.st_size;
-       }
+    {
+      size_t   length;                 /* Length of response */
 
-        cupsdLogMessage(CUPSD_LOG_DEBUG,
-                        "[Client %d] Content-Length: " CUPS_LLFMT,
-                        con->number, CUPS_LLCAST length);
-       if (httpPrintf(HTTP(con), "Content-Length: " CUPS_LLFMT "\r\n\r\n",
-                      CUPS_LLCAST length) < 0)
-         return (0);
 
-       if (cupsdFlushHeader(con) < 0)
-         return (0);
+      length = ippLength(con->response);
 
-       con->http->data_encoding  = HTTP_ENCODE_LENGTH;
-       con->http->data_remaining = length;
+      if (con->file >= 0 && !con->pipe_pid)
+      {
+       struct stat     fileinfo;       /* File information */
 
-       if (con->http->data_remaining <= INT_MAX)
-         con->http->_data_remaining = con->http->data_remaining;
-       else
-         con->http->_data_remaining = INT_MAX;
+       if (!fstat(con->file, &fileinfo))
+         length += fileinfo.st_size;
       }
 
-      cupsdAddSelect(httpGetFd(con->http), (cupsd_selfunc_t)cupsdReadClient,
-                     (cupsd_selfunc_t)cupsdWriteClient, con);
+      cupsdLogMessage(CUPSD_LOG_DEBUG,
+                     "[Client %d] Content-Length: " CUPS_LLFMT,
+                     con->number, CUPS_LLCAST length);
+      httpSetLength(con->http, length);
+    }
 
+    if (cupsdSendHeader(con, HTTP_OK, "application/ipp", CUPSD_AUTH_NONE))
+    {
      /*
       * Tell the caller the response header was sent successfully...
       */
 
+      cupsdAddSelect(httpGetFd(con->http), (cupsd_selfunc_t)cupsdReadClient,
+                    (cupsd_selfunc_t)cupsdWriteClient, con);
+    
       return (1);
     }
     else
index 8ead3f143f8b0c42260ba173258c4643641e9132..4dde8ad10898740f253fab50236161113a3b402d 100644 (file)
@@ -109,6 +109,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
              _cupsLangPuts(stdout, cupsServer());
            else
              _cupsLangPrintf(stdout, "%s:%d", cupsServer(), ippPort());
+           op = 'H';
             break;
 
         case 'P' : /* Show paper types */