diff -Naur asterisk.old/apps/app_queue.c asterisk.new/apps/app_queue.c --- asterisk.old/apps/app_queue.c 2004-10-05 19:06:20.358704876 +0200 +++ asterisk.new/apps/app_queue.c 2004-10-05 19:51:27.357640634 +0200 @@ -1723,7 +1723,7 @@ if (!res) break; if (valid_exit(&qe, res)) { - ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%c|%d", res, qe.pos); + ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%d|%d", res, qe.pos); break; } } @@ -1757,7 +1757,7 @@ if (!qe.handled) ast_queue_log(queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start); } else if (res > 0) - ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%c|%d", res, qe.pos); + ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%d|%d", res, qe.pos); break; } @@ -1778,7 +1778,7 @@ break; } if (res && valid_exit(&qe, res)) { - ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%c|%d", res, qe.pos); + ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%d|%d", res, qe.pos); break; } /* exit after 'timeout' cycle if 'n' option enabled */ diff -Naur asterisk.old/logger.c asterisk.new/logger.c --- asterisk.old/logger.c 2004-10-05 19:06:20.365703516 +0200 +++ asterisk.new/logger.c 2004-10-05 19:26:13.100973686 +0200 @@ -48,6 +48,19 @@ #define MAX_MSG_QUEUE 200 +#define QUEUE_LOG_MYSQL + +#ifdef QUEUE_LOG_MYSQL +#include +AST_MUTEX_DEFINE_STATIC(mysql_lock); +static MYSQL *mysql; +static char mydbuser[120]; +static char mydbpass[120]; +static char mydbhost[120]; +static char mydbname[120]; +#define DATE_FORMAT "%Y-%m-%d %T" +#endif + static char dateformat[256] = "%b %e %T"; /* Original Asterisk Format */ AST_MUTEX_DEFINE_STATIC(msglist_lock); AST_MUTEX_DEFINE_STATIC(loglock); @@ -221,6 +234,22 @@ return; ast_mutex_lock(&loglock); + +#ifdef QUEUE_LOG_MYSQL + if ((s = ast_variable_retrieve(cfg, "general", "dbpass"))) { + strncpy(mydbpass, s, sizeof(mydbpass)-1); + } + if ((s = ast_variable_retrieve(cfg, "general", "dbuser"))) { + strncpy(mydbuser, s, sizeof(mydbuser)-1); + } + if ((s = ast_variable_retrieve(cfg, "general", "dbhost"))) { + strncpy(mydbhost, s, sizeof(mydbhost)-1); + } + if ((s = ast_variable_retrieve(cfg, "general", "dbname"))) { + strncpy(mydbname, s, sizeof(mydbname)-1); + } +#endif + if ((s = ast_variable_retrieve(cfg, "general", "appendhostname"))) { if(ast_true(s)) { if(gethostname(hostname, sizeof(hostname))) { @@ -245,6 +274,22 @@ var = var->next; } +#ifdef QUEUE_LOG_MYSQL + ast_mutex_lock(&mysql_lock); + if (!mysql && !ast_strlen_zero(mydbname)) { + mysql = mysql_init(NULL); + if (!mysql_real_connect(mysql, mydbhost[0] ? mydbhost : NULL, mydbuser, mydbpass, mydbname, 0, NULL, 0)) { + memset(mydbpass, '*', strlen(mydbpass)); + ast_log(LOG_WARNING, "Database connection for queue_log failed (db=%s, host=%s, user=%s, pass=%s)!\n", mydbname, mydbhost, mydbuser, mydbpass); + free(mysql); + mysql = NULL; + } else { + ast_verbose(VERBOSE_PREFIX_1, "Connected to database '%s' on '%s' as '%s'\n", mydbname, mydbhost, mydbuser); + } + } + ast_mutex_unlock(&mysql_lock); +#endif + ast_destroy(cfg); ast_mutex_unlock(&loglock); } @@ -256,14 +301,90 @@ { va_list ap; ast_mutex_lock(&qloglock); +#ifdef QUEUE_LOG_MYSQL + char sqlcmd[2048], timestr[128]; + time_t t; + struct tm tm; + struct timeval tv; + int d, counter; + char extra[200], *s, c; +#endif if (qlog) { va_start(ap, fmt); - fprintf(qlog, "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event); + fprintf(qlog, "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event); + ast_verbose(VERBOSE_PREFIX_1, "Logging this: %ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event); vfprintf(qlog, fmt, ap); fprintf(qlog, "\n"); va_end(ap); fflush(qlog); } + +#ifdef QUEUE_LOG_MYSQL + + if(mysql) { + + counter = 0; + memset(sqlcmd,0,2048); + gettimeofday(&tv,NULL); + t = tv.tv_sec; + localtime_r(&t,&tm); + strftime(timestr,128,DATE_FORMAT,&tm); + ast_mutex_lock(&mysql_lock); + + + + va_start(ap, fmt); + + memset(extra,0,200); + + /* + get the parameters string + */ + while(*fmt) { + switch(*fmt++) { + case '%': + break; + case 'l': + break; + case 's': + s = va_arg(ap, char *); + sprintf(extra,"%s, '%s' ", extra, s); + counter++; + break; + case 'd': + d = va_arg(ap, int); + sprintf(extra,"%s, '%d' ", extra, d); + counter++; + break; + case 'c': + c = va_arg(ap, char); + sprintf(extra,"%s, '%c' ", extra, c); + counter++; + break; + default: +// ast_log(LOG_ERROR, "Here it is the missing type: %c\n", *(fmt-1)); + } + } + + /* + add missing extra fields + */ + for(counter; counter < 3; counter++) { + sprintf(extra,"%s, '' ", extra); + } + + va_end(ap); + + sprintf(sqlcmd,"INSERT INTO queue_log (time, callid, queuename, agent, event, extra1, extra2, extra3) VALUES ('%s', '%s','%s','%s','%s'%s) ", timestr, callid, queuename, agent, event, extra); + ast_log(LOG_DEBUG, "This is the text of the query for queue_log %s\n", sqlcmd); + if (mysql_real_query(mysql,sqlcmd,strlen(sqlcmd))) { + ast_log(LOG_ERROR,"Failed to insert into database this query: %s .\n", sqlcmd); + } else { + } + } + ast_mutex_unlock(&mysql_lock); +#endif + ast_mutex_unlock(&qloglock); } diff -Naur asterisk.old/Makefile asterisk.new/Makefile --- asterisk.old/Makefile 2004-10-05 19:06:20.361704293 +0200 +++ asterisk.new/Makefile 2004-10-05 19:26:13.097974269 +0200 @@ -186,7 +186,7 @@ ifeq (${OSARCH},Linux) LIBS=-ldl -lpthread endif -LIBS+=-lncurses -lm +LIBS+=-lncurses -L/usr/lib/mysql -lmysqlclient -lm ifeq (${OSARCH},Linux) LIBS+=-lresolv #-lnjamd endif diff -Naur asterisk.old/.version asterisk.new/.version --- asterisk.old/.version 1970-01-01 01:00:00.000000000 +0100 +++ asterisk.new/.version 2004-10-05 19:26:13.396916172 +0200 @@ -0,0 +1 @@ +CVS-HEAD-10/05/04-19:07:43