Newer
Older
while (i) {
/* find our switch */
if (!strcmp(i->name, sw) && !strcmp(i->data, data) &&
(!strcmp(i->registrar, registrar) || !registrar)) {
/* remove from list */
if (pi)
pi->next = i->next;
else
con->alts = i->next;
/* free switch and return */
free(i);
ast_mutex_unlock(&con->lock);
return 0;
}
pi = i;
i = i->next;
}
/* we can't find the right switch */
ast_mutex_unlock(&con->lock);
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
return -1;
}
/*
* This functions lock contexts list, search for the right context,
* call ast_context_remove_extension2, unlock contexts list and return.
* In this function we are using
*/
int ast_context_remove_extension(char *context, char *extension, int priority, char *registrar)
{
struct ast_context *c;
if (ast_lock_contexts()) return -1;
/* walk contexts ... */
c = ast_walk_contexts(NULL);
while (c) {
/* ... search for the right one ... */
if (!strcmp(ast_get_context_name(c), context)) {
/* ... remove extension ... */
int ret = ast_context_remove_extension2(c, extension, priority,
registrar);
/* ... unlock contexts list and return */
ast_unlock_contexts();
return ret;
}
c = ast_walk_contexts(c);
}
/* we can't find the right context */
ast_unlock_contexts();
return -1;
}
/*
* When do you want to call this function, make sure that &conlock is locked,
* because some process can handle with your *con context before you lock
* it.
*
* This functionc locks given context, search for the right extension and
* fires out all peer in this extensions with given priority. If priority
* is set to 0, all peers are removed. After that, unlock context and
* return.
*/
int ast_context_remove_extension2(struct ast_context *con, char *extension, int priority, char *registrar)
{
struct ast_exten *exten, *prev_exten = NULL;
if (ast_mutex_lock(&con->lock)) return -1;
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
/* go through all extensions in context and search the right one ... */
exten = con->root;
while (exten) {
/* look for right extension */
if (!strcmp(exten->exten, extension) &&
(!strcmp(exten->registrar, registrar) || !registrar)) {
struct ast_exten *peer;
/* should we free all peers in this extension? (priority == 0)? */
if (priority == 0) {
/* remove this extension from context list */
if (prev_exten)
prev_exten->next = exten->next;
else
con->root = exten->next;
/* fire out all peers */
peer = exten;
while (peer) {
exten = peer->peer;
if (!peer->priority==PRIORITY_HINT)
ast_remove_hint(peer);
peer->datad(peer->data);
free(peer);
peer = exten;
}
ast_mutex_unlock(&con->lock);
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
return 0;
} else {
/* remove only extension with exten->priority == priority */
struct ast_exten *previous_peer = NULL;
peer = exten;
while (peer) {
/* is this our extension? */
if (peer->priority == priority &&
(!strcmp(peer->registrar, registrar) || !registrar)) {
/* we are first priority extension? */
if (!previous_peer) {
/* exists previous extension here? */
if (prev_exten) {
/* yes, so we must change next pointer in
* previous connection to next peer
*/
if (peer->peer) {
prev_exten->next = peer->peer;
peer->peer->next = exten->next;
} else
prev_exten->next = exten->next;
} else {
/* no previous extension, we are first
* extension, so change con->root ...
*/
if (peer->peer)
con->root = peer->peer;
else
con->root = exten->next;
}
} else {
/* we are not first priority in extension */
previous_peer->peer = peer->peer;
}
/* now, free whole priority extension */
if (peer->priority==PRIORITY_HINT)
ast_remove_hint(peer);
ast_mutex_unlock(&con->lock);
return 0;
} else {
/* this is not right extension, skip to next peer */
previous_peer = peer;
peer = peer->peer;
}
}
ast_mutex_unlock(&con->lock);
return -1;
}
}
prev_exten = exten;
exten = exten->next;
}
/* we can't find right extension */
ast_mutex_unlock(&con->lock);
int ast_register_application(char *app, int (*execute)(struct ast_channel *, void *), char *synopsis, char *description)
Mark Spencer
committed
struct ast_app *tmp, *prev, *cur;
if (ast_mutex_lock(&applock)) {
ast_log(LOG_ERROR, "Unable to lock application list\n");
return -1;
}
tmp = apps;
while(tmp) {
if (!strcasecmp(app, tmp->name)) {
ast_log(LOG_WARNING, "Already have an application '%s'\n", app);
ast_mutex_unlock(&applock);
return -1;
}
tmp = tmp->next;
}
tmp = malloc(sizeof(struct ast_app));
if (tmp) {
tmp->synopsis = synopsis;
tmp->description = description;
Mark Spencer
committed
/* Store in alphabetical order */
cur = apps;
prev = NULL;
while(cur) {
if (strcasecmp(tmp->name, cur->name) < 0)
break;
prev = cur;
cur = cur->next;
}
if (prev) {
tmp->next = prev->next;
prev->next = tmp;
} else {
tmp->next = apps;
apps = tmp;
}
} else {
ast_log(LOG_WARNING, "Out of memory\n");
ast_mutex_unlock(&applock);
ast_verbose( VERBOSE_PREFIX_2 "Registered application '%s'\n", term_color(tmps, tmp->name, COLOR_BRCYAN, 0, sizeof(tmps)));
ast_mutex_unlock(&applock);
if (ast_mutex_lock(&switchlock)) {
ast_log(LOG_ERROR, "Unable to lock switch lock\n");
if (!strcasecmp(tmp->name, sw->name))
break;
prev = tmp;
ast_mutex_unlock(&switchlock);
ast_log(LOG_WARNING, "Switch '%s' already found\n", sw->name);
return -1;
}
sw->next = NULL;
if (prev)
prev->next = sw;
else
switches = sw;
ast_mutex_unlock(&switchlock);
void ast_unregister_switch(struct ast_switch *sw)
if (ast_mutex_lock(&switchlock)) {
ast_log(LOG_ERROR, "Unable to lock switch lock\n");
return;
if (tmp == sw) {
if (prev)
prev->next = tmp->next;
else
switches = tmp->next;
tmp->next = NULL;
break;
ast_mutex_unlock(&switchlock);
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
/*
* Help for CLI commands ...
*/
static char show_application_help[] =
"Usage: show application <application> [<application> [<application> [...]]]\n"
" Describes a particular application.\n";
static char show_applications_help[] =
"Usage: show applications\n"
" List applications which are currently available.\n";
static char show_dialplan_help[] =
"Usage: show dialplan [exten@][context]\n"
" Show dialplan\n";
static char show_switches_help[] =
"Usage: show switches\n"
" Show registered switches\n";
/*
* IMPLEMENTATION OF CLI FUNCTIONS IS IN THE SAME ORDER AS COMMANDS HELPS
*
*/
/*
* 'show application' CLI command implementation functions ...
*/
/*
* There is a possibility to show informations about more than one
* application at one time. You can type 'show application Dial Echo' and
* you will see informations about these two applications ...
*/
static char *complete_show_application(char *line, char *word,
int pos, int state)
if (ast_mutex_lock(&applock)) {
ast_log(LOG_ERROR, "Unable to lock application list\n");
/* ... walk all applications ... */
a = apps;
while (a) {
/* ... check if word matches this application ... */
if (!strncasecmp(word, a->name, strlen(word))) {
/* ... if this is right app serve it ... */
if (++which > state) {
char *ret = strdup(a->name);
ast_mutex_unlock(&applock);
ast_mutex_unlock(&applock);
}
static int handle_show_application(int fd, int argc, char *argv[])
{
int app, no_registered_app = 1;
if (argc < 3) return RESULT_SHOWUSAGE;
/* try to lock applications list ... */
if (ast_mutex_lock(&applock)) {
ast_log(LOG_ERROR, "Unable to lock application list\n");
return -1;
}
/* ... go through all applications ... */
a = apps;
while (a) {
/* ... compare this application name with all arguments given
* to 'show application' command ... */
for (app = 2; app < argc; app++) {
if (!strcasecmp(a->name, argv[app])) {
no_registered_app = 0;
/* ... one of our applications, show info ...*/
snprintf(buf, sizeof(buf),
"\n -= Info about application '%s' =- \n\n"
"[Synopsis]:\n %s\n\n"
"[Description]:\n%s\n",
a->name,
a->synopsis ? a->synopsis : "Not available",
a->description ? a-> description : "Not available");
ast_cli(fd, buf);
}
ast_mutex_unlock(&applock);
/* we found at least one app? no? */
if (no_registered_app) {
ast_cli(fd, "Your application(s) is (are) not registered\n");
return RESULT_FAILURE;
}
static int handle_show_switches(int fd, int argc, char *argv[])
struct ast_switch *sw;
if (!switches) {
ast_cli(fd, "There are no registered alternative switches\n");
return RESULT_SUCCESS;
}
/* ... we have applications ... */
ast_cli(fd, "\n -= Registered Asterisk Alternative Switches =-\n");
if (ast_mutex_lock(&switchlock)) {
ast_log(LOG_ERROR, "Unable to lock switches\n");
return -1;
}
sw = switches;
while (sw) {
ast_cli(fd, "%s: %s\n", sw->name, sw->description);
sw = sw->next;
}
ast_mutex_unlock(&switchlock);
return RESULT_SUCCESS;
}
/*
* 'show applications' CLI command implementation functions ...
*/
static int handle_show_applications(int fd, int argc, char *argv[])
{
struct ast_app *a;
/* try to lock applications list ... */
if (ast_mutex_lock(&applock)) {
ast_log(LOG_ERROR, "Unable to lock application list\n");
return -1;
}
/* ... go to first application ... */
a = apps;
/* ... have we got at least one application (first)? no? */
if (!a) {
ast_cli(fd, "There is no registered applications\n");
ast_mutex_unlock(&applock);
return -1;
}
/* ... we have applications ... */
ast_cli(fd, "\n -= Registered Asterisk Applications =-\n");
/* ... go through all applications ... */
while (a) {
/* ... show informations about applications ... */
ast_cli(fd," %15s: %s\n",
a->name,
a->synopsis ? a->synopsis : "<Synopsis not available>");
a = a->next;
}
/* ... unlock and return */
ast_mutex_unlock(&applock);
return RESULT_SUCCESS;
}
/*
* 'show dialplan' CLI command implementation functions ...
*/
static char *complete_show_dialplan_context(char *line, char *word, int pos,
int state)
{
struct ast_context *c;
int which = 0;
/* we are do completion of [exten@]context on second position only */
if (pos != 2) return NULL;
/* try to lock contexts list ... */
if (ast_lock_contexts()) {
ast_log(LOG_ERROR, "Unable to lock context list\n");
return NULL;
}
/* ... walk through all contexts ... */
c = ast_walk_contexts(NULL);
while(c) {
/* ... word matches context name? yes? ... */
if (!strncasecmp(word, ast_get_context_name(c), strlen(word))) {
/* ... for serve? ... */
if (++which > state) {
/* ... yes, serve this context name ... */
char *ret = strdup(ast_get_context_name(c));
ast_unlock_contexts();
return ret;
}
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
/* ... unlock and return */
ast_unlock_contexts();
return NULL;
}
static int handle_show_dialplan(int fd, int argc, char *argv[])
{
struct ast_context *c;
char *exten = NULL, *context = NULL;
int context_existence = 0, extension_existence = 0;
if (argc != 3 && argc != 2) return -1;
/* we obtain [exten@]context? if yes, split them ... */
if (argc == 3) {
char *splitter = argv[2];
/* is there a '@' character? */
if (strchr(argv[2], '@')) {
/* yes, split into exten & context ... */
exten = strsep(&splitter, "@");
context = splitter;
/* check for length and change to NULL if !strlen() */
if (!strlen(exten)) exten = NULL;
if (!strlen(context)) context = NULL;
} else
{
/* no '@' char, only context given */
context = argv[2];
if (!strlen(context)) context = NULL;
}
}
/* try to lock contexts */
if (ast_lock_contexts()) {
ast_log(LOG_WARNING, "Failed to lock contexts list\n");
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
return RESULT_FAILURE;
}
/* walk all contexts ... */
c = ast_walk_contexts(NULL);
while (c) {
/* show this context? */
if (!context ||
!strcmp(ast_get_context_name(c), context)) {
context_existence = 1;
/* try to lock context before walking in ... */
if (!ast_lock_context(c)) {
struct ast_exten *e;
struct ast_include *i;
struct ast_ignorepat *ip;
struct ast_sw *sw;
char buf[256], buf2[256];
int context_info_printed = 0;
/* are we looking for exten too? if yes, we print context
* if we our extension only
*/
if (!exten) {
ast_cli(fd, "[ Context '%s' created by '%s' ]\n",
ast_get_context_name(c), ast_get_context_registrar(c));
context_info_printed = 1;
}
/* walk extensions ... */
e = ast_walk_context_extensions(c, NULL);
while (e) {
struct ast_exten *p;
/* looking for extension? is this our extension? */
if (exten &&
strcmp(ast_get_extension_name(e), exten))
{
/* we are looking for extension and it's not our
* extension, so skip to next extension */
e = ast_walk_context_extensions(c, e);
continue;
}
extension_existence = 1;
/* may we print context info? */
if (!context_info_printed) {
ast_cli(fd, "[ Context '%s' created by '%s' ]\n",
ast_get_context_name(c),
ast_get_context_registrar(c));
context_info_printed = 1;
}
/* write extension name and first peer */
bzero(buf, sizeof(buf));
snprintf(buf, sizeof(buf), "'%s' =>",
ast_get_extension_name(e));
snprintf(buf2, sizeof(buf2),
"%d. %s(%s)",
ast_get_extension_priority(e),
ast_get_extension_app(e),
(char *)ast_get_extension_app_data(e));
ast_cli(fd, " %-17s %-45s [%s]\n", buf, buf2,
ast_get_extension_registrar(e));
/* walk next extension peers */
p = ast_walk_extension_priorities(e, e);
while (p) {
bzero((void *)buf2, sizeof(buf2));
snprintf(buf2, sizeof(buf2),
"%d. %s(%s)",
ast_get_extension_priority(p),
ast_get_extension_app(p),
(char *)ast_get_extension_app_data(p));
ast_cli(fd," %-17s %-45s [%s]\n",
"", buf2,
ast_get_extension_registrar(p));
p = ast_walk_extension_priorities(e, p);
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
/* include & ignorepat we all printing if we are not
* looking for exact extension
*/
if (!exten) {
if (ast_walk_context_extensions(c, NULL))
ast_cli(fd, "\n");
/* walk included and write info ... */
i = ast_walk_context_includes(c, NULL);
while (i) {
bzero(buf, sizeof(buf));
snprintf(buf, sizeof(buf), "'%s'",
ast_get_include_name(i));
ast_cli(fd, " Include => %-45s [%s]\n",
buf, ast_get_include_registrar(i));
i = ast_walk_context_includes(c, i);
}
/* walk ignore patterns and write info ... */
ip = ast_walk_context_ignorepats(c, NULL);
while (ip) {
bzero(buf, sizeof(buf));
snprintf(buf, sizeof(buf), "'%s'",
ast_get_ignorepat_name(ip));
ast_cli(fd, " Ignore pattern => %-45s [%s]\n",
buf, ast_get_ignorepat_registrar(ip));
ip = ast_walk_context_ignorepats(c, ip);
}
sw = ast_walk_context_switches(c, NULL);
while(sw) {
bzero(buf, sizeof(buf));
snprintf(buf, sizeof(buf), "'%s/%s'",
ast_get_switch_name(sw),
ast_get_switch_data(sw));
ast_cli(fd, " Alt. Switch => %-45s [%s]\n",
buf, ast_get_switch_registrar(sw));
sw = ast_walk_context_switches(c, sw);
}
}
ast_unlock_context(c);
/* if we print something in context, make an empty line */
if (context_info_printed) ast_cli(fd, "\n");
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
ast_unlock_contexts();
/* check for input failure and throw some error messages */
if (context && !context_existence) {
ast_cli(fd, "There is no existence of '%s' context\n",
context);
return RESULT_FAILURE;
}
if (exten && !extension_existence) {
if (context)
ast_cli(fd, "There is no existence of %s@%s extension\n",
exten, context);
else
ast_cli(fd,
"There is no existence of '%s' extension in all contexts\n",
exten);
return RESULT_FAILURE;
}
/* everything ok */
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
/*
* CLI entries for upper commands ...
*/
static struct ast_cli_entry show_applications_cli =
{ { "show", "applications", NULL },
handle_show_applications, "Shows registered applications",
show_applications_help };
static struct ast_cli_entry show_application_cli =
{ { "show", "application", NULL },
handle_show_application, "Describe a specific application",
show_application_help, complete_show_application };
static struct ast_cli_entry show_dialplan_cli =
{ { "show", "dialplan", NULL },
handle_show_dialplan, "Show dialplan",
show_dialplan_help, complete_show_dialplan_context };
static struct ast_cli_entry show_switches_cli =
{ { "show", "switches", NULL },
handle_show_switches, "Show alternative switches",
show_switches_help, NULL };
int ast_unregister_application(char *app) {
struct ast_app *tmp, *tmpl = NULL;
if (ast_mutex_lock(&applock)) {
ast_log(LOG_ERROR, "Unable to lock application list\n");
return -1;
}
tmp = apps;
while(tmp) {
if (!strcasecmp(app, tmp->name)) {
if (tmpl)
tmpl->next = tmp->next;
else
apps = tmp->next;
if (option_verbose > 1)
ast_verbose( VERBOSE_PREFIX_2 "Unregistered application '%s'\n", tmp->name);
ast_mutex_unlock(&applock);
return 0;
}
tmpl = tmp;
tmp = tmp->next;
}
ast_mutex_unlock(&applock);
struct ast_context *ast_context_create(struct ast_context **extcontexts, char *name, char *registrar)
struct ast_context *tmp, **local_contexts;
if (!extcontexts) {
local_contexts = &contexts;
ast_mutex_lock(&conlock);
} else
local_contexts = extcontexts;
tmp = *local_contexts;
while(tmp) {
if (!strcasecmp(tmp->name, name)) {
ast_mutex_unlock(&conlock);
ast_log(LOG_WARNING, "Tried to register context '%s', already in use\n", name);
ast_mutex_unlock(&conlock);
return NULL;
}
tmp = tmp->next;
}
tmp = malloc(sizeof(struct ast_context));
if (tmp) {
ast_mutex_init(&tmp->lock);
if (option_debug)
ast_log(LOG_DEBUG, "Registered context '%s'\n", tmp->name);
else if (option_verbose > 2)
ast_verbose( VERBOSE_PREFIX_3 "Registered extension context '%s'\n", tmp->name);
} else
ast_log(LOG_WARNING, "Out of memory\n");
ast_mutex_unlock(&conlock);
void __ast_context_destroy(struct ast_context *con, char *registrar, int lock);
void ast_merge_contexts_and_delete(struct ast_context **extcontexts, char *registrar) {
struct ast_context *tmp, *lasttmp = NULL;
tmp = *extcontexts;
ast_mutex_lock(&conlock);
if (registrar) {
__ast_context_destroy(NULL,registrar,0);
while (tmp) {
lasttmp = tmp;
tmp = tmp->next;
}
} else {
while (tmp) {
__ast_context_destroy(tmp,tmp->registrar,0);
lasttmp = tmp;
tmp = tmp->next;
}
}
if (lasttmp) {
lasttmp->next = contexts;
contexts = *extcontexts;
*extcontexts = NULL;
} else
ast_log(LOG_WARNING, "Requested contexts didn't get merged\n");
ast_mutex_unlock(&conlock);
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
*/
int ast_context_add_include(char *context, char *include, char *registrar)
{
struct ast_context *c;
if (ast_lock_contexts()) {
errno = EBUSY;
return -1;
}
/* walk contexts ... */
c = ast_walk_contexts(NULL);
while (c) {
/* ... search for the right one ... */
if (!strcmp(ast_get_context_name(c), context)) {
int ret = ast_context_add_include2(c, include, registrar);
/* ... unlock contexts list and return */
ast_unlock_contexts();
return ret;
}
c = ast_walk_contexts(c);
}
/* we can't find the right context */
ast_unlock_contexts();
#define FIND_NEXT \
do { \
c = info; \
while(*c && (*c != '|')) c++; \
} while(0)
static void get_timerange(struct ast_include *i, char *times)
{
char *e;
int x;
int s1, s2;
int e1, e2;
//[PHM 07/01/03]
//start disabling all times, fill the fields with 0's, as they may contain garbage
memset(i->minmask, 0, sizeof(i->minmask));
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
/* Star is all times */
if (!strlen(times) || !strcmp(times, "*")) {
for (x=0;x<24;x++)
i->minmask[x] = (1 << 30) - 1;
return;
}
/* Otherwise expect a range */
e = strchr(times, '-');
if (!e) {
ast_log(LOG_WARNING, "Time range is not valid. Assuming no time.\n");
return;
}
*e = '\0';
e++;
while(*e && !isdigit(*e)) e++;
if (!*e) {
ast_log(LOG_WARNING, "Invalid time range. Assuming no time.\n");
return;
}
if (sscanf(times, "%d:%d", &s1, &s2) != 2) {
ast_log(LOG_WARNING, "%s isn't a time. Assuming no time.\n", times);
return;
}
if (sscanf(e, "%d:%d", &e1, &e2) != 2) {
ast_log(LOG_WARNING, "%s isn't a time. Assuming no time.\n", e);
return;
}
s1 = s1 * 30 + s2/2;
if ((s1 < 0) || (s1 >= 24*30)) {
ast_log(LOG_WARNING, "%s isn't a valid star time. Assuming no time.\n", times);
return;
}
e1 = e1 * 30 + e2/2;
if ((e1 < 0) || (e2 >= 24*30)) {
ast_log(LOG_WARNING, "%s isn't a valid start time. Assuming no time.\n", times);
return;
}
/* Go through the time and enable each appropriate bit */
for (x=s1;x != e1;x = (x + 1) % (24 * 30)) {
i->minmask[x/30] |= (1 << (x % 30));
}
/* Do the last one */
i->minmask[x/30] |= (1 << (x % 30));
/* All done */
}
static char *days[] =
{
"sun",
"mon",
"tue",
"wed",
"thu",
"fri",
"sat",
};
static unsigned int get_dow(char *dow)
{
char *c;
/* The following line is coincidence, really! */
int s, e, x;
/* Check for all days */
if (!strlen(dow) || !strcmp(dow, "*"))
return (1 << 7) - 1;
/* Get start and ending days */
c = strchr(dow, '-');
if (c) {
*c = '\0';
c++;
/* Find the start */
s = 0;
while((s < 7) && strcasecmp(dow, days[s])) s++;
if (s >= 7) {
ast_log(LOG_WARNING, "Invalid day '%s', assuming none\n", dow);
return 0;
}
if (c) {
e = 0;
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
if (e >= 7) {
ast_log(LOG_WARNING, "Invalid day '%s', assuming none\n", c);
return 0;
}
} else
e = s;
mask = 0;
for (x=s;x!=e;x = (x + 1) % 7) {
mask |= (1 << x);
}
/* One last one */
mask |= (1 << x);
return mask;
}
static unsigned int get_day(char *day)
{
char *c;
/* The following line is coincidence, really! */
int s, e, x;
unsigned int mask;
/* Check for all days */
if (!strlen(day) || !strcmp(day, "*")) {
mask = (1 << 30) + ((1 << 30) - 1);
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
}
/* Get start and ending days */
c = strchr(day, '-');
if (c) {
*c = '\0';
c++;
}
/* Find the start */
if (sscanf(day, "%d", &s) != 1) {
ast_log(LOG_WARNING, "Invalid day '%s', assuming none\n", day);
return 0;
}
if ((s < 1) || (s > 31)) {
ast_log(LOG_WARNING, "Invalid day '%s', assuming none\n", day);
return 0;
}
s--;
if (c) {
if (sscanf(c, "%d", &e) != 1) {
ast_log(LOG_WARNING, "Invalid day '%s', assuming none\n", c);
return 0;
}
if ((e < 1) || (e > 31)) {
ast_log(LOG_WARNING, "Invalid day '%s', assuming none\n", c);
return 0;
}
e--;
} else
e = s;
mask = 0;
for (x=s;x!=e;x = (x + 1) % 31) {
mask |= (1 << x);
}
mask |= (1 << x);
return mask;
}
static char *months[] =
{
"jan",
"feb",
"mar",
"apr",
"may",