2 * "$Id: ipp-support.c 4785 2005-10-13 19:39:05Z mike $"
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...
50 static const char * const ipp_status_oks
[] = /* "OK" status codes */
53 "successful-ok-ignored-or-substituted-attributes",
54 "successful-ok-conflicting-attributes",
55 "successful-ok-ignored-subscriptions",
56 "successful-ok-ignored-notifications",
57 "successful-ok-too-many-events",
58 "successful-ok-but-cancel-subscription"
60 * const ipp_status_400s
[] = /* Client errors */
62 "client-error-bad-request",
63 "client-error-forbidden",
64 "client-error-not-authenticated",
65 "client-error-not-authorized",
66 "client-error-not-possible",
67 "client-error-timeout",
68 "client-error-not-found",
70 "client-error-request-entity-too-large",
71 "client-error-request-value-too-long",
72 "client-error-document-format-not-supported",
73 "client-error-attributes-or-values-not-supported",
74 "client-error-uri-scheme-not-supported",
75 "client-error-charset-not-supported",
76 "client-error-conflicting-attributes",
77 "client-error-compression-not-supported",
78 "client-error-compression-error",
79 "client-error-document-format-error",
80 "client-error-document-access-error",
81 "client-error-attributes-not-settable",
82 "client-error-ignored-all-subscriptions",
83 "client-error-too-many-subscriptions",
84 "client-error-ignored-all-notifications",
85 "client-error-print-support-file-not-found"
87 * const ipp_status_500s
[] = /* Server errors */
89 "server-error-internal-error",
90 "server-error-operation-not-supported",
91 "server-error-service-unavailable",
92 "server-error-version-not-supported",
93 "server-error-device-error",
94 "server-error-temporary-error",
95 "server-error-not-accepting-jobs",
97 "server-error-job-canceled",
98 "server-error-multiple-document-jobs-not-supported",
99 "server-error-printer-is-deactivated"
101 static char * const ipp_std_ops
[] =
103 /* 0x0000 - 0x000f */
104 "", "", "Print-Job", "Print-URI",
105 "Validate-Job", "Create-Job", "Send-Document",
106 "Send-URI", "Cancel-Job", "Get-Job-Attributes",
107 "Get-Jobs", "Get-Printer-Attributes",
108 "Hold-Job", "Release-Job", "Restart-Job", "",
110 /* 0x0010 - 0x001f */
111 "Pause-Printer", "Resume-Printer",
112 "Purge-Jobs", "Set-Printer-Attributes",
113 "Set-Job-Attributes",
114 "Get-Printer-Supported-Values",
115 "Create-Printer-Subscription",
116 "Create-Job-Subscription",
117 "Get-Subscription-Attributes",
118 "Get-Subscriptions", "Renew-Subscription",
119 "Cancel-Subscription", "Get-Notifications",
120 "Send-Notifications", "", "",
122 /* 0x0020 - 0x002f */
124 "Get-Printer-Support-Files",
127 "Pause-Printer-After-Current-Job",
129 "Release-Held-New-Jobs",
130 "Deactivate-Printer",
136 "Cancel-Current-Job",
137 "Suspend-Current-Job",
140 /* 0x0030 - 0x0031 */
144 * const ipp_cups_ops
[] =
149 "CUPS-Delete-Printer",
159 "CUPS-Authenticate-Job"
164 * 'ippErrorString()' - Return a name for the given status code.
167 const char * /* O - Text string */
168 ippErrorString(ipp_status_t error
) /* I - Error status */
170 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
174 * See if the error code is a known value...
177 if (error
>= IPP_OK
&& error
<= IPP_OK_BUT_CANCEL_SUBSCRIPTION
)
178 return (ipp_status_oks
[error
]);
179 else if (error
== IPP_REDIRECTION_OTHER_SITE
)
180 return ("redirection-other-site");
181 else if (error
>= IPP_BAD_REQUEST
&& error
<= IPP_PRINT_SUPPORT_FILE_NOT_FOUND
)
182 return (ipp_status_400s
[error
- IPP_BAD_REQUEST
]);
183 else if (error
>= IPP_INTERNAL_ERROR
&& error
<= IPP_PRINTER_IS_DEACTIVATED
)
184 return (ipp_status_500s
[error
- IPP_INTERNAL_ERROR
]);
187 * No, build an "unknown-xxxx" error string...
190 sprintf(cg
->ipp_unknown
, "unknown-%04x", error
);
192 return (cg
->ipp_unknown
);
197 * 'ippErrorValue()' - Return a status code for the given name.
202 ipp_status_t
/* O - IPP status code */
203 ippErrorValue(const char *name
) /* I - Name */
208 for (i
= 0; i
< (sizeof(ipp_status_oks
) / sizeof(ipp_status_oks
[0])); i
++)
209 if (!strcasecmp(name
, ipp_status_oks
[i
]))
210 return ((ipp_status_t
)i
);
212 if (!strcasecmp(name
, "redirection-other-site"))
213 return (IPP_REDIRECTION_OTHER_SITE
);
215 for (i
= 0; i
< (sizeof(ipp_status_400s
) / sizeof(ipp_status_400s
[0])); i
++)
216 if (!strcasecmp(name
, ipp_status_400s
[i
]))
217 return ((ipp_status_t
)(i
+ 0x400));
219 for (i
= 0; i
< (sizeof(ipp_status_500s
) / sizeof(ipp_status_500s
[0])); i
++)
220 if (!strcasecmp(name
, ipp_status_500s
[i
]))
221 return ((ipp_status_t
)(i
+ 0x500));
223 return ((ipp_status_t
)-1);
228 * 'ippOpString()' - Return a name for the given operation id.
233 const char * /* O - Name */
234 ippOpString(ipp_op_t op
) /* I - Operation ID */
236 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
240 * See if the operation ID is a known value...
243 if (op
>= IPP_PRINT_JOB
&& op
<= IPP_SCHEDULE_JOB_AFTER
)
244 return (ipp_std_ops
[op
]);
245 else if (op
== IPP_PRIVATE
)
246 return ("windows-ext");
247 else if (op
>= CUPS_GET_DEFAULT
&& op
<= CUPS_AUTHENTICATE_JOB
)
248 return (ipp_cups_ops
[op
- CUPS_GET_DEFAULT
]);
251 * No, build an "unknown-xxxx" operation string...
254 sprintf(cg
->ipp_unknown
, "unknown-%04x", op
);
256 return (cg
->ipp_unknown
);
261 * 'ippOpValue()' - Return an operation id for the given name.
266 ipp_op_t
/* O - Operation ID */
267 ippOpValue(const char *name
) /* I - Textual name */
272 for (i
= 0; i
< (sizeof(ipp_std_ops
) / sizeof(ipp_std_ops
[0])); i
++)
273 if (!strcasecmp(name
, ipp_std_ops
[i
]))
274 return ((ipp_op_t
)i
);
276 if (!strcasecmp(name
, "windows-ext"))
277 return (IPP_PRIVATE
);
279 for (i
= 0; i
< (sizeof(ipp_cups_ops
) / sizeof(ipp_cups_ops
[0])); i
++)
280 if (!strcasecmp(name
, ipp_cups_ops
[i
]))
281 return ((ipp_op_t
)(i
+ 0x4001));
283 return ((ipp_op_t
)-1);
288 * 'ippPort()' - Return the default IPP port number.
291 int /* O - Port number */
294 const char *ipp_port
; /* IPP_PORT environment variable */
295 struct servent
*port
; /* Port number info */
296 int portnum
; /* Port number */
297 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
302 if ((ipp_port
= getenv("IPP_PORT")) != NULL
)
303 portnum
= atoi(ipp_port
);
304 else if ((port
= getservbyname("ipp", NULL
)) == NULL
)
305 portnum
= CUPS_DEFAULT_IPP_PORT
;
307 portnum
= ntohs(port
->s_port
);
310 cg
->ipp_port
= portnum
;
313 return (cg
->ipp_port
);
318 * 'ippSetPort()' - Set the default port number.
322 ippSetPort(int p
) /* I - Port number to use */
324 fprintf(stderr
, "ippSetPort(p=%d)\n", p
);
326 _cupsGlobals()->ipp_port
= p
;
331 * End of "$Id: ipp-support.c 4785 2005-10-13 19:39:05Z mike $".