all repos — cgit @ c52e84135e6272d008f69a9ac00265875ff4e60e

a hyperfast web frontend for git written in c

shared.c (view raw)

  1/* shared.c: global vars + some callback functions
  2 *
  3 * Copyright (C) 2006 Lars Hjemli
  4 *
  5 * Licensed under GNU General Public License v2
  6 *   (see COPYING for full license text)
  7 */
  8
  9#include "cgit.h"
 10
 11struct repolist cgit_repolist;
 12struct repoinfo *cgit_repo;
 13
 14char *cgit_root_title   = "Git repository browser";
 15char *cgit_css          = "/cgit.css";
 16char *cgit_logo         = "/git-logo.png";
 17char *cgit_logo_link    = "http://www.kernel.org/pub/software/scm/git/docs/";
 18char *cgit_virtual_root = NULL;
 19
 20char *cgit_cache_root   = "/var/cache/cgit";
 21
 22int cgit_nocache               =  0;
 23int cgit_max_lock_attempts     =  5;
 24int cgit_cache_root_ttl        =  5;
 25int cgit_cache_repo_ttl        =  5;
 26int cgit_cache_dynamic_ttl     =  5;
 27int cgit_cache_static_ttl      = -1;
 28int cgit_cache_max_create_time =  5;
 29
 30int cgit_max_msg_len = 60;
 31
 32char *cgit_repo_name    = NULL;
 33char *cgit_repo_desc    = NULL;
 34char *cgit_repo_owner   = NULL;
 35
 36int cgit_query_has_symref = 0;
 37int cgit_query_has_sha1   = 0;
 38
 39char *cgit_querystring  = NULL;
 40char *cgit_query_repo   = NULL;
 41char *cgit_query_page   = NULL;
 42char *cgit_query_head   = NULL;
 43char *cgit_query_search = NULL;
 44char *cgit_query_sha1   = NULL;
 45char *cgit_query_sha2   = NULL;
 46char *cgit_query_path   = NULL;
 47int   cgit_query_ofs    = 0;
 48
 49int htmlfd = 0;
 50
 51struct repoinfo *add_repo(const char *url)
 52{
 53	struct repoinfo *ret;
 54
 55	if (++cgit_repolist.count > cgit_repolist.length) {
 56		if (cgit_repolist.length == 0)
 57			cgit_repolist.length = 8;
 58		else
 59			cgit_repolist.length *= 2;
 60		cgit_repolist.repos = xrealloc(cgit_repolist.repos, 
 61					       cgit_repolist.length * 
 62					       sizeof(struct repoinfo));
 63	}
 64
 65	ret = &cgit_repolist.repos[cgit_repolist.count-1];
 66	ret->url = xstrdup(url);
 67	ret->name = ret->url;
 68	ret->path = NULL;
 69	ret->desc = NULL;
 70	ret->owner = NULL;
 71	return ret;
 72}
 73
 74void cgit_global_config_cb(const char *name, const char *value)
 75{
 76	if (!strcmp(name, "root-title"))
 77		cgit_root_title = xstrdup(value);
 78	else if (!strcmp(name, "css"))
 79		cgit_css = xstrdup(value);
 80	else if (!strcmp(name, "logo"))
 81		cgit_logo = xstrdup(value);
 82	else if (!strcmp(name, "logo-link"))
 83		cgit_logo_link = xstrdup(value);
 84	else if (!strcmp(name, "virtual-root"))
 85		cgit_virtual_root = xstrdup(value);
 86	else if (!strcmp(name, "nocache"))
 87		cgit_nocache = atoi(value);
 88	else if (!strcmp(name, "cache-root"))
 89		cgit_cache_root = xstrdup(value);
 90	else if (!strcmp(name, "cache-root-ttl"))
 91		cgit_cache_root_ttl = atoi(value);
 92	else if (!strcmp(name, "cache-repo-ttl"))
 93		cgit_cache_repo_ttl = atoi(value);
 94	else if (!strcmp(name, "cache-static-ttl"))
 95		cgit_cache_static_ttl = atoi(value);
 96	else if (!strcmp(name, "cache-dynamic-ttl"))
 97		cgit_cache_dynamic_ttl = atoi(value);
 98	else if (!strcmp(name, "max-message-length"))
 99		cgit_max_msg_len = atoi(value);
100	else if (!strcmp(name, "repo.url"))
101		cgit_repo = add_repo(value);
102	else if (!strcmp(name, "repo.name"))
103		cgit_repo->name = xstrdup(value);
104	else if (cgit_repo && !strcmp(name, "repo.path"))
105		cgit_repo->path = xstrdup(value);
106	else if (cgit_repo && !strcmp(name, "repo.desc"))
107		cgit_repo->desc = xstrdup(value);
108	else if (cgit_repo && !strcmp(name, "repo.owner"))
109		cgit_repo->owner = xstrdup(value);
110}
111
112void cgit_repo_config_cb(const char *name, const char *value)
113{
114	if (!strcmp(name, "name"))
115		cgit_repo_name = xstrdup(value);
116	else if (!strcmp(name, "desc"))
117		cgit_repo_desc = xstrdup(value);
118	else if (!strcmp(name, "owner"))
119		cgit_repo_owner = xstrdup(value);
120}
121
122void cgit_querystring_cb(const char *name, const char *value)
123{
124	if (!strcmp(name,"r")) {
125		cgit_query_repo = xstrdup(value);
126	} else if (!strcmp(name, "p")) {
127		cgit_query_page = xstrdup(value);
128	} else if (!strcmp(name, "q")) {
129		cgit_query_search = xstrdup(value);
130	} else if (!strcmp(name, "h")) {
131		cgit_query_head = xstrdup(value);
132		cgit_query_has_symref = 1;
133	} else if (!strcmp(name, "id")) {
134		cgit_query_sha1 = xstrdup(value);
135		cgit_query_has_sha1 = 1;
136	} else if (!strcmp(name, "id2")) {
137		cgit_query_sha2 = xstrdup(value);
138		cgit_query_has_sha1 = 1;
139	} else if (!strcmp(name, "ofs")) {
140		cgit_query_ofs = atoi(value);
141	} else if (!strcmp(name, "path")) {
142		cgit_query_path = xstrdup(value);
143	}
144}
145
146void *cgit_free_commitinfo(struct commitinfo *info)
147{
148	free(info->author);
149	free(info->author_email);
150	free(info->committer);
151	free(info->committer_email);
152	free(info->subject);
153	free(info);
154	return NULL;
155}
156
157int hextoint(char c)
158{
159	if (c >= 'a' && c <= 'f')
160		return 10 + c - 'a';
161	else if (c >= 'A' && c <= 'F')
162		return 10 + c - 'A';
163	else if (c >= '0' && c <= '9')
164		return c - '0';
165	else
166		return -1;
167}
168