BBlack has submitted this change and it was merged. Change subject: Format GeoIP VCL C code for consistency with Varnish ......................................................................
Format GeoIP VCL C code for consistency with Varnish The only significant change is the removal of 'inline' from the declaration of geo_init. Change-Id: Iea8941896ba711ce00a927d49a35526782baa286 --- M templates/varnish/geoip.inc.vcl.erb 1 file changed, 30 insertions(+), 14 deletions(-) Approvals: BBlack: Looks good to me, approved jenkins-bot: Verified diff --git a/templates/varnish/geoip.inc.vcl.erb b/templates/varnish/geoip.inc.vcl.erb index 4ee2007..5d12d6e 100644 --- a/templates/varnish/geoip.inc.vcl.erb +++ b/templates/varnish/geoip.inc.vcl.erb @@ -21,13 +21,15 @@ char * geo_sanitize_for_cookie (char *string); void geo_set_cache_control (const struct sess *sp); - inline void geo_init () { + void + geo_init() { if (gi == NULL) { gi = GeoIP_open("/usr/share/GeoIP/GeoIPCity.dat", GEOIP_MMAP_CACHE); } } - int geo_get_addr_family (const char *addr) { + int + geo_get_addr_family(const char *addr) { struct addrinfo hint; struct addrinfo *info = NULL; int ret, result; @@ -46,7 +48,12 @@ return result; } - char * geo_get_xff_ip (const struct sess *sp) { + /* + * Return the first IP address from the X-Forwarded-For header of the + * incoming request, or NULL if no such header was set. + */ + char * + geo_get_xff_ip(const struct sess *sp) { char *xff = VRT_GetHdr(sp, HDR_REQ, "\020X-Forwarded-For:"); char *xff_list_item, *last; @@ -59,17 +66,26 @@ return xff; } - char * geo_sanitize_for_cookie (char *string) { - char *ptr; - for (ptr = string; *ptr; ptr++) { - if (strchr(";, ", *ptr)) { - *ptr = '_'; + /* + * Make a string safe to use as a cookie value in a Set-Cookie header by + * replacing characters that are disallowed by RFC 6265 with underscores. + */ + char * + geo_sanitize_for_cookie(char *string) { + char *ptr; + for (ptr = string; *ptr; ptr++) { + if (strchr(";, ", *ptr)) { + *ptr = '_'; + } } - } - return string; + return string; } - void geo_set_cache_control (const struct sess *sp) { + /* + * Set Last-Modified and Cache-Control headers for GeoIP requests. + */ + void + geo_set_cache_control(const struct sess *sp) { char *now = VRT_time_string(sp, VRT_r_now(sp)); VRT_SetHdr(sp, HDR_OBJ, "\016Last-Modified:", now, vrt_magic_string_end); VRT_SetHdr(sp, HDR_OBJ, "\016Cache-Control:", "private, max-age=86400, s-maxage=0", vrt_magic_string_end); @@ -135,10 +151,10 @@ /* Set-Cookie: GeoIP=US:San_Francisco:37.7749:-122.4194:v6; path=/ */ snprintf(latlon, sizeof(latlon), "%.4f:%.4f", record->latitude, record->longitude); cookie = VRT_WrkString(sp, "GeoIP=", - record->country_code, ":", - geo_sanitize_for_cookie(record->city), ":", + record->country_code, ":", + geo_sanitize_for_cookie(record->city), ":", latlon, ":", - AF_INET6 ? "v6" : "v4", "; path=/", + AF_INET6 ? "v6" : "v4", "; path=/", vrt_magic_string_end); GeoIPRecord_delete(record); } else { -- To view, visit https://gerrit.wikimedia.org/r/115343 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Iea8941896ba711ce00a927d49a35526782baa286 Gerrit-PatchSet: 2 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Ori.livneh <o...@wikimedia.org> Gerrit-Reviewer: BBlack <bbl...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits