2 * Asterisk -- A telephony toolkit for Linux.
4 * Copyright (C) 1999-2005, Digium, Inc.
6 * Manuel Guesdon <mguesdon@oxymium.net> - Postgresql RealTime Driver Author/Adaptor
7 * Mark Spencer <markster@digium.com> - Asterisk Author
8 * Matthew Boehm <mboehm@cytelcom.com> - MySQL RealTime Driver Author
10 * res_config_pgsql.c <Postgresql plugin for RealTime configuration engine>
12 * v1.0 - (07-11-05) - Initial version based on res_config_mysql v2.0
17 * \brief Postgresql plugin for Asterisk RealTime Architecture
19 * \author Mark Spencer <markster@digium.com>
20 * \author Manuel Guesdon <mguesdon@oxymium.net> - Postgresql RealTime Driver Author/Adaptor
22 * \arg http://www.postgresql.org
26 <depend>pgsql</depend>
31 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
36 #include <libpq-fe.h> /* PostgreSQL */
38 #include "asterisk/file.h"
39 #include "asterisk/logger.h"
40 #include "asterisk/channel.h"
41 #include "asterisk/pbx.h"
42 #include "asterisk/config.h"
43 #include "asterisk/module.h"
44 #include "asterisk/lock.h"
45 #include "asterisk/options.h"
46 #include "asterisk/utils.h"
47 #include "asterisk/cli.h"
49 AST_MUTEX_DEFINE_STATIC(pgsql_lock);
51 #define RES_CONFIG_PGSQL_CONF "res_pgsql.conf"
53 PGconn *pgsqlConn = NULL;
55 #define MAX_DB_OPTION_SIZE 64
57 static char dbhost[MAX_DB_OPTION_SIZE] = "";
58 static char dbuser[MAX_DB_OPTION_SIZE] = "";
59 static char dbpass[MAX_DB_OPTION_SIZE] = "";
60 static char dbname[MAX_DB_OPTION_SIZE] = "";
61 static char dbsock[MAX_DB_OPTION_SIZE] = "";
62 static int dbport = 5432;
63 static time_t connect_time = 0;
65 static int parse_config(void);
66 static int pgsql_reconnect(const char *database);
67 static int realtime_pgsql_status(int fd, int argc, char **argv);
71 static char cli_realtime_pgsql_status_usage[] =
72 "Usage: realtime pgsql status\n"
73 " Shows connection information for the Postgresql RealTime driver\n";
75 static struct ast_cli_entry cli_realtime_pgsql_status = {
76 { "realtime", "pgsql", "status", NULL }, realtime_pgsql_status,
77 "Shows connection information for the Postgresql RealTime driver",
78 cli_realtime_pgsql_status_usage, NULL
81 static struct ast_variable *realtime_pgsql(const char *database, const char *table, va_list ap)
83 PGresult *result = NULL;
89 const char *newparam, *newval;
90 struct ast_variable *var = NULL, *prev = NULL;
93 ast_log(LOG_WARNING, "Postgresql RealTime: No table specified.\n");
97 /* Get the first parameter and first value in our list of passed paramater/value pairs */
98 newparam = va_arg(ap, const char *);
99 newval = va_arg(ap, const char *);
100 if (!newparam || !newval) {
102 "Postgresql RealTime: Realtime retrieval requires at least 1 parameter and 1 value to search on.\n");
110 /* Create the first part of the query using the first parameter/value pairs we just extracted
111 If there is only 1 set, then we have our query. Otherwise, loop thru the list and concat */
112 op = strchr(newparam, ' ') ? "" : " =";
114 snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE %s%s '%s'", table, newparam, op,
116 while ((newparam = va_arg(ap, const char *))) {
117 newval = va_arg(ap, const char *);
118 if (!strchr(newparam, ' '))
122 snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " AND %s%s '%s'", newparam,
127 /* We now have our complete statement; Lets connect to the server and execute it. */
128 ast_mutex_lock(&pgsql_lock);
129 if (!pgsql_reconnect(database)) {
130 ast_mutex_unlock(&pgsql_lock);
134 if (!(result = PQexec(pgsqlConn, sql))) {
136 "Postgresql RealTime: Failed to query database. Check debug for more info.\n");
137 ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
138 ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s\n",
139 PQerrorMessage(pgsqlConn));
140 ast_mutex_unlock(&pgsql_lock);
143 ExecStatusType result_status = PQresultStatus(result);
144 if (result_status != PGRES_COMMAND_OK
145 && result_status != PGRES_TUPLES_OK
146 && result_status != PGRES_NONFATAL_ERROR) {
148 "Postgresql RealTime: Failed to query database. Check debug for more info.\n");
149 ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
150 ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s (%s)\n",
151 PQresultErrorMessage(result), PQresStatus(result_status));
152 ast_mutex_unlock(&pgsql_lock);
157 ast_log(LOG_DEBUG, "1Postgresql RealTime: Result=%p Query: %s\n", result, sql);
159 if ((num_rows = PQntuples(result)) > 0) {
162 int numFields = PQnfields(result);
163 char **fieldnames = NULL;
165 ast_log(LOG_DEBUG, "Postgresql RealTime: Found %d rows.\n", num_rows);
167 if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) {
168 ast_mutex_unlock(&pgsql_lock);
172 for (i = 0; i < numFields; i++)
173 fieldnames[i] = PQfname(result, i);
174 for (rowIndex = 0; rowIndex < num_rows; rowIndex++) {
175 for (i = 0; i < numFields; i++) {
176 stringp = PQgetvalue(result, rowIndex, i);
178 chunk = strsep(&stringp, ";");
179 if (chunk && !ast_strlen_zero(ast_strip(chunk))) {
181 prev->next = ast_variable_new(fieldnames[i], chunk);
186 prev = var = ast_variable_new(fieldnames[i], chunk);
195 "Postgresql RealTime: Could not find any rows in table %s.\n", table);
198 ast_mutex_unlock(&pgsql_lock);
204 static struct ast_config *realtime_multi_pgsql(const char *database, const char *table, va_list ap)
206 PGresult *result = NULL;
209 const char *initfield = NULL;
213 const char *newparam, *newval;
214 struct ast_realloca ra;
215 struct ast_variable *var = NULL;
216 struct ast_config *cfg = NULL;
217 struct ast_category *cat = NULL;
220 ast_log(LOG_WARNING, "Postgresql RealTime: No table specified.\n");
224 memset(&ra, 0, sizeof(ra));
226 if (!(cfg = ast_config_new()))
229 /* Get the first parameter and first value in our list of passed paramater/value pairs */
230 newparam = va_arg(ap, const char *);
231 newval = va_arg(ap, const char *);
232 if (!newparam || !newval) {
234 "Postgresql RealTime: Realtime retrieval requires at least 1 parameter and 1 value to search on.\n");
242 initfield = ast_strdupa(newparam);
243 if ((op = strchr(initfield, ' '))) {
247 /* Create the first part of the query using the first parameter/value pairs we just extracted
248 If there is only 1 set, then we have our query. Otherwise, loop thru the list and concat */
250 if (!strchr(newparam, ' '))
255 snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE %s%s '%s'", table, newparam, op,
257 while ((newparam = va_arg(ap, const char *))) {
258 newval = va_arg(ap, const char *);
259 if (!strchr(newparam, ' '))
263 snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " AND %s%s '%s'", newparam,
268 snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " ORDER BY %s", initfield);
273 /* We now have our complete statement; Lets connect to the server and execute it. */
274 ast_mutex_lock(&pgsql_lock);
275 if (!pgsql_reconnect(database)) {
276 ast_mutex_unlock(&pgsql_lock);
280 if (!(result = PQexec(pgsqlConn, sql))) {
282 "Postgresql RealTime: Failed to query database. Check debug for more info.\n");
283 ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
284 ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s\n",
285 PQerrorMessage(pgsqlConn));
286 ast_mutex_unlock(&pgsql_lock);
289 ExecStatusType result_status = PQresultStatus(result);
290 if (result_status != PGRES_COMMAND_OK
291 && result_status != PGRES_TUPLES_OK
292 && result_status != PGRES_NONFATAL_ERROR) {
294 "Postgresql RealTime: Failed to query database. Check debug for more info.\n");
295 ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
296 ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s (%s)\n",
297 PQresultErrorMessage(result), PQresStatus(result_status));
298 ast_mutex_unlock(&pgsql_lock);
303 ast_log(LOG_DEBUG, "2Postgresql RealTime: Result=%p Query: %s\n", result, sql);
305 if ((num_rows = PQntuples(result)) > 0) {
306 int numFields = PQnfields(result);
309 char **fieldnames = NULL;
311 ast_log(LOG_DEBUG, "Postgresql RealTime: Found %d rows.\n", num_rows);
313 if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) {
314 ast_mutex_unlock(&pgsql_lock);
318 for (i = 0; i < numFields; i++)
319 fieldnames[i] = PQfname(result, i);
321 for (rowIndex = 0; rowIndex < num_rows; rowIndex++) {
323 if (!(cat = ast_category_new("")))
325 for (i = 0; i < numFields; i++) {
326 stringp = PQgetvalue(result, rowIndex, i);
328 chunk = strsep(&stringp, ";");
329 if (chunk && !ast_strlen_zero(ast_strip(chunk))) {
330 if (initfield && !strcmp(initfield, fieldnames[i])) {
331 ast_category_rename(cat, chunk);
333 var = ast_variable_new(fieldnames[i], chunk);
334 ast_variable_append(cat, var);
338 ast_category_append(cfg, cat);
343 "Postgresql RealTime: Could not find any rows in table %s.\n", table);
346 ast_mutex_unlock(&pgsql_lock);
352 static int update_pgsql(const char *database, const char *table, const char *keyfield,
353 const char *lookup, va_list ap)
355 PGresult *result = NULL;
358 const char *newparam, *newval;
361 ast_log(LOG_WARNING, "Postgresql RealTime: No table specified.\n");
365 /* Get the first parameter and first value in our list of passed paramater/value pairs */
366 newparam = va_arg(ap, const char *);
367 newval = va_arg(ap, const char *);
368 if (!newparam || !newval) {
370 "Postgresql RealTime: Realtime retrieval requires at least 1 parameter and 1 value to search on.\n");
378 /* Create the first part of the query using the first parameter/value pairs we just extracted
379 If there is only 1 set, then we have our query. Otherwise, loop thru the list and concat */
381 snprintf(sql, sizeof(sql), "UPDATE %s SET %s = '%s'", table, newparam, newval);
382 while ((newparam = va_arg(ap, const char *))) {
383 newval = va_arg(ap, const char *);
384 snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), ", %s = '%s'", newparam,
388 snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " WHERE %s = '%s'", keyfield,
391 ast_log(LOG_DEBUG, "Postgresql RealTime: Update SQL: %s\n", sql);
393 /* We now have our complete statement; Lets connect to the server and execute it. */
394 ast_mutex_lock(&pgsql_lock);
395 if (!pgsql_reconnect(database)) {
396 ast_mutex_unlock(&pgsql_lock);
400 if (!(result = PQexec(pgsqlConn, sql))) {
402 "Postgresql RealTime: Failed to query database. Check debug for more info.\n");
403 ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
404 ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s\n",
405 PQerrorMessage(pgsqlConn));
406 ast_mutex_unlock(&pgsql_lock);
409 ExecStatusType result_status = PQresultStatus(result);
410 if (result_status != PGRES_COMMAND_OK
411 && result_status != PGRES_TUPLES_OK
412 && result_status != PGRES_NONFATAL_ERROR) {
414 "Postgresql RealTime: Failed to query database. Check debug for more info.\n");
415 ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
416 ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s (%s)\n",
417 PQresultErrorMessage(result), PQresStatus(result_status));
418 ast_mutex_unlock(&pgsql_lock);
423 numrows = atoi(PQcmdTuples(result));
424 ast_mutex_unlock(&pgsql_lock);
426 ast_log(LOG_DEBUG, "Postgresql RealTime: Updated %d rows on table: %s\n", numrows,
429 /* From http://dev.pgsql.com/doc/pgsql/en/pgsql-affected-rows.html
430 * An integer greater than zero indicates the number of rows affected
431 * Zero indicates that no records were updated
432 * -1 indicates that the query returned an error (although, if the query failed, it should have been caught above.)
436 return (int) numrows;
441 static struct ast_config *config_pgsql(const char *database, const char *table,
442 const char *file, struct ast_config *cfg)
444 PGresult *result = NULL;
446 struct ast_variable *new_v;
447 struct ast_category *cur_cat = NULL;
450 int last_cat_metric = 0;
454 if (!file || !strcmp(file, RES_CONFIG_PGSQL_CONF)) {
455 ast_log(LOG_WARNING, "Postgresql RealTime: Cannot configure myself.\n");
459 snprintf(sql, sizeof(sql),
460 "SELECT category, var_name, var_val, cat_metric FROM %s WHERE filename='%s' and commented=0 ORDER BY filename, cat_metric desc, var_metric asc, category, var_name, var_val, id",
463 ast_log(LOG_DEBUG, "Postgresql RealTime: Static SQL: %s\n", sql);
465 /* We now have our complete statement; Lets connect to the server and execute it. */
466 ast_mutex_lock(&pgsql_lock);
467 if (!pgsql_reconnect(database)) {
468 ast_mutex_unlock(&pgsql_lock);
472 if (!(result = PQexec(pgsqlConn, sql))) {
474 "Postgresql RealTime: Failed to query database. Check debug for more info.\n");
475 ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
476 ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s\n",
477 PQerrorMessage(pgsqlConn));
478 ast_mutex_unlock(&pgsql_lock);
481 ExecStatusType result_status = PQresultStatus(result);
482 if (result_status != PGRES_COMMAND_OK
483 && result_status != PGRES_TUPLES_OK
484 && result_status != PGRES_NONFATAL_ERROR) {
486 "Postgresql RealTime: Failed to query database. Check debug for more info.\n");
487 ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
488 ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s (%s)\n",
489 PQresultErrorMessage(result), PQresStatus(result_status));
490 ast_mutex_unlock(&pgsql_lock);
495 if ((num_rows = PQntuples(result)) > 0) {
496 int numFields = PQnfields(result);
499 char **fieldnames = NULL;
501 ast_log(LOG_DEBUG, "Postgresql RealTime: Found %ld rows.\n", num_rows);
503 if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) {
504 ast_mutex_unlock(&pgsql_lock);
508 for (i = 0; i < numFields; i++)
509 fieldnames[i] = PQfname(result, i);
511 for (rowIndex = 0; rowIndex < num_rows; rowIndex++) {
512 char *field_category = PQgetvalue(result, rowIndex, 0);
513 char *field_var_name = PQgetvalue(result, rowIndex, 1);
514 char *field_var_val = PQgetvalue(result, rowIndex, 2);
515 char *field_cat_metric = PQgetvalue(result, rowIndex, 3);
516 if (!strcmp(field_var_name, "#include")) {
517 if (!ast_config_internal_load(field_var_val, cfg)) {
519 ast_mutex_unlock(&pgsql_lock);
525 if (strcmp(last, field_category) || last_cat_metric != atoi(field_cat_metric)) {
526 cur_cat = ast_category_new(field_category);
529 strcpy(last, field_category);
530 last_cat_metric = atoi(field_cat_metric);
531 ast_category_append(cfg, cur_cat);
533 new_v = ast_variable_new(field_var_name, field_var_val);
534 ast_variable_append(cur_cat, new_v);
538 "Postgresql RealTime: Could not find config '%s' in database.\n", file);
542 ast_mutex_unlock(&pgsql_lock);
547 static struct ast_config_engine pgsql_engine = {
549 .load_func = config_pgsql,
550 .realtime_func = realtime_pgsql,
551 .realtime_multi_func = realtime_multi_pgsql,
552 .update_func = update_pgsql
555 static int load_module(void *mod)
559 ast_mutex_lock(&pgsql_lock);
561 if (!pgsql_reconnect(NULL)) {
563 "Postgresql RealTime: Couldn't establish connection. Check debug.\n");
564 ast_log(LOG_DEBUG, "Postgresql RealTime: Cannot Connect: %s\n",
565 PQerrorMessage(pgsqlConn));
568 ast_config_engine_register(&pgsql_engine);
569 if (option_verbose) {
570 ast_verbose("Postgresql RealTime driver loaded.\n");
572 ast_cli_register(&cli_realtime_pgsql_status);
574 ast_mutex_unlock(&pgsql_lock);
579 static int unload_module(void *mod)
581 /* Aquire control before doing anything to the module itself. */
582 ast_mutex_lock(&pgsql_lock);
588 ast_cli_unregister(&cli_realtime_pgsql_status);
589 ast_config_engine_deregister(&pgsql_engine);
590 if (option_verbose) {
591 ast_verbose("Postgresql RealTime unloaded.\n");
594 STANDARD_HANGUP_LOCALUSERS;
596 /* Unlock so something else can destroy the lock. */
597 ast_mutex_unlock(&pgsql_lock);
602 static int reload(void *mod)
604 /* Aquire control before doing anything to the module itself. */
605 ast_mutex_lock(&pgsql_lock);
613 if (!pgsql_reconnect(NULL)) {
615 "Postgresql RealTime: Couldn't establish connection. Check debug.\n");
616 ast_log(LOG_DEBUG, "Postgresql RealTime: Cannot Connect: %s\n",
617 PQerrorMessage(pgsqlConn));
620 ast_verbose(VERBOSE_PREFIX_2 "Postgresql RealTime reloaded.\n");
622 /* Done reloading. Release lock so others can now use driver. */
623 ast_mutex_unlock(&pgsql_lock);
628 int parse_config(void)
630 struct ast_config *config;
633 config = ast_config_load(RES_CONFIG_PGSQL_CONF);
636 if (!(s = ast_variable_retrieve(config, "general", "dbuser"))) {
638 "Postgresql RealTime: No database user found, using 'asterisk' as default.\n");
639 strcpy(dbuser, "asterisk");
641 ast_copy_string(dbuser, s, sizeof(dbuser));
644 if (!(s = ast_variable_retrieve(config, "general", "dbpass"))) {
646 "Postgresql RealTime: No database password found, using 'asterisk' as default.\n");
647 strcpy(dbpass, "asterisk");
649 ast_copy_string(dbpass, s, sizeof(dbpass));
652 if (!(s = ast_variable_retrieve(config, "general", "dbhost"))) {
654 "Postgresql RealTime: No database host found, using localhost via socket.\n");
657 ast_copy_string(dbhost, s, sizeof(dbhost));
660 if (!(s = ast_variable_retrieve(config, "general", "dbname"))) {
662 "Postgresql RealTime: No database name found, using 'asterisk' as default.\n");
663 strcpy(dbname, "asterisk");
665 ast_copy_string(dbname, s, sizeof(dbname));
668 if (!(s = ast_variable_retrieve(config, "general", "dbport"))) {
670 "Postgresql RealTime: No database port found, using 5432 as default.\n");
676 if (dbhost && !(s = ast_variable_retrieve(config, "general", "dbsock"))) {
678 "Postgresql RealTime: No database socket found, using '/tmp/pgsql.sock' as default.\n");
679 strcpy(dbsock, "/tmp/pgsql.sock");
681 ast_copy_string(dbsock, s, sizeof(dbsock));
684 ast_config_destroy(config);
687 ast_log(LOG_DEBUG, "Postgresql RealTime Host: %s\n", dbhost);
688 ast_log(LOG_DEBUG, "Postgresql RealTime Port: %i\n", dbport);
690 ast_log(LOG_DEBUG, "Postgresql RealTime Socket: %s\n", dbsock);
692 ast_log(LOG_DEBUG, "Postgresql RealTime User: %s\n", dbuser);
693 ast_log(LOG_DEBUG, "Postgresql RealTime Password: %s\n", dbpass);
694 ast_log(LOG_DEBUG, "Postgresql RealTime DBName: %s\n", dbname);
699 static const char *description(void)
701 return "Postgresql RealTime Configuration Driver";
705 static const char *key(void)
707 return ASTERISK_GPL_KEY;
710 STD_MOD(MOD_0, reload, NULL, NULL);
712 static int pgsql_reconnect(const char *database)
714 char my_database[50];
716 ast_copy_string(my_database, S_OR(database, dbname), sizeof(my_database));
718 /* mutex lock should have been locked before calling this function. */
720 if (pgsqlConn && PQstatus(pgsqlConn) != CONNECTION_OK) {
725 if ((!pgsqlConn) && (dbhost || dbsock) && dbuser && dbpass && my_database) {
726 char *connInfo = NULL;
727 unsigned int size = 100 + strlen(dbhost)
730 + strlen(my_database);
732 if (!(connInfo = ast_malloc(size)))
735 sprintf(connInfo, "host=%s port=%d dbname=%s user=%s password=%s",
736 dbhost, dbport, my_database, dbuser, dbpass);
737 ast_log(LOG_DEBUG, "%u connInfo=%s\n", size, connInfo);
738 pgsqlConn = PQconnectdb(connInfo);
739 ast_log(LOG_DEBUG, "%u connInfo=%s\n", size, connInfo);
742 ast_log(LOG_DEBUG, "pgsqlConn=%p\n", pgsqlConn);
744 ast_log(LOG_DEBUG, "Postgresql RealTime: Successfully connected to database.\n");
745 connect_time = time(NULL);
749 "Postgresql RealTime: Failed to connect database server %s on %s. Check debug for more info.\n",
751 ast_log(LOG_DEBUG, "Postgresql RealTime: Cannot Connect: %s\n",
752 PQresultErrorMessage(NULL));
756 ast_log(LOG_DEBUG, "Postgresql RealTime: Everything is fine.\n");
761 static int realtime_pgsql_status(int fd, int argc, char **argv)
763 char status[256], status2[100] = "";
764 int ctime = time(NULL) - connect_time;
766 if (pgsqlConn && PQstatus(pgsqlConn) == CONNECTION_OK) {
768 snprintf(status, 255, "Connected to %s@%s, port %d", dbname, dbhost, dbport);
770 snprintf(status, 255, "Connected to %s on socket file %s", dbname, dbsock);
772 snprintf(status, 255, "Connected to %s@%s", dbname, dbhost);
775 if (dbuser && *dbuser) {
776 snprintf(status2, 99, " with username %s", dbuser);
779 if (ctime > 31536000) {
780 ast_cli(fd, "%s%s for %d years, %d days, %d hours, %d minutes, %d seconds.\n",
781 status, status2, ctime / 31536000, (ctime % 31536000) / 86400,
782 (ctime % 86400) / 3600, (ctime % 3600) / 60, ctime % 60);
783 } else if (ctime > 86400) {
784 ast_cli(fd, "%s%s for %d days, %d hours, %d minutes, %d seconds.\n", status,
785 status2, ctime / 86400, (ctime % 86400) / 3600, (ctime % 3600) / 60,
787 } else if (ctime > 3600) {
788 ast_cli(fd, "%s%s for %d hours, %d minutes, %d seconds.\n", status, status2,
789 ctime / 3600, (ctime % 3600) / 60, ctime % 60);
790 } else if (ctime > 60) {
791 ast_cli(fd, "%s%s for %d minutes, %d seconds.\n", status, status2, ctime / 60,
794 ast_cli(fd, "%s%s for %d seconds.\n", status, status2, ctime);
797 return RESULT_SUCCESS;
799 return RESULT_FAILURE;