4 * Internet Printing Protocol support functions for the Common UNIX
5 * Printing System (CUPS).
7 * Copyright 1997-2005 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Easy Software Products and are protected by Federal
11 * copyright law. Distribution and use rights are outlined in the file
12 * "LICENSE.txt" which should have been included with this file. If this
13 * file is missing or damaged please contact Easy Software Products
16 * Attn: CUPS Licensing Information
17 * Easy Software Products
18 * 44141 Airport View Drive, Suite 204
19 * Hollywood, Maryland 20636 USA
21 * Voice: (301) 373-9600
22 * EMail: cups-info@cups.org
23 * WWW: http://www.cups.org
25 * This file is subject to the Apple OS-Developed Software exception.
29 * ippErrorString() - Return a name for the given status code.
30 * ippErrorValue() - Return a status code for the given name.
31 * ippOpString() - Return a name for the given operation id.
32 * ippOpValue() - Return an operation id for the given name.
33 * ippPort() - Return the default IPP port number.
34 * ippSetPort() - Set the default port number.
38 * Include necessary headers...
55 static int ipp_port
= 0;
56 static const char * const ipp_status_oks
[] = /* "OK" status codes */
59 "successful-ok-ignored-or-substituted-attributes",
60 "successful-ok-conflicting-attributes",
61 "successful-ok-ignored-subscriptions",
62 "successful-ok-ignored-notifications",
63 "successful-ok-too-many-events",
64 "successful-ok-but-cancel-subscription"
66 * const ipp_status_400s
[] = /* Client errors */
68 "client-error-bad-request",
69 "client-error-forbidden",
70 "client-error-not-authenticated",
71 "client-error-not-authorized",
72 "client-error-not-possible",
73 "client-error-timeout",
74 "client-error-not-found",
76 "client-error-request-entity-too-large",
77 "client-error-request-value-too-long",
78 "client-error-document-format-not-supported",
79 "client-error-attributes-or-values-not-supported",
80 "client-error-uri-scheme-not-supported",
81 "client-error-charset-not-supported",
82 "client-error-conflicting-attributes",
83 "client-error-compression-not-supported",
84 "client-error-compression-error",
85 "client-error-document-format-error",
86 "client-error-document-access-error",
87 "client-error-attributes-not-settable",
88 "client-error-ignored-all-subscriptions",
89 "client-error-too-many-subscriptions",
90 "client-error-ignored-all-notifications",
91 "client-error-print-support-file-not-found"
93 * const ipp_status_500s
[] = /* Server errors */
95 "server-error-internal-error",
96 "server-error-operation-not-supported",
97 "server-error-service-unavailable",
98 "server-error-version-not-supported",
99 "server-error-device-error",
100 "server-error-temporary-error",
101 "server-error-not-accepting-jobs",
103 "server-error-job-canceled",
104 "server-error-multiple-document-jobs-not-supported",
105 "server-error-printer-is-deactivated"
107 static char * const ipp_std_ops
[] =
109 /* 0x0000 - 0x000f */
110 "", "", "Print-Job", "Print-URI",
111 "Validate-Job", "Create-Job", "Send-Document",
112 "Send-URI", "Cancel-Job", "Get-Job-Attributes",
113 "Get-Jobs", "Get-Printer-Attributes",
114 "Hold-Job", "Release-Job", "Restart-Job", "",
116 /* 0x0010 - 0x001f */
117 "Pause-Printer", "Resume-Printer",
118 "Purge-Jobs", "Set-Printer-Attributes",
119 "Set-Job-Attributes",
120 "Get-Printer-Supported-Values",
121 "Create-Printer-Subscription",
122 "Create-Job-Subscription",
123 "Get-Subscription-Attributes",
124 "Get-Subscriptions", "Renew-Subscription",
125 "Cancel-Subscription", "Get-Notifications",
126 "Send-Notifications", "", "",
128 /* 0x0020 - 0x002f */
130 "Get-Printer-Support-Files",
133 "Pause-Printer-After-Current-Job",
135 "Release-Held-New-Jobs",
136 "Deactivate-Printer",
142 "Cancel-Current-Job",
143 "Suspend-Current-Job",
146 /* 0x0030 - 0x0031 */
150 * const ipp_cups_ops
[] =
155 "CUPS-Delete-Printer",
169 * 'ippErrorString()' - Return a name for the given status code.
172 const char * /* O - Text string */
173 ippErrorString(ipp_status_t error
) /* I - Error status */
175 static char unknown
[255]; /* Unknown error statuses */
179 * See if the error code is a known value...
182 if (error
>= IPP_OK
&& error
<= IPP_OK_BUT_CANCEL_SUBSCRIPTION
)
183 return (ipp_status_oks
[error
]);
184 else if (error
== IPP_REDIRECTION_OTHER_SITE
)
185 return ("redirection-other-site");
186 else if (error
>= IPP_BAD_REQUEST
&& error
<= IPP_PRINT_SUPPORT_FILE_NOT_FOUND
)
187 return (ipp_status_400s
[error
- IPP_BAD_REQUEST
]);
188 else if (error
>= IPP_INTERNAL_ERROR
&& error
<= IPP_PRINTER_IS_DEACTIVATED
)
189 return (ipp_status_500s
[error
- IPP_INTERNAL_ERROR
]);
192 * No, build an "unknown-xxxx" error string...
195 sprintf(unknown
, "unknown-%04x", error
);
202 * 'ippErrorValue()' - Return a status code for the given name.
205 ipp_status_t
/* O - IPP status code */
206 ippErrorValue(const char *name
) /* I - Name */
211 for (i
= 0; i
< (sizeof(ipp_status_oks
) / sizeof(ipp_status_oks
[0])); i
++)
212 if (!strcasecmp(name
, ipp_status_oks
[i
]))
213 return ((ipp_status_t
)i
);
215 if (!strcasecmp(name
, "redirection-other-site"))
216 return (IPP_REDIRECTION_OTHER_SITE
);
218 for (i
= 0; i
< (sizeof(ipp_status_400s
) / sizeof(ipp_status_400s
[0])); i
++)
219 if (!strcasecmp(name
, ipp_status_400s
[i
]))
220 return ((ipp_status_t
)(i
+ 0x400));
222 for (i
= 0; i
< (sizeof(ipp_status_500s
) / sizeof(ipp_status_500s
[0])); i
++)
223 if (!strcasecmp(name
, ipp_status_500s
[i
]))
224 return ((ipp_status_t
)(i
+ 0x500));
226 return ((ipp_status_t
)-1);
231 * 'ippOpString()' - Return a name for the given operation id.
234 const char * /* O - Name */
235 ippOpString(ipp_op_t op
) /* I - Operation ID */
237 static char unknown
[255]; /* Unknown error statuses */
241 * See if the operation ID is a known value...
244 if (op
>= IPP_PRINT_JOB
&& op
<= IPP_SCHEDULE_JOB_AFTER
)
245 return (ipp_std_ops
[op
]);
246 else if (op
== IPP_PRIVATE
)
247 return ("windows-ext");
248 else if (op
>= CUPS_GET_DEFAULT
&& op
<= CUPS_MOVE_JOB
)
249 return (ipp_cups_ops
[op
- CUPS_GET_DEFAULT
]);
252 * No, build an "unknown-xxxx" operation string...
255 sprintf(unknown
, "unknown-%04x", op
);
262 * 'ippOpValue()' - Return an operation id for the given name.
265 ipp_op_t
/* O - Operation ID */
266 ippOpValue(const char *name
) /* I - Textual name */
271 for (i
= 0; i
< (sizeof(ipp_std_ops
) / sizeof(ipp_std_ops
[0])); i
++)
272 if (!strcasecmp(name
, ipp_std_ops
[i
]))
273 return ((ipp_op_t
)i
);
275 if (!strcasecmp(name
, "windows-ext"))
276 return (IPP_PRIVATE
);
278 for (i
= 0; i
< (sizeof(ipp_cups_ops
) / sizeof(ipp_cups_ops
[0])); i
++)
279 if (!strcasecmp(name
, ipp_cups_ops
[i
]))
280 return ((ipp_op_t
)(i
+ 0x4001));
282 return ((ipp_op_t
)-1);
287 * 'ippPort()' - Return the default IPP port number.
290 int /* O - Port number */
293 const char *server_port
; /* SERVER_PORT environment variable */
294 struct servent
*port
; /* Port number info */
299 else if ((server_port
= getenv("IPP_PORT")) != NULL
)
300 return (ipp_port
= atoi(server_port
));
301 else if ((port
= getservbyname("ipp", NULL
)) == NULL
)
302 return (ipp_port
= CUPS_DEFAULT_IPP_PORT
);
304 return (ipp_port
= ntohs(port
->s_port
));
309 * 'ippSetPort()' - Set the default port number.
313 ippSetPort(int p
) /* I - Port number to use */