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