-rw-r--r-- | cgit.c | 3 | ||||
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | html.c | 64 | ||||
-rw-r--r-- | html.h | 2 | ||||
-rw-r--r-- | parsing.c | 49 | ||||
-rw-r--r-- | shared.c | 12 |
6 files changed, 68 insertions, 64 deletions
@@ -12,2 +12,3 @@ #include "configfile.h" +#include "html.h" #include "ui-shared.h" @@ -446,3 +447,3 @@ int main(int argc, const char **argv) cgit_parse_args(argc, argv); - cgit_parse_query(ctx.qry.raw, querystring_cb); + http_parse_querystring(ctx.qry.raw, querystring_cb); if (!cgit_prepare_cache(&item)) @@ -193,3 +193,2 @@ extern int chk_non_negative(int result, char *msg); -extern int hextoint(char c); extern char *trim_end(const char *str, char c); @@ -216,3 +215,2 @@ extern char *fmt(const char *format,...); -extern int cgit_parse_query(char *txt, configfn fn); extern struct commitinfo *cgit_parse_commit(struct commit *commit); @@ -187 +187,65 @@ int html_include(const char *filename) } + +int hextoint(char c) +{ + if (c >= 'a' && c <= 'f') + return 10 + c - 'a'; + else if (c >= 'A' && c <= 'F') + return 10 + c - 'A'; + else if (c >= '0' && c <= '9') + return c - '0'; + else + return -1; +} + +char *convert_query_hexchar(char *txt) +{ + int d1, d2; + if (strlen(txt) < 3) { + *txt = '\0'; + return txt-1; + } + d1 = hextoint(*(txt+1)); + d2 = hextoint(*(txt+2)); + if (d1<0 || d2<0) { + strcpy(txt, txt+3); + return txt-1; + } else { + *txt = d1 * 16 + d2; + strcpy(txt+1, txt+3); + return txt; + } +} + +int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value)) +{ + char *t, *value = NULL, c; + + if (!txt) + return 0; + + t = txt = strdup(txt); + if (t == NULL) { + printf("Out of memory\n"); + exit(1); + } + while((c=*t) != '\0') { + if (c=='=') { + *t = '\0'; + value = t+1; + } else if (c=='+') { + *t = ' '; + } else if (c=='%') { + t = convert_query_hexchar(t); + } else if (c=='&') { + *t = '\0'; + (*fn)(txt, value); + txt = t+1; + value = NULL; + } + t++; + } + if (t!=txt) + (*fn)(txt, value); + return 0; +} @@ -17,2 +17,4 @@ extern int html_include(const char *filename); +extern int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value)); + #endif /* HTML_H */ @@ -10,51 +10,2 @@ -char *convert_query_hexchar(char *txt) -{ - int d1, d2; - if (strlen(txt) < 3) { - *txt = '\0'; - return txt-1; - } - d1 = hextoint(*(txt+1)); - d2 = hextoint(*(txt+2)); - if (d1<0 || d2<0) { - strcpy(txt, txt+3); - return txt-1; - } else { - *txt = d1 * 16 + d2; - strcpy(txt+1, txt+3); - return txt; - } -} - -int cgit_parse_query(char *txt, configfn fn) -{ - char *t, *value = NULL, c; - - if (!txt) - return 0; - - t = txt = xstrdup(txt); - - while((c=*t) != '\0') { - if (c=='=') { - *t = '\0'; - value = t+1; - } else if (c=='+') { - *t = ' '; - } else if (c=='%') { - t = convert_query_hexchar(t); - } else if (c=='&') { - *t = '\0'; - (*fn)(txt, value); - txt = t+1; - value = NULL; - } - t++; - } - if (t!=txt) - (*fn)(txt, value); - return 0; -} - /* @@ -91,14 +91,2 @@ void *cgit_free_commitinfo(struct commitinfo *info) -int hextoint(char c) -{ - if (c >= 'a' && c <= 'f') - return 10 + c - 'a'; - else if (c >= 'A' && c <= 'F') - return 10 + c - 'A'; - else if (c >= '0' && c <= '9') - return c - '0'; - else - return -1; -} - char *trim_end(const char *str, char c) |