static char *buildpath(const char *base, int baselen, const char *path) { if (path[0]) return fmtalloc("%.*s%s/", baselen, base, path); else return fmtalloc("%.*s/", baselen, base); }
char *cgit_repourl(const char *reponame) { if (ctx.cfg.virtual_root) return fmtalloc("%s%s/", ctx.cfg.virtual_root, reponame); else return fmtalloc("?r=%s", reponame); }
char *cgit_currenturl(void) { if (!ctx.qry.url) return xstrdup(cgit_rooturl()); const char *root = cgit_rooturl(); size_t len = strlen(root); if (len && root[len - 1] == '/') return fmtalloc("%s%s", root, ctx.qry.url); return fmtalloc("%s/%s", root, ctx.qry.url); }
/* The caller must free the return value. */ static char* append_readme_path(const char *filename, const char *ref, const char *path) { char *file, *base_dir, *full_path, *resolved_base = NULL, *resolved_full = NULL; /* If a subpath is specified for the about page, make it relative * to the directory containing the configured readme. */ file = xstrdup(filename); base_dir = dirname(file); if (!strcmp(base_dir, ".") || !strcmp(base_dir, "..")) { if (!ref) { free(file); return NULL; } full_path = xstrdup(path); } else full_path = fmtalloc("%s/%s", base_dir, path); if (!ref) { resolved_base = realpath(base_dir, NULL); resolved_full = realpath(full_path, NULL); if (!resolved_base || !resolved_full || !starts_with(resolved_full, resolved_base)) { free(full_path); full_path = NULL; } } free(file); free(resolved_base); free(resolved_full); return full_path; }
const char *cgit_loginurl(void) { static const char *login_url; if (!login_url) login_url = fmtalloc("%s?p=login", cgit_rooturl()); return login_url; }
static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) { const struct cgit_snapshot_format* f; struct strbuf filename = STRBUF_INIT; const char *basename; int free_ref = 0; if (!ref || strlen(ref) < 1) return; basename = cgit_repobasename(repo->url); if (prefixcmp(ref, basename) != 0) { if ((ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1])) ref++; if (isdigit(ref[0])) { ref = fmtalloc("%s-%s", basename, ref); free_ref = 1; } } for (f = cgit_snapshot_formats; f->suffix; f++) { if (!(repo->snapshots & f->bit)) continue; strbuf_reset(&filename); strbuf_addf(&filename, "%s%s", ref, f->suffix); cgit_snapshot_link(filename.buf, NULL, NULL, NULL, NULL, filename.buf); html(" "); } if (free_ref) free((char *)ref); strbuf_release(&filename); }
int fileinit(File *f, Wal *w, int n) { f->w = w; f->seq = n; f->path = fmtalloc("%s/binlog.%d", w->dir, n); return !!f->path; }
char *cgit_hosturl(void) { if (ctx.env.http_host) return xstrdup(ctx.env.http_host); if (!ctx.env.server_name) return NULL; if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80) return xstrdup(ctx.env.server_name); return fmtalloc("%s:%s", ctx.env.server_name, ctx.env.server_port); }
const char *cgit_hosturl() { if (ctx.env.http_host) return ctx.env.http_host; if (!ctx.env.server_name) return NULL; if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80) return ctx.env.server_name; return fmtalloc("%s:%s", ctx.env.server_name, ctx.env.server_port); }
static void about_fn(void) { if (ctx.repo) { if (!ctx.qry.path && ctx.qry.url[strlen(ctx.qry.url) - 1] != '/' && ctx.env.path_info[strlen(ctx.env.path_info) - 1] != '/') cgit_redirect(fmtalloc("%s/", cgit_currenturl()), true); else cgit_print_repo_readme(ctx.qry.path); } else cgit_print_site_readme(); }