]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/request.c
Fix source file header text duplication text duplication.
[thirdparty/cups.git] / cups / request.c
index f4e7e8892b56e49c11b827606f2f31e3452a8886..39cbe6ccdf8f796bc356cd871c67a6e7b47fb44f 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * "$Id$"
- *
  * IPP utilities for CUPS.
  *
  * Copyright 2007-2014 by Apple Inc.
@@ -10,7 +8,7 @@
  * property of Apple Inc. and are protected by Federal copyright
  * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
  * which should have been included with this file.  If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * missing or damaged, see the license at "http://www.cups.org/".
  *
  * This file is subject to the Apple OS-Developed Software exception.
  */
@@ -53,10 +51,7 @@ cupsDoFileRequest(http_t     *http,  /* I - Connection to server or @code CUPS_HT
   int          infile;                 /* Input file */
 
 
-  DEBUG_printf(("cupsDoFileRequest(http=%p, request=%p(%s), resource=\"%s\", "
-                "filename=\"%s\")", http, request,
-               request ? ippOpString(request->request.op.operation_id) : "?",
-               resource, filename));
+  DEBUG_printf(("cupsDoFileRequest(http=%p, request=%p(%s), resource=\"%s\", filename=\"%s\")", (void *)http, (void *)request, request ? ippOpString(request->request.op.operation_id) : "?", resource, filename));
 
   if (filename)
   {
@@ -99,7 +94,7 @@ cupsDoFileRequest(http_t     *http,   /* I - Connection to server or @code CUPS_HT
  * If "outfile" is a valid file descriptor, @code cupsDoIORequest@ copies
  * all of the data after the IPP response message to the file.
  *
- * @since CUPS 1.3/OS X 10.5@
+ * @since CUPS 1.3/macOS 10.5@
  */
 
 ipp_t *                                        /* O - Response data */
@@ -117,10 +112,7 @@ cupsDoIORequest(http_t     *http,  /* I - Connection to server or @code CUPS_HTTP
   char         buffer[32768];          /* Output buffer */
 
 
-  DEBUG_printf(("cupsDoIORequest(http=%p, request=%p(%s), resource=\"%s\", "
-                "infile=%d, outfile=%d)", http, request,
-               request ? ippOpString(request->request.op.operation_id) : "?",
-               resource, infile, outfile));
+  DEBUG_printf(("cupsDoIORequest(http=%p, request=%p(%s), resource=\"%s\", infile=%d, outfile=%d)", (void *)http, (void *)request, request ? ippOpString(request->request.op.operation_id) : "?", resource, infile, outfile));
 
  /*
   * Range check input...
@@ -245,7 +237,7 @@ cupsDoIORequest(http_t     *http,   /* I - Connection to server or @code CUPS_HTTP
     * Get the server's response...
     */
 
-    if (status <= HTTP_STATUS_CONTINUE)
+    if (status <= HTTP_STATUS_CONTINUE || status == HTTP_STATUS_OK)
     {
       response = cupsGetResponse(http, resource);
       status   = httpGetStatus(http);
@@ -304,10 +296,7 @@ cupsDoRequest(http_t     *http,            /* I - Connection to server or @code CUPS_HTTP_
               ipp_t      *request,     /* I - IPP request */
               const char *resource)    /* I - HTTP resource for POST */
 {
-  DEBUG_printf(("cupsDoRequest(http=%p, request=%p(%s), resource=\"%s\")",
-                http, request,
-               request ? ippOpString(request->request.op.operation_id) : "?",
-               resource));
+  DEBUG_printf(("cupsDoRequest(http=%p, request=%p(%s), resource=\"%s\")", (void *)http, (void *)request, request ? ippOpString(request->request.op.operation_id) : "?", resource));
 
   return (cupsDoIORequest(http, request, resource, -1, -1));
 }
@@ -321,7 +310,7 @@ cupsDoRequest(http_t     *http,             /* I - Connection to server or @code CUPS_HTTP_
  * @link cupsReadResponseData@ after getting a successful response,
  * otherwise call @link httpFlush@ to complete the response processing.
  *
- * @since CUPS 1.4/OS X 10.6@
+ * @since CUPS 1.4/macOS 10.6@
  */
 
 ipp_t *                                        /* O - Response or @code NULL@ on HTTP error */
@@ -333,18 +322,32 @@ cupsGetResponse(http_t     *http, /* I - Connection to server or @code CUPS_HTTP
   ipp_t                *response = NULL;       /* IPP response */
 
 
-  DEBUG_printf(("cupsGetResponse(http=%p, resource=\"%s\")", http, resource));
+  DEBUG_printf(("cupsGetResponse(http=%p, resource=\"%s\")", (void *)http, resource));
+  DEBUG_printf(("1cupsGetResponse: http->state=%d", http ? http->state : HTTP_STATE_ERROR));
 
  /*
   * Connect to the default server as needed...
   */
 
   if (!http)
-    http = _cupsConnect();
+  {
+    _cups_globals_t *cg = _cupsGlobals();
+                                       /* Pointer to library globals */
 
-  if (!http || (http->state != HTTP_STATE_POST_RECV &&
-                http->state != HTTP_STATE_POST_SEND))
+    if ((http = cg->http) == NULL)
+    {
+      _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("No active connection."), 1);
+      DEBUG_puts("1cupsGetResponse: No active connection - returning NULL.");
+      return (NULL);
+    }
+  }
+
+  if (http->state != HTTP_STATE_POST_RECV && http->state != HTTP_STATE_POST_SEND)
+  {
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("No request sent."), 1);
+    DEBUG_puts("1cupsGetResponse: Not in POST state - returning NULL.");
     return (NULL);
+  }
 
  /*
   * Check for an unfinished chunked request...
@@ -483,7 +486,7 @@ cupsLastError(void)
  * 'cupsLastErrorString()' - Return the last IPP status-message received on the
  *                           current thread.
  *
- * @since CUPS 1.2/OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 const char *                           /* O - status-message text from last request */
@@ -530,7 +533,7 @@ _cupsNextDelay(int current,         /* I  - Current delay value or 0 */
  * files from @code CUPS_GET_PPD@ and @code CUPS_GET_DOCUMENT@ requests,
  * respectively.
  *
- * @since CUPS 1.4/OS X 10.6@
+ * @since CUPS 1.4/macOS 10.6@
  */
 
 ssize_t                                        /* O - Bytes read, 0 on EOF, -1 on error */
@@ -543,8 +546,7 @@ cupsReadResponseData(
   * Get the default connection as needed...
   */
 
-  DEBUG_printf(("cupsReadResponseData(http=%p, buffer=%p, "
-                "length=" CUPS_LLFMT ")", http, buffer, CUPS_LLCAST length));
+  DEBUG_printf(("cupsReadResponseData(http=%p, buffer=%p, length=" CUPS_LLFMT ")", (void *)http, (void *)buffer, CUPS_LLCAST length));
 
   if (!http)
   {
@@ -581,7 +583,7 @@ cupsReadResponseData(
  * Note: Unlike @link cupsDoFileRequest@, @link cupsDoIORequest@, and
  * @link cupsDoRequest@, the request is NOT freed with @link ippDelete@.
  *
- * @since CUPS 1.4/OS X 10.6@
+ * @since CUPS 1.4/macOS 10.6@
  */
 
 http_status_t                          /* O - Initial HTTP status */
@@ -596,10 +598,7 @@ cupsSendRequest(http_t     *http,  /* I - Connection to server or @code CUPS_HTTP
   http_status_t                expect;         /* Expect: header to use */
 
 
-  DEBUG_printf(("cupsSendRequest(http=%p, request=%p(%s), resource=\"%s\", "
-                "length=" CUPS_LLFMT ")", http, request,
-               request ? ippOpString(request->request.op.operation_id) : "?",
-               resource, CUPS_LLCAST length));
+  DEBUG_printf(("cupsSendRequest(http=%p, request=%p(%s), resource=\"%s\", length=" CUPS_LLFMT ")", (void *)http, (void *)request, request ? ippOpString(request->request.op.operation_id) : "?", resource, CUPS_LLCAST length));
 
  /*
   * Range check input...
@@ -733,9 +732,8 @@ cupsSendRequest(http_t     *http,   /* I - Connection to server or @code CUPS_HTTP
     got_status     = 0;
 
     while ((state = ippWrite(http, request)) != IPP_STATE_DATA)
-      if (state == IPP_STATE_ERROR)
-       break;
-      else if (httpCheck(http))
+    {
+      if (httpCheck(http))
       {
         got_status = 1;
 
@@ -743,15 +741,30 @@ cupsSendRequest(http_t     *http, /* I - Connection to server or @code CUPS_HTTP
        if (status >= HTTP_STATUS_MULTIPLE_CHOICES)
          break;
       }
+      else if (state == IPP_STATE_ERROR)
+       break;
+    }
 
     if (state == IPP_STATE_ERROR)
     {
-      DEBUG_puts("1cupsSendRequest: Unable to send IPP request.");
+     /*
+      * We weren't able to send the IPP request. But did we already get a HTTP
+      * error status?
+      */
 
-      http->status = HTTP_STATUS_ERROR;
-      http->state  = HTTP_STATE_WAITING;
+      if (!got_status || status < HTTP_STATUS_MULTIPLE_CHOICES)
+      {
+       /*
+        * No, something else went wrong.
+       */
 
-      return (HTTP_STATUS_ERROR);
+       DEBUG_puts("1cupsSendRequest: Unable to send IPP request.");
+
+       http->status = HTTP_STATUS_ERROR;
+       http->state  = HTTP_STATE_WAITING;
+
+       return (HTTP_STATUS_ERROR);
+      }
     }
 
    /*
@@ -876,7 +889,7 @@ cupsSendRequest(http_t     *http,   /* I - Connection to server or @code CUPS_HTTP
  * This function is used after @link cupsSendRequest@ to provide a PPD and
  * after @link cupsStartDocument@ to provide a document file.
  *
- * @since CUPS 1.4/OS X 10.6@
+ * @since CUPS 1.4/macOS 10.6@
  */
 
 http_status_t                          /* O - @code HTTP_STATUS_CONTINUE@ if OK or HTTP status on error */
@@ -892,8 +905,7 @@ cupsWriteRequestData(
   * Get the default connection as needed...
   */
 
-  DEBUG_printf(("cupsWriteRequestData(http=%p, buffer=%p, "
-                "length=" CUPS_LLFMT ")", http, buffer, CUPS_LLCAST length));
+  DEBUG_printf(("cupsWriteRequestData(http=%p, buffer=%p, length=" CUPS_LLFMT ")", (void *)http, (void *)buffer, CUPS_LLCAST length));
 
   if (!http)
   {
@@ -1158,8 +1170,3 @@ _cupsSetHTTPError(http_status_t status)   /* I - HTTP status code */
        break;
   }
 }
-
-
-/*
- * End of "$Id$".
- */