]> gitweb.ps.run Git - ps-cgit/blobdiff - cgit.c
Prepare for 'about site' page / add 'root-readme' option to cgitrc
[ps-cgit] / cgit.c
diff --git a/cgit.c b/cgit.c
index f749b6be181b85fdb9b020ef659f517b289a6b08..a402758fab53bc2c099e7b803fa8deee68226250 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -7,7 +7,10 @@
  */
 
 #include "cgit.h"
+#include "cache.h"
 #include "cmd.h"
+#include "configfile.h"
+#include "html.h"
 #include "ui-shared.h"
 
 const char *cgit_version = CGIT_VERSION;
@@ -16,6 +19,10 @@ void config_cb(const char *name, const char *value)
 {
        if (!strcmp(name, "root-title"))
                ctx.cfg.root_title = xstrdup(value);
+       else if (!strcmp(name, "root-desc"))
+               ctx.cfg.root_desc = xstrdup(value);
+       else if (!strcmp(name, "root-readme"))
+               ctx.cfg.root_readme = xstrdup(value);
        else if (!strcmp(name, "css"))
                ctx.cfg.css = xstrdup(value);
        else if (!strcmp(name, "logo"))
@@ -102,7 +109,7 @@ void config_cb(const char *name, const char *value)
                else
                        ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value));
        } else if (!strcmp(name, "include"))
-               cgit_read_config(value, config_cb);
+               parse_configfile(value, config_cb);
 }
 
 static void querystring_cb(const char *name, const char *value)
@@ -156,6 +163,7 @@ static void prepare_context(struct cgit_context *ctx)
        ctx->cfg.renamelimit = -1;
        ctx->cfg.robots = "index, nofollow";
        ctx->cfg.root_title = "Git repository browser";
+       ctx->cfg.root_desc = "a fast webinterface for the git dscm";
        ctx->cfg.script_name = CGIT_SCRIPT_NAME;
        ctx->page.mimetype = "text/html";
        ctx->page.charset = PAGE_ENCODING;
@@ -176,7 +184,9 @@ static int cgit_prepare_cache(struct cacheitem *item)
        }
 
        if (!ctx.repo) {
-               item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root));
+               item->name = xstrdup(fmt("%s/index.%s.html",
+                                        ctx.cfg.cache_root,
+                                        cache_safe_filename(ctx.qry.raw)));
                item->ttl = ctx.cfg.cache_root_ttl;
                return 1;
        }
@@ -299,7 +309,16 @@ static void process_request(struct cgit_context *ctx)
                return;
        }
 
-       if (cmd->want_repo && prepare_repo_cmd(ctx))
+       if (cmd->want_repo && !ctx->repo) {
+               cgit_print_http_headers(ctx);
+               cgit_print_docstart(ctx);
+               cgit_print_pageheader(ctx);
+               cgit_print_error(fmt("No repository selected"));
+               cgit_print_docend();
+               return;
+       }
+
+       if (ctx->repo && prepare_repo_cmd(ctx))
                return;
 
        if (cmd->want_layout) {
@@ -435,14 +454,15 @@ int main(int argc, const char **argv)
        cgit_repolist.count = 0;
        cgit_repolist.repos = NULL;
 
-       cgit_read_config(cgit_config_env ? cgit_config_env : CGIT_CONFIG,
+       parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG,
                         config_cb);
+       ctx.repo = NULL;
        if (getenv("SCRIPT_NAME"))
                ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME"));
        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) {