Remove emem from GeoIP
Change-Id: Ifa96dc38a277b86c28f762489251dcc595afae67 Reviewed-on: https://code.wireshark.org/review/6603 Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
parent
86726f404a
commit
403be722ce
|
@ -608,7 +608,7 @@ add_geoip_info_entry(proto_tree *geoip_info_tree, proto_item *geoip_info_item, t
|
|||
guint dbnum;
|
||||
|
||||
for (dbnum = 0; dbnum < num_dbs; dbnum++) {
|
||||
const char *geoip_str = geoip_db_lookup_ipv4(dbnum, ip, NULL);
|
||||
char *geoip_str = geoip_db_lookup_ipv4(dbnum, ip, NULL);
|
||||
int db_type = geoip_db_type(dbnum);
|
||||
|
||||
int geoip_hf, geoip_local_hf;
|
||||
|
@ -674,6 +674,7 @@ add_geoip_info_entry(proto_tree *geoip_info_tree, proto_item *geoip_info_item, t
|
|||
item_cnt++;
|
||||
proto_item_append_text(geoip_info_item, "%s%s",
|
||||
plurality(item_cnt, "", ", "), geoip_str);
|
||||
wmem_free(NULL, geoip_str);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -644,7 +644,7 @@ add_geoip_info_entry(proto_tree *geoip_info_tree, proto_item *geoip_info_item, t
|
|||
guint dbnum;
|
||||
|
||||
for (dbnum = 0; dbnum < num_dbs; dbnum++) {
|
||||
const char *geoip_str = geoip_db_lookup_ipv6(dbnum, *ip, NULL);
|
||||
char *geoip_str = geoip_db_lookup_ipv6(dbnum, *ip, NULL);
|
||||
int db_type = geoip_db_type(dbnum);
|
||||
|
||||
int geoip_hf, geoip_local_hf;
|
||||
|
@ -708,6 +708,7 @@ add_geoip_info_entry(proto_tree *geoip_info_tree, proto_item *geoip_info_item, t
|
|||
|
||||
item_cnt++;
|
||||
proto_item_append_text(geoip_info_item, "%s%s", plurality(item_cnt, "", ", "), geoip_str);
|
||||
wmem_free(NULL, geoip_str);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -290,30 +290,33 @@ geoip_db_lookup_latlon4(guint32 addr, float *lat, float *lon) {
|
|||
*/
|
||||
|
||||
/* Ensure that a given db value is UTF-8 */
|
||||
static const char *
|
||||
static char *
|
||||
db_val_to_utf_8(const char *val, GeoIP *gi) {
|
||||
|
||||
if (GeoIP_charset(gi) == GEOIP_CHARSET_ISO_8859_1) {
|
||||
char *utf8_val;
|
||||
utf8_val = g_convert(val, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
|
||||
if (utf8_val) {
|
||||
char *ret_val = ep_strdup(utf8_val);
|
||||
char *ret_val = wmem_strdup(NULL, utf8_val);
|
||||
g_free(utf8_val);
|
||||
return ret_val;
|
||||
}
|
||||
}
|
||||
return val;
|
||||
return wmem_strdup(NULL, val);
|
||||
}
|
||||
|
||||
const char *
|
||||
char *
|
||||
geoip_db_lookup_ipv4(guint dbnum, guint32 addr, const char *not_found) {
|
||||
GeoIP *gi;
|
||||
GeoIPRecord *gir;
|
||||
const char *raw_val, *ret = not_found;
|
||||
char *val;
|
||||
const char *raw_val;
|
||||
char *val, *ret = NULL;
|
||||
|
||||
if (dbnum > geoip_db_num_dbs()) {
|
||||
return ret;
|
||||
if (not_found == NULL)
|
||||
return NULL;
|
||||
|
||||
return wmem_strdup(NULL, not_found);
|
||||
}
|
||||
gi = g_array_index(geoip_dat_arr, GeoIP *, dbnum);
|
||||
if (gi) {
|
||||
|
@ -329,8 +332,9 @@ geoip_db_lookup_ipv4(guint dbnum, guint32 addr, const char *not_found) {
|
|||
case GEOIP_CITY_EDITION_REV1:
|
||||
gir = GeoIP_record_by_ipnum(gi, addr);
|
||||
if (gir && gir->city && gir->region) {
|
||||
val = ep_strdup_printf("%s, %s", gir->city, gir->region);
|
||||
val = wmem_strdup_printf(NULL, "%s, %s", gir->city, gir->region);
|
||||
ret = db_val_to_utf_8(val, gi);
|
||||
wmem_free(NULL, val);
|
||||
} else if (gir && gir->city) {
|
||||
ret = db_val_to_utf_8(gir->city, gi);
|
||||
}
|
||||
|
@ -351,7 +355,7 @@ geoip_db_lookup_ipv4(guint dbnum, guint32 addr, const char *not_found) {
|
|||
float lon;
|
||||
char *c;
|
||||
if(geoip_db_lookup_latlon4(addr, &lat, &lon) == 0) {
|
||||
val = ep_strdup_printf("%f", lat);
|
||||
val = wmem_strdup_printf(NULL, "%f", lat);
|
||||
c = strchr(val, ',');
|
||||
if (c != NULL) *c = '.';
|
||||
ret = val;
|
||||
|
@ -365,7 +369,7 @@ geoip_db_lookup_ipv4(guint dbnum, guint32 addr, const char *not_found) {
|
|||
float lon;
|
||||
char *c;
|
||||
if(geoip_db_lookup_latlon4(addr, &lat, &lon) == 0) {
|
||||
val = ep_strdup_printf("%f", lon);
|
||||
val = wmem_strdup_printf(NULL, "%f", lon);
|
||||
c = strchr(val, ',');
|
||||
if (c != NULL) *c = '.';
|
||||
ret = val;
|
||||
|
@ -377,6 +381,14 @@ geoip_db_lookup_ipv4(guint dbnum, guint32 addr, const char *not_found) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == NULL) {
|
||||
if (not_found == NULL)
|
||||
return NULL;
|
||||
|
||||
return wmem_strdup(NULL, not_found);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -417,17 +429,20 @@ geoip_db_lookup_latlon6(geoipv6_t addr _U_, float *lat _U_, float *lon _U_) {
|
|||
}
|
||||
#endif /* NUM_DB_TYPES */
|
||||
|
||||
const char *
|
||||
char *
|
||||
geoip_db_lookup_ipv6(guint dbnum, struct e_in6_addr addr, const char *not_found) {
|
||||
GeoIP *gi;
|
||||
geoipv6_t gaddr;
|
||||
const char *raw_val, *ret = not_found;
|
||||
char *val;
|
||||
const char *raw_val;
|
||||
char *val, *ret = NULL;
|
||||
#if NUM_DB_TYPES > 31
|
||||
GeoIPRecord *gir;
|
||||
#endif
|
||||
if (dbnum > geoip_db_num_dbs()) {
|
||||
return ret;
|
||||
if (not_found == NULL)
|
||||
return NULL;
|
||||
|
||||
return wmem_strdup(NULL, not_found);
|
||||
}
|
||||
|
||||
memcpy(&gaddr, &addr, sizeof(addr));
|
||||
|
@ -447,8 +462,9 @@ geoip_db_lookup_ipv6(guint dbnum, struct e_in6_addr addr, const char *not_found)
|
|||
case GEOIP_CITY_EDITION_REV1_V6:
|
||||
gir = GeoIP_record_by_ipnum_v6(gi, gaddr);
|
||||
if (gir && gir->city && gir->region) {
|
||||
val = ep_strdup_printf("%s, %s", gir->city, gir->region);
|
||||
val = wmem_strdup_printf(NULL, "%s, %s", gir->city, gir->region);
|
||||
ret = db_val_to_utf_8(val, gi);
|
||||
wmem_free(NULL, val);
|
||||
} else if (gir && gir->city) {
|
||||
ret = db_val_to_utf_8(gir->city, gi);
|
||||
}
|
||||
|
@ -470,7 +486,7 @@ geoip_db_lookup_ipv6(guint dbnum, struct e_in6_addr addr, const char *not_found)
|
|||
float lon;
|
||||
char *c;
|
||||
if(geoip_db_lookup_latlon6(gaddr, &lat, &lon) == 0) {
|
||||
val = ep_strdup_printf("%f", lat);
|
||||
val = wmem_strdup_printf(NULL, "%f", lat);
|
||||
c = strchr(val, ',');
|
||||
if (c != NULL) *c = '.';
|
||||
ret = val;
|
||||
|
@ -484,7 +500,7 @@ geoip_db_lookup_ipv6(guint dbnum, struct e_in6_addr addr, const char *not_found)
|
|||
float lon;
|
||||
char *c;
|
||||
if(geoip_db_lookup_latlon6(gaddr, &lat, &lon) == 0) {
|
||||
val = ep_strdup_printf("%f", lon);
|
||||
val = wmem_strdup_printf(NULL, "%f", lon);
|
||||
c = strchr(val, ',');
|
||||
if (c != NULL) *c = '.';
|
||||
ret = val;
|
||||
|
@ -496,14 +512,25 @@ geoip_db_lookup_ipv6(guint dbnum, struct e_in6_addr addr, const char *not_found)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == NULL) {
|
||||
if (not_found == NULL)
|
||||
return NULL;
|
||||
|
||||
return wmem_strdup(NULL, not_found);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else /* HAVE_GEOIP_V6 */
|
||||
|
||||
const char *
|
||||
char *
|
||||
geoip_db_lookup_ipv6(guint dbnum _U_, struct e_in6_addr addr _U_, const char *not_found) {
|
||||
return not_found;
|
||||
if (not_found == NULL)
|
||||
return NULL;
|
||||
|
||||
return wmem_strdup(NULL, not_found);
|
||||
}
|
||||
|
||||
#endif /* HAVE_GEOIP_V6 */
|
||||
|
@ -548,14 +575,20 @@ geoip_db_type(guint dbnum _U_) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
const char *
|
||||
char *
|
||||
geoip_db_lookup_ipv4(guint dbnum _U_, guint32 addr _U_, const char *not_found) {
|
||||
return not_found;
|
||||
if (not_found == NULL)
|
||||
return NULL;
|
||||
|
||||
return wmem_strdup(NULL, not_found);
|
||||
}
|
||||
|
||||
const char *
|
||||
char *
|
||||
geoip_db_lookup_ipv6(guint dbnum _U_, guint32 addr _U_, const char *not_found) {
|
||||
return not_found;
|
||||
if (not_found == NULL)
|
||||
return NULL;
|
||||
|
||||
return wmem_strdup(NULL, not_found);
|
||||
}
|
||||
|
||||
gchar *
|
||||
|
|
|
@ -74,9 +74,9 @@ WS_DLL_PUBLIC int geoip_db_type(guint dbnum);
|
|||
* @param addr IPv4 address to look up
|
||||
* @param not_found The string to return if the lookup fails. May be NULL.
|
||||
*
|
||||
* @return The database entry if found, else not_found. Return value must not be freed.
|
||||
* @return The database entry if found, else not_found. Return value must be freed with wmem_free.
|
||||
*/
|
||||
WS_DLL_PUBLIC const char *geoip_db_lookup_ipv4(guint dbnum, guint32 addr, const char *not_found);
|
||||
WS_DLL_PUBLIC char *geoip_db_lookup_ipv4(guint dbnum, guint32 addr, const char *not_found);
|
||||
|
||||
/**
|
||||
* Look up an IPv6 address in a database
|
||||
|
@ -85,9 +85,9 @@ WS_DLL_PUBLIC const char *geoip_db_lookup_ipv4(guint dbnum, guint32 addr, const
|
|||
* @param addr IPv6 address to look up
|
||||
* @param not_found The string to return if the lookup fails. May be NULL.
|
||||
*
|
||||
* @return The database entry if found, else not_found. Return value must not be freed.
|
||||
* @return The database entry if found, else not_found. Return value must be freed with wmem_free.
|
||||
*/
|
||||
WS_DLL_PUBLIC const char *geoip_db_lookup_ipv6(guint dbnum, struct e_in6_addr addr, const char *not_found);
|
||||
WS_DLL_PUBLIC char *geoip_db_lookup_ipv6(guint dbnum, struct e_in6_addr addr, const char *not_found);
|
||||
|
||||
/**
|
||||
* Get all configured paths
|
||||
|
|
|
@ -585,14 +585,16 @@ draw_hostlist_table_data(hostlist_table *hl)
|
|||
/* Filled in from the GeoIP config, if any */
|
||||
for (j = 0; j < ENDP_NUM_GEOIP_COLUMNS; j++) {
|
||||
if (host->myaddress.type == AT_IPv4 && j < geoip_db_num_dbs()) {
|
||||
const guchar *name = geoip_db_lookup_ipv4(j, pntoh32(host->myaddress.data), "-");
|
||||
guchar *name = geoip_db_lookup_ipv4(j, pntoh32(host->myaddress.data), "-");
|
||||
geoip[j] = g_strdup(name);
|
||||
wmem_free(NULL, name);
|
||||
} else if (host->myaddress.type == AT_IPv6 && j < geoip_db_num_dbs()) {
|
||||
const guchar *name;
|
||||
guchar *name;
|
||||
const struct e_in6_addr *addr = (const struct e_in6_addr *) host->myaddress.data;
|
||||
|
||||
name = geoip_db_lookup_ipv6(j, *addr, "-");
|
||||
geoip[j] = g_strdup(name);
|
||||
wmem_free(NULL, name);
|
||||
} else {
|
||||
geoip[j] = NULL;
|
||||
}
|
||||
|
|
|
@ -267,7 +267,7 @@ public:
|
|||
EndpointTreeWidget *ep_tree = qobject_cast<EndpointTreeWidget *>(treeWidget());
|
||||
if (ep_tree) {
|
||||
for (int col = ENDP_NUM_COLUMNS; col < ep_tree->columnCount(); col++) {
|
||||
const char *col_text = NULL;
|
||||
char *col_text = NULL;
|
||||
foreach (unsigned db, ep_tree->columnToDb(col)) {
|
||||
if (endp_item->myaddress.type == AT_IPv4) {
|
||||
col_text = geoip_db_lookup_ipv4(db, pntoh32(endp_item->myaddress.data), NULL);
|
||||
|
@ -280,6 +280,7 @@ public:
|
|||
}
|
||||
}
|
||||
setText(col, col_text ? col_text : geoip_none_);
|
||||
wmem_free(NULL, col_text);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -195,7 +195,7 @@ create_endpoint_geoip_map(const GArray *endp_array, gchar **err_str) {
|
|||
tpl_entry = g_string_new("");
|
||||
|
||||
for (i = 0; i < endp_array->len; i++) {
|
||||
const char *lat, *lon, *country, *city, *asn;
|
||||
char *lat = NULL, *lon = NULL, *country = NULL, *city = NULL, *asn = NULL;
|
||||
hostlist_talker_t *endp_item = &g_array_index(endp_array, hostlist_talker_t, i);
|
||||
|
||||
if (endp_item->myaddress.type == AT_IPv4) {
|
||||
|
@ -272,8 +272,13 @@ create_endpoint_geoip_map(const GArray *endp_array, gchar **err_str) {
|
|||
map_endpoint_opener = ",\n{\n";
|
||||
}
|
||||
|
||||
/* XXX Display an error if we we have no entries */
|
||||
wmem_free(NULL, lat);
|
||||
wmem_free(NULL, lon);
|
||||
wmem_free(NULL, country);
|
||||
wmem_free(NULL, city);
|
||||
wmem_free(NULL, asn);
|
||||
|
||||
/* XXX Display an error if we we have no entries */
|
||||
}
|
||||
|
||||
while (fgets(tpl_line, MAX_TPL_LINE_LEN, tpl_file) != NULL) {
|
||||
|
|
Loading…
Reference in New Issue