]>
git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/html.c
4 * HTML support functions for CUPS.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
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/".
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.
27 * Include necessary headers...
30 #include "cgi-private.h"
37 static const char *cgi_multipart
= NULL
;
38 /* Multipart separator, if any */
45 static const char *cgi_null_passwd(const char *prompt
);
49 * 'cgiEndHTML()' - End a HTML page.
56 * Send the standard trailer...
59 cgiCopyTemplateLang("trailer.tmpl");
64 * 'cgiEndMultipart()' - End the delivery of a multipart web page.
72 printf("\n%s--\n", cgi_multipart
);
79 * 'cgiFormEncode()' - Encode a string as a form variable.
82 char * /* O - Destination string */
83 cgiFormEncode(char *dst
, /* I - Destination string */
84 const char *src
, /* I - Source string */
85 size_t dstsize
) /* I - Size of destination string */
87 char *dstptr
, /* Pointer into destination */
88 *dstend
; /* End of destination */
89 static const char *hex
= /* Hexadecimal characters */
94 * Mark the end of the string...
97 dstend
= dst
+ dstsize
- 1;
100 * Loop through the source string and copy...
103 for (dstptr
= dst
; *src
&& dstptr
< dstend
;)
109 * Encode spaces with a "+"...
120 * Encode special characters with %XX escape...
123 if (dstptr
< (dstend
- 2))
126 *dstptr
++ = hex
[(*src
& 255) >> 4];
127 *dstptr
++ = hex
[*src
& 15];
134 * Copy other characters literally...
143 * Nul-terminate the destination string...
149 * Return the encoded string...
157 * 'cgiStartHTML()' - Start a HTML page.
161 cgiStartHTML(const char *title
) /* I - Title of page */
164 * Disable any further authentication attempts...
167 cupsSetPasswordCB(cgi_null_passwd
);
170 * Tell the client to expect UTF-8 encoded HTML...
176 puts("Content-Type: text/html;charset=utf-8\n");
179 * Send a standard header...
182 cgiSetVariable("TITLE", title
);
183 cgiSetServerVersion();
185 cgiCopyTemplateLang("header.tmpl");
190 * 'cgiStartMultipart()' - Start a multipart delivery of a web page.
194 cgiStartMultipart(void)
196 puts("MIME-Version: 1.0\n"
197 "Content-Type: multipart/x-mixed-replace; boundary=\"CUPS-MULTIPART\"\n");
200 cgi_multipart
= "--CUPS-MULTIPART";
205 * 'cgiSupportsMultipart()' - Does the browser support multi-part documents?
208 int /* O - 1 if multi-part supported, 0 otherwise */
209 cgiSupportsMultipart(void)
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
222 * 'cgi_null_passwd()' - Return a NULL password for authentication.
225 static const char * /* O - NULL */
226 cgi_null_passwd(const char *prompt
) /* I - Prompt string (unused) */
230 fprintf(stderr
, "DEBUG: cgi_null_passwd(prompt=\"%s\") called!\n",
231 prompt
? prompt
: "(null)");