4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 /* $Id: printer.c 149 2006-04-25 16:55:01Z njacobs $ */
32 #include <papi_impl.h>
36 contains(char *value
, char **list
)
40 if ((value
== NULL
) || (list
== NULL
))
43 for (i
= 0; list
[i
] != NULL
; i
++)
44 if (strcasecmp(value
, list
[i
]) == 0)
51 papiPrinterQuery(papi_service_t handle
, char *name
,
52 char **requested_attrs
,
53 papi_attribute_t
**job_attributes
,
54 papi_printer_t
*printer
)
57 service_t
*svc
= handle
;
60 if ((svc
== NULL
) || (name
== NULL
) || (printer
== NULL
))
61 return (PAPI_BAD_ARGUMENT
);
63 if ((status
= service_fill_in(svc
, name
)) == PAPI_OK
) {
66 if ((contains("printer-state", requested_attrs
) == 1) ||
67 (contains("printer-state-reasons", requested_attrs
) == 1))
68 status
= lpd_find_printer_info(svc
,
69 (printer_t
**)printer
);
71 if ((status
== PAPI_OK
) && (*printer
== NULL
)) {
74 *printer
= p
= calloc(1, sizeof (*p
));
76 papiAttributeListAddString(&(p
->attributes
),
77 PAPI_ATTR_APPEND
, "printer-name",
78 queue_name_from_uri(svc
->uri
));
80 if (uri_to_string(svc
->uri
, buf
, sizeof (buf
)) == 0)
81 papiAttributeListAddString(&(p
->attributes
),
83 "printer-uri-supported", buf
);
85 /* Set printer accepting: mimic prepapi behavior */
86 if ((p
= *printer
) != NULL
)
87 papiAttributeListAddBoolean(&(p
->attributes
),
89 "printer-is-accepting-jobs", PAPI_TRUE
);
97 papiPrinterPurgeJobs(papi_service_t handle
, char *name
, papi_job_t
**jobs
)
100 service_t
*svc
= handle
;
102 if ((svc
== NULL
) || (name
== NULL
))
103 return (PAPI_BAD_ARGUMENT
);
105 if ((status
= service_fill_in(svc
, name
)) == PAPI_OK
)
106 status
= lpd_purge_jobs(svc
, (job_t
***)jobs
);
112 papiPrinterListJobs(papi_service_t handle
, char *name
,
113 char **requested_attrs
, int type_mask
,
114 int max_num_jobs
, papi_job_t
**jobs
)
116 papi_status_t status
;
117 service_t
*svc
= handle
;
119 if ((svc
== NULL
) || (name
== NULL
) || (jobs
== NULL
))
120 return (PAPI_BAD_ARGUMENT
);
122 if ((status
= service_fill_in(svc
, name
)) == PAPI_OK
)
123 status
= lpd_find_jobs_info(svc
, (job_t
***)jobs
);
129 papiPrinterGetAttributeList(papi_printer_t printer
)
131 printer_t
*p
= printer
;
136 return (p
->attributes
);
140 papiPrinterFree(papi_printer_t printer
)
142 printer_t
*p
= printer
;
145 if (p
->attributes
!= NULL
)
146 papiAttributeListFree(p
->attributes
);
152 papiPrinterListFree(papi_printer_t
*printers
)
154 if (printers
!= NULL
) {
157 for (i
= 0; printers
[i
] != NULL
; i
++)
158 papiPrinterFree(printers
[i
]);
165 papiPrinterDisable(papi_service_t handle
, char *name
, char *message
)
167 service_t
*svc
= handle
;
168 papi_status_t status
;
170 if ((status
= service_fill_in(svc
, name
)) == PAPI_OK
) {
172 gettext("Warning: %s is remote, disable has no meaning."),
173 queue_name_from_uri(svc
->uri
));
175 return (PAPI_OPERATION_NOT_SUPPORTED
);
179 papiPrinterEnable(papi_service_t handle
, char *name
)
181 service_t
*svc
= handle
;
182 papi_status_t status
;
184 if ((status
= service_fill_in(svc
, name
)) == PAPI_OK
) {
186 gettext("Warning: %s is remote, enable has no meaning."),
187 queue_name_from_uri(svc
->uri
));
189 return (PAPI_OPERATION_NOT_SUPPORTED
);
194 papiPrinterResume(papi_service_t handle
, char *name
)
196 service_t
*svc
= handle
;
197 papi_status_t status
;
199 if ((status
= service_fill_in(svc
, name
)) == PAPI_OK
) {
201 gettext("Warning: %s is remote, accept has no meaning."),
202 queue_name_from_uri(svc
->uri
));
204 return (PAPI_OPERATION_NOT_SUPPORTED
);
209 papiPrinterPause(papi_service_t handle
, char *name
, char *message
)
211 service_t
*svc
= handle
;
212 papi_status_t status
;
214 if ((status
= service_fill_in(svc
, name
)) == PAPI_OK
) {
216 gettext("Warning: %s is remote, reject has no meaning."),
217 queue_name_from_uri(svc
->uri
));
219 return (PAPI_OPERATION_NOT_SUPPORTED
);