* Completed self-service list subscription via web.
[citadel.git] / citadel / tools.c
index e73a9b122d0738c9b189eac89503cb3df1322a3e..3a457ae6efc072a71c87bfa325699e6049df0bd0 100644 (file)
@@ -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]);
+       }
+}
+
+