实现在函数:
static ngx_http_ip2location_ctx_t * ngx_http_ip2location_create_ctx(ngx_http_request_t *r):
声明:
u_char iparam[NGX_INET6_ADDRSTRLEN + 1];
ngx_http_variable_value_t* val;
ngx_str_t name = ngx_string("arg_ip");//uri里的ip参数
iparam[0]='\0';//初始化
val = ngx_http_get_variable(r, &name, 0); //获取ip值
if( val && !val->not_found && val->valid){
memcpy(iparam, val->data, val->len);
iparam[val->len]='\0';
}
if(iparam[0]!='\0'){
ctx->record = IP2Location_get_all(imcf->database, (char *)iparam);
}else{
ctx->record = IP2Location_get_all(imcf->database, (char *)address);
}
网友评论