On overflow, truncate to markp (but only if markp != NULL). */
| 234 | |
| 235 | /* On overflow, truncate to markp (but only if markp != NULL). */ |
| 236 | boolean |
| 237 | swr_add_uricoded( |
| 238 | const char *in, |
| 239 | char **out, |
| 240 | int *remaining, |
| 241 | char *markp) |
| 242 | { |
| 243 | while (*in) { |
| 244 | if (isalnum(*in) || strchr("_-.~", *in)) { |
| 245 | **out = *in; |
| 246 | (*out)++; |
| 247 | (*remaining)--; |
| 248 | } else if (*in == ' ') { |
| 249 | **out = '+'; |
| 250 | (*out)++; |
| 251 | (*remaining)--; |
| 252 | } else { |
| 253 | if (*remaining <= 3) { |
| 254 | if (markp) |
| 255 | *out = markp, *remaining = 0; |
| 256 | **out = '\0'; |
| 257 | return TRUE; |
| 258 | } else { |
| 259 | char chr[40]; /* [4] should suffice */ |
| 260 | int x; |
| 261 | |
| 262 | Sprintf(chr, "%%%02X", *in); |
| 263 | x = (int) strlen(chr); |
| 264 | if (x <= *remaining) { |
| 265 | Strcpy(*out, chr); |
| 266 | *out += x; |
| 267 | *remaining -= x; |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | in++; |
| 272 | if (!*remaining) { |
| 273 | if (markp) |
| 274 | *out = markp, *remaining = 0; |
| 275 | **out = '\0'; |
| 276 | return TRUE; |
| 277 | } |
| 278 | **out = '\0'; |
| 279 | } |
| 280 | return FALSE; /* normal return */ |
| 281 | } |
| 282 | |
| 283 | static char url[MAX_URL]; // XXX too bad this isn't allocated as needed |
| 284 | static int urem = MAX_URL; // adjusted for gc.crash_urlmax below |