On Fri, Aug 14, 2015 at 04:50:57PM +0200, Christian Hesse wrote:
> From: Christian Hesse <[email protected]>
> 
> 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 <[email protected]>
> ---
>  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
_______________________________________________
CGit mailing list
[email protected]
http://lists.zx2c4.com/mailman/listinfo/cgit

Reply via email to