mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-18 18:58:22 +00:00
More from the resolve-shadow-warnings branch. This time the cdr/ directory.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@136300 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -191,8 +191,8 @@ static int load_config(void)
|
||||
*/
|
||||
for (var = ast_variable_browse(cfg, catg); var; var = var->next) {
|
||||
if (strncmp(var->name, "alias", 5) == 0 && strcasecmp(var->value, columnname) == 0) {
|
||||
char *tmp = ast_strdupa(var->name + 5);
|
||||
cdrvar = ast_strip(tmp);
|
||||
char *alias = ast_strdupa(var->name + 5);
|
||||
cdrvar = ast_strip(alias);
|
||||
ast_verb(3, "Found alias %s for column %s in %s@%s\n", cdrvar, columnname, tableptr->table, tableptr->connection);
|
||||
break;
|
||||
}
|
||||
|
@@ -178,7 +178,7 @@ static int append_int(char *buf, int s, size_t bufsize)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int append_date(char *buf, struct timeval tv, size_t bufsize)
|
||||
static int append_date(char *buf, struct timeval when, size_t bufsize)
|
||||
{
|
||||
char tmp[80] = "";
|
||||
struct ast_tm tm;
|
||||
@@ -186,12 +186,12 @@ static int append_date(char *buf, struct timeval tv, size_t bufsize)
|
||||
if (strlen(buf) > bufsize - 3)
|
||||
return -1;
|
||||
|
||||
if (ast_tvzero(tv)) {
|
||||
if (ast_tvzero(when)) {
|
||||
strncat(buf, ",", bufsize - strlen(buf) - 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ast_localtime(&tv, &tm, usegmtime ? "GMT" : NULL);
|
||||
ast_localtime(&when, &tm, usegmtime ? "GMT" : NULL);
|
||||
ast_strftime(tmp, sizeof(tmp), DATE_FORMAT, &tm);
|
||||
|
||||
return append_string(buf, tmp, bufsize);
|
||||
|
@@ -204,14 +204,14 @@ static int pgsql_log(struct ast_cdr *cdr)
|
||||
LENGTHEN_BUF2(12);
|
||||
lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "%s", value);
|
||||
} else if (strncmp(cur->type, "float", 5) == 0) {
|
||||
struct timeval *tv = cur->name[0] == 'd' ? &cdr->start : &cdr->answer;
|
||||
struct timeval *when = cur->name[0] == 'd' ? &cdr->start : &cdr->answer;
|
||||
LENGTHEN_BUF2(30);
|
||||
lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "%f", (double)cdr->end.tv_sec - tv->tv_sec + cdr->end.tv_usec / 1000000.0 - tv->tv_usec / 1000000.0);
|
||||
lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "%f", (double)cdr->end.tv_sec - when->tv_sec + cdr->end.tv_usec / 1000000.0 - when->tv_usec / 1000000.0);
|
||||
} else {
|
||||
/* Char field, probably */
|
||||
struct timeval *tv = cur->name[0] == 'd' ? &cdr->start : &cdr->answer;
|
||||
struct timeval *when = cur->name[0] == 'd' ? &cdr->start : &cdr->answer;
|
||||
LENGTHEN_BUF2(30);
|
||||
lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "'%f'", (double)cdr->end.tv_sec - tv->tv_sec + cdr->end.tv_usec / 1000000.0 - tv->tv_usec / 1000000.0);
|
||||
lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "'%f'", (double)cdr->end.tv_sec - when->tv_sec + cdr->end.tv_usec / 1000000.0 - when->tv_usec / 1000000.0);
|
||||
}
|
||||
} else if (strcmp(cur->name, "disposition") == 0 || strcmp(cur->name, "amaflags") == 0) {
|
||||
if (strncmp(cur->type, "int", 3) == 0) {
|
||||
@@ -321,7 +321,7 @@ static int pgsql_log(struct ast_cdr *cdr)
|
||||
|
||||
static int unload_module(void)
|
||||
{
|
||||
struct columns *cur;
|
||||
struct columns *current;
|
||||
ast_cdr_unregister(name);
|
||||
|
||||
/* Give all threads time to finish */
|
||||
@@ -342,8 +342,8 @@ static int unload_module(void)
|
||||
ast_free(table);
|
||||
|
||||
AST_RWLIST_WRLOCK(&psql_columns);
|
||||
while ((cur = AST_RWLIST_REMOVE_HEAD(&psql_columns, list))) {
|
||||
ast_free(cur);
|
||||
while ((current = AST_RWLIST_REMOVE_HEAD(&psql_columns, list))) {
|
||||
ast_free(current);
|
||||
}
|
||||
AST_RWLIST_UNLOCK(&psql_columns);
|
||||
|
||||
|
@@ -87,50 +87,50 @@ static struct ast_flags global_flags = { RADIUS_FLAG_USEGMTIME | RADIUS_FLAG_LOG
|
||||
|
||||
static rc_handle *rh = NULL;
|
||||
|
||||
static int build_radius_record(VALUE_PAIR **send, struct ast_cdr *cdr)
|
||||
static int build_radius_record(VALUE_PAIR **tosend, struct ast_cdr *cdr)
|
||||
{
|
||||
int recordtype = PW_STATUS_STOP;
|
||||
struct ast_tm tm;
|
||||
char timestr[128];
|
||||
char *tmp;
|
||||
|
||||
if (!rc_avpair_add(rh, send, PW_ACCT_STATUS_TYPE, &recordtype, 0, 0))
|
||||
if (!rc_avpair_add(rh, tosend, PW_ACCT_STATUS_TYPE, &recordtype, 0, 0))
|
||||
return -1;
|
||||
|
||||
/* Account code */
|
||||
if (!rc_avpair_add(rh, send, PW_AST_ACCT_CODE, &cdr->accountcode, strlen(cdr->accountcode), VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_ACCT_CODE, &cdr->accountcode, strlen(cdr->accountcode), VENDOR_CODE))
|
||||
return -1;
|
||||
|
||||
/* Source */
|
||||
if (!rc_avpair_add(rh, send, PW_AST_SRC, &cdr->src, strlen(cdr->src), VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_SRC, &cdr->src, strlen(cdr->src), VENDOR_CODE))
|
||||
return -1;
|
||||
|
||||
/* Destination */
|
||||
if (!rc_avpair_add(rh, send, PW_AST_DST, &cdr->dst, strlen(cdr->dst), VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_DST, &cdr->dst, strlen(cdr->dst), VENDOR_CODE))
|
||||
return -1;
|
||||
|
||||
/* Destination context */
|
||||
if (!rc_avpair_add(rh, send, PW_AST_DST_CTX, &cdr->dcontext, strlen(cdr->dcontext), VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_DST_CTX, &cdr->dcontext, strlen(cdr->dcontext), VENDOR_CODE))
|
||||
return -1;
|
||||
|
||||
/* Caller ID */
|
||||
if (!rc_avpair_add(rh, send, PW_AST_CLID, &cdr->clid, strlen(cdr->clid), VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_CLID, &cdr->clid, strlen(cdr->clid), VENDOR_CODE))
|
||||
return -1;
|
||||
|
||||
/* Channel */
|
||||
if (!rc_avpair_add(rh, send, PW_AST_CHAN, &cdr->channel, strlen(cdr->channel), VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_CHAN, &cdr->channel, strlen(cdr->channel), VENDOR_CODE))
|
||||
return -1;
|
||||
|
||||
/* Destination Channel */
|
||||
if (!rc_avpair_add(rh, send, PW_AST_DST_CHAN, &cdr->dstchannel, strlen(cdr->dstchannel), VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_DST_CHAN, &cdr->dstchannel, strlen(cdr->dstchannel), VENDOR_CODE))
|
||||
return -1;
|
||||
|
||||
/* Last Application */
|
||||
if (!rc_avpair_add(rh, send, PW_AST_LAST_APP, &cdr->lastapp, strlen(cdr->lastapp), VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_LAST_APP, &cdr->lastapp, strlen(cdr->lastapp), VENDOR_CODE))
|
||||
return -1;
|
||||
|
||||
/* Last Data */
|
||||
if (!rc_avpair_add(rh, send, PW_AST_LAST_DATA, &cdr->lastdata, strlen(cdr->lastdata), VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_LAST_DATA, &cdr->lastdata, strlen(cdr->lastdata), VENDOR_CODE))
|
||||
return -1;
|
||||
|
||||
|
||||
@@ -138,61 +138,61 @@ static int build_radius_record(VALUE_PAIR **send, struct ast_cdr *cdr)
|
||||
ast_strftime(timestr, sizeof(timestr), DATE_FORMAT,
|
||||
ast_localtime(&cdr->start, &tm,
|
||||
ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME) ? "GMT" : NULL));
|
||||
if (!rc_avpair_add(rh, send, PW_AST_START_TIME, timestr, strlen(timestr), VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_START_TIME, timestr, strlen(timestr), VENDOR_CODE))
|
||||
return -1;
|
||||
|
||||
/* Answer Time */
|
||||
ast_strftime(timestr, sizeof(timestr), DATE_FORMAT,
|
||||
ast_localtime(&cdr->answer, &tm,
|
||||
ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME) ? "GMT" : NULL));
|
||||
if (!rc_avpair_add(rh, send, PW_AST_ANSWER_TIME, timestr, strlen(timestr), VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_ANSWER_TIME, timestr, strlen(timestr), VENDOR_CODE))
|
||||
return -1;
|
||||
|
||||
/* End Time */
|
||||
ast_strftime(timestr, sizeof(timestr), DATE_FORMAT,
|
||||
ast_localtime(&cdr->end, &tm,
|
||||
ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME) ? "GMT" : NULL));
|
||||
if (!rc_avpair_add(rh, send, PW_AST_END_TIME, timestr, strlen(timestr), VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_END_TIME, timestr, strlen(timestr), VENDOR_CODE))
|
||||
return -1;
|
||||
|
||||
/* Duration */
|
||||
if (!rc_avpair_add(rh, send, PW_AST_DURATION, &cdr->duration, 0, VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_DURATION, &cdr->duration, 0, VENDOR_CODE))
|
||||
return -1;
|
||||
|
||||
/* Billable seconds */
|
||||
if (!rc_avpair_add(rh, send, PW_AST_BILL_SEC, &cdr->billsec, 0, VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_BILL_SEC, &cdr->billsec, 0, VENDOR_CODE))
|
||||
return -1;
|
||||
|
||||
/* Disposition */
|
||||
tmp = ast_cdr_disp2str(cdr->disposition);
|
||||
if (!rc_avpair_add(rh, send, PW_AST_DISPOSITION, tmp, strlen(tmp), VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_DISPOSITION, tmp, strlen(tmp), VENDOR_CODE))
|
||||
return -1;
|
||||
|
||||
/* AMA Flags */
|
||||
tmp = ast_cdr_flags2str(cdr->amaflags);
|
||||
if (!rc_avpair_add(rh, send, PW_AST_AMA_FLAGS, tmp, strlen(tmp), VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_AMA_FLAGS, tmp, strlen(tmp), VENDOR_CODE))
|
||||
return -1;
|
||||
|
||||
if (ast_test_flag(&global_flags, RADIUS_FLAG_LOGUNIQUEID)) {
|
||||
/* Unique ID */
|
||||
if (!rc_avpair_add(rh, send, PW_AST_UNIQUE_ID, &cdr->uniqueid, strlen(cdr->uniqueid), VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_UNIQUE_ID, &cdr->uniqueid, strlen(cdr->uniqueid), VENDOR_CODE))
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ast_test_flag(&global_flags, RADIUS_FLAG_LOGUSERFIELD)) {
|
||||
/* append the user field */
|
||||
if (!rc_avpair_add(rh, send, PW_AST_USER_FIELD, &cdr->userfield, strlen(cdr->userfield), VENDOR_CODE))
|
||||
if (!rc_avpair_add(rh, tosend, PW_AST_USER_FIELD, &cdr->userfield, strlen(cdr->userfield), VENDOR_CODE))
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Setting Acct-Session-Id & User-Name attributes for proper generation
|
||||
of Acct-Unique-Session-Id on server side */
|
||||
/* Channel */
|
||||
if (!rc_avpair_add(rh, send, PW_USER_NAME, &cdr->channel, strlen(cdr->channel), 0))
|
||||
if (!rc_avpair_add(rh, tosend, PW_USER_NAME, &cdr->channel, strlen(cdr->channel), 0))
|
||||
return -1;
|
||||
|
||||
/* Unique ID */
|
||||
if (!rc_avpair_add(rh, send, PW_ACCT_SESSION_ID, &cdr->uniqueid, strlen(cdr->uniqueid), 0))
|
||||
if (!rc_avpair_add(rh, tosend, PW_ACCT_SESSION_ID, &cdr->uniqueid, strlen(cdr->uniqueid), 0))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
@@ -201,14 +201,14 @@ static int build_radius_record(VALUE_PAIR **send, struct ast_cdr *cdr)
|
||||
static int radius_log(struct ast_cdr *cdr)
|
||||
{
|
||||
int result = ERROR_RC;
|
||||
VALUE_PAIR *send = NULL;
|
||||
VALUE_PAIR *tosend = NULL;
|
||||
|
||||
if (build_radius_record(&send, cdr)) {
|
||||
if (build_radius_record(&tosend, cdr)) {
|
||||
ast_debug(1, "Unable to create RADIUS record. CDR not recorded!\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
result = rc_acct(rh, 0, send);
|
||||
result = rc_acct(rh, 0, tosend);
|
||||
if (result != OK_RC)
|
||||
ast_log(LOG_ERROR, "Failed to record Radius CDR record!\n");
|
||||
|
||||
|
@@ -265,12 +265,12 @@ static char *anti_injection(const char *str, int len)
|
||||
return buf;
|
||||
}
|
||||
|
||||
static void get_date(char *dateField, size_t len, struct timeval tv)
|
||||
static void get_date(char *dateField, size_t len, struct timeval when)
|
||||
{
|
||||
/* To make sure we have date variable if not insert null to SQL */
|
||||
if (!ast_tvzero(tv)) {
|
||||
struct ast_tm tm;
|
||||
ast_localtime(&tv, &tm, NULL);
|
||||
ast_localtime(&when, &tm, NULL);
|
||||
ast_strftime(dateField, len, "'" DATE_FORMAT "'", &tm);
|
||||
} else {
|
||||
ast_copy_string(dateField, "null", len);
|
||||
|
Reference in New Issue
Block a user