Add CLI command "marko show birthday" to show "birthday information"
for Mark Spencers upcoming 30th birthday. To enable, run `make menuselect` and select the option MARKO_BDAY under Compiler Flags. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@58742 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
parent
5dc7f1d898
commit
6cce2f3311
|
@ -30,4 +30,7 @@
|
|||
<member name="LOADABLE_MODULES" displayname="Runtime module loading">
|
||||
<defaultenabled>yes</defaultenabled>
|
||||
</member>
|
||||
<member name="MARKO_BDAY" displayname="Enable Mark Spencer Birthday Edition">
|
||||
<defaultenabled>no</defaultenabled>
|
||||
</member>
|
||||
</category>
|
||||
|
|
|
@ -1416,6 +1416,12 @@ static const char version_help[] =
|
|||
"Usage: core show version\n"
|
||||
" Shows Asterisk version information.\n";
|
||||
|
||||
#if defined(MARKO_BDAY)
|
||||
static const char markobday_help[] =
|
||||
"Usage: marko show birthday\n"
|
||||
" Shows time until/since Mark Spencers 30th birthday.\n";
|
||||
#endif
|
||||
|
||||
static int handle_version(int fd, int argc, char *argv[])
|
||||
{
|
||||
if (argc != 3)
|
||||
|
@ -1426,6 +1432,73 @@ static int handle_version(int fd, int argc, char *argv[])
|
|||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
#if defined(MARKO_BDAY)
|
||||
static void print_markobdaystr(int fd, time_t timeval, const char *prefix)
|
||||
{
|
||||
int x; /* the main part - years, weeks, etc. */
|
||||
struct ast_str *out;
|
||||
|
||||
#define SECOND (1)
|
||||
#define MINUTE (SECOND*60)
|
||||
#define HOUR (MINUTE*60)
|
||||
#define DAY (HOUR*24)
|
||||
#define WEEK (DAY*7)
|
||||
#define YEAR (DAY*365)
|
||||
#define NEEDCOMMA(x) ((x)? ",": "") /* define if we need a comma */
|
||||
if (timeval < 0) /* invalid, nothing to show */
|
||||
return;
|
||||
|
||||
out = ast_str_alloca(256);
|
||||
if (timeval > YEAR) {
|
||||
x = (timeval / YEAR);
|
||||
timeval -= (x * YEAR);
|
||||
ast_str_append(&out, 0, "%d year%s%s ", x, ESS(x),NEEDCOMMA(timeval));
|
||||
}
|
||||
if (timeval > WEEK) {
|
||||
x = (timeval / WEEK);
|
||||
timeval -= (x * WEEK);
|
||||
ast_str_append(&out, 0, "%d week%s%s ", x, ESS(x),NEEDCOMMA(timeval));
|
||||
}
|
||||
if (timeval > DAY) {
|
||||
x = (timeval / DAY);
|
||||
timeval -= (x * DAY);
|
||||
ast_str_append(&out, 0, "%d day%s%s ", x, ESS(x),NEEDCOMMA(timeval));
|
||||
}
|
||||
if (timeval > HOUR) {
|
||||
x = (timeval / HOUR);
|
||||
timeval -= (x * HOUR);
|
||||
ast_str_append(&out, 0, "%d hour%s%s ", x, ESS(x),NEEDCOMMA(timeval));
|
||||
}
|
||||
if (timeval > MINUTE) {
|
||||
x = (timeval / MINUTE);
|
||||
timeval -= (x * MINUTE);
|
||||
ast_str_append(&out, 0, "%d minute%s%s ", x, ESS(x),NEEDCOMMA(timeval));
|
||||
}
|
||||
x = timeval;
|
||||
if (x > 0 || out->used == 0) /* 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, out->str);
|
||||
}
|
||||
|
||||
static int handle_markobday(int fd, int argc, char *argv[])
|
||||
{
|
||||
time_t markobdaystarttime = 1176008400; /* 2007-04-08 00:00:00 */
|
||||
time_t markobdayendtime = 1176094799; /* 2007-04-08 23:59:59 */
|
||||
time_t curtime;
|
||||
|
||||
curtime = time(NULL);
|
||||
if (markobdaystarttime && markobdayendtime) {
|
||||
if (curtime >= markobdaystarttime && curtime <= markobdayendtime)
|
||||
ast_cli(fd, "Happy 30th birthday Marko!\n");
|
||||
else if (curtime > markobdayendtime)
|
||||
print_markobdaystr(fd, curtime - markobdayendtime, "Time since Mark Spencers 30th birthday");
|
||||
else
|
||||
print_markobdaystr(fd, markobdaystarttime - curtime, "Time until Mark Spencers 30th birthday");
|
||||
}
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
static int handle_quit(int fd, int argc, char *argv[])
|
||||
{
|
||||
|
@ -1601,6 +1674,12 @@ static struct ast_cli_entry cli_asterisk[] = {
|
|||
handle_version, "Display version info",
|
||||
version_help },
|
||||
|
||||
#if defined(MARKO_BDAY)
|
||||
{ { "marko", "show", "birthday", NULL },
|
||||
handle_markobday, "Display time until/since Mark Spencers 30th birthday",
|
||||
markobday_help },
|
||||
#endif
|
||||
|
||||
{ { "!", NULL },
|
||||
handle_bang, "Execute a shell command",
|
||||
bang_help },
|
||||
|
@ -2162,6 +2241,10 @@ static void ast_remotecontrol(char * data)
|
|||
fdprint(ast_consock, tmp);
|
||||
snprintf(tmp, sizeof(tmp), "core set debug atleast %d", option_debug);
|
||||
fdprint(ast_consock, tmp);
|
||||
#if defined(MARKO_BDAY)
|
||||
snprintf(tmp, sizeof(tmp), "marko show birthday");
|
||||
fdprint(ast_consock, tmp);
|
||||
#endif
|
||||
if (ast_opt_mute) {
|
||||
snprintf(tmp, sizeof(tmp), "log and verbose output currently muted ('logger unmute' to unmute)");
|
||||
fdprint(ast_consock, tmp);
|
||||
|
|
Loading…
Reference in New Issue