[PATCH 2/3] about: send images plain

John Keeping john at keeping.me.uk
Sat Aug 15 13:30:43 CEST 2015


On Fri, Aug 14, 2015 at 11:16:36PM +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>
> ---
>  ui-summary.c | 35 +++++++++++++++++++++++++++++++++--
>  1 file changed, 33 insertions(+), 2 deletions(-)
> 
> diff --git a/ui-summary.c b/ui-summary.c
> index fb04dc3..99c9234 100644
> --- a/ui-summary.c
> +++ b/ui-summary.c
> @@ -9,9 +9,10 @@
>  #include "cgit.h"
>  #include "ui-summary.h"
>  #include "html.h"
> +#include "ui-blob.h"
>  #include "ui-log.h"
> +#include "ui-plain.h"
>  #include "ui-refs.h"
> -#include "ui-blob.h"
>  #include "ui-shared.h"
>  
>  static int urls;
> @@ -100,8 +101,38 @@ static char* append_readme_path(const char *filename, const char *ref, const cha
>  
>  void cgit_print_repo_readme(char *path)
>  {
> -	char *filename, *ref;
> +	char *ext = NULL, *filename, *ref, *mimetype = NULL;
>  	int free_filename = 0;
> +	int freemime = 0;
> +	struct string_list_item *mime;
> +
> +	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;
> +		}
> +	}

This would be simpler if the refactoring in patch 3 was done as a
preparatory step rather than a clean up afterwards.

> +	if (mimetype && strncmp(mimetype, "image/", 6) == 0) {
> +		ctx.page.mimetype = mimetype;
> +		ctx.page.charset = NULL;
> +		cgit_print_plain();
> +
> +		if (freemime)
> +			free(mimetype);
> +
> +		return;
> +	}
> +
> +	if (freemime)
> +		free(mimetype);
>  
>  	cgit_print_layout_start();
>  	if (ctx.repo->readme.nr == 0)
> -- 
> 2.5.0
> 
> _______________________________________________
> CGit mailing list
> CGit at lists.zx2c4.com
> http://lists.zx2c4.com/mailman/listinfo/cgit


More information about the CGit mailing list