Fix a compilation error. Remove spaces.
This commit is contained in:
parent
bb3e006354
commit
a2d7a49107
1 changed files with 63 additions and 64 deletions
|
@ -47,35 +47,35 @@ static void ngx_http_geoip2_cleanup(void *data);
|
||||||
|
|
||||||
|
|
||||||
static ngx_command_t ngx_http_geoip2_commands[] = {
|
static ngx_command_t ngx_http_geoip2_commands[] = {
|
||||||
|
|
||||||
{ ngx_string("geoip2_mmdb"),
|
{ ngx_string("geoip2_mmdb"),
|
||||||
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
||||||
ngx_http_geoip2_mmdb,
|
ngx_http_geoip2_mmdb,
|
||||||
NGX_HTTP_MAIN_CONF_OFFSET,
|
NGX_HTTP_MAIN_CONF_OFFSET,
|
||||||
0,
|
0,
|
||||||
NULL },
|
NULL },
|
||||||
|
|
||||||
{ ngx_string("geoip2_data"),
|
{ ngx_string("geoip2_data"),
|
||||||
NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE,
|
NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE,
|
||||||
ngx_http_geoip2_data,
|
ngx_http_geoip2_data,
|
||||||
NGX_HTTP_MAIN_CONF_OFFSET,
|
NGX_HTTP_MAIN_CONF_OFFSET,
|
||||||
0,
|
0,
|
||||||
NULL },
|
NULL },
|
||||||
|
|
||||||
{ ngx_string("geoip2_proxy"),
|
{ ngx_string("geoip2_proxy"),
|
||||||
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
||||||
ngx_http_geoip2_proxy,
|
ngx_http_geoip2_proxy,
|
||||||
NGX_HTTP_MAIN_CONF_OFFSET,
|
NGX_HTTP_MAIN_CONF_OFFSET,
|
||||||
0,
|
0,
|
||||||
NULL },
|
NULL },
|
||||||
|
|
||||||
{ ngx_string("geoip2_proxy_recursive"),
|
{ ngx_string("geoip2_proxy_recursive"),
|
||||||
NGX_HTTP_MAIN_CONF|NGX_CONF_FLAG,
|
NGX_HTTP_MAIN_CONF|NGX_CONF_FLAG,
|
||||||
ngx_conf_set_flag_slot,
|
ngx_conf_set_flag_slot,
|
||||||
NGX_HTTP_MAIN_CONF_OFFSET,
|
NGX_HTTP_MAIN_CONF_OFFSET,
|
||||||
offsetof(ngx_http_geoip2_conf_t, proxy_recursive),
|
offsetof(ngx_http_geoip2_conf_t, proxy_recursive),
|
||||||
NULL },
|
NULL },
|
||||||
|
|
||||||
ngx_null_command
|
ngx_null_command
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -83,13 +83,13 @@ static ngx_command_t ngx_http_geoip2_commands[] = {
|
||||||
static ngx_http_module_t ngx_http_geoip2_module_ctx = {
|
static ngx_http_module_t ngx_http_geoip2_module_ctx = {
|
||||||
NULL, /* preconfiguration */
|
NULL, /* preconfiguration */
|
||||||
NULL, /* preconfiguration */
|
NULL, /* preconfiguration */
|
||||||
|
|
||||||
ngx_http_geoip2_create_conf, /* create main configuration */
|
ngx_http_geoip2_create_conf, /* create main configuration */
|
||||||
ngx_http_geoip2_init_conf, /* init main configuration */
|
ngx_http_geoip2_init_conf, /* init main configuration */
|
||||||
|
|
||||||
NULL, /* create server configuration */
|
NULL, /* create server configuration */
|
||||||
NULL, /* merge server configuration */
|
NULL, /* merge server configuration */
|
||||||
|
|
||||||
NULL, /* create location configuration */
|
NULL, /* create location configuration */
|
||||||
NULL /* merge location configuration */
|
NULL /* merge location configuration */
|
||||||
};
|
};
|
||||||
|
@ -121,29 +121,29 @@ ngx_http_geoip2_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
|
||||||
ngx_http_geoip2_conf_t *gcf;
|
ngx_http_geoip2_conf_t *gcf;
|
||||||
ngx_addr_t addr;
|
ngx_addr_t addr;
|
||||||
ngx_array_t *xfwd;
|
ngx_array_t *xfwd;
|
||||||
|
|
||||||
#if (NGX_HAVE_INET6)
|
#if (NGX_HAVE_INET6)
|
||||||
uint8_t address[16], *addressp = address;
|
uint8_t address[16], *addressp = address;
|
||||||
#else
|
#else
|
||||||
unsigned long address;
|
unsigned long address;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gcf = ngx_http_get_module_main_conf(r, ngx_http_geoip2_module);
|
gcf = ngx_http_get_module_main_conf(r, ngx_http_geoip2_module);
|
||||||
|
|
||||||
if (!gcf->initialized) {
|
if (!gcf->initialized) {
|
||||||
goto not_found;
|
goto not_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr.sockaddr = r->connection->sockaddr;
|
addr.sockaddr = r->connection->sockaddr;
|
||||||
addr.socklen = r->connection->socklen;
|
addr.socklen = r->connection->socklen;
|
||||||
|
|
||||||
xfwd = &r->headers_in.x_forwarded_for;
|
xfwd = &r->headers_in.x_forwarded_for;
|
||||||
|
|
||||||
if (xfwd->nelts > 0 && gcf->proxies != NULL) {
|
if (xfwd->nelts > 0 && gcf->proxies != NULL) {
|
||||||
(void) ngx_http_get_forwarded_addr(r, &addr, xfwd, NULL,
|
(void) ngx_http_get_forwarded_addr(r, &addr, xfwd, NULL,
|
||||||
gcf->proxies, gcf->proxy_recursive);
|
gcf->proxies, gcf->proxy_recursive);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (addr.sockaddr->sa_family) {
|
switch (addr.sockaddr->sa_family) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
#if (NGX_HAVE_INET6)
|
#if (NGX_HAVE_INET6)
|
||||||
|
@ -151,7 +151,7 @@ ngx_http_geoip2_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
|
||||||
ngx_memcpy(addressp + 12, &((struct sockaddr_in *)
|
ngx_memcpy(addressp + 12, &((struct sockaddr_in *)
|
||||||
addr.sockaddr)->sin_addr.s_addr, 4);
|
addr.sockaddr)->sin_addr.s_addr, 4);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
ngx_memcpy(addressp, &((struct sockaddr_in6 *)
|
ngx_memcpy(addressp, &((struct sockaddr_in6 *)
|
||||||
addr.sockaddr)->sin6_addr.s6_addr, 16);
|
addr.sockaddr)->sin6_addr.s6_addr, 16);
|
||||||
|
@ -159,36 +159,36 @@ ngx_http_geoip2_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
|
||||||
address = ((struct sockaddr_in *)addr.sockaddr)->sin_addr.s_addr;
|
address = ((struct sockaddr_in *)addr.sockaddr)->sin_addr.s_addr;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
goto not_found;
|
goto not_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (NGX_HAVE_INET6)
|
#if (NGX_HAVE_INET6)
|
||||||
if (ngx_memcmp(&address, &gcf->address, sizeof(address)) != 0) {
|
if (ngx_memcmp(&address, &gcf->address, sizeof(address)) != 0) {
|
||||||
#else
|
#else
|
||||||
if (address != gcf->address)
|
if (address != gcf->address) {
|
||||||
#endif
|
#endif
|
||||||
memcpy(&gcf->address, &address, sizeof(address));
|
memcpy(&gcf->address, &address, sizeof(address));
|
||||||
gcf->result = MMDB_lookup_sockaddr(&gcf->database, addr.sockaddr,
|
gcf->result = MMDB_lookup_sockaddr(&gcf->database, addr.sockaddr,
|
||||||
&mmdb_error);
|
&mmdb_error);
|
||||||
|
|
||||||
if (mmdb_error != MMDB_SUCCESS) {
|
if (mmdb_error != MMDB_SUCCESS) {
|
||||||
goto not_found;
|
goto not_found;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gcf->result.found_entry || MMDB_aget_value(&gcf->result.entry,
|
if (!gcf->result.found_entry || MMDB_aget_value(&gcf->result.entry,
|
||||||
&entry_data,
|
&entry_data,
|
||||||
geoip2->lookup)
|
geoip2->lookup)
|
||||||
!= MMDB_SUCCESS) {
|
!= MMDB_SUCCESS) {
|
||||||
goto not_found;
|
goto not_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!entry_data.has_data) {
|
if (!entry_data.has_data) {
|
||||||
goto not_found;
|
goto not_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (entry_data.type) {
|
switch (entry_data.type) {
|
||||||
case MMDB_DATA_TYPE_UTF8_STRING:
|
case MMDB_DATA_TYPE_UTF8_STRING:
|
||||||
v->data = (u_char *) entry_data.utf8_string;
|
v->data = (u_char *) entry_data.utf8_string;
|
||||||
|
@ -197,17 +197,16 @@ ngx_http_geoip2_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
|
||||||
default:
|
default:
|
||||||
goto not_found;
|
goto not_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
v->valid = 1;
|
v->valid = 1;
|
||||||
v->no_cacheable = 0;
|
v->no_cacheable = 0;
|
||||||
v->not_found = 0;
|
v->not_found = 0;
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
|
|
||||||
not_found:
|
not_found:
|
||||||
|
|
||||||
v->not_found = 1;
|
v->not_found = 1;
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,23 +216,23 @@ ngx_http_geoip2_create_conf(ngx_conf_t *cf)
|
||||||
{
|
{
|
||||||
ngx_pool_cleanup_t *cln;
|
ngx_pool_cleanup_t *cln;
|
||||||
ngx_http_geoip2_conf_t *conf;
|
ngx_http_geoip2_conf_t *conf;
|
||||||
|
|
||||||
conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_geoip2_conf_t));
|
conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_geoip2_conf_t));
|
||||||
if (conf == NULL) {
|
if (conf == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
conf->proxy_recursive = NGX_CONF_UNSET;
|
conf->proxy_recursive = NGX_CONF_UNSET;
|
||||||
conf->initialized = 0;
|
conf->initialized = 0;
|
||||||
|
|
||||||
cln = ngx_pool_cleanup_add(cf->pool, 0);
|
cln = ngx_pool_cleanup_add(cf->pool, 0);
|
||||||
if (cln == NULL) {
|
if (cln == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cln->handler = ngx_http_geoip2_cleanup;
|
cln->handler = ngx_http_geoip2_cleanup;
|
||||||
cln->data = conf;
|
cln->data = conf;
|
||||||
|
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,44 +244,44 @@ ngx_http_geoip2_data(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||||
ngx_http_geoip2_ctx_t *geoip2;
|
ngx_http_geoip2_ctx_t *geoip2;
|
||||||
ngx_http_variable_t *var;
|
ngx_http_variable_t *var;
|
||||||
int i, nelts;
|
int i, nelts;
|
||||||
|
|
||||||
geoip2 = ngx_pcalloc(cf->pool, sizeof(ngx_http_geoip2_ctx_t));
|
geoip2 = ngx_pcalloc(cf->pool, sizeof(ngx_http_geoip2_ctx_t));
|
||||||
if (geoip2 == NULL) {
|
if (geoip2 == NULL) {
|
||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
geoip2->lookup = ngx_pcalloc(cf->pool,
|
geoip2->lookup = ngx_pcalloc(cf->pool,
|
||||||
sizeof(const char *) * (cf->args->nelts - 1));
|
sizeof(const char *) * (cf->args->nelts - 1));
|
||||||
if (geoip2->lookup == NULL) {
|
if (geoip2->lookup == NULL) {
|
||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = cf->args->elts;
|
value = cf->args->elts;
|
||||||
name = value[1];
|
name = value[1];
|
||||||
nelts = (int) cf->args->nelts;
|
nelts = (int) cf->args->nelts;
|
||||||
|
|
||||||
if (name.data[0] != '$') {
|
if (name.data[0] != '$') {
|
||||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||||
"invalid variable name \"%V\"", &name);
|
"invalid variable name \"%V\"", &name);
|
||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
name.len--;
|
name.len--;
|
||||||
name.data++;
|
name.data++;
|
||||||
|
|
||||||
var = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE);
|
var = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE);
|
||||||
if (var == NULL) {
|
if (var == NULL) {
|
||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 2; i < nelts; i++) {
|
for (i = 2; i < nelts; i++) {
|
||||||
geoip2->lookup[i-2] = (char *) value[i].data;
|
geoip2->lookup[i-2] = (char *) value[i].data;
|
||||||
}
|
}
|
||||||
geoip2->lookup[i] = NULL;
|
geoip2->lookup[i] = NULL;
|
||||||
|
|
||||||
var->get_handler = ngx_http_geoip2_variable;
|
var->get_handler = ngx_http_geoip2_variable;
|
||||||
var->data = (uintptr_t) geoip2;
|
var->data = (uintptr_t) geoip2;
|
||||||
|
|
||||||
return NGX_CONF_OK;
|
return NGX_CONF_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,15 +290,15 @@ static char *
|
||||||
ngx_http_geoip2_init_conf(ngx_conf_t *cf, void *conf)
|
ngx_http_geoip2_init_conf(ngx_conf_t *cf, void *conf)
|
||||||
{
|
{
|
||||||
ngx_http_geoip2_conf_t *gcf = conf;
|
ngx_http_geoip2_conf_t *gcf = conf;
|
||||||
|
|
||||||
ngx_conf_init_value(gcf->proxy_recursive, 0);
|
ngx_conf_init_value(gcf->proxy_recursive, 0);
|
||||||
|
|
||||||
#if (NGX_HAVE_INET6)
|
#if (NGX_HAVE_INET6)
|
||||||
ngx_memset(&gcf->address, 0, sizeof(gcf->address));
|
ngx_memset(&gcf->address, 0, sizeof(gcf->address));
|
||||||
#else
|
#else
|
||||||
gcf->address = 0;
|
gcf->address = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return NGX_CONF_OK;
|
return NGX_CONF_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,23 +308,23 @@ ngx_http_geoip2_mmdb(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||||
{
|
{
|
||||||
ngx_http_geoip2_conf_t *gcf = conf;
|
ngx_http_geoip2_conf_t *gcf = conf;
|
||||||
ngx_str_t *value;
|
ngx_str_t *value;
|
||||||
|
|
||||||
if (gcf->initialized) {
|
if (gcf->initialized) {
|
||||||
return "is duplicate";
|
return "is duplicate";
|
||||||
}
|
}
|
||||||
|
|
||||||
value = cf->args->elts;
|
value = cf->args->elts;
|
||||||
|
|
||||||
int status = MMDB_open((char *) value[1].data,
|
int status = MMDB_open((char *) value[1].data,
|
||||||
MMDB_MODE_MMAP, &gcf->database);
|
MMDB_MODE_MMAP, &gcf->database);
|
||||||
|
|
||||||
if (status != MMDB_SUCCESS) {
|
if (status != MMDB_SUCCESS) {
|
||||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||||
"MMDB_open(\"%V\") failed - %s", &value[1],
|
"MMDB_open(\"%V\") failed - %s", &value[1],
|
||||||
MMDB_strerror(status));
|
MMDB_strerror(status));
|
||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
gcf->initialized = 1;
|
gcf->initialized = 1;
|
||||||
return NGX_CONF_OK;
|
return NGX_CONF_OK;
|
||||||
}
|
}
|
||||||
|
@ -337,27 +336,27 @@ ngx_http_geoip2_proxy(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||||
ngx_http_geoip2_conf_t *gcf = conf;
|
ngx_http_geoip2_conf_t *gcf = conf;
|
||||||
ngx_str_t *value;
|
ngx_str_t *value;
|
||||||
ngx_cidr_t cidr, *c;
|
ngx_cidr_t cidr, *c;
|
||||||
|
|
||||||
value = cf->args->elts;
|
value = cf->args->elts;
|
||||||
|
|
||||||
if (ngx_http_geoip2_cidr_value(cf, &value[1], &cidr) != NGX_OK) {
|
if (ngx_http_geoip2_cidr_value(cf, &value[1], &cidr) != NGX_OK) {
|
||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gcf->proxies == NULL) {
|
if (gcf->proxies == NULL) {
|
||||||
gcf->proxies = ngx_array_create(cf->pool, 4, sizeof(ngx_cidr_t));
|
gcf->proxies = ngx_array_create(cf->pool, 4, sizeof(ngx_cidr_t));
|
||||||
if (gcf->proxies == NULL) {
|
if (gcf->proxies == NULL) {
|
||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c = ngx_array_push(gcf->proxies);
|
c = ngx_array_push(gcf->proxies);
|
||||||
if (c == NULL) {
|
if (c == NULL) {
|
||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
*c = cidr;
|
*c = cidr;
|
||||||
|
|
||||||
return NGX_CONF_OK;
|
return NGX_CONF_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,28 +364,28 @@ static ngx_int_t
|
||||||
ngx_http_geoip2_cidr_value(ngx_conf_t *cf, ngx_str_t *net, ngx_cidr_t *cidr)
|
ngx_http_geoip2_cidr_value(ngx_conf_t *cf, ngx_str_t *net, ngx_cidr_t *cidr)
|
||||||
{
|
{
|
||||||
ngx_int_t rc;
|
ngx_int_t rc;
|
||||||
|
|
||||||
if (ngx_strcmp(net->data, "255.255.255.255") == 0) {
|
if (ngx_strcmp(net->data, "255.255.255.255") == 0) {
|
||||||
cidr->family = AF_INET;
|
cidr->family = AF_INET;
|
||||||
cidr->u.in.addr = 0xffffffff;
|
cidr->u.in.addr = 0xffffffff;
|
||||||
cidr->u.in.mask = 0xffffffff;
|
cidr->u.in.mask = 0xffffffff;
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = ngx_ptocidr(net, cidr);
|
rc = ngx_ptocidr(net, cidr);
|
||||||
|
|
||||||
if (rc == NGX_ERROR) {
|
if (rc == NGX_ERROR) {
|
||||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||||
"invalid network \"%V\"", net);
|
"invalid network \"%V\"", net);
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc == NGX_DONE) {
|
if (rc == NGX_DONE) {
|
||||||
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
||||||
"low address bits of %V are meaningless", net);
|
"low address bits of %V are meaningless", net);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,9 +394,9 @@ static void
|
||||||
ngx_http_geoip2_cleanup(void *data)
|
ngx_http_geoip2_cleanup(void *data)
|
||||||
{
|
{
|
||||||
ngx_http_geoip2_conf_t *gcf = data;
|
ngx_http_geoip2_conf_t *gcf = data;
|
||||||
|
|
||||||
if (gcf->initialized) {
|
if (gcf->initialized) {
|
||||||
MMDB_close(&gcf->database);
|
MMDB_close(&gcf->database);
|
||||||
gcf->initialized = 0;
|
gcf->initialized = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue