Skip to content

Commit

Permalink
Cleanup, removal of deprecated constants, DEBUG_printf modernization.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Sep 7, 2023
1 parent 26836ad commit e3952d3
Show file tree
Hide file tree
Showing 108 changed files with 7,016 additions and 7,107 deletions.
8 changes: 0 additions & 8 deletions backend/dnssd.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ main(int argc, /* I - Number of command-line args */
AvahiClient *client; /* Client information */
int error; /* Error code, if any */
#endif /* HAVE_AVAHI */
#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
struct sigaction action; /* Actions for POSIX signals */
#endif /* HAVE_SIGACTION && !HAVE_SIGSET */


/*
Expand All @@ -169,17 +167,11 @@ main(int argc, /* I - Number of command-line args */

setbuf(stderr, NULL);

#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
sigset(SIGTERM, sigterm_handler);
#elif defined(HAVE_SIGACTION)
memset(&action, 0, sizeof(action));

sigemptyset(&action.sa_mask);
action.sa_handler = sigterm_handler;
sigaction(SIGTERM, &action, NULL);
#else
signal(SIGTERM, sigterm_handler);
#endif /* HAVE_SIGSET */

/*
* Check command-line...
Expand Down
36 changes: 14 additions & 22 deletions backend/ipp.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ main(int argc, /* I - Number of command-line args */
int fd; /* File descriptor */
off_t bytes = 0; /* Bytes copied */
char buffer[16384]; /* Copy buffer */
#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
struct sigaction action; /* Actions for POSIX signals */
#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
int version; /* IPP version */
ppd_file_t *ppd = NULL; /* PPD file */
_ppd_cache_t *pc = NULL; /* PPD cache and mapping data */
Expand All @@ -284,10 +282,6 @@ main(int argc, /* I - Number of command-line args */
* Ignore SIGPIPE and catch SIGTERM signals...
*/

#ifdef HAVE_SIGSET
sigset(SIGPIPE, SIG_IGN);
sigset(SIGTERM, sigterm_handler);
#elif defined(HAVE_SIGACTION)
memset(&action, 0, sizeof(action));
action.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &action, NULL);
Expand All @@ -296,10 +290,6 @@ main(int argc, /* I - Number of command-line args */
sigaddset(&action.sa_mask, SIGTERM);
action.sa_handler = sigterm_handler;
sigaction(SIGTERM, &action, NULL);
#else
signal(SIGPIPE, SIG_IGN);
signal(SIGTERM, sigterm_handler);
#endif /* HAVE_SIGSET */

/*
* Check command-line...
Expand Down Expand Up @@ -796,8 +786,8 @@ main(int argc, /* I - Number of command-line args */
* Validate TLS credentials...
*/

cups_array_t *creds; /* TLS credentials */
cups_array_t *lcreds = NULL; /* Loaded credentials */
char *creds; /* TLS credentials */
char *lcreds = NULL; /* Loaded credentials */
http_trust_t trust; /* Trust level */
char credinfo[1024], /* Information on credentials */
lcredinfo[1024];/* Information on saved credentials */
Expand All @@ -815,21 +805,23 @@ main(int argc, /* I - Number of command-line args */

fputs("DEBUG: Connection is encrypted.\n", stderr);

if (!httpCopyCredentials(http, &creds))
if ((creds = httpCopyPeerCredentials(http)) != NULL)
{
trust = httpCredentialsGetTrust(creds, hostname);
httpCredentialsString(creds, credinfo, sizeof(credinfo));
trust = cupsGetCredentialsTrust(NULL, hostname, creds);
cupsGetCredentialsInfo(creds, credinfo, sizeof(credinfo));

fprintf(stderr, "DEBUG: %s (%s)\n", trust_msgs[trust], cupsGetErrorString());
fprintf(stderr, "DEBUG: Printer credentials: %s\n", credinfo);

if (!httpLoadCredentials(NULL, &lcreds, hostname))
if ((lcreds = cupsCopyCredentials(NULL, hostname)) != NULL)
{
httpCredentialsString(lcreds, lcredinfo, sizeof(lcredinfo));
cupsGetCredentialsInfo(lcreds, lcredinfo, sizeof(lcredinfo));
fprintf(stderr, "DEBUG: Stored credentials: %s\n", lcredinfo);
}
else
{
fputs("DEBUG: No stored credentials.\n", stderr);
}

update_reasons(NULL, "-cups-pki-invalid,cups-pki-changed,cups-pki-expired,cups-pki-unknown");
if (trusts[trust])
Expand All @@ -845,11 +837,11 @@ main(int argc, /* I - Number of command-line args */
* can detect changes...
*/

httpSaveCredentials(NULL, creds, hostname);
cupsSaveCredentials(NULL, hostname, creds, /*key*/NULL);
}

httpFreeCredentials(lcreds);
httpFreeCredentials(creds);
free(lcreds);
free(creds);
}
else
{
Expand All @@ -864,8 +856,8 @@ main(int argc, /* I - Number of command-line args */
_cupsLangPrintFilter(stderr, "INFO", _("Connected to printer."));

fprintf(stderr, "DEBUG: Connected to %s:%d...\n",
httpAddrString(http->hostaddr, addrname, sizeof(addrname)),
httpAddrPort(http->hostaddr));
httpAddrGetString(http->hostaddr, addrname, sizeof(addrname)),
httpAddrGetPort(http->hostaddr));

/*
* Build a URI for the printer and fill the standard IPP attributes for
Expand Down
12 changes: 1 addition & 11 deletions backend/lpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */
copies; /* Number of copies */
ssize_t bytes = 0; /* Initial bytes read */
char buffer[16384]; /* Initial print buffer */
#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
struct sigaction action; /* Actions for POSIX signals */
#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
int num_jobopts; /* Number of job options */
cups_option_t *jobopts = NULL; /* Job options */

Expand All @@ -138,10 +136,6 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */
* Ignore SIGPIPE and catch SIGTERM signals...
*/

#ifdef HAVE_SIGSET
sigset(SIGPIPE, SIG_IGN);
sigset(SIGTERM, sigterm_handler);
#elif defined(HAVE_SIGACTION)
memset(&action, 0, sizeof(action));
action.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &action, NULL);
Expand All @@ -150,10 +144,6 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */
sigaddset(&action.sa_mask, SIGTERM);
action.sa_handler = sigterm_handler;
sigaction(SIGTERM, &action, NULL);
#else
signal(SIGPIPE, SIG_IGN);
signal(SIGTERM, sigterm_handler);
#endif /* HAVE_SIGSET */

/*
* Check command-line...
Expand Down Expand Up @@ -582,7 +572,7 @@ cups_rresvport(int *port, /* IO - Port number to bind to */
* Set the port number...
*/

_httpAddrSetPort(&addr, *port);
httpAddrSetPort(&addr, *port);

/*
* Try binding the port to the socket; return if all is OK...
Expand Down
8 changes: 0 additions & 8 deletions backend/runloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ backendRunLoop(
struct timeval timeout; /* Timeout for select() */
time_t curtime, /* Current time */
snmp_update = 0;
#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
struct sigaction action; /* Actions for POSIX signals */
#endif /* HAVE_SIGACTION && !HAVE_SIGSET */


fprintf(stderr,
Expand All @@ -168,17 +166,11 @@ backendRunLoop(

if (!print_fd)
{
#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
sigset(SIGTERM, SIG_IGN);
#elif defined(HAVE_SIGACTION)
memset(&action, 0, sizeof(action));

sigemptyset(&action.sa_mask);
action.sa_handler = SIG_IGN;
sigaction(SIGTERM, &action, NULL);
#else
signal(SIGTERM, SIG_IGN);
#endif /* HAVE_SIGSET */
}
else if (print_fd < 0)
{
Expand Down
16 changes: 2 additions & 14 deletions backend/snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */
{
int ipv4, /* SNMP IPv4 socket */
ipv6; /* SNMP IPv6 socket */
#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
struct sigaction action; /* Actions for POSIX signals */
#endif /* HAVE_SIGACTION && !HAVE_SIGSET */


/*
Expand All @@ -202,18 +200,12 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */
* Catch SIGALRM signals...
*/

#ifdef HAVE_SIGSET
sigset(SIGALRM, alarm_handler);
#elif defined(HAVE_SIGACTION)
memset(&action, 0, sizeof(action));

sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, SIGALRM);
action.sa_handler = alarm_handler;
sigaction(SIGALRM, &action, NULL);
#else
signal(SIGALRM, alarm_handler);
#endif /* HAVE_SIGSET */

/*
* Open the SNMP socket...
Expand Down Expand Up @@ -428,10 +420,6 @@ alarm_handler(int sig) /* I - Signal number */

(void)sig;

#if !defined(HAVE_SIGSET) && !defined(HAVE_SIGACTION)
signal(SIGALRM, alarm_handler);
#endif /* !HAVE_SIGSET && !HAVE_SIGACTION */

if (DebugLevel)
backendMessage("DEBUG: ALARM!\n");
}
Expand Down Expand Up @@ -1132,7 +1120,7 @@ read_snmp_response(int fd) /* I - SNMP socket file descriptor */
scheme, sizeof(scheme),
userpass, sizeof(userpass),
hostname, sizeof(hostname), &port,
resource, sizeof(resource)) >= HTTP_URI_OK)
resource, sizeof(resource)) >= HTTP_URI_STATUS_OK)
device->uri = strdup((char *)packet.object_value.string.bytes);
}
break;
Expand Down Expand Up @@ -1328,7 +1316,7 @@ try_connect(http_addr_t *addr, /* I - Socket address */
return (-1);
}

_httpAddrSetPort(addr, port);
httpAddrSetPort(addr, port);

alarm(1);

Expand Down
8 changes: 0 additions & 8 deletions backend/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */
ssize_t bytes = 0, /* Initial bytes read */
tbytes; /* Total number of bytes written */
char buffer[1024]; /* Initial print buffer */
#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
struct sigaction action; /* Actions for POSIX signals */
#endif /* HAVE_SIGACTION && !HAVE_SIGSET */


/*
Expand All @@ -93,15 +91,9 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */
* Ignore SIGPIPE signals...
*/

#ifdef HAVE_SIGSET
sigset(SIGPIPE, SIG_IGN);
#elif defined(HAVE_SIGACTION)
memset(&action, 0, sizeof(action));
action.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &action, NULL);
#else
signal(SIGPIPE, SIG_IGN);
#endif /* HAVE_SIGSET */

/*
* Check command-line...
Expand Down
10 changes: 1 addition & 9 deletions backend/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */
username[255], /* Username info (not used) */
resource[1024], /* Resource info (device and options) */
*options; /* Pointer to options */
#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
struct sigaction action; /* Actions for POSIX signals */
#endif /* HAVE_SIGACTION && !HAVE_SIGSET */


/*
Expand All @@ -145,15 +143,9 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */
* Ignore SIGPIPE signals...
*/

#ifdef HAVE_SIGSET
sigset(SIGPIPE, SIG_IGN);
#elif defined(HAVE_SIGACTION)
memset(&action, 0, sizeof(action));
action.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &action, NULL);
#else
signal(SIGPIPE, SIG_IGN);
#endif /* HAVE_SIGSET */

/*
* Check command-line...
Expand Down Expand Up @@ -181,7 +173,7 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */
if (httpSeparateURI(HTTP_URI_CODING_ALL, uri,
method, sizeof(method), username, sizeof(username),
hostname, sizeof(hostname), &port,
resource, sizeof(resource)) < HTTP_URI_OK)
resource, sizeof(resource)) < HTTP_URI_STATUS_OK)
{
_cupsLangPrintFilter(stderr, "ERROR",
_("No device URI found in argv[0] or in DEVICE_URI "
Expand Down
4 changes: 2 additions & 2 deletions berkeley/lpq.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ main(int argc, /* I - Number of command-line arguments */
switch (*opt)
{
case 'E' : /* Encrypt */
cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
cupsSetEncryption(HTTP_ENCRYPTION_REQUIRED);

if (http)
httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
httpEncryption(http, HTTP_ENCRYPTION_REQUIRED);
break;

case 'U' : /* Username */
Expand Down
6 changes: 3 additions & 3 deletions berkeley/lpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ main(int argc, /* I - Number of command-line arguments */
switch (ch = *opt)
{
case 'E' : /* Encrypt */
cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
cupsSetEncryption(HTTP_ENCRYPTION_REQUIRED);
break;

case 'U' : /* Username */
Expand Down Expand Up @@ -391,11 +391,11 @@ main(int argc, /* I - Number of command-line arguments */
status = cupsStartDocument(CUPS_HTTP_DEFAULT, printer, job_id, NULL,
format, 1);

while (status == HTTP_CONTINUE &&
while (status == HTTP_STATUS_CONTINUE &&
(bytes = read(0, buffer, sizeof(buffer))) > 0)
status = cupsWriteRequestData(CUPS_HTTP_DEFAULT, buffer, (size_t)bytes);

if (status != HTTP_CONTINUE)
if (status != HTTP_STATUS_CONTINUE)
{
_cupsLangPrintf(stderr, _("%s: Error - unable to queue from stdin - %s."),
argv[0], httpStatus(status));
Expand Down
2 changes: 1 addition & 1 deletion berkeley/lprm.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ main(int argc, /* I - Number of command-line arguments */
switch (*opt)
{
case 'E' : /* Encrypt */
cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
cupsSetEncryption(HTTP_ENCRYPTION_REQUIRED);
break;

case 'P' : /* Cancel jobs on a printer */
Expand Down
8 changes: 4 additions & 4 deletions cgi-bin/admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,9 +956,9 @@ do_am_printer(http_t *http, /* I - HTTP connection */
if (httpGet(http, uri))
httpGet(http, uri);

while ((get_status = httpUpdate(http)) == HTTP_CONTINUE);
while ((get_status = httpUpdate(http)) == HTTP_STATUS_CONTINUE);

if (get_status != HTTP_OK)
if (get_status != HTTP_STATUS_OK)
{
httpFlush(http);

Expand Down Expand Up @@ -1598,13 +1598,13 @@ do_config_server(http_t *http) /* I - HTTP connection */

status = cupsPutFile(http, "/admin/conf/cupsd.conf", tempfile);

if (status == HTTP_UNAUTHORIZED)
if (status == HTTP_STATUS_UNAUTHORIZED)
{
puts("Status: 401\n");
unlink(tempfile);
exit(0);
}
else if (status != HTTP_CREATED)
else if (status != HTTP_STATUS_CREATED)
{
cgiSetVariable("MESSAGE",
cgiText(_("Unable to upload cupsd.conf file")));
Expand Down
4 changes: 2 additions & 2 deletions cgi-bin/ipp-var.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,10 @@ cgiPrintCommand(http_t *http, /* I - Connection to server */
}

status = cupsStartDocument(http, dest, job_id, NULL, CUPS_FORMAT_COMMAND, 1);
if (status == HTTP_CONTINUE)
if (status == HTTP_STATUS_CONTINUE)
status = cupsWriteRequestData(http, command_file,
strlen(command_file));
if (status == HTTP_CONTINUE)
if (status == HTTP_STATUS_CONTINUE)
cupsFinishDocument(http, dest);

if (cupsGetError() >= IPP_REDIRECTION_OTHER_SITE)
Expand Down
Loading

0 comments on commit e3952d3

Please sign in to comment.