diff --git a/cdr.c b/cdr.c index 36dd477..025fc93 100644 --- a/cdr.c +++ b/cdr.c @@ -196,6 +196,56 @@ static int cdr_parse_srcleg(char *srcleg, cdr_entry_t *cdr) g_strlcpy(cdr->source_cli, tmp2, sizeof(cdr->source_cli)); tmp2 = ++tmp1; + tmp1 = strchr(tmp2, MED_SEP); + if(tmp1 == NULL) + { + syslog(LOG_WARNING, "Call-Id '%s' has no separated source external subscriber id, '%s'", cdr->call_id, tmp2); + return -1; + } + *tmp1 = '\0'; + g_strlcpy(cdr->source_ext_subscriber_id, tmp2, sizeof(cdr->source_ext_subscriber_id)); + tmp2 = ++tmp1; + + tmp1 = strchr(tmp2, MED_SEP); + if(tmp1 == NULL) + { + syslog(LOG_WARNING, "Call-Id '%s' has no separated source external contract id, '%s'", cdr->call_id, tmp2); + return -1; + } + *tmp1 = '\0'; + g_strlcpy(cdr->source_ext_contract_id, tmp2, sizeof(cdr->source_ext_contract_id)); + tmp2 = ++tmp1; + + tmp1 = strchr(tmp2, MED_SEP); + if(tmp1 == NULL) + { + syslog(LOG_WARNING, "Call-Id '%s' has no separated source account id, '%s'", cdr->call_id, tmp2); + return -1; + } + *tmp1 = '\0'; + cdr->source_account_id = atoll(tmp2); + tmp2 = ++tmp1; + + tmp1 = strchr(tmp2, MED_SEP); + if(tmp1 == NULL) + { + syslog(LOG_WARNING, "Call-Id '%s' has no separated peer auth user, '%s'", cdr->call_id, tmp2); + return -1; + } + *tmp1 = '\0'; + g_strlcpy(cdr->peer_auth_user, tmp2, sizeof(cdr->peer_auth_user)); + tmp2 = ++tmp1; + + tmp1 = strchr(tmp2, MED_SEP); + if(tmp1 == NULL) + { + syslog(LOG_WARNING, "Call-Id '%s' has no separated peer auth realm, '%s'", cdr->call_id, tmp2); + return -1; + } + *tmp1 = '\0'; + g_strlcpy(cdr->peer_auth_realm, tmp2, sizeof(cdr->peer_auth_realm)); + tmp2 = ++tmp1; + tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { @@ -223,7 +273,37 @@ static int cdr_parse_dstleg(char *dstleg, cdr_entry_t *cdr) len = strlen(dstleg); tmp2 = dstleg; - + + tmp1 = strchr(tmp2, MED_SEP); + if(tmp1 == NULL) + { + syslog(LOG_WARNING, "Call-Id '%s' has no separated destination external subscriber id, '%s'", cdr->call_id, tmp2); + return -1; + } + *tmp1 = '\0'; + g_strlcpy(cdr->destination_ext_subscriber_id, tmp2, sizeof(cdr->destination_ext_subscriber_id)); + tmp2 = ++tmp1; + + tmp1 = strchr(tmp2, MED_SEP); + if(tmp1 == NULL) + { + syslog(LOG_WARNING, "Call-Id '%s' has no separated destination external contract id, '%s'", cdr->call_id, tmp2); + return -1; + } + *tmp1 = '\0'; + g_strlcpy(cdr->destination_ext_contract_id, tmp2, sizeof(cdr->destination_ext_contract_id)); + tmp2 = ++tmp1; + + tmp1 = strchr(tmp2, MED_SEP); + if(tmp1 == NULL) + { + syslog(LOG_WARNING, "Call-Id '%s' has no separated destination account id, '%s'", cdr->call_id, tmp2); + return -1; + } + *tmp1 = '\0'; + cdr->destination_account_id = atoll(tmp2); + tmp2 = ++tmp1; + tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { diff --git a/cdr.h b/cdr.h index 0f8fb16..a6692f0 100644 --- a/cdr.h +++ b/cdr.h @@ -20,7 +20,10 @@ typedef struct { char call_id[128]; char source_user_id[37]; + char source_ext_subscriber_id[256]; + char source_ext_contract_id[256]; char source_provider_id[256]; + u_int64_t source_account_id; char source_user[256]; char source_domain[256]; char source_cli[65]; @@ -28,6 +31,9 @@ typedef struct { char destination_user_id[37]; char destination_provider_id[256]; + char destination_ext_subscriber_id[256]; + char destination_ext_contract_id[256]; + u_int64_t destination_account_id; char destination_user[256]; char destination_domain[256]; char destination_user_in[256]; @@ -37,6 +43,9 @@ typedef struct { char call_type[8]; char call_status[16]; char call_code[4]; + + char peer_auth_user[256]; + char peer_auth_realm[256]; char start_time[32]; u_int32_t duration; diff --git a/debian/changelog b/debian/changelog index f669aca..b1916bb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +ngcp-mediator (1.3.0) unstable; urgency=low + + * Write source/destination external subscriber and contract ids, + internal account ids and peer auth user/realm to cdr table. + + -- Andreas Granig Thu, 21 Jul 2011 18:32:39 +0200 + ngcp-mediator (1.2.2) unstable; urgency=low * Use "mysql" instead of "$mysql" in LSB headers. diff --git a/medmysql.c b/medmysql.c index 299b07d..ed80947 100644 --- a/medmysql.c +++ b/medmysql.c @@ -318,11 +318,11 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, u_int64_t count, struct medmysql_ if (batches->cdrs.len == 0) { batches->cdrs.len = sprintf(batches->cdrs.str, "insert into cdr (id, update_time, " \ - "source_user_id, source_provider_id, source_user, source_domain, " \ + "source_user_id, source_provider_id, source_external_subscriber_id, source_external_contract_id, source_account_id, source_user, source_domain, " \ "source_cli, source_clir, "\ - "destination_user_id, destination_provider_id, destination_user, destination_domain, " \ + "destination_user_id, destination_provider_id, destination_external_subscriber_id, destination_external_contract_id, destination_account_id, destination_user, destination_domain, " \ "destination_user_in, destination_domain_in, destination_user_dialed, " \ - "call_type, call_status, call_code, start_time, duration, call_id, " \ + "peer_auth_user, peer_auth_realm, call_type, call_status, call_code, start_time, duration, call_id, " \ "carrier_cost, reseller_cost, customer_cost) values "); } @@ -332,17 +332,29 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, u_int64_t count, struct medmysql_ char str_carrier_cost[32] = ""; char str_reseller_cost[32] = ""; char str_customer_cost[32] = ""; + char str_source_accid[32] = ""; + char str_dest_accid[32] = ""; snprintf(str_source_clir, sizeof(str_source_clir), "%d", e->source_clir); snprintf(str_duration, sizeof(str_duration), "%d", e->duration); snprintf(str_carrier_cost, sizeof(str_carrier_cost), "%d", e->carrier_cost); snprintf(str_reseller_cost, sizeof(str_reseller_cost), "%d", e->reseller_cost); snprintf(str_customer_cost, sizeof(str_customer_cost), "%d", e->customer_cost); + snprintf(str_source_accid, sizeof(str_source_accid), "%d", e->source_account_id); + snprintf(str_dest_accid, sizeof(str_dest_accid), "%d", e->destination_account_id); CDRPRINT("(NULL, now(), '"); CDRESCAPE(e->source_user_id); CDRPRINT("','"); CDRESCAPE(e->source_provider_id); CDRPRINT("','"); + + CDRESCAPE(e->source_ext_subscriber_id); + CDRPRINT("','"); + CDRESCAPE(e->source_ext_contract_id); + CDRPRINT("',"); + CDRESCAPE(str_source_accid); + CDRPRINT(",'"); + CDRESCAPE(e->source_user); CDRPRINT("','"); CDRESCAPE(e->source_domain); @@ -355,6 +367,12 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, u_int64_t count, struct medmysql_ CDRPRINT("','"); CDRESCAPE(e->destination_provider_id); CDRPRINT("','"); + CDRESCAPE(e->destination_ext_subscriber_id); + CDRPRINT("','"); + CDRESCAPE(e->destination_ext_contract_id); + CDRPRINT("',"); + CDRESCAPE(str_dest_accid); + CDRPRINT(",'"); CDRESCAPE(e->destination_user); CDRPRINT("','"); CDRESCAPE(e->destination_domain); @@ -365,6 +383,10 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, u_int64_t count, struct medmysql_ CDRPRINT("','"); CDRESCAPE(e->destination_dialed); CDRPRINT("','"); + CDRESCAPE(e->peer_auth_user); + CDRPRINT("','"); + CDRESCAPE(e->peer_auth_realm); + CDRPRINT("','"); CDRESCAPE(e->call_type); CDRPRINT("','"); CDRESCAPE(e->call_status);