From mboxrd@z Thu Jan 1 00:00:00 1970 From: lekensteyn at gmail.com (Peter Wu) Date: Wed, 27 Nov 2013 23:11:49 +0100 Subject: [PATCH 1/1] enable cgit to show gravatar for author, committer and tagger In-Reply-To: <1385586862-29756-1-git-send-email-mail@eworm.de> References: <20131127215933.4a3b6a58@leda.localdomain> <1385586862-29756-1-git-send-email-mail@eworm.de> Message-ID: <461884100.iMVHHtLi2p@al> 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