Index: main/asterisk.c =================================================================== --- main/asterisk.c (revision 72757) +++ main/asterisk.c (working copy) @@ -2345,6 +2345,7 @@ struct ast_config *cfg; struct ast_variable *v; char *config = AST_CONFIG_FILE; + char hostname[MAXHOSTNAMELEN] = ""; if (ast_opt_override_config) { cfg = ast_config_load(ast_config_AST_CONFIG_FILE); @@ -2492,6 +2493,14 @@ ast_copy_string(ast_config_AST_RUN_GROUP, v->value, sizeof(ast_config_AST_RUN_GROUP)); } else if (!strcasecmp(v->name, "systemname")) { ast_copy_string(ast_config_AST_SYSTEM_NAME, v->value, sizeof(ast_config_AST_SYSTEM_NAME)); + } else if (!strcasecmp(v->name, "autosystemname")) { + if (ast_true(v->value)) { + if (gethostname(hostname, sizeof(hostname)-1)) { + ast_log(LOG_ERROR, "Cannot obtain hostname for this system. 'autosystemname' option disabled.\n"); + } else { + ast_copy_string(ast_config_AST_SYSTEM_NAME, hostname, sizeof(ast_config_AST_SYSTEM_NAME)); + } + } } else if (!strcasecmp(v->name, "languageprefix")) { ast_language_is_prefix = ast_true(v->value); } Index: cdr/cdr_pgsql.c =================================================================== --- cdr/cdr_pgsql.c (revision 72757) +++ cdr/cdr_pgsql.c (working copy) @@ -71,14 +71,18 @@ static int pgsql_log(struct ast_cdr *cdr) { struct tm tm; - char sqlcmd[2048] = "", timestr[128]; + char sqlcmd[2048] = "", startstr[128], answerstr[128], endstr[128]; char *pgerror; PGresult *result; ast_mutex_lock(&pgsql_lock); ast_localtime(&cdr->start.tv_sec, &tm, NULL); - strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm); + strftime(startstr, sizeof(startstr), DATE_FORMAT, &tm); + ast_localtime(&cdr->answer.tv_sec, &tm, NULL); + strftime(answerstr, sizeof(answerstr), DATE_FORMAT, &tm); + ast_localtime(&cdr->end.tv_sec, &tm, NULL); + strftime(endstr, sizeof(endstr), DATE_FORMAT, &tm); if ((!connected) && pghostname && pgdbuser && pgpassword && pgdbname) { conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword); @@ -124,11 +128,11 @@ if (option_debug > 1) ast_log(LOG_DEBUG, "cdr_pgsql: inserting a CDR record.\n"); - snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s (calldate,clid,src,dst,dcontext,channel,dstchannel," - "lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield) VALUES" - " ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%ld,%ld,'%s',%ld,'%s','%s','%s')", - table,timestr,clid,cdr->src, cdr->dst, dcontext,channel, dstchannel, lastapp, lastdata, - cdr->duration,cdr->billsec,ast_cdr_disp2str(cdr->disposition),cdr->amaflags, cdr->accountcode, uniqueid, userfield); + snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s (clid,src,dst,dcontext,channel,dstchannel," + "lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield,start,answer,end) VALUES" + " ('%s','%s','%s','%s', '%s','%s','%s','%s',%ld,%ld,'%s',%ld,'%s','%s','%s','%s','%s','%s')", + table,clid,cdr->src, cdr->dst, dcontext,channel, dstchannel, lastapp, lastdata, + cdr->duration,cdr->billsec,ast_cdr_disp2str(cdr->disposition),cdr->amaflags, cdr->accountcode, uniqueid, userfield,startstr,answerstr,endstr); if (option_debug > 2) ast_log(LOG_DEBUG, "cdr_pgsql: SQL command executed: %s\n",sqlcmd);