]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/ipp-support.c
Mirror 1.1.x changes...
[thirdparty/cups.git] / cups / ipp-support.c
1 /*
2 * "$Id: ipp-support.c,v 1.2.2.3 2003/01/24 20:45:12 mike Exp $"
3 *
4 * Internet Printing Protocol support functions for the Common UNIX
5 * Printing System (CUPS).
6 *
7 * Copyright 1997-2003 by Easy Software Products, all rights reserved.
8 *
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
14 * at:
15 *
16 * Attn: CUPS Licensing Information
17 * Easy Software Products
18 * 44141 Airport View Drive, Suite 204
19 * Hollywood, Maryland 20636-3111 USA
20 *
21 * Voice: (301) 373-9603
22 * EMail: cups-info@cups.org
23 * WWW: http://www.cups.org
24 *
25 * This file is subject to the Apple OS-Developed Software exception.
26 *
27 * Contents:
28 *
29 * ippErrorString() - Return a textual message for the given error
30 * message.
31 * ippPort() - Return the default IPP port number.
32 * ippSetPort() - Set the default port number.
33 */
34
35 /*
36 * Include necessary headers...
37 */
38
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include "string.h"
42 #include "language.h"
43
44 #include "ipp.h"
45 #include "debug.h"
46 #include <ctype.h>
47
48
49 /*
50 * Local globals...
51 */
52
53 static int ipp_port = 0;
54
55
56 /*
57 * 'ippErrorString()' - Return a textual message for the given error message.
58 */
59
60 const char * /* O - Text string */
61 ippErrorString(ipp_status_t error) /* I - Error status */
62 {
63 static char unknown[255]; /* Unknown error statuses */
64 static const char * const status_oks[] = /* "OK" status codes */
65 {
66 "successful-ok",
67 "successful-ok-ignored-or-substituted-attributes",
68 "successful-ok-conflicting-attributes",
69 "successful-ok-ignored-subscriptions",
70 "successful-ok-ignored-notifications",
71 "successful-ok-too-many-events",
72 "successful-ok-but-cancel-subscription"
73 },
74 * const status_400s[] = /* Client errors */
75 {
76 "client-error-bad-request",
77 "client-error-forbidden",
78 "client-error-not-authenticated",
79 "client-error-not-authorized",
80 "client-error-not-possible",
81 "client-error-timeout",
82 "client-error-not-found",
83 "client-error-gone",
84 "client-error-request-entity-too-large",
85 "client-error-request-value-too-long",
86 "client-error-document-format-not-supported",
87 "client-error-attributes-or-values-not-supported",
88 "client-error-uri-scheme-not-supported",
89 "client-error-charset-not-supported",
90 "client-error-conflicting-attributes",
91 "client-error-compression-not-supported",
92 "client-error-compression-error",
93 "client-error-document-format-error",
94 "client-error-document-access-error",
95 "client-error-attributes-not-settable",
96 "client-error-ignored-all-subscriptions",
97 "client-error-too-many-subscriptions",
98 "client-error-ignored-all-notifications",
99 "client-error-print-support-file-not-found"
100 },
101 * const status_500s[] = /* Server errors */
102 {
103 "server-error-internal-error",
104 "server-error-operation-not-supported",
105 "server-error-service-unavailable",
106 "server-error-version-not-supported",
107 "server-error-device-error",
108 "server-error-temporary-error",
109 "server-error-not-accepting-jobs",
110 "server-error-busy",
111 "server-error-job-canceled",
112 "server-error-multiple-document-jobs-not-supported",
113 "server-error-printer-is-deactivated"
114 };
115
116
117 /*
118 * See if the error code is a known value...
119 */
120
121 if (error >= IPP_OK && error <= IPP_OK_BUT_CANCEL_SUBSCRIPTION)
122 return (status_oks[error]);
123 else if (error == IPP_REDIRECTION_OTHER_SITE)
124 return ("redirection-other-site");
125 else if (error >= IPP_BAD_REQUEST && error <= IPP_PRINT_SUPPORT_FILE_NOT_FOUND)
126 return (status_400s[error - IPP_BAD_REQUEST]);
127 else if (error >= IPP_INTERNAL_ERROR && error <= IPP_PRINTER_IS_DEACTIVATED)
128 return (status_500s[error - IPP_INTERNAL_ERROR]);
129
130 /*
131 * No, build an "unknown-xxxx" error string...
132 */
133
134 sprintf(unknown, "unknown-%04x", error);
135
136 return (unknown);
137 }
138
139
140 /*
141 * 'ippPort()' - Return the default IPP port number.
142 */
143
144 int /* O - Port number */
145 ippPort(void)
146 {
147 const char *server_port; /* SERVER_PORT environment variable */
148 struct servent *port; /* Port number info */
149
150
151 if (ipp_port)
152 return (ipp_port);
153 else if ((server_port = getenv("IPP_PORT")) != NULL)
154 return (ipp_port = atoi(server_port));
155 else if ((port = getservbyname("ipp", NULL)) == NULL)
156 return (ipp_port = CUPS_DEFAULT_IPP_PORT);
157 else
158 return (ipp_port = ntohs(port->s_port));
159 }
160
161
162 /*
163 * 'ippSetPort()' - Set the default port number.
164 */
165
166 void
167 ippSetPort(int p) /* I - Port number to use */
168 {
169 ipp_port = p;
170 }
171
172
173 /*
174 * End of "$Id: ipp-support.c,v 1.2.2.3 2003/01/24 20:45:12 mike Exp $".
175 */