Nginx-Perl
view release on metacpan or search on metacpan
src/http/modules/ngx_http_realip_module.c view on Meta::CPAN
ngx_int_t rc;
ngx_str_t *value;
ngx_cidr_t *cidr;
value = cf->args->elts;
if (rlcf->from == NULL) {
rlcf->from = ngx_array_create(cf->pool, 2,
sizeof(ngx_cidr_t));
if (rlcf->from == NULL) {
return NGX_CONF_ERROR;
}
}
cidr = ngx_array_push(rlcf->from);
if (cidr == NULL) {
return NGX_CONF_ERROR;
}
#if (NGX_HAVE_UNIX_DOMAIN)
if (ngx_strcmp(value[1].data, "unix:") == 0) {
cidr->family = AF_UNIX;
return NGX_CONF_OK;
}
#endif
rc = ngx_ptocidr(&value[1], cidr);
if (rc == NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%V\"",
&value[1]);
return NGX_CONF_ERROR;
}
if (rc == NGX_DONE) {
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
"low address bits of %V are meaningless", &value[1]);
}
return NGX_CONF_OK;
}
static char *
ngx_http_realip(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_realip_loc_conf_t *rlcf = conf;
ngx_str_t *value;
value = cf->args->elts;
if (ngx_strcmp(value[1].data, "X-Real-IP") == 0) {
rlcf->type = NGX_HTTP_REALIP_XREALIP;
return NGX_CONF_OK;
}
if (ngx_strcmp(value[1].data, "X-Forwarded-For") == 0) {
rlcf->type = NGX_HTTP_REALIP_XFWD;
return NGX_CONF_OK;
}
if (ngx_strcmp(value[1].data, "proxy_protocol") == 0) {
rlcf->type = NGX_HTTP_REALIP_PROXY;
return NGX_CONF_OK;
}
rlcf->type = NGX_HTTP_REALIP_HEADER;
rlcf->hash = ngx_hash_strlow(value[1].data, value[1].data, value[1].len);
rlcf->header = value[1];
return NGX_CONF_OK;
}
static void *
ngx_http_realip_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_realip_loc_conf_t *conf;
conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_realip_loc_conf_t));
if (conf == NULL) {
return NULL;
}
/*
* set by ngx_pcalloc():
*
* conf->from = NULL;
* conf->hash = 0;
* conf->header = { 0, NULL };
*/
conf->type = NGX_CONF_UNSET_UINT;
conf->recursive = NGX_CONF_UNSET;
return conf;
}
static char *
ngx_http_realip_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_realip_loc_conf_t *prev = parent;
ngx_http_realip_loc_conf_t *conf = child;
if (conf->from == NULL) {
conf->from = prev->from;
}
ngx_conf_merge_uint_value(conf->type, prev->type, NGX_HTTP_REALIP_XREALIP);
ngx_conf_merge_value(conf->recursive, prev->recursive, 0);
if (conf->header.len == 0) {
conf->hash = prev->hash;
conf->header = prev->header;
}
( run in 2.528 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )