MT#9565 Populate src/dst gpp fields.

agranig/gpp
Andreas Granig 11 years ago
parent 7604dcec2c
commit 0b04da23e1

60
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)); g_strlcpy(cdr->source_ip, tmp2, sizeof(cdr->source_ip));
tmp2 = ++tmp1; 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); syslog(LOG_WARNING, "Call-Id '%s' has no separated init time, '%s'", cdr->call_id, tmp2);
return -1; return -1;
} }
*tmp1 = '\0';
cdr->init_time = g_strtod(tmp2, NULL); 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; 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)); g_strlcpy(cdr->destination_domain_in, tmp2, sizeof(cdr->destination_domain_in));
tmp2 = ++tmp1; tmp2 = ++tmp1;
if(len < tmp2 - dstleg + 1) tmp1 = strchr(tmp2, MED_SEP);
return 0; 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); 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; return 0;
} }

@ -29,6 +29,7 @@ typedef struct {
char source_cli[65]; char source_cli[65];
char source_ip[65]; char source_ip[65];
u_int8_t source_clir; u_int8_t source_clir;
char source_gpp[10][255];
char destination_user_id[37]; char destination_user_id[37];
char destination_provider_id[256]; char destination_provider_id[256];
@ -41,6 +42,7 @@ typedef struct {
char destination_domain_in[256]; char destination_domain_in[256];
char destination_dialed[256]; char destination_dialed[256];
u_int64_t destination_lcr_id; u_int64_t destination_lcr_id;
char destination_gpp[10][255];
char call_type[8]; char call_type[8];
char call_status[16]; char call_status[16];

@ -26,10 +26,10 @@ int daemonize()
close(fds); close(fds);
} }
fds = open("/dev/null", O_RDWR); /* stdin */ fds = open("/dev/null", O_RDWR); /* stdin */
dup(fds); /* stdout */ if(dup(fds) < 0) {}; /* stdout */
dup(fds); /* stderr */ if(dup(fds) < 0) {}; /* stderr */
umask(027); umask(027);
chdir("/"); if(chdir("/") < 0) {};
} }
return 0; return 0;

@ -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) int medmysql_insert_cdrs(cdr_entry_t *entries, u_int64_t count, struct medmysql_batches *batches)
{ {
u_int64_t i; u_int64_t i;
int gpp;
for(i = 0; i < count; ++i) 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, " \ "duration, call_id, " \
"source_carrier_cost, source_reseller_cost, source_customer_cost, " \ "source_carrier_cost, source_reseller_cost, source_customer_cost, " \
"destination_carrier_cost, destination_reseller_cost, destination_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]); 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); CDRESCAPE(str_dest_customer_cost);
CDRPRINT(","); CDRPRINT(",");
CDRESCAPE(str_split); 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("),"); CDRPRINT("),");
if (check_shutdown()) if (check_shutdown())

Loading…
Cancel
Save