summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c3
-rw-r--r--cgit.h2
-rw-r--r--html.c64
-rw-r--r--html.h2
-rw-r--r--parsing.c49
-rw-r--r--shared.c12
6 files changed, 68 insertions, 64 deletions
diff --git a/cgit.c b/cgit.c
index 1f46e0d..763242a 100644
--- a/cgit.c
+++ b/cgit.c
@@ -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))
diff --git a/cgit.h b/cgit.h
index 91d18f8..ee8c716 100644
--- a/cgit.h
+++ b/cgit.h
@@ -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);
diff --git a/html.c b/html.c
index 0962e71..98ffaf9 100644
--- a/html.c
+++ b/html.c
@@ -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;
+}
diff --git a/html.h b/html.h
index 63f4551..e6fdc54 100644
--- a/html.h
+++ b/html.h
@@ -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 */
diff --git a/parsing.c b/parsing.c
index 9a4a7a3..66e8b3d 100644
--- a/parsing.c
+++ b/parsing.c
@@ -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;
-}
-
/*
diff --git a/shared.c b/shared.c
index 48002ac..f5875e4 100644
--- a/shared.c
+++ b/shared.c
@@ -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)