-rw-r--r-- | parsing.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -58,63 +58,84 @@ int read_config_line(FILE *f, char *line, const char **value, int bufsize) isname = 1; i++; } line[i+1] = 0; return i; } int cgit_read_config(const char *filename, configfn fn) { int ret = 0, len; char line[256]; const char *value; FILE *f = fopen(filename, "r"); if (!f) return -1; while((len = read_config_line(f, line, &value, sizeof(line))) > 0) (*fn)(line, value); fclose(f); return ret; } +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; } char *substr(const char *head, const char *tail) { char *buf; buf = xmalloc(tail - head + 1); strncpy(buf, head, tail - head); buf[tail - head] = '\0'; return buf; } struct commitinfo *cgit_parse_commit(struct commit *commit) |