2 * "$Id: ipp-support.c 5903 2006-08-29 20:45:15Z mike $"
4 * Internet Printing Protocol support functions for the Common UNIX
5 * Printing System (CUPS).
7 * Copyright 1997-2006 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",
59 "successful-ok-events-complete"
61 * const ipp_status_400s
[] = /* Client errors */
63 "client-error-bad-request",
64 "client-error-forbidden",
65 "client-error-not-authenticated",
66 "client-error-not-authorized",
67 "client-error-not-possible",
68 "client-error-timeout",
69 "client-error-not-found",
71 "client-error-request-entity-too-large",
72 "client-error-request-value-too-long",
73 "client-error-document-format-not-supported",
74 "client-error-attributes-or-values-not-supported",
75 "client-error-uri-scheme-not-supported",
76 "client-error-charset-not-supported",
77 "client-error-conflicting-attributes",
78 "client-error-compression-not-supported",
79 "client-error-compression-error",
80 "client-error-document-format-error",
81 "client-error-document-access-error",
82 "client-error-attributes-not-settable",
83 "client-error-ignored-all-subscriptions",
84 "client-error-too-many-subscriptions",
85 "client-error-ignored-all-notifications",
86 "client-error-print-support-file-not-found"
88 * const ipp_status_500s
[] = /* Server errors */
90 "server-error-internal-error",
91 "server-error-operation-not-supported",
92 "server-error-service-unavailable",
93 "server-error-version-not-supported",
94 "server-error-device-error",
95 "server-error-temporary-error",
96 "server-error-not-accepting-jobs",
98 "server-error-job-canceled",
99 "server-error-multiple-document-jobs-not-supported",
100 "server-error-printer-is-deactivated"
102 static char * const ipp_std_ops
[] =
104 /* 0x0000 - 0x000f */
105 "", "", "Print-Job", "Print-URI",
106 "Validate-Job", "Create-Job", "Send-Document",
107 "Send-URI", "Cancel-Job", "Get-Job-Attributes",
108 "Get-Jobs", "Get-Printer-Attributes",
109 "Hold-Job", "Release-Job", "Restart-Job", "",
111 /* 0x0010 - 0x001f */
112 "Pause-Printer", "Resume-Printer",
113 "Purge-Jobs", "Set-Printer-Attributes",
114 "Set-Job-Attributes",
115 "Get-Printer-Supported-Values",
116 "Create-Printer-Subscription",
117 "Create-Job-Subscription",
118 "Get-Subscription-Attributes",
119 "Get-Subscriptions", "Renew-Subscription",
120 "Cancel-Subscription", "Get-Notifications",
121 "Send-Notifications", "", "",
123 /* 0x0020 - 0x002f */
125 "Get-Printer-Support-Files",
128 "Pause-Printer-After-Current-Job",
130 "Release-Held-New-Jobs",
131 "Deactivate-Printer",
137 "Cancel-Current-Job",
138 "Suspend-Current-Job",
141 /* 0x0030 - 0x0031 */
145 * const ipp_cups_ops
[] =
149 "CUPS-Add-Modify-Printer",
150 "CUPS-Delete-Printer",
152 "CUPS-Add-Modify-Class",
160 "CUPS-Authenticate-Job"
165 * 'ippErrorString()' - Return a name for the given status code.
168 const char * /* O - Text string */
169 ippErrorString(ipp_status_t error
) /* I - Error status */
171 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
175 * See if the error code is a known value...
178 if (error
>= IPP_OK
&& error
<= IPP_OK_EVENTS_COMPLETE
)
179 return (ipp_status_oks
[error
]);
180 else if (error
== IPP_REDIRECTION_OTHER_SITE
)
181 return ("redirection-other-site");
182 else if (error
>= IPP_BAD_REQUEST
&& error
<= IPP_PRINT_SUPPORT_FILE_NOT_FOUND
)
183 return (ipp_status_400s
[error
- IPP_BAD_REQUEST
]);
184 else if (error
>= IPP_INTERNAL_ERROR
&& error
<= IPP_PRINTER_IS_DEACTIVATED
)
185 return (ipp_status_500s
[error
- IPP_INTERNAL_ERROR
]);
188 * No, build an "unknown-xxxx" error string...
191 sprintf(cg
->ipp_unknown
, "unknown-%04x", error
);
193 return (cg
->ipp_unknown
);
198 * 'ippErrorValue()' - Return a status code for the given name.
203 ipp_status_t
/* O - IPP status code */
204 ippErrorValue(const char *name
) /* I - Name */
209 for (i
= 0; i
< (sizeof(ipp_status_oks
) / sizeof(ipp_status_oks
[0])); i
++)
210 if (!strcasecmp(name
, ipp_status_oks
[i
]))
211 return ((ipp_status_t
)i
);
213 if (!strcasecmp(name
, "redirection-other-site"))
214 return (IPP_REDIRECTION_OTHER_SITE
);
216 for (i
= 0; i
< (sizeof(ipp_status_400s
) / sizeof(ipp_status_400s
[0])); i
++)
217 if (!strcasecmp(name
, ipp_status_400s
[i
]))
218 return ((ipp_status_t
)(i
+ 0x400));
220 for (i
= 0; i
< (sizeof(ipp_status_500s
) / sizeof(ipp_status_500s
[0])); i
++)
221 if (!strcasecmp(name
, ipp_status_500s
[i
]))
222 return ((ipp_status_t
)(i
+ 0x500));
224 return ((ipp_status_t
)-1);
229 * 'ippOpString()' - Return a name for the given operation id.
234 const char * /* O - Name */
235 ippOpString(ipp_op_t op
) /* I - Operation ID */
237 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
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_AUTHENTICATE_JOB
)
249 return (ipp_cups_ops
[op
- CUPS_GET_DEFAULT
]);
252 * No, build an "unknown-xxxx" operation string...
255 sprintf(cg
->ipp_unknown
, "unknown-%04x", op
);
257 return (cg
->ipp_unknown
);
262 * 'ippOpValue()' - Return an operation id for the given name.
267 ipp_op_t
/* O - Operation ID */
268 ippOpValue(const char *name
) /* I - Textual name */
273 for (i
= 0; i
< (sizeof(ipp_std_ops
) / sizeof(ipp_std_ops
[0])); i
++)
274 if (!strcasecmp(name
, ipp_std_ops
[i
]))
275 return ((ipp_op_t
)i
);
277 if (!strcasecmp(name
, "windows-ext"))
278 return (IPP_PRIVATE
);
280 for (i
= 0; i
< (sizeof(ipp_cups_ops
) / sizeof(ipp_cups_ops
[0])); i
++)
281 if (!strcasecmp(name
, ipp_cups_ops
[i
]))
282 return ((ipp_op_t
)(i
+ 0x4001));
284 if (!strcasecmp(name
, "CUPS-Add-Class"))
285 return (CUPS_ADD_MODIFY_CLASS
);
287 if (!strcasecmp(name
, "CUPS-Add-Printer"))
288 return (CUPS_ADD_MODIFY_PRINTER
);
290 return ((ipp_op_t
)-1);
295 * 'ippPort()' - Return the default IPP port number.
298 int /* O - Port number */
301 const char *ipp_port
; /* IPP_PORT environment variable */
302 struct servent
*port
; /* Port number info */
303 int portnum
; /* Port number */
304 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
307 DEBUG_puts("ippPort()");
312 * See if the server definition includes the port number...
315 DEBUG_puts("ippPort: Not initialized...");
321 puts("ippPort: Set via cupsServer()...");
327 if ((ipp_port
= getenv("IPP_PORT")) != NULL
)
329 DEBUG_puts("ippPort: Set via IPP_PORT...");
330 portnum
= atoi(ipp_port
);
332 else if ((port
= getservbyname("ipp", NULL
)) == NULL
)
334 DEBUG_puts("ippPort: Set via CUPS_DEFAULT_IPP_PORT...");
335 portnum
= CUPS_DEFAULT_IPP_PORT
;
339 DEBUG_puts("ippPort: Set via ipp service entry...");
340 portnum
= ntohs(port
->s_port
);
344 cg
->ipp_port
= portnum
;
347 DEBUG_printf(("ippPort: Returning %d...\n", cg
->ipp_port
));
349 return (cg
->ipp_port
);
354 * 'ippSetPort()' - Set the default port number.
358 ippSetPort(int p
) /* I - Port number to use */
360 DEBUG_printf(("ippSetPort(p=%d)\n", p
));
362 _cupsGlobals()->ipp_port
= p
;
367 * End of "$Id: ipp-support.c 5903 2006-08-29 20:45:15Z mike $".