summaryrefslogtreecommitdiffabout
path: root/cgit.c
Unidiff
Diffstat (limited to 'cgit.c') (more/less context) (show whitespace changes)
-rw-r--r--cgit.c87
1 files changed, 78 insertions, 9 deletions
diff --git a/cgit.c b/cgit.c
index 5301840..5816f3d 100644
--- a/cgit.c
+++ b/cgit.c
@@ -19,2 +19,25 @@ const char *cgit_version = CGIT_VERSION;
19 19
20void add_mimetype(const char *name, const char *value)
21{
22 struct string_list_item *item;
23
24 item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes);
25 item->util = xstrdup(value);
26}
27
28struct cgit_filter *new_filter(const char *cmd, int extra_args)
29{
30 struct cgit_filter *f;
31
32 if (!cmd || !cmd[0])
33 return NULL;
34
35 f = xmalloc(sizeof(struct cgit_filter));
36 f->cmd = xstrdup(cmd);
37 f->argv = xmalloc((2 + extra_args) * sizeof(char *));
38 f->argv[0] = f->cmd;
39 f->argv[1] = NULL;
40 return f;
41}
42
20void config_cb(const char *name, const char *value) 43void config_cb(const char *name, const char *value)
@@ -33,2 +56,4 @@ void config_cb(const char *name, const char *value)
33 ctx.cfg.footer = xstrdup(value); 56 ctx.cfg.footer = xstrdup(value);
57 else if (!strcmp(name, "head-include"))
58 ctx.cfg.head_include = xstrdup(value);
34 else if (!strcmp(name, "header")) 59 else if (!strcmp(name, "header"))
@@ -51,2 +76,6 @@ void config_cb(const char *name, const char *value)
51 ctx.cfg.nocache = atoi(value); 76 ctx.cfg.nocache = atoi(value);
77 else if (!strcmp(name, "noplainemail"))
78 ctx.cfg.noplainemail = atoi(value);
79 else if (!strcmp(name, "noheader"))
80 ctx.cfg.noheader = atoi(value);
52 else if (!strcmp(name, "snapshots")) 81 else if (!strcmp(name, "snapshots"))
@@ -73,2 +102,8 @@ void config_cb(const char *name, const char *value)
73 ctx.cfg.cache_dynamic_ttl = atoi(value); 102 ctx.cfg.cache_dynamic_ttl = atoi(value);
103 else if (!strcmp(name, "about-filter"))
104 ctx.cfg.about_filter = new_filter(value, 0);
105 else if (!strcmp(name, "commit-filter"))
106 ctx.cfg.commit_filter = new_filter(value, 0);
107 else if (!strcmp(name, "embedded"))
108 ctx.cfg.embedded = atoi(value);
74 else if (!strcmp(name, "max-message-length")) 109 else if (!strcmp(name, "max-message-length"))
@@ -81,2 +116,4 @@ void config_cb(const char *name, const char *value)
81 ctx.cfg.max_commit_count = atoi(value); 116 ctx.cfg.max_commit_count = atoi(value);
117 else if (!strcmp(name, "source-filter"))
118 ctx.cfg.source_filter = new_filter(value, 1);
82 else if (!strcmp(name, "summary-log")) 119 else if (!strcmp(name, "summary-log"))
@@ -97,2 +134,4 @@ void config_cb(const char *name, const char *value)
97 ctx.cfg.local_time = atoi(value); 134 ctx.cfg.local_time = atoi(value);
135 else if (!prefixcmp(name, "mimetype."))
136 add_mimetype(name + 9, value);
98 else if (!strcmp(name, "repo.group")) 137 else if (!strcmp(name, "repo.group"))
@@ -123,2 +162,8 @@ void config_cb(const char *name, const char *value)
123 ctx.repo->module_link= xstrdup(value); 162 ctx.repo->module_link= xstrdup(value);
163 else if (ctx.repo && !strcmp(name, "repo.about-filter"))
164 ctx.repo->about_filter = new_filter(value, 0);
165 else if (ctx.repo && !strcmp(name, "repo.commit-filter"))
166 ctx.repo->commit_filter = new_filter(value, 0);
167 else if (ctx.repo && !strcmp(name, "repo.source-filter"))
168 ctx.repo->source_filter = new_filter(value, 1);
124 else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { 169 else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) {
@@ -175,2 +220,7 @@ static void querystring_cb(const char *name, const char *value)
175 220
221char *xstrdupn(const char *str)
222{
223 return (str ? xstrdup(str) : NULL);
224}
225
176static void prepare_context(struct cgit_context *ctx) 226static void prepare_context(struct cgit_context *ctx)
@@ -188,3 +238,3 @@ static void prepare_context(struct cgit_context *ctx)
188 ctx->cfg.css = "/cgit.css"; 238 ctx->cfg.css = "/cgit.css";
189 ctx->cfg.logo = "/git-logo.png"; 239 ctx->cfg.logo = "/cgit.png";
190 ctx->cfg.local_time = 0; 240 ctx->cfg.local_time = 0;
@@ -205,2 +255,12 @@ static void prepare_context(struct cgit_context *ctx)
205 ctx->cfg.summary_tags = 10; 255 ctx->cfg.summary_tags = 10;
256 ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG"));
257 ctx->env.http_host = xstrdupn(getenv("HTTP_HOST"));
258 ctx->env.https = xstrdupn(getenv("HTTPS"));
259 ctx->env.no_http = xstrdupn(getenv("NO_HTTP"));
260 ctx->env.path_info = xstrdupn(getenv("PATH_INFO"));
261 ctx->env.query_string = xstrdupn(getenv("QUERY_STRING"));
262 ctx->env.request_method = xstrdupn(getenv("REQUEST_METHOD"));
263 ctx->env.script_name = xstrdupn(getenv("SCRIPT_NAME"));
264 ctx->env.server_name = xstrdupn(getenv("SERVER_NAME"));
265 ctx->env.server_port = xstrdupn(getenv("SERVER_PORT"));
206 ctx->page.mimetype = "text/html"; 266 ctx->page.mimetype = "text/html";
@@ -211,2 +271,10 @@ static void prepare_context(struct cgit_context *ctx)
211 ctx->page.expires = ctx->page.modified; 271 ctx->page.expires = ctx->page.modified;
272 ctx->page.etag = NULL;
273 memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list));
274 if (ctx->env.script_name)
275 ctx->cfg.script_name = ctx->env.script_name;
276 if (ctx->env.query_string)
277 ctx->qry.raw = ctx->env.query_string;
278 if (!ctx->env.cgit_config)
279 ctx->env.cgit_config = CGIT_CONFIG;
212} 280}
@@ -290,2 +358,4 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
290 ctx->qry.head = ctx->repo->defbranch; 358 ctx->qry.head = ctx->repo->defbranch;
359 ctx->page.status = 404;
360 ctx->page.statusmsg = "not found";
291 cgit_print_http_headers(ctx); 361 cgit_print_http_headers(ctx);
@@ -381,2 +451,5 @@ static void cgit_parse_args(int argc, const char **argv)
381 } 451 }
452 if (!strcmp(argv[i], "--nohttp")) {
453 ctx.env.no_http = "1";
454 }
382 if (!strncmp(argv[i], "--query=", 8)) { 455 if (!strncmp(argv[i], "--query=", 8)) {
@@ -433,3 +506,2 @@ int main(int argc, const char **argv)
433{ 506{
434 const char *cgit_config_env = getenv("CGIT_CONFIG");
435 const char *path; 507 const char *path;
@@ -443,9 +515,4 @@ int main(int argc, const char **argv)
443 515
444 if (getenv("SCRIPT_NAME"))
445 ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME"));
446 if (getenv("QUERY_STRING"))
447 ctx.qry.raw = xstrdup(getenv("QUERY_STRING"));
448 cgit_parse_args(argc, argv); 516 cgit_parse_args(argc, argv);
449 parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG, 517 parse_configfile(ctx.env.cgit_config, config_cb);
450 config_cb);
451 ctx.repo = NULL; 518 ctx.repo = NULL;
@@ -464,3 +531,3 @@ int main(int argc, const char **argv)
464 */ 531 */
465 path = getenv("PATH_INFO"); 532 path = ctx.env.path_info;
466 if (!ctx.qry.url && path) { 533 if (!ctx.qry.url && path) {
@@ -480,2 +547,4 @@ int main(int argc, const char **argv)
480 ctx.page.expires += ttl*60; 547 ctx.page.expires += ttl*60;
548 if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD"))
549 ctx.cfg.nocache = 1;
481 if (ctx.cfg.nocache) 550 if (ctx.cfg.nocache)