2 * "$Id: ipp-support.c 6649 2007-07-11 21:46:42Z mike $"
4 * Internet Printing Protocol support functions for the Common UNIX
5 * Printing System (CUPS).
7 * Copyright 2007 by Apple Inc.
8 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
10 * These coded instructions, statements, and computer programs are the
11 * property of Apple Inc. and are protected by Federal copyright
12 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
13 * which should have been included with this file. If this file is
14 * file is missing or damaged, see the license at "http://www.cups.org/".
16 * This file is subject to the Apple OS-Developed Software exception.
20 * ippErrorString() - Return a name for the given status code.
21 * ippErrorValue() - Return a status code for the given name.
22 * ippOpString() - Return a name for the given operation id.
23 * ippOpValue() - Return an operation id for the given name.
24 * ippPort() - Return the default IPP port number.
25 * ippSetPort() - Set the default port number.
29 * Include necessary headers...
41 static const char * const ipp_status_oks
[] = /* "OK" status codes */
44 "successful-ok-ignored-or-substituted-attributes",
45 "successful-ok-conflicting-attributes",
46 "successful-ok-ignored-subscriptions",
47 "successful-ok-ignored-notifications",
48 "successful-ok-too-many-events",
49 "successful-ok-but-cancel-subscription",
50 "successful-ok-events-complete"
52 * const ipp_status_400s
[] = /* Client errors */
54 "client-error-bad-request",
55 "client-error-forbidden",
56 "client-error-not-authenticated",
57 "client-error-not-authorized",
58 "client-error-not-possible",
59 "client-error-timeout",
60 "client-error-not-found",
62 "client-error-request-entity-too-large",
63 "client-error-request-value-too-long",
64 "client-error-document-format-not-supported",
65 "client-error-attributes-or-values-not-supported",
66 "client-error-uri-scheme-not-supported",
67 "client-error-charset-not-supported",
68 "client-error-conflicting-attributes",
69 "client-error-compression-not-supported",
70 "client-error-compression-error",
71 "client-error-document-format-error",
72 "client-error-document-access-error",
73 "client-error-attributes-not-settable",
74 "client-error-ignored-all-subscriptions",
75 "client-error-too-many-subscriptions",
76 "client-error-ignored-all-notifications",
77 "client-error-print-support-file-not-found"
79 * const ipp_status_500s
[] = /* Server errors */
81 "server-error-internal-error",
82 "server-error-operation-not-supported",
83 "server-error-service-unavailable",
84 "server-error-version-not-supported",
85 "server-error-device-error",
86 "server-error-temporary-error",
87 "server-error-not-accepting-jobs",
89 "server-error-job-canceled",
90 "server-error-multiple-document-jobs-not-supported",
91 "server-error-printer-is-deactivated"
93 static char * const ipp_std_ops
[] =
96 "", "", "Print-Job", "Print-URI",
97 "Validate-Job", "Create-Job", "Send-Document",
98 "Send-URI", "Cancel-Job", "Get-Job-Attributes",
99 "Get-Jobs", "Get-Printer-Attributes",
100 "Hold-Job", "Release-Job", "Restart-Job", "",
102 /* 0x0010 - 0x001f */
103 "Pause-Printer", "Resume-Printer",
104 "Purge-Jobs", "Set-Printer-Attributes",
105 "Set-Job-Attributes",
106 "Get-Printer-Supported-Values",
107 "Create-Printer-Subscription",
108 "Create-Job-Subscription",
109 "Get-Subscription-Attributes",
110 "Get-Subscriptions", "Renew-Subscription",
111 "Cancel-Subscription", "Get-Notifications",
112 "Send-Notifications", "", "",
114 /* 0x0020 - 0x002f */
116 "Get-Printer-Support-Files",
119 "Pause-Printer-After-Current-Job",
121 "Release-Held-New-Jobs",
122 "Deactivate-Printer",
128 "Cancel-Current-Job",
129 "Suspend-Current-Job",
132 /* 0x0030 - 0x0031 */
136 * const ipp_cups_ops
[] =
140 "CUPS-Add-Modify-Printer",
141 "CUPS-Delete-Printer",
143 "CUPS-Add-Modify-Class",
151 "CUPS-Authenticate-Job",
157 * 'ippErrorString()' - Return a name for the given status code.
160 const char * /* O - Text string */
161 ippErrorString(ipp_status_t error
) /* I - Error status */
163 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
167 * See if the error code is a known value...
170 if (error
>= IPP_OK
&& error
<= IPP_OK_EVENTS_COMPLETE
)
171 return (ipp_status_oks
[error
]);
172 else if (error
== IPP_REDIRECTION_OTHER_SITE
)
173 return ("redirection-other-site");
174 else if (error
== CUPS_SEE_OTHER
)
175 return ("cups-see-other");
176 else if (error
>= IPP_BAD_REQUEST
&& error
<= IPP_PRINT_SUPPORT_FILE_NOT_FOUND
)
177 return (ipp_status_400s
[error
- IPP_BAD_REQUEST
]);
178 else if (error
>= IPP_INTERNAL_ERROR
&& error
<= IPP_PRINTER_IS_DEACTIVATED
)
179 return (ipp_status_500s
[error
- IPP_INTERNAL_ERROR
]);
182 * No, build an "unknown-xxxx" error string...
185 sprintf(cg
->ipp_unknown
, "unknown-%04x", error
);
187 return (cg
->ipp_unknown
);
192 * 'ippErrorValue()' - Return a status code for the given name.
197 ipp_status_t
/* O - IPP status code */
198 ippErrorValue(const char *name
) /* I - Name */
203 for (i
= 0; i
< (sizeof(ipp_status_oks
) / sizeof(ipp_status_oks
[0])); i
++)
204 if (!strcasecmp(name
, ipp_status_oks
[i
]))
205 return ((ipp_status_t
)i
);
207 if (!strcasecmp(name
, "redirection-other-site"))
208 return (IPP_REDIRECTION_OTHER_SITE
);
210 if (!strcasecmp(name
, "cups-see-other"))
211 return (CUPS_SEE_OTHER
);
213 for (i
= 0; i
< (sizeof(ipp_status_400s
) / sizeof(ipp_status_400s
[0])); i
++)
214 if (!strcasecmp(name
, ipp_status_400s
[i
]))
215 return ((ipp_status_t
)(i
+ 0x400));
217 for (i
= 0; i
< (sizeof(ipp_status_500s
) / sizeof(ipp_status_500s
[0])); i
++)
218 if (!strcasecmp(name
, ipp_status_500s
[i
]))
219 return ((ipp_status_t
)(i
+ 0x500));
221 return ((ipp_status_t
)-1);
226 * 'ippOpString()' - Return a name for the given operation id.
231 const char * /* O - Name */
232 ippOpString(ipp_op_t op
) /* I - Operation ID */
234 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
238 * See if the operation ID is a known value...
241 if (op
>= IPP_PRINT_JOB
&& op
<= IPP_SCHEDULE_JOB_AFTER
)
242 return (ipp_std_ops
[op
]);
243 else if (op
== IPP_PRIVATE
)
244 return ("windows-ext");
245 else if (op
>= CUPS_GET_DEFAULT
&& op
<= CUPS_GET_PPD
)
246 return (ipp_cups_ops
[op
- CUPS_GET_DEFAULT
]);
249 * No, build an "unknown-xxxx" operation string...
252 sprintf(cg
->ipp_unknown
, "unknown-%04x", op
);
254 return (cg
->ipp_unknown
);
259 * 'ippOpValue()' - Return an operation id for the given name.
264 ipp_op_t
/* O - Operation ID */
265 ippOpValue(const char *name
) /* I - Textual name */
270 for (i
= 0; i
< (sizeof(ipp_std_ops
) / sizeof(ipp_std_ops
[0])); i
++)
271 if (!strcasecmp(name
, ipp_std_ops
[i
]))
272 return ((ipp_op_t
)i
);
274 if (!strcasecmp(name
, "windows-ext"))
275 return (IPP_PRIVATE
);
277 for (i
= 0; i
< (sizeof(ipp_cups_ops
) / sizeof(ipp_cups_ops
[0])); i
++)
278 if (!strcasecmp(name
, ipp_cups_ops
[i
]))
279 return ((ipp_op_t
)(i
+ 0x4001));
281 if (!strcasecmp(name
, "CUPS-Add-Class"))
282 return (CUPS_ADD_MODIFY_CLASS
);
284 if (!strcasecmp(name
, "CUPS-Add-Printer"))
285 return (CUPS_ADD_MODIFY_PRINTER
);
287 return ((ipp_op_t
)-1);
292 * 'ippPort()' - Return the default IPP port number.
295 int /* O - Port number */
298 const char *ipp_port
; /* IPP_PORT environment variable */
299 struct servent
*port
; /* Port number info */
300 int portnum
; /* Port number */
301 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
304 DEBUG_puts("ippPort()");
309 * See if the server definition includes the port number...
312 DEBUG_puts("ippPort: Not initialized...");
318 puts("ippPort: Set via cupsServer()...");
324 if ((ipp_port
= getenv("IPP_PORT")) != NULL
)
326 DEBUG_puts("ippPort: Set via IPP_PORT...");
327 portnum
= atoi(ipp_port
);
329 else if ((port
= getservbyname("ipp", NULL
)) == NULL
)
331 DEBUG_puts("ippPort: Set via CUPS_DEFAULT_IPP_PORT...");
332 portnum
= CUPS_DEFAULT_IPP_PORT
;
336 DEBUG_puts("ippPort: Set via ipp service entry...");
337 portnum
= ntohs(port
->s_port
);
341 cg
->ipp_port
= portnum
;
344 DEBUG_printf(("ippPort: Returning %d...\n", cg
->ipp_port
));
346 return (cg
->ipp_port
);
351 * 'ippSetPort()' - Set the default port number.
355 ippSetPort(int p
) /* I - Port number to use */
357 DEBUG_printf(("ippSetPort(p=%d)\n", p
));
359 _cupsGlobals()->ipp_port
= p
;
364 * End of "$Id: ipp-support.c 6649 2007-07-11 21:46:42Z mike $".