author | Georg Lukas <georg@op-co.de> | 2009-11-28 02:44:33 (UTC) |
---|---|---|
committer | Georg Lukas <georg@op-co.de> | 2009-11-28 02:44:33 (UTC) |
commit | ef07ccc72da0270e9298c36046a0187dc359b0da (patch) (side-by-side diff) | |
tree | 57a2ffdeb929d9b4ed44dfae3a1fb7ca550aac63 | |
parent | 545b5a5dcae2a0c322381493ee90f6c37353da9c (diff) | |
download | cgit-ef07ccc72da0270e9298c36046a0187dc359b0da.zip cgit-ef07ccc72da0270e9298c36046a0187dc359b0da.tar.gz cgit-ef07ccc72da0270e9298c36046a0187dc359b0da.tar.bz2 |
"max-blob-size" config var to limit generated HTML size
Sometimes it is not feasible to generate the HTML pretty-print for large
files, especially if a source-filter is involved or binary data is to be
displayed. The "max-blob-size" config var allows to disable HTML output
for blobs bigger than X KBytes. Plain downloads are not affected.
Signed-off-by: Georg Lukas <georg@op-co.de>
-rw-r--r-- | cgit.c | 3 | ||||
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | cgitrc.5.txt | 4 | ||||
-rw-r--r-- | ui-tree.c | 6 |
4 files changed, 14 insertions, 0 deletions
@@ -164,8 +164,10 @@ void config_cb(const char *name, const char *value) 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); + else if (!strcmp(name, "max-blob-size")) + ctx.cfg.max_blob_size = atoi(value); else if (!strcmp(name, "max-repo-count")) ctx.cfg.max_repo_count = atoi(value); else if (!strcmp(name, "max-commit-count")) ctx.cfg.max_commit_count = atoi(value); @@ -269,8 +271,9 @@ static void prepare_context(struct cgit_context *ctx) 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.module_link = "./?repo=%s&page=commit&id=%s"; ctx->cfg.renamelimit = -1; ctx->cfg.robots = "index, nofollow"; @@ -184,8 +184,9 @@ struct cgit_config { int max_commit_count; int max_lock_attempts; int max_msg_len; int max_repodesc_len; + int max_blob_size; int max_stats; int nocache; int noplainemail; int noheader; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 0c13485..e69140b 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -176,8 +176,12 @@ max-repo-count:: max-repodesc-length:: Specifies the maximum number of repo description characters to display on the repository index page. Default value: "80". +max-blob-size:: + Specifies the maximum size of a blob to display HTML for in KBytes. + Default value: "0" (limit disabled). + max-stats:: Set the default maximum statistics period. Valid values are "week", "month", "quarter" and "year". If unspecified, statistics are disabled. Default value: none. See also: "repo.max-stats". @@ -106,8 +106,14 @@ static void print_object(const unsigned char *sha1, char *path, const char *base cgit_plain_link("plain", NULL, NULL, ctx.qry.head, curr_rev, path); htmlf(")<br/>blob: %s\n", sha1_to_hex(sha1)); + if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) { + htmlf("<div class='error'>blob size (%dKB) exceeds display size limit (%dKB).</div>", + size / 1024, ctx.cfg.max_blob_size); + return; + } + if (buffer_is_binary(buf, size)) print_binary_buffer(buf, size); else print_text_buffer(basename, buf, size); |