xref: /illumos-gate/usr/src/lib/print/libpapi-common/common/papi.h (revision fc910014e8a32a65612105835a10995f2c13d942)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  */
27 
28 #ifndef _PAPI_H
29 #define	_PAPI_H
30 
31 /* $Id: papi.h 161 2006-05-03 04:32:59Z njacobs $ */
32 
33 #include <sys/types.h>
34 #include <time.h>
35 #include <stdio.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /*
42  * Types
43  */
44 
45 /*	service related types	*/
46 typedef void *papi_service_t;
47 typedef void *papi_printer_t;
48 typedef void *papi_job_t;
49 typedef void *papi_stream_t;
50 
51 typedef enum {
52 	PAPI_ENCRYPT_IF_REQUESTED,	/* Encrypt if requested (TLS upgrade) */
53 	PAPI_ENCRYPT_NEVER,		/* Never encrypt */
54 	PAPI_ENCRYPT_REQUIRED,		/* Encryption required (TLS upgrade) */
55 	PAPI_ENCRYPT_ALWAYS		/* Always encrypt (SSL) */
56 } papi_encryption_t;
57 
58 /*	attribute related types	*/
59 typedef enum {
60 	PAPI_STRING,
61 	PAPI_INTEGER,
62 	PAPI_BOOLEAN,
63 	PAPI_RANGE,
64 	PAPI_RESOLUTION,
65 	PAPI_DATETIME,
66 	PAPI_COLLECTION,
67 	PAPI_METADATA
68 } papi_attribute_value_type_t;
69 
70 typedef enum {
71 	PAPI_RES_PER_INCH = 3,
72 	PAPI_RES_PER_CM
73 } papi_resolution_unit_t;
74 
75 enum {	/* for boolean values */
76 	PAPI_FALSE = 0,
77 	PAPI_TRUE = 1
78 };
79 
80 typedef enum {
81 	PAPI_UNSUPPORTED = 0x10,
82 	PAPI_DEFAULT = 0x11,
83 	PAPI_UNKNOWN,
84 	PAPI_NO_VALUE,
85 	PAPI_NOT_SETTABLE = 0x15,
86 	PAPI_DELETE = 0x16
87 } papi_metadata_t;
88 
89 #define	PAPI_LIST_JOBS_OTHERS		0x0001
90 #define	PAPI_LIST_JOBS_COMPLETED	0x0002
91 #define	PAPI_LIST_JOBS_NOT_COMPLETED	0x0004
92 #define	PAPI_LIST_JOBS_ALL		0xFFFF
93 
94 typedef struct papi_attribute_s papi_attribute_t;
95 
96 typedef union {
97 	char *string;				/* PAPI_STRING value */
98 	int integer;				/* PAPI_INTEGER value */
99 	char boolean;				/* PAPI_BOOLEAN value */
100 	struct {				/* PAPI_RANGE value */
101 		int lower;
102 		int upper;
103 	} range;
104 	struct {				/* PAPI_RESOLUTION value */
105 		int xres;
106 		int yres;
107 		papi_resolution_unit_t units;
108 	} resolution;
109 	time_t datetime;			/* PAPI_DATETIME value */
110 	papi_attribute_t **collection;		/* PAPI_COLLECTION value */
111 	papi_metadata_t metadata;		/* PAPI_METADATA value */
112 } papi_attribute_value_t;
113 
114 struct papi_attribute_s {
115 	char *name;				/* attribute name */
116 	papi_attribute_value_type_t type;	/* type of values */
117 	papi_attribute_value_t **values;	/* list of values */
118 };
119 
120 #define	PAPI_ATTR_APPEND	0x0001	/* Add values to attr */
121 #define	PAPI_ATTR_REPLACE	0x0002	/* Delete existing values, then add */
122 #define	PAPI_ATTR_EXCL		0x0004	/* Fail if attr exists */
123 
124 /*	job related types	*/
125 typedef enum {
126 	PAPI_JT_FORMAT_JDF = 0,
127 	PAPI_JT_FORMAT_PWG = 1
128 } papi_jt_format_t;
129 
130 typedef struct {
131 	papi_jt_format_t format;
132 	char *ticket_data;
133 	char *file_name;
134 } papi_job_ticket_t;
135 
136 /*	status related types	*/
137 typedef enum {
138 	PAPI_OK = 0x0000,
139 	PAPI_OK_SUBST,
140 	PAPI_OK_CONFLICT,
141 	PAPI_OK_IGNORED_SUBSCRIPTIONS,
142 	PAPI_OK_IGNORED_NOTIFICATIONS,
143 	PAPI_OK_TOO_MANY_EVENTS,
144 	PAPI_OK_BUT_CANCEL_SUBSCRIPTION,
145 	PAPI_REDIRECTION_OTHER_SITE = 0x0300,
146 	PAPI_BAD_REQUEST = 0x0400,
147 	PAPI_FORBIDDEN,
148 	PAPI_NOT_AUTHENTICATED,
149 	PAPI_NOT_AUTHORIZED,
150 	PAPI_NOT_POSSIBLE,
151 	PAPI_TIMEOUT,
152 	PAPI_NOT_FOUND,
153 	PAPI_GONE,
154 	PAPI_REQUEST_ENTITY,
155 	PAPI_REQUEST_VALUE,
156 	PAPI_DOCUMENT_FORMAT,
157 	PAPI_ATTRIBUTES,
158 	PAPI_URI_SCHEME,
159 	PAPI_CHARSET,
160 	PAPI_CONFLICT,
161 	PAPI_COMPRESSION_NOT_SUPPORTED,
162 	PAPI_COMPRESSION_ERROR,
163 	PAPI_DOCUMENT_FORMAT_ERROR,
164 	PAPI_DOCUMENT_ACCESS_ERROR,
165 	PAPI_ATTRIBUTES_NOT_SETTABLE,
166 	PAPI_IGNORED_ALL_SUBSCRIPTIONS,
167 	PAPI_TOO_MANY_SUBSCRIPTIONS,
168 	PAPI_IGNORED_ALL_NOTIFICATIONS,
169 	PAPI_PRINT_SUPPORT_FILE_NOT_FOUND,
170 	PAPI_INTERNAL_ERROR = 0x0500,
171 	PAPI_OPERATION_NOT_SUPPORTED,
172 	PAPI_SERVICE_UNAVAILABLE,
173 	PAPI_VERSION_NOT_SUPPORTED,
174 	PAPI_DEVICE_ERROR,
175 	PAPI_TEMPORARY_ERROR,
176 	PAPI_NOT_ACCEPTING,
177 	PAPI_PRINTER_BUSY,
178 	PAPI_ERROR_JOB_CANCELLED,
179 	PAPI_MULTIPLE_JOBS_NOT_SUPPORTED,
180 	PAPI_PRINTER_IS_DEACTIVATED,
181 	PAPI_BAD_ARGUMENT,
182 	PAPI_JOB_TICKET_NOT_SUPPORTED
183 } papi_status_t;
184 
185 /*	list filter related	*/
186 typedef enum {
187 	PAPI_FILTER_BITMASK = 0
188 } papi_filter_type_t;
189 
190 typedef struct {
191 	papi_filter_type_t type;
192 	union {
193 		struct {			/* PAPI_FILTER_BITMASK */
194 			unsigned int mask;
195 			unsigned int value;
196 		} bitmask;
197 	} filter;
198 } papi_filter_t;
199 
200 enum {
201 	PAPI_PRINTER_LOCAL = 0x0000,	/* Local destination */
202 	PAPI_PRINTER_CLASS = 0x0001,	/* Printer class */
203 	PAPI_PRINTER_REMOTE = 0x0002,	/* Remote destination */
204 	PAPI_PRINTER_BW = 0x0004,	/* Can do B&W printing */
205 	PAPI_PRINTER_COLOR = 0x0008,	/* Can do color printing */
206 	PAPI_PRINTER_DUPLEX = 0x0010,	/* Can do duplex printing */
207 	PAPI_PRINTER_STAPLE = 0x0020,	/* Can do stapling */
208 	PAPI_PRINTER_COPIES = 0x0040,	/* Can do copies */
209 	PAPI_PRINTER_COLLATE = 0x0080,	/* Can collate copies */
210 	PAPI_PRINTER_PUNCH = 0x0100,	/* Can punch output */
211 	PAPI_PRINTER_COVER = 0x0200,	/* Can cover output */
212 	PAPI_PRINTER_BIND = 0x0400,	/* Can bind output */
213 	PAPI_PRINTER_SORT = 0x0800,	/* Can sort output */
214 	PAPI_PRINTER_SMALL = 0x1000,	/* Can do letter/legal/a4 */
215 	PAPI_PRINTER_MEDIUM = 0x2000,	/* Can do tabloid/B/C/A3/A2 */
216 	PAPI_PRINTER_LARGE = 0x4000,	/* Can do D/E/A1/A0 */
217 	PAPI_PRINTER_VARIABLE = 0x8000,	/* Can do variable sizes */
218 	PAPI_PRINTER_IMPLICIT = 0x10000, /* implicit class */
219 	PAPI_PRINTER_DEFAULT = 0x20000,	/* Default printer on network */
220 	PAPI_PRINTER_OPTIONS = 0xfffc	/* ~ (CLASS | REMOTE | IMPLICIT) */
221 };
222 
223 /*
224  * Functions
225  */
226 
227 /* 	Service related		*/
228 extern papi_status_t papiServiceCreate(papi_service_t *handle,
229 					char *service_name, char *user_name,
230 					char *password,
231 					int (*authCB)(papi_service_t svc,
232 							void *app_data),
233 					papi_encryption_t encryption,
234 					void *app_data);
235 extern void papiServiceDestroy(papi_service_t handle);
236 extern papi_status_t papiServiceSetUserName(papi_service_t handle,
237 					char *user_name);
238 extern papi_status_t papiServiceSetPassword(papi_service_t handle,
239 					char *password);
240 extern papi_status_t papiServiceSetEncryption(papi_service_t handle,
241 					papi_encryption_t encryption);
242 extern papi_status_t papiServiceSetAuthCB(papi_service_t handle,
243 					int (*authCB)(papi_service_t s,
244 							void *app_data));
245 extern papi_status_t papiServiceSetAppData(papi_service_t handle,
246 					void *app_data);
247 extern char *papiServiceGetServiceName(papi_service_t handle);
248 extern char *papiServiceGetUserName(papi_service_t handle);
249 extern char *papiServiceGetPassword(papi_service_t handle);
250 extern papi_encryption_t papiServiceGetEncryption(papi_service_t handle);
251 extern void *papiServiceGetAppData(papi_service_t handle);
252 extern papi_attribute_t **papiServiceGetAttributeList(papi_service_t handle);
253 extern char *papiServiceGetStatusMessage(papi_service_t handle);
254 
255 /*	Attribute related	 */
256 extern papi_status_t papiAttributeListAddValue(papi_attribute_t ***attrs,
257 					int flags, char *name,
258 					papi_attribute_value_type_t type,
259 					papi_attribute_value_t *value);
260 extern papi_status_t papiAttributeListAddString(papi_attribute_t ***attrs,
261 					int flags, char *name, char *string);
262 extern papi_status_t papiAttributeListAddInteger(papi_attribute_t ***attrs,
263 					int flags, char *name, int integer);
264 extern papi_status_t papiAttributeListAddBoolean(papi_attribute_t ***attrs,
265 					int flags, char *name, char boolean);
266 extern papi_status_t papiAttributeListAddRange(papi_attribute_t ***attrs,
267 					int flags, char *name,
268 					int lower, int upper);
269 extern papi_status_t papiAttributeListAddResolution(papi_attribute_t ***attrs,
270 					int flags, char *name,
271 					int xres, int yres,
272 					papi_resolution_unit_t units);
273 extern papi_status_t papiAttributeListAddDatetime(papi_attribute_t ***attrs,
274 					int flags, char *name, time_t datetime);
275 extern papi_status_t papiAttributeListAddCollection(papi_attribute_t ***attrs,
276 					int flags, char *name,
277 					papi_attribute_t **collection);
278 extern papi_status_t papiAttributeListAddMetadata(papi_attribute_t ***attrs,
279 					int flags, char *name,
280 					papi_metadata_t metadata);
281 extern papi_status_t papiAttributeListDelete(papi_attribute_t ***attributes,
282 					char *name);
283 extern papi_status_t papiAttributeListGetValue(papi_attribute_t **list,
284 					void **iterator, char *name,
285 					papi_attribute_value_type_t type,
286 					papi_attribute_value_t **value);
287 extern papi_status_t papiAttributeListGetString(papi_attribute_t **list,
288 					void **iterator, char *name,
289 					char **vptr);
290 extern papi_status_t papiAttributeListGetInteger(papi_attribute_t **list,
291 					void **iterator, char *name, int *vptr);
292 extern papi_status_t papiAttributeListGetBoolean(papi_attribute_t **list,
293 					void **iterator, char *name,
294 					char *vptr);
295 extern papi_status_t papiAttributeListGetRange(papi_attribute_t **list,
296 					void **iterator, char *name,
297 					int *min, int *max);
298 extern papi_status_t papiAttributeListGetResolution(papi_attribute_t **list,
299 					void **iterator, char *name,
300 					int *x, int *y,
301 					papi_resolution_unit_t *units);
302 extern papi_status_t papiAttributeListGetDatetime(papi_attribute_t **list,
303 					void **iterator, char *name,
304 					time_t *dt);
305 extern papi_status_t papiAttributeListGetCollection(papi_attribute_t **list,
306 					void **iterator, char *name,
307 					papi_attribute_t ***collection);
308 extern papi_status_t papiAttributeListGetMetadata(papi_attribute_t **list,
309 					void **iterator, char *name,
310 					papi_metadata_t *vptr);
311 extern papi_attribute_t *papiAttributeListFind(papi_attribute_t **list,
312 					char *name);
313 extern papi_attribute_t *papiAttributeListGetNext(papi_attribute_t **list,
314 					void **iterator);
315 extern void papiAttributeListFree(papi_attribute_t **attributes);
316 
317 extern papi_status_t papiAttributeListFromString(papi_attribute_t ***attrs,
318 					int flags, char *string);
319 extern papi_status_t papiAttributeListToString(papi_attribute_t **attrs,
320 					char *delim,
321 					char *buffer, size_t buflen);
322 extern void papiAttributeListPrint(FILE *fp, papi_attribute_t **list,
323 					char *prefix_fmt, ...);
324 
325 /*	Printer related		 */
326 extern papi_status_t papiPrintersList(papi_service_t handle,
327 					char **requested_attrs,
328 					papi_filter_t *filter,
329 					papi_printer_t **printers);
330 extern papi_status_t papiPrinterQuery(papi_service_t handle, char *name,
331 					char **requested_attrs,
332 					papi_attribute_t **job_attributes,
333 					papi_printer_t *printer);
334 extern papi_status_t papiPrinterAdd(papi_service_t handle, char *name,
335 					papi_attribute_t **attributes,
336 					papi_printer_t *printer);
337 extern papi_status_t papiPrinterModify(papi_service_t handle, char *name,
338 					papi_attribute_t **attributes,
339 					papi_printer_t *printer);
340 extern papi_status_t papiPrinterRemove(papi_service_t handle, char *name);
341 extern papi_status_t papiPrinterDisable(papi_service_t handle, char *name,
342 					char *message);
343 extern papi_status_t papiPrinterEnable(papi_service_t handle, char *name);
344 extern papi_status_t papiPrinterPause(papi_service_t handle, char *name,
345 					char *message);
346 extern papi_status_t papiPrinterResume(papi_service_t handle, char *name);
347 extern papi_status_t papiPrinterPurgeJobs(papi_service_t handle,
348 					char *name, papi_job_t **jobs);
349 extern papi_status_t papiPrinterListJobs(papi_service_t handle,
350 					char *name, char **requested_attrs,
351 					int type_mask, int max_num_jobs,
352 					papi_job_t **jobs);
353 extern papi_attribute_t **papiPrinterGetAttributeList(papi_printer_t printer);
354 extern void papiPrinterFree(papi_printer_t printer);
355 extern void papiPrinterListFree(papi_printer_t *printers);
356 
357 /*	Job related		*/
358 extern papi_status_t papiJobSubmit(papi_service_t handle, char *printer,
359 					papi_attribute_t **job_attributes,
360 					papi_job_ticket_t *job_ticket,
361 					char **files, papi_job_t *job);
362 extern papi_status_t papiJobSubmitByReference(papi_service_t handle,
363 					char *printer,
364 					papi_attribute_t **job_attributes,
365 					papi_job_ticket_t *job_ticket,
366 					char **files, papi_job_t *job);
367 extern papi_status_t papiJobValidate(papi_service_t handle, char *printer,
368 					papi_attribute_t **job_attributes,
369 					papi_job_ticket_t *job_ticket,
370 					char **files, papi_job_t *job);
371 extern papi_status_t papiJobStreamOpen(papi_service_t handle,
372 					char *printer,
373 					papi_attribute_t **job_attributes,
374 					papi_job_ticket_t *job_ticket,
375 					papi_stream_t *stream);
376 extern papi_status_t papiJobStreamWrite(papi_service_t handle,
377 					papi_stream_t stream,
378 					void *buffer, size_t buflen);
379 extern papi_status_t papiJobStreamClose(papi_service_t handle,
380 					papi_stream_t stream,
381 					papi_job_t *job);
382 extern papi_status_t papiJobQuery(papi_service_t handle, char *printer,
383 					int32_t job_id, char **requested_attrs,
384 					papi_job_t *job);
385 extern papi_status_t papiJobModify(papi_service_t handle, char *printer,
386 					int32_t job_id,
387 					papi_attribute_t **attributes,
388 					papi_job_t *job);
389 extern papi_status_t papiJobMove(papi_service_t handle, char *printer,
390 					int32_t job_id, char *destination);
391 extern papi_status_t papiJobCancel(papi_service_t handle, char *printer,
392 					int32_t job_id);
393 extern papi_status_t papiJobHold(papi_service_t handle, char *printer,
394 					int32_t job_id);
395 extern papi_status_t papiJobRelease(papi_service_t handle, char *printer,
396 					int32_t job_id);
397 extern papi_status_t papiJobRestart(papi_service_t handle, char *printer,
398 					int32_t job_id);
399 extern papi_status_t papiJobPromote(papi_service_t handle, char *printer,
400 					int32_t job_id);
401 extern papi_attribute_t **papiJobGetAttributeList(papi_job_t printer);
402 extern char *papiJobGetPrinterName(papi_job_t printer);
403 extern int32_t papiJobGetId(papi_job_t printer);
404 extern papi_job_ticket_t *papiJobGetJobTicket(papi_job_t printer);
405 extern void papiJobFree(papi_job_t job);
406 extern void papiJobListFree(papi_job_t *jobs);
407 
408 #ifdef SOLARIS_PRIVATE_POST_0_9
409 /*
410  * These have been added to support IPP create-job/send-document with PAPI v0.9
411  * in an IPP listener using PAPI as it's spooler interface.  A future version
412  * of the API is expected to support this type of functionality
413  */
414 extern papi_status_t papiJobCreate(papi_service_t handle, char *printer,
415 					papi_attribute_t **job_attributes,
416 					papi_job_ticket_t *job_ticket,
417 					papi_job_t *job);
418 extern papi_status_t papiJobStreamAdd(papi_service_t handle, char *printer,
419 					int32_t id, papi_stream_t *stream);
420 extern papi_status_t papiJobCommit(papi_service_t handle, char *printer,
421 					int32_t id);
422 extern papi_status_t papiServiceSetPeer(papi_service_t handle, int peerfd);
423 #endif /* SOLARIS_PRIVATE_POST_0_9 */
424 
425 extern char *papiStatusString(papi_status_t status);
426 
427 /*
428  * Internal functions that aren't in the API, but are shared across
429  * protocol support implementations(psms) and the tightly bound
430  * listener library.  Do not use these in your applications.
431  */
432 extern void list_append();
433 extern void list_concatenate();
434 extern void list_remove();
435 extern void copy_attributes(papi_attribute_t ***result,
436 				papi_attribute_t **list);
437 extern void split_and_copy_attributes(char **list,
438 				papi_attribute_t **attributes,
439 				papi_attribute_t ***in,
440 				papi_attribute_t ***out);
441 
442 extern papi_attribute_t **getprinterbyname(char *name, char *ns);
443 
444 extern int is_localhost(char *hostname);
445 
446 #ifdef __cplusplus
447 }
448 #endif
449 
450 #endif /* _PAPI_H */
451