summaryrefslogtreecommitdiff
path: root/usr/src/lib/print/libpapi-common/common/papi.h
blob: 5fcaccc58409e2ca39f18602abaa80d2cdc82ebb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
/*
 * CDDL HEADER START
 *
 * 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.
 *
 * 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.
 *
 * 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]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 *
 */

#ifndef _PAPI_H
#define	_PAPI_H

/* $Id: papi.h 161 2006-05-03 04:32:59Z njacobs $ */

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <sys/types.h>
#include <time.h>
#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
 * Types
 */

/*	service related types	*/
typedef void *papi_service_t;
typedef void *papi_printer_t;
typedef void *papi_job_t;
typedef void *papi_stream_t;

typedef enum {
	PAPI_ENCRYPT_IF_REQUESTED,	/* Encrypt if requested (TLS upgrade) */
	PAPI_ENCRYPT_NEVER,		/* Never encrypt */
	PAPI_ENCRYPT_REQUIRED,		/* Encryption required (TLS upgrade) */
	PAPI_ENCRYPT_ALWAYS		/* Always encrypt (SSL) */
} papi_encryption_t;

/*	attribute related types	*/
typedef enum {
	PAPI_STRING,
	PAPI_INTEGER,
	PAPI_BOOLEAN,
	PAPI_RANGE,
	PAPI_RESOLUTION,
	PAPI_DATETIME,
	PAPI_COLLECTION,
	PAPI_METADATA
} papi_attribute_value_type_t;

typedef enum {
	PAPI_RES_PER_INCH = 3,
	PAPI_RES_PER_CM
} papi_resolution_unit_t;

enum {	/* for boolean values */
	PAPI_FALSE = 0,
	PAPI_TRUE = 1
};

typedef enum {
	PAPI_UNSUPPORTED = 0x10,
	PAPI_DEFAULT = 0x11,
	PAPI_UNKNOWN,
	PAPI_NO_VALUE,
	PAPI_NOT_SETTABLE = 0x15,
	PAPI_DELETE = 0x16
} papi_metadata_t;

#define	PAPI_LIST_JOBS_OTHERS		0x0001
#define	PAPI_LIST_JOBS_COMPLETED	0x0002
#define	PAPI_LIST_JOBS_NOT_COMPLETED	0x0004
#define	PAPI_LIST_JOBS_ALL		0xFFFF

typedef struct papi_attribute_s papi_attribute_t;

typedef union {
	char *string;				/* PAPI_STRING value */
	int integer;				/* PAPI_INTEGER value */
	char boolean;				/* PAPI_BOOLEAN value */
	struct {				/* PAPI_RANGE value */
		int lower;
		int upper;
	} range;
	struct {				/* PAPI_RESOLUTION value */
		int xres;
		int yres;
		papi_resolution_unit_t units;
	} resolution;
	time_t datetime;			/* PAPI_DATETIME value */
	papi_attribute_t **collection;		/* PAPI_COLLECTION value */
	papi_metadata_t metadata;		/* PAPI_METADATA value */
} papi_attribute_value_t;

struct papi_attribute_s {
	char *name;				/* attribute name */
	papi_attribute_value_type_t type;	/* type of values */
	papi_attribute_value_t **values;	/* list of values */
};

#define	PAPI_ATTR_APPEND	0x0001	/* Add values to attr */
#define	PAPI_ATTR_REPLACE	0x0002	/* Delete existing values, then add */
#define	PAPI_ATTR_EXCL		0x0004	/* Fail if attr exists */

/*	job related types	*/
typedef enum {
	PAPI_JT_FORMAT_JDF = 0,
	PAPI_JT_FORMAT_PWG = 1
} papi_jt_format_t;

typedef struct {
	papi_jt_format_t format;
	char *ticket_data;
	char *file_name;
} papi_job_ticket_t;

/*	status related types	*/
typedef enum {
	PAPI_OK = 0x0000,
	PAPI_OK_SUBST,
	PAPI_OK_CONFLICT,
	PAPI_OK_IGNORED_SUBSCRIPTIONS,
	PAPI_OK_IGNORED_NOTIFICATIONS,
	PAPI_OK_TOO_MANY_EVENTS,
	PAPI_OK_BUT_CANCEL_SUBSCRIPTION,
	PAPI_REDIRECTION_OTHER_SITE = 0x0300,
	PAPI_BAD_REQUEST = 0x0400,
	PAPI_FORBIDDEN,
	PAPI_NOT_AUTHENTICATED,
	PAPI_NOT_AUTHORIZED,
	PAPI_NOT_POSSIBLE,
	PAPI_TIMEOUT,
	PAPI_NOT_FOUND,
	PAPI_GONE,
	PAPI_REQUEST_ENTITY,
	PAPI_REQUEST_VALUE,
	PAPI_DOCUMENT_FORMAT,
	PAPI_ATTRIBUTES,
	PAPI_URI_SCHEME,
	PAPI_CHARSET,
	PAPI_CONFLICT,
	PAPI_COMPRESSION_NOT_SUPPORTED,
	PAPI_COMPRESSION_ERROR,
	PAPI_DOCUMENT_FORMAT_ERROR,
	PAPI_DOCUMENT_ACCESS_ERROR,
	PAPI_ATTRIBUTES_NOT_SETTABLE,
	PAPI_IGNORED_ALL_SUBSCRIPTIONS,
	PAPI_TOO_MANY_SUBSCRIPTIONS,
	PAPI_IGNORED_ALL_NOTIFICATIONS,
	PAPI_PRINT_SUPPORT_FILE_NOT_FOUND,
	PAPI_INTERNAL_ERROR = 0x0500,
	PAPI_OPERATION_NOT_SUPPORTED,
	PAPI_SERVICE_UNAVAILABLE,
	PAPI_VERSION_NOT_SUPPORTED,
	PAPI_DEVICE_ERROR,
	PAPI_TEMPORARY_ERROR,
	PAPI_NOT_ACCEPTING,
	PAPI_PRINTER_BUSY,
	PAPI_ERROR_JOB_CANCELLED,
	PAPI_MULTIPLE_JOBS_NOT_SUPPORTED,
	PAPI_PRINTER_IS_DEACTIVATED,
	PAPI_BAD_ARGUMENT,
	PAPI_JOB_TICKET_NOT_SUPPORTED
} papi_status_t;

/*	list filter related	*/
typedef enum {
	PAPI_FILTER_BITMASK = 0
} papi_filter_type_t;

typedef struct {
	papi_filter_type_t type;
	union {
		struct {			/* PAPI_FILTER_BITMASK */
			unsigned int mask;
			unsigned int value;
		} bitmask;
	} filter;
} papi_filter_t;

enum {
	PAPI_PRINTER_LOCAL = 0x0000,	/* Local destination */
	PAPI_PRINTER_CLASS = 0x0001,	/* Printer class */
	PAPI_PRINTER_REMOTE = 0x0002,	/* Remote destination */
	PAPI_PRINTER_BW = 0x0004,	/* Can do B&W printing */
	PAPI_PRINTER_COLOR = 0x0008,	/* Can do color printing */
	PAPI_PRINTER_DUPLEX = 0x0010,	/* Can do duplex printing */
	PAPI_PRINTER_STAPLE = 0x0020,	/* Can do stapling */
	PAPI_PRINTER_COPIES = 0x0040,	/* Can do copies */
	PAPI_PRINTER_COLLATE = 0x0080,	/* Can collate copies */
	PAPI_PRINTER_PUNCH = 0x0100,	/* Can punch output */
	PAPI_PRINTER_COVER = 0x0200,	/* Can cover output */
	PAPI_PRINTER_BIND = 0x0400,	/* Can bind output */
	PAPI_PRINTER_SORT = 0x0800,	/* Can sort output */
	PAPI_PRINTER_SMALL = 0x1000,	/* Can do letter/legal/a4 */
	PAPI_PRINTER_MEDIUM = 0x2000,	/* Can do tabloid/B/C/A3/A2 */
	PAPI_PRINTER_LARGE = 0x4000,	/* Can do D/E/A1/A0 */
	PAPI_PRINTER_VARIABLE = 0x8000,	/* Can do variable sizes */
	PAPI_PRINTER_IMPLICIT = 0x10000, /* implicit class */
	PAPI_PRINTER_DEFAULT = 0x20000,	/* Default printer on network */
	PAPI_PRINTER_OPTIONS = 0xfffc	/* ~ (CLASS | REMOTE | IMPLICIT) */
};

/*
 * Functions
 */

/* 	Service related		*/
extern papi_status_t papiServiceCreate(papi_service_t *handle,
					char *service_name, char *user_name,
					char *password,
					int (*authCB)(papi_service_t svc,
							void *app_data),
					papi_encryption_t encryption,
					void *app_data);
extern void papiServiceDestroy(papi_service_t handle);
extern papi_status_t papiServiceSetUserName(papi_service_t handle,
					char *user_name);
extern papi_status_t papiServiceSetPassword(papi_service_t handle,
					char *password);
extern papi_status_t papiServiceSetEncryption(papi_service_t handle,
					papi_encryption_t encryption);
extern papi_status_t papiServiceSetAuthCB(papi_service_t handle,
					int (*authCB)(papi_service_t s,
							void *app_data));
extern papi_status_t papiServiceSetAppData(papi_service_t handle,
					void *app_data);
extern char *papiServiceGetServiceName(papi_service_t handle);
extern char *papiServiceGetUserName(papi_service_t handle);
extern char *papiServiceGetPassword(papi_service_t handle);
extern papi_encryption_t papiServiceGetEncryption(papi_service_t handle);
extern void *papiServiceGetAppData(papi_service_t handle);
extern papi_attribute_t **papiServiceGetAttributeList(papi_service_t handle);
extern char *papiServiceGetStatusMessage(papi_service_t handle);

/*	Attribute related	 */
extern papi_status_t papiAttributeListAddValue(papi_attribute_t ***attrs,
					int flags, char *name,
					papi_attribute_value_type_t type,
					papi_attribute_value_t *value);
extern papi_status_t papiAttributeListAddString(papi_attribute_t ***attrs,
					int flags, char *name, char *string);
extern papi_status_t papiAttributeListAddInteger(papi_attribute_t ***attrs,
					int flags, char *name, int integer);
extern papi_status_t papiAttributeListAddBoolean(papi_attribute_t ***attrs,
					int flags, char *name, char boolean);
extern papi_status_t papiAttributeListAddRange(papi_attribute_t ***attrs,
					int flags, char *name,
					int lower, int upper);
extern papi_status_t papiAttributeListAddResolution(papi_attribute_t ***attrs,
					int flags, char *name,
					int xres, int yres,
					papi_resolution_unit_t units);
extern papi_status_t papiAttributeListAddDatetime(papi_attribute_t ***attrs,
					int flags, char *name, time_t datetime);
extern papi_status_t papiAttributeListAddCollection(papi_attribute_t ***attrs,
					int flags, char *name,
					papi_attribute_t **collection);
extern papi_status_t papiAttributeListAddMetadata(papi_attribute_t ***attrs,
					int flags, char *name,
					papi_metadata_t metadata);
extern papi_status_t papiAttributeListDelete(papi_attribute_t ***attributes,
					char *name);
extern papi_status_t papiAttributeListGetValue(papi_attribute_t **list,
					void **iterator, char *name,
					papi_attribute_value_type_t type,
					papi_attribute_value_t **value);
extern papi_status_t papiAttributeListGetString(papi_attribute_t **list,
					void **iterator, char *name,
					char **vptr);
extern papi_status_t papiAttributeListGetInteger(papi_attribute_t **list,
					void **iterator, char *name, int *vptr);
extern papi_status_t papiAttributeListGetBoolean(papi_attribute_t **list,
					void **iterator, char *name,
					char *vptr);
extern papi_status_t papiAttributeListGetRange(papi_attribute_t **list,
					void **iterator, char *name,
					int *min, int *max);
extern papi_status_t papiAttributeListGetResolution(papi_attribute_t **list,
					void **iterator, char *name,
					int *x, int *y,
					papi_resolution_unit_t *units);
extern papi_status_t papiAttributeListGetDatetime(papi_attribute_t **list,
					void **iterator, char *name,
					time_t *dt);
extern papi_status_t papiAttributeListGetCollection(papi_attribute_t **list,
					void **iterator, char *name,
					papi_attribute_t ***collection);
extern papi_status_t papiAttributeListGetMetadata(papi_attribute_t **list,
					void **iterator, char *name,
					papi_metadata_t *vptr);
extern papi_attribute_t *papiAttributeListFind(papi_attribute_t **list,
					char *name);
extern papi_attribute_t *papiAttributeListGetNext(papi_attribute_t **list,
					void **iterator);
extern void papiAttributeListFree(papi_attribute_t **attributes);

extern papi_status_t papiAttributeListFromString(papi_attribute_t ***attrs,
					int flags, char *string);
extern papi_status_t papiAttributeListToString(papi_attribute_t **attrs,
					char *delim,
					char *buffer, size_t buflen);
extern void papiAttributeListPrint(FILE *fp, papi_attribute_t **list,
					char *prefix_fmt, ...);

/*	Printer related		 */
extern papi_status_t papiPrintersList(papi_service_t handle,
					char **requested_attrs,
					papi_filter_t *filter,
					papi_printer_t **printers);
extern papi_status_t papiPrinterQuery(papi_service_t handle, char *name,
					char **requested_attrs,
					papi_attribute_t **job_attributes,
					papi_printer_t *printer);
extern papi_status_t papiPrinterAdd(papi_service_t handle, char *name,
					papi_attribute_t **attributes,
					papi_printer_t *printer);
extern papi_status_t papiPrinterModify(papi_service_t handle, char *name,
					papi_attribute_t **attributes,
					papi_printer_t *printer);
extern papi_status_t papiPrinterRemove(papi_service_t handle, char *name);
extern papi_status_t papiPrinterDisable(papi_service_t handle, char *name,
					char *message);
extern papi_status_t papiPrinterEnable(papi_service_t handle, char *name);
extern papi_status_t papiPrinterPause(papi_service_t handle, char *name,
					char *message);
extern papi_status_t papiPrinterResume(papi_service_t handle, char *name);
extern papi_status_t papiPrinterPurgeJobs(papi_service_t handle,
					char *name, papi_job_t **jobs);
extern papi_status_t papiPrinterListJobs(papi_service_t handle,
					char *name, char **requested_attrs,
					int type_mask, int max_num_jobs,
					papi_job_t **jobs);
extern papi_attribute_t **papiPrinterGetAttributeList(papi_printer_t printer);
extern void papiPrinterFree(papi_printer_t printer);
extern void papiPrinterListFree(papi_printer_t *printers);

/*	Job related		*/
extern papi_status_t papiJobSubmit(papi_service_t handle, char *printer,
					papi_attribute_t **job_attributes,
					papi_job_ticket_t *job_ticket,
					char **files, papi_job_t *job);
extern papi_status_t papiJobSubmitByReference(papi_service_t handle,
					char *printer,
					papi_attribute_t **job_attributes,
					papi_job_ticket_t *job_ticket,
					char **files, papi_job_t *job);
extern papi_status_t papiJobValidate(papi_service_t handle, char *printer,
					papi_attribute_t **job_attributes,
					papi_job_ticket_t *job_ticket,
					char **files, papi_job_t *job);
extern papi_status_t papiJobStreamOpen(papi_service_t handle,
					char *printer,
					papi_attribute_t **job_attributes,
					papi_job_ticket_t *job_ticket,
					papi_stream_t *stream);
extern papi_status_t papiJobStreamWrite(papi_service_t handle,
					papi_stream_t stream,
					void *buffer, size_t buflen);
extern papi_status_t papiJobStreamClose(papi_service_t handle,
					papi_stream_t stream,
					papi_job_t *job);
extern papi_status_t papiJobQuery(papi_service_t handle, char *printer,
					int32_t job_id, char **requested_attrs,
					papi_job_t *job);
extern papi_status_t papiJobModify(papi_service_t handle, char *printer,
					int32_t job_id,
					papi_attribute_t **attributes,
					papi_job_t *job);
extern papi_status_t papiJobMove(papi_service_t handle, char *printer,
					int32_t job_id, char *destination);
extern papi_status_t papiJobCancel(papi_service_t handle, char *printer,
					int32_t job_id);
extern papi_status_t papiJobHold(papi_service_t handle, char *printer,
					int32_t job_id);
extern papi_status_t papiJobRelease(papi_service_t handle, char *printer,
					int32_t job_id);
extern papi_status_t papiJobRestart(papi_service_t handle, char *printer,
					int32_t job_id);
extern papi_status_t papiJobPromote(papi_service_t handle, char *printer,
					int32_t job_id);
extern papi_attribute_t **papiJobGetAttributeList(papi_job_t printer);
extern char *papiJobGetPrinterName(papi_job_t printer);
extern int32_t papiJobGetId(papi_job_t printer);
extern papi_job_ticket_t *papiJobGetJobTicket(papi_job_t printer);
extern void papiJobFree(papi_job_t job);
extern void papiJobListFree(papi_job_t *jobs);

#ifdef SOLARIS_PRIVATE_POST_0_9
/*
 * These have been added to support IPP create-job/send-document with PAPI v0.9
 * in an IPP listener using PAPI as it's spooler interface.  A future version
 * of the API is expected to support this type of functionality
 */
extern papi_status_t papiJobCreate(papi_service_t handle, char *printer,
					papi_attribute_t **job_attributes,
					papi_job_ticket_t *job_ticket,
					papi_job_t *job);
extern papi_status_t papiJobStreamAdd(papi_service_t handle, char *printer,
					int32_t id, papi_stream_t *stream);
extern papi_status_t papiJobCommit(papi_service_t handle, char *printer,
					int32_t id);
extern papi_status_t papiServiceSetPeer(papi_service_t handle, int peerfd);
#endif /* SOLARIS_PRIVATE_POST_0_9 */

extern char *papiStatusString(papi_status_t status);

/*
 * Internal functions that aren't in the API, but are shared across
 * protocol support implementations(psms) and the tightly bound
 * listener library.  Do not use these in your applications.
 */
extern void list_append();
extern void list_concatenate();
extern void list_remove();
extern void copy_attributes(papi_attribute_t ***result,
				papi_attribute_t **list);
extern void split_and_copy_attributes(char **list,
				papi_attribute_t **attributes,
				papi_attribute_t ***in,
				papi_attribute_t ***out);

extern papi_attribute_t **getprinterbyname(char *name, char *ns);

extern int is_localhost(char *hostname);

#ifdef __cplusplus
}
#endif

#endif /* _PAPI_H */