]>
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 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
11 * Include necessary headers...
14 #include "cgi-private.h"
21 static const char *cgi_multipart
= NULL
;
22 /* Multipart separator, if any */
29 static const char *cgi_null_passwd(const char *prompt
);
33 * 'cgiEndHTML()' - End a HTML page.
40 * Send the standard trailer...
43 cgiCopyTemplateLang("trailer.tmpl");
48 * 'cgiEndMultipart()' - End the delivery of a multipart web page.
56 printf("\n%s--\n", cgi_multipart
);
63 * 'cgiFormEncode()' - Encode a string as a form variable.
66 char * /* O - Destination string */
67 cgiFormEncode(char *dst
, /* I - Destination string */
68 const char *src
, /* I - Source string */
69 size_t dstsize
) /* I - Size of destination string */
71 char *dstptr
, /* Pointer into destination */
72 *dstend
; /* End of destination */
73 static const char *hex
= /* Hexadecimal characters */
78 * Mark the end of the string...
81 dstend
= dst
+ dstsize
- 1;
84 * Loop through the source string and copy...
87 for (dstptr
= dst
; *src
&& dstptr
< dstend
;)
93 * Encode spaces with a "+"...
104 * Encode special characters with %XX escape...
107 if (dstptr
< (dstend
- 2))
110 *dstptr
++ = hex
[(*src
& 255) >> 4];
111 *dstptr
++ = hex
[*src
& 15];
118 * Copy other characters literally...
127 * Nul-terminate the destination string...
133 * Return the encoded string...
141 * 'cgiStartHTML()' - Start a HTML page.
145 cgiStartHTML(const char *title
) /* I - Title of page */
148 * Disable any further authentication attempts...
151 cupsSetPasswordCB(cgi_null_passwd
);
154 * Tell the client to expect UTF-8 encoded HTML...
160 puts("Content-Type: text/html;charset=utf-8\n");
163 * Send a standard header...
166 cgiSetVariable("TITLE", title
);
167 cgiSetServerVersion();
169 cgiCopyTemplateLang("header.tmpl");
174 * 'cgiStartMultipart()' - Start a multipart delivery of a web page.
178 cgiStartMultipart(void)
180 puts("MIME-Version: 1.0\n"
181 "Content-Type: multipart/x-mixed-replace; boundary=\"CUPS-MULTIPART\"\n");
184 cgi_multipart
= "--CUPS-MULTIPART";
189 * 'cgiSupportsMultipart()' - Does the browser support multi-part documents?
192 int /* O - 1 if multi-part supported, 0 otherwise */
193 cgiSupportsMultipart(void)
196 * Too many bug reports for browsers that don't support it, and too much pain
197 * to whitelist known-good browsers, so for now we just punt on multi-part
206 * 'cgi_null_passwd()' - Return a NULL password for authentication.
209 static const char * /* O - NULL */
210 cgi_null_passwd(const char *prompt
) /* I - Prompt string (unused) */
214 fprintf(stderr
, "DEBUG: cgi_null_passwd(prompt=\"%s\") called!\n",
215 prompt
? prompt
: "(null)");