From: john at keeping.me.uk (John Keeping)
Subject: [PATCH 2/2] about: send images plain
Date: Fri, 14 Aug 2015 16:13:35 +0100 [thread overview]
Message-ID: <20150814151335.GB1412@serenity.lan> (raw)
In-Reply-To: <1439563857-32527-2-git-send-email-list@eworm.de>
On Fri, Aug 14, 2015 at 04:50:57PM +0200, Christian Hesse wrote:
> From: Christian Hesse <mail at eworm.de>
>
> The about page used to display just fine, but images were broken: The
> binary image data was embedded in html code.
> Use cgit_print_plain() to send images in plain mode and make them
> available on about page.
>
> Signed-off-by: Christian Hesse <mail at eworm.de>
> ---
> cmd.c | 33 +++++++++++++++++++++++++++++++--
> 1 file changed, 31 insertions(+), 2 deletions(-)
>
> diff --git a/cmd.c b/cmd.c
> index 20c80b0..d77ee63 100644
> --- a/cmd.c
> +++ b/cmd.c
> @@ -43,8 +43,37 @@ static void about_fn(void)
> 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);
The entire block below is probably better as an implementation detail of
cgit_print_repo_readme(), so that about_fn() remains relatively concise.
> + else {
> + char *ext = NULL;
> + int freemime = 0;
> + struct string_list_item *mime;
> + char * mimetype = NULL;
> +
The section below is very similar to bits of ui-plain.c::print_object().
I wonder if ui-shared.c should have something like:
int mimetype_for_filename(const char *filename, const char **mime, int *freemime);
and we can keep get_mimetype_from_file() as an implementation detail.
> + if (ctx.qry.path)
> + ext = strrchr(ctx.qry.path, '.');
> +
> + if (ext && *(++ext)) {
> + mime = string_list_lookup(&ctx.cfg.mimetypes, ext);
> + if (mime) {
> + mimetype = (char *)mime->util;
> + } else {
> + mimetype = get_mimetype_from_file(ctx.cfg.mimetype_file, ext);
> + if (mimetype)
> + freemime = 1;
> + }
> + }
> +
> + if (mimetype && strncmp(mimetype, "image/", 6) == 0) {
In ui-plain.c we inspect the buffer to see if the file looks binary; I
wonder if that makes sense here (not that it's necessarily easy to do
so).
> + ctx.page.mimetype = mimetype;
> + ctx.page.charset = NULL;
> + cgit_print_plain();
> + } else
> + cgit_print_repo_readme(ctx.qry.path);
> +
> + /* If we allocated this, then casting away const is safe. */
> + if (freemime)
> + free(mimetype);
> + }
> } else
> cgit_print_site_readme();
> }
> --
> 2.5.0
next prev parent reply other threads:[~2015-08-14 15:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-14 14:50 [PATCH 1/2] move get_mimetype_from_file() to shared list
2015-08-14 14:50 ` [PATCH 2/2] about: send images plain list
2015-08-14 15:13 ` john [this message]
2015-08-14 21:16 ` [PATCH 2/3] " list
2015-08-14 21:16 ` [PATCH 3/3] move shared code to get_mimetype_from_file() list
2015-08-15 11:29 ` john
2015-08-15 20:12 ` list
2015-08-14 23:07 ` [PATCH 2/3] about: send images plain Jason
2015-08-15 20:10 ` list
2015-08-15 11:30 ` john
2015-08-15 20:08 ` [PATCH 2/3] refactor get_mimetype_from_file() to get_mimetype_from_qrypath() list
2015-08-15 20:08 ` [PATCH 3/3] ui-summary: send images plain for about page list
2015-08-16 12:19 ` [PATCH 2/3] refactor get_mimetype_from_file() to get_mimetype_from_qrypath() john
2015-08-16 12:51 ` list
2015-08-16 12:53 ` [PATCH 2/3] refactor get_mimetype_from_file() to get_mimetype_for_filename() list
2015-08-16 12:53 ` [PATCH 3/3] ui-summary: send images plain for about page list
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150814151335.GB1412@serenity.lan \
--to=cgit@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).