summaryrefslogtreecommitdiff
path: root/res/res_config_pgsql.c
diff options
context:
space:
mode:
authorRodrigo Ramírez Norambuena <a@rodrigoramirez.com>2016-02-18 01:58:01 -0300
committerRodrigo Ramírez Norambuena <a@rodrigoramirez.com>2016-03-07 03:42:18 -0300
commit0ec9fe54219f8ad8a1e2c6f0a17843dcf08b7451 (patch)
treec2607814027ff8a7c5c9c88b49542948003ec819 /res/res_config_pgsql.c
parent62282bb8ce15e3e70b3e2fd79834c02911b5f8ff (diff)
main/cli.c: Refactor function to print seconds formatted
Refactor and created function ast_cli_print_timestr_fromseconds to print seconds formatted: year(s) week(s) day(s) hour(s) second(s) This function now is used in addons/cdr_mysql.c,cdr_pgsql.c, main/cli.c, res_config_ldap.c, res_config_pgsql.c. Change-Id: Ibeb8634102cd11d3f8623398b279cb731bcde36c
Diffstat (limited to 'res/res_config_pgsql.c')
-rw-r--r--res/res_config_pgsql.c24
1 files changed, 6 insertions, 18 deletions
diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c
index 77c52aa0b..73f43ee2c 100644
--- a/res/res_config_pgsql.c
+++ b/res/res_config_pgsql.c
@@ -1574,7 +1574,9 @@ static char *handle_cli_realtime_pgsql_cache(struct ast_cli_entry *e, int cmd, s
static char *handle_cli_realtime_pgsql_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- char connection_info[256], credentials[100] = "";
+ char connection_info[256];
+ char credentials[100] = "";
+ char buf[376]; /* 256+100+"Connected to "+" for "+NULL */
int ctimesec = time(NULL) - connect_time;
switch (cmd) {
@@ -1601,24 +1603,10 @@ static char *handle_cli_realtime_pgsql_status(struct ast_cli_entry *e, int cmd,
if (!ast_strlen_zero(dbuser))
snprintf(credentials, sizeof(credentials), " with username %s", dbuser);
- if (pgsqlConn && PQstatus(pgsqlConn) == CONNECTION_OK) {
- if (ctimesec > 31536000)
- ast_cli(a->fd, "Connected to %s%s for %d years, %d days, %d hours, %d minutes, %d seconds.\n",
- connection_info, credentials, ctimesec / 31536000, (ctimesec % 31536000) / 86400,
- (ctimesec % 86400) / 3600, (ctimesec % 3600) / 60, ctimesec % 60);
- else if (ctimesec > 86400)
- ast_cli(a->fd, "Connected to %s%s for %d days, %d hours, %d minutes, %d seconds.\n", connection_info,
- credentials, ctimesec / 86400, (ctimesec % 86400) / 3600, (ctimesec % 3600) / 60,
- ctimesec % 60);
- else if (ctimesec > 3600)
- ast_cli(a->fd, "Connected to %s%s for %d hours, %d minutes, %d seconds.\n", connection_info, credentials,
- ctimesec / 3600, (ctimesec % 3600) / 60, ctimesec % 60);
- else if (ctimesec > 60)
- ast_cli(a->fd, "Connected to %s%s for %d minutes, %d seconds.\n", connection_info, credentials, ctimesec / 60,
- ctimesec % 60);
- else
- ast_cli(a->fd, "Connected to %s%s for %d seconds.\n", connection_info, credentials, ctimesec);
+ if (pgsqlConn && PQstatus(pgsqlConn) == CONNECTION_OK) {
+ snprintf(buf, sizeof(buf), "Connected to %s%s for ", connection_info, credentials);
+ ast_cli_print_timestr_fromseconds(a->fd, ctimesec, buf);
return CLI_SUCCESS;
} else {
ast_cli(a->fd, "Unable to connect %s%s\n", connection_info, credentials);