8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / print / libpapi-lpd / common / printer.c
blob308d9c9443f31544e30a5f597f80d08647e3959d
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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 $ */
30 #include <stdlib.h>
31 #include <strings.h>
32 #include <papi_impl.h>
33 #include <libintl.h>
35 static int
36 contains(char *value, char **list)
38 int i;
40 if ((value == NULL) || (list == NULL))
41 return (1);
43 for (i = 0; list[i] != NULL; i++)
44 if (strcasecmp(value, list[i]) == 0)
45 return (1);
47 return (0);
50 papi_status_t
51 papiPrinterQuery(papi_service_t handle, char *name,
52 char **requested_attrs,
53 papi_attribute_t **job_attributes,
54 papi_printer_t *printer)
56 papi_status_t status;
57 service_t *svc = handle;
58 printer_t *p = NULL;
60 if ((svc == NULL) || (name == NULL) || (printer == NULL))
61 return (PAPI_BAD_ARGUMENT);
63 if ((status = service_fill_in(svc, name)) == PAPI_OK) {
64 *printer = NULL;
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)) {
72 char buf[BUFSIZ];
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),
82 PAPI_ATTR_APPEND,
83 "printer-uri-supported", buf);
85 /* Set printer accepting: mimic prepapi behavior */
86 if ((p = *printer) != NULL)
87 papiAttributeListAddBoolean(&(p->attributes),
88 PAPI_ATTR_REPLACE,
89 "printer-is-accepting-jobs", PAPI_TRUE);
93 return (status);
96 papi_status_t
97 papiPrinterPurgeJobs(papi_service_t handle, char *name, papi_job_t **jobs)
99 papi_status_t status;
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);
108 return (status);
111 papi_status_t
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);
125 return (status);
128 papi_attribute_t **
129 papiPrinterGetAttributeList(papi_printer_t printer)
131 printer_t *p = printer;
133 if (p == NULL)
134 return (NULL);
136 return (p->attributes);
139 void
140 papiPrinterFree(papi_printer_t printer)
142 printer_t *p = printer;
144 if (p != NULL) {
145 if (p->attributes != NULL)
146 papiAttributeListFree(p->attributes);
147 free(p);
151 void
152 papiPrinterListFree(papi_printer_t *printers)
154 if (printers != NULL) {
155 int i;
157 for (i = 0; printers[i] != NULL; i++)
158 papiPrinterFree(printers[i]);
159 free(printers);
164 papi_status_t
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) {
171 detailed_error(svc,
172 gettext("Warning: %s is remote, disable has no meaning."),
173 queue_name_from_uri(svc->uri));
175 return (PAPI_OPERATION_NOT_SUPPORTED);
178 papi_status_t
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) {
185 detailed_error(svc,
186 gettext("Warning: %s is remote, enable has no meaning."),
187 queue_name_from_uri(svc->uri));
189 return (PAPI_OPERATION_NOT_SUPPORTED);
193 papi_status_t
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) {
200 detailed_error(svc,
201 gettext("Warning: %s is remote, accept has no meaning."),
202 queue_name_from_uri(svc->uri));
204 return (PAPI_OPERATION_NOT_SUPPORTED);
208 papi_status_t
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) {
215 detailed_error(svc,
216 gettext("Warning: %s is remote, reject has no meaning."),
217 queue_name_from_uri(svc->uri));
219 return (PAPI_OPERATION_NOT_SUPPORTED);