2006-12-10 22:41:14 +01:00
|
|
|
/* cgit.c: cgi for the git scm
|
|
|
|
*
|
2014-01-08 15:10:49 +01:00
|
|
|
* Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
|
2006-12-10 22:41:14 +01:00
|
|
|
*
|
|
|
|
* Licensed under GNU General Public License v2
|
|
|
|
* (see COPYING for full license text)
|
|
|
|
*/
|
|
|
|
|
2006-12-09 15:18:17 +01:00
|
|
|
#include "cgit.h"
|
2008-03-27 09:22:13 +01:00
|
|
|
#include "cache.h"
|
2008-03-24 00:51:19 +01:00
|
|
|
#include "cmd.h"
|
2008-03-28 00:09:11 +01:00
|
|
|
#include "configfile.h"
|
2008-04-08 21:11:36 +02:00
|
|
|
#include "html.h"
|
2008-03-24 16:50:57 +01:00
|
|
|
#include "ui-shared.h"
|
2008-12-07 13:17:21 +01:00
|
|
|
#include "ui-stats.h"
|
2013-05-25 16:32:37 +02:00
|
|
|
#include "ui-blob.h"
|
|
|
|
#include "ui-summary.h"
|
2008-09-15 00:07:12 +02:00
|
|
|
#include "scan-tree.h"
|
2006-12-09 15:18:17 +01:00
|
|
|
|
2008-03-24 23:10:59 +01:00
|
|
|
const char *cgit_version = CGIT_VERSION;
|
|
|
|
|
2013-03-04 08:52:33 +01:00
|
|
|
static void add_mimetype(const char *name, const char *value)
|
2009-02-13 20:43:30 +01:00
|
|
|
{
|
|
|
|
struct string_list_item *item;
|
|
|
|
|
2010-08-22 13:29:57 +02:00
|
|
|
item = string_list_insert(&ctx.cfg.mimetypes, xstrdup(name));
|
2009-02-13 20:43:30 +01:00
|
|
|
item->util = xstrdup(value);
|
|
|
|
}
|
|
|
|
|
2009-08-20 17:41:54 +02:00
|
|
|
static void process_cached_repolist(const char *path);
|
|
|
|
|
2013-03-04 08:52:33 +01:00
|
|
|
static void repo_config(struct cgit_repo *repo, const char *name, const char *value)
|
2009-08-23 23:23:20 +02:00
|
|
|
{
|
2011-06-15 10:04:13 +02:00
|
|
|
struct string_list_item *item;
|
|
|
|
|
2009-08-23 23:23:20 +02:00
|
|
|
if (!strcmp(name, "name"))
|
|
|
|
repo->name = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "clone-url"))
|
|
|
|
repo->clone_url = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "desc"))
|
|
|
|
repo->desc = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "owner"))
|
|
|
|
repo->owner = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "defbranch"))
|
|
|
|
repo->defbranch = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "snapshots"))
|
|
|
|
repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value);
|
2010-11-15 18:39:50 +01:00
|
|
|
else if (!strcmp(name, "enable-commit-graph"))
|
2012-04-18 12:32:13 +02:00
|
|
|
repo->enable_commit_graph = atoi(value);
|
2009-08-23 23:23:20 +02:00
|
|
|
else if (!strcmp(name, "enable-log-filecount"))
|
2012-04-18 12:32:13 +02:00
|
|
|
repo->enable_log_filecount = atoi(value);
|
2009-08-23 23:23:20 +02:00
|
|
|
else if (!strcmp(name, "enable-log-linecount"))
|
2012-04-18 12:32:13 +02:00
|
|
|
repo->enable_log_linecount = atoi(value);
|
2009-11-07 19:10:58 +01:00
|
|
|
else if (!strcmp(name, "enable-remote-branches"))
|
|
|
|
repo->enable_remote_branches = atoi(value);
|
2010-02-27 13:12:55 +01:00
|
|
|
else if (!strcmp(name, "enable-subject-links"))
|
|
|
|
repo->enable_subject_links = atoi(value);
|
2013-04-08 16:57:12 +02:00
|
|
|
else if (!strcmp(name, "branch-sort")) {
|
|
|
|
if (!strcmp(value, "age"))
|
|
|
|
repo->branch_sort = 1;
|
|
|
|
if (!strcmp(value, "name"))
|
|
|
|
repo->branch_sort = 0;
|
|
|
|
} else if (!strcmp(name, "commit-sort")) {
|
2012-10-13 16:10:30 +02:00
|
|
|
if (!strcmp(value, "date"))
|
|
|
|
repo->commit_sort = 1;
|
|
|
|
if (!strcmp(value, "topo"))
|
|
|
|
repo->commit_sort = 2;
|
|
|
|
} else if (!strcmp(name, "max-stats"))
|
2009-08-23 23:23:20 +02:00
|
|
|
repo->max_stats = cgit_find_stats_period(value, NULL);
|
|
|
|
else if (!strcmp(name, "module-link"))
|
|
|
|
repo->module_link= xstrdup(value);
|
2014-05-29 17:35:46 +02:00
|
|
|
else if (starts_with(name, "module-link.")) {
|
2013-05-26 15:20:02 +02:00
|
|
|
item = string_list_append(&repo->submodules, xstrdup(name + 12));
|
2011-06-15 10:04:13 +02:00
|
|
|
item->util = xstrdup(value);
|
|
|
|
} else if (!strcmp(name, "section"))
|
2009-08-23 23:23:20 +02:00
|
|
|
repo->section = xstrdup(value);
|
2013-05-26 15:20:02 +02:00
|
|
|
else if (!strcmp(name, "readme") && value != NULL) {
|
|
|
|
if (repo->readme.items == ctx.cfg.readme.items)
|
|
|
|
memset(&repo->readme, 0, sizeof(repo->readme));
|
|
|
|
string_list_append(&repo->readme, xstrdup(value));
|
|
|
|
} else if (!strcmp(name, "logo") && value != NULL)
|
2010-12-23 12:47:54 +01:00
|
|
|
repo->logo = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "logo-link") && value != NULL)
|
|
|
|
repo->logo_link = xstrdup(value);
|
|
|
|
else if (ctx.cfg.enable_filter_overrides) {
|
2009-08-24 08:53:21 +02:00
|
|
|
if (!strcmp(name, "about-filter"))
|
2014-01-10 05:19:05 +01:00
|
|
|
repo->about_filter = cgit_new_filter(value, ABOUT);
|
2009-08-24 08:53:21 +02:00
|
|
|
else if (!strcmp(name, "commit-filter"))
|
2014-01-10 05:19:05 +01:00
|
|
|
repo->commit_filter = cgit_new_filter(value, COMMIT);
|
2009-08-24 08:53:21 +02:00
|
|
|
else if (!strcmp(name, "source-filter"))
|
2014-01-10 05:19:05 +01:00
|
|
|
repo->source_filter = cgit_new_filter(value, SOURCE);
|
2014-01-13 04:04:52 +01:00
|
|
|
else if (!strcmp(name, "email-filter"))
|
|
|
|
repo->email_filter = cgit_new_filter(value, EMAIL);
|
2014-08-04 15:23:08 +02:00
|
|
|
else if (!strcmp(name, "owner-filter"))
|
|
|
|
repo->owner_filter = cgit_new_filter(value, OWNER);
|
2015-01-29 12:52:49 +01:00
|
|
|
} else if (!strcmp(name, "hide")) {
|
|
|
|
repo->hide = atoi(value);
|
|
|
|
} else if (!strcmp(name, "ignore")) {
|
|
|
|
repo->ignore = atoi(value);
|
2009-08-23 23:23:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-04 08:52:33 +01:00
|
|
|
static void config_cb(const char *name, const char *value)
|
2008-03-24 17:26:08 +01:00
|
|
|
{
|
2009-08-23 23:23:20 +02:00
|
|
|
if (!strcmp(name, "section") || !strcmp(name, "repo.group"))
|
|
|
|
ctx.cfg.section = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "repo.url"))
|
|
|
|
ctx.repo = cgit_add_repo(value);
|
|
|
|
else if (ctx.repo && !strcmp(name, "repo.path"))
|
|
|
|
ctx.repo->path = trim_end(value, '/');
|
2014-05-29 17:35:46 +02:00
|
|
|
else if (ctx.repo && starts_with(name, "repo."))
|
2009-08-23 23:23:20 +02:00
|
|
|
repo_config(ctx.repo, name + 5, value);
|
2013-05-26 15:20:02 +02:00
|
|
|
else if (!strcmp(name, "readme") && value != NULL)
|
|
|
|
string_list_append(&ctx.cfg.readme, xstrdup(value));
|
2009-08-23 23:23:20 +02:00
|
|
|
else if (!strcmp(name, "root-title"))
|
2008-03-24 17:26:08 +01:00
|
|
|
ctx.cfg.root_title = xstrdup(value);
|
2008-04-29 00:55:34 +02:00
|
|
|
else if (!strcmp(name, "root-desc"))
|
|
|
|
ctx.cfg.root_desc = xstrdup(value);
|
2008-04-29 01:06:30 +02:00
|
|
|
else if (!strcmp(name, "root-readme"))
|
|
|
|
ctx.cfg.root_readme = xstrdup(value);
|
2008-03-24 17:26:08 +01:00
|
|
|
else if (!strcmp(name, "css"))
|
|
|
|
ctx.cfg.css = xstrdup(value);
|
2008-07-19 20:40:30 +02:00
|
|
|
else if (!strcmp(name, "favicon"))
|
|
|
|
ctx.cfg.favicon = xstrdup(value);
|
2008-06-26 13:53:30 +02:00
|
|
|
else if (!strcmp(name, "footer"))
|
|
|
|
ctx.cfg.footer = xstrdup(value);
|
2009-03-15 05:11:54 +01:00
|
|
|
else if (!strcmp(name, "head-include"))
|
|
|
|
ctx.cfg.head_include = xstrdup(value);
|
2009-01-29 21:27:39 +01:00
|
|
|
else if (!strcmp(name, "header"))
|
|
|
|
ctx.cfg.header = xstrdup(value);
|
2008-03-24 17:26:08 +01:00
|
|
|
else if (!strcmp(name, "logo"))
|
|
|
|
ctx.cfg.logo = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "index-header"))
|
|
|
|
ctx.cfg.index_header = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "index-info"))
|
|
|
|
ctx.cfg.index_info = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "logo-link"))
|
|
|
|
ctx.cfg.logo_link = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "module-link"))
|
|
|
|
ctx.cfg.module_link = xstrdup(value);
|
2010-11-08 19:41:13 +01:00
|
|
|
else if (!strcmp(name, "strict-export"))
|
|
|
|
ctx.cfg.strict_export = xstrdup(value);
|
2008-03-24 17:26:08 +01:00
|
|
|
else if (!strcmp(name, "virtual-root")) {
|
2013-04-01 20:03:34 +02:00
|
|
|
ctx.cfg.virtual_root = ensure_end(value, '/');
|
2008-03-24 17:26:08 +01:00
|
|
|
} else if (!strcmp(name, "nocache"))
|
|
|
|
ctx.cfg.nocache = atoi(value);
|
2009-08-07 14:05:17 +02:00
|
|
|
else if (!strcmp(name, "noplainemail"))
|
|
|
|
ctx.cfg.noplainemail = atoi(value);
|
2009-07-25 12:19:31 +02:00
|
|
|
else if (!strcmp(name, "noheader"))
|
|
|
|
ctx.cfg.noheader = atoi(value);
|
2008-03-24 17:26:08 +01:00
|
|
|
else if (!strcmp(name, "snapshots"))
|
|
|
|
ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
|
2009-08-24 08:53:21 +02:00
|
|
|
else if (!strcmp(name, "enable-filter-overrides"))
|
|
|
|
ctx.cfg.enable_filter_overrides = atoi(value);
|
2011-01-12 19:06:07 +01:00
|
|
|
else if (!strcmp(name, "enable-http-clone"))
|
|
|
|
ctx.cfg.enable_http_clone = atoi(value);
|
2008-03-24 17:26:08 +01:00
|
|
|
else if (!strcmp(name, "enable-index-links"))
|
|
|
|
ctx.cfg.enable_index_links = atoi(value);
|
2013-02-01 10:59:13 +01:00
|
|
|
else if (!strcmp(name, "enable-index-owner"))
|
|
|
|
ctx.cfg.enable_index_owner = atoi(value);
|
2010-11-15 18:39:50 +01:00
|
|
|
else if (!strcmp(name, "enable-commit-graph"))
|
|
|
|
ctx.cfg.enable_commit_graph = atoi(value);
|
2008-03-24 17:26:08 +01:00
|
|
|
else if (!strcmp(name, "enable-log-filecount"))
|
|
|
|
ctx.cfg.enable_log_filecount = atoi(value);
|
|
|
|
else if (!strcmp(name, "enable-log-linecount"))
|
|
|
|
ctx.cfg.enable_log_linecount = atoi(value);
|
2009-11-07 19:10:58 +01:00
|
|
|
else if (!strcmp(name, "enable-remote-branches"))
|
|
|
|
ctx.cfg.enable_remote_branches = atoi(value);
|
2010-02-27 13:12:55 +01:00
|
|
|
else if (!strcmp(name, "enable-subject-links"))
|
|
|
|
ctx.cfg.enable_subject_links = atoi(value);
|
2009-08-21 14:26:52 +02:00
|
|
|
else if (!strcmp(name, "enable-tree-linenumbers"))
|
|
|
|
ctx.cfg.enable_tree_linenumbers = atoi(value);
|
2012-10-09 12:56:14 +02:00
|
|
|
else if (!strcmp(name, "enable-git-config"))
|
|
|
|
ctx.cfg.enable_git_config = atoi(value);
|
2008-12-07 13:17:21 +01:00
|
|
|
else if (!strcmp(name, "max-stats"))
|
|
|
|
ctx.cfg.max_stats = cgit_find_stats_period(value, NULL);
|
2008-04-28 11:32:42 +02:00
|
|
|
else if (!strcmp(name, "cache-size"))
|
|
|
|
ctx.cfg.cache_size = atoi(value);
|
2008-03-24 17:26:08 +01:00
|
|
|
else if (!strcmp(name, "cache-root"))
|
2010-03-22 00:09:43 +01:00
|
|
|
ctx.cfg.cache_root = xstrdup(expand_macros(value));
|
2008-03-24 17:26:08 +01:00
|
|
|
else if (!strcmp(name, "cache-root-ttl"))
|
|
|
|
ctx.cfg.cache_root_ttl = atoi(value);
|
|
|
|
else if (!strcmp(name, "cache-repo-ttl"))
|
|
|
|
ctx.cfg.cache_repo_ttl = atoi(value);
|
2009-08-20 17:41:54 +02:00
|
|
|
else if (!strcmp(name, "cache-scanrc-ttl"))
|
|
|
|
ctx.cfg.cache_scanrc_ttl = atoi(value);
|
2008-03-24 17:26:08 +01:00
|
|
|
else if (!strcmp(name, "cache-static-ttl"))
|
|
|
|
ctx.cfg.cache_static_ttl = atoi(value);
|
|
|
|
else if (!strcmp(name, "cache-dynamic-ttl"))
|
|
|
|
ctx.cfg.cache_dynamic_ttl = atoi(value);
|
2013-05-28 16:33:30 +02:00
|
|
|
else if (!strcmp(name, "cache-about-ttl"))
|
|
|
|
ctx.cfg.cache_about_ttl = atoi(value);
|
2014-02-05 10:23:58 +01:00
|
|
|
else if (!strcmp(name, "cache-snapshot-ttl"))
|
|
|
|
ctx.cfg.cache_snapshot_ttl = atoi(value);
|
2012-07-12 19:13:39 +02:00
|
|
|
else if (!strcmp(name, "case-sensitive-sort"))
|
|
|
|
ctx.cfg.case_sensitive_sort = atoi(value);
|
2009-08-09 13:27:21 +02:00
|
|
|
else if (!strcmp(name, "about-filter"))
|
2014-01-10 05:19:05 +01:00
|
|
|
ctx.cfg.about_filter = cgit_new_filter(value, ABOUT);
|
2009-07-31 17:42:57 +02:00
|
|
|
else if (!strcmp(name, "commit-filter"))
|
2014-01-10 05:19:05 +01:00
|
|
|
ctx.cfg.commit_filter = cgit_new_filter(value, COMMIT);
|
2014-01-13 04:04:52 +01:00
|
|
|
else if (!strcmp(name, "email-filter"))
|
|
|
|
ctx.cfg.email_filter = cgit_new_filter(value, EMAIL);
|
2014-08-04 15:23:08 +02:00
|
|
|
else if (!strcmp(name, "owner-filter"))
|
|
|
|
ctx.cfg.owner_filter = cgit_new_filter(value, OWNER);
|
2014-01-14 21:49:31 +01:00
|
|
|
else if (!strcmp(name, "auth-filter"))
|
|
|
|
ctx.cfg.auth_filter = cgit_new_filter(value, AUTH);
|
2009-01-22 23:33:56 +01:00
|
|
|
else if (!strcmp(name, "embedded"))
|
|
|
|
ctx.cfg.embedded = atoi(value);
|
2010-02-05 01:08:16 +01:00
|
|
|
else if (!strcmp(name, "max-atom-items"))
|
|
|
|
ctx.cfg.max_atom_items = atoi(value);
|
2008-03-24 17:26:08 +01:00
|
|
|
else if (!strcmp(name, "max-message-length"))
|
|
|
|
ctx.cfg.max_msg_len = atoi(value);
|
|
|
|
else if (!strcmp(name, "max-repodesc-length"))
|
|
|
|
ctx.cfg.max_repodesc_len = atoi(value);
|
2009-11-28 03:44:33 +01:00
|
|
|
else if (!strcmp(name, "max-blob-size"))
|
|
|
|
ctx.cfg.max_blob_size = atoi(value);
|
2008-05-03 10:54:39 +02:00
|
|
|
else if (!strcmp(name, "max-repo-count"))
|
|
|
|
ctx.cfg.max_repo_count = atoi(value);
|
2008-03-24 17:26:08 +01:00
|
|
|
else if (!strcmp(name, "max-commit-count"))
|
|
|
|
ctx.cfg.max_commit_count = atoi(value);
|
2010-07-29 17:52:29 +02:00
|
|
|
else if (!strcmp(name, "project-list"))
|
|
|
|
ctx.cfg.project_list = xstrdup(expand_macros(value));
|
2009-08-23 19:35:56 +02:00
|
|
|
else if (!strcmp(name, "scan-path"))
|
|
|
|
if (!ctx.cfg.nocache && ctx.cfg.cache_size)
|
2010-03-22 00:09:43 +01:00
|
|
|
process_cached_repolist(expand_macros(value));
|
2010-07-29 17:52:29 +02:00
|
|
|
else if (ctx.cfg.project_list)
|
|
|
|
scan_projects(expand_macros(value),
|
|
|
|
ctx.cfg.project_list, repo_config);
|
2009-08-23 19:35:56 +02:00
|
|
|
else
|
2010-03-22 00:09:43 +01:00
|
|
|
scan_tree(expand_macros(value), repo_config);
|
2010-11-15 20:41:00 +01:00
|
|
|
else if (!strcmp(name, "scan-hidden-path"))
|
|
|
|
ctx.cfg.scan_hidden_path = atoi(value);
|
2010-08-21 15:44:09 +02:00
|
|
|
else if (!strcmp(name, "section-from-path"))
|
|
|
|
ctx.cfg.section_from_path = atoi(value);
|
2012-10-16 23:32:40 +02:00
|
|
|
else if (!strcmp(name, "repository-sort"))
|
|
|
|
ctx.cfg.repository_sort = xstrdup(value);
|
2012-10-09 20:53:29 +02:00
|
|
|
else if (!strcmp(name, "section-sort"))
|
|
|
|
ctx.cfg.section_sort = atoi(value);
|
2009-07-31 16:55:27 +02:00
|
|
|
else if (!strcmp(name, "source-filter"))
|
2014-01-10 05:19:05 +01:00
|
|
|
ctx.cfg.source_filter = cgit_new_filter(value, SOURCE);
|
2008-03-24 17:26:08 +01:00
|
|
|
else if (!strcmp(name, "summary-log"))
|
|
|
|
ctx.cfg.summary_log = atoi(value);
|
|
|
|
else if (!strcmp(name, "summary-branches"))
|
|
|
|
ctx.cfg.summary_branches = atoi(value);
|
|
|
|
else if (!strcmp(name, "summary-tags"))
|
|
|
|
ctx.cfg.summary_tags = atoi(value);
|
2009-09-14 20:19:02 +02:00
|
|
|
else if (!strcmp(name, "side-by-side-diffs"))
|
2014-10-05 11:59:04 +02:00
|
|
|
ctx.cfg.difftype = atoi(value) ? DIFF_SSDIFF : DIFF_UNIFIED;
|
2008-03-24 17:26:08 +01:00
|
|
|
else if (!strcmp(name, "agefile"))
|
|
|
|
ctx.cfg.agefile = xstrdup(value);
|
2011-07-19 10:51:58 +02:00
|
|
|
else if (!strcmp(name, "mimetype-file"))
|
|
|
|
ctx.cfg.mimetype_file = xstrdup(value);
|
2008-03-24 17:26:08 +01:00
|
|
|
else if (!strcmp(name, "renamelimit"))
|
|
|
|
ctx.cfg.renamelimit = atoi(value);
|
2010-07-29 19:47:50 +02:00
|
|
|
else if (!strcmp(name, "remove-suffix"))
|
|
|
|
ctx.cfg.remove_suffix = atoi(value);
|
2008-03-24 17:26:08 +01:00
|
|
|
else if (!strcmp(name, "robots"))
|
|
|
|
ctx.cfg.robots = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "clone-prefix"))
|
|
|
|
ctx.cfg.clone_prefix = xstrdup(value);
|
2011-06-06 22:49:13 +02:00
|
|
|
else if (!strcmp(name, "clone-url"))
|
|
|
|
ctx.cfg.clone_url = xstrdup(value);
|
2008-08-01 14:54:38 +02:00
|
|
|
else if (!strcmp(name, "local-time"))
|
|
|
|
ctx.cfg.local_time = atoi(value);
|
2012-10-13 16:10:30 +02:00
|
|
|
else if (!strcmp(name, "commit-sort")) {
|
|
|
|
if (!strcmp(value, "date"))
|
|
|
|
ctx.cfg.commit_sort = 1;
|
|
|
|
if (!strcmp(value, "topo"))
|
|
|
|
ctx.cfg.commit_sort = 2;
|
2013-04-08 16:57:12 +02:00
|
|
|
} else if (!strcmp(name, "branch-sort")) {
|
|
|
|
if (!strcmp(value, "age"))
|
|
|
|
ctx.cfg.branch_sort = 1;
|
|
|
|
if (!strcmp(value, "name"))
|
|
|
|
ctx.cfg.branch_sort = 0;
|
2014-05-29 17:35:46 +02:00
|
|
|
} else if (starts_with(name, "mimetype."))
|
2009-02-13 20:43:30 +01:00
|
|
|
add_mimetype(name + 9, value);
|
2009-08-23 23:23:20 +02:00
|
|
|
else if (!strcmp(name, "include"))
|
2010-03-22 00:09:43 +01:00
|
|
|
parse_configfile(expand_macros(value), config_cb);
|
2008-03-24 17:26:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void querystring_cb(const char *name, const char *value)
|
|
|
|
{
|
2009-08-17 09:05:13 +02:00
|
|
|
if (!value)
|
|
|
|
value = "";
|
|
|
|
|
2008-03-24 17:26:08 +01:00
|
|
|
if (!strcmp(name,"r")) {
|
|
|
|
ctx.qry.repo = xstrdup(value);
|
|
|
|
ctx.repo = cgit_get_repoinfo(value);
|
|
|
|
} else if (!strcmp(name, "p")) {
|
|
|
|
ctx.qry.page = xstrdup(value);
|
|
|
|
} else if (!strcmp(name, "url")) {
|
2009-09-14 23:37:13 +02:00
|
|
|
if (*value == '/')
|
|
|
|
value++;
|
2008-08-09 21:11:41 +02:00
|
|
|
ctx.qry.url = xstrdup(value);
|
2008-03-24 17:26:08 +01:00
|
|
|
cgit_parse_url(value);
|
|
|
|
} else if (!strcmp(name, "qt")) {
|
|
|
|
ctx.qry.grep = xstrdup(value);
|
|
|
|
} else if (!strcmp(name, "q")) {
|
|
|
|
ctx.qry.search = xstrdup(value);
|
|
|
|
} else if (!strcmp(name, "h")) {
|
|
|
|
ctx.qry.head = xstrdup(value);
|
|
|
|
ctx.qry.has_symref = 1;
|
|
|
|
} else if (!strcmp(name, "id")) {
|
|
|
|
ctx.qry.sha1 = xstrdup(value);
|
|
|
|
ctx.qry.has_sha1 = 1;
|
|
|
|
} else if (!strcmp(name, "id2")) {
|
|
|
|
ctx.qry.sha2 = xstrdup(value);
|
|
|
|
ctx.qry.has_sha1 = 1;
|
|
|
|
} else if (!strcmp(name, "ofs")) {
|
|
|
|
ctx.qry.ofs = atoi(value);
|
|
|
|
} else if (!strcmp(name, "path")) {
|
|
|
|
ctx.qry.path = trim_end(value, '/');
|
|
|
|
} else if (!strcmp(name, "name")) {
|
|
|
|
ctx.qry.name = xstrdup(value);
|
2008-06-24 23:42:32 +02:00
|
|
|
} else if (!strcmp(name, "mimetype")) {
|
|
|
|
ctx.qry.mimetype = xstrdup(value);
|
2013-03-04 05:21:33 +01:00
|
|
|
} else if (!strcmp(name, "s")) {
|
2008-11-25 15:25:35 +01:00
|
|
|
ctx.qry.sort = xstrdup(value);
|
2008-11-29 18:39:41 +01:00
|
|
|
} else if (!strcmp(name, "showmsg")) {
|
|
|
|
ctx.qry.showmsg = atoi(value);
|
2008-12-06 17:38:19 +01:00
|
|
|
} else if (!strcmp(name, "period")) {
|
|
|
|
ctx.qry.period = xstrdup(value);
|
2014-10-05 11:59:04 +02:00
|
|
|
} else if (!strcmp(name, "dt")) {
|
|
|
|
ctx.qry.difftype = atoi(value);
|
|
|
|
ctx.qry.has_difftype = 1;
|
2009-09-14 20:19:02 +02:00
|
|
|
} else if (!strcmp(name, "ss")) {
|
2014-10-05 11:59:04 +02:00
|
|
|
/* No longer generated, but there may be links out there. */
|
|
|
|
ctx.qry.difftype = atoi(value) ? DIFF_SSDIFF : DIFF_UNIFIED;
|
|
|
|
ctx.qry.has_difftype = 1;
|
2010-02-04 01:31:17 +01:00
|
|
|
} else if (!strcmp(name, "all")) {
|
|
|
|
ctx.qry.show_all = atoi(value);
|
2010-06-10 20:15:27 +02:00
|
|
|
} else if (!strcmp(name, "context")) {
|
|
|
|
ctx.qry.context = atoi(value);
|
2010-06-24 17:52:57 +02:00
|
|
|
} else if (!strcmp(name, "ignorews")) {
|
|
|
|
ctx.qry.ignorews = atoi(value);
|
2008-03-24 17:26:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
static void prepare_context(void)
|
2008-03-24 17:26:08 +01:00
|
|
|
{
|
2014-01-15 21:53:15 +01:00
|
|
|
memset(&ctx, 0, sizeof(ctx));
|
|
|
|
ctx.cfg.agefile = "info/web/last-modified";
|
|
|
|
ctx.cfg.nocache = 0;
|
|
|
|
ctx.cfg.cache_size = 0;
|
|
|
|
ctx.cfg.cache_max_create_time = 5;
|
|
|
|
ctx.cfg.cache_root = CGIT_CACHE_ROOT;
|
|
|
|
ctx.cfg.cache_about_ttl = 15;
|
2014-02-05 10:23:58 +01:00
|
|
|
ctx.cfg.cache_snapshot_ttl = 5;
|
2014-01-15 21:53:15 +01:00
|
|
|
ctx.cfg.cache_repo_ttl = 5;
|
|
|
|
ctx.cfg.cache_root_ttl = 5;
|
|
|
|
ctx.cfg.cache_scanrc_ttl = 15;
|
|
|
|
ctx.cfg.cache_dynamic_ttl = 5;
|
|
|
|
ctx.cfg.cache_static_ttl = -1;
|
|
|
|
ctx.cfg.case_sensitive_sort = 1;
|
|
|
|
ctx.cfg.branch_sort = 0;
|
|
|
|
ctx.cfg.commit_sort = 0;
|
|
|
|
ctx.cfg.css = "/cgit.css";
|
|
|
|
ctx.cfg.logo = "/cgit.png";
|
|
|
|
ctx.cfg.favicon = "/favicon.ico";
|
|
|
|
ctx.cfg.local_time = 0;
|
|
|
|
ctx.cfg.enable_http_clone = 1;
|
|
|
|
ctx.cfg.enable_index_owner = 1;
|
|
|
|
ctx.cfg.enable_tree_linenumbers = 1;
|
|
|
|
ctx.cfg.enable_git_config = 0;
|
|
|
|
ctx.cfg.max_repo_count = 50;
|
|
|
|
ctx.cfg.max_commit_count = 50;
|
|
|
|
ctx.cfg.max_lock_attempts = 5;
|
|
|
|
ctx.cfg.max_msg_len = 80;
|
|
|
|
ctx.cfg.max_repodesc_len = 80;
|
|
|
|
ctx.cfg.max_blob_size = 0;
|
|
|
|
ctx.cfg.max_stats = 0;
|
|
|
|
ctx.cfg.project_list = NULL;
|
|
|
|
ctx.cfg.renamelimit = -1;
|
|
|
|
ctx.cfg.remove_suffix = 0;
|
|
|
|
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.scan_hidden_path = 0;
|
|
|
|
ctx.cfg.script_name = CGIT_SCRIPT_NAME;
|
|
|
|
ctx.cfg.section = "";
|
|
|
|
ctx.cfg.repository_sort = "name";
|
|
|
|
ctx.cfg.section_sort = 1;
|
|
|
|
ctx.cfg.summary_branches = 10;
|
|
|
|
ctx.cfg.summary_log = 10;
|
|
|
|
ctx.cfg.summary_tags = 10;
|
|
|
|
ctx.cfg.max_atom_items = 10;
|
2014-10-05 11:59:04 +02:00
|
|
|
ctx.cfg.difftype = DIFF_UNIFIED;
|
2014-01-15 21:53:15 +01:00
|
|
|
ctx.env.cgit_config = getenv("CGIT_CONFIG");
|
|
|
|
ctx.env.http_host = getenv("HTTP_HOST");
|
|
|
|
ctx.env.https = getenv("HTTPS");
|
|
|
|
ctx.env.no_http = getenv("NO_HTTP");
|
|
|
|
ctx.env.path_info = getenv("PATH_INFO");
|
|
|
|
ctx.env.query_string = getenv("QUERY_STRING");
|
|
|
|
ctx.env.request_method = getenv("REQUEST_METHOD");
|
|
|
|
ctx.env.script_name = getenv("SCRIPT_NAME");
|
|
|
|
ctx.env.server_name = getenv("SERVER_NAME");
|
|
|
|
ctx.env.server_port = getenv("SERVER_PORT");
|
|
|
|
ctx.env.http_cookie = getenv("HTTP_COOKIE");
|
|
|
|
ctx.env.http_referer = getenv("HTTP_REFERER");
|
|
|
|
ctx.env.content_length = getenv("CONTENT_LENGTH") ? strtoul(getenv("CONTENT_LENGTH"), NULL, 10) : 0;
|
|
|
|
ctx.env.authenticated = 0;
|
|
|
|
ctx.page.mimetype = "text/html";
|
|
|
|
ctx.page.charset = PAGE_ENCODING;
|
|
|
|
ctx.page.filename = NULL;
|
|
|
|
ctx.page.size = 0;
|
|
|
|
ctx.page.modified = time(NULL);
|
|
|
|
ctx.page.expires = ctx.page.modified;
|
|
|
|
ctx.page.etag = NULL;
|
|
|
|
memset(&ctx.cfg.mimetypes, 0, sizeof(struct string_list));
|
|
|
|
if (ctx.env.script_name)
|
|
|
|
ctx.cfg.script_name = xstrdup(ctx.env.script_name);
|
|
|
|
if (ctx.env.query_string)
|
|
|
|
ctx.qry.raw = xstrdup(ctx.env.query_string);
|
|
|
|
if (!ctx.env.cgit_config)
|
|
|
|
ctx.env.cgit_config = CGIT_CONFIG;
|
2007-01-12 00:00:15 +01:00
|
|
|
}
|
|
|
|
|
2008-01-04 13:43:40 +01:00
|
|
|
struct refmatch {
|
|
|
|
char *req_ref;
|
|
|
|
char *first_ref;
|
|
|
|
int match;
|
|
|
|
};
|
|
|
|
|
2013-03-04 08:52:33 +01:00
|
|
|
static int find_current_ref(const char *refname, const unsigned char *sha1,
|
|
|
|
int flags, void *cb_data)
|
2008-01-04 13:43:40 +01:00
|
|
|
{
|
|
|
|
struct refmatch *info;
|
|
|
|
|
|
|
|
info = (struct refmatch *)cb_data;
|
|
|
|
if (!strcmp(refname, info->req_ref))
|
|
|
|
info->match = 1;
|
|
|
|
if (!info->first_ref)
|
|
|
|
info->first_ref = xstrdup(refname);
|
|
|
|
return info->match;
|
|
|
|
}
|
|
|
|
|
2013-03-04 13:25:35 +01:00
|
|
|
static void free_refmatch_inner(struct refmatch *info)
|
|
|
|
{
|
|
|
|
if (info->first_ref)
|
|
|
|
free(info->first_ref);
|
|
|
|
}
|
|
|
|
|
2013-03-04 08:52:33 +01:00
|
|
|
static char *find_default_branch(struct cgit_repo *repo)
|
2008-01-04 13:43:40 +01:00
|
|
|
{
|
|
|
|
struct refmatch info;
|
2008-07-27 12:32:08 +02:00
|
|
|
char *ref;
|
2008-01-04 13:43:40 +01:00
|
|
|
|
|
|
|
info.req_ref = repo->defbranch;
|
|
|
|
info.first_ref = NULL;
|
|
|
|
info.match = 0;
|
|
|
|
for_each_branch_ref(find_current_ref, &info);
|
|
|
|
if (info.match)
|
2008-07-27 12:32:08 +02:00
|
|
|
ref = info.req_ref;
|
2008-01-04 13:43:40 +01:00
|
|
|
else
|
2008-07-27 12:32:08 +02:00
|
|
|
ref = info.first_ref;
|
|
|
|
if (ref)
|
|
|
|
ref = xstrdup(ref);
|
2013-03-04 13:25:35 +01:00
|
|
|
free_refmatch_inner(&info);
|
|
|
|
|
2008-07-27 12:32:08 +02:00
|
|
|
return ref;
|
2008-01-04 13:43:40 +01:00
|
|
|
}
|
|
|
|
|
2013-03-03 22:42:35 +01:00
|
|
|
static char *guess_defbranch(void)
|
2011-06-20 20:59:10 +02:00
|
|
|
{
|
2011-06-21 00:52:51 +02:00
|
|
|
const char *ref;
|
|
|
|
unsigned char sha1[20];
|
2011-06-20 20:59:10 +02:00
|
|
|
|
2014-12-19 08:28:34 +01:00
|
|
|
ref = resolve_ref_unsafe("HEAD", 0, sha1, NULL);
|
2014-05-29 17:35:46 +02:00
|
|
|
if (!ref || !starts_with(ref, "refs/heads/"))
|
2011-06-21 00:52:51 +02:00
|
|
|
return "master";
|
|
|
|
return xstrdup(ref + 11);
|
2011-06-20 20:59:10 +02:00
|
|
|
}
|
2013-05-26 15:20:02 +02:00
|
|
|
/* The caller must free filename and ref after calling this. */
|
|
|
|
static inline void parse_readme(const char *readme, char **filename, char **ref, struct cgit_repo *repo)
|
|
|
|
{
|
|
|
|
const char *colon;
|
|
|
|
|
|
|
|
*filename = NULL;
|
|
|
|
*ref = NULL;
|
|
|
|
|
|
|
|
if (!readme || !readme[0])
|
|
|
|
return;
|
2011-06-20 20:59:10 +02:00
|
|
|
|
2013-05-26 15:20:02 +02:00
|
|
|
/* Check if the readme is tracked in the git repo. */
|
|
|
|
colon = strchr(readme, ':');
|
|
|
|
if (colon && strlen(colon) > 1) {
|
|
|
|
/* If it starts with a colon, we want to use
|
|
|
|
* the default branch */
|
|
|
|
if (colon == readme && repo->defbranch)
|
|
|
|
*ref = xstrdup(repo->defbranch);
|
|
|
|
else
|
|
|
|
*ref = xstrndup(readme, colon - readme);
|
|
|
|
readme = colon + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prepend repo path to relative readme path unless tracked. */
|
|
|
|
if (!(*ref) && readme[0] != '/')
|
|
|
|
*filename = fmtalloc("%s/%s", repo->path, readme);
|
|
|
|
else
|
|
|
|
*filename = xstrdup(readme);
|
|
|
|
}
|
2013-05-25 16:32:37 +02:00
|
|
|
static void choose_readme(struct cgit_repo *repo)
|
|
|
|
{
|
2013-05-26 15:20:02 +02:00
|
|
|
int found;
|
|
|
|
char *filename, *ref;
|
|
|
|
struct string_list_item *entry;
|
2013-05-25 16:32:37 +02:00
|
|
|
|
2013-05-26 15:20:02 +02:00
|
|
|
if (!repo->readme.nr)
|
2013-05-25 16:32:37 +02:00
|
|
|
return;
|
|
|
|
|
2013-05-26 15:20:02 +02:00
|
|
|
found = 0;
|
|
|
|
for_each_string_list_item(entry, &repo->readme) {
|
|
|
|
parse_readme(entry->string, &filename, &ref, repo);
|
|
|
|
if (!filename) {
|
2013-05-25 16:32:37 +02:00
|
|
|
free(filename);
|
|
|
|
free(ref);
|
|
|
|
continue;
|
|
|
|
}
|
2013-05-26 15:20:02 +02:00
|
|
|
if (ref) {
|
|
|
|
if (cgit_ref_path_exists(filename, ref, 1)) {
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!access(filename, R_OK)) {
|
|
|
|
found = 1;
|
2013-05-25 16:32:37 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(filename);
|
|
|
|
free(ref);
|
|
|
|
}
|
2013-05-26 15:20:02 +02:00
|
|
|
repo->readme.strdup_strings = 1;
|
|
|
|
string_list_clear(&repo->readme, 0);
|
|
|
|
repo->readme.strdup_strings = 0;
|
|
|
|
if (found)
|
|
|
|
string_list_append(&repo->readme, filename)->util = ref;
|
2013-05-25 16:32:37 +02:00
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
static int prepare_repo_cmd(void)
|
2006-12-09 15:18:17 +01:00
|
|
|
{
|
2008-01-04 13:43:40 +01:00
|
|
|
unsigned char sha1[20];
|
2008-02-16 21:16:53 +01:00
|
|
|
int nongit = 0;
|
2011-06-18 14:32:43 +02:00
|
|
|
int rc;
|
2007-05-16 00:14:51 +02:00
|
|
|
|
Do not load user or system gitconfig and gitattributes
While doing any kind of git loading, unset HOME variables and set
NOSYSTEM variables so that cgit does not load any settings that a user
may have set for his own /usr/bin/git usage.
This fixes a fatal error introduced with git 1.8, whereupon git would
fatally exit when failing to access particular files.
The result of this is that only repo-local configuration files are
accessed:
zx2c4@thinkpad ~/Projects/cgit $ HOME=/root QUERY_STRING="url=foo/log"
CGIT_CONFIG=tests/trash/cgitrc strace -e access ./cgit >/dev/null
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
access("repos/foo/.git/objects", X_OK) = 0
access("repos/foo/.git/refs", X_OK) = 0
access("repos/foo/.git/config", R_OK) = 0
access("repos/foo/.git/config", R_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
+++ exited with 0 +++
Reported-by: Ferry Huberts <ferry.huberts@pelagic.nl>
Tested-by: Jason A. Donenfeld <Jason@zx2c4.com>
Tested-by: Ferry Huberts <ferry.huberts@pelagic.nl>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2013-04-08 21:12:19 +02:00
|
|
|
/* The path to the git repository. */
|
2014-01-15 21:53:15 +01:00
|
|
|
setenv("GIT_DIR", ctx.repo->path, 1);
|
Do not load user or system gitconfig and gitattributes
While doing any kind of git loading, unset HOME variables and set
NOSYSTEM variables so that cgit does not load any settings that a user
may have set for his own /usr/bin/git usage.
This fixes a fatal error introduced with git 1.8, whereupon git would
fatally exit when failing to access particular files.
The result of this is that only repo-local configuration files are
accessed:
zx2c4@thinkpad ~/Projects/cgit $ HOME=/root QUERY_STRING="url=foo/log"
CGIT_CONFIG=tests/trash/cgitrc strace -e access ./cgit >/dev/null
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
access("repos/foo/.git/objects", X_OK) = 0
access("repos/foo/.git/refs", X_OK) = 0
access("repos/foo/.git/config", R_OK) = 0
access("repos/foo/.git/config", R_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
+++ exited with 0 +++
Reported-by: Ferry Huberts <ferry.huberts@pelagic.nl>
Tested-by: Jason A. Donenfeld <Jason@zx2c4.com>
Tested-by: Ferry Huberts <ferry.huberts@pelagic.nl>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2013-04-08 21:12:19 +02:00
|
|
|
|
|
|
|
/* Do not look in /etc/ for gitconfig and gitattributes. */
|
|
|
|
setenv("GIT_CONFIG_NOSYSTEM", "1", 1);
|
|
|
|
setenv("GIT_ATTR_NOSYSTEM", "1", 1);
|
|
|
|
unsetenv("HOME");
|
|
|
|
unsetenv("XDG_CONFIG_HOME");
|
|
|
|
|
|
|
|
/* Setup the git directory and initialize the notes system. Both of these
|
|
|
|
* load local configuration from the git repository, so we do them both while
|
|
|
|
* the HOME variables are unset. */
|
2008-02-16 21:16:53 +01:00
|
|
|
setup_git_directory_gently(&nongit);
|
Do not load user or system gitconfig and gitattributes
While doing any kind of git loading, unset HOME variables and set
NOSYSTEM variables so that cgit does not load any settings that a user
may have set for his own /usr/bin/git usage.
This fixes a fatal error introduced with git 1.8, whereupon git would
fatally exit when failing to access particular files.
The result of this is that only repo-local configuration files are
accessed:
zx2c4@thinkpad ~/Projects/cgit $ HOME=/root QUERY_STRING="url=foo/log"
CGIT_CONFIG=tests/trash/cgitrc strace -e access ./cgit >/dev/null
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
access("repos/foo/.git/objects", X_OK) = 0
access("repos/foo/.git/refs", X_OK) = 0
access("repos/foo/.git/config", R_OK) = 0
access("repos/foo/.git/config", R_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
+++ exited with 0 +++
Reported-by: Ferry Huberts <ferry.huberts@pelagic.nl>
Tested-by: Jason A. Donenfeld <Jason@zx2c4.com>
Tested-by: Ferry Huberts <ferry.huberts@pelagic.nl>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2013-04-08 21:12:19 +02:00
|
|
|
init_display_notes(NULL);
|
|
|
|
|
2008-02-16 21:16:53 +01:00
|
|
|
if (nongit) {
|
2014-01-15 21:53:15 +01:00
|
|
|
const char *name = ctx.repo->name;
|
2011-06-18 14:32:43 +02:00
|
|
|
rc = errno;
|
2014-01-15 21:53:15 +01:00
|
|
|
ctx.page.title = fmtalloc("%s - %s", ctx.cfg.root_title,
|
2013-04-06 11:28:57 +02:00
|
|
|
"config error");
|
2014-01-15 21:53:15 +01:00
|
|
|
ctx.repo = NULL;
|
|
|
|
cgit_print_http_headers();
|
|
|
|
cgit_print_docstart();
|
|
|
|
cgit_print_pageheader();
|
2013-04-06 12:23:52 +02:00
|
|
|
cgit_print_error("Failed to open %s: %s", name,
|
|
|
|
rc ? strerror(rc) : "Not a valid git repository");
|
2006-12-09 15:18:17 +01:00
|
|
|
cgit_print_docend();
|
2008-03-24 01:09:39 +01:00
|
|
|
return 1;
|
2006-12-09 15:18:17 +01:00
|
|
|
}
|
2014-01-15 21:53:15 +01:00
|
|
|
ctx.page.title = fmtalloc("%s - %s", ctx.repo->name, ctx.repo->desc);
|
2007-02-03 15:02:55 +01:00
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
if (!ctx.repo->defbranch)
|
|
|
|
ctx.repo->defbranch = guess_defbranch();
|
2011-06-20 20:59:10 +02:00
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
if (!ctx.qry.head) {
|
|
|
|
ctx.qry.nohead = 1;
|
|
|
|
ctx.qry.head = find_default_branch(ctx.repo);
|
2008-01-04 13:43:40 +01:00
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
if (!ctx.qry.head) {
|
|
|
|
cgit_print_http_headers();
|
|
|
|
cgit_print_docstart();
|
|
|
|
cgit_print_pageheader();
|
2008-01-04 13:43:40 +01:00
|
|
|
cgit_print_error("Repository seems to be empty");
|
|
|
|
cgit_print_docend();
|
2008-03-24 01:09:39 +01:00
|
|
|
return 1;
|
2008-01-04 13:43:40 +01:00
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
if (get_sha1(ctx.qry.head, sha1)) {
|
|
|
|
char *tmp = xstrdup(ctx.qry.head);
|
|
|
|
ctx.qry.head = ctx.repo->defbranch;
|
|
|
|
ctx.page.status = 404;
|
|
|
|
ctx.page.statusmsg = "Not found";
|
|
|
|
cgit_print_http_headers();
|
|
|
|
cgit_print_docstart();
|
|
|
|
cgit_print_pageheader();
|
2013-04-06 12:23:52 +02:00
|
|
|
cgit_print_error("Invalid branch: %s", tmp);
|
2008-01-04 13:43:40 +01:00
|
|
|
cgit_print_docend();
|
2014-01-17 00:48:17 +01:00
|
|
|
free(tmp);
|
2008-03-24 01:09:39 +01:00
|
|
|
return 1;
|
2008-01-04 13:43:40 +01:00
|
|
|
}
|
2015-02-07 14:18:28 +01:00
|
|
|
string_list_sort(&ctx.repo->submodules);
|
2014-01-15 21:53:15 +01:00
|
|
|
cgit_prepare_repo_env(ctx.repo);
|
|
|
|
choose_readme(ctx.repo);
|
2008-03-24 01:09:39 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2008-01-04 13:43:40 +01:00
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
static inline void open_auth_filter(const char *function)
|
2014-01-14 21:49:31 +01:00
|
|
|
{
|
2014-01-15 21:53:15 +01:00
|
|
|
cgit_open_filter(ctx.cfg.auth_filter, function,
|
|
|
|
ctx.env.http_cookie ? ctx.env.http_cookie : "",
|
|
|
|
ctx.env.request_method ? ctx.env.request_method : "",
|
|
|
|
ctx.env.query_string ? ctx.env.query_string : "",
|
|
|
|
ctx.env.http_referer ? ctx.env.http_referer : "",
|
|
|
|
ctx.env.path_info ? ctx.env.path_info : "",
|
|
|
|
ctx.env.http_host ? ctx.env.http_host : "",
|
|
|
|
ctx.env.https ? ctx.env.https : "",
|
|
|
|
ctx.qry.repo ? ctx.qry.repo : "",
|
|
|
|
ctx.qry.page ? ctx.qry.page : "",
|
|
|
|
ctx.qry.url ? ctx.qry.url : "",
|
2014-01-16 23:21:54 +01:00
|
|
|
cgit_loginurl());
|
2014-01-14 21:49:31 +01:00
|
|
|
}
|
|
|
|
|
2014-01-16 11:39:17 +01:00
|
|
|
/* We intentionally keep this rather small, instead of looping and
|
|
|
|
* feeding it to the filter a couple bytes at a time. This way, the
|
|
|
|
* filter itself does not need to handle any denial of service or
|
|
|
|
* buffer bloat issues. If this winds up being too small, people
|
|
|
|
* will complain on the mailing list, and we'll increase it as needed. */
|
2014-01-14 21:49:31 +01:00
|
|
|
#define MAX_AUTHENTICATION_POST_BYTES 4096
|
2014-01-16 11:39:17 +01:00
|
|
|
/* The filter is expected to spit out "Status: " and all headers. */
|
2014-01-15 21:53:15 +01:00
|
|
|
static inline void authenticate_post(void)
|
2014-01-14 21:49:31 +01:00
|
|
|
{
|
|
|
|
char buffer[MAX_AUTHENTICATION_POST_BYTES];
|
|
|
|
int len;
|
2014-01-16 11:39:17 +01:00
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
open_auth_filter("authenticate-post");
|
|
|
|
len = ctx.env.content_length;
|
2014-01-14 21:49:31 +01:00
|
|
|
if (len > MAX_AUTHENTICATION_POST_BYTES)
|
|
|
|
len = MAX_AUTHENTICATION_POST_BYTES;
|
|
|
|
if (read(STDIN_FILENO, buffer, len) < 0)
|
|
|
|
die_errno("Could not read POST from stdin");
|
|
|
|
if (write(STDOUT_FILENO, buffer, len) < 0)
|
|
|
|
die_errno("Could not write POST to stdout");
|
2014-01-15 21:53:15 +01:00
|
|
|
cgit_close_filter(ctx.cfg.auth_filter);
|
2014-01-14 21:49:31 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
static inline void authenticate_cookie(void)
|
2014-01-14 21:49:31 +01:00
|
|
|
{
|
|
|
|
/* If we don't have an auth_filter, consider all cookies valid, and thus return early. */
|
2014-01-15 21:53:15 +01:00
|
|
|
if (!ctx.cfg.auth_filter) {
|
|
|
|
ctx.env.authenticated = 1;
|
2014-01-14 21:49:31 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we're having something POST'd to /login, we're authenticating POST,
|
|
|
|
* instead of the cookie, so call authenticate_post and bail out early.
|
|
|
|
* This pattern here should match /?p=login with POST. */
|
2014-01-15 21:53:15 +01:00
|
|
|
if (ctx.env.request_method && ctx.qry.page && !ctx.repo && \
|
|
|
|
!strcmp(ctx.env.request_method, "POST") && !strcmp(ctx.qry.page, "login")) {
|
|
|
|
authenticate_post();
|
2014-01-14 21:49:31 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we've made it this far, we're authenticating the cookie for real, so do that. */
|
2014-01-15 21:53:15 +01:00
|
|
|
open_auth_filter("authenticate-cookie");
|
|
|
|
ctx.env.authenticated = cgit_close_filter(ctx.cfg.auth_filter);
|
2014-01-14 21:49:31 +01:00
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
static void process_request(void)
|
2008-03-24 01:09:39 +01:00
|
|
|
{
|
|
|
|
struct cgit_cmd *cmd;
|
|
|
|
|
2014-01-14 21:49:31 +01:00
|
|
|
/* If we're not yet authenticated, no matter what page we're on,
|
|
|
|
* display the authentication body from the auth_filter. This should
|
|
|
|
* never be cached. */
|
2014-01-15 21:53:15 +01:00
|
|
|
if (!ctx.env.authenticated) {
|
|
|
|
ctx.page.title = "Authentication Required";
|
|
|
|
cgit_print_http_headers();
|
|
|
|
cgit_print_docstart();
|
|
|
|
cgit_print_pageheader();
|
|
|
|
open_auth_filter("body");
|
|
|
|
cgit_close_filter(ctx.cfg.auth_filter);
|
2014-01-14 21:49:31 +01:00
|
|
|
cgit_print_docend();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
cmd = cgit_get_cmd();
|
2008-03-24 01:09:39 +01:00
|
|
|
if (!cmd) {
|
2014-01-15 21:53:15 +01:00
|
|
|
ctx.page.title = "cgit error";
|
|
|
|
ctx.page.status = 404;
|
|
|
|
ctx.page.statusmsg = "Not found";
|
|
|
|
cgit_print_http_headers();
|
|
|
|
cgit_print_docstart();
|
|
|
|
cgit_print_pageheader();
|
2008-03-24 01:09:39 +01:00
|
|
|
cgit_print_error("Invalid request");
|
|
|
|
cgit_print_docend();
|
2007-02-08 13:53:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
if (!ctx.cfg.enable_http_clone && cmd->is_clone) {
|
2011-01-12 19:06:07 +01:00
|
|
|
html_status(404, "Not found", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
/* If cmd->want_vpath is set, assume ctx.qry.path contains a "virtual"
|
|
|
|
* in-project path limit to be made available at ctx.qry.vpath.
|
|
|
|
* Otherwise, no path limit is in effect (ctx.qry.vpath = NULL).
|
2010-06-10 01:09:26 +02:00
|
|
|
*/
|
2014-01-15 21:53:15 +01:00
|
|
|
ctx.qry.vpath = cmd->want_vpath ? ctx.qry.path : NULL;
|
2010-06-10 01:09:26 +02:00
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
if (cmd->want_repo && !ctx.repo) {
|
|
|
|
cgit_print_http_headers();
|
|
|
|
cgit_print_docstart();
|
|
|
|
cgit_print_pageheader();
|
2013-04-06 12:23:52 +02:00
|
|
|
cgit_print_error("No repository selected");
|
2008-04-29 01:01:30 +02:00
|
|
|
cgit_print_docend();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
if (ctx.repo && prepare_repo_cmd())
|
2007-12-10 21:47:29 +01:00
|
|
|
return;
|
|
|
|
|
2008-03-24 01:09:39 +01:00
|
|
|
if (cmd->want_layout) {
|
2014-01-15 21:53:15 +01:00
|
|
|
cgit_print_http_headers();
|
|
|
|
cgit_print_docstart();
|
|
|
|
cgit_print_pageheader();
|
2007-05-18 03:00:54 +02:00
|
|
|
}
|
2007-02-17 13:46:18 +01:00
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
cmd->fn();
|
2007-02-17 13:46:18 +01:00
|
|
|
|
2008-03-24 01:09:39 +01:00
|
|
|
if (cmd->want_layout)
|
|
|
|
cgit_print_docend();
|
2006-12-09 15:18:17 +01:00
|
|
|
}
|
|
|
|
|
2013-03-04 08:52:33 +01:00
|
|
|
static int cmp_repos(const void *a, const void *b)
|
2008-09-15 00:07:12 +02:00
|
|
|
{
|
|
|
|
const struct cgit_repo *ra = a, *rb = b;
|
|
|
|
return strcmp(ra->url, rb->url);
|
|
|
|
}
|
|
|
|
|
2013-03-04 08:52:33 +01:00
|
|
|
static char *build_snapshot_setting(int bitmap)
|
2009-08-24 10:55:01 +02:00
|
|
|
{
|
|
|
|
const struct cgit_snapshot_format *f;
|
2013-04-06 11:28:57 +02:00
|
|
|
struct strbuf result = STRBUF_INIT;
|
2009-08-24 10:55:01 +02:00
|
|
|
|
|
|
|
for (f = cgit_snapshot_formats; f->suffix; f++) {
|
|
|
|
if (f->bit & bitmap) {
|
2013-04-06 11:28:57 +02:00
|
|
|
if (result.len)
|
|
|
|
strbuf_addch(&result, ' ');
|
|
|
|
strbuf_addstr(&result, f->suffix);
|
2009-08-24 10:55:01 +02:00
|
|
|
}
|
|
|
|
}
|
2013-04-06 11:28:57 +02:00
|
|
|
return strbuf_detach(&result, NULL);
|
2009-08-24 10:55:01 +02:00
|
|
|
}
|
|
|
|
|
2013-03-04 08:52:33 +01:00
|
|
|
static char *get_first_line(char *txt)
|
2009-08-24 13:27:15 +02:00
|
|
|
{
|
|
|
|
char *t = xstrdup(txt);
|
|
|
|
char *p = strchr(t, '\n');
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2013-03-04 08:52:33 +01:00
|
|
|
static void print_repo(FILE *f, struct cgit_repo *repo)
|
2008-09-15 00:07:12 +02:00
|
|
|
{
|
2013-05-26 15:20:02 +02:00
|
|
|
struct string_list_item *item;
|
2009-08-19 17:47:24 +02:00
|
|
|
fprintf(f, "repo.url=%s\n", repo->url);
|
|
|
|
fprintf(f, "repo.name=%s\n", repo->name);
|
|
|
|
fprintf(f, "repo.path=%s\n", repo->path);
|
2008-09-15 00:07:12 +02:00
|
|
|
if (repo->owner)
|
2009-08-19 17:47:24 +02:00
|
|
|
fprintf(f, "repo.owner=%s\n", repo->owner);
|
2009-08-24 13:27:15 +02:00
|
|
|
if (repo->desc) {
|
|
|
|
char *tmp = get_first_line(repo->desc);
|
|
|
|
fprintf(f, "repo.desc=%s\n", tmp);
|
|
|
|
free(tmp);
|
|
|
|
}
|
2013-05-26 15:20:02 +02:00
|
|
|
for_each_string_list_item(item, &repo->readme) {
|
|
|
|
if (item->util)
|
|
|
|
fprintf(f, "repo.readme=%s:%s\n", (char *)item->util, item->string);
|
|
|
|
else
|
|
|
|
fprintf(f, "repo.readme=%s\n", item->string);
|
|
|
|
}
|
2009-08-24 10:22:21 +02:00
|
|
|
if (repo->defbranch)
|
|
|
|
fprintf(f, "repo.defbranch=%s\n", repo->defbranch);
|
|
|
|
if (repo->module_link)
|
|
|
|
fprintf(f, "repo.module-link=%s\n", repo->module_link);
|
|
|
|
if (repo->section)
|
|
|
|
fprintf(f, "repo.section=%s\n", repo->section);
|
|
|
|
if (repo->clone_url)
|
|
|
|
fprintf(f, "repo.clone-url=%s\n", repo->clone_url);
|
2010-11-15 18:39:50 +01:00
|
|
|
fprintf(f, "repo.enable-commit-graph=%d\n",
|
|
|
|
repo->enable_commit_graph);
|
2009-08-24 10:22:21 +02:00
|
|
|
fprintf(f, "repo.enable-log-filecount=%d\n",
|
|
|
|
repo->enable_log_filecount);
|
|
|
|
fprintf(f, "repo.enable-log-linecount=%d\n",
|
|
|
|
repo->enable_log_linecount);
|
|
|
|
if (repo->about_filter && repo->about_filter != ctx.cfg.about_filter)
|
2014-01-12 18:13:51 +01:00
|
|
|
cgit_fprintf_filter(repo->about_filter, f, "repo.about-filter=");
|
2009-08-24 10:22:21 +02:00
|
|
|
if (repo->commit_filter && repo->commit_filter != ctx.cfg.commit_filter)
|
2014-01-12 18:13:51 +01:00
|
|
|
cgit_fprintf_filter(repo->commit_filter, f, "repo.commit-filter=");
|
2009-08-24 10:22:21 +02:00
|
|
|
if (repo->source_filter && repo->source_filter != ctx.cfg.source_filter)
|
2014-01-12 18:13:51 +01:00
|
|
|
cgit_fprintf_filter(repo->source_filter, f, "repo.source-filter=");
|
2014-01-13 04:04:52 +01:00
|
|
|
if (repo->email_filter && repo->email_filter != ctx.cfg.email_filter)
|
|
|
|
cgit_fprintf_filter(repo->email_filter, f, "repo.email-filter=");
|
2014-08-04 15:23:08 +02:00
|
|
|
if (repo->owner_filter && repo->owner_filter != ctx.cfg.owner_filter)
|
|
|
|
cgit_fprintf_filter(repo->owner_filter, f, "repo.owner-filter=");
|
2009-08-24 10:55:01 +02:00
|
|
|
if (repo->snapshots != ctx.cfg.snapshots) {
|
|
|
|
char *tmp = build_snapshot_setting(repo->snapshots);
|
2013-04-06 11:28:57 +02:00
|
|
|
fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : "");
|
2009-08-24 10:55:01 +02:00
|
|
|
free(tmp);
|
|
|
|
}
|
2009-08-24 11:02:48 +02:00
|
|
|
if (repo->max_stats != ctx.cfg.max_stats)
|
|
|
|
fprintf(f, "repo.max-stats=%s\n",
|
|
|
|
cgit_find_stats_periodname(repo->max_stats));
|
2013-05-25 14:05:06 +02:00
|
|
|
if (repo->logo)
|
|
|
|
fprintf(f, "repo.logo=%s\n", repo->logo);
|
|
|
|
if (repo->logo_link)
|
|
|
|
fprintf(f, "repo.logo-link=%s\n", repo->logo_link);
|
|
|
|
fprintf(f, "repo.enable-remote-branches=%d\n", repo->enable_remote_branches);
|
|
|
|
fprintf(f, "repo.enable-subject-links=%d\n", repo->enable_subject_links);
|
|
|
|
if (repo->branch_sort == 1)
|
|
|
|
fprintf(f, "repo.branch-sort=age\n");
|
|
|
|
if (repo->commit_sort) {
|
|
|
|
if (repo->commit_sort == 1)
|
|
|
|
fprintf(f, "repo.commit-sort=date\n");
|
|
|
|
else if (repo->commit_sort == 2)
|
|
|
|
fprintf(f, "repo.commit-sort=topo\n");
|
|
|
|
}
|
2015-01-29 12:52:49 +01:00
|
|
|
fprintf(f, "repo.hide=%d\n", repo->hide);
|
|
|
|
fprintf(f, "repo.ignore=%d\n", repo->ignore);
|
2009-08-19 17:47:24 +02:00
|
|
|
fprintf(f, "\n");
|
2008-09-15 00:07:12 +02:00
|
|
|
}
|
|
|
|
|
2013-03-04 08:52:33 +01:00
|
|
|
static void print_repolist(FILE *f, struct cgit_repolist *list, int start)
|
2008-09-15 00:07:12 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2013-03-04 05:21:33 +01:00
|
|
|
for (i = start; i < list->count; i++)
|
2009-08-19 17:47:24 +02:00
|
|
|
print_repo(f, &list->repos[i]);
|
2008-09-15 00:07:12 +02:00
|
|
|
}
|
|
|
|
|
2009-08-20 17:41:54 +02:00
|
|
|
/* Scan 'path' for git repositories, save the resulting repolist in 'cached_rc'
|
|
|
|
* and return 0 on success.
|
|
|
|
*/
|
|
|
|
static int generate_cached_repolist(const char *path, const char *cached_rc)
|
|
|
|
{
|
2013-04-06 11:28:57 +02:00
|
|
|
struct strbuf locked_rc = STRBUF_INIT;
|
|
|
|
int result = 0;
|
2009-08-20 17:41:54 +02:00
|
|
|
int idx;
|
|
|
|
FILE *f;
|
|
|
|
|
2013-04-06 11:28:57 +02:00
|
|
|
strbuf_addf(&locked_rc, "%s.lock", cached_rc);
|
|
|
|
f = fopen(locked_rc.buf, "wx");
|
2009-08-20 17:41:54 +02:00
|
|
|
if (!f) {
|
|
|
|
/* Inform about the error unless the lockfile already existed,
|
|
|
|
* since that only means we've got concurrent requests.
|
|
|
|
*/
|
2013-04-06 11:28:57 +02:00
|
|
|
result = errno;
|
|
|
|
if (result != EEXIST)
|
2009-08-20 17:41:54 +02:00
|
|
|
fprintf(stderr, "[cgit] Error opening %s: %s (%d)\n",
|
2013-04-06 11:28:57 +02:00
|
|
|
locked_rc.buf, strerror(result), result);
|
|
|
|
goto out;
|
2009-08-20 17:41:54 +02:00
|
|
|
}
|
|
|
|
idx = cgit_repolist.count;
|
2010-07-29 17:52:29 +02:00
|
|
|
if (ctx.cfg.project_list)
|
|
|
|
scan_projects(path, ctx.cfg.project_list, repo_config);
|
|
|
|
else
|
|
|
|
scan_tree(path, repo_config);
|
2009-08-20 17:41:54 +02:00
|
|
|
print_repolist(f, &cgit_repolist, idx);
|
2013-04-06 11:28:57 +02:00
|
|
|
if (rename(locked_rc.buf, cached_rc))
|
2009-08-20 17:41:54 +02:00
|
|
|
fprintf(stderr, "[cgit] Error renaming %s to %s: %s (%d)\n",
|
2013-04-06 11:28:57 +02:00
|
|
|
locked_rc.buf, cached_rc, strerror(errno), errno);
|
2009-08-20 17:41:54 +02:00
|
|
|
fclose(f);
|
2013-04-06 11:28:57 +02:00
|
|
|
out:
|
|
|
|
strbuf_release(&locked_rc);
|
|
|
|
return result;
|
2008-09-15 00:07:12 +02:00
|
|
|
}
|
|
|
|
|
2009-08-20 17:41:54 +02:00
|
|
|
static void process_cached_repolist(const char *path)
|
|
|
|
{
|
|
|
|
struct stat st;
|
2013-04-06 11:28:57 +02:00
|
|
|
struct strbuf cached_rc = STRBUF_INIT;
|
2009-08-20 17:41:54 +02:00
|
|
|
time_t age;
|
2010-07-29 17:52:29 +02:00
|
|
|
unsigned long hash;
|
2009-08-20 17:41:54 +02:00
|
|
|
|
2010-07-29 17:52:29 +02:00
|
|
|
hash = hash_str(path);
|
|
|
|
if (ctx.cfg.project_list)
|
|
|
|
hash += hash_str(ctx.cfg.project_list);
|
2013-04-06 11:28:57 +02:00
|
|
|
strbuf_addf(&cached_rc, "%s/rc-%8lx", ctx.cfg.cache_root, hash);
|
2009-08-20 17:41:54 +02:00
|
|
|
|
2013-04-06 11:28:57 +02:00
|
|
|
if (stat(cached_rc.buf, &st)) {
|
2009-08-20 17:41:54 +02:00
|
|
|
/* Nothing is cached, we need to scan without forking. And
|
|
|
|
* if we fail to generate a cached repolist, we need to
|
|
|
|
* invoke scan_tree manually.
|
|
|
|
*/
|
2013-04-06 11:28:57 +02:00
|
|
|
if (generate_cached_repolist(path, cached_rc.buf)) {
|
2010-07-29 17:52:29 +02:00
|
|
|
if (ctx.cfg.project_list)
|
|
|
|
scan_projects(path, ctx.cfg.project_list,
|
|
|
|
repo_config);
|
|
|
|
else
|
|
|
|
scan_tree(path, repo_config);
|
|
|
|
}
|
2013-04-06 11:28:57 +02:00
|
|
|
goto out;
|
2009-08-20 17:41:54 +02:00
|
|
|
}
|
|
|
|
|
2013-04-06 11:28:57 +02:00
|
|
|
parse_configfile(cached_rc.buf, config_cb);
|
2009-08-20 17:41:54 +02:00
|
|
|
|
|
|
|
/* If the cached configfile hasn't expired, lets exit now */
|
|
|
|
age = time(NULL) - st.st_mtime;
|
|
|
|
if (age <= (ctx.cfg.cache_scanrc_ttl * 60))
|
2013-04-06 11:28:57 +02:00
|
|
|
goto out;
|
2009-08-20 17:41:54 +02:00
|
|
|
|
|
|
|
/* The cached repolist has been parsed, but it was old. So lets
|
|
|
|
* rescan the specified path and generate a new cached repolist
|
|
|
|
* in a child-process to avoid latency for the current request.
|
|
|
|
*/
|
|
|
|
if (fork())
|
2013-04-06 11:28:57 +02:00
|
|
|
goto out;
|
2009-08-20 17:41:54 +02:00
|
|
|
|
2013-04-06 11:28:57 +02:00
|
|
|
exit(generate_cached_repolist(path, cached_rc.buf));
|
|
|
|
out:
|
|
|
|
strbuf_release(&cached_rc);
|
2009-08-20 17:41:54 +02:00
|
|
|
}
|
2008-09-15 00:07:12 +02:00
|
|
|
|
2006-12-16 13:33:32 +01:00
|
|
|
static void cgit_parse_args(int argc, const char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
2008-09-15 00:07:12 +02:00
|
|
|
int scan = 0;
|
2006-12-16 13:33:32 +01:00
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
2014-01-20 13:05:08 +01:00
|
|
|
if (!strcmp(argv[i], "--version")) {
|
|
|
|
printf("CGit %s | http://git.zx2c4.com/cgit/\n\nCompiled in features:\n", CGIT_VERSION);
|
|
|
|
#ifdef NO_LUA
|
|
|
|
printf("[-] ");
|
|
|
|
#else
|
|
|
|
printf("[+] ");
|
|
|
|
#endif
|
|
|
|
printf("Lua scripting\n");
|
|
|
|
#ifndef HAVE_LINUX_SENDFILE
|
|
|
|
printf("[-] ");
|
|
|
|
#else
|
|
|
|
printf("[+] ");
|
|
|
|
#endif
|
|
|
|
printf("Linux sendfile() usage\n");
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
2014-05-29 17:35:46 +02:00
|
|
|
if (starts_with(argv[i], "--cache=")) {
|
2013-03-03 16:04:29 +01:00
|
|
|
ctx.cfg.cache_root = xstrdup(argv[i] + 8);
|
2014-01-10 14:55:30 +01:00
|
|
|
} else if (!strcmp(argv[i], "--nocache")) {
|
2008-02-16 13:07:13 +01:00
|
|
|
ctx.cfg.nocache = 1;
|
2014-01-10 14:55:30 +01:00
|
|
|
} else if (!strcmp(argv[i], "--nohttp")) {
|
2009-08-10 09:20:17 +02:00
|
|
|
ctx.env.no_http = "1";
|
2014-05-29 17:35:46 +02:00
|
|
|
} else if (starts_with(argv[i], "--query=")) {
|
2013-03-03 16:04:29 +01:00
|
|
|
ctx.qry.raw = xstrdup(argv[i] + 8);
|
2014-05-29 17:35:46 +02:00
|
|
|
} else if (starts_with(argv[i], "--repo=")) {
|
2013-03-03 16:04:29 +01:00
|
|
|
ctx.qry.repo = xstrdup(argv[i] + 7);
|
2014-05-29 17:35:46 +02:00
|
|
|
} else if (starts_with(argv[i], "--page=")) {
|
2013-03-03 16:04:29 +01:00
|
|
|
ctx.qry.page = xstrdup(argv[i] + 7);
|
2014-05-29 17:35:46 +02:00
|
|
|
} else if (starts_with(argv[i], "--head=")) {
|
2013-03-03 16:04:29 +01:00
|
|
|
ctx.qry.head = xstrdup(argv[i] + 7);
|
2008-02-16 11:53:40 +01:00
|
|
|
ctx.qry.has_symref = 1;
|
2014-05-29 17:35:46 +02:00
|
|
|
} else if (starts_with(argv[i], "--sha1=")) {
|
2013-03-03 16:04:29 +01:00
|
|
|
ctx.qry.sha1 = xstrdup(argv[i] + 7);
|
2008-02-16 11:53:40 +01:00
|
|
|
ctx.qry.has_sha1 = 1;
|
2014-05-29 17:35:46 +02:00
|
|
|
} else if (starts_with(argv[i], "--ofs=")) {
|
2013-03-03 16:04:29 +01:00
|
|
|
ctx.qry.ofs = atoi(argv[i] + 6);
|
2014-05-29 17:35:46 +02:00
|
|
|
} else if (starts_with(argv[i], "--scan-tree=") ||
|
|
|
|
starts_with(argv[i], "--scan-path=")) {
|
2014-01-10 14:55:31 +01:00
|
|
|
/*
|
|
|
|
* HACK: The global snapshot bit mask defines the set
|
|
|
|
* of allowed snapshot formats, but the config file
|
|
|
|
* hasn't been parsed yet so the mask is currently 0.
|
|
|
|
* By setting all bits high before scanning we make
|
|
|
|
* sure that any in-repo cgitrc snapshot setting is
|
|
|
|
* respected by scan_tree().
|
|
|
|
*
|
|
|
|
* NOTE: We assume that there aren't more than 8
|
|
|
|
* different snapshot formats supported by cgit...
|
2009-08-24 13:31:49 +02:00
|
|
|
*/
|
|
|
|
ctx.cfg.snapshots = 0xFF;
|
2008-09-15 00:07:12 +02:00
|
|
|
scan++;
|
2009-08-24 00:04:58 +02:00
|
|
|
scan_tree(argv[i] + 12, repo_config);
|
2008-09-15 00:07:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (scan) {
|
|
|
|
qsort(cgit_repolist.repos, cgit_repolist.count,
|
|
|
|
sizeof(struct cgit_repo), cmp_repos);
|
2009-08-19 17:47:24 +02:00
|
|
|
print_repolist(stdout, &cgit_repolist, 0);
|
2008-09-15 00:07:12 +02:00
|
|
|
exit(0);
|
2006-12-16 13:33:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-28 11:32:42 +02:00
|
|
|
static int calc_ttl()
|
|
|
|
{
|
|
|
|
if (!ctx.repo)
|
|
|
|
return ctx.cfg.cache_root_ttl;
|
|
|
|
|
|
|
|
if (!ctx.qry.page)
|
|
|
|
return ctx.cfg.cache_repo_ttl;
|
|
|
|
|
2013-05-28 16:33:30 +02:00
|
|
|
if (!strcmp(ctx.qry.page, "about"))
|
|
|
|
return ctx.cfg.cache_about_ttl;
|
|
|
|
|
2014-02-05 10:23:58 +01:00
|
|
|
if (!strcmp(ctx.qry.page, "snapshot"))
|
|
|
|
return ctx.cfg.cache_snapshot_ttl;
|
|
|
|
|
2008-04-28 11:32:42 +02:00
|
|
|
if (ctx.qry.has_sha1)
|
|
|
|
return ctx.cfg.cache_static_ttl;
|
|
|
|
|
2013-05-28 16:43:02 +02:00
|
|
|
if (ctx.qry.has_symref)
|
|
|
|
return ctx.cfg.cache_dynamic_ttl;
|
|
|
|
|
2008-04-28 11:32:42 +02:00
|
|
|
return ctx.cfg.cache_repo_ttl;
|
|
|
|
}
|
|
|
|
|
2006-12-10 22:31:36 +01:00
|
|
|
int main(int argc, const char **argv)
|
|
|
|
{
|
2008-08-09 21:11:41 +02:00
|
|
|
const char *path;
|
2008-04-28 11:32:42 +02:00
|
|
|
int err, ttl;
|
2006-12-11 17:25:41 +01:00
|
|
|
|
2014-01-13 14:16:18 +01:00
|
|
|
cgit_init_filters();
|
2014-01-14 21:49:31 +01:00
|
|
|
atexit(cgit_cleanup_filters);
|
2014-01-13 14:16:18 +01:00
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
prepare_context();
|
2007-02-03 15:02:55 +01:00
|
|
|
cgit_repolist.length = 0;
|
|
|
|
cgit_repolist.count = 0;
|
|
|
|
cgit_repolist.repos = NULL;
|
|
|
|
|
2006-12-16 13:33:32 +01:00
|
|
|
cgit_parse_args(argc, argv);
|
2010-03-22 00:09:43 +01:00
|
|
|
parse_configfile(expand_macros(ctx.env.cgit_config), config_cb);
|
2008-09-15 00:07:12 +02:00
|
|
|
ctx.repo = NULL;
|
2008-04-08 21:11:36 +02:00
|
|
|
http_parse_querystring(ctx.qry.raw, querystring_cb);
|
2008-04-28 11:32:42 +02:00
|
|
|
|
2008-12-26 10:33:01 +01:00
|
|
|
/* If virtual-root isn't specified in cgitrc, lets pretend
|
2011-03-05 13:47:04 +01:00
|
|
|
* that virtual-root equals SCRIPT_NAME, minus any possibly
|
|
|
|
* trailing slashes.
|
2008-08-09 21:11:41 +02:00
|
|
|
*/
|
2013-04-01 20:03:34 +02:00
|
|
|
if (!ctx.cfg.virtual_root && ctx.cfg.script_name)
|
|
|
|
ctx.cfg.virtual_root = ensure_end(ctx.cfg.script_name, '/');
|
2008-12-26 10:33:01 +01:00
|
|
|
|
|
|
|
/* If no url parameter is specified on the querystring, lets
|
|
|
|
* use PATH_INFO as url. This allows cgit to work with virtual
|
|
|
|
* urls without the need for rewriterules in the webserver (as
|
|
|
|
* long as PATH_INFO is included in the cache lookup key).
|
|
|
|
*/
|
2009-08-10 08:21:09 +02:00
|
|
|
path = ctx.env.path_info;
|
2008-12-26 10:33:01 +01:00
|
|
|
if (!ctx.qry.url && path) {
|
|
|
|
if (path[0] == '/')
|
|
|
|
path++;
|
|
|
|
ctx.qry.url = xstrdup(path);
|
|
|
|
if (ctx.qry.raw) {
|
2013-04-06 11:28:57 +02:00
|
|
|
char *newqry = fmtalloc("%s?%s", path, ctx.qry.raw);
|
|
|
|
free(ctx.qry.raw);
|
|
|
|
ctx.qry.raw = newqry;
|
2008-12-26 10:33:01 +01:00
|
|
|
} else
|
2009-08-20 10:07:51 +02:00
|
|
|
ctx.qry.raw = xstrdup(ctx.qry.url);
|
2008-12-26 10:33:01 +01:00
|
|
|
cgit_parse_url(ctx.qry.url);
|
2008-08-09 21:11:41 +02:00
|
|
|
}
|
|
|
|
|
2014-01-14 21:49:31 +01:00
|
|
|
/* Before we go any further, we set ctx.env.authenticated by checking to see
|
|
|
|
* if the supplied cookie is valid. All cookies are valid if there is no
|
|
|
|
* auth_filter. If there is an auth_filter, the filter decides. */
|
2014-01-15 21:53:15 +01:00
|
|
|
authenticate_cookie();
|
2014-01-14 21:49:31 +01:00
|
|
|
|
2008-04-28 11:32:42 +02:00
|
|
|
ttl = calc_ttl();
|
2013-05-28 16:33:30 +02:00
|
|
|
if (ttl < 0)
|
|
|
|
ctx.page.expires += 10 * 365 * 24 * 60 * 60; /* 10 years */
|
|
|
|
else
|
|
|
|
ctx.page.expires += ttl * 60;
|
2014-01-14 21:49:31 +01:00
|
|
|
if (!ctx.env.authenticated || (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD")))
|
2009-02-19 23:24:15 +01:00
|
|
|
ctx.cfg.nocache = 1;
|
2008-04-28 11:32:42 +02:00
|
|
|
if (ctx.cfg.nocache)
|
|
|
|
ctx.cfg.cache_size = 0;
|
|
|
|
err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
|
2014-01-15 21:53:15 +01:00
|
|
|
ctx.qry.raw, ttl, process_request);
|
|
|
|
cgit_cleanup_filters();
|
2008-04-28 11:32:42 +02:00
|
|
|
if (err)
|
2013-04-06 12:23:52 +02:00
|
|
|
cgit_print_error("Error processing page: %s (%d)",
|
|
|
|
strerror(err), err);
|
2008-04-28 11:32:42 +02:00
|
|
|
return err;
|
2006-12-09 15:18:17 +01:00
|
|
|
}
|