Beispiel #1
0
int
cancel_jobs_for_user(char *user, papi_encryption_t encryption, char *pname) {

	papi_status_t status;
	papi_service_t svc = NULL;
	char **printers = NULL;
	int i, exit_code;

	if (pname == NULL) {
		status = papiServiceCreate(&svc, NULL, NULL, NULL,
		    cli_auth_callback, encryption, NULL);
		printers = interest_list(svc);
		papiServiceDestroy(svc);
	} else {
		list_append(&printers, strdup(pname));
	}

	if (printers == NULL)
		exit(0);

	for (i = 0; printers[i] != NULL; i++) {
		char *printer = printers[i];

		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);
		}
		exit_code = berkeley_cancel_request(svc, stdout, printer, 1,
		    &user);

		papiServiceDestroy(svc);
		if (exit_code != 0)
			break;
	}
	free(printers);
	return (exit_code);
}
Beispiel #2
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);
}
Beispiel #3
0
static int
printer_query(char *name, int (*report)(papi_service_t, char *, papi_printer_t,
					int, int), papi_encryption_t encryption,
		int verbose, int description)
{
	int result = 0;
	papi_status_t status;
	papi_service_t svc = NULL;

	status = papiServiceCreate(&svc, name, NULL, NULL, cli_auth_callback,
					encryption, NULL);
	if (status != PAPI_OK) {
		fprintf(stderr, gettext(
			"Failed to contact service for %s: %s\n"),
			name ? name : "(NULL)",
			verbose_papi_message(svc, status));
		papiServiceDestroy(svc);
		return (-1);
	}

	if (name == NULL) { /* all */
		char **interest = interest_list(svc);

		if (interest != NULL) {
			int i;

			for (i = 0; interest[i] != NULL; i++)
				result += printer_query(interest[i], report,
							encryption, verbose,
							description);
		}
	} else {
		papi_printer_t printer = NULL;
		char **keys = NULL;

		/*
		 * Limit the query to only required data to reduce the need
		 * to go remote for information.
		 */
		if (report == report_device)
			keys = report_device_keys;
		else if (report == report_class)
			keys = report_class_keys;
		else if (report == report_accepting)
			keys = report_accepting_keys;
		else if ((report == report_printer) && (verbose == 0))
			keys = report_printer_keys;

		status = papiPrinterQuery(svc, name, keys, NULL, &printer);
		if (status != PAPI_OK) {
			fprintf(stderr, gettext(
				"Failed to get printer info for %s: %s\n"),
				name, verbose_papi_message(svc, status));
			papiServiceDestroy(svc);
			return (-1);
		}

		if (printer != NULL)
			result = report(svc, name, printer, verbose,
					description);

		papiPrinterFree(printer);
	}

	papiServiceDestroy(svc);

	return (result);
}