]>
git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/html.c
2 * HTML support functions for CUPS.
4 * Copyright 2007-2011 by Apple Inc.
5 * Copyright 1997-2006 by Easy Software Products.
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/".
15 * Include necessary headers...
18 #include "cgi-private.h"
25 static const char *cgi_multipart
= NULL
;
26 /* Multipart separator, if any */
33 static const char *cgi_null_passwd(const char *prompt
);
37 * 'cgiEndHTML()' - End a HTML page.
44 * Send the standard trailer...
47 cgiCopyTemplateLang("trailer.tmpl");
52 * 'cgiEndMultipart()' - End the delivery of a multipart web page.
60 printf("\n%s--\n", cgi_multipart
);
67 * 'cgiFormEncode()' - Encode a string as a form variable.
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 */
75 char *dstptr
, /* Pointer into destination */
76 *dstend
; /* End of destination */
77 static const char *hex
= /* Hexadecimal characters */
82 * Mark the end of the string...
85 dstend
= dst
+ dstsize
- 1;
88 * Loop through the source string and copy...
91 for (dstptr
= dst
; *src
&& dstptr
< dstend
;)
97 * Encode spaces with a "+"...
108 * Encode special characters with %XX escape...
111 if (dstptr
< (dstend
- 2))
114 *dstptr
++ = hex
[(*src
& 255) >> 4];
115 *dstptr
++ = hex
[*src
& 15];
122 * Copy other characters literally...
131 * Nul-terminate the destination string...
137 * Return the encoded string...
145 * 'cgiStartHTML()' - Start a HTML page.
149 cgiStartHTML(const char *title
) /* I - Title of page */
152 * Disable any further authentication attempts...
155 cupsSetPasswordCB(cgi_null_passwd
);
158 * Tell the client to expect UTF-8 encoded HTML...
164 puts("Content-Type: text/html;charset=utf-8\n");
167 * Send a standard header...
170 cgiSetVariable("TITLE", title
);
171 cgiSetServerVersion();
173 cgiCopyTemplateLang("header.tmpl");
178 * 'cgiStartMultipart()' - Start a multipart delivery of a web page.
182 cgiStartMultipart(void)
184 puts("MIME-Version: 1.0\n"
185 "Content-Type: multipart/x-mixed-replace; boundary=\"CUPS-MULTIPART\"\n");
188 cgi_multipart
= "--CUPS-MULTIPART";
193 * 'cgiSupportsMultipart()' - Does the browser support multi-part documents?
196 int /* O - 1 if multi-part supported, 0 otherwise */
197 cgiSupportsMultipart(void)
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
210 * 'cgi_null_passwd()' - Return a NULL password for authentication.
213 static const char * /* O - NULL */
214 cgi_null_passwd(const char *prompt
) /* I - Prompt string (unused) */
218 fprintf(stderr
, "DEBUG: cgi_null_passwd(prompt=\"%s\") called!\n",
219 prompt
? prompt
: "(null)");