From 0b04da23e1fa3f8300d46c6ed2fc7f9521f11cfd Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Tue, 14 Oct 2014 16:15:49 +0200 Subject: [PATCH] MT#9565 Populate src/dst gpp fields. --- cdr.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++--- cdr.h | 2 ++ daemonizer.c | 6 +++--- medmysql.c | 36 ++++++++++++++++++++++++++++++- 4 files changed, 97 insertions(+), 7 deletions(-) diff --git a/cdr.c b/cdr.c index 200b7ec..10f0bb4 100644 --- a/cdr.c +++ b/cdr.c @@ -280,12 +280,38 @@ static int cdr_parse_srcleg(char *srcleg, cdr_entry_t *cdr) g_strlcpy(cdr->source_ip, tmp2, sizeof(cdr->source_ip)); tmp2 = ++tmp1; - if(len < tmp2 - srcleg + 1) + tmp1 = strchr(tmp2, MED_SEP); + if(tmp1 == NULL) { syslog(LOG_WARNING, "Call-Id '%s' has no separated init time, '%s'", cdr->call_id, tmp2); return -1; } + *tmp1 = '\0'; cdr->init_time = g_strtod(tmp2, NULL); + tmp2 = ++tmp1; + + + if(len < tmp2 - srcleg + 1) + { + syslog(LOG_WARNING, "Call-Id '%s' has no separated source gpp, skipping those fields", cdr->call_id); + return 0; + } + else + { + int i; + for(i = 0; i < 10; ++i) + { + tmp1 = strchr(tmp2, MED_SEP); + if(tmp1 == NULL) + { + syslog(LOG_WARNING, "Call-Id '%s' has no separated source gpp %d, '%s'", cdr->call_id, i, tmp2); + return -1; + } + *tmp1 = '\0'; + g_strlcpy(cdr->source_gpp[i], tmp2, sizeof(cdr->source_gpp[i])); + tmp2 = ++tmp1; + } + } return 0; } @@ -398,9 +424,37 @@ static int cdr_parse_dstleg(char *dstleg, cdr_entry_t *cdr) g_strlcpy(cdr->destination_domain_in, tmp2, sizeof(cdr->destination_domain_in)); tmp2 = ++tmp1; - if(len < tmp2 - dstleg + 1) - return 0; + tmp1 = strchr(tmp2, MED_SEP); + if(tmp1 == NULL) + { + syslog(LOG_WARNING, "Call-Id '%s' has no separated lcr flags", cdr->call_id); + return -1; + } + *tmp1 = '\0'; cdr->destination_lcr_id = atoll(tmp2); + tmp2 = ++tmp1; + + if(len < tmp2 - dstleg + 1) + { + syslog(LOG_WARNING, "Call-Id '%s' has no separated destination gpp, skipping those fields", cdr->call_id); + return 0; + } + else + { + int i; + for(i = 0; i < 10; ++i) + { + tmp1 = strchr(tmp2, MED_SEP); + if(tmp1 == NULL) + { + syslog(LOG_WARNING, "Call-Id '%s' has no separated destination gpp %d, '%s'", cdr->call_id, i, tmp2); + return -1; + } + *tmp1 = '\0'; + g_strlcpy(cdr->destination_gpp[i], tmp2, sizeof(cdr->destination_gpp[i])); + tmp2 = ++tmp1; + } + } return 0; } diff --git a/cdr.h b/cdr.h index 0f6afdd..fada1b4 100644 --- a/cdr.h +++ b/cdr.h @@ -29,6 +29,7 @@ typedef struct { char source_cli[65]; char source_ip[65]; u_int8_t source_clir; + char source_gpp[10][255]; char destination_user_id[37]; char destination_provider_id[256]; @@ -41,6 +42,7 @@ typedef struct { char destination_domain_in[256]; char destination_dialed[256]; u_int64_t destination_lcr_id; + char destination_gpp[10][255]; char call_type[8]; char call_status[16]; diff --git a/daemonizer.c b/daemonizer.c index ff432f9..3ab16ae 100644 --- a/daemonizer.c +++ b/daemonizer.c @@ -26,10 +26,10 @@ int daemonize() close(fds); } fds = open("/dev/null", O_RDWR); /* stdin */ - dup(fds); /* stdout */ - dup(fds); /* stderr */ + if(dup(fds) < 0) {}; /* stdout */ + if(dup(fds) < 0) {}; /* stderr */ umask(027); - chdir("/"); + if(chdir("/") < 0) {}; } return 0; diff --git a/medmysql.c b/medmysql.c index 526ccc2..34b9c37 100644 --- a/medmysql.c +++ b/medmysql.c @@ -313,6 +313,7 @@ int medmysql_delete_entries(const char *callid, struct medmysql_batches *batches int medmysql_insert_cdrs(cdr_entry_t *entries, u_int64_t count, struct medmysql_batches *batches) { u_int64_t i; + int gpp; for(i = 0; i < count; ++i) { @@ -333,7 +334,12 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, u_int64_t count, struct medmysql_ "duration, call_id, " \ "source_carrier_cost, source_reseller_cost, source_customer_cost, " \ "destination_carrier_cost, destination_reseller_cost, destination_customer_cost, " \ - "split) values "); + "split, " \ + "source_gpp0, source_gpp1, source_gpp2, source_gpp3, source_gpp4, " \ + "source_gpp5, source_gpp6, source_gpp7, source_gpp8, source_gpp9, " \ + "destination_gpp0, destination_gpp1, destination_gpp2, destination_gpp3, destination_gpp4, " \ + "destination_gpp5, destination_gpp6, destination_gpp7, destination_gpp8, destination_gpp9, " \ + ") values "); } cdr_entry_t *e = &(entries[i]); @@ -438,6 +444,34 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, u_int64_t count, struct medmysql_ CDRESCAPE(str_dest_customer_cost); CDRPRINT(","); CDRESCAPE(str_split); + for(gpp = 0; gpp < 10; ++gpp) + { + if(strnlen(e->source_gpp[gpp], sizeof(e->source_gpp[gpp])) > 0) + { + CDRPRINT(",'"); + CDRESCAPE(e->source_gpp[gpp]); + CDRPRINT("'"); + } + else + { + CDRPRINT(",NULL"); + } + } + for(gpp = 0; gpp < 10; ++gpp) + { + if(strnlen(e->destination_gpp[gpp], sizeof(e->destination_gpp[gpp])) > 0) + { + CDRPRINT(",'"); + CDRESCAPE(e->destination_gpp[gpp]); + CDRPRINT("'"); + } + else + { + CDRPRINT(",NULL"); + } + } + + CDRPRINT("),"); if (check_shutdown())