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