diff options
Diffstat (limited to 'html.c')
-rw-r--r-- | html.c | 78 |
1 files changed, 39 insertions, 39 deletions
@@ -54,7 +54,7 @@ char *fmt(const char *format, ...) | |||
54 | va_start(args, format); | 54 | va_start(args, format); |
55 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); | 55 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); |
56 | va_end(args); | 56 | va_end(args); |
57 | if (len>sizeof(buf[bufidx])) { | 57 | if (len > sizeof(buf[bufidx])) { |
58 | fprintf(stderr, "[html.c] string truncated: %s\n", format); | 58 | fprintf(stderr, "[html.c] string truncated: %s\n", format); |
59 | exit(1); | 59 | exit(1); |
60 | } | 60 | } |
@@ -94,19 +94,19 @@ void html_txt(const char *txt) | |||
94 | const char *t = txt; | 94 | const char *t = txt; |
95 | while(t && *t){ | 95 | while(t && *t){ |
96 | int c = *t; | 96 | int c = *t; |
97 | if (c=='<' || c=='>' || c=='&') { | 97 | if (c == '<' || c == '>' || c == '&') { |
98 | html_raw(txt, t - txt); | 98 | html_raw(txt, t - txt); |
99 | if (c=='>') | 99 | if (c == '>') |
100 | html(">"); | 100 | html(">"); |
101 | else if (c=='<') | 101 | else if (c == '<') |
102 | html("<"); | 102 | html("<"); |
103 | else if (c=='&') | 103 | else if (c == '&') |
104 | html("&"); | 104 | html("&"); |
105 | txt = t+1; | 105 | txt = t + 1; |
106 | } | 106 | } |
107 | t++; | 107 | t++; |
108 | } | 108 | } |
109 | if (t!=txt) | 109 | if (t != txt) |
110 | html(txt); | 110 | html(txt); |
111 | } | 111 | } |
112 | 112 | ||
@@ -115,21 +115,21 @@ void html_ntxt(int len, const char *txt) | |||
115 | const char *t = txt; | 115 | const char *t = txt; |
116 | while(t && *t && len--){ | 116 | while(t && *t && len--){ |
117 | int c = *t; | 117 | int c = *t; |
118 | if (c=='<' || c=='>' || c=='&') { | 118 | if (c == '<' || c == '>' || c == '&') { |
119 | html_raw(txt, t - txt); | 119 | html_raw(txt, t - txt); |
120 | if (c=='>') | 120 | if (c == '>') |
121 | html(">"); | 121 | html(">"); |
122 | else if (c=='<') | 122 | else if (c == '<') |
123 | html("<"); | 123 | html("<"); |
124 | else if (c=='&') | 124 | else if (c == '&') |
125 | html("&"); | 125 | html("&"); |
126 | txt = t+1; | 126 | txt = t + 1; |
127 | } | 127 | } |
128 | t++; | 128 | t++; |
129 | } | 129 | } |
130 | if (t!=txt) | 130 | if (t != txt) |
131 | html_raw(txt, t - txt); | 131 | html_raw(txt, t - txt); |
132 | if (len<0) | 132 | if (len < 0) |
133 | html("..."); | 133 | html("..."); |
134 | } | 134 | } |
135 | 135 | ||
@@ -138,23 +138,23 @@ void html_attr(const char *txt) | |||
138 | const char *t = txt; | 138 | const char *t = txt; |
139 | while(t && *t){ | 139 | while(t && *t){ |
140 | int c = *t; | 140 | int c = *t; |
141 | if (c=='<' || c=='>' || c=='\'' || c=='\"' || c=='&') { | 141 | if (c == '<' || c == '>' || c == '\'' || c == '\"' || c == '&') { |
142 | html_raw(txt, t - txt); | 142 | html_raw(txt, t - txt); |
143 | if (c=='>') | 143 | if (c == '>') |
144 | html(">"); | 144 | html(">"); |
145 | else if (c=='<') | 145 | else if (c == '<') |
146 | html("<"); | 146 | html("<"); |
147 | else if (c=='\'') | 147 | else if (c == '\'') |
148 | html("'"); | 148 | html("'"); |
149 | else if (c=='"') | 149 | else if (c == '"') |
150 | html("""); | 150 | html("""); |
151 | else if (c=='&') | 151 | else if (c == '&') |
152 | html("&"); | 152 | html("&"); |
153 | txt = t+1; | 153 | txt = t + 1; |
154 | } | 154 | } |
155 | t++; | 155 | t++; |
156 | } | 156 | } |
157 | if (t!=txt) | 157 | if (t != txt) |
158 | html(txt); | 158 | html(txt); |
159 | } | 159 | } |
160 | 160 | ||
@@ -164,14 +164,14 @@ void html_url_path(const char *txt) | |||
164 | while(t && *t){ | 164 | while(t && *t){ |
165 | unsigned char c = *t; | 165 | unsigned char c = *t; |
166 | const char *e = url_escape_table[c]; | 166 | const char *e = url_escape_table[c]; |
167 | if (e && c!='+' && c!='&') { | 167 | if (e && c != '+' && c != '&') { |
168 | html_raw(txt, t - txt); | 168 | html_raw(txt, t - txt); |
169 | html(e); | 169 | html(e); |
170 | txt = t+1; | 170 | txt = t + 1; |
171 | } | 171 | } |
172 | t++; | 172 | t++; |
173 | } | 173 | } |
174 | if (t!=txt) | 174 | if (t != txt) |
175 | html(txt); | 175 | html(txt); |
176 | } | 176 | } |
177 | 177 | ||
@@ -186,11 +186,11 @@ void html_url_arg(const char *txt) | |||
186 | if (e) { | 186 | if (e) { |
187 | html_raw(txt, t - txt); | 187 | html_raw(txt, t - txt); |
188 | html(e); | 188 | html(e); |
189 | txt = t+1; | 189 | txt = t + 1; |
190 | } | 190 | } |
191 | t++; | 191 | t++; |
192 | } | 192 | } |
193 | if (t!=txt) | 193 | if (t != txt) |
194 | html(txt); | 194 | html(txt); |
195 | } | 195 | } |
196 | 196 | ||
@@ -286,14 +286,14 @@ char *convert_query_hexchar(char *txt) | |||
286 | *txt = '\0'; | 286 | *txt = '\0'; |
287 | return txt-1; | 287 | return txt-1; |
288 | } | 288 | } |
289 | d1 = hextoint(*(txt+1)); | 289 | d1 = hextoint(*(txt + 1)); |
290 | d2 = hextoint(*(txt+2)); | 290 | d2 = hextoint(*(txt + 2)); |
291 | if (d1<0 || d2<0) { | 291 | if (d1 < 0 || d2 < 0) { |
292 | memmove(txt, txt+3, n-2); | 292 | memmove(txt, txt + 3, n - 2); |
293 | return txt-1; | 293 | return txt-1; |
294 | } else { | 294 | } else { |
295 | *txt = d1 * 16 + d2; | 295 | *txt = d1 * 16 + d2; |
296 | memmove(txt+1, txt+3, n-2); | 296 | memmove(txt + 1, txt + 3, n - 2); |
297 | return txt; | 297 | return txt; |
298 | } | 298 | } |
299 | } | 299 | } |
@@ -311,22 +311,22 @@ int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const | |||
311 | exit(1); | 311 | exit(1); |
312 | } | 312 | } |
313 | while((c=*t) != '\0') { | 313 | while((c=*t) != '\0') { |
314 | if (c=='=') { | 314 | if (c == '=') { |
315 | *t = '\0'; | 315 | *t = '\0'; |
316 | value = t+1; | 316 | value = t + 1; |
317 | } else if (c=='+') { | 317 | } else if (c == '+') { |
318 | *t = ' '; | 318 | *t = ' '; |
319 | } else if (c=='%') { | 319 | } else if (c == '%') { |
320 | t = convert_query_hexchar(t); | 320 | t = convert_query_hexchar(t); |
321 | } else if (c=='&') { | 321 | } else if (c == '&') { |
322 | *t = '\0'; | 322 | *t = '\0'; |
323 | (*fn)(txt, value); | 323 | (*fn)(txt, value); |
324 | txt = t+1; | 324 | txt = t + 1; |
325 | value = NULL; | 325 | value = NULL; |
326 | } | 326 | } |
327 | t++; | 327 | t++; |
328 | } | 328 | } |
329 | if (t!=txt) | 329 | if (t != txt) |
330 | (*fn)(txt, value); | 330 | (*fn)(txt, value); |
331 | free(o); | 331 | free(o); |
332 | return 0; | 332 | return 0; |