コード例 #1
0
ファイル: vmod_geoip.c プロジェクト: b3cft/geoip-vmod
const char *
vmod_country(struct sess *sp, const char *ip)
{
    const char *country = NULL;
    char *cp;

    if (!gi) {
        gi = GeoIP_new(GEOIP_STANDARD);
        if (gi) {
            WSP(sp, SLT_VCL_Log, "GeoIP database was loaded on request.");
        } else {
            WSP(sp, SLT_VCL_Log, "GeoIP database was not loaded on request.");
        }
    }
    if (gi) {
      country = GeoIP_country_code_by_addr(gi, ip);
    }
    if (!country) {
      country= unknownCountry;
    }

    char lowerCountry[2];
    strcpy(lowerCountry, country);
    strtolower(lowerCountry);

    cp= WS_Dup(sp->wrk->ws, (const char *)lowerCountry);

    return(cp);
}
コード例 #2
0
const char *
vmod_get(struct sess *sp, struct vmod_priv *priv, const char *key)
{
	size_t len;
	uint32_t flags;
	memcached_return rc;
	memcached_st *mc = get_memcached(priv->priv);
	if (!mc) return NULL;

	char *value = memcached_get(mc, key, strlen(key), &len, &flags, &rc);
	if (!value) return NULL;

	char *ws_buf = WS_Dup(sp->ws, value);
	free(value);

	return ws_buf;
}