static char *cli_realtime_update(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int res = 0; switch (cmd) { case CLI_INIT: e->command = "realtime update"; e->usage = "Usage: realtime update <family> <colmatch> <valuematch> <colupdate> <newvalue>\n" " Update a single variable using the RealTime driver.\n" " You must supply a family name, a column to update on, a new value, column to match, and value to match.\n" " Ex: realtime update sipfriends name bobsphone port 4343\n" " will execute SQL as UPDATE sipfriends SET port = 4343 WHERE name = bobsphone\n"; return NULL; case CLI_GENERATE: return NULL; } if (a->argc < 7) return CLI_SHOWUSAGE; res = ast_update_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL); if (res < 0) { ast_cli(a->fd, "Failed to update. Check the debug log for possible SQL related entries.\n"); return CLI_FAILURE; } ast_cli(a->fd, "Updated %d RealTime record%s.\n", res, ESS(res)); return CLI_SUCCESS; }
static char *cli_realtime_update2(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int res = -1; switch (cmd) { case CLI_INIT: e->command = "realtime update2"; e->usage = "Usage: realtime update2 <family> <colmatch> <valuematch> [... <colmatch5> <valuematch5>] NULL <colupdate> <newvalue>\n" " Update a single variable, requiring one or more fields to match using the\n" " RealTime driver. You must supply a family name, a column to update, a new\n" " value, and at least one column and value to match.\n" " Ex: realtime update sipfriends name bobsphone ipaddr 127.0.0.1 NULL port 4343\n" " will execute SQL as\n" " UPDATE sipfriends SET port='4343' WHERE name='bobsphone' and ipaddr='127.0.0.1'\n"; return NULL; case CLI_GENERATE: return NULL; } if (a->argc < 7) return CLI_SHOWUSAGE; if (a->argc == 7) { res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], SENTINEL, a->argv[5], a->argv[6], SENTINEL); } else if (a->argc == 9) { res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL, a->argv[7], a->argv[8], SENTINEL); } else if (a->argc == 11) { res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], SENTINEL, a->argv[9], a->argv[10], SENTINEL); } else if (a->argc == 13) { res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], SENTINEL, a->argv[11], a->argv[12], SENTINEL); } else if (a->argc == 15) { res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], a->argv[11], a->argv[12], SENTINEL, a->argv[13], a->argv[14], SENTINEL); } else { return CLI_SHOWUSAGE; } if (res < 0) { ast_cli(a->fd, "Failed to update. Check the debug log for possible SQL related entries.\n"); return CLI_FAILURE; } ast_cli(a->fd, "Updated %d RealTime record%s.\n", res, ESS(res)); return CLI_SUCCESS; }
static char *cli_realtime_destroy(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int res = -1; switch (cmd) { case CLI_INIT: e->command = "realtime destroy"; e->usage = "Usage: realtime destroy <family> <colmatch1> <valuematch1> [<colmatch2> <valuematch2> [... <colmatch5> <valuematch5>]]\n" " Remove a stored row using the RealTime driver.\n" " You must supply a family name and name/value pairs (up to 5).\n"; return NULL; case CLI_GENERATE: return NULL; } if (a->argc < 5) { return CLI_SHOWUSAGE; } else if (a->argc == 5) { res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], SENTINEL); } else if (a->argc == 7) { res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL); } else if (a->argc == 9) { res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], SENTINEL); } else if (a->argc == 11) { res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], SENTINEL); } else if (a->argc == 13) { res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], a->argv[11], a->argv[12], SENTINEL); } else { return CLI_SHOWUSAGE; } if (res < 0) { ast_cli(a->fd, "Failed to remove record. Check the debug log for possible SQL related entries.\n"); return CLI_FAILURE; } ast_cli(a->fd, "Removed %d RealTime record%s.\n", res, ESS(res)); return CLI_SUCCESS; }
void isaac_tvelap(struct timeval timeval, int printsec, char *out) { int x; /* the main part - years, weeks, etc. */ char year[256] = "", week[256] = "", day[256] = "", hour[256] = "", minute[256] = ""; if (timeval.tv_sec < 0) /* invalid, nothing to show */ return; if (printsec) { /* plain seconds output */ sprintf(out, "%lu", (u_long) timeval.tv_sec); return; } if (timeval.tv_sec > YEAR) { x = (timeval.tv_sec / YEAR); timeval.tv_sec -= (x * YEAR); sprintf(year, " %d year%s%s", x, ESS(x), NEEDCOMMA(timeval.tv_sec)); } if (timeval.tv_sec > WEEK) { x = (timeval.tv_sec / WEEK); timeval.tv_sec -= (x * WEEK); sprintf(week, " %d week%s%s", x, ESS(x), NEEDCOMMA(timeval.tv_sec)); } if (timeval.tv_sec > DAY) { x = (timeval.tv_sec / DAY); timeval.tv_sec -= (x * DAY); sprintf(day, " %d day%s%s", x, ESS(x), NEEDCOMMA(timeval.tv_sec)); } if (timeval.tv_sec > HOUR) { x = (timeval.tv_sec / HOUR); timeval.tv_sec -= (x * HOUR); sprintf(hour, " %d hour%s%s", x, ESS(x), NEEDCOMMA(timeval.tv_sec)); } if (timeval.tv_sec > MINUTE) { x = (timeval.tv_sec / MINUTE); timeval.tv_sec -= (x * MINUTE); sprintf(minute, " %d minute%s%s", x, ESS(x), NEEDCOMMA(timeval.tv_sec)); } x = timeval.tv_sec; sprintf(out, "%s%s%s%s%s %d second%s ", year, week, day, hour, minute, x, ESS(x)); }
static char *format_uptimestr(time_t timeval) { int years = 0, weeks = 0, days = 0, hours = 0, mins = 0, secs = 0; char timestr[256]=""; int bytes = 0; int maxbytes = 0; int offset = 0; #define SECOND (1) #define MINUTE (SECOND*60) #define HOUR (MINUTE*60) #define DAY (HOUR*24) #define WEEK (DAY*7) #define YEAR (DAY*365) #define ESS(x) ((x == 1) ? "" : "s") maxbytes = sizeof(timestr); if (timeval < 0) return NULL; if (timeval > YEAR) { years = (timeval / YEAR); timeval -= (years * YEAR); if (years > 0) { snprintf(timestr + offset, maxbytes, "%d year%s, ", years, ESS(years)); bytes = strlen(timestr + offset); offset += bytes; maxbytes -= bytes; } } if (timeval > WEEK) { weeks = (timeval / WEEK); timeval -= (weeks * WEEK); if (weeks > 0) { snprintf(timestr + offset, maxbytes, "%d week%s, ", weeks, ESS(weeks)); bytes = strlen(timestr + offset); offset += bytes; maxbytes -= bytes; } } if (timeval > DAY) { days = (timeval / DAY); timeval -= (days * DAY); if (days > 0) { snprintf(timestr + offset, maxbytes, "%d day%s, ", days, ESS(days)); bytes = strlen(timestr + offset); offset += bytes; maxbytes -= bytes; } } if (timeval > HOUR) { hours = (timeval / HOUR); timeval -= (hours * HOUR); if (hours > 0) { snprintf(timestr + offset, maxbytes, "%d hour%s, ", hours, ESS(hours)); bytes = strlen(timestr + offset); offset += bytes; maxbytes -= bytes; } } if (timeval > MINUTE) { mins = (timeval / MINUTE); timeval -= (mins * MINUTE); if (mins > 0) { snprintf(timestr + offset, maxbytes, "%d minute%s, ", mins, ESS(mins)); bytes = strlen(timestr + offset); offset += bytes; maxbytes -= bytes; } } secs = timeval; if (secs > 0) { snprintf(timestr + offset, maxbytes, "%d second%s", secs, ESS(secs)); } return timestr ? strdup(timestr) : NULL; }