return CLI_SHOWUSAGE;
if (connected) {
- char status[256], status2[100] = "";
+ char status[256];
+ char status2[100] = "";
+ char buf[362]; /* 256+100+" for "+NULL */
int ctime = time(NULL) - connect_time;
if (dbport)
snprintf(status, 255, "Connected to %s@%s, port %d", ast_str_buffer(dbname), ast_str_buffer(hostname), dbport);
snprintf(status2, 99, " with username %s", ast_str_buffer(dbuser));
if (ast_str_strlen(dbtable))
snprintf(status2, 99, " using table %s", ast_str_buffer(dbtable));
- if (ctime > 31536000) {
- ast_cli(a->fd, "%s%s for %d years, %d days, %d hours, %d minutes, %d seconds.\n", status, status2, ctime / 31536000, (ctime % 31536000) / 86400, (ctime % 86400) / 3600, (ctime % 3600) / 60, ctime % 60);
- } else if (ctime > 86400) {
- ast_cli(a->fd, "%s%s for %d days, %d hours, %d minutes, %d seconds.\n", status, status2, ctime / 86400, (ctime % 86400) / 3600, (ctime % 3600) / 60, ctime % 60);
- } else if (ctime > 3600) {
- ast_cli(a->fd, "%s%s for %d hours, %d minutes, %d seconds.\n", status, status2, ctime / 3600, (ctime % 3600) / 60, ctime % 60);
- } else if (ctime > 60) {
- ast_cli(a->fd, "%s%s for %d minutes, %d seconds.\n", status, status2, ctime / 60, ctime % 60);
- } else {
- ast_cli(a->fd, "%s%s for %d seconds.\n", status, status2, ctime);
- }
+
+ snprintf(buf, sizeof(buf), "%s%s for ", status, status2);
+ ast_cli_print_timestr_fromseconds(a->fd, ctime, buf);
+
if (records == totalrecords)
ast_cli(a->fd, " Wrote %d records since last restart.\n", totalrecords);
else
return CLI_SHOWUSAGE;
if (connected) {
- char status[256], status2[100] = "";
+ char status[256];
+ char status2[100] = "";
+ char buf[362]; /* 256+100+" for "+NULL */
int ctime = time(NULL) - connect_time;
if (pgdbport) {
if (table && *table) {
snprintf(status2, 99, " using table %s", table);
}
- if (ctime > 31536000) {
- ast_cli(a->fd, "%s%s for %d years, %d days, %d hours, %d minutes, %d seconds.\n", status, status2, ctime / 31536000, (ctime % 31536000) / 86400, (ctime % 86400) / 3600, (ctime % 3600) / 60, ctime % 60);
- } else if (ctime > 86400) {
- ast_cli(a->fd, "%s%s for %d days, %d hours, %d minutes, %d seconds.\n", status, status2, ctime / 86400, (ctime % 86400) / 3600, (ctime % 3600) / 60, ctime % 60);
- } else if (ctime > 3600) {
- ast_cli(a->fd, "%s%s for %d hours, %d minutes, %d seconds.\n", status, status2, ctime / 3600, (ctime % 3600) / 60, ctime % 60);
- } else if (ctime > 60) {
- ast_cli(a->fd, "%s%s for %d minutes, %d seconds.\n", status, status2, ctime / 60, ctime % 60);
- } else {
- ast_cli(a->fd, "%s%s for %d seconds.\n", status, status2, ctime);
- }
+
+ snprintf(buf, sizeof(buf), "%s%s for ", status, status2);
+ ast_cli_print_timestr_fromseconds(a->fd, ctime, buf);
+
if (records == totalrecords) {
ast_cli(a->fd, " Wrote %d records since last restart.\n", totalrecords);
} else {
*/
char *ast_complete_channels(const char *line, const char *word, int pos, int state, int rpos);
+/*!
+ * \since 13.8
+ * \brief Print on cli a duration in seconds in format
+ * %s year(s), %s week(s), %s day(s), %s hour(s), %s second(s)
+ *
+ * \param ast_cli_args fd to print by ast_cli
+ * \param duration The time (in seconds) to print
+ * \param prefix A Prefix string to add before of duration formatted
+ */
+void ast_cli_print_timestr_fromseconds(int fd, int seconds, const char *prefix);
+
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
return;
if (printsec) { /* plain seconds output */
- ast_cli(fd, "%s: %lu\n", prefix, (u_long)timeval.tv_sec);
+ ast_cli(fd, "%s%lu\n", prefix, (u_long)timeval.tv_sec);
return;
}
out = ast_str_alloca(256);
/* if there is nothing, print 0 seconds */
ast_str_append(&out, 0, "%d second%s", x, ESS(x));
}
- ast_cli(fd, "%s: %s\n", prefix, ast_str_buffer(out));
+ ast_cli(fd, "%s%s\n", prefix, ast_str_buffer(out));
}
static struct ast_cli_entry *cli_next(struct ast_cli_entry *e)
printsec = 0;
else
return CLI_SHOWUSAGE;
- if (ast_startuptime.tv_sec)
- print_uptimestr(a->fd, ast_tvsub(curtime, ast_startuptime), "System uptime", printsec);
- if (ast_lastreloadtime.tv_sec)
- print_uptimestr(a->fd, ast_tvsub(curtime, ast_lastreloadtime), "Last reload", printsec);
+ if (ast_startuptime.tv_sec) {
+ print_uptimestr(a->fd, ast_tvsub(curtime, ast_startuptime), "System uptime: ", printsec);
+ }
+ if (ast_lastreloadtime.tv_sec) {
+ print_uptimestr(a->fd, ast_tvsub(curtime, ast_lastreloadtime), "Last reload: ", printsec);
+ }
return CLI_SUCCESS;
}
ast_cli(a->fd, "%d call%s processed\n", ast_processed_calls(), ESS(ast_processed_calls()));
if (ast_startuptime.tv_sec && showuptime) {
- print_uptimestr(a->fd, ast_tvsub(curtime, ast_startuptime), "System uptime", printsec);
+ print_uptimestr(a->fd, ast_tvsub(curtime, ast_startuptime), "System uptime: ", printsec);
}
return RESULT_SUCCESS;
}
return count;
}
+
+void ast_cli_print_timestr_fromseconds(int fd, int seconds, const char *prefix)
+{
+ print_uptimestr(fd, ast_tv(seconds, 0), prefix, 0);
+}
*/
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) {
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;
}
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) {
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);