Ejemplo n.º 1
0
static int
lpstat_default_printer(papi_encryption_t encryption)
{
	papi_status_t status;
	papi_service_t svc = NULL;
	papi_printer_t p = NULL;
	char *name = NULL;

	status = papiServiceCreate(&svc, NULL, NULL, NULL, cli_auth_callback,
					encryption, NULL);
	if (status == PAPI_OK) {
		char *req[] = { "printer-name", NULL };

		status = papiPrinterQuery(svc, DEFAULT_DEST, req, NULL, &p);
		if (p != NULL)
			name = printer_name(p);
	}
	if (name != NULL)
		printf(gettext("system default printer: %s\n"), name);
	else
		printf(gettext("no system default destination\n"));
	papiPrinterFree(p);
	papiServiceDestroy(svc);

	return (0);
}
Ejemplo n.º 2
0
void
papiPrinterListFree(papi_printer_t *printers)
{
	if (printers != NULL) {
		int i;

		for (i = 0; printers[i] != NULL; i++)
			papiPrinterFree(printers[i]);
		free(printers);
	}
}
Ejemplo n.º 3
0
static char *
get_device_uri(papi_service_t svc, char *name)
{
	papi_status_t status;
	papi_printer_t p = NULL;
	char *keys[] = { "device-uri", NULL };
	char *result = NULL;

	status = papiPrinterQuery(svc, name, keys, NULL, &p);
	if ((status == PAPI_OK) && (p != NULL)) {
		papi_attribute_t **attrs = papiPrinterGetAttributeList(p);

		(void) papiAttributeListGetString(attrs, NULL,
					"device-uri", &result);
		if (result != NULL)
			result = strdup(result);

		papiPrinterFree(p);
	}

	return (result);
}
Ejemplo n.º 4
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);
}