]> gitweb.ps.run Git - ps-cgit/blobdiff - parsing.c
Introduce struct cgit_context
[ps-cgit] / parsing.c
index f156c12b7ef6e8ce76a6e844db5ba530e2bc4a56..8cf56a4e89f2e7aa80878100b4197ebfe5d66afe 100644 (file)
--- a/parsing.c
+++ b/parsing.c
@@ -6,8 +6,6 @@
  *   (see COPYING for full license text)
  */
 
  *   (see COPYING for full license text)
  */
 
-#include <iconv.h>
-
 #include "cgit.h"
 
 int next_char(FILE *f)
 #include "cgit.h"
 
 int next_char(FILE *f)
@@ -151,7 +149,7 @@ void cgit_parse_url(const char *url)
 
        cgit_repo = cgit_get_repoinfo(url);
        if (cgit_repo) {
 
        cgit_repo = cgit_get_repoinfo(url);
        if (cgit_repo) {
-               cgit_query_repo = cgit_repo->url;
+               ctx.qry.repo = cgit_repo->url;
                return;
        }
 
                return;
        }
 
@@ -165,75 +163,19 @@ void cgit_parse_url(const char *url)
                        continue;
                }
 
                        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])
                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_cmd = cgit_get_cmd_index(cmd + 1);
-               cgit_query_page = xstrdup(cmd + 1);
+               ctx.qry.page = xstrdup(cmd + 1);
                return;
        }
 }
 
                return;
        }
 }
 
-static char *iconv_msg(char *msg, const char *encoding)
-{
-       iconv_t msg_conv = iconv_open(PAGE_ENCODING, encoding);
-       size_t inlen = strlen(msg);
-       char *in;
-       char *out;
-       size_t inleft;
-       size_t outleft;
-       char *buf;
-       char *ret;
-       size_t buf_sz;
-       int again, fail;
-
-       if(msg_conv == (iconv_t)-1)
-               return NULL;
-
-       buf_sz = inlen * 2;
-       buf = xmalloc(buf_sz+1);
-       do {
-               in = msg;
-               inleft = inlen;
-
-               out = buf;
-               outleft = buf_sz;
-               iconv(msg_conv, &in, &inleft, &out, &outleft);
-
-               if(inleft == 0) {
-                       fail = 0;
-                       again = 0;
-               } else if(inleft != 0 && errno == E2BIG) {
-                       fail = 0;
-                       again = 1;
-
-                       buf_sz *= 2;
-                       free(buf);
-                       buf = xmalloc(buf_sz+1);
-               } else {
-                       fail = 1;
-                       again = 0;
-               }
-       } while(again && !fail);
-
-       if(fail) {
-               free(buf);
-               ret = NULL;
-       } else {
-               buf = xrealloc(buf, out - buf);
-               *out = 0;
-               ret = buf;
-       }
-
-       iconv_close(msg_conv);
-
-       return ret;
-}
-
 char *substr(const char *head, const char *tail)
 {
        char *buf;
 char *substr(const char *head, const char *tail)
 {
        char *buf;
@@ -277,7 +219,7 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
                p = t;
                t = strchr(t, '>') + 1;
                ret->author_email = substr(p, t);
                p = t;
                t = strchr(t, '>') + 1;
                ret->author_email = substr(p, t);
-               ret->author_date = atol(++t);
+               ret->author_date = atol(t+1);
                p = strchr(t, '\n') + 1;
        }
 
                p = strchr(t, '\n') + 1;
        }
 
@@ -288,7 +230,7 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
                p = t;
                t = strchr(t, '>') + 1;
                ret->committer_email = substr(p, t);
                p = t;
                t = strchr(t, '>') + 1;
                ret->committer_email = substr(p, t);
-               ret->committer_date = atol(++t);
+               ret->committer_date = atol(t+1);
                p = strchr(t, '\n') + 1;
        }
 
                p = strchr(t, '\n') + 1;
        }
 
@@ -320,6 +262,22 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
        } else
                ret->subject = substr(p, p+strlen(p));
 
        } else
                ret->subject = substr(p, p+strlen(p));
 
+       if(strcmp(ret->msg_encoding, PAGE_ENCODING)) {
+               t = reencode_string(ret->subject, PAGE_ENCODING,
+                                   ret->msg_encoding);
+               if(t) {
+                       free(ret->subject);
+                       ret->subject = t;
+               }
+
+               t = reencode_string(ret->msg, PAGE_ENCODING,
+                                   ret->msg_encoding);
+               if(t) {
+                       free(ret->msg);
+                       ret->msg = t;
+               }
+       }
+
        return ret;
 }
 
        return ret;
 }
 
@@ -357,7 +315,7 @@ struct taginfo *cgit_parse_tag(struct tag *tag)
                        p = t;
                        t = strchr(t, '>') + 1;
                        ret->tagger_email = substr(p, t);
                        p = t;
                        t = strchr(t, '>') + 1;
                        ret->tagger_email = substr(p, t);
-                       ret->tagger_date = atol(++t);
+                       ret->tagger_date = atol(t+1);
                }
                p = strchr(p, '\n') + 1;
        }
                }
                p = strchr(p, '\n') + 1;
        }