Пример #1
0
papi_status_t
ipp_cancel_job(papi_service_t svc, papi_attribute_t **request,
		papi_attribute_t ***response)
{
	papi_status_t status;
	papi_attribute_t **operational = NULL;

	char *message = NULL;
	char *queue = NULL;
	int id = -1;

	/* Get operational attributes from the request */
	(void) papiAttributeListGetCollection(request, NULL,
				"operational-attributes-group", &operational);

	/*
	 * the operational-attributes-group must contain:
	 *	job-uri (or printer-uri/job-id)
	 */
	get_printer_id(operational, &queue, &id);
	if (id < 0) {
		ipp_set_status(response, PAPI_BAD_REQUEST,
				"missing job-uri or job-id");
		return (PAPI_BAD_REQUEST);
	} else if (queue == NULL) {
		ipp_set_status(response, PAPI_BAD_REQUEST,
				"missing printer-uri or job-uri");
		return (PAPI_BAD_REQUEST);
	}

	/*
	 * the operational-attributes-group may contain:
	 *	message
	 */
	(void) papiAttributeListGetString(operational, NULL,
				"message", &message);

	status = papiJobCancel(svc, queue, id);
	if (status != PAPI_OK) {
		ipp_set_status(response, status,
				"cancel failed: %s-%d: %s",
				(queue ? queue : "(null)"), id,
				ipp_svc_status_mesg(svc, status));
	} else if (message != NULL) {	/* add unsupported attribute group */
		papi_attribute_t **unsupported = NULL;

		papiAttributeListAddValue(&unsupported, PAPI_ATTR_EXCL,
					"message", PAPI_COLLECTION, NULL);
		(void) papiAttributeListAddCollection(response,
			PAPI_ATTR_REPLACE, "unsupported-attributes-group",
			unsupported);
		papiAttributeListFree(unsupported);

		status = PAPI_OK_SUBST;
		ipp_set_status(response, status,
			"unsupported attribute in request");
	}

	return (status);
}
Пример #2
0
papi_status_t
papiJobValidate(papi_service_t handle, char *printer,
		papi_attribute_t **job_attributes,
		papi_job_ticket_t *job_ticket,
		char **files, papi_job_t *job)
{
	papi_status_t status;
	papi_attribute_t **attributes = NULL;
	int i;

	papiAttributeListAddString(&attributes, PAPI_ATTR_REPLACE,
	    "job-hold-until", "indefinite");
	for (i = 0; job_attributes[i]; i++)
		list_append(&attributes, job_attributes[i]);

	status = papiJobSubmitByReference(handle, printer,
	    (papi_attribute_t **)attributes,
	    job_ticket, files, job);
	if (status == PAPI_OK) {
		int id = papiJobGetId(*job);

		if (id != -1)
			papiJobCancel(handle, printer, id);
	}

	attributes[1] = NULL;	/* after attr[0], they are in another list */
	papiAttributeListFree(attributes);

	return (status);
}
Пример #3
0
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);
}