Newer
Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
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
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
(head)->last->field.next = (list)->first; \
(head)->last = (list)->last; \
} \
} while (0)
#define AST_RWLIST_APPEND_LIST AST_LIST_APPEND_LIST
/*!
\brief Removes and returns the head entry from a list.
\param head This is a pointer to the list head structure
\param field This is the name of the field (declared using AST_LIST_ENTRY())
used to link entries of this list together.
Removes the head entry from the list, and returns a pointer to it.
This macro is safe to call on an empty list.
*/
#define AST_LIST_REMOVE_HEAD(head, field) ({ \
typeof((head)->first) cur = (head)->first; \
if (cur) { \
(head)->first = cur->field.next; \
cur->field.next = NULL; \
if ((head)->last == cur) \
(head)->last = NULL; \
} \
cur; \
})
#define AST_RWLIST_REMOVE_HEAD AST_LIST_REMOVE_HEAD
/*!
\brief Removes a specific entry from a list.
\param head This is a pointer to the list head structure
\param elm This is a pointer to the entry to be removed.
\param field This is the name of the field (declared using AST_LIST_ENTRY())
used to link entries of this list together.
\warning The removed entry is \b not freed nor modified in any way.
*/
#define AST_LIST_REMOVE(head, elm, field) do { \
if ((head)->first == (elm)) { \
(head)->first = (elm)->field.next; \
if ((head)->last == (elm)) \
(head)->last = NULL; \
} else { \
typeof(elm) curelm = (head)->first; \
while (curelm && (curelm->field.next != (elm))) \
curelm = curelm->field.next; \
if (curelm) { \
curelm->field.next = (elm)->field.next; \
if ((head)->last == (elm)) \
(head)->last = curelm; \
} \
} \
(elm)->field.next = NULL; \
} while (0)
#define AST_RWLIST_REMOVE AST_LIST_REMOVE
/* chanvars.h */
struct ast_var_t {
AST_LIST_ENTRY(ast_var_t) entries;
char *value;
char name[0];
};
AST_LIST_HEAD_NOLOCK(varshead, ast_var_t);
AST_RWLOCK_DEFINE_STATIC(globalslock);
static struct varshead globals = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
/* IN CONFLICT: struct ast_var_t *ast_var_assign(const char *name, const char *value); */
static struct ast_var_t *ast_var_assign(const char *name, const char *value);
static void ast_var_delete(struct ast_var_t *var);
/*from channel.h */
#define AST_MAX_EXTENSION 80 /*!< Max length of an extension */
/* from pbx.h */
#define PRIORITY_HINT -1 /*!< Special Priority for a hint */
enum ast_extension_states {
AST_EXTENSION_REMOVED = -2, /*!< Extension removed */
AST_EXTENSION_DEACTIVATED = -1, /*!< Extension hint removed */
AST_EXTENSION_NOT_INUSE = 0, /*!< No device INUSE or BUSY */
AST_EXTENSION_INUSE = 1 << 0, /*!< One or more devices INUSE */
AST_EXTENSION_BUSY = 1 << 1, /*!< All devices BUSY */
AST_EXTENSION_UNAVAILABLE = 1 << 2, /*!< All devices UNAVAILABLE/UNREGISTERED */
AST_EXTENSION_RINGING = 1 << 3, /*!< All devices RINGING */
AST_EXTENSION_ONHOLD = 1 << 4, /*!< All devices ONHOLD */
};
struct ast_custom_function {
const char *name; /*!< Name */
const char *synopsis; /*!< Short description for "show functions" */
const char *desc; /*!< Help text that explains it all */
const char *syntax; /*!< Syntax description */
int (*read)(struct ast_channel *, const char *, char *, char *, size_t); /*!< Read function, if read is supported */
int (*write)(struct ast_channel *, const char *, char *, const char *); /*!< Write function, if write is supported */
AST_RWLIST_ENTRY(ast_custom_function) acflist;
};
typedef int (ast_switch_f)(struct ast_channel *chan, const char *context,
const char *exten, int priority, const char *callerid, const char *data);
struct ast_switch {
AST_LIST_ENTRY(ast_switch) list;
const char *name; /*!< Name of the switch */
const char *description; /*!< Description of the switch */
ast_switch_f *exists;
ast_switch_f *canmatch;
ast_switch_f *exec;
ast_switch_f *matchmore;
};
static char *config_filename = "extensions.conf";
static char *global_registrar = "conf2ael";
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
static char userscontext[AST_MAX_EXTENSION] = "default";
static int static_config = 0;
static int write_protect_config = 1;
static int autofallthrough_config = 0;
static int clearglobalvars_config = 0;
static void pbx_substitute_variables_helper(struct ast_channel *c,const char *cp1,char *cp2,int count);
/* stolen from callerid.c */
/*! \brief Clean up phone string
* remove '(', ' ', ')', non-trailing '.', and '-' not in square brackets.
* Basically, remove anything that could be invalid in a pattern.
*/
static void ast_shrink_phone_number(char *n)
{
int x, y=0;
int bracketed = 0;
for (x=0; n[x]; x++) {
switch(n[x]) {
case '[':
bracketed++;
n[y++] = n[x];
break;
case ']':
bracketed--;
n[y++] = n[x];
break;
case '-':
if (bracketed)
n[y++] = n[x];
break;
case '.':
if (!n[x+1])
n[y++] = n[x];
break;
default:
if (!strchr("()", n[x]))
n[y++] = n[x];
}
}
n[y] = '\0';
}
/* stolen from chanvars.c */
static const char *ast_var_name(const struct ast_var_t *var)
{
const char *name;
if (var == NULL || (name = var->name) == NULL)
return NULL;
/* Return the name without the initial underscores */
if (name[0] == '_') {
name++;
if (name[0] == '_')
name++;
}
return name;
}
/* experiment 1: see if it's easier just to use existing config code
* to read in the extensions.conf file. In this scenario,
I have to rip/copy code from other modules, because they
are staticly declared as-is. A solution would be to move
the ripped code to another location and make them available
to other modules and standalones */
/* Our own version of ast_log, since the expr parser uses it. -- stolen from utils/check_expr.c */
static void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
{
va_list vars;
va_start(vars,fmt);
printf("LOG: lev:%d file:%s line:%d func: %s ",
level, file, line, function);
vprintf(fmt, vars);
fflush(stdout);
va_end(vars);
}
void __attribute__((format(printf, 1, 2))) ast_verbose(const char *fmt, ...)
{
va_list vars;
va_start(vars,fmt);
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
printf("VERBOSE: ");
vprintf(fmt, vars);
fflush(stdout);
va_end(vars);
}
/* stolen from main/utils.c */
static char *ast_process_quotes_and_slashes(char *start, char find, char replace_with)
{
char *dataPut = start;
int inEscape = 0;
int inQuotes = 0;
for (; *start; start++) {
if (inEscape) {
*dataPut++ = *start; /* Always goes verbatim */
inEscape = 0;
} else {
if (*start == '\\') {
inEscape = 1; /* Do not copy \ into the data */
} else if (*start == '\'') {
inQuotes = 1 - inQuotes; /* Do not copy ' into the data */
} else {
/* Replace , with |, unless in quotes */
*dataPut++ = inQuotes ? *start : ((*start == find) ? replace_with : *start);
}
}
}
if (start != dataPut)
*dataPut = 0;
return dataPut;
}
static int ast_true(const char *s)
{
if (ast_strlen_zero(s))
return 0;
/* Determine if this is a true value */
if (!strcasecmp(s, "yes") ||
!strcasecmp(s, "true") ||
!strcasecmp(s, "y") ||
!strcasecmp(s, "t") ||
!strcasecmp(s, "1") ||
!strcasecmp(s, "on"))
return -1;
return 0;
}
#define ONE_MILLION 1000000
/*
* put timeval in a valid range. usec is 0..999999
* negative values are not allowed and truncated.
*/
static struct timeval tvfix(struct timeval a)
{
if (a.tv_usec >= ONE_MILLION) {
ast_log(LOG_WARNING, "warning too large timestamp %ld.%ld\n",
(long)a.tv_sec, (long int) a.tv_usec);
a.tv_sec += a.tv_usec / ONE_MILLION;
a.tv_usec %= ONE_MILLION;
} else if (a.tv_usec < 0) {
ast_log(LOG_WARNING, "warning negative timestamp %ld.%ld\n",
(long)a.tv_sec, (long int) a.tv_usec);
a.tv_usec = 0;
}
return a;
}
struct timeval ast_tvadd(struct timeval a, struct timeval b);
struct timeval ast_tvadd(struct timeval a, struct timeval b)
{
/* consistency checks to guarantee usec in 0..999999 */
a = tvfix(a);
b = tvfix(b);
a.tv_sec += b.tv_sec;
a.tv_usec += b.tv_usec;
if (a.tv_usec >= ONE_MILLION) {
a.tv_sec++;
a.tv_usec -= ONE_MILLION;
}
return a;
}
struct timeval ast_tvsub(struct timeval a, struct timeval b);
struct timeval ast_tvsub(struct timeval a, struct timeval b)
{
/* consistency checks to guarantee usec in 0..999999 */
a = tvfix(a);
b = tvfix(b);
a.tv_sec -= b.tv_sec;
a.tv_usec -= b.tv_usec;
if (a.tv_usec < 0) {
a.tv_sec-- ;
a.tv_usec += ONE_MILLION;
}
return a;
}
#undef ONE_MILLION
void ast_mark_lock_failed(void *lock_addr);
void ast_mark_lock_failed(void *lock_addr)
{
/* Pretend to do something. */
}
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
/* stolen from pbx.c */
#define VAR_BUF_SIZE 4096
#define VAR_NORMAL 1
#define VAR_SOFTTRAN 2
#define VAR_HARDTRAN 3
#define BACKGROUND_SKIP (1 << 0)
#define BACKGROUND_NOANSWER (1 << 1)
#define BACKGROUND_MATCHEXTEN (1 << 2)
#define BACKGROUND_PLAYBACK (1 << 3)
/*!
\brief ast_exten: An extension
The dialplan is saved as a linked list with each context
having it's own linked list of extensions - one item per
priority.
*/
struct ast_exten {
char *exten; /*!< Extension name */
int matchcid; /*!< Match caller id ? */
const char *cidmatch; /*!< Caller id to match for this extension */
int priority; /*!< Priority */
const char *label; /*!< Label */
struct ast_context *parent; /*!< The context this extension belongs to */
const char *app; /*!< Application to execute */
struct ast_app *cached_app; /*!< Cached location of application */
void *data; /*!< Data to use (arguments) */
void (*datad)(void *); /*!< Data destructor */
struct ast_exten *peer; /*!< Next higher priority with our extension */
const char *registrar; /*!< Registrar */
struct ast_exten *next; /*!< Extension with a greater ID */
char stuff[0];
};
/* from pbx.h */
typedef int (*ast_state_cb_type)(char *context, char* id, enum ast_extension_states state, void *data);
struct ast_timing {
int hastime; /*!< If time construct exists */
unsigned int monthmask; /*!< Mask for month */
unsigned int daymask; /*!< Mask for date */
unsigned int dowmask; /*!< Mask for day of week (mon-sun) */
unsigned int minmask[48]; /*!< Mask for minute */
char *timezone; /*!< NULL, or zoneinfo style timezone */
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
};
/* end of pbx.h */
/*! \brief ast_include: include= support in extensions.conf */
struct ast_include {
const char *name;
const char *rname; /*!< Context to include */
const char *registrar; /*!< Registrar */
int hastime; /*!< If time construct exists */
struct ast_timing timing; /*!< time construct */
struct ast_include *next; /*!< Link them together */
char stuff[0];
};
/*! \brief ast_sw: Switch statement in extensions.conf */
struct ast_sw {
char *name;
const char *registrar; /*!< Registrar */
char *data; /*!< Data load */
int eval;
AST_LIST_ENTRY(ast_sw) list;
char *tmpdata;
char stuff[0];
};
/*! \brief ast_ignorepat: Ignore patterns in dial plan */
struct ast_ignorepat {
const char *registrar;
struct ast_ignorepat *next;
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
};
/*! \brief ast_context: An extension context */
struct ast_context {
ast_rwlock_t lock; /*!< A lock to prevent multiple threads from clobbering the context */
struct ast_exten *root; /*!< The root of the list of extensions */
struct ast_context *next; /*!< Link them together */
struct ast_include *includes; /*!< Include other contexts */
struct ast_ignorepat *ignorepats; /*!< Patterns for which to continue playing dialtone */
const char *registrar; /*!< Registrar */
AST_LIST_HEAD_NOLOCK(, ast_sw) alts; /*!< Alternative switches */
ast_mutex_t macrolock; /*!< A lock to implement "exclusive" macros - held whilst a call is executing in the macro */
char name[0]; /*!< Name of the context */
};
/*! \brief ast_app: A registered application */
struct ast_app {
int (*execute)(struct ast_channel *chan, void *data);
const char *synopsis; /*!< Synopsis text for 'show applications' */
const char *description; /*!< Description (help text) for 'show application <name>' */
AST_RWLIST_ENTRY(ast_app) list; /*!< Next app in list */
void *module; /*!< Module this app belongs to */
char name[0]; /*!< Name of the application */
};
/*! \brief ast_state_cb: An extension state notify register item */
struct ast_state_cb {
int id;
void *data;
ast_state_cb_type callback;
struct ast_state_cb *next;
};
/*! \brief Structure for dial plan hints
\note Hints are pointers from an extension in the dialplan to one or
more devices (tech/name)
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
- See \ref AstExtState
*/
struct ast_hint {
struct ast_exten *exten; /*!< Extension */
int laststate; /*!< Last known state */
struct ast_state_cb *callbacks; /*!< Callback list for this extension */
AST_RWLIST_ENTRY(ast_hint) list;/*!< Pointer to next hint in list */
};
struct store_hint {
char *context;
char *exten;
struct ast_state_cb *callbacks;
int laststate;
AST_LIST_ENTRY(store_hint) list;
char data[1];
};
AST_LIST_HEAD(store_hints, store_hint);
#define STATUS_NO_CONTEXT 1
#define STATUS_NO_EXTENSION 2
#define STATUS_NO_PRIORITY 3
#define STATUS_NO_LABEL 4
#define STATUS_SUCCESS 5
static struct ast_var_t *ast_var_assign(const char *name, const char *value)
struct ast_var_t *var;
int name_len = strlen(name) + 1;
int value_len = strlen(value) + 1;
if (!(var = ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char)))) {
return NULL;
}
ast_copy_string(var->name, name, name_len);
var->value = var->name + name_len;
ast_copy_string(var->value, value, value_len);
return var;
static void ast_var_delete(struct ast_var_t *var)
{
2476
2477
2478
2479
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
2516
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
}
/* chopped this one off at the knees! */
static int ast_func_write(struct ast_channel *chan, const char *function, const char *value)
{
/* ast_log(LOG_ERROR, "Function %s not registered\n", function); we are not interested in the details here */
return -1;
}
static unsigned int ast_app_separate_args(char *buf, char delim, char **array, int arraylen)
{
int argc;
char *scan;
int paren = 0, quote = 0;
if (!buf || !array || !arraylen)
return 0;
memset(array, 0, arraylen * sizeof(*array));
scan = buf;
for (argc = 0; *scan && (argc < arraylen - 1); argc++) {
array[argc] = scan;
for (; *scan; scan++) {
if (*scan == '(')
paren++;
else if (*scan == ')') {
if (paren)
paren--;
} else if (*scan == '"' && delim != '"') {
quote = quote ? 0 : 1;
/* Remove quote character from argument */
memmove(scan, scan + 1, strlen(scan));
scan--;
} else if (*scan == '\\') {
/* Literal character, don't parse */
memmove(scan, scan + 1, strlen(scan));
} else if ((*scan == delim) && !paren && !quote) {
*scan++ = '\0';
break;
}
}
}
if (*scan)
array[argc++] = scan;
return argc;
}
static void pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
{
struct ast_var_t *newvariable;
struct varshead *headp;
const char *nametail = name;
/* XXX may need locking on the channel ? */
if (name[strlen(name)-1] == ')') {
char *function = ast_strdupa(name);
ast_func_write(chan, function, value);
return;
}
headp = &globals;
/* For comparison purposes, we have to strip leading underscores */
if (*nametail == '_') {
nametail++;
if (*nametail == '_')
nametail++;
}
AST_LIST_TRAVERSE (headp, newvariable, entries) {
if (strcasecmp(ast_var_name(newvariable), nametail) == 0) {
/* there is already such a variable, delete it */
AST_LIST_REMOVE(headp, newvariable, entries);
ast_var_delete(newvariable);
break;
}
}
if (value && (newvariable = ast_var_assign(name, value))) {
if ((option_verbose > 1) && (headp == &globals))
ast_verbose(VERBOSE_PREFIX_2 "Setting global variable '%s' to '%s'\n", name, value);
AST_LIST_INSERT_HEAD(headp, newvariable, entries);
}
}
static int pbx_builtin_setvar(struct ast_channel *chan, const void *data)
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
2601
2602
2603
2604
{
char *name, *value, *mydata;
int argc;
char *argv[24]; /* this will only support a maximum of 24 variables being set in a single operation */
int global = 0;
int x;
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Set requires at least one variable name/value pair.\n");
return 0;
}
mydata = ast_strdupa(data);
argc = ast_app_separate_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
/* check for a trailing flags argument */
if ((argc > 1) && !strchr(argv[argc-1], '=')) {
argc--;
if (strchr(argv[argc], 'g'))
global = 1;
}
for (x = 0; x < argc; x++) {
name = argv[x];
if ((value = strchr(name, '='))) {
*value++ = '\0';
pbx_builtin_setvar_helper((global) ? NULL : chan, name, value);
} else
ast_log(LOG_WARNING, "Ignoring entry '%s' with no = (and not last 'options' entry)\n", name);
}
return(0);
}
int localized_pbx_builtin_setvar(struct ast_channel *chan, const void *data);
int localized_pbx_builtin_setvar(struct ast_channel *chan, const void *data)
{
return pbx_builtin_setvar(chan, data);
}
/*! \brief Helper for get_range.
* return the index of the matching entry, starting from 1.
* If names is not supplied, try numeric values.
*/
static int lookup_name(const char *s, char *const names[], int max)
{
int i;
if (names && *s > '9') {
for (i = 0; names[i]; i++) {
if (!strcasecmp(s, names[i])) {
return i;
}
}
}
/* Allow months and weekdays to be specified as numbers, as well */
/* What the array offset would have been: "1" would be at offset 0 */
return i - 1;
}
return -1; /* error return */
}
/*! \brief helper function to return a range up to max (7, 12, 31 respectively).
* names, if supplied, is an array of names that should be mapped to numbers.
*/
static unsigned get_range(char *src, int max, char *const names[], const char *msg)
{
int start, end; /* start and ending position */
unsigned int mask = 0;
/* Check for whole range */
if (ast_strlen_zero(src) || !strcmp(src, "*")) {
return (1 << max) - 1;
}
while ((part = strsep(&src, "&"))) {
/* Get start and ending position */
char *endpart = strchr(part, '-');
if (endpart) {
*endpart++ = '\0';
}
/* Find the start */
if ((start = lookup_name(part, names, max)) < 0) {
ast_log(LOG_WARNING, "Invalid %s '%s', skipping element\n", msg, part);
continue;
}
if (endpart) { /* find end of range */
if ((end = lookup_name(endpart, names, max)) < 0) {
ast_log(LOG_WARNING, "Invalid end %s '%s', skipping element\n", msg, endpart);
continue;
}
} else {
end = start;
}
/* Fill the mask. Remember that ranges are cyclic */
mask |= (1 << end); /* initialize with last element */
while (start != end) {
if (start >= max) {
start = 0;
}
mask |= (1 << start);
start++;
}
}
return mask;
}
/*! \brief store a bitmask of valid times, one bit each 2 minute */
static void get_timerange(struct ast_timing *i, char *times)
{
char *endpart, *part;
int x;
int st_h, st_m;
int endh, endm;
int minute_start, minute_end;
/* start disabling all times, fill the fields with 0's, as they may contain garbage */
memset(i->minmask, 0, sizeof(i->minmask));
/* 1-minute per bit */
/* Star is all times */
if (ast_strlen_zero(times) || !strcmp(times, "*")) {
/* 48, because each hour takes 2 integers; 30 bits each */
for (x = 0; x < 48; x++) {
i->minmask[x] = 0x3fffffff; /* 30 bits */
return;
}
/* Otherwise expect a range */
while ((part = strsep(×, "&"))) {
if (!(endpart = strchr(part, '-'))) {
if (sscanf(part, "%2d:%2d", &st_h, &st_m) != 2 || st_h < 0 || st_h > 23 || st_m < 0 || st_m > 59) {
ast_log(LOG_WARNING, "%s isn't a valid time.\n", part);
continue;
}
i->minmask[st_h * 2 + (st_m >= 30 ? 1 : 0)] |= (1 << (st_m % 30));
continue;
}
*endpart++ = '\0';
/* why skip non digits? Mostly to skip spaces */
while (*endpart && !isdigit(*endpart)) {
endpart++;
}
if (!*endpart) {
ast_log(LOG_WARNING, "Invalid time range starting with '%s-'.\n", part);
continue;
}
if (sscanf(part, "%2d:%2d", &st_h, &st_m) != 2 || st_h < 0 || st_h > 23 || st_m < 0 || st_m > 59) {
ast_log(LOG_WARNING, "'%s' isn't a valid start time.\n", part);
continue;
}
if (sscanf(endpart, "%2d:%2d", &endh, &endm) != 2 || endh < 0 || endh > 23 || endm < 0 || endm > 59) {
ast_log(LOG_WARNING, "'%s' isn't a valid end time.\n", endpart);
continue;
}
minute_start = st_h * 60 + st_m;
minute_end = endh * 60 + endm;
/* Go through the time and enable each appropriate bit */
for (x = minute_start; x != minute_end; x = (x + 1) % (24 * 60)) {
i->minmask[x / 30] |= (1 << (x % 30));
}
/* Do the last one */
i->minmask[x / 30] |= (1 << (x % 30));
}
/* All done */
return;
}
static void null_datad(void *foo)
{
}
/*! \brief Find realtime engine for realtime family */
static struct ast_config_engine *find_engine(const char *family, char *database, int dbsiz, char *table, int tabsiz)
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
{
struct ast_config_engine *eng, *ret = NULL;
struct ast_config_map *map;
for (map = config_maps; map; map = map->next) {
if (!strcasecmp(family, map->name)) {
if (database)
ast_copy_string(database, map->database, dbsiz);
if (table)
ast_copy_string(table, map->table ? map->table : family, tabsiz);
break;
}
}
/* Check if the required driver (engine) exist */
if (map) {
for (eng = config_engine_list; !ret && eng; eng = eng->next) {
if (!strcasecmp(eng->name, map->driver))
ret = eng;
}
}
/* if we found a mapping, but the engine is not available, then issue a warning */
if (map && !ret)
ast_log(LOG_WARNING, "Realtime mapping for '%s' found to engine '%s', but the engine is not available\n", map->name, map->driver);
return ret;
}
struct ast_category *ast_config_get_current_category(const struct ast_config *cfg);
struct ast_category *ast_config_get_current_category(const struct ast_config *cfg)
{
return cfg->current;
}
Steve Murphy
committed
static struct ast_category *ast_category_new(const char *name, const char *in_file, int lineno);
Steve Murphy
committed
static struct ast_category *ast_category_new(const char *name, const char *in_file, int lineno)
{
struct ast_category *category;
if ((category = ast_calloc(1, sizeof(*category))))
ast_copy_string(category->name, name, sizeof(category->name));
Steve Murphy
committed
category->file = strdup(in_file);
category->lineno = lineno; /* if you don't know the lineno, set it to 999999 or something real big */
return category;
2799
2800
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
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
}
struct ast_category *localized_category_get(const struct ast_config *config, const char *category_name);
struct ast_category *localized_category_get(const struct ast_config *config, const char *category_name)
{
return category_get(config, category_name, 0);
}
static void move_variables(struct ast_category *old, struct ast_category *new)
{
struct ast_variable *var = old->root;
old->root = NULL;
#if 1
/* we can just move the entire list in a single op */
ast_variable_append(new, var);
#else
while (var) {
struct ast_variable *next = var->next;
var->next = NULL;
ast_variable_append(new, var);
var = next;
}
#endif
}
static void inherit_category(struct ast_category *new, const struct ast_category *base)
{
struct ast_variable *var;
for (var = base->root; var; var = var->next)
ast_variable_append(new, variable_clone(var));
}
static void ast_category_append(struct ast_config *config, struct ast_category *category);
static void ast_category_append(struct ast_config *config, struct ast_category *category)
{
if (config->last)
config->last->next = category;
else
config->root = category;
config->last = category;
config->current = category;
}
static void ast_category_destroy(struct ast_category *cat);
static void ast_category_destroy(struct ast_category *cat)
{
ast_variables_destroy(cat->root);
Steve Murphy
committed
if (cat->file)
free(cat->file);
free(cat);
}
static struct ast_config_engine text_file_engine = {
.name = "text",
.load_func = config_text_file_load,
};
Steve Murphy
committed
static struct ast_config *ast_config_internal_load(const char *filename, struct ast_config *cfg, int withcomments, const char *suggested_incl_file);
Steve Murphy
committed
static struct ast_config *ast_config_internal_load(const char *filename, struct ast_config *cfg, int withcomments, const char *suggested_incl_file)
{
char db[256];
char table[256];
struct ast_config_engine *loader = &text_file_engine;
struct ast_config *result;
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
if (cfg->include_level == cfg->max_include_level) {
ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level);
return NULL;
}
cfg->include_level++;
/* silence is golden!
ast_log(LOG_WARNING, "internal loading file %s level=%d\n", filename, cfg->include_level);
*/
if (strcmp(filename, extconfig_conf) && strcmp(filename, "asterisk.conf") && config_engine_list) {
struct ast_config_engine *eng;
eng = find_engine(filename, db, sizeof(db), table, sizeof(table));
if (eng && eng->load_func) {
loader = eng;
} else {
eng = find_engine("global", db, sizeof(db), table, sizeof(table));
if (eng && eng->load_func)
loader = eng;
}
}
Steve Murphy
committed
result = loader->load_func(db, table, filename, cfg, withcomments, suggested_incl_file);
ast_log(LOG_WARNING, "finished internal loading file %s level=%d\n", filename, cfg->include_level);
*/
if (result)
result->include_level--;
return result;
}
Steve Murphy
committed
static int process_text_line(struct ast_config *cfg, struct ast_category **cat, char *buf, int lineno, const char *configfile, int withcomments, const char *suggested_include_file)
{
char *c;
char *cur = buf;
struct ast_variable *v;
int object, do_exec, do_include;
/* Actually parse the entry */
if (cur[0] == '[') {
struct ast_category *newcat = NULL;
char *catname;
/* A category header */
c = strchr(cur, ']');
if (!c) {
ast_log(LOG_WARNING, "parse error: no closing ']', line %d of %s\n", lineno, configfile);
return -1;
}
*c++ = '\0';
cur++;
if (*c++ != '(')
c = NULL;
catname = cur;
Steve Murphy
committed
if (!(*cat = newcat = ast_category_new(catname, ast_strlen_zero(suggested_include_file)?configfile:suggested_include_file, lineno))) {
return -1;
}
Steve Murphy
committed
(*cat)->lineno = lineno;
/* add comments */
if (withcomments && comment_buffer && comment_buffer[0] ) {
newcat->precomments = ALLOC_COMMENT(comment_buffer);
}
if (withcomments && lline_buffer && lline_buffer[0] ) {
newcat->sameline = ALLOC_COMMENT(lline_buffer);
}
if( withcomments )
CB_RESET();
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
/* If there are options or categories to inherit from, process them now */
if (c) {
if (!(cur = strchr(c, ')'))) {
ast_log(LOG_WARNING, "parse error: no closing ')', line %d of %s\n", lineno, configfile);
return -1;
}
*cur = '\0';
while ((cur = strsep(&c, ","))) {
if (!strcasecmp(cur, "!")) {
(*cat)->ignored = 1;
} else if (!strcasecmp(cur, "+")) {
*cat = category_get(cfg, catname, 1);
if (!*cat) {
ast_config_destroy(cfg);
if (newcat)
ast_category_destroy(newcat);
ast_log(LOG_WARNING, "Category addition requested, but category '%s' does not exist, line %d of %s\n", catname, lineno, configfile);
return -1;
}
if (newcat) {
move_variables(newcat, *cat);
ast_category_destroy(newcat);
newcat = NULL;
}
} else {
struct ast_category *base;
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
base = category_get(cfg, cur, 1);
if (!base) {
ast_log(LOG_WARNING, "Inheritance requested, but category '%s' does not exist, line %d of %s\n", cur, lineno, configfile);
return -1;
}
inherit_category(*cat, base);
}
}
}
if (newcat)
ast_category_append(cfg, *cat);
} else if (cur[0] == '#') {
/* A directive */
cur++;
c = cur;
while(*c && (*c > 32)) c++;
if (*c) {
*c = '\0';
/* Find real argument */
c = ast_skip_blanks(c + 1);
if (!*c)
c = NULL;
c = NULL;
do_include = !strcasecmp(cur, "include");
if(!do_include)
do_exec = !strcasecmp(cur, "exec");