From f2382990742bff816ec54883e6204ededc378e7f Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Thu, 6 Aug 2026 21:09:57 -1000 Subject: Settle the names, types and layout of the sources --- source/cgit.c | 118 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 59 insertions(+), 59 deletions(-) (limited to 'source/cgit.c') diff --git a/source/cgit.c b/source/cgit.c index c2c488d..5cb52fd 100644 --- a/source/cgit.c +++ b/source/cgit.c @@ -20,6 +20,12 @@ #include "ui-summary.h" #include "scan-tree.h" +/* 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. */ +#define MAX_AUTHENTICATION_POST_BYTES 4096 const char *cgit_version = CGIT_VERSION; /* @@ -58,19 +64,19 @@ void cgit_repo_config(struct cgit_repo *repo, const char *name, const char *valu struct string_list_item *item; if (!strcmp(name, "name")) - repo->name = strdup_first_line(value); + repo->name = cgit_strdup_first_line(value); else if (!strcmp(name, "clone-url")) - repo->clone_url = strdup_first_line(value); + repo->clone_url = cgit_strdup_first_line(value); else if (!strcmp(name, "desc")) - repo->desc = strdup_first_line(value); + repo->desc = cgit_strdup_first_line(value); else if (!strcmp(name, "owner")) - repo->owner = strdup_first_line(value); + repo->owner = cgit_strdup_first_line(value); else if (!strcmp(name, "homepage")) - repo->homepage = strdup_first_line(value); + repo->homepage = cgit_strdup_first_line(value); else if (!strcmp(name, "defbranch")) - repo->defbranch = strdup_first_line(value); + repo->defbranch = cgit_strdup_first_line(value); else if (!strcmp(name, "extra-head-content")) - repo->extra_head_content = strdup_first_line(value); + repo->extra_head_content = cgit_strdup_first_line(value); else if (!strcmp(name, "snapshots")) repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); else if (!strcmp(name, "enable-blame")) @@ -104,22 +110,22 @@ void cgit_repo_config(struct cgit_repo *repo, const char *name, const char *valu } else if (!strcmp(name, "max-stats")) repo->max_stats = cgit_find_stats_period(value, NULL); else if (!strcmp(name, "module-link")) - repo->module_link= strdup_first_line(value); + repo->module_link= cgit_strdup_first_line(value); else if (skip_prefix(name, "module-link.", &path)) { - item = string_list_append(&repo->submodules, strdup_first_line(path)); - item->util = strdup_first_line(value); + item = string_list_append(&repo->submodules, cgit_strdup_first_line(path)); + item->util = cgit_strdup_first_line(value); } else if (!strcmp(name, "section")) - repo->section = strdup_first_line(value); + repo->section = cgit_strdup_first_line(value); else if (!strcmp(name, "snapshot-prefix")) - repo->snapshot_prefix = strdup_first_line(value); + repo->snapshot_prefix = cgit_strdup_first_line(value); 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, strdup_first_line(value)); + string_list_append(&repo->readme, cgit_strdup_first_line(value)); } else if (!strcmp(name, "logo") && value != NULL) - repo->logo = strdup_first_line(value); + repo->logo = cgit_strdup_first_line(value); else if (!strcmp(name, "logo-link") && value != NULL) - repo->logo_link = strdup_first_line(value); + repo->logo_link = cgit_strdup_first_line(value); else if (!strcmp(name, "hide")) repo->hide = atoi(value); else if (!strcmp(name, "ignore")) @@ -141,43 +147,43 @@ static void config_cb(const char *name, const char *value) const char *arg; if (!strcmp(name, "section")) - ctx.cfg.section = strdup_first_line(value); + ctx.cfg.section = cgit_strdup_first_line(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, '/'); + ctx.repo->path = cgit_trim_end(value, '/'); else if (ctx.repo && skip_prefix(name, "repo.", &arg)) cgit_repo_config(ctx.repo, arg, value); else if (!strcmp(name, "readme")) - string_list_append(&ctx.cfg.readme, strdup_first_line(value)); + string_list_append(&ctx.cfg.readme, cgit_strdup_first_line(value)); else if (!strcmp(name, "root-title")) - ctx.cfg.root_title = strdup_first_line(value); + ctx.cfg.root_title = cgit_strdup_first_line(value); else if (!strcmp(name, "root-desc")) - ctx.cfg.root_desc = strdup_first_line(value); + ctx.cfg.root_desc = cgit_strdup_first_line(value); else if (!strcmp(name, "root-readme")) - ctx.cfg.root_readme = strdup_first_line(value); + ctx.cfg.root_readme = cgit_strdup_first_line(value); else if (!strcmp(name, "css")) - string_list_append(&ctx.cfg.css, strdup_first_line(value)); + string_list_append(&ctx.cfg.css, cgit_strdup_first_line(value)); else if (!strcmp(name, "js")) - string_list_append(&ctx.cfg.js, strdup_first_line(value)); + string_list_append(&ctx.cfg.js, cgit_strdup_first_line(value)); else if (!strcmp(name, "favicon")) - ctx.cfg.favicon = strdup_first_line(value); + ctx.cfg.favicon = cgit_strdup_first_line(value); else if (!strcmp(name, "footer")) - ctx.cfg.footer = strdup_first_line(value); + ctx.cfg.footer = cgit_strdup_first_line(value); else if (!strcmp(name, "head-include")) - ctx.cfg.head_include = strdup_first_line(value); + ctx.cfg.head_include = cgit_strdup_first_line(value); else if (!strcmp(name, "header")) - ctx.cfg.header = strdup_first_line(value); + ctx.cfg.header = cgit_strdup_first_line(value); else if (!strcmp(name, "logo")) - ctx.cfg.logo = strdup_first_line(value); + ctx.cfg.logo = cgit_strdup_first_line(value); else if (!strcmp(name, "logo-link")) - ctx.cfg.logo_link = strdup_first_line(value); + ctx.cfg.logo_link = cgit_strdup_first_line(value); else if (!strcmp(name, "module-link")) - ctx.cfg.module_link = strdup_first_line(value); + ctx.cfg.module_link = cgit_strdup_first_line(value); else if (!strcmp(name, "strict-export")) - ctx.cfg.strict_export = strdup_first_line(value); + ctx.cfg.strict_export = cgit_strdup_first_line(value); else if (!strcmp(name, "virtual-root")) - ctx.cfg.virtual_root = ensure_end(value, '/'); + ctx.cfg.virtual_root = cgit_ensure_end(value, '/'); else if (!strcmp(name, "noplainemail")) ctx.cfg.noplainemail = atoi(value); else if (!strcmp(name, "noheader")) @@ -225,7 +231,7 @@ static void config_cb(const char *name, const char *value) else if (!strcmp(name, "cache-size")) ctx.cfg.cache_size = atoi(value); else if (!strcmp(name, "cache-root")) - ctx.cfg.cache_root = strdup_first_line(expand_macros(value)); + ctx.cfg.cache_root = cgit_strdup_first_line(cgit_expand_macros(value)); else if (!strcmp(name, "cache-root-ttl")) ctx.cfg.cache_root_ttl = atoi(value); else if (!strcmp(name, "cache-repo-ttl")) @@ -275,21 +281,21 @@ static void config_cb(const char *name, const char *value) else if (!strcmp(name, "max-patch-count")) ctx.cfg.max_patch_count = atoi(value); else if (!strcmp(name, "project-list")) - ctx.cfg.project_list = strdup_first_line(expand_macros(value)); + ctx.cfg.project_list = cgit_strdup_first_line(cgit_expand_macros(value)); else if (!strcmp(name, "scan-path")) if (ctx.cfg.cache_size) - process_cached_repolist(expand_macros(value)); + process_cached_repolist(cgit_expand_macros(value)); else if (ctx.cfg.project_list) - scan_projects(expand_macros(value), + scan_projects(cgit_expand_macros(value), ctx.cfg.project_list); else - scan_tree(expand_macros(value)); + scan_tree(cgit_expand_macros(value)); else if (!strcmp(name, "scan-hidden-path")) ctx.cfg.scan_hidden_path = atoi(value); else if (!strcmp(name, "section-from-path")) ctx.cfg.section_from_path = atoi(value); else if (!strcmp(name, "repository-sort")) - ctx.cfg.repository_sort = strdup_first_line(value); + ctx.cfg.repository_sort = cgit_strdup_first_line(value); else if (!strcmp(name, "section-sort")) ctx.cfg.section_sort = atoi(value); else if (!strcmp(name, "source-filter")) @@ -303,19 +309,19 @@ static void config_cb(const char *name, const char *value) else if (!strcmp(name, "side-by-side-diffs")) ctx.cfg.difftype = atoi(value) ? DIFF_SSDIFF : DIFF_UNIFIED; else if (!strcmp(name, "agefile")) - ctx.cfg.agefile = strdup_first_line(value); + ctx.cfg.agefile = cgit_strdup_first_line(value); else if (!strcmp(name, "mimetype-file")) - ctx.cfg.mimetype_file = strdup_first_line(value); + ctx.cfg.mimetype_file = cgit_strdup_first_line(value); else if (!strcmp(name, "renamelimit")) ctx.cfg.renamelimit = atoi(value); else if (!strcmp(name, "remove-suffix")) ctx.cfg.remove_suffix = atoi(value); else if (!strcmp(name, "robots")) - ctx.cfg.robots = strdup_first_line(value); + ctx.cfg.robots = cgit_strdup_first_line(value); else if (!strcmp(name, "clone-prefix")) - ctx.cfg.clone_prefix = strdup_first_line(value); + ctx.cfg.clone_prefix = cgit_strdup_first_line(value); else if (!strcmp(name, "clone-url")) - ctx.cfg.clone_url = strdup_first_line(value); + ctx.cfg.clone_url = cgit_strdup_first_line(value); else if (!strcmp(name, "local-time")) ctx.cfg.local_time = atoi(value); else if (!strcmp(name, "date-format")) @@ -333,7 +339,7 @@ static void config_cb(const char *name, const char *value) } else if (skip_prefix(name, "mimetype.", &arg)) add_mimetype(arg, value); else if (!strcmp(name, "include")) - parse_configfile(expand_macros(value), config_cb); + parse_configfile(cgit_expand_macros(value), config_cb); } static void querystring_cb(const char *name, const char *value) @@ -377,7 +383,7 @@ static void querystring_cb(const char *name, const char *value) ofs = -1; ctx.qry.ofs = ofs; } else if (!strcmp(name, "path")) { - ctx.qry.path = trim_end(value, '/'); + ctx.qry.path = cgit_trim_end(value, '/'); } else if (!strcmp(name, "s")) { ctx.qry.sort = xstrdup(value); } else if (!strcmp(name, "showmsg")) { @@ -567,7 +573,7 @@ static inline void parse_readme(const char *readme, char **filename, char **ref, /* Prepend repo path to relative readme path unless tracked. */ if (!(*ref) && readme[0] != '/') - *filename = fmtalloc("%s/%s", repo->path, readme); + *filename = cgit_fmtalloc("%s/%s", repo->path, readme); else *filename = xstrdup(readme); } @@ -628,7 +634,7 @@ static int prepare_repo_cmd(int nongit) if (nongit) { const char *name = ctx.repo->name; rc = errno; - ctx.page.title = fmtalloc("%s - %s", ctx.cfg.root_title, + ctx.page.title = cgit_fmtalloc("%s - %s", ctx.cfg.root_title, "config error"); ctx.repo = NULL; cgit_print_http_headers(); @@ -639,7 +645,7 @@ static int prepare_repo_cmd(int nongit) cgit_print_docend(); return 1; } - ctx.page.title = fmtalloc("%s - %s", ctx.repo->name, ctx.repo->desc); + ctx.page.title = cgit_fmtalloc("%s - %s", ctx.repo->name, ctx.repo->desc); if (!ctx.repo->defbranch) ctx.repo->defbranch = guess_defbranch(); @@ -693,12 +699,6 @@ static inline void open_auth_filter(const char *function) cgit_loginurl()); } -/* 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. */ -#define MAX_AUTHENTICATION_POST_BYTES 4096 /* The filter is expected to spit out "Status: " and all headers. */ static inline void authenticate_post(void) { @@ -944,9 +944,9 @@ static void process_cached_repolist(const char *path) time_t age; unsigned long hash; - hash = hash_str(path); + hash = cache_hash_str(path); if (ctx.cfg.project_list) - hash += hash_str(ctx.cfg.project_list); + hash += cache_hash_str(ctx.cfg.project_list); strbuf_addf(&cached_rc, "%s/rc-%8lx", ctx.cfg.cache_root, hash); if (stat(cached_rc.buf, &st)) { @@ -1095,7 +1095,7 @@ int cmd_main(int argc, const char **argv) cgit_repolist.repos = NULL; cgit_parse_args(argc, argv); - parse_configfile(expand_macros(ctx.env.cgit_config), config_cb); + parse_configfile(cgit_expand_macros(ctx.env.cgit_config), config_cb); ctx.repo = NULL; http_parse_querystring(ctx.qry.raw, querystring_cb); @@ -1104,7 +1104,7 @@ int cmd_main(int argc, const char **argv) * trailing slashes. */ if (!ctx.cfg.virtual_root && ctx.cfg.script_name) - ctx.cfg.virtual_root = ensure_end(ctx.cfg.script_name, '/'); + ctx.cfg.virtual_root = cgit_ensure_end(ctx.cfg.script_name, '/'); /* If no url parameter is specified on the querystring, lets * use PATH_INFO as url. This allows cgit to work with virtual @@ -1117,7 +1117,7 @@ int cmd_main(int argc, const char **argv) path++; ctx.qry.url = xstrdup(path); if (ctx.qry.raw) { - char *newqry = fmtalloc("%s?%s", path, ctx.qry.raw); + char *newqry = cgit_fmtalloc("%s?%s", path, ctx.qry.raw); free(ctx.qry.raw); ctx.qry.raw = newqry; } else -- cgit v2.8.0