Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request.c: Use errno only if it is non-zero (fixes #893) #1009

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cups/cups-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,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
Expand Down
2 changes: 1 addition & 1 deletion cups/getdevices.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ cupsGetDevices(

if (status != HTTP_STATUS_OK)
{
_cupsSetHTTPError(status);
_cupsSetHTTPError(http, status);
return (cupsGetError());
}

Expand Down
4 changes: 2 additions & 2 deletions cups/getputfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ cupsGetFd(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFA
}
else
{
_cupsSetHTTPError(status);
_cupsSetHTTPError(http, status);
httpFlush(http);
}

Expand Down Expand Up @@ -491,7 +491,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);
}

Expand Down
6 changes: 3 additions & 3 deletions cups/http-addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ httpAddrListen(http_addr_t *addr, // I - Address to bind to
// Create the socket and set options...
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);
}

Expand Down Expand Up @@ -260,7 +260,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);

Expand All @@ -270,7 +270,7 @@ httpAddrListen(http_addr_t *addr, // I - Address to bind to
// Listen...
if (listen(fd, INT_MAX))
{
_cupsSetHTTPError(HTTP_STATUS_ERROR);
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0);

close(fd);

Expand Down
2 changes: 1 addition & 1 deletion cups/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,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);
Expand Down
8 changes: 4 additions & 4 deletions cups/ipp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2849,7 +2849,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;
}
Expand All @@ -2874,7 +2874,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;
}
Expand Down Expand Up @@ -3181,7 +3181,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;
}
Expand Down Expand Up @@ -5989,7 +5989,7 @@ ipp_set_value(ipp_t *ipp, // IO - IPP message
// Reallocate memory...
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);
}
Expand Down
2 changes: 1 addition & 1 deletion cups/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ cupsJSONImportURL(
else
{
// Save the last HTTP status as a CUPS error...
_cupsSetHTTPError(status);
_cupsSetHTTPError(http, status);
}

// Flush any remaining data...
Expand Down
2 changes: 1 addition & 1 deletion cups/ppd-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,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);
Expand Down
15 changes: 8 additions & 7 deletions cups/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,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;
}

Expand Down Expand Up @@ -445,7 +445,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...
Expand Down Expand Up @@ -829,7 +829,7 @@ cupsSendRequest(http_t *http, /* I - Connection to server or @code CUPS_HTTP
{
int temp_status; /* Temporary status */

_cupsSetHTTPError(status);
_cupsSetHTTPError(http, status);

do
{
Expand Down Expand Up @@ -985,7 +985,7 @@ cupsWriteRequestData(
_httpUpdate(http, &status);
if (status >= HTTP_STATUS_MULTIPLE_CHOICES)
{
_cupsSetHTTPError(status);
_cupsSetHTTPError(http, status);

do
{
Expand Down Expand Up @@ -1151,7 +1151,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)
{
Expand Down Expand Up @@ -1196,8 +1197,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 IPP_STATUS_ERROR_SERVICE_UNAVAILABLE!", status);
Expand Down
Loading