]> git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/html.c
Remove all of the Subversion keywords from various source files.
[thirdparty/cups.git] / cgi-bin / html.c
1 /*
2 * HTML support functions for CUPS.
3 *
4 * Copyright 2007-2011 by Apple Inc.
5 * Copyright 1997-2006 by Easy Software Products.
6 *
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
12 */
13
14 /*
15 * Include necessary headers...
16 */
17
18 #include "cgi-private.h"
19
20
21 /*
22 * Local globals...
23 */
24
25 static const char *cgi_multipart = NULL;
26 /* Multipart separator, if any */
27
28
29 /*
30 * Local functions...
31 */
32
33 static const char *cgi_null_passwd(const char *prompt);
34
35
36 /*
37 * 'cgiEndHTML()' - End a HTML page.
38 */
39
40 void
41 cgiEndHTML(void)
42 {
43 /*
44 * Send the standard trailer...
45 */
46
47 cgiCopyTemplateLang("trailer.tmpl");
48 }
49
50
51 /*
52 * 'cgiEndMultipart()' - End the delivery of a multipart web page.
53 */
54
55 void
56 cgiEndMultipart(void)
57 {
58 if (cgi_multipart)
59 {
60 printf("\n%s--\n", cgi_multipart);
61 fflush(stdout);
62 }
63 }
64
65
66 /*
67 * 'cgiFormEncode()' - Encode a string as a form variable.
68 */
69
70 char * /* O - Destination string */
71 cgiFormEncode(char *dst, /* I - Destination string */
72 const char *src, /* I - Source string */
73 size_t dstsize) /* I - Size of destination string */
74 {
75 char *dstptr, /* Pointer into destination */
76 *dstend; /* End of destination */
77 static const char *hex = /* Hexadecimal characters */
78 "0123456789ABCDEF";
79
80
81 /*
82 * Mark the end of the string...
83 */
84
85 dstend = dst + dstsize - 1;
86
87 /*
88 * Loop through the source string and copy...
89 */
90
91 for (dstptr = dst; *src && dstptr < dstend;)
92 {
93 switch (*src)
94 {
95 case ' ' :
96 /*
97 * Encode spaces with a "+"...
98 */
99
100 *dstptr++ = '+';
101 src ++;
102 break;
103
104 case '&' :
105 case '%' :
106 case '+' :
107 /*
108 * Encode special characters with %XX escape...
109 */
110
111 if (dstptr < (dstend - 2))
112 {
113 *dstptr++ = '%';
114 *dstptr++ = hex[(*src & 255) >> 4];
115 *dstptr++ = hex[*src & 15];
116 src ++;
117 }
118 break;
119
120 default :
121 /*
122 * Copy other characters literally...
123 */
124
125 *dstptr++ = *src++;
126 break;
127 }
128 }
129
130 /*
131 * Nul-terminate the destination string...
132 */
133
134 *dstptr = '\0';
135
136 /*
137 * Return the encoded string...
138 */
139
140 return (dst);
141 }
142
143
144 /*
145 * 'cgiStartHTML()' - Start a HTML page.
146 */
147
148 void
149 cgiStartHTML(const char *title) /* I - Title of page */
150 {
151 /*
152 * Disable any further authentication attempts...
153 */
154
155 cupsSetPasswordCB(cgi_null_passwd);
156
157 /*
158 * Tell the client to expect UTF-8 encoded HTML...
159 */
160
161 if (cgi_multipart)
162 puts(cgi_multipart);
163
164 puts("Content-Type: text/html;charset=utf-8\n");
165
166 /*
167 * Send a standard header...
168 */
169
170 cgiSetVariable("TITLE", title);
171 cgiSetServerVersion();
172
173 cgiCopyTemplateLang("header.tmpl");
174 }
175
176
177 /*
178 * 'cgiStartMultipart()' - Start a multipart delivery of a web page.
179 */
180
181 void
182 cgiStartMultipart(void)
183 {
184 puts("MIME-Version: 1.0\n"
185 "Content-Type: multipart/x-mixed-replace; boundary=\"CUPS-MULTIPART\"\n");
186 fflush(stdout);
187
188 cgi_multipart = "--CUPS-MULTIPART";
189 }
190
191
192 /*
193 * 'cgiSupportsMultipart()' - Does the browser support multi-part documents?
194 */
195
196 int /* O - 1 if multi-part supported, 0 otherwise */
197 cgiSupportsMultipart(void)
198 {
199 /*
200 * Too many bug reports for browsers that don't support it, and too much pain
201 * to whitelist known-good browsers, so for now we just punt on multi-part
202 * support... :(
203 */
204
205 return (0);
206 }
207
208
209 /*
210 * 'cgi_null_passwd()' - Return a NULL password for authentication.
211 */
212
213 static const char * /* O - NULL */
214 cgi_null_passwd(const char *prompt) /* I - Prompt string (unused) */
215 {
216 (void)prompt;
217
218 fprintf(stderr, "DEBUG: cgi_null_passwd(prompt=\"%s\") called!\n",
219 prompt ? prompt : "(null)");
220
221 return (NULL);
222 }