114 if (PQstatus(
conn) != CONNECTION_BAD) {
117 #ifdef HAVE_PGSQL_pg_encoding_to_char
124 pgerror = PQerrorMessage(
conn);
135 char buf[257], escapebuf[513], *
value;
151 if (strcmp(cur->
name,
"calldate") == 0 && !value) {
169 if (strcmp(cur->
name,
"start") == 0 || strcmp(cur->
name,
"calldate") == 0) {
170 if (strncmp(cur->
type,
"int", 3) == 0) {
173 }
else if (strncmp(cur->
type,
"float", 5) == 0) {
175 ast_str_append(&sql2, 0,
"%s%f", first ?
"" :
",", (
double)cdr->
start.tv_sec + (
double)cdr->
start.tv_usec / 1000000.0);
183 }
else if (strcmp(cur->
name,
"answer") == 0) {
184 if (strncmp(cur->
type,
"int", 3) == 0) {
187 }
else if (strncmp(cur->
type,
"float", 5) == 0) {
197 }
else if (strcmp(cur->
name,
"end") == 0) {
198 if (strncmp(cur->
type,
"int", 3) == 0) {
201 }
else if (strncmp(cur->
type,
"float", 5) == 0) {
203 ast_str_append(&sql2, 0,
"%s%f", first ?
"" :
",", (
double)cdr->
end.tv_sec + (
double)cdr->
end.tv_usec / 1000000.0);
211 }
else if (strcmp(cur->
name,
"duration") == 0 || strcmp(cur->
name,
"billsec") == 0) {
212 if (cur->
type[0] ==
'i') {
217 }
else if (strncmp(cur->
type,
"float", 5) == 0) {
227 }
else if (strcmp(cur->
name,
"disposition") == 0 || strcmp(cur->
name,
"amaflags") == 0) {
228 if (strncmp(cur->
type,
"int", 3) == 0) {
242 if (strncmp(cur->
type,
"int", 3) == 0) {
244 if (value && sscanf(value,
"%30lld", &whatever) == 1) {
251 }
else if (strncmp(cur->
type,
"float", 5) == 0) {
252 long double whatever;
253 if (value && sscanf(value,
"%30Lf", &whatever) == 1) {
263 PQescapeStringConn(
conn, escapebuf, value, strlen(value), NULL);
278 ast_debug(2,
"inserting a CDR record.\n");
283 if (PQstatus(
conn) == CONNECTION_OK) {
288 if (PQstatus(
conn) == CONNECTION_OK) {
292 pgerror = PQerrorMessage(
conn);
305 if (PQresultStatus(result) != PGRES_COMMAND_OK) {
306 pgerror = PQresultErrorMessage(result);
309 ast_log(
LOG_ERROR,
"Connection may have been lost... attempting to reconnect.\n");
311 if (PQstatus(
conn) == CONNECTION_OK) {
316 if (PQresultStatus(result) != PGRES_COMMAND_OK) {
317 pgerror = PQresultErrorMessage(result);
318 ast_log(
LOG_ERROR,
"HARD ERROR! Attempted reconnection failed. DROPPING CALL RECORD!\n");
static ast_mutex_t pgsql_lock
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
struct ast_str * ast_str_create(size_t init_len)
Create a malloc'ed dynamic length string.
#define ast_mutex_lock(a)
#define ast_verb(level,...)
void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur, int raw)
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
#define ast_debug(level,...)
Log a DEBUG message.
#define AST_RWLIST_TRAVERSE
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
struct sla_ringing_trunk * first
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
#define LENGTHEN_BUF1(size)
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
int64_t ast_tvdiff_us(struct timeval end, struct timeval start)
Computes the difference (in microseconds) between two struct timeval instances.
#define ast_mutex_unlock(a)
#define LENGTHEN_BUF2(size)