]> granicus.if.org Git - cgit/commitdiff
Move cgit_parse_query() from parsing.c to html.c as http_parse_querystring()
authorLars Hjemli <hjemli@gmail.com>
Tue, 8 Apr 2008 19:11:36 +0000 (21:11 +0200)
committerLars Hjemli <hjemli@gmail.com>
Tue, 8 Apr 2008 19:11:36 +0000 (21:11 +0200)
This is a generic http-function.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
cgit.c
cgit.h
html.c
html.h
parsing.c
shared.c

diff --git a/cgit.c b/cgit.c
index 1f46e0d701f83f3a36d2e9282f44461f956b1041..763242abc4258779fe5daa0ed8cec8c6bcb3bc43 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -10,6 +10,7 @@
 #include "cache.h"
 #include "cmd.h"
 #include "configfile.h"
+#include "html.h"
 #include "ui-shared.h"
 
 const char *cgit_version = CGIT_VERSION;
@@ -444,7 +445,7 @@ int main(int argc, const char **argv)
        if (getenv("QUERY_STRING"))
                ctx.qry.raw = xstrdup(getenv("QUERY_STRING"));
        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))
                return 0;
        if (ctx.cfg.nocache) {
diff --git a/cgit.h b/cgit.h
index 91d18f80182b07e6b310c0bc13dc9a49cbcd3d9e..ee8c716be4d50bd799d0c3fa899876bf7f54a2ec 100644 (file)
--- a/cgit.h
+++ b/cgit.h
@@ -191,7 +191,6 @@ extern int chk_zero(int result, char *msg);
 extern int chk_positive(int result, char *msg);
 extern int chk_non_negative(int result, char *msg);
 
-extern int hextoint(char c);
 extern char *trim_end(const char *str, char c);
 extern char *strlpart(char *txt, int maxlen);
 extern char *strrpart(char *txt, int maxlen);
@@ -214,7 +213,6 @@ extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
 
 extern char *fmt(const char *format,...);
 
-extern int cgit_parse_query(char *txt, configfn fn);
 extern struct commitinfo *cgit_parse_commit(struct commit *commit);
 extern struct taginfo *cgit_parse_tag(struct tag *tag);
 extern void cgit_parse_url(const char *url);
diff --git a/html.c b/html.c
index 0962e71a32b66a68f1653594de37506425e5eca9..98ffaf976a4abdf92e4ba4f5a973ab0c5184a515 100644 (file)
--- a/html.c
+++ b/html.c
@@ -185,3 +185,67 @@ int html_include(const char *filename)
        fclose(f);
        return 0;
 }
+
+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 63f4551e1dce5c649ba86fd6ee02dd7ccf07a9b4..e6fdc5442965f5f5ba3f699d2a3e6e575b01aa09 100644 (file)
--- a/html.h
+++ b/html.h
@@ -15,4 +15,6 @@ extern void html_link_close(void);
 extern void html_fileperm(unsigned short mode);
 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 */
index 9a4a7a35474d37184ccbf2b41eb2429a4e857baf..66e8b3db21fd4369f62f3ba8b0029276ea9e9cd5 100644 (file)
--- 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 '/'
index 48002accd987129bb72f62b9fc0b5d6a05bcf174..f5875e4273d55d6380dedd3310ebac08a9b636d7 100644 (file)
--- a/shared.c
+++ b/shared.c
@@ -89,18 +89,6 @@ void *cgit_free_commitinfo(struct commitinfo *info)
        return NULL;
 }
 
-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)
 {
        int len;