summaryrefslogtreecommitdiff
path: root/res
diff options
context:
space:
mode:
Diffstat (limited to 'res')
-rw-r--r--res/res_config_ldap.c25
-rw-r--r--res/res_config_pgsql.c24
2 files changed, 11 insertions, 38 deletions
diff --git a/res/res_config_ldap.c b/res/res_config_ldap.c
index 95eae29c1..845427379 100644
--- a/res/res_config_ldap.c
+++ b/res/res_config_ldap.c
@@ -1837,7 +1837,9 @@ static int ldap_reconnect(void)
*/
static char *realtime_ldap_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- char status[256], credentials[100] = "";
+ char status[256];
+ char credentials[100] = "";
+ char buf[362]; /* 256+100+" for "+NULL */
int ctimesec = time(NULL) - connect_time;
switch (cmd) {
@@ -1860,25 +1862,8 @@ static char *realtime_ldap_status(struct ast_cli_entry *e, int cmd, struct ast_c
if (!ast_strlen_zero(user))
snprintf(credentials, sizeof(credentials), " with username %s", user);
- if (ctimesec > 31536000) {
- ast_cli(a->fd, "%s%s for %d years, %d days, %d hours, %d minutes, %d seconds.\n",
- status, credentials, ctimesec / 31536000,
- (ctimesec % 31536000) / 86400, (ctimesec % 86400) / 3600,
- (ctimesec % 3600) / 60, ctimesec % 60);
- } else if (ctimesec > 86400) {
- ast_cli(a->fd, "%s%s for %d days, %d hours, %d minutes, %d seconds.\n",
- status, credentials, ctimesec / 86400, (ctimesec % 86400) / 3600,
- (ctimesec % 3600) / 60, ctimesec % 60);
- } else if (ctimesec > 3600) {
- ast_cli(a->fd, "%s%s for %d hours, %d minutes, %d seconds.\n",
- status, credentials, ctimesec / 3600, (ctimesec % 3600) / 60,
- ctimesec % 60);
- } else if (ctimesec > 60) {
- ast_cli(a->fd, "%s%s for %d minutes, %d seconds.\n", status, credentials,
- ctimesec / 60, ctimesec % 60);
- } else {
- ast_cli(a->fd, "%s%s for %d seconds.\n", status, credentials, ctimesec);
- }
+ snprintf(buf, sizeof(buf), "%s%s for ", status, credentials);
+ ast_cli_print_timestr_fromseconds(a->fd, ctimesec, buf);
return CLI_SUCCESS;
}
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);