]> git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/html.c
Merge changes from CUPS 1.4svn-r8033.
[thirdparty/cups.git] / cgi-bin / html.c
1 /*
2 * "$Id: html.c 6649 2007-07-11 21:46:42Z mike $"
3 *
4 * HTML support functions for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
8 *
9 * These coded instructions, statements, and computer programs are the
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/".
14 *
15 * Contents:
16 *
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 * cgi_null_passwd() - Return a NULL password for authentication.
23 */
24
25 /*
26 * Include necessary headers...
27 */
28
29 #include "cgi-private.h"
30
31
32 /*
33 * Local globals...
34 */
35
36 static const char *cgi_multipart = NULL;
37 /* Multipart separator, if any */
38
39
40 /*
41 * Local functions...
42 */
43
44 static const char *cgi_null_passwd(const char *prompt);
45
46
47 /*
48 * 'cgiEndHTML()' - End a HTML page.
49 */
50
51 void
52 cgiEndHTML(void)
53 {
54 /*
55 * Send the standard trailer...
56 */
57
58 cgiCopyTemplateLang("trailer.tmpl");
59 }
60
61
62 /*
63 * 'cgiEndMultipart()' - End the delivery of a multipart web page.
64 */
65
66 void
67 cgiEndMultipart(void)
68 {
69 if (cgi_multipart)
70 printf("\n%s--\n", cgi_multipart);
71 }
72
73
74 /*
75 * 'cgiFormEncode()' - Encode a string as a form variable...
76 */
77
78 char * /* O - Destination string */
79 cgiFormEncode(char *dst, /* I - Destination string */
80 const char *src, /* I - Source string */
81 size_t dstsize) /* I - Size of destination string */
82 {
83 char *dstptr, /* Pointer into destination */
84 *dstend; /* End of destination */
85 static const char *hex = /* Hexadecimal characters */
86 "0123456789ABCDEF";
87
88
89 /*
90 * Mark the end of the string...
91 */
92
93 dstend = dst + dstsize - 1;
94
95 /*
96 * Loop through the source string and copy...
97 */
98
99 for (dstptr = dst; *src && dstptr < dstend;)
100 {
101 switch (*src)
102 {
103 case ' ' :
104 /*
105 * Encode spaces with a "+"...
106 */
107
108 *dstptr++ = '+';
109 src ++;
110 break;
111
112 case '&' :
113 case '%' :
114 case '+' :
115 /*
116 * Encode special characters with %XX escape...
117 */
118
119 if (dstptr < (dstend - 2))
120 {
121 *dstptr++ = '%';
122 *dstptr++ = hex[(*src & 255) >> 4];
123 *dstptr++ = hex[*src & 15];
124 src ++;
125 }
126 break;
127
128 default :
129 /*
130 * Copy other characters literally...
131 */
132
133 *dstptr++ = *src++;
134 break;
135 }
136 }
137
138 /*
139 * Nul-terminate the destination string...
140 */
141
142 *dstptr = '\0';
143
144 /*
145 * Return the encoded string...
146 */
147
148 return (dst);
149 }
150
151
152 /*
153 * 'cgiStartHTML()' - Start a HTML page.
154 */
155
156 void
157 cgiStartHTML(const char *title) /* I - Title of page */
158 {
159 /*
160 * Disable any further authentication attempts...
161 */
162
163 cupsSetPasswordCB(cgi_null_passwd);
164
165 /*
166 * Tell the client to expect UTF-8 encoded HTML...
167 */
168
169 if (cgi_multipart)
170 puts(cgi_multipart);
171
172 puts("Content-Type: text/html;charset=utf-8\n");
173
174 /*
175 * Send a standard header...
176 */
177
178 cgiSetVariable("TITLE", title);
179 cgiSetServerVersion();
180
181 cgiCopyTemplateLang("header.tmpl");
182 }
183
184
185 /*
186 * 'cgiStartMultipart()' - Start a multipart delivery of a web page...
187 */
188
189 void
190 cgiStartMultipart(void)
191 {
192 puts("MIME-Version: 1.0");
193 puts("Content-Type: multipart/x-mixed-replace; boundary=\"CUPS-MULTIPART\"\n");
194 cgi_multipart = "--CUPS-MULTIPART";
195 }
196
197
198 /*
199 * 'cgi_null_passwd()' - Return a NULL password for authentication.
200 */
201
202 static const char * /* O - NULL */
203 cgi_null_passwd(const char *prompt) /* I - Prompt string (unused) */
204 {
205 (void)prompt;
206
207 fprintf(stderr, "DEBUG: cgi_null_passwd(prompt=\"%s\") called!\n",
208 prompt ? prompt : "(null)");
209
210 return (NULL);
211 }
212
213
214 /*
215 * End of "$Id: html.c 6649 2007-07-11 21:46:42Z mike $".
216 */