1 /*
2  * Private IPP definitions for CUPS.
3  *
4  * Copyright © 2007-2018 by Apple Inc.
5  * Copyright © 1997-2006 by Easy Software Products.
6  *
7  * Licensed under Apache License v2.0.  See the file "LICENSE" for more
8  * information.
9  */
10 
11 #ifndef _CUPS_IPP_PRIVATE_H_
12 #  define _CUPS_IPP_PRIVATE_H_
13 
14 /*
15  * Include necessary headers...
16  */
17 
18 #  include <cups/cups.h>
19 
20 
21 /*
22  * C++ magic...
23  */
24 
25 #  ifdef __cplusplus
26 extern "C" {
27 #  endif /* __cplusplus */
28 
29 
30 /*
31  * Constants...
32  */
33 
34 #  define IPP_BUF_SIZE	(IPP_MAX_LENGTH + 2)
35 					/* Size of buffer */
36 
37 
38 /*
39  * Structures...
40  */
41 
42 typedef union _ipp_request_u		/**** Request Header ****/
43 {
44   struct				/* Any Header */
45   {
46     ipp_uchar_t	version[2];		/* Protocol version number */
47     int		op_status;		/* Operation ID or status code*/
48     int		request_id;		/* Request ID */
49   }		any;
50 
51   struct				/* Operation Header */
52   {
53     ipp_uchar_t	version[2];		/* Protocol version number */
54     ipp_op_t	operation_id;		/* Operation ID */
55     int		request_id;		/* Request ID */
56   }		op;
57 
58   struct				/* Status Header */
59   {
60     ipp_uchar_t	version[2];		/* Protocol version number */
61     ipp_status_t status_code;		/* Status code */
62     int		request_id;		/* Request ID */
63   }		status;
64 
65   /**** New in CUPS 1.1.19 ****/
66   struct				/* Event Header @since CUPS 1.1.19/macOS 10.3@ */
67   {
68     ipp_uchar_t	version[2];		/* Protocol version number */
69     ipp_status_t status_code;		/* Status code */
70     int		request_id;		/* Request ID */
71   }		event;
72 } _ipp_request_t;
73 
74 typedef union _ipp_value_u		/**** Attribute Value ****/
75 {
76   int		integer;		/* Integer/enumerated value */
77 
78   char		boolean;		/* Boolean value */
79 
80   ipp_uchar_t	date[11];		/* Date/time value */
81 
82   struct
83   {
84     int		xres,			/* Horizontal resolution */
85 		yres;			/* Vertical resolution */
86     ipp_res_t	units;			/* Resolution units */
87   }		resolution;		/* Resolution value */
88 
89   struct
90   {
91     int		lower,			/* Lower value */
92 		upper;			/* Upper value */
93   }		range;			/* Range of integers value */
94 
95   struct
96   {
97     char	*language;		/* Language code */
98     char	*text;			/* String */
99   }		string;			/* String with language value */
100 
101   struct
102   {
103     int		length;			/* Length of attribute */
104     void	*data;			/* Data in attribute */
105   }		unknown;		/* Unknown attribute type */
106 
107 /**** New in CUPS 1.1.19 ****/
108   ipp_t		*collection;		/* Collection value @since CUPS 1.1.19/macOS 10.3@ */
109 } _ipp_value_t;
110 
111 struct _ipp_attribute_s			/**** IPP attribute ****/
112 {
113   ipp_attribute_t *next;		/* Next attribute in list */
114   ipp_tag_t	group_tag,		/* Job/Printer/Operation group tag */
115 		value_tag;		/* What type of value is it? */
116   char		*name;			/* Name of attribute */
117   int		num_values;		/* Number of values */
118   _ipp_value_t	values[1];		/* Values */
119 };
120 
121 struct _ipp_s				/**** IPP Request/Response/Notification ****/
122 {
123   ipp_state_t		state;		/* State of request */
124   _ipp_request_t	request;	/* Request header */
125   ipp_attribute_t	*attrs;		/* Attributes */
126   ipp_attribute_t	*last;		/* Last attribute in list */
127   ipp_attribute_t	*current;	/* Current attribute (for read/write) */
128   ipp_tag_t		curtag;		/* Current attribute group tag */
129 
130 /**** New in CUPS 1.2 ****/
131   ipp_attribute_t	*prev;		/* Previous attribute (for read) @since CUPS 1.2/macOS 10.5@ */
132 
133 /**** New in CUPS 1.4.4 ****/
134   int			use;		/* Use count @since CUPS 1.4.4/macOS 10.6.?@ */
135 /**** New in CUPS 2.0 ****/
136   int			atend,		/* At end of list? */
137 			curindex;	/* Current attribute index for hierarchical search */
138 };
139 
140 typedef struct _ipp_option_s		/**** Attribute mapping data ****/
141 {
142   int		multivalue;		/* Option has multiple values? */
143   const char	*name;			/* Option/attribute name */
144   ipp_tag_t	value_tag;		/* Value tag for this attribute */
145   ipp_tag_t	group_tag;		/* Group tag for this attribute */
146   ipp_tag_t	alt_group_tag;		/* Alternate group tag for this
147 					 * attribute */
148   const ipp_op_t *operations;		/* Allowed operations for this attr */
149 } _ipp_option_t;
150 
151 typedef struct _ipp_file_s _ipp_file_t;/**** File Parser ****/
152 typedef struct _ipp_vars_s _ipp_vars_t;/**** Variables ****/
153 
154 typedef int (*_ipp_fattr_cb_t)(_ipp_file_t *f, void *user_data, const char *attr);
155 					/**** File Attribute (Filter) Callback ****/
156 typedef int (*_ipp_ferror_cb_t)(_ipp_file_t *f, void *user_data, const char *error);
157 					/**** File Parser Error Callback ****/
158 typedef int (*_ipp_ftoken_cb_t)(_ipp_file_t *f, _ipp_vars_t *v, void *user_data, const char *token);
159 					/**** File Parser Token Callback ****/
160 
161 struct _ipp_vars_s			/**** Variables ****/
162 {
163   char		*uri,			/* URI for printer */
164 		scheme[64],		/* Scheme from URI */
165 		username[256],		/* Username from URI */
166 		*password,		/* Password from URI (if any) */
167 		host[256],		/* Hostname from URI */
168 		portstr[32],		/* Port number string */
169 		resource[1024];		/* Resource path from URI */
170   int 		port;			/* Port number from URI */
171   int		num_vars;		/* Number of variables */
172   cups_option_t	*vars;			/* Array of variables */
173   int		password_tries;		/* Number of retries for password */
174   _ipp_fattr_cb_t attrcb;		/* Attribute (filter) callback */
175   _ipp_ferror_cb_t errorcb;		/* Error callback */
176   _ipp_ftoken_cb_t tokencb;		/* Token callback */
177 };
178 
179 struct _ipp_file_s			/**** File Parser */
180 {
181   const char		*filename;	/* Filename */
182   cups_file_t		*fp;		/* File pointer */
183   int			linenum;	/* Current line number */
184   ipp_t			*attrs;		/* Attributes */
185   ipp_tag_t		group_tag;	/* Current group for new attributes */
186 };
187 
188 
189 /*
190  * Prototypes for private functions...
191  */
192 
193 /* encode.c */
194 #ifdef DEBUG
195 extern const char	*_ippCheckOptions(void) _CUPS_PRIVATE;
196 #endif /* DEBUG */
197 extern _ipp_option_t	*_ippFindOption(const char *name) _CUPS_PRIVATE;
198 
199 /* ipp-file.c */
200 extern ipp_t		*_ippFileParse(_ipp_vars_t *v, const char *filename, void *user_data) _CUPS_PRIVATE;
201 extern int		_ippFileReadToken(_ipp_file_t *f, char *token, size_t tokensize) _CUPS_PRIVATE;
202 
203 /* ipp-vars.c */
204 extern void		_ippVarsDeinit(_ipp_vars_t *v) _CUPS_PRIVATE;
205 extern void		_ippVarsExpand(_ipp_vars_t *v, char *dst, const char *src, size_t dstsize) _CUPS_NONNULL(1,2,3) _CUPS_PRIVATE;
206 extern const char	*_ippVarsGet(_ipp_vars_t *v, const char *name) _CUPS_PRIVATE;
207 extern void		_ippVarsInit(_ipp_vars_t *v, _ipp_fattr_cb_t attrcb, _ipp_ferror_cb_t errorcb, _ipp_ftoken_cb_t tokencb) _CUPS_PRIVATE;
208 extern const char	*_ippVarsPasswordCB(const char *prompt, http_t *http, const char *method, const char *resource, void *user_data) _CUPS_PRIVATE;
209 extern int		_ippVarsSet(_ipp_vars_t *v, const char *name, const char *value) _CUPS_PRIVATE;
210 
211 
212 /*
213  * C++ magic...
214  */
215 
216 #  ifdef __cplusplus
217 }
218 #  endif /* __cplusplus */
219 #endif /* !_CUPS_IPP_H_ */
220