6001 strcat(9f) needs a manpage
[unleashed.git] / usr / src / man / man3papi / papiPrintersList.3papi
blob69d31be0cc4a83fd9ba2440ebe41fc5ee3b9be3d
1 '\" te
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"
7 .SH NAME
8 papiPrintersList, papiPrinterQuery, papiPrinterAdd, papiPrinterModify,
9 papiPrinterRemove, papiPrinterDisable, papiPrinterEnable, papiPrinterPause,
10 papiPrinterResume, papiPrinterPurgeJobs, papiPrinterListJobs,
11 papiPrinterGetAttributeList, papiPrinterFree, papiPrinterListFree \- print
12 object manipulation
13 .SH SYNOPSIS
14 .LP
15 .nf
16 cc [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-lpapi\fR [ \fIlibrary\fR\&.\|.\|. ]
17 #include <papi.h>
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);
22 .fi
24 .LP
25 .nf
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);
29 .fi
31 .LP
32 .nf
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);
35 .fi
37 .LP
38 .nf
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);
41 .fi
43 .LP
44 .nf
45 \fBpapi_status_t\fR \fBpapiPrinterRemove\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR);
46 .fi
48 .LP
49 .nf
50 \fBpapi_status_t\fR \fBpapiPrinterDisable\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR,
51      \fBchar *\fR\fImessage\fR);
52 .fi
54 .LP
55 .nf
56 \fBpapi_status_t\fR \fBpapiPrinterEnable\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR);
57 .fi
59 .LP
60 .nf
61 \fBpapi_status_t\fR \fBpapiPrinterPause\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR,
62      \fBchar *\fR\fImessage\fR);
63 .fi
65 .LP
66 .nf
67 \fBpapi_status_t\fR \fBpapiPrinterResume\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR);
68 .fi
70 .LP
71 .nf
72 \fBpapi_status_t\fR \fBpapiPrinterPurgeJobs\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR,
73      \fBpapi_job_t **\fR\fIjobs\fR);
74 .fi
76 .LP
77 .nf
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);
81 .fi
83 .LP
84 .nf
85 \fBpapi_attribute_t **\fR\fBpapiPrinterGetAttributeList\fR(\fBpapi_printer_t\fR \fIprinter\fR);
86 .fi
88 .LP
89 .nf
90 \fBvoid\fR \fBpapiPrinterFree\fR(\fBpapi_printer_t\fR \fIprinter\fR);
91 .fi
93 .LP
94 .nf
95 \fBvoid\fR \fBpapiPrinterListFree\fR(\fBpapi_printer_t *\fR\fIprinters\fR);
96 .fi
98 .SH PARAMETERS
99 .sp
100 .ne 2
102 \fB\fIattributes\fR\fR
104 .RS 19n
105 a set of attributes to be applied to a printer object
109 .ne 2
111 \fB\fIfilter\fR\fR
113 .RS 19n
114 a filter to be applied during printer enumeration
118 .ne 2
120 \fB\fIhandle\fR\fR
122 .RS 19n
123 a pointer to a handle to be used for all PAPI operations, created by calling
124 \fBpapiServiceCreate()\fR
128 .ne 2
130 \fB\fIjob_attributes\fR\fR
132 .RS 19n
133 unused
137 .ne 2
139 \fB\fIjobs\fR\fR
141 .RS 19n
142 a pointer to a list to return job objects (initialized to \fINULL\fR)
143 enumerated by \fBpapiPrinterGetJobs()\fR
147 .ne 2
149 \fB\fImax_num_jobs\fR\fR
151 .RS 19n
152 the maximum number of jobs to return from a \fBpapiPrinterGetJobs()\fR request
156 .ne 2
158 \fB\fImessage\fR\fR
160 .RS 19n
161 a message to be associated with a printer while disabled or paused
165 .ne 2
167 \fB\fIname\fR\fR
169 .RS 19n
170 the name of the printer object being operated on
174 .ne 2
176 \fB\fIprinter\fR\fR
178 .RS 19n
179 a pointer to a printer object (initialized to \fINULL\fR) to be filled in by
180 \fBpapiPrinterQuery()\fR, \fBpapiPrinterAdd()\fR, and \fBpapiPrinterModify()\fR
184 .ne 2
186 \fB\fIprinters\fR\fR
188 .RS 19n
189 a pointer to a list to return printer objects (initialized to \fINULL\fR)
190 enumerated by \fBpapiPrintersList()\fR
194 .ne 2
196 \fB\fIrequested_attrs\fR\fR
198 .RS 19n
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)
205 .ne 2
207 \fB\fItype_mask\fR\fR
209 .RS 19n
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
212 jobs
214 .ne 2
216 \fB\fBPAPI_LIST_JOBS_COMPLETED\fR\fR
218 .sp .6
219 .RS 4n
220 include completed jobs
224 .ne 2
226 \fB\fBPAPI_LIST_JOBS_NOT_COMPLETED\fR\fR
228 .sp .6
229 .RS 4n
230 include jobs not complete
234 .ne 2
236 \fB\fBPAPI_LIST_JOBS_ALL\fR\fR
238 .sp .6
239 .RS 4n
240 report on all jobs
245 .SH DESCRIPTION
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
273 print queue.
276 The \fBpapiPrinterResume()\fR function resumes queueing of print jobs on the
277 named print queue.
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
287 printer object.
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.
300 .SH RETURN VALUES
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.
310 .SH EXAMPLES
312 \fBExample 1 \fREnumerate all available printers.
314 .in +2
316 #include <stdio.h>
317 #include <stdlib.h>
318 #include <unistd.h>
319 #include <libintl.h>
320 #include <pwd.h>
321 #include <papi.h>
323 static int
324 authCB(papi_service_t svc, void *app_data)
326     char prompt[BUFSIZ];
327     char *user, *svc_name, *passphrase;
329     /* get the name of the service we are contacting */
330     if ((svc_name = papiServiceGetServiceName(svc)) == NULL)
331             return (-1);
333     /* find out who we are supposed to be */
334     if ((user = papiServiceGetUserName(svc)) == NULL) {
335             struct passwd *pw;
337             if ((pw = getpwuid(getuid())) != NULL)
338                     user = pw->pw_name;
339             else
340                     user = "nobody";
341     }
343     /* build the prompt string */
344     snprintf(prompt, sizeof (prompt),
345             gettext("passphrase for %s to access %s: "), user,
346                    svc_name);
348     /* ask for the passphrase */
349     if ((passphrase = getpassphrase(prompt)) != NULL)
350             papiServiceSetPassword(svc, passphrase);
352     return (0);
355 /*ARGSUSED*/
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;
364     int c;
366     while ((c = getopt(ac, av, "s:")) != EOF)
367         switch (c) {
368         case 's':
369             svc_name = optarg;
370             break;
371         }
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);
380         exit(1);
381     }
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);
388         exit(1);
389     }
391     if (printers != NULL) {
392         int i;
394         for (i = 0; printers[i] != NULL; i++) {
395             papi_attribute_t **list =
396                 papiPrinterGetAttributeList(printers[i]);
398             if (list != NULL) {
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);
408             }
409         }
410         papiPrinterListFree(printers);
411     }
413     papiServiceDestroy(svc);
415     exit(0);
418 .in -2
421 \fBExample 2 \fRDump all printer attributes.
423 .in +2
426  * program to query a printer for it's attributes via PAPI
427  */
428 #include <stdio.h>
429 #include <stdlib.h>
430 #include <unistd.h>
431 #include <libintl.h>
432 #include <pwd.h>
433 #include <papi.h>
435 static int
436 authCB(papi_service_t svc, void *app_data)
438     char prompt[BUFSIZ];
439     char *user, *svc_name, *passphrase;
441     /* get the name of the service we are contacting */
442     if ((svc_name = papiServiceGetServiceName(svc)) == NULL)
443             return (-1);
445     /* find out who we are supposed to be */
446     if ((user = papiServiceGetUserName(svc)) == NULL) {
447             struct passwd *pw;
449             if ((pw = getpwuid(getuid())) != NULL)
450                     user = pw->pw_name;
451             else
452                     user = "nobody";
453     }
455     /* build the prompt string */
456     snprintf(prompt, sizeof (prompt),
457             gettext("passphrase for %s to access %s: "), user,
458                     svc_name);
460     /* ask for the passphrase */
461     if ((passphrase = getpassphrase(prompt)) != NULL)
462             papiServiceSetPassword(svc, passphrase);
464     return (0);
467 /*ARGSUSED*/
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";
476     int c;
478     while ((c = getopt(ac, av, "s:p:")) != EOF)
479         switch (c) {
480         case 's':
481             svc_name = optarg;
482             break;
483         case 'p':
484             pname = optarg;
485             break;
486         }
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);
495         exit(1);
496     }
498     status = papiPrinterQuery(svc, pname, NULL, NULL, &printer);
499     if ((status == PAPI_OK) && (printer != NULL)) {
500         papi_attribute_t **list = papiPrinterGetAttributeList(printer);
501         char *buffer = NULL;
502         size_t size = 0;
504         while (papiAttributeListToString(list, "\en\et", buffer, size)
505                     != PAPI_OK)
506             buffer = realloc(buffer, size += BUFSIZ);
508         printf("%s:\en\et%s\en", pname, buffer);
509     } else
510         printf("papiPrinterQuery(%s): %s\en", pname,
511                     papiStatusString(status));
513     papiPrinterFree(printer);
514     papiServiceDestroy(svc);
516     exit(0);
519 .in -2
521 .SH ATTRIBUTES
524 See \fBattributes\fR(5) for descriptions of the following attributes:
529 box;
530 c | c
531 l | l .
532 ATTRIBUTE TYPE  ATTRIBUTE VALUE
534 Interface Stability     Volatile
536 MT-Level        Safe
539 .SH SEE ALSO
542 \fBlibpapi\fR(3LIB), \fBattributes\fR(5)