MT#8195 use dst_leg peer id and lookup against peer group/contract ID

Squashed commit of the following:

commit e137454f9d871332ef055b3de8eb9c703caece03
Author: Richard Fuchs <rfuchs@sipwise.com>
Date:   Fri Jul 25 11:03:17 2014 -0400

    MT#8195 lookup peer host ID against peer group/contract ID

commit 47e3509e634d9892fc1e2bc8111df6a90416addc
Author: Richard Fuchs <rfuchs@sipwise.com>
Date:   Fri Jul 18 11:03:23 2014 -0400

    MT#8195 use dst_leg peer id
mr3.5.1
Richard Fuchs 12 years ago
parent e20c83f961
commit 71657dda3d

15
cdr.c

@ -388,12 +388,19 @@ static int cdr_parse_dstleg(char *dstleg, cdr_entry_t *cdr)
g_strlcpy(cdr->destination_user_in, tmp2, sizeof(cdr->destination_user_in));
tmp2 = ++tmp1;
if(len < tmp2 - dstleg + 1)
tmp1 = strchr(tmp2, MED_SEP);
if(tmp1 == NULL)
{
syslog(LOG_WARNING, "Call-Id '%s' has no separated incoming destination domain", cdr->call_id);
return -1;
}
*tmp1 = '\0';
g_strlcpy(cdr->destination_domain_in, tmp2, sizeof(cdr->destination_domain_in));
tmp2 = ++tmp1;
if(len < tmp2 - dstleg + 1)
return 0;
cdr->destination_lcr_id = atoll(tmp2);
return 0;
}
@ -569,6 +576,12 @@ void cdr_set_provider(cdr_entry_t *cdr)
g_strlcpy(cdr->destination_provider_id, "0", sizeof(cdr->destination_provider_id));
}
}
else if (cdr->destination_lcr_id) {
snprintf(cdr->destination_provider_id, sizeof(cdr->destination_provider_id),
"%llu", (unsigned long long) cdr->destination_lcr_id);
val = g_hash_table_lookup(med_peer_id_table, cdr->destination_provider_id);
g_strlcpy(cdr->destination_provider_id, val ? : "0", sizeof(cdr->destination_provider_id));
}
else if((val = g_hash_table_lookup(med_peer_ip_table, cdr->destination_domain)) != NULL)
{
g_strlcpy(cdr->destination_provider_id, val, sizeof(cdr->destination_provider_id));

@ -40,6 +40,7 @@ typedef struct {
char destination_user_in[256];
char destination_domain_in[256];
char destination_dialed[256];
u_int64_t destination_lcr_id;
char call_type[8];
char call_status[16];

@ -23,6 +23,7 @@ u_int64_t mediator_count = 0;
GHashTable *med_peer_ip_table = NULL;
GHashTable *med_peer_host_table = NULL;
GHashTable *med_peer_id_table = NULL;
GHashTable *med_uuid_table = NULL;
@ -31,9 +32,10 @@ static int mediator_load_maps()
{
med_peer_ip_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
med_peer_host_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
med_peer_id_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
med_uuid_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
if(medmysql_load_maps(med_peer_ip_table, med_peer_host_table))
if(medmysql_load_maps(med_peer_ip_table, med_peer_host_table, med_peer_id_table))
return -1;
if(medmysql_load_uuids(med_uuid_table))
return -1;
@ -54,11 +56,14 @@ static void mediator_destroy_maps()
g_hash_table_destroy(med_peer_ip_table);
if(med_peer_host_table)
g_hash_table_destroy(med_peer_host_table);
if(med_peer_id_table)
g_hash_table_destroy(med_peer_id_table);
if(med_uuid_table)
g_hash_table_destroy(med_uuid_table);
med_peer_ip_table = NULL;
med_peer_host_table = NULL;
med_peer_id_table = NULL;
med_uuid_table = NULL;
}
@ -69,6 +74,8 @@ static void mediator_print_maps()
g_hash_table_foreach(med_peer_ip_table, mediator_print_mapentry, NULL);
syslog(LOG_DEBUG, "Peer host map:");
g_hash_table_foreach(med_peer_host_table, mediator_print_mapentry, NULL);
syslog(LOG_DEBUG, "Peer ID map:");
g_hash_table_foreach(med_peer_id_table, mediator_print_mapentry, NULL);
syslog(LOG_DEBUG, "UUID map:");
g_hash_table_foreach(med_uuid_table, mediator_print_mapentry, NULL);
}

@ -75,6 +75,7 @@ typedef struct {
extern GHashTable *med_peer_host_table;
extern GHashTable *med_peer_ip_table;
extern GHashTable *med_peer_id_table;
extern GHashTable *med_uuid_table;

@ -13,7 +13,7 @@
"src_leg, dst_leg " \
"from acc where callid = '%s' order by time_hires asc"
#define MED_LOAD_PEER_QUERY "select h.ip, h.host, g.peering_contract_id " \
#define MED_LOAD_PEER_QUERY "select h.ip, h.host, g.peering_contract_id, h.id " \
"from provisioning.voip_peer_hosts h, provisioning.voip_peer_groups g " \
"where g.id = h.group_id"
#define MED_LOAD_UUID_QUERY "select vs.uuid, r.contract_id from billing.voip_subscribers vs, " \
@ -451,7 +451,7 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, u_int64_t count, struct medmysql_
}
/**********************************************************************/
int medmysql_load_maps(GHashTable *ip_table, GHashTable *host_table)
int medmysql_load_maps(GHashTable *ip_table, GHashTable *host_table, GHashTable *id_table)
{
MYSQL_RES *res;
MYSQL_ROW row;
@ -493,6 +493,8 @@ int medmysql_load_maps(GHashTable *ip_table, GHashTable *host_table)
else
g_hash_table_insert(host_table, strdup(row[1]), strdup(row[2]));
}
if (id_table)
g_hash_table_insert(id_table, strdup(row[3]), strdup(row[2]));
}
out:

@ -28,7 +28,7 @@ int medmysql_trash_entries(const char *callid, struct medmysql_batches *);
int medmysql_backup_entries(const char *callid, struct medmysql_batches *);
int medmysql_delete_entries(const char *callid, struct medmysql_batches *);
int medmysql_insert_cdrs(cdr_entry_t *records, u_int64_t count, struct medmysql_batches *);
int medmysql_load_maps(GHashTable *ip_table, GHashTable *host_table);
int medmysql_load_maps(GHashTable *ip_table, GHashTable *host_table, GHashTable *id_table);
int medmysql_load_uuids(GHashTable *uuid_table);
int medmysql_batch_start(struct medmysql_batches *);
int medmysql_batch_end(struct medmysql_batches *);

Loading…
Cancel
Save