2 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH PAPIPRINTERSLIST 3PAPI "Sep 10, 2013"
8 papiPrintersList, papiPrinterQuery, papiPrinterAdd, papiPrinterModify,
9 papiPrinterRemove, papiPrinterDisable, papiPrinterEnable, papiPrinterPause,
10 papiPrinterResume, papiPrinterPurgeJobs, papiPrinterListJobs,
11 papiPrinterGetAttributeList, papiPrinterFree, papiPrinterListFree \- print
16 cc [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-lpapi\fR [ \fIlibrary\fR\&.\|.\|. ]
19 \fBpapi_status_t\fR \fBpapiPrintersList\fR(\fBpapi_service_t\fR \fIhandle\fR,
20 \fBchar **\fR\fIrequested_attrs\fR, \fBpapi_filter_t *\fR\fIfilter\fR,
21 \fBpapi_printer_t **\fR\fIprinters\fR);
26 \fBpapi_status_t\fR \fBpapiPrinterQuery\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR,
27 \fBchar **\fR\fIrequested_attrs\fR, \fBpapi_attribute_t **\fR\fIjob_attributes\fR,
28 \fBpapi_printer_t *\fR\fIprinter\fR);
33 \fBpapi_status_t\fR \fBpapiPrinterAdd\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR,
34 \fBpapi_attribute_t **\fR\fIattributes\fR, \fBpapi_printer_t *\fR\fIprinter\fR);
39 \fBpapi_status_t\fR \fBpapiPrinterModify\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR,
40 \fBpapi_attribute_t **\fR\fIattributes\fR, \fBpapi_printer_t *\fR\fIprinter\fR);
45 \fBpapi_status_t\fR \fBpapiPrinterRemove\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR);
50 \fBpapi_status_t\fR \fBpapiPrinterDisable\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR,
51 \fBchar *\fR\fImessage\fR);
56 \fBpapi_status_t\fR \fBpapiPrinterEnable\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR);
61 \fBpapi_status_t\fR \fBpapiPrinterPause\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR,
62 \fBchar *\fR\fImessage\fR);
67 \fBpapi_status_t\fR \fBpapiPrinterResume\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR);
72 \fBpapi_status_t\fR \fBpapiPrinterPurgeJobs\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR,
73 \fBpapi_job_t **\fR\fIjobs\fR);
78 \fBpapi_status_t\fR \fBpapiPrinterListJobs\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR,
79 \fBchar **\fR\fIrequested_attrs\fR, \fBint\fR \fItype_mask\fR, \fBint\fR \fImax_num_jobs\fR,
80 \fBpapi_job_t **\fR\fIjobs\fR);
85 \fBpapi_attribute_t **\fR\fBpapiPrinterGetAttributeList\fR(\fBpapi_printer_t\fR \fIprinter\fR);
90 \fBvoid\fR \fBpapiPrinterFree\fR(\fBpapi_printer_t\fR \fIprinter\fR);
95 \fBvoid\fR \fBpapiPrinterListFree\fR(\fBpapi_printer_t *\fR\fIprinters\fR);
102 \fB\fIattributes\fR\fR
105 a set of attributes to be applied to a printer object
114 a filter to be applied during printer enumeration
123 a pointer to a handle to be used for all PAPI operations, created by calling
124 \fBpapiServiceCreate()\fR
130 \fB\fIjob_attributes\fR\fR
142 a pointer to a list to return job objects (initialized to \fINULL\fR)
143 enumerated by \fBpapiPrinterGetJobs()\fR
149 \fB\fImax_num_jobs\fR\fR
152 the maximum number of jobs to return from a \fBpapiPrinterGetJobs()\fR request
161 a message to be associated with a printer while disabled or paused
170 the name of the printer object being operated on
179 a pointer to a printer object (initialized to \fINULL\fR) to be filled in by
180 \fBpapiPrinterQuery()\fR, \fBpapiPrinterAdd()\fR, and \fBpapiPrinterModify()\fR
189 a pointer to a list to return printer objects (initialized to \fINULL\fR)
190 enumerated by \fBpapiPrintersList()\fR
196 \fB\fIrequested_attrs\fR\fR
199 a null-terminated array of pointers to attribute names requested during printer
200 enumeration (\fBpapiPrintersList()\fR), printer query
201 (\fBpapiPrinterQuery()\fR), or job enumeration (\fBpapiPrinterListJobs()\fR)
207 \fB\fItype_mask\fR\fR
210 a bit field indicating which type of jobs to return \fBPAPI_LIST_JOBS_OTHERS\fR
211 include jobs submitted by others. The default is to report only on your own
216 \fB\fBPAPI_LIST_JOBS_COMPLETED\fR\fR
220 include completed jobs
226 \fB\fBPAPI_LIST_JOBS_NOT_COMPLETED\fR\fR
230 include jobs not complete
236 \fB\fBPAPI_LIST_JOBS_ALL\fR\fR
248 The \fBpapiPrintersList()\fR function retrieves the requested attributes from
249 the print service(s) for all available printers. Because the Solaris
250 implementation is name service-enabled, applications should retrieve only the
251 \fBprinter-name\fR and \fBprinter-uri-supported\fR attributes using this
252 function, thereby reducing the overhead involved in generating a printer list.
253 Further integration of printer state and capabilities can be performed with
254 \fBpapiPrinterQuery()\fR.
257 The \fBpapiPrinterAdd()\fR, \fBpapiPrinterModify()\fR, and
258 \fBpapiPrinterRemove()\fR functions allow for creation, modification, and
259 removal of print queues. Print queues are added or modified according to the
260 attribute list passed into the call. A printer object is returned that reflects
261 the configuration of the printer after the addition or modification has been
262 applied. At this time, they provide only minimal functionality and only for
263 the LP print service.
266 The \fBpapiPrinterDisable()\fR and \fBpapiPrinterEnable()\fR functions allow
267 applications to turn off and on queueing (accepting print requests) for a print
268 queue. The \fBpapiPrinterEnable()\fR and \fBpapiPrinterDisable()\fR functions
269 allow applications to turn on and off print job processing for a print queue.
272 The \fBpapiPrinterPause()\fR function stops queueing of print jobs on the named
276 The \fBpapiPrinterResume()\fR function resumes queueing of print jobs on the
280 The \fBpapiPrinterPurgeJobs()\fR function allows applications to delete all
281 print jobs that it has privilege to remove. A list of cancelled jobs is
282 returned in the jobs argument.
285 The \fBpapiPrinterListJobs()\fR function enumerates print jobs on a particular
286 queue. \fBpapiPrinterGetAttributeList()\fR retrieves an attribute list from a
290 The \fBpapiPrinterGetAttributeList()\fR function retrieves an attribute list
291 from a printer object returned from \fBpapiPrinterQuery()\fR,
292 \fBpapiPrintersList()\fR, \fBpapiPrinterModify()\fR, and
293 \fBpapiPrinterAdd()\fR. This attribute list can be searched for various
294 information about the printer object.
297 The \fBpapiPrinterFree()\fR and \fBpapiPrinterListFree()\fR functions
298 deallocate memory allocated for the return of printer object(s) from functions
299 that return printer objects.
303 Upon successful completion, all functions that return a value return
304 \fBPAPI_OK\fR. Otherwise, they return an appropriate \fBpapi_status_t()\fR
305 indicating the type of failure.
308 Upon successful completion, \fBpapiPrinterGetAttributeList()\fR returns a
309 pointer to the requested data. Otherwise, it returns \fINULL\fR.
312 \fBExample 1 \fREnumerate all available printers.
324 authCB(papi_service_t svc, void *app_data)
327 char *user, *svc_name, *passphrase;
329 /* get the name of the service we are contacting */
330 if ((svc_name = papiServiceGetServiceName(svc)) == NULL)
333 /* find out who we are supposed to be */
334 if ((user = papiServiceGetUserName(svc)) == NULL) {
337 if ((pw = getpwuid(getuid())) != NULL)
343 /* build the prompt string */
344 snprintf(prompt, sizeof (prompt),
345 gettext("passphrase for %s to access %s: "), user,
348 /* ask for the passphrase */
349 if ((passphrase = getpassphrase(prompt)) != NULL)
350 papiServiceSetPassword(svc, passphrase);
357 main(int ac, char *av[])
359 papi_status_t status;
360 papi_service_t svc = NULL;
361 papi_printer_t *printers = NULL;
362 char *attrs[] = { "printer-name", "printer-uri-supported", NULL };
363 char *svc_name = NULL;
366 while ((c = getopt(ac, av, "s:")) != EOF)
373 status = papiServiceCreate(&svc, svc_name, NULL, NULL, authCB,
374 PAPI_ENCRYPT_NEVER, NULL);
376 if (status != PAPI_OK) {
377 printf("papiServiceCreate(%s): %s\en", svc_name ? svc_name :
378 "NULL", papiStatusString(status));
379 papiServiceDestroy(svc);
383 status = papiPrintersList(svc, attrs, NULL, &printers);
384 if (status != PAPI_OK) {
385 printf("papiPrintersList(%s): %s\en", svc_name ? svc_name :
386 "NULL", papiStatusString(status));
387 papiServiceDestroy(svc);
391 if (printers != NULL) {
394 for (i = 0; printers[i] != NULL; i++) {
395 papi_attribute_t **list =
396 papiPrinterGetAttributeList(printers[i]);
399 char *name = "unknown";
400 char *uri = "unknown";
402 (void) papiAttributeListGetString(list, NULL,
403 "printer-name", &name);
405 (void) papiAttributeListGetString(list, NULL,
406 "printer-uri-supported", &uri);
407 printf("%s is %s\en", name, uri);
410 papiPrinterListFree(printers);
413 papiServiceDestroy(svc);
421 \fBExample 2 \fRDump all printer attributes.
426 * program to query a printer for it's attributes via PAPI
436 authCB(papi_service_t svc, void *app_data)
439 char *user, *svc_name, *passphrase;
441 /* get the name of the service we are contacting */
442 if ((svc_name = papiServiceGetServiceName(svc)) == NULL)
445 /* find out who we are supposed to be */
446 if ((user = papiServiceGetUserName(svc)) == NULL) {
449 if ((pw = getpwuid(getuid())) != NULL)
455 /* build the prompt string */
456 snprintf(prompt, sizeof (prompt),
457 gettext("passphrase for %s to access %s: "), user,
460 /* ask for the passphrase */
461 if ((passphrase = getpassphrase(prompt)) != NULL)
462 papiServiceSetPassword(svc, passphrase);
469 main(int ac, char *av[])
471 papi_status_t status;
472 papi_service_t svc = NULL;
473 papi_printer_t printer = NULL;
474 char *svc_name = NULL;
475 char *pname = "unknown";
478 while ((c = getopt(ac, av, "s:p:")) != EOF)
488 status = papiServiceCreate(&svc, svc_name, NULL, NULL, authCB,
489 PAPI_ENCRYPT_NEVER, NULL);
491 if (status != PAPI_OK) {
492 printf("papiServiceCreate(%s): %s\en", svc_name ? svc_name :
493 "NULL", papiStatusString(status));
494 papiServiceDestroy(svc);
498 status = papiPrinterQuery(svc, pname, NULL, NULL, &printer);
499 if ((status == PAPI_OK) && (printer != NULL)) {
500 papi_attribute_t **list = papiPrinterGetAttributeList(printer);
504 while (papiAttributeListToString(list, "\en\et", buffer, size)
506 buffer = realloc(buffer, size += BUFSIZ);
508 printf("%s:\en\et%s\en", pname, buffer);
510 printf("papiPrinterQuery(%s): %s\en", pname,
511 papiStatusString(status));
513 papiPrinterFree(printer);
514 papiServiceDestroy(svc);
524 See \fBattributes\fR(5) for descriptions of the following attributes:
532 ATTRIBUTE TYPE ATTRIBUTE VALUE
534 Interface Stability Volatile
542 \fBlibpapi\fR(3LIB), \fBattributes\fR(5)