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 2006 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * 26 */ 27 28 /* $Id: strings.c 151 2006-04-25 16:55:34Z njacobs $ */ 29 30 #include <stdio.h> 31 #include <stdlib.h> 32 #include <string.h> 33 34 #include "ipp.h" 35 36 static char *tag_strings[] = { 37 /* delimiter tags */ 38 "reserved-delimiter-00", 39 "operational-attributes-group", 40 "job-attributes-group", 41 "end-of-attributes-group", 42 "printer-attributes-group", 43 "unsupported-attributes-group", 44 "subscription-attributes-group", 45 "event-notification-attributes-group", 46 "reserved-delimiter-08", 47 "reserved-delimiter-09", 48 "reserved-delimiter-0a", 49 "reserved-delimiter-0b", 50 "reserved-delimiter-0c", 51 "reserved-delimiter-0d", 52 "reserved-delimiter-0e", 53 "reserved-delimiter-0f", 54 /* value tags */ 55 "unsupported", 56 "reserved-default", 57 "unknown", 58 "no-value", 59 "reserved-out-of-band-14", 60 "not-settable", 61 "delete-attribute", 62 "admin-define", 63 "reserved-out-of-band-18", 64 "reserved-out-of-band-19", 65 "reserved-out-of-band-1a", 66 "reserved-out-of-band-1b", 67 "reserved-out-of-band-1c", 68 "reserved-out-of-band-1d", 69 "reserved-out-of-band-1e", 70 "reserved-out-of-band-1f", 71 "reserved", 72 "integer", 73 "boolean", 74 "enum", 75 "reserved-integer-type-24", 76 "reserved-integer-type-25", 77 "reserved-integer-type-26", 78 "reserved-integer-type-27", 79 "reserved-integer-type-28", 80 "reserved-integer-type-29", 81 "reserved-integer-type-2a", 82 "reserved-integer-type-2b", 83 "reserved-integer-type-2c", 84 "reserved-integer-type-2d", 85 "reserved-integer-type-2e", 86 "reserved-integer-type-2f", 87 "octetString", 88 "dateTime", 89 "resolution", 90 "rangeOfInteger", 91 "begCollection", 92 "textWithLanguage", 93 "nameWithLanguage", 94 "endCollection", 95 "reserved-octetString-38", 96 "reserved-octetString-39", 97 "reserved-octetString-3a", 98 "reserved-octetString-3b", 99 "reserved-octetString-3c", 100 "reserved-octetString-3d", 101 "reserved-octetString-3e", 102 "reserved-octetString-3f", 103 "reserved", 104 "textWithoutLanguage", 105 "nameWithoutLanguage", 106 "reserved", 107 "keyword", 108 "uri", 109 "uriScheme", 110 "charset", 111 "naturalLanguage", 112 "mimeMediaType", 113 "memberAttrName", 114 "reserved-charString-4b", 115 "reserved-charString-4c", 116 "reserved-charString-4d", 117 "reserved-charString-4e", 118 "reserved-charString-4f", 119 "reserved-charString-50", 120 "reserved-charString-51", 121 "reserved-charString-52", 122 "reserved-charString-53", 123 "reserved-charString-54", 124 "reserved-charString-55", 125 "reserved-charString-56", 126 "reserved-charString-57", 127 "reserved-charString-58", 128 "reserved-charString-59", 129 "reserved-charString-5a", 130 "reserved-charString-5b", 131 "reserved-charString-5c", 132 "reserved-charString-5d", 133 "reserved-charString-5e", 134 "reserved-charString-5f", 135 }; 136 137 static char *opid_strings[] = { 138 "reserved-0x0000", 139 "reserved-0x0001", 140 "Print-Job", 141 "Print-URI", 142 "Validate-Job", 143 "Create-Job", 144 "Send-Document", 145 "Send-URI", 146 "Cancel-Job", 147 "Get-Job-Attributes", 148 "Get-Jobs", 149 "Get-Printer-Attributes", 150 "Hold-Job", 151 "Release-Job", 152 "Restart-Job", 153 "reserved-0x000f", 154 "Pause-Printer", 155 "Resume-Printer", 156 "Purge-Jobs", 157 "Set-Printer-Attributes", 158 "Set-Job-Attributes", 159 "Get-Printer-Supported-Values", 160 "Create-Printer-Subscription", 161 "Create-Job-Subscription", 162 "Get-Subscription-Attributes", 163 "Get-Subscriptions", 164 "Renew-Subscription", 165 "Cancel-Subscription", 166 "Get-Notifications", 167 "Send-Notifications", 168 "Get-Resource-Attributes-deleted", 169 "Get-Resource-Data-deleted", 170 "Get-Resources-deleted", 171 "Get-Print-Support-Files", 172 "Disable-Printer", 173 "Pause-Printer-After-Current-Job", 174 "Hold-New-Jobs", 175 "Release-Held-New-Jobs", 176 "Deactivate-Printer", 177 "Activate-Printer", 178 "Restart-Printer", 179 "Shutdown-Printer", 180 "Startup-Printer", 181 "Reprocess-Job", 182 "Cancel-Current-Job", 183 "Suspend-Current-Job", 184 "Resume-Job", 185 "Promote-Job", 186 "Schedule-Job-After", 187 NULL 188 }; 189 190 static char *res_opid_strings[] = { 191 "Microsoft-0x4000", 192 "CUPS-Get-Default", 193 "CUPS-Get-Printers", 194 "CUPS-Add-Printer", 195 "CUPS-Delete-Printer", 196 "CUPS-Get-Classes", 197 "CUPS-Add-Class", 198 "CUPS-Delete-Class", 199 "CUPS-Accept-Jobs", 200 "CUPS-Reject-Jobs", 201 "CUPS-Set-Default", 202 "CUPS-Get-Devices", 203 "CUPS-Get-PPDs", 204 "CUPS-Move-Job", 205 "CUPS-0x400e", 206 "CUPS-0x400f", 207 "Peerless-0x4010", 208 NULL 209 }; 210 #define KNOWN_RESERVED_MIN 0x4000 211 #define KNOWN_RESERVED_MAX 0x4010 212 213 static char *ok_status_strings[] = { 214 "successful-ok", 215 "successful-ok-ignored-or-substituted-attributes", 216 "successful-ok-conflicting-attributes", 217 "successful-ok-ignored-subscriptions", 218 "successful-ok-ignored-notifications", 219 "successful-ok-too-many-events", 220 "successful-ok-but-cancel-subscription" 221 }; 222 223 static char *redir_status_strings[] = { 224 "redirection-other-site" 225 }; 226 227 static char *client_error_status_strings[] = { 228 "client-error-bad-request", 229 "client-error-forbidden", 230 "client-error-not-authenticated", 231 "client-error-not-authorized", 232 "client-error-not-possible", 233 "client-error-timeout", 234 "client-error-not-found", 235 "client-error-gone", 236 "client-error-request-entity-too-large", 237 "client-error-request-value-too-long", 238 "client-error-document-format-not-supported", 239 "client-error-attributes-or-values-not-supported", 240 "client-error-uri-scheme-not-supported", 241 "client-error-charset-not-supported", 242 "client-error-conflicting-attributes", 243 "client-error-compression-not-supported", 244 "client-error-compression-error", 245 "client-error-document-format-error", 246 "client-error-document-access-error", 247 "client-error-attributes-not-settable", 248 "client-error-ignored-all-subscriptions", 249 "client-error-too-many-subscriptions", 250 "client-error-ignored-all-notifications", 251 "client-error-print-support-file-not-found" 252 }; 253 254 static char *server_error_status_strings[] = { 255 "server-error-internal-error", 256 "server-error-operation-not-supported", 257 "server-error-service-unavailable", 258 "server-error-version-not-supported", 259 "server-error-device-error", 260 "server-error-temporary-error", 261 "server-error-not-accepting-jobs", 262 "server-error-busy", 263 "server-error-job-canceled", 264 "server-error-multiple-document-jobs-not-supported", 265 "server-error-printer-is-deactivated" 266 }; 267 268 char * 269 ipp_tag_string(int8_t id, char *ret, size_t len) 270 { 271 if (id < VTAG_MAX) 272 (void) strlcpy(ret, tag_strings[id], len); 273 else if (id == VTAG_EXTEND) 274 (void) strlcpy(ret, "extension", len); 275 else 276 (void) snprintf(ret, len, "bogus-0x%.2x", id); 277 278 return (ret); 279 } 280 281 char * 282 ipp_opid_string(int16_t id, char *ret, size_t len) 283 { 284 if (id < OPID_RESERVED_MIN) 285 (void) strlcpy(ret, opid_strings[id], len); 286 else if (id < OPID_RESERVED_VENDOR_MIN) 287 (void) snprintf(ret, len, "reserved-0x%.4x", id); 288 else if (id <= KNOWN_RESERVED_MAX) 289 (void) strlcpy(ret, 290 res_opid_strings[id - KNOWN_RESERVED_MIN], len); 291 else /* if (id <= OPID_RESERVED_VENDOR_MAX) */ 292 (void) snprintf(ret, len, "reserved-vendor-0x%.4x", id); 293 294 return (ret); 295 } 296 297 int16_t 298 ipp_string_opid(char *string) 299 { 300 int i; 301 302 for (i = 0; opid_strings[i] != NULL; i++) 303 if (strcasecmp(opid_strings[i], string) == 0) 304 return (i); 305 306 for (i = 0; res_opid_strings[i] != NULL; i++) 307 if (strcasecmp(res_opid_strings[i], string) == 0) 308 return (0x4000 + i); 309 310 return (-1); 311 } 312 313 char * 314 ipp_status_string(int16_t id, char *ret, size_t len) 315 { 316 if (id <= IPP_OK_MAX) 317 (void) strlcpy(ret, ok_status_strings[id], len); 318 else if (id >= IPP_REDIR_MIN && id <= IPP_REDIR_MAX) 319 (void) strlcpy(ret, 320 redir_status_strings[id - IPP_REDIR_MIN], len); 321 else if (id >= IPP_CERR_MIN && id <= IPP_CERR_MAX) 322 (void) strlcpy(ret, 323 client_error_status_strings[id - IPP_CERR_MIN], len); 324 else if (id >= IPP_SERR_MIN && id <= IPP_SERR_MAX) 325 (void) strlcpy(ret, 326 server_error_status_strings[id - IPP_SERR_MIN], len); 327 else 328 (void) snprintf(ret, len, "bogus-0x%.4hx", id); 329 330 return (ret); 331 } 332 333 334 335 /* 336 * attribute template handling routines 337 */ 338 char *job_template[] = { 339 "copies", 340 "finishing", 341 "job-hold-until", 342 "job-priority", 343 "job-sheets", 344 "media", 345 "multiple-document-handling", 346 "number-up", 347 "page-ranges-supported", 348 "print-quality", 349 "printer-resoultion", 350 "sides", 351 NULL 352 }; 353 354 char *job_description[] = { 355 "copies-default", "copies-supported", 356 "finishing-default", "finishing-supported", 357 "job-hold-until-default", "job-hold-until-supported", 358 "job-priority-default", "job-priority-supported", 359 "job-sheets-default", "job-sheets-supported", 360 "media-default", "media-supported", 361 "multiple-document-handling-default", 362 "multiple-document-handling-supported", 363 "number-up-default", "number-up-supported", 364 "page-ranges-supported", 365 "print-quality-default", "print-quality-supported", 366 "printer-resoultion-default", "printer-resoultion-supported", 367 "sides-default", "sides-supported", 368 NULL 369 }; 370 371 char *printer_description[] = { 372 "printer-uri-supported", 373 "uri-security-supported", 374 "uri-authentication-supported", 375 "printer-name", 376 "printer-location", 377 "printer-info", 378 "printer-more-info", 379 "printer-driver-installer", 380 "printer-make-and-model", 381 "printer-more-info-manufacturer", 382 "printer-state", 383 "printer-state-reasons", 384 "printer-state-message", 385 "ipp-versions-supported", 386 "multiple-document-jobs-supported", 387 "charset-configured", 388 "charset-supported", 389 "natural-language-configured", 390 "generated-natural-language-supported", 391 "document-format-default", 392 "document-format-supported", 393 "printer-is-accepting-jobs", 394 "queued-job-count", 395 "printer-message-from-operator", 396 "color-supported", 397 "reference-uri-schemes-supported", 398 "pdl-override-supported", 399 "printer-up-time", 400 "printer-current-time", 401 "multiple-operation-time-out", 402 "compression-supported", 403 "job-k-octets-supported", 404 "job-impressions-supported", 405 "job-media-sheets-supported", 406 "pages-per-minute", 407 "pages-per-minute-color", 408 NULL 409 }; 410