char* http_escape ( const char *  str,
const char *  prepend 
)

Escape a string according to HTTP/1.1. A string can be prepended as well, which won't be escaped.

Definition at line 59 of file util.c.

00060 {
00061         const char *c;
00062         const char allowed[] = "-_.!~*'()/";
00063         GString *ret;
00064 
00065         if (prepend == NULL)
00066                 prepend = "";
00067 
00068         /* Argument may be empty */
00069         if (str == NULL)
00070                 return g_strdup(prepend);
00071 
00072         ret = g_string_new(prepend);
00073 
00074         for (c = str; *c != '\0'; c++) {
00075                 if (*c == ' ')
00076                         g_string_append_c(ret, '+');
00077                 else if (g_ascii_isalnum(*c) || strchr(allowed, *c) != NULL)
00078                         /* Character is allowed */
00079                         g_string_append_c(ret, *c);
00080                 else
00081                         /* Reserved or unwise character */
00082                         g_string_append_printf(ret, "%%%02hhx",
00083                             (const unsigned char)*c);
00084         }
00085 
00086         return g_string_free(ret, FALSE);
00087 }

Here is the caller graph for this function:

 All Data Structures Files Functions Variables Defines
Generated on Mon Mar 15 04:45:48 2010 for herrie by  doxygen 1.6.3