]> git.ipfire.org Git - thirdparty/cups.git/blame - cgi-bin/html.c
Load cups into easysw/current.
[thirdparty/cups.git] / cgi-bin / html.c
CommitLineData
ef416fc2 1/*
bc44d920 2 * "$Id: html.c 6649 2007-07-11 21:46:42Z mike $"
ef416fc2 3 *
4 * HTML support functions for the Common UNIX Printing System (CUPS).
5 *
bc44d920 6 * Copyright 2007 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 *
17 * cgiEndHTML() - End a HTML page.
18 * cgiFormEncode() - Encode a string as a form variable...
19 * cgiStartHTML() - Start a HTML page.
20 * cgi_null_passwd() - Return a NULL password for authentication.
21 */
22
23/*
24 * Include necessary headers...
25 */
26
27#include "cgi-private.h"
28
29
30/*
31 * Local functions...
32 */
33
34static const char *cgi_null_passwd(const char *prompt);
35
36
37/*
38 * 'cgiEndHTML()' - End a HTML page.
39 */
40
41void
42cgiEndHTML(void)
43{
44 /*
45 * Send the standard trailer...
46 */
47
48 cgiCopyTemplateLang("trailer.tmpl");
49}
50
51
52/*
53 * 'cgiFormEncode()' - Encode a string as a form variable...
54 */
55
56char * /* O - Destination string */
57cgiFormEncode(char *dst, /* I - Destination string */
58 const char *src, /* I - Source string */
59 size_t dstsize) /* I - Size of destination string */
60{
61 char *dstptr, /* Pointer into destination */
62 *dstend; /* End of destination */
63 static const char *hex = /* Hexadecimal characters */
64 "0123456789ABCDEF";
65
66
67 /*
68 * Mark the end of the string...
69 */
70
71 dstend = dst + dstsize - 1;
72
73 /*
74 * Loop through the source string and copy...
75 */
76
77 for (dstptr = dst; *src && dstptr < dstend;)
78 {
79 switch (*src)
80 {
81 case ' ' :
82 /*
83 * Encode spaces with a "+"...
84 */
85
86 *dstptr++ = '+';
87 src ++;
88 break;
89
90 case '&' :
91 case '%' :
92 case '+' :
93 /*
94 * Encode special characters with %XX escape...
95 */
96
97 if (dstptr < (dstend - 2))
98 {
99 *dstptr++ = '%';
100 *dstptr++ = hex[(*src & 255) >> 4];
101 *dstptr++ = hex[*src & 15];
102 src ++;
103 }
104 break;
105
106 default :
107 /*
108 * Copy other characters literally...
109 */
110
111 *dstptr++ = *src++;
112 break;
113 }
114 }
115
116 /*
117 * Nul-terminate the destination string...
118 */
119
120 *dstptr = '\0';
121
122 /*
123 * Return the encoded string...
124 */
125
126 return (dst);
127}
128
129
130/*
131 * 'cgiStartHTML()' - Start a HTML page.
132 */
133
134void
135cgiStartHTML(const char *title) /* I - Title of page */
136{
137 /*
138 * Disable any further authentication attempts...
139 */
140
141 cupsSetPasswordCB(cgi_null_passwd);
142
143 /*
144 * Tell the client to expect UTF-8 encoded HTML...
145 */
146
147 puts("Content-Type: text/html;charset=utf-8\n");
148
149 /*
150 * Send a standard header...
151 */
152
153 cgiSetVariable("TITLE", title);
154 cgiSetServerVersion();
155
156 cgiCopyTemplateLang("header.tmpl");
157}
158
159
160/*
161 * 'cgi_null_passwd()' - Return a NULL password for authentication.
162 */
163
164static const char * /* O - NULL */
165cgi_null_passwd(const char *prompt) /* I - Prompt string (unused) */
166{
167 (void)prompt;
168
f301802f 169 fprintf(stderr, "DEBUG: cgi_null_passwd(prompt=\"%s\") called!\n",
170 prompt ? prompt : "(null)");
ef416fc2 171
172 return (NULL);
173}
174
175
176/*
bc44d920 177 * End of "$Id: html.c 6649 2007-07-11 21:46:42Z mike $".
ef416fc2 178 */