[PATCH 1/1] enable cgit to show gravatar for author, committer and tagger

Peter Wu lekensteyn at gmail.com
Wed Nov 27 23:11:49 CET 2013


On Wednesday 27 November 2013 22:14:22 Christian Hesse wrote:
> +char * cgit_get_gravatar(const char *email) {
> +       unsigned char digest[16];
> +       char hex[33], *lower, *tmp;
> +       char *gravatar;
> +
> +       gravatar = malloc(77);

I do not quite like this magic number, does anyone have problems with
creating a GRAVATAR_URL macro? 77 seems also small enough to throw on the
stack. (Btw, len("//www.gravatar.com/avatar/?s=16&d=retro") + 32 + 1
says that the length is 76 including nul byte).

> +       /* duplicate to lower and skip brackets! */
> +       lower = strdup(email + 1);
> +       lower[strlen(lower) - 1] = '\0';

Ahh, I though it was off by one, but apparently you remove the brackets. OK.

> +
> +       /* make the chars lower case */
> +       for (tmp = lower; *tmp; ++tmp)
> +               *tmp = tolower(*tmp);
> +
> +       MD5((unsigned char *)lower, strlen(lower), digest);
> +
> +       str_to_hex(hex, digest, 16);
> +
> +       sprintf(gravatar, "//www.gravatar.com/avatar/%s?s=16&d=retro", hex);

It seems ugly to me to store the HTML-escaped URL here. What do you think of
using just "&" here and html_txt() when outputting the URL? Processing these
few chars and performing an extra write() should not hurt performance.

Regarding the GRAVATAR_URL macro mentioned earlier, if used that could
also be inserted here. A comment could then describe why this URL is used
(16x16 image using "awesome generated, 8-bit arcade-style pixelated faces"
as default, https://en.gravatar.com/site/implement/images/)

> +       free(lower);
> +
> +       return gravatar;
> +}

Regards,
Peter


More information about the CGit mailing list