summaryrefslogtreecommitdiff
path: root/src/mrl_utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mrl_utils.cpp')
-rw-r--r--src/mrl_utils.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/mrl_utils.cpp b/src/mrl_utils.cpp
index a2e2668..7c9283f 100644
--- a/src/mrl_utils.cpp
+++ b/src/mrl_utils.cpp
@@ -247,7 +247,7 @@ void mrl_mmdb_init(const char *path)
}
}
-int mrl_search_ip_country(MMDB_s mmdb, const char *ip_address, const char *mycountry)
+int mrl_search_ip_country(MMDB_s mmdb, const char *ip_address, const unsigned int level, const char *name)
{
int gai_error, mmdb_error;
MMDB_lookup_result_s result = MMDB_lookup_string(&mmdb, ip_address, &gai_error, &mmdb_error);
@@ -263,9 +263,21 @@ int mrl_search_ip_country(MMDB_s mmdb, const char *ip_address, const char *mycou
assert(0);
}
MMDB_entry_data_s entry_data;
+ int status = 0;
if (result.found_entry)
- {
- int status = MMDB_get_value(&result.entry, &entry_data, "COUNTRY", NULL);
+ {
+ switch (level)
+ {
+ case MRL_COUNTRY_LEVEL:
+ status = MMDB_get_value(&result.entry, &entry_data, "COUNTRY", NULL);
+ break;
+ case MRL_PROVINCE_LEVEL:
+ status = MMDB_get_value(&result.entry, &entry_data, "PROVINCE", NULL);
+ break;
+ default:
+ assert(0);
+ break;
+ }
if (MMDB_SUCCESS != status)
{
MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_mmdb_search","Got an error looking up the entry data - %s!",MMDB_strerror(status));
@@ -273,7 +285,7 @@ int mrl_search_ip_country(MMDB_s mmdb, const char *ip_address, const char *mycou
}
if (entry_data.has_data)
{
- if(memcmp(mycountry, entry_data.utf8_string, entry_data.data_size) == 0)
+ if(memcmp(name, entry_data.utf8_string, entry_data.data_size) == 0)
{
return 0;
}
@@ -289,7 +301,7 @@ int mrl_search_ip_country(MMDB_s mmdb, const char *ip_address, const char *mycou
int mrl_is_inside_ip(const char *ip_addr)
{
int location = 0;
- location = mrl_search_ip_country(mrl_instance.mrl_mmdb, ip_addr, mrl_instance.mrl_cfg.ip_location);
+ location = mrl_search_ip_country(mrl_instance.mrl_mmdb, ip_addr, mrl_instance.mrl_cfg.ip_location_level,mrl_instance.mrl_cfg.ip_location_name);
if(location < 0)
{
MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_is_inside_ip","cur ip addr %s not exist in mmdb",ip_addr);