| 31 | }; |
| 32 | |
| 33 | cripts::string |
| 34 | get_geo_string(const sockaddr *addr, Qualifiers q) |
| 35 | { |
| 36 | ink_release_assert(gMaxMindDB != nullptr); |
| 37 | ink_release_assert(addr != nullptr); |
| 38 | |
| 39 | cripts::string ret = "(unknown)"; |
| 40 | int mmdb_error; |
| 41 | |
| 42 | MMDB_lookup_result_s result = MMDB_lookup_sockaddr(gMaxMindDB, addr, &mmdb_error); |
| 43 | |
| 44 | if (MMDB_SUCCESS != mmdb_error) { |
| 45 | return ret; |
| 46 | } |
| 47 | |
| 48 | MMDB_entry_data_list_s *entry_data_list = nullptr; |
| 49 | if (!result.found_entry) { |
| 50 | return ret; |
| 51 | } |
| 52 | |
| 53 | int status = MMDB_get_entry_data_list(&result.entry, &entry_data_list); |
| 54 | if (MMDB_SUCCESS != status) { |
| 55 | return ret; |
| 56 | } |
| 57 | |
| 58 | if (entry_data_list == nullptr) { |
| 59 | return ret; |
| 60 | } |
| 61 | |
| 62 | const char *field_name; |
| 63 | switch (q) { |
| 64 | case GEO_QUAL_COUNTRY: |
| 65 | field_name = "country_code"; |
| 66 | break; |
| 67 | case GEO_QUAL_ASN_NAME: |
| 68 | field_name = "autonomous_system_organization"; |
| 69 | break; |
| 70 | default: |
| 71 | Error("Cripts: Unsupported field %d", q); |
| 72 | return ret; |
| 73 | break; |
| 74 | } |
| 75 | |
| 76 | MMDB_entry_data_s entry_data; |
| 77 | |
| 78 | status = MMDB_get_value(&result.entry, &entry_data, field_name, NULL); |
| 79 | if (MMDB_SUCCESS != status) { |
| 80 | return ret; |
| 81 | } |
| 82 | ret = cripts::string(entry_data.utf8_string, entry_data.data_size); |
| 83 | |
| 84 | if (nullptr != entry_data_list) { |
| 85 | MMDB_free_entry_data_list(entry_data_list); |
| 86 | } |
| 87 | |
| 88 | return ret; |
| 89 | } |
| 90 |
no test coverage detected