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);
69 static const char cli_realtime_pgsql_status_usage[] =
70 "Usage: realtime pgsql status\n"
71 " Shows connection information for the Postgresql RealTime driver\n";
73 static struct ast_cli_entry cli_realtime[] = {
74 { { "realtime", "pgsql", "status", NULL },
75 realtime_pgsql_status, "Shows connection information for the Postgresql RealTime driver",
76 cli_realtime_pgsql_status_usage },
79 static struct ast_variable *realtime_pgsql(const char *database, const char *table, va_list ap)
81 PGresult *result = NULL;
87 const char *newparam, *newval;
88 struct ast_variable *var = NULL, *prev = NULL;
91 ast_log(LOG_WARNING, "Postgresql RealTime: No table specified.\n");
95 /* Get the first parameter and first value in our list of passed paramater/value pairs */
96 newparam = va_arg(ap, const char *);
97 newval = va_arg(ap, const char *);
98 if (!newparam || !newval) {
100 "Postgresql RealTime: Realtime retrieval requires at least 1 parameter and 1 value to search on.\n");
108 /* Create the first part of the query using the first parameter/value pairs we just extracted
109 If there is only 1 set, then we have our query. Otherwise, loop thru the list and concat */
110 op = strchr(newparam, ' ') ? "" : " =";
112 snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE %s%s '%s'", table, newparam, op,
114 while ((newparam = va_arg(ap, const char *))) {
115 newval = va_arg(ap, const char *);
116 if (!strchr(newparam, ' '))
120 snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " AND %s%s '%s'", newparam,
125 /* We now have our complete statement; Lets connect to the server and execute it. */
126 ast_mutex_lock(&pgsql_lock);
127 if (!pgsql_reconnect(database)) {
128 ast_mutex_unlock(&pgsql_lock);
132 if (!(result = PQexec(pgsqlConn, sql))) {
134 "Postgresql RealTime: Failed to query database. Check debug for more info.\n");
136 ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
137 ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s\n",
138 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");
150 ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
151 ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s (%s)\n",
152 PQresultErrorMessage(result), PQresStatus(result_status));
154 ast_mutex_unlock(&pgsql_lock);
160 ast_log(LOG_DEBUG, "1Postgresql RealTime: Result=%p Query: %s\n", result, sql);
162 if ((num_rows = PQntuples(result)) > 0) {
165 int numFields = PQnfields(result);
166 char **fieldnames = NULL;
169 ast_log(LOG_DEBUG, "Postgresql RealTime: Found %d rows.\n", num_rows);
171 if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) {
172 ast_mutex_unlock(&pgsql_lock);
176 for (i = 0; i < numFields; i++)
177 fieldnames[i] = PQfname(result, i);
178 for (rowIndex = 0; rowIndex < num_rows; rowIndex++) {
179 for (i = 0; i < numFields; i++) {
180 stringp = PQgetvalue(result, rowIndex, i);
182 chunk = strsep(&stringp, ";");
183 if (!ast_strlen_zero(ast_strip(chunk))) {
185 prev->next = ast_variable_new(fieldnames[i], chunk);
190 prev = var = ast_variable_new(fieldnames[i], chunk);
196 ast_free(fieldnames);
199 "Postgresql RealTime: Could not find any rows in table %s.\n", table);
202 ast_mutex_unlock(&pgsql_lock);
208 static struct ast_config *realtime_multi_pgsql(const char *database, const char *table, va_list ap)
210 PGresult *result = NULL;
213 const char *initfield = NULL;
217 const char *newparam, *newval;
218 struct ast_realloca ra;
219 struct ast_variable *var = NULL;
220 struct ast_config *cfg = NULL;
221 struct ast_category *cat = NULL;
224 ast_log(LOG_WARNING, "Postgresql RealTime: No table specified.\n");
228 memset(&ra, 0, sizeof(ra));
230 if (!(cfg = ast_config_new()))
233 /* Get the first parameter and first value in our list of passed paramater/value pairs */
234 newparam = va_arg(ap, const char *);
235 newval = va_arg(ap, const char *);
236 if (!newparam || !newval) {
238 "Postgresql RealTime: Realtime retrieval requires at least 1 parameter and 1 value to search on.\n");
246 initfield = ast_strdupa(newparam);
247 if ((op = strchr(initfield, ' '))) {
251 /* Create the first part of the query using the first parameter/value pairs we just extracted
252 If there is only 1 set, then we have our query. Otherwise, loop thru the list and concat */
254 if (!strchr(newparam, ' '))
259 snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE %s%s '%s'", table, newparam, op,
261 while ((newparam = va_arg(ap, const char *))) {
262 newval = va_arg(ap, const char *);
263 if (!strchr(newparam, ' '))
267 snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " AND %s%s '%s'", newparam,
272 snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " ORDER BY %s", initfield);
277 /* We now have our complete statement; Lets connect to the server and execute it. */
278 ast_mutex_lock(&pgsql_lock);
279 if (!pgsql_reconnect(database)) {
280 ast_mutex_unlock(&pgsql_lock);
284 if (!(result = PQexec(pgsqlConn, sql))) {
286 "Postgresql RealTime: Failed to query database. Check debug for more info.\n");
288 ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
289 ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s\n",
290 PQerrorMessage(pgsqlConn));
292 ast_mutex_unlock(&pgsql_lock);
295 ExecStatusType result_status = PQresultStatus(result);
296 if (result_status != PGRES_COMMAND_OK
297 && result_status != PGRES_TUPLES_OK
298 && result_status != PGRES_NONFATAL_ERROR) {
300 "Postgresql RealTime: Failed to query database. Check debug for more info.\n");
302 ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
303 ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s (%s)\n",
304 PQresultErrorMessage(result), PQresStatus(result_status));
306 ast_mutex_unlock(&pgsql_lock);
312 ast_log(LOG_DEBUG, "2Postgresql RealTime: Result=%p Query: %s\n", result, sql);
314 if ((num_rows = PQntuples(result)) > 0) {
315 int numFields = PQnfields(result);
318 char **fieldnames = NULL;
321 ast_log(LOG_DEBUG, "Postgresql RealTime: Found %d rows.\n", num_rows);
323 if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) {
324 ast_mutex_unlock(&pgsql_lock);
328 for (i = 0; i < numFields; i++)
329 fieldnames[i] = PQfname(result, i);
331 for (rowIndex = 0; rowIndex < num_rows; rowIndex++) {
333 if (!(cat = ast_category_new("")))
335 for (i = 0; i < numFields; i++) {
336 stringp = PQgetvalue(result, rowIndex, i);
338 chunk = strsep(&stringp, ";");
339 if (!ast_strlen_zero(ast_strip(chunk))) {
340 if (initfield && !strcmp(initfield, fieldnames[i])) {
341 ast_category_rename(cat, chunk);
343 var = ast_variable_new(fieldnames[i], chunk);
344 ast_variable_append(cat, var);
348 ast_category_append(cfg, cat);
350 ast_free(fieldnames);
353 "Postgresql RealTime: Could not find any rows in table %s.\n", table);
356 ast_mutex_unlock(&pgsql_lock);
362 static int update_pgsql(const char *database, const char *table, const char *keyfield,
363 const char *lookup, va_list ap)
365 PGresult *result = NULL;
368 const char *newparam, *newval;
371 ast_log(LOG_WARNING, "Postgresql RealTime: No table specified.\n");
375 /* Get the first parameter and first value in our list of passed paramater/value pairs */
376 newparam = va_arg(ap, const char *);
377 newval = va_arg(ap, const char *);
378 if (!newparam || !newval) {
380 "Postgresql RealTime: Realtime retrieval requires at least 1 parameter and 1 value to search on.\n");
388 /* Create the first part of the query using the first parameter/value pairs we just extracted
389 If there is only 1 set, then we have our query. Otherwise, loop thru the list and concat */
391 snprintf(sql, sizeof(sql), "UPDATE %s SET %s = '%s'", table, newparam, newval);
392 while ((newparam = va_arg(ap, const char *))) {
393 newval = va_arg(ap, const char *);
394 snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), ", %s = '%s'", newparam,
398 snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " WHERE %s = '%s'", keyfield,
402 ast_log(LOG_DEBUG, "Postgresql RealTime: Update SQL: %s\n", sql);
404 /* We now have our complete statement; Lets connect to the server and execute it. */
405 ast_mutex_lock(&pgsql_lock);
406 if (!pgsql_reconnect(database)) {
407 ast_mutex_unlock(&pgsql_lock);
411 if (!(result = PQexec(pgsqlConn, sql))) {
413 "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\n",
417 PQerrorMessage(pgsqlConn));
419 ast_mutex_unlock(&pgsql_lock);
422 ExecStatusType result_status = PQresultStatus(result);
423 if (result_status != PGRES_COMMAND_OK
424 && result_status != PGRES_TUPLES_OK
425 && result_status != PGRES_NONFATAL_ERROR) {
427 "Postgresql RealTime: Failed to query database. Check debug for more info.\n");
429 ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
430 ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s (%s)\n",
431 PQresultErrorMessage(result), PQresStatus(result_status));
433 ast_mutex_unlock(&pgsql_lock);
438 numrows = atoi(PQcmdTuples(result));
439 ast_mutex_unlock(&pgsql_lock);
442 ast_log(LOG_DEBUG, "Postgresql RealTime: Updated %d rows on table: %s\n", numrows,
445 /* From http://dev.pgsql.com/doc/pgsql/en/pgsql-affected-rows.html
446 * An integer greater than zero indicates the number of rows affected
447 * Zero indicates that no records were updated
448 * -1 indicates that the query returned an error (although, if the query failed, it should have been caught above.)
452 return (int) numrows;
457 static struct ast_config *config_pgsql(const char *database, const char *table,
458 const char *file, struct ast_config *cfg,
461 PGresult *result = NULL;
463 struct ast_variable *new_v;
464 struct ast_category *cur_cat = NULL;
465 char sqlbuf[1024] = "";
467 size_t sqlleft = sizeof(sqlbuf);
469 int last_cat_metric = 0;
473 if (!file || !strcmp(file, RES_CONFIG_PGSQL_CONF)) {
474 ast_log(LOG_WARNING, "Postgresql RealTime: Cannot configure myself.\n");
478 ast_build_string(&sql, &sqlleft, "SELECT category, var_name, var_val, cat_metric FROM %s ", table);
479 ast_build_string(&sql, &sqlleft, "WHERE filename='%s' and commented=0", file);
480 ast_build_string(&sql, &sqlleft, "ORDER BY cat_metric DESC, var_metric ASC, category, var_name ");
483 ast_log(LOG_DEBUG, "Postgresql RealTime: Static SQL: %s\n", sqlbuf);
485 /* We now have our complete statement; Lets connect to the server and execute it. */
486 ast_mutex_lock(&pgsql_lock);
487 if (!pgsql_reconnect(database)) {
488 ast_mutex_unlock(&pgsql_lock);
492 if (!(result = PQexec(pgsqlConn, sqlbuf))) {
494 "Postgresql RealTime: Failed to query database. Check debug for more info.\n");
496 ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
497 ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s\n",
498 PQerrorMessage(pgsqlConn));
500 ast_mutex_unlock(&pgsql_lock);
503 ExecStatusType result_status = PQresultStatus(result);
504 if (result_status != PGRES_COMMAND_OK
505 && result_status != PGRES_TUPLES_OK
506 && result_status != PGRES_NONFATAL_ERROR) {
508 "Postgresql RealTime: Failed to query database. Check debug for more info.\n");
510 ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
511 ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s (%s)\n",
512 PQresultErrorMessage(result), PQresStatus(result_status));
514 ast_mutex_unlock(&pgsql_lock);
519 if ((num_rows = PQntuples(result)) > 0) {
523 ast_log(LOG_DEBUG, "Postgresql RealTime: Found %ld rows.\n", num_rows);
525 for (rowIndex = 0; rowIndex < num_rows; rowIndex++) {
526 char *field_category = PQgetvalue(result, rowIndex, 0);
527 char *field_var_name = PQgetvalue(result, rowIndex, 1);
528 char *field_var_val = PQgetvalue(result, rowIndex, 2);
529 char *field_cat_metric = PQgetvalue(result, rowIndex, 3);
530 if (!strcmp(field_var_name, "#include")) {
531 if (!ast_config_internal_load(field_var_val, cfg, 0)) {
533 ast_mutex_unlock(&pgsql_lock);
539 if (strcmp(last, field_category) || last_cat_metric != atoi(field_cat_metric)) {
540 cur_cat = ast_category_new(field_category);
543 strcpy(last, field_category);
544 last_cat_metric = atoi(field_cat_metric);
545 ast_category_append(cfg, cur_cat);
547 new_v = ast_variable_new(field_var_name, field_var_val);
548 ast_variable_append(cur_cat, new_v);
552 "Postgresql RealTime: Could not find config '%s' in database.\n", file);
556 ast_mutex_unlock(&pgsql_lock);
561 static struct ast_config_engine pgsql_engine = {
563 .load_func = config_pgsql,
564 .realtime_func = realtime_pgsql,
565 .realtime_multi_func = realtime_multi_pgsql,
566 .update_func = update_pgsql
569 static int load_module(void)
572 return AST_MODULE_LOAD_DECLINE;
574 ast_mutex_lock(&pgsql_lock);
576 if (!pgsql_reconnect(NULL)) {
578 "Postgresql RealTime: Couldn't establish connection. Check debug.\n");
580 ast_log(LOG_DEBUG, "Postgresql RealTime: Cannot Connect: %s\n",
581 PQerrorMessage(pgsqlConn));
584 ast_config_engine_register(&pgsql_engine);
585 if (option_verbose) {
586 ast_verbose("Postgresql RealTime driver loaded.\n");
588 ast_cli_register_multiple(cli_realtime, sizeof(cli_realtime) / sizeof(struct ast_cli_entry));
590 ast_mutex_unlock(&pgsql_lock);
595 static int unload_module(void)
597 /* Aquire control before doing anything to the module itself. */
598 ast_mutex_lock(&pgsql_lock);
604 ast_cli_unregister_multiple(cli_realtime, sizeof(cli_realtime) / sizeof(struct ast_cli_entry));
605 ast_config_engine_deregister(&pgsql_engine);
606 if (option_verbose) {
607 ast_verbose("Postgresql RealTime unloaded.\n");
610 ast_module_user_hangup_all();
612 /* Unlock so something else can destroy the lock. */
613 ast_mutex_unlock(&pgsql_lock);
618 static int reload(void)
620 /* Aquire control before doing anything to the module itself. */
621 ast_mutex_lock(&pgsql_lock);
629 if (!pgsql_reconnect(NULL)) {
631 "Postgresql RealTime: Couldn't establish connection. Check debug.\n");
633 ast_log(LOG_DEBUG, "Postgresql RealTime: Cannot Connect: %s\n",
634 PQerrorMessage(pgsqlConn));
637 ast_verbose(VERBOSE_PREFIX_2 "Postgresql RealTime reloaded.\n");
639 /* Done reloading. Release lock so others can now use driver. */
640 ast_mutex_unlock(&pgsql_lock);
645 static int parse_config(void)
647 struct ast_config *config;
650 config = ast_config_load(RES_CONFIG_PGSQL_CONF);
653 ast_log(LOG_WARNING, "Unable to load config %s\n",RES_CONFIG_PGSQL_CONF);
656 if (!(s = ast_variable_retrieve(config, "general", "dbuser"))) {
658 "Postgresql RealTime: No database user found, using 'asterisk' as default.\n");
659 strcpy(dbuser, "asterisk");
661 ast_copy_string(dbuser, s, sizeof(dbuser));
664 if (!(s = ast_variable_retrieve(config, "general", "dbpass"))) {
666 "Postgresql RealTime: No database password found, using 'asterisk' as default.\n");
667 strcpy(dbpass, "asterisk");
669 ast_copy_string(dbpass, s, sizeof(dbpass));
672 if (!(s = ast_variable_retrieve(config, "general", "dbhost"))) {
674 "Postgresql RealTime: No database host found, using localhost via socket.\n");
677 ast_copy_string(dbhost, s, sizeof(dbhost));
680 if (!(s = ast_variable_retrieve(config, "general", "dbname"))) {
682 "Postgresql RealTime: No database name found, using 'asterisk' as default.\n");
683 strcpy(dbname, "asterisk");
685 ast_copy_string(dbname, s, sizeof(dbname));
688 if (!(s = ast_variable_retrieve(config, "general", "dbport"))) {
690 "Postgresql RealTime: No database port found, using 5432 as default.\n");
696 if (dbhost && !(s = ast_variable_retrieve(config, "general", "dbsock"))) {
698 "Postgresql RealTime: No database socket found, using '/tmp/pgsql.sock' as default.\n");
699 strcpy(dbsock, "/tmp/pgsql.sock");
701 ast_copy_string(dbsock, s, sizeof(dbsock));
703 ast_config_destroy(config);
707 ast_log(LOG_DEBUG, "Postgresql RealTime Host: %s\n", dbhost);
708 ast_log(LOG_DEBUG, "Postgresql RealTime Port: %i\n", dbport);
710 ast_log(LOG_DEBUG, "Postgresql RealTime Socket: %s\n", dbsock);
712 ast_log(LOG_DEBUG, "Postgresql RealTime User: %s\n", dbuser);
713 ast_log(LOG_DEBUG, "Postgresql RealTime Password: %s\n", dbpass);
714 ast_log(LOG_DEBUG, "Postgresql RealTime DBName: %s\n", dbname);
720 static int pgsql_reconnect(const char *database)
722 char my_database[50];
724 ast_copy_string(my_database, S_OR(database, dbname), sizeof(my_database));
726 /* mutex lock should have been locked before calling this function. */
728 if (pgsqlConn && PQstatus(pgsqlConn) != CONNECTION_OK) {
733 if ((!pgsqlConn) && (dbhost || dbsock) && dbuser && dbpass && my_database) {
734 char *connInfo = NULL;
735 unsigned int size = 100 + strlen(dbhost)
738 + strlen(my_database);
740 if (!(connInfo = ast_malloc(size)))
743 sprintf(connInfo, "host=%s port=%d dbname=%s user=%s password=%s",
744 dbhost, dbport, my_database, dbuser, dbpass);
746 ast_log(LOG_DEBUG, "%u connInfo=%s\n", size, connInfo);
747 pgsqlConn = PQconnectdb(connInfo);
749 ast_log(LOG_DEBUG, "%u connInfo=%s\n", size, connInfo);
753 ast_log(LOG_DEBUG, "pgsqlConn=%p\n", pgsqlConn);
754 if (pgsqlConn && PQstatus(pgsqlConn) == CONNECTION_OK) {
756 ast_log(LOG_DEBUG, "Postgresql RealTime: Successfully connected to database.\n");
757 connect_time = time(NULL);
761 "Postgresql RealTime: Failed to connect database server %s on %s. Check debug for more info.\n",
764 ast_log(LOG_DEBUG, "Postgresql RealTime: Cannot Connect: %s\n",
765 PQresultErrorMessage(NULL));
770 ast_log(LOG_DEBUG, "Postgresql RealTime: Everything is fine.\n");
775 static int realtime_pgsql_status(int fd, int argc, char **argv)
777 char status[256], status2[100] = "";
778 int ctime = time(NULL) - connect_time;
780 if (pgsqlConn && PQstatus(pgsqlConn) == CONNECTION_OK) {
782 snprintf(status, 255, "Connected to %s@%s, port %d", dbname, dbhost, dbport);
784 snprintf(status, 255, "Connected to %s on socket file %s", dbname, dbsock);
786 snprintf(status, 255, "Connected to %s@%s", dbname, dbhost);
789 if (dbuser && *dbuser) {
790 snprintf(status2, 99, " with username %s", dbuser);
793 if (ctime > 31536000) {
794 ast_cli(fd, "%s%s for %d years, %d days, %d hours, %d minutes, %d seconds.\n",
795 status, status2, ctime / 31536000, (ctime % 31536000) / 86400,
796 (ctime % 86400) / 3600, (ctime % 3600) / 60, ctime % 60);
797 } else if (ctime > 86400) {
798 ast_cli(fd, "%s%s for %d days, %d hours, %d minutes, %d seconds.\n", status,
799 status2, ctime / 86400, (ctime % 86400) / 3600, (ctime % 3600) / 60,
801 } else if (ctime > 3600) {
802 ast_cli(fd, "%s%s for %d hours, %d minutes, %d seconds.\n", status, status2,
803 ctime / 3600, (ctime % 3600) / 60, ctime % 60);
804 } else if (ctime > 60) {
805 ast_cli(fd, "%s%s for %d minutes, %d seconds.\n", status, status2, ctime / 60,
808 ast_cli(fd, "%s%s for %d seconds.\n", status, status2, ctime);
811 return RESULT_SUCCESS;
813 return RESULT_FAILURE;
817 /* needs usecount semantics defined */
818 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "PostgreSQL RealTime Configuration Driver",
820 .unload = unload_module,