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