From d14d77fe95c3b6224b40df9b101dded0deea913c Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sat, 16 Feb 2008 11:53:40 +0100 Subject: Introduce struct cgit_context This struct will hold all the cgit runtime information currently found in a multitude of global variables. The first cleanup removes all querystring-related variables. Signed-off-by: Lars Hjemli --- parsing.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'parsing.c') diff --git a/parsing.c b/parsing.c index 5093b8b..8cf56a4 100644 --- a/parsing.c +++ b/parsing.c @@ -149,7 +149,7 @@ void cgit_parse_url(const char *url) cgit_repo = cgit_get_repoinfo(url); if (cgit_repo) { - cgit_query_repo = cgit_repo->url; + ctx.qry.repo = cgit_repo->url; return; } @@ -163,15 +163,15 @@ void cgit_parse_url(const char *url) continue; } - cgit_query_repo = cgit_repo->url; + ctx.qry.repo = cgit_repo->url; p = strchr(cmd + 1, '/'); if (p) { p[0] = '\0'; if (p[1]) - cgit_query_path = trim_end(p + 1, '/'); + ctx.qry.path = trim_end(p + 1, '/'); } cgit_cmd = cgit_get_cmd_index(cmd + 1); - cgit_query_page = xstrdup(cmd + 1); + ctx.qry.page = xstrdup(cmd + 1); return; } } -- cgit v1.2.1 From d1f3bbe9d22029f45a77bb938c176ccc0c827d46 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sat, 16 Feb 2008 13:56:09 +0100 Subject: Move cgit_repo into cgit_context This removes the global variable which is used to keep track of the currently selected repository, and adds a new variable in the cgit_context structure. Signed-off-by: Lars Hjemli --- parsing.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'parsing.c') diff --git a/parsing.c b/parsing.c index 8cf56a4..027f06b 100644 --- a/parsing.c +++ b/parsing.c @@ -143,27 +143,27 @@ void cgit_parse_url(const char *url) { char *cmd, *p; - cgit_repo = NULL; + ctx.repo = NULL; if (!url || url[0] == '\0') return; - cgit_repo = cgit_get_repoinfo(url); - if (cgit_repo) { - ctx.qry.repo = cgit_repo->url; + ctx.repo = cgit_get_repoinfo(url); + if (ctx.repo) { + ctx.qry.repo = ctx.repo->url; return; } cmd = strchr(url, '/'); - while (!cgit_repo && cmd) { + while (!ctx.repo && cmd) { cmd[0] = '\0'; - cgit_repo = cgit_get_repoinfo(url); - if (cgit_repo == NULL) { + ctx.repo = cgit_get_repoinfo(url); + if (ctx.repo == NULL) { cmd[0] = '/'; cmd = strchr(cmd + 1, '/'); continue; } - ctx.qry.repo = cgit_repo->url; + ctx.qry.repo = ctx.repo->url; p = strchr(cmd + 1, '/'); if (p) { p[0] = '\0'; -- cgit v1.2.1 From e0e4478e7b4812f822d60a13a33525f8e529e1e8 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Mon, 24 Mar 2008 01:09:39 +0100 Subject: Add command dispatcher This simplifies the code in cgit.c and makes it easier to extend cgit with new pages/commands. Signed-off-by: Lars Hjemli --- parsing.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'parsing.c') diff --git a/parsing.c b/parsing.c index 027f06b..8dce488 100644 --- a/parsing.c +++ b/parsing.c @@ -170,8 +170,8 @@ void cgit_parse_url(const char *url) if (p[1]) ctx.qry.path = trim_end(p + 1, '/'); } - cgit_cmd = cgit_get_cmd_index(cmd + 1); - ctx.qry.page = xstrdup(cmd + 1); + if (cmd[1]) + ctx.qry.page = xstrdup(cmd + 1); return; } } -- cgit v1.2.1 From 20a33548b9a87a6eb23162ee5d137daa46d78613 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Fri, 28 Mar 2008 00:09:11 +0100 Subject: Move function for configfile parsing into configfile.[ch] This is a generic function which wanted its own little object file. Signed-off-by: Lars Hjemli --- parsing.c | 75 --------------------------------------------------------------- 1 file changed, 75 deletions(-) (limited to 'parsing.c') diff --git a/parsing.c b/parsing.c index 8dce488..9a4a7a3 100644 --- a/parsing.c +++ b/parsing.c @@ -8,81 +8,6 @@ #include "cgit.h" -int next_char(FILE *f) -{ - int c = fgetc(f); - if (c=='\r') { - c = fgetc(f); - if (c!='\n') { - ungetc(c, f); - c = '\r'; - } - } - return c; -} - -void skip_line(FILE *f) -{ - int c; - - while((c=next_char(f)) && c!='\n' && c!=EOF) - ; -} - -int read_config_line(FILE *f, char *line, const char **value, int bufsize) -{ - int i = 0, isname = 0; - - *value = NULL; - while(i 8) - return -1; - if (!(f = fopen(filename, "r"))) - return -1; - nesting++; - while((len = read_config_line(f, line, &value, sizeof(line))) > 0) - (*fn)(line, value); - nesting--; - fclose(f); - return 0; -} - char *convert_query_hexchar(char *txt) { int d1, d2; -- cgit v1.2.1 From e87e89633383b8b75c68c98be3e0c14212109de2 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Tue, 8 Apr 2008 21:11:36 +0200 Subject: Move cgit_parse_query() from parsing.c to html.c as http_parse_querystring() This is a generic http-function. Signed-off-by: Lars Hjemli --- parsing.c | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) (limited to 'parsing.c') diff --git a/parsing.c b/parsing.c index 9a4a7a3..66e8b3d 100644 --- a/parsing.c +++ b/parsing.c @@ -8,55 +8,6 @@ #include "cgit.h" -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; -} - /* * url syntax: [repo ['/' cmd [ '/' path]]] * repo: any valid repo url, may contain '/' -- cgit v1.2.1