Moved break out of FORMAT macro

This commit is contained in:
Lee Valentine 2016-06-17 10:32:55 -07:00
parent 9ebca76996
commit 2f9ee969c8

View file

@ -50,14 +50,14 @@ static ngx_int_t ngx_http_geoip2_cidr_value(ngx_conf_t *cf, ngx_str_t *net,
static void ngx_http_geoip2_cleanup(void *data); static void ngx_http_geoip2_cleanup(void *data);
#define FORMAT(fmt, ...) \ #define FORMAT(fmt, ...) do { \
p = ngx_palloc(r->pool, NGX_OFF_T_LEN); \ p = ngx_palloc(r->pool, NGX_OFF_T_LEN); \
if (p == NULL) { \ if (p == NULL) { \
return NGX_ERROR; \ return NGX_ERROR; \
} \ } \
v->len = ngx_sprintf(p, fmt, __VA_ARGS__) - p; \ v->len = ngx_sprintf(p, fmt, __VA_ARGS__) - p; \
v->data = p; \ v->data = p; \
break } while (0)
static ngx_command_t ngx_http_geoip2_commands[] = { static ngx_command_t ngx_http_geoip2_commands[] = {
@ -195,6 +195,7 @@ ngx_http_geoip2_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
switch (entry_data.type) { switch (entry_data.type) {
case MMDB_DATA_TYPE_BOOLEAN: case MMDB_DATA_TYPE_BOOLEAN:
FORMAT("%d", entry_data.boolean); FORMAT("%d", entry_data.boolean);
break;
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;
v->len = entry_data.data_size; v->len = entry_data.data_size;
@ -205,16 +206,22 @@ ngx_http_geoip2_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
break; break;
case MMDB_DATA_TYPE_FLOAT: case MMDB_DATA_TYPE_FLOAT:
FORMAT("%.5f", entry_data.float_value); FORMAT("%.5f", entry_data.float_value);
break;
case MMDB_DATA_TYPE_DOUBLE: case MMDB_DATA_TYPE_DOUBLE:
FORMAT("%.5f", entry_data.double_value); FORMAT("%.5f", entry_data.double_value);
break;
case MMDB_DATA_TYPE_UINT16: case MMDB_DATA_TYPE_UINT16:
FORMAT("%uD", entry_data.uint16); FORMAT("%uD", entry_data.uint16);
break;
case MMDB_DATA_TYPE_UINT32: case MMDB_DATA_TYPE_UINT32:
FORMAT("%uD", entry_data.uint32); FORMAT("%uD", entry_data.uint32);
break;
case MMDB_DATA_TYPE_INT32: case MMDB_DATA_TYPE_INT32:
FORMAT("%D", entry_data.int32); FORMAT("%D", entry_data.int32);
break;
case MMDB_DATA_TYPE_UINT64: case MMDB_DATA_TYPE_UINT64:
FORMAT("%uL", entry_data.uint64); FORMAT("%uL", entry_data.uint64);
break;
case MMDB_DATA_TYPE_UINT128: ; case MMDB_DATA_TYPE_UINT128: ;
#if MMDB_UINT128_IS_BYTE_ARRAY #if MMDB_UINT128_IS_BYTE_ARRAY
uint8_t *val = (uint8_t *)entry_data.uint128; uint8_t *val = (uint8_t *)entry_data.uint128;
@ -229,6 +236,7 @@ ngx_http_geoip2_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
FORMAT("0x%016uxL%016uxL", FORMAT("0x%016uxL%016uxL",
(uint64_t) (val >> 64), (uint64_t) val); (uint64_t) (val >> 64), (uint64_t) val);
#endif #endif
break;
default: default:
goto not_found; goto not_found;
} }