Exemple #1
0
VCL_VOID
vmod_resp(VRT_CTX, VCL_STRING val)
{
	//thread check
	if(ctx->req == NULL || ctx->req->magic != REQ_MAGIC){
		VSLb(ctx->vsl, SLT_Error,"vmod-dump: dump.resp work only at client-thread.");
		return;
	}
	
	VSLb(ctx->vsl, SLT_Debug,"%s-I: %s %d %s %d", VMOD_DUMP_PRE,
		VRT_IP_string(ctx, VRT_r_client_ip(ctx)),
		VSA_Port(VRT_r_client_ip(ctx)),
		VRT_IP_string(ctx, VRT_r_server_ip(ctx)),
		VSA_Port(VRT_r_server_ip(ctx))
	);
	VDP_push(ctx->req, VDP_dump, (void*)val, 1);
}
/* Returns the GeoIP info as synthetic response */
void vcl_geoip_send_synthetic(const struct sess *sp) {
    vcl_string hval[HEADER_MAXLEN];
    vcl_string *ip = VRT_IP_string(sp, VRT_r_client_ip(sp));
    if (geoip_lookup(ip, hval)) {
        VRT_synth_page(sp, 0, hval, vrt_magic_string_end);
    }
    else {
        VRT_synth_page(sp, 0, "", vrt_magic_string_end);
    }
}
/* Sets "X-Geo-IP" header with the geoip resolved information */
void vcl_geoip_set_header(const struct sess *sp) {
    vcl_string hval[HEADER_MAXLEN];
    vcl_string *ip = VRT_IP_string(sp, VRT_r_client_ip(sp));
    if (geoip_lookup(ip, hval)) {
        VRT_SetHdr(sp, HDR_REQ, "\011X-Geo-IP:", hval, vrt_magic_string_end);
    }
    else {
        /* Send an empty header */
        VRT_SetHdr(sp, HDR_REQ, "\011X-Geo-IP:", "", vrt_magic_string_end);
    }
}
Exemple #4
0
VCL_VOID
vmod_req(VRT_CTX, VCL_STRING val)
{
	//thread check
	if(ctx->req == NULL || ctx->req->magic != REQ_MAGIC){
		VSLb(ctx->vsl, SLT_Error,"vmod-dump: dump.req work only at client-thread.");
		return;
	}
	//remote client local server
	//VRT_r_remote_ip
	//VRT_r_client_ip
	//VRT_r_local_ip
	//VRT_r_server_ip
	//VRT_IP_string(IP) ip->str
	//VSA_Port(IP) ip->port
	VSLb(ctx->vsl, SLT_Debug,"%s-I: %s %d %s %d", VMOD_DUMP_PRE,
		VRT_IP_string(ctx, VRT_r_client_ip(ctx)),
		VSA_Port(VRT_r_client_ip(ctx)),
		VRT_IP_string(ctx, VRT_r_server_ip(ctx)),
		VSA_Port(VRT_r_server_ip(ctx))
	);
	VSLb(ctx->vsl, SLT_Debug,"%s-S: REQ", VMOD_DUMP_PRE);
	VSLb(ctx->vsl, SLT_Debug,"%s-V: %s", VMOD_DUMP_PRE, val);
	unsigned u;
	//reserve work-space

	u = WS_Reserve(ctx->req->ws, 0);
	if(u <= VMOD_DUMP_KEY_LEN) {
		//no space.
		WS_Release(ctx->req->ws, 0);
		return;
	}
	work_head(ctx->req,ctx->req->ws->f, u, ctx->req->http0,HTTP1_Req);
	//free work-space
	WS_Release(ctx->req->ws, 0);
	
	VRB_Iterate(ctx->req, vbf_printRequestBody, NULL);
	VSLb(ctx->vsl, SLT_Debug,"%s-S: END", VMOD_DUMP_PRE);
}
/* Simplified version: sets "X-Geo-IP" header with the country only */
void vcl_geoip_country_set_header(const struct sess *sp) {
    vcl_string hval[HEADER_MAXLEN];
    vcl_string *ip = VRT_IP_string(sp, VRT_r_client_ip(sp));
    geoip_lookup_country(ip, hval);
    VRT_SetHdr(sp, HDR_REQ, "\011X-Geo-IP:", hval, vrt_magic_string_end);
}