papi_status_t ipp_purge_jobs(papi_service_t svc, papi_attribute_t **request, papi_attribute_t ***response) { papi_status_t status; papi_job_t *jobs = NULL; papi_attribute_t **operational = NULL; char *queue = NULL; /* Get operational attributes from the request */ (void) papiAttributeListGetCollection(request, NULL, "operational-attributes-group", &operational); /* * The operational-attributes-group must contain: * printer-uri */ get_printer_id(operational, &queue, NULL); if (queue == NULL) { ipp_set_status(response, status, "printer-uri: %s", papiStatusString(status)); return (PAPI_BAD_REQUEST); } if ((status = papiPrinterPurgeJobs(svc, queue, &jobs)) != PAPI_OK) { ipp_set_status(response, status, "purge failed: %s: %s", (queue ? queue : "(null)"), ipp_svc_status_mesg(svc, status)); } papiJobListFree(jobs); return (status); }
/* ARGSUSED2 */ static int report_printer(papi_service_t svc, char *name, papi_printer_t printer, int verbose, int description) { papi_status_t status; papi_attribute_t **attrs = papiPrinterGetAttributeList(printer); time_t curr; int32_t pstat = 0; char *member = NULL; status = papiAttributeListGetString(attrs, NULL, "member-names", &member); if (status == PAPI_OK) /* it's a class */ return (0); if (name == NULL) { status = papiAttributeListGetString(attrs, NULL, "printer-name", &name); if (status != PAPI_OK) status = papiAttributeListGetString(attrs, NULL, "printer-uri-supported", &name); } if (name == NULL) return (-1); printf(gettext("printer %s "), name); status = papiAttributeListGetInteger(attrs, NULL, "printer-state", &pstat); switch (pstat) { case 0x03: /* idle */ printf(gettext("idle. enabled")); break; case 0x04: { /* processing */ char *requested[] = { "job-id", NULL }; papi_job_t *j = NULL; int32_t jobid = 0; (void) papiPrinterListJobs(svc, name, requested, 0, 1, &j); if ((j != NULL) && (j[0] != NULL)) jobid = papiJobGetId(j[0]); papiJobListFree(j); printf(gettext("now printing %s-%d. enabled"), name, jobid); } break; case 0x05: /* stopped */ printf(gettext("disabled")); break; default: printf(gettext("unknown state(0x%x)."), pstat); break; } (void) time(&curr); (void) papiAttributeListGetDatetime(attrs, NULL, "printer-up-time", &curr); (void) papiAttributeListGetDatetime(attrs, NULL, "printer-state-time", &curr); (void) papiAttributeListGetDatetime(attrs, NULL, "lpsched-disable-date", &curr); printf(gettext(" since %s. available.\n"), nctime(&curr)); if (pstat == 0x05) { char *reason = "unknown reason"; (void) papiAttributeListGetString(attrs, NULL, "printer-state-reasons", &reason); (void) papiAttributeListGetString(attrs, NULL, "lpsched-disable-reason", &reason); printf(gettext("\t%s\n"), reason); } if (verbose == 1) { void *iter; char *str; str = ""; (void) papiAttributeListGetString(attrs, NULL, "form-ready", &str); printf(gettext("\tForm mounted: %s\n"), str); str = ""; iter = NULL; (void) papiAttributeListGetString(attrs, &iter, "document-format-supported", &str); printf(gettext("\tContent types: %s"), str); while (papiAttributeListGetString(attrs, &iter, NULL, &str) == PAPI_OK) printf(", %s", str); printf("\n"); str = ""; (void) papiAttributeListGetString(attrs, NULL, "printer-info", &str); printf(gettext("\tDescription: %s\n"), str); str = ""; (void) papiAttributeListGetString(attrs, NULL, "lpsched-dial-info", &str); printf(gettext("\tConnection: %s\n"), ((str[0] != '\0') ? gettext("direct") : str)); str = ""; (void) papiAttributeListGetString(attrs, NULL, "lpsched-interface-script", &str); printf(gettext("\tInterface: %s\n"), str); str = NULL; (void) papiAttributeListGetString(attrs, NULL, "ppd-file-uri", &str); (void) papiAttributeListGetString(attrs, NULL, "lpsched-ppd-source-path", &str); if (str != NULL) printf(gettext("\tPPD: %s\n"), str); str = NULL; (void) papiAttributeListGetString(attrs, NULL, "lpsched-fault-alert-command", &str); if (str != NULL) printf(gettext("\tOn fault: %s\n"), str); str = ""; (void) papiAttributeListGetString(attrs, NULL, "lpsched-fault-recovery", &str); printf(gettext("\tAfter fault: %s\n"), ((str[0] == '\0') ? gettext("continue") : str)); str = "(all)"; iter = NULL; (void) papiAttributeListGetString(attrs, &iter, "requesting-user-name-allowed", &str); printf(gettext("\tUsers allowed:\n\t\t%s\n"), ((str[0] == '\0') ? gettext("(none)") : str)); if ((str != NULL) && (str[0] != '\0')) while (papiAttributeListGetString(attrs, &iter, NULL, &str) == PAPI_OK) printf("\t\t%s\n", str); str = NULL; iter = NULL; (void) papiAttributeListGetString(attrs, &iter, "requesting-user-name-denied", &str); if (str != NULL) { printf(gettext("\tUsers denied:\n\t\t%s\n"), ((str[0] == '\0') ? gettext("(none)") : str)); if ((str != NULL) && (str[0] != '\0')) while (papiAttributeListGetString(attrs, &iter, NULL, &str) == PAPI_OK) printf("\t\t%s\n", str); } str = "(none)"; iter = NULL; (void) papiAttributeListGetString(attrs, &iter, "form-supported", &str); printf(gettext("\tForms allowed:\n\t\t%s\n"), ((str[0] == '\0') ? gettext("(none)") : str)); if ((str != NULL) && (str[0] != '\0')) while (papiAttributeListGetString(attrs, &iter, NULL, &str) == PAPI_OK) printf("\t\t%s\n", str); str = ""; iter = NULL; (void) papiAttributeListGetString(attrs, &iter, "media-supported", &str); printf(gettext("\tMedia supported:\n\t\t%s\n"), ((str[0] == '\0') ? gettext("(none)") : str)); if ((str != NULL) && (str[0] != '\0')) while (papiAttributeListGetString(attrs, &iter, NULL, &str) == PAPI_OK) printf("\t\t%s\n", str); str = ""; (void) papiAttributeListGetString(attrs, NULL, "job-sheets-supported", &str); printf(gettext("\tBanner %s\n"), (strcasecmp(str, "none") == 0 ? gettext("not required") : gettext("required"))); str = ""; iter = NULL; (void) papiAttributeListGetString(attrs, &iter, "lpsched-print-wheels", &str); printf(gettext("\tCharacter sets:\n\t\t%s\n"), ((str[0] == '\0') ? gettext("(none)") : str)); if ((str != NULL) && (str[0] != '\0')) while (papiAttributeListGetString(attrs, &iter, NULL, &str) == PAPI_OK) printf("\t\t%s\n", str); printf(gettext("\tDefault pitch:\n")); printf(gettext("\tDefault page size:\n")); printf(gettext("\tDefault port setting:\n")); str = ""; iter = NULL; (void) papiAttributeListGetString(attrs, &iter, "lpsched-options", &str); if (str != NULL) { printf(gettext("\tOptions: %s"), str); while (papiAttributeListGetString(attrs, &iter, NULL, &str) == PAPI_OK) printf(", %s", str); printf("\n"); } } else if (description == 1) { char *str = ""; (void) papiAttributeListGetString(attrs, NULL, "printer-description", &str); printf(gettext("\tDescription: %s\n"), str); } else if (verbose > 1) papiAttributeListPrint(stdout, attrs, "\t"); if (verbose > 0) printf("\n"); return (0); }
static int job_query(char *request, int (*report)(papi_job_t, int, int), papi_encryption_t encryption, int show_rank, int verbose) { int result = 0; papi_status_t status; papi_service_t svc = NULL; char *printer = NULL; int32_t id = -1; get_printer_id(request, &printer, &id); status = papiServiceCreate(&svc, printer, NULL, NULL, cli_auth_callback, encryption, NULL); if (status != PAPI_OK) { fprintf(stderr, gettext( "Failed to contact service for %s: %s\n"), (printer ? printer : "all"), verbose_papi_message(svc, status)); return (-1); } if (printer == NULL) { /* all */ char **interest = interest_list(svc); if (interest != NULL) { int i; for (i = 0; interest[i] != NULL; i++) result += job_query(interest[i], report, encryption, show_rank, verbose); } } else if (id == -1) { /* a printer */ papi_job_t *jobs = NULL; status = papiPrinterListJobs(svc, printer, NULL, 0, 0, &jobs); if (status != PAPI_OK) { fprintf(stderr, gettext( "Failed to get job list: %s\n"), verbose_papi_message(svc, status)); papiServiceDestroy(svc); return (-1); } if (jobs != NULL) { int i; for (i = 0; jobs[i] != NULL; i++) result += report(jobs[i], show_rank, verbose); } papiJobListFree(jobs); } else { /* a job */ papi_job_t job = NULL; status = papiJobQuery(svc, printer, id, NULL, &job); if (status != PAPI_OK) { fprintf(stderr, gettext( "Failed to get job info for %s: %s\n"), request, verbose_papi_message(svc, status)); papiServiceDestroy(svc); return (-1); } if (job != NULL) result = report(job, show_rank, verbose); papiJobFree(job); } papiServiceDestroy(svc); return (result); }
int main(int ac, char *av[]) { int exit_code = 0; char *user = NULL; papi_encryption_t encryption = PAPI_ENCRYPT_NEVER; int c; int32_t rid = -1; int first_dest = 0; (void) setlocale(LC_ALL, ""); (void) textdomain("SUNW_OST_OSCMD"); if (ac == 1) usage(av[0]); while ((c = getopt(ac, av, "Eu:")) != EOF) switch (c) { case 'E': encryption = PAPI_ENCRYPT_REQUIRED; break; case 'u': user = optarg; break; default: usage(av[0]); } for (c = optind; c < ac; c++) { papi_status_t status; papi_service_t svc = NULL; papi_job_t *jobs = NULL; char *printer = NULL; int32_t id = -1; status = papiServiceCreate(&svc, av[c], NULL, NULL, cli_auth_callback, encryption, NULL); if (status != PAPI_OK) { if (first_dest == 0) { (void) get_printer_id(av[c], &printer, &id); status = papiServiceCreate(&svc, printer, NULL, NULL, cli_auth_callback, encryption, NULL); } if (status != PAPI_OK) { fprintf(stderr, gettext( "Failed to contact service for %s: %s\n"), printer, verbose_papi_message(svc, status)); exit(1); } } else { first_dest = 1; printer = av[c]; } #define OUT ((status == PAPI_OK) ? stdout : stderr) if (id != -1) { /* it's a job */ char *mesg = gettext("cancelled"); /* * Check if the job-id is job-id-requested * or job-id. If it is job-id-requested then find * corresponding job-id and send it to cancel */ rid = job_to_be_queried(svc, printer, id); if (rid < 0) { /* * Either it is a remote job which cannot be * cancelled based on job-id or job-id is * not found */ exit_code = 1; fprintf(OUT, "%s-%d: %s\n", printer, id, gettext("not-found")); } else { status = papiJobCancel(svc, printer, rid); if (status == PAPI_NOT_AUTHORIZED) { mesg = papiStatusString(status); exit_code = 1; } else if (status != PAPI_OK) { mesg = gettext( verbose_papi_message( svc, status)); exit_code = 1; } fprintf(OUT, "%s-%d: %s\n", printer, id, mesg); } } else { /* it's a printer */ if (user == NULL) { /* Remove first job from printer */ status = papiPrinterListJobs(svc, printer, NULL, NULL, 0, &jobs); if (status != PAPI_OK) { fprintf(stderr, gettext( "ListJobs %s: %s\n"), printer, verbose_papi_message(svc, status)); exit_code = 1; } if (jobs != NULL && *jobs != NULL) { char *mesg = gettext("cancelled"); id = papiJobGetId(*jobs); status = papiJobCancel(svc, printer, id); if (status == PAPI_NOT_AUTHORIZED) { mesg = papiStatusString(status); exit_code = 1; } else if (status != PAPI_OK) { mesg = gettext( verbose_papi_message( svc, status)); exit_code = 1; } /* * If job-id-requested exists for this * job-id then that should be displayed */ rid = get_job_id_requested(*jobs); if (rid >= 0) fprintf(OUT, "%s-%d: %s\n", printer, rid, mesg); else fprintf(OUT, "%s-%d: %s\n", printer, id, mesg); } papiJobListFree(jobs); } else { /* Purging user's print jobs */ exit_code = cancel_jobs_for_user(user, encryption, printer); } } papiServiceDestroy(svc); } if (optind == ac) exit_code = cancel_jobs_for_user(user, encryption, NULL); return (exit_code); }