]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Rework setting HTTP related errors (fixes #893)
authorZdenek Dohnal <zdohnal@redhat.com>
Wed, 24 Jul 2024 07:19:46 +0000 (09:19 +0200)
committerZdenek Dohnal <zdohnal@redhat.com>
Wed, 24 Jul 2024 07:19:46 +0000 (09:19 +0200)
CHANGES.md
cups/cups-private.h
cups/getdevices.c
cups/getputfile.c
cups/http-addr.c
cups/http.c
cups/ipp.c
cups/ppd-util.c
cups/request.c

index 44c5741d9a8ec30eac1c622de3afa9b123057649..e0aa26cd21fe641571ca29f2d985d5697cf0db25 100644 (file)
@@ -5,6 +5,7 @@ CHANGES - OpenPrinting CUPS
 Changes in CUPS v2.4.11 (YYYY-MM-DD)
 ------------------------------------
 
+- Fix incorrect error message for HTTP/IPP errors (Issue #893)
 - Updated the maximum file descriptor limit for `cupsd` to 64k-1 (Issue #989)
 - Fix checkbox support (Issue #1008)
 
index 4d4245bf05628a5f73b28b2471261e63bcecab76..3eca0da87d8654971177b099ef02b5526706185e 100644 (file)
@@ -284,7 +284,7 @@ extern const char   *_cupsGSSServiceName(void) _CUPS_PRIVATE;
 extern int             _cupsNextDelay(int current, int *previous) _CUPS_PRIVATE;
 extern void            _cupsSetDefaults(void) _CUPS_INTERNAL;
 extern void            _cupsSetError(ipp_status_t status, const char *message, int localize) _CUPS_PRIVATE;
-extern void            _cupsSetHTTPError(http_status_t status) _CUPS_INTERNAL;
+extern void            _cupsSetHTTPError(http_t *http, http_status_t status) _CUPS_INTERNAL;
 #  ifdef HAVE_GSSAPI
 extern int             _cupsSetNegotiateAuthString(http_t *http, const char *method, const char *resource) _CUPS_PRIVATE;
 #  endif /* HAVE_GSSAPI */
index 03102d488009d36ed095c06c5b849e7924ba5919..a6612b637efdf6a5b5663cfea3bc581667845c9f 100644 (file)
@@ -155,7 +155,7 @@ cupsGetDevices(
 
   if (status != HTTP_STATUS_OK)
   {
-    _cupsSetHTTPError(status);
+    _cupsSetHTTPError(http, status);
     return (cupsLastError());
   }
 
index 53d3d313de1aec0ca31d92527445dd3bc8f94720..902386d2634a59de131bb6844bf39e95e8eb83b0 100644 (file)
@@ -195,7 +195,7 @@ cupsGetFd(http_t     *http,         /* I - Connection to server or @code CUPS_HTTP_DEFA
   }
   else
   {
-    _cupsSetHTTPError(status);
+    _cupsSetHTTPError(http, status);
     httpFlush(http);
   }
 
@@ -496,7 +496,7 @@ cupsPutFd(http_t     *http,         /* I - Connection to server or @code CUPS_HTTP_DEFA
 
   if (status != HTTP_STATUS_CREATED)
   {
-    _cupsSetHTTPError(status);
+    _cupsSetHTTPError(http, status);
     httpFlush(http);
   }
 
index 80c1fa8fcb66a08dc9e6acb0061ed5b8f7f64aa3..f93f00fa54b820950dbf30b5b92a7b83c289e512 100644 (file)
@@ -181,7 +181,7 @@ httpAddrListen(http_addr_t *addr,   /* I - Address to bind to */
 
   if ((fd = socket(addr->addr.sa_family, SOCK_STREAM, 0)) < 0)
   {
-    _cupsSetHTTPError(HTTP_STATUS_ERROR);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0);
     return (-1);
   }
 
@@ -240,7 +240,7 @@ httpAddrListen(http_addr_t *addr,   /* I - Address to bind to */
 
   if (status)
   {
-    _cupsSetHTTPError(HTTP_STATUS_ERROR);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0);
 
     close(fd);
 
@@ -253,7 +253,7 @@ httpAddrListen(http_addr_t *addr,   /* I - Address to bind to */
 
   if (listen(fd, INT_MAX))
   {
-    _cupsSetHTTPError(HTTP_STATUS_ERROR);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0);
 
     close(fd);
 
index ec772bf8c48a23bc589ae094941a8c52742ab99b..31a8be36142965fd6fe4304a40ec90a98856b062 100644 (file)
@@ -168,7 +168,7 @@ httpAcceptConnection(int fd,                /* I - Listen socket file descriptor */
   if ((http->fd = accept(fd, (struct sockaddr *)&(http->addrlist->addr),
                         &addrlen)) < 0)
   {
-    _cupsSetHTTPError(HTTP_STATUS_ERROR);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0);
     httpClose(http);
 
     return (NULL);
index bba888beadbb02d9262b36a9c33e8843746be6e4..f44dd0553cfd34b3d741e17160f45bb6d502d8a3 100644 (file)
@@ -3179,7 +3179,7 @@ ippReadIO(void       *src,                /* I - Data source */
            attr = ipp->current = ipp_add_attr(ipp, NULL, ipp->curtag, IPP_TAG_ZERO, 1);
            if (!attr)
            {
-             _cupsSetHTTPError(HTTP_STATUS_ERROR);
+             _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unable to allocate IPP attribute."), 1);
              DEBUG_puts("1ippReadIO: unable to allocate attribute.");
              goto rollback;
            }
@@ -3208,7 +3208,7 @@ ippReadIO(void       *src,                /* I - Data source */
            if ((attr = ipp->current = ipp_add_attr(ipp, (char *)buffer, ipp->curtag, tag,
                                                    1)) == NULL)
            {
-             _cupsSetHTTPError(HTTP_STATUS_ERROR);
++            _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unable to allocate IPP attribute."), 1);
              DEBUG_puts("1ippReadIO: unable to allocate attribute.");
              goto rollback;
            }
@@ -3558,7 +3558,7 @@ ippReadIO(void       *src,                /* I - Data source */
                {
                  if ((value->unknown.data = malloc((size_t)n)) == NULL)
                  {
-                   _cupsSetHTTPError(HTTP_STATUS_ERROR);
+                   _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unable to allocate IPP attribute."), 1);
                    DEBUG_puts("1ippReadIO: Unable to allocate value");
                    goto rollback;
                  }
@@ -6723,7 +6723,7 @@ ipp_set_value(ipp_t           *ipp,       /* IO - IPP message */
 
   if ((temp = realloc(temp, sizeof(ipp_attribute_t) + (size_t)(alloc_values - 1) * sizeof(_ipp_value_t))) == NULL)
   {
-    _cupsSetHTTPError(HTTP_STATUS_ERROR);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unable to reallocate IPP attribute value."), 1);
     DEBUG_puts("4ipp_set_value: Unable to resize attribute.");
     return (NULL);
   }
index 66f43661d1dc543685f9d519300ac70e1381f502..39f2104721c3b5cd110669a3c9023ab0bbf68a66 100644 (file)
@@ -436,7 +436,7 @@ cupsGetPPD3(http_t     *http,               /* I  - HTTP connection or @code CUPS_HTTP_DEFAUL
   }
   else if (status != HTTP_STATUS_NOT_MODIFIED)
   {
-    _cupsSetHTTPError(status);
+    _cupsSetHTTPError(http2, status);
 
     if (buffer[0])
       unlink(buffer);
index 2ede4b309e220816cd99ad016c37108c3ea50835..5e52e41e62967d8b8bbfb813fb7c808641b36a6b 100644 (file)
@@ -243,7 +243,7 @@ cupsDoIORequest(http_t     *http,   /* I - Connection to server or @code CUPS_HTTP
         (status >= HTTP_STATUS_BAD_REQUEST && status != HTTP_STATUS_UNAUTHORIZED &&
         status != HTTP_STATUS_UPGRADE_REQUIRED))
     {
-      _cupsSetHTTPError(status);
+      _cupsSetHTTPError(http, status);
       break;
     }
 
@@ -415,7 +415,7 @@ cupsGetResponse(http_t     *http,   /* I - Connection to server or @code CUPS_HTTP
 
     httpFlush(http);
 
-    _cupsSetHTTPError(status);
+    _cupsSetHTTPError(http, status);
 
    /*
     * Then handle encryption and authentication...
@@ -809,7 +809,7 @@ cupsSendRequest(http_t     *http,   /* I - Connection to server or @code CUPS_HTTP
     {
       int temp_status;                 /* Temporary status */
 
-      _cupsSetHTTPError(status);
+      _cupsSetHTTPError(http, status);
 
       do
       {
@@ -967,7 +967,7 @@ cupsWriteRequestData(
       _httpUpdate(http, &status);
       if (status >= HTTP_STATUS_MULTIPLE_CHOICES)
       {
-        _cupsSetHTTPError(status);
+        _cupsSetHTTPError(http, status);
 
        do
        {
@@ -1134,7 +1134,8 @@ _cupsSetError(ipp_status_t status,        /* I - IPP status code */
  */
 
 void
-_cupsSetHTTPError(http_status_t status)        /* I - HTTP status code */
+_cupsSetHTTPError(http_t       *http,  /* I - HTTP connection */
+                 http_status_t status) /* I - HTTP status code */
 {
   switch (status)
   {
@@ -1179,8 +1180,8 @@ _cupsSetHTTPError(http_status_t status)   /* I - HTTP status code */
         break;
 
     case HTTP_STATUS_ERROR :
-       _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0);
-        break;
+       _cupsSetError(IPP_STATUS_ERROR_INTERNAL, http->error != 0 ? strerror(http->error) : "Internal Server Error", 0);
+       break;
 
     default :
        DEBUG_printf(("4_cupsSetHTTPError: HTTP error %d mapped to "