diff options
Diffstat (limited to 'systemv')
-rw-r--r-- | systemv/cancel.c | 8 | ||||
-rw-r--r-- | systemv/cupstestppd.c | 1 | ||||
-rw-r--r-- | systemv/lp.c | 18 | ||||
-rw-r--r-- | systemv/lpadmin.c | 118 | ||||
-rw-r--r-- | systemv/lpstat.c | 26 |
5 files changed, 33 insertions, 138 deletions
diff --git a/systemv/cancel.c b/systemv/cancel.c index c85a86e0..0f303886 100644 --- a/systemv/cancel.c +++ b/systemv/cancel.c @@ -274,7 +274,7 @@ main(int argc, /* I - Number of command-line arguments */ } else { - sprintf(uri, "ipp://localhost/jobs/%d", job_id); + snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri); } @@ -311,8 +311,7 @@ main(int argc, /* I - Number of command-line arguments */ op == IPP_PURGE_JOBS ? "purge-jobs" : "cancel-job", cupsLastErrorString()); - if (response) - ippDelete(response); + ippDelete(response); return (1); } @@ -375,8 +374,7 @@ main(int argc, /* I - Number of command-line arguments */ op == IPP_PURGE_JOBS ? "purge-jobs" : "cancel-job", cupsLastErrorString()); - if (response) - ippDelete(response); + ippDelete(response); return (1); } diff --git a/systemv/cupstestppd.c b/systemv/cupstestppd.c index b94cae94..c3a2d19d 100644 --- a/systemv/cupstestppd.c +++ b/systemv/cupstestppd.c @@ -261,7 +261,6 @@ main(int argc, /* I - Number of command-line args */ default : usage(); - break; } } else diff --git a/systemv/lp.c b/systemv/lp.c index 298c1582..fd818a56 100644 --- a/systemv/lp.c +++ b/systemv/lp.c @@ -161,6 +161,12 @@ main(int argc, /* I - Number of command-line arguments */ "name."), argv[0]); return (1); } + else if (cupsLastError() == IPP_STATUS_ERROR_NOT_FOUND) + { + _cupsLangPrintf(stderr, + _("%s: Error - The printer or class does not exist."), argv[0]); + return (1); + } break; case 'f' : /* Form */ @@ -280,9 +286,7 @@ main(int argc, /* I - Number of command-line arguments */ return (1); } - sprintf(buffer, "%d", num_copies); - num_options = cupsAddOption("copies", buffer, num_options, - &options); + num_options = cupsAddIntegerOption("copies", num_copies, num_options, &options); break; case 'o' : /* Option */ @@ -342,9 +346,7 @@ main(int argc, /* I - Number of command-line arguments */ return (1); } - sprintf(buffer, "%d", priority); - num_options = cupsAddOption("job-priority", buffer, num_options, - &options); + num_options = cupsAddIntegerOption("job-priority", priority, num_options, &options); break; case 's' : /* Silent */ @@ -660,7 +662,7 @@ restart_job(const char *command, /* I - Command name */ request = ippNewRequest(IPP_RESTART_JOB); - sprintf(uri, "ipp://localhost/jobs/%d", job_id); + snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri); @@ -708,7 +710,7 @@ set_job_attrs( request = ippNewRequest(IPP_SET_JOB_ATTRIBUTES); - sprintf(uri, "ipp://localhost/jobs/%d", job_id); + snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri); diff --git a/systemv/lpadmin.c b/systemv/lpadmin.c index ca6d386b..dc875cb8 100644 --- a/systemv/lpadmin.c +++ b/systemv/lpadmin.c @@ -1,7 +1,8 @@ /* * "lpadmin" command for CUPS. * - * Copyright © 2007-2019 by Apple Inc. + * Copyright © 2021 by OpenPrinting. + * Copyright © 2007-2021 by Apple Inc. * Copyright © 1997-2006 by Easy Software Products. * * Licensed under Apache License v2.0. See the file "LICENSE" for more @@ -28,7 +29,6 @@ static int delete_printer_from_class(http_t *http, char *printer, static int delete_printer_option(http_t *http, char *printer, char *option); static int enable_printer(http_t *http, char *printer); -static char *get_printer_ppd(const char *uri, char *buffer, size_t bufsize, int *num_options, cups_option_t **options); static cups_ptype_t get_printer_type(http_t *http, char *printer, char *uri, size_t urisize); static int set_printer_options(http_t *http, char *printer, @@ -240,14 +240,14 @@ main(int argc, /* I - Number of command-line arguments */ case 'E' : /* Enable the printer/enable encryption */ if (printer == NULL) { -#ifdef HAVE_SSL +#ifdef HAVE_TLS cupsSetEncryption(HTTP_ENCRYPTION_REQUIRED); if (http) httpEncryption(http, HTTP_ENCRYPTION_REQUIRED); #else _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), argv[0]); -#endif /* HAVE_SSL */ +#endif /* HAVE_TLS */ break; } @@ -625,14 +625,7 @@ main(int argc, /* I - Number of command-line arguments */ return (1); #endif /* __APPLE__ */ } - else if (ppd_name && !strcmp(ppd_name, "everywhere") && device_uri) - { - if ((file = get_printer_ppd(device_uri, evefile, sizeof(evefile), &num_options, &options)) == NULL) - return (1); - - num_options = cupsRemoveOption("ppd-name", num_options, &options); - } - else if (ppd_name || file) + else if ((ppd_name && strcmp(ppd_name, "everywhere")) || file) { _cupsLangPuts(stderr, _("lpadmin: Printer drivers are deprecated and will stop working in a future version of CUPS.")); } @@ -1157,105 +1150,6 @@ enable_printer(http_t *http, /* I - Server connection */ /* - * 'get_printer_ppd()' - Get an IPP Everywhere PPD file for the given URI. - */ - -static char * /* O - Filename or NULL */ -get_printer_ppd( - const char *uri, /* I - Printer URI */ - char *buffer, /* I - Filename buffer */ - size_t bufsize, /* I - Size of filename buffer */ - int *num_options, /* IO - Number of options */ - cups_option_t **options) /* IO - Options */ -{ - http_t *http; /* Connection to printer */ - ipp_t *request, /* Get-Printer-Attributes request */ - *response; /* Get-Printer-Attributes response */ - ipp_attribute_t *attr; /* Attribute from response */ - char resolved[1024], /* Resolved URI */ - scheme[32], /* URI scheme */ - userpass[256], /* Username:password */ - host[256], /* Hostname */ - resource[256]; /* Resource path */ - int port; /* Port number */ - static const char * const pattrs[] = /* Attributes to use */ - { - "all", - "media-col-database" - }; - - - /* - * Connect to the printer... - */ - - if (strstr(uri, "._tcp")) - { - /* - * Resolve URI... - */ - - if (!_httpResolveURI(uri, resolved, sizeof(resolved), _HTTP_RESOLVE_DEFAULT, NULL, NULL)) - { - _cupsLangPrintf(stderr, _("%s: Unable to resolve \"%s\"."), "lpadmin", uri); - return (NULL); - } - - uri = resolved; - } - - if (httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme), userpass, sizeof(userpass), host, sizeof(host), &port, resource, sizeof(resource)) < HTTP_URI_STATUS_OK) - { - _cupsLangPrintf(stderr, _("%s: Bad printer URI \"%s\"."), "lpadmin", uri); - return (NULL); - } - - http = httpConnect2(host, port, NULL, AF_UNSPEC, !strcmp(scheme, "ipps") ? HTTP_ENCRYPTION_ALWAYS : HTTP_ENCRYPTION_IF_REQUESTED, 1, 30000, NULL); - if (!http) - { - _cupsLangPrintf(stderr, _("%s: Unable to connect to \"%s:%d\": %s"), "lpadmin", host, port, cupsLastErrorString()); - return (NULL); - } - - /* - * Send a Get-Printer-Attributes request... - */ - - request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES); - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri); - ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", sizeof(pattrs) / sizeof(pattrs[0]), NULL, pattrs); - response = cupsDoRequest(http, request, resource); - - if (cupsLastError() >= IPP_STATUS_REDIRECTION_OTHER_SITE) - { - _cupsLangPrintf(stderr, _("%s: Unable to query printer: %s"), "lpadmin", cupsLastErrorString()); - buffer[0] = '\0'; - } - else if (_ppdCreateFromIPP(buffer, bufsize, response)) - { - if (!cupsGetOption("printer-geo-location", *num_options, *options) && (attr = ippFindAttribute(response, "printer-geo-location", IPP_TAG_URI)) != NULL) - *num_options = cupsAddOption("printer-geo-location", ippGetString(attr, 0, NULL), *num_options, options); - - if (!cupsGetOption("printer-info", *num_options, *options) && (attr = ippFindAttribute(response, "printer-info", IPP_TAG_TEXT)) != NULL) - *num_options = cupsAddOption("printer-info", ippGetString(attr, 0, NULL), *num_options, options); - - if (!cupsGetOption("printer-location", *num_options, *options) && (attr = ippFindAttribute(response, "printer-location", IPP_TAG_TEXT)) != NULL) - *num_options = cupsAddOption("printer-location", ippGetString(attr, 0, NULL), *num_options, options); - } - else - _cupsLangPrintf(stderr, _("%s: Unable to create PPD file: %s"), "lpadmin", strerror(errno)); - - ippDelete(response); - httpClose(http); - - if (buffer[0]) - return (buffer); - else - return (NULL); -} - - -/* * 'get_printer_type()' - Determine the printer type and URI. */ @@ -1373,7 +1267,7 @@ set_printer_options( if (file) ppdfile = file; - else if ((ppdname = cupsGetOption("ppd-name", num_options, options)) != NULL && strcmp(ppdname, "raw") && num_options > 1) + else if ((ppdname = cupsGetOption("ppd-name", num_options, options)) != NULL && strcmp(ppdname, "everywhere") && strcmp(ppdname, "raw") && num_options > 1) { if ((ppdfile = cupsGetServerPPD(http, ppdname)) != NULL) { diff --git a/systemv/lpstat.c b/systemv/lpstat.c index 1d14cb8e..86e7a7ca 100644 --- a/systemv/lpstat.c +++ b/systemv/lpstat.c @@ -634,7 +634,7 @@ match_list(const char *list, /* I - List of names */ if (!name) return (0); - while (*list) + do { /* * Skip leading whitespace and commas... @@ -660,6 +660,7 @@ match_list(const char *list, /* I - List of names */ while (*list && !isspace(*list & 255) && *list != ',') list ++; } + while (*list); return (0); } @@ -810,8 +811,8 @@ show_accepting(const char *printers, /* I - Destinations */ _cupsLangPrintf(stdout, _("%s not accepting requests since %s -"), printer, printer_state_time); _cupsLangPrintf(stdout, _("\t%s"), - (message == NULL || !*message) ? - "reason unknown" : message); + (message && *message) ? + message : "reason unknown"); } for (i = 0; i < num_dests; i ++) @@ -826,8 +827,8 @@ show_accepting(const char *printers, /* I - Destinations */ _("%s/%s not accepting requests since %s -"), printer, dests[i].instance, printer_state_time); _cupsLangPrintf(stdout, _("\t%s"), - (message == NULL || !*message) ? - "reason unknown" : message); + (message && *message) ? + message : "reason unknown"); } } } @@ -950,7 +951,7 @@ show_classes(const char *dests) /* I - Destinations */ printer_uri = NULL; members = NULL; - while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) + do { if (!strcmp(attr->name, "printer-name") && attr->value_tag == IPP_TAG_NAME) @@ -966,6 +967,7 @@ show_classes(const char *dests) /* I - Destinations */ attr = attr->next; } + while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER); /* * If this is a remote class, grab the class info from the @@ -1789,10 +1791,10 @@ show_printers(const char *printers, /* I - Destinations */ if ((message && *message) || pstate == IPP_PRINTER_STOPPED) { - if (!message || !*message) - _cupsLangPuts(stdout, _("\treason unknown")); + if (message && *message) + _cupsLangPrintf(stdout, "\t%s", message); else - _cupsLangPrintf(stdout, "\t%s", message); + _cupsLangPuts(stdout, _("\treason unknown")); } if (long_status > 1) @@ -1909,10 +1911,10 @@ show_printers(const char *printers, /* I - Destinations */ if ((message && *message) || pstate == IPP_PRINTER_STOPPED) { - if (!message || !*message) - _cupsLangPuts(stdout, _("\treason unknown")); - else + if (message && *message) _cupsLangPrintf(stdout, "\t%s", message); + else + _cupsLangPuts(stdout, _("\treason unknown")); } if (long_status > 1) |