]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
f7deaa1a | 2 | * "$Id: html.c 5548 2006-05-19 19:38:31Z mike $" |
ef416fc2 | 3 | * |
4 | * HTML support functions for the Common UNIX Printing System (CUPS). | |
5 | * | |
6 | * Copyright 1997-2006 by Easy Software Products. | |
7 | * | |
8 | * These coded instructions, statements, and computer programs are the | |
9 | * property of Easy Software Products and are protected by Federal | |
10 | * copyright law. Distribution and use rights are outlined in the file | |
11 | * "LICENSE.txt" which should have been included with this file. If this | |
12 | * file is missing or damaged please contact Easy Software Products | |
13 | * at: | |
14 | * | |
15 | * Attn: CUPS Licensing Information | |
16 | * Easy Software Products | |
17 | * 44141 Airport View Drive, Suite 204 | |
18 | * Hollywood, Maryland 20636 USA | |
19 | * | |
20 | * Voice: (301) 373-9600 | |
21 | * EMail: cups-info@cups.org | |
22 | * WWW: http://www.cups.org | |
23 | * | |
24 | * Contents: | |
25 | * | |
26 | * cgiEndHTML() - End a HTML page. | |
27 | * cgiFormEncode() - Encode a string as a form variable... | |
28 | * cgiStartHTML() - Start a HTML page. | |
29 | * cgi_null_passwd() - Return a NULL password for authentication. | |
30 | */ | |
31 | ||
32 | /* | |
33 | * Include necessary headers... | |
34 | */ | |
35 | ||
36 | #include "cgi-private.h" | |
37 | ||
38 | ||
39 | /* | |
40 | * Local functions... | |
41 | */ | |
42 | ||
43 | static const char *cgi_null_passwd(const char *prompt); | |
44 | ||
45 | ||
46 | /* | |
47 | * 'cgiEndHTML()' - End a HTML page. | |
48 | */ | |
49 | ||
50 | void | |
51 | cgiEndHTML(void) | |
52 | { | |
53 | /* | |
54 | * Send the standard trailer... | |
55 | */ | |
56 | ||
57 | cgiCopyTemplateLang("trailer.tmpl"); | |
58 | } | |
59 | ||
60 | ||
61 | /* | |
62 | * 'cgiFormEncode()' - Encode a string as a form variable... | |
63 | */ | |
64 | ||
65 | char * /* O - Destination string */ | |
66 | cgiFormEncode(char *dst, /* I - Destination string */ | |
67 | const char *src, /* I - Source string */ | |
68 | size_t dstsize) /* I - Size of destination string */ | |
69 | { | |
70 | char *dstptr, /* Pointer into destination */ | |
71 | *dstend; /* End of destination */ | |
72 | static const char *hex = /* Hexadecimal characters */ | |
73 | "0123456789ABCDEF"; | |
74 | ||
75 | ||
76 | /* | |
77 | * Mark the end of the string... | |
78 | */ | |
79 | ||
80 | dstend = dst + dstsize - 1; | |
81 | ||
82 | /* | |
83 | * Loop through the source string and copy... | |
84 | */ | |
85 | ||
86 | for (dstptr = dst; *src && dstptr < dstend;) | |
87 | { | |
88 | switch (*src) | |
89 | { | |
90 | case ' ' : | |
91 | /* | |
92 | * Encode spaces with a "+"... | |
93 | */ | |
94 | ||
95 | *dstptr++ = '+'; | |
96 | src ++; | |
97 | break; | |
98 | ||
99 | case '&' : | |
100 | case '%' : | |
101 | case '+' : | |
102 | /* | |
103 | * Encode special characters with %XX escape... | |
104 | */ | |
105 | ||
106 | if (dstptr < (dstend - 2)) | |
107 | { | |
108 | *dstptr++ = '%'; | |
109 | *dstptr++ = hex[(*src & 255) >> 4]; | |
110 | *dstptr++ = hex[*src & 15]; | |
111 | src ++; | |
112 | } | |
113 | break; | |
114 | ||
115 | default : | |
116 | /* | |
117 | * Copy other characters literally... | |
118 | */ | |
119 | ||
120 | *dstptr++ = *src++; | |
121 | break; | |
122 | } | |
123 | } | |
124 | ||
125 | /* | |
126 | * Nul-terminate the destination string... | |
127 | */ | |
128 | ||
129 | *dstptr = '\0'; | |
130 | ||
131 | /* | |
132 | * Return the encoded string... | |
133 | */ | |
134 | ||
135 | return (dst); | |
136 | } | |
137 | ||
138 | ||
139 | /* | |
140 | * 'cgiStartHTML()' - Start a HTML page. | |
141 | */ | |
142 | ||
143 | void | |
144 | cgiStartHTML(const char *title) /* I - Title of page */ | |
145 | { | |
146 | /* | |
147 | * Disable any further authentication attempts... | |
148 | */ | |
149 | ||
150 | cupsSetPasswordCB(cgi_null_passwd); | |
151 | ||
152 | /* | |
153 | * Tell the client to expect UTF-8 encoded HTML... | |
154 | */ | |
155 | ||
156 | puts("Content-Type: text/html;charset=utf-8\n"); | |
157 | ||
158 | /* | |
159 | * Send a standard header... | |
160 | */ | |
161 | ||
162 | cgiSetVariable("TITLE", title); | |
163 | cgiSetServerVersion(); | |
164 | ||
165 | cgiCopyTemplateLang("header.tmpl"); | |
166 | } | |
167 | ||
168 | ||
169 | /* | |
170 | * 'cgi_null_passwd()' - Return a NULL password for authentication. | |
171 | */ | |
172 | ||
173 | static const char * /* O - NULL */ | |
174 | cgi_null_passwd(const char *prompt) /* I - Prompt string (unused) */ | |
175 | { | |
176 | (void)prompt; | |
177 | ||
f301802f | 178 | fprintf(stderr, "DEBUG: cgi_null_passwd(prompt=\"%s\") called!\n", |
179 | prompt ? prompt : "(null)"); | |
ef416fc2 | 180 | |
181 | return (NULL); | |
182 | } | |
183 | ||
184 | ||
185 | /* | |
f7deaa1a | 186 | * End of "$Id: html.c 5548 2006-05-19 19:38:31Z mike $". |
ef416fc2 | 187 | */ |