X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Ftools.c;h=3a457ae6efc072a71c87bfa325699e6049df0bd0;hb=d65dd711bf8271c815441f826fc0b24e3d6b49ae;hp=e73a9b122d0738c9b189eac89503cb3df1322a3e;hpb=3aac5cbcc78c8a19bc2aa0fc30da6f6b5503caa0;p=citadel.git diff --git a/citadel/tools.c b/citadel/tools.c index e73a9b122..3a457ae6e 100644 --- a/citadel/tools.c +++ b/citadel/tools.c @@ -607,3 +607,30 @@ char *myfgets(char *s, int size, FILE *stream) { return ret; } + +/* + * Escape a string for feeding out as a URL. + * Output buffer must be big enough to handle escape expansion! + */ +void urlesc(char *outbuf, char *strbuf) +{ + int a, b, c; + char *ec = " #&;`'|*?-~<>^()[]{}$\\"; + + strcpy(outbuf, ""); + + for (a = 0; a < strlen(strbuf); ++a) { + c = 0; + for (b = 0; b < strlen(ec); ++b) { + if (strbuf[a] == ec[b]) + c = 1; + } + b = strlen(outbuf); + if (c == 1) + sprintf(&outbuf[b], "%%%02x", strbuf[a]); + else + sprintf(&outbuf[b], "%c", strbuf[a]); + } +} + +