Asterisk - The Open Source Telephony Project  GIT-master-44aef04
Data Structures | Macros | Functions | Variables
conf2ael.c File Reference
#include "asterisk.h"
#include "asterisk/paths.h"
#include <locale.h>
#include <ctype.h>
#include <err.h>
#include <regex.h>
#include "asterisk/pbx.h"
#include "asterisk/ast_expr.h"
#include "asterisk/channel.h"
#include "asterisk/chanvars.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/config.h"
#include "asterisk/options.h"
#include "asterisk/callerid.h"
#include "asterisk/lock.h"
#include "asterisk/hashtab.h"
#include "asterisk/ael_structs.h"
#include "asterisk/devicestate.h"
#include "asterisk/stringfields.h"
#include "asterisk/pval.h"
#include "asterisk/extconf.h"

Go to the source code of this file.

Data Structures

struct  ast_app
 ast_app: A registered application More...
 
struct  ast_context
 ast_context: An extension context - must remain in sync with fake_context More...
 
struct  ast_exten
 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. More...
 
struct  ast_hint
 Structure for dial plan hints. More...
 
struct  ast_ignorepat
 ast_ignorepat: Ignore patterns in dial plan More...
 
struct  ast_include
 ast_include: include= support in extensions.conf More...
 
struct  ast_state_cb
 ast_state_cb: An extension state notify register item More...
 
struct  ast_sw
 ast_sw: Switch statement in extensions.conf More...
 
struct  profile_data
 
struct  profile_entry
 
struct  store_hint
 
struct  store_hints
 

Macros

#define ASTMM_LIBC   ASTMM_IGNORE
 
#define BACKGROUND_MATCHEXTEN   (1 << 2)
 
#define BACKGROUND_NOANSWER   (1 << 1)
 
#define BACKGROUND_PLAYBACK   (1 << 3)
 
#define BACKGROUND_SKIP   (1 << 0)
 
#define EXT_DATA_SIZE   8192
 
#define STATUS_NO_CONTEXT   1
 
#define STATUS_NO_EXTENSION   2
 
#define STATUS_NO_LABEL   4
 
#define STATUS_NO_PRIORITY   3
 
#define STATUS_SUCCESS   5
 
#define SWITCH_DATA_LENGTH   256
 
#define VAR_BUF_SIZE   4096
 
#define VAR_HARDTRAN   3
 
#define VAR_NORMAL   1
 
#define VAR_SOFTTRAN   2
 

Functions

void __ast_cli_register_multiple (void)
 
int all_bits_set (unsigned int *word, int bitsperword, int totalbits)
 
int ast_add_extension2 (struct ast_context *con, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar, const char *registrar_file, int registrar_line)
 Add an extension to an extension context, this time with an ast_context *. More...
 
int ast_add_profile (const char *x, uint64_t scale)
 support for event profiling More...
 
void ast_cli_unregister_multiple (void)
 
int ast_context_add_ignorepat2 (struct ast_context *con, const char *value, const char *registrar)
 
int ast_context_add_include2 (struct ast_context *con, const char *value, const char *registrar)
 Add a context include. More...
 
int ast_context_add_switch2 (struct ast_context *con, const char *value, const char *data, int eval, const char *registrar)
 Adds a switch (first param is a ast_context) More...
 
void ast_context_destroy (struct ast_context *con, const char *registrar)
 Destroy a context (matches the specified context or ANY context if NULL) More...
 
struct ast_contextast_context_find_or_create (struct ast_context **extcontexts, struct ast_hashtab *exttable, const char *name, const char *registrar)
 Register a new context or find an existing one. More...
 
int ast_context_verify_includes (struct ast_context *con)
 Verifies includes in an ast_contect structure. More...
 
struct ast_custom_functionast_custom_function_find (const char *name)
 
const char * ast_get_context_name (struct ast_context *con)
 
int ast_hashtab_compare_contexts (const void *ah_a, const void *ah_b)
 hashtable functions for contexts More...
 
unsigned int ast_hashtab_hash_contexts (const void *obj)
 
void ast_log (int level, const char *file, int line, const char *function, const char *fmt,...)
 Used for sending a log message This is the standard logger function. Probably the only way you will invoke it would be something like this: ast_log(AST_LOG_WHATEVER, "Problem with the %s Captain. We should get some more. Will %d be enough?\n", "flux capacitor", 10); where WHATEVER is one of ERROR, DEBUG, EVENT, NOTICE, or WARNING depending on which log you wish to output to. These are implemented as macros, that will provide the function with the needed arguments. More...
 
void ast_merge_contexts_and_delete (struct ast_context **extcontexts, struct ast_hashtab *exttable, const char *registrar)
 Merge the temporary contexts into a global contexts list and delete from the global list the ones that are being added. More...
 
void ast_module_register (const struct ast_module_info *x)
 
void ast_module_unregister (const struct ast_module_info *x)
 
struct ast_extenast_walk_context_extensions (struct ast_context *con, struct ast_exten *exten)
 
const struct ast_includeast_walk_context_includes (const struct ast_context *con, const struct ast_include *inc)
 
struct ast_contextast_walk_contexts (struct ast_context *con)
 
static int bit_at (unsigned int *word, int bitsperword, int bitnum)
 
void get_start_stop (unsigned int *word, int bitsperword, int totalbits, int *start, int *end)
 
int main (int argc, char **argv)
 
int pbx_builtin_setvar (struct ast_channel *chan, const char *data)
 Parse and set a single channel variable, where the name and value are separated with an '=' character. More...
 
struct ast_extenpbx_find_extension (struct ast_channel *chan, struct ast_context *bypass, struct pbx_find_info *q, const char *context, const char *exten, int priority, const char *label, const char *callerid, enum ext_match_t action)
 
void pbx_substitute_variables_helper (struct ast_channel *c, const char *cp1, char *cp2, int count)
 

Variables

const char * ast_config_AST_CONFIG_DIR = "/etc/asterisk"
 
char * config = "extensions.conf"
 
struct ast_contextcontexts
 
char * days []
 
struct ast_contextlocal_contexts
 
char * months []
 
int option_debug = 0
 
int option_verbose = 0
 

Macro Definition Documentation

◆ ASTMM_LIBC

#define ASTMM_LIBC   ASTMM_IGNORE

Definition at line 30 of file conf2ael.c.

◆ BACKGROUND_MATCHEXTEN

#define BACKGROUND_MATCHEXTEN   (1 << 2)

Definition at line 117 of file conf2ael.c.

◆ BACKGROUND_NOANSWER

#define BACKGROUND_NOANSWER   (1 << 1)

Definition at line 116 of file conf2ael.c.

◆ BACKGROUND_PLAYBACK

#define BACKGROUND_PLAYBACK   (1 << 3)

Definition at line 118 of file conf2ael.c.

◆ BACKGROUND_SKIP

#define BACKGROUND_SKIP   (1 << 0)

Definition at line 115 of file conf2ael.c.

◆ EXT_DATA_SIZE

#define EXT_DATA_SIZE   8192

Definition at line 104 of file conf2ael.c.

◆ STATUS_NO_CONTEXT

#define STATUS_NO_CONTEXT   1

Definition at line 229 of file conf2ael.c.

◆ STATUS_NO_EXTENSION

#define STATUS_NO_EXTENSION   2

Definition at line 230 of file conf2ael.c.

◆ STATUS_NO_LABEL

#define STATUS_NO_LABEL   4

Definition at line 232 of file conf2ael.c.

◆ STATUS_NO_PRIORITY

#define STATUS_NO_PRIORITY   3

Definition at line 231 of file conf2ael.c.

◆ STATUS_SUCCESS

#define STATUS_SUCCESS   5

Definition at line 233 of file conf2ael.c.

◆ SWITCH_DATA_LENGTH

#define SWITCH_DATA_LENGTH   256

Definition at line 107 of file conf2ael.c.

◆ VAR_BUF_SIZE

#define VAR_BUF_SIZE   4096

Definition at line 109 of file conf2ael.c.

◆ VAR_HARDTRAN

#define VAR_HARDTRAN   3

Definition at line 113 of file conf2ael.c.

◆ VAR_NORMAL

#define VAR_NORMAL   1

Definition at line 111 of file conf2ael.c.

◆ VAR_SOFTTRAN

#define VAR_SOFTTRAN   2

Definition at line 112 of file conf2ael.c.

Function Documentation

◆ __ast_cli_register_multiple()

void __ast_cli_register_multiple ( void  )

Definition at line 599 of file conf2ael.c.

Referenced by ast_context_find_or_create().

600 {
601 }

◆ all_bits_set()

int all_bits_set ( unsigned int *  word,
int  bitsperword,
int  totalbits 
)

Definition at line 286 of file conf2ael.c.

References total.

Referenced by main().

287 {
288 
289  int i, total=totalbits/bitsperword,bitmask = 0;
290 
291  for (i=0; i<bitsperword; i++)
292  {
293  bitmask |= (1 << i);
294  }
295 
296  for (i=0; i<total; i++)
297  {
298  if (word[i] != bitmask)
299  return 0;
300  }
301  return 1;
302 }
static int total
Definition: res_adsi.c:968
short word

◆ ast_add_extension2()

int ast_add_extension2 ( struct ast_context con,
int  replace,
const char *  extension,
int  priority,
const char *  label,
const char *  callerid,
const char *  application,
void *  data,
void(*)(void *)  datad,
const char *  registrar,
const char *  registrar_file,
int  registrar_line 
)

Add an extension to an extension context, this time with an ast_context *.

Parameters
registrar_fileoptional configuration file that defines this extension
registrar_lineoptional line number of configuration file that defines extension
Note
For details about the other arguments, check ast_add_extension()

Add an extension to an extension context, this time with an ast_context *.

We sort extensions in order of matching preference, so that we can stop the search as soon as we find a suitable match. This ordering also takes care of wildcards such as '.' (meaning "one or more of any character") and '!' (which is 'earlymatch', meaning "zero or more of any character" but also impacts the return value from CANMATCH and EARLYMATCH.

The extension match rules defined in the devmeeting 2006.05.05 are quite simple: WE SELECT THE LONGEST MATCH. In detail, "longest" means the number of matched characters in the extension. In case of ties (e.g. _XXX and 333) in the length of a pattern, we give priority to entries with the smallest cardinality (e.g, [5-9] comes before [2-8] before the former has only 5 elements, while the latter has 7, etc. In case of same cardinality, the first element in the range counts. If we still have a tie, any final '!' will make this as a possibly less specific pattern.

EBUSY - can't lock EEXIST - extension with the same priority exist and no replace is set

Definition at line 562 of file conf2ael.c.

References ast_exten::datad, and localized_add_extension2().

Referenced by add_extensions(), lua_register_hints(), manager_dialplan_extension_add(), pbx_load_config(), and pbx_load_users().

566 {
567  return localized_add_extension2(con, replace, extension, priority, label, callerid, application, data, datad, registrar);
568 }
static int priority
structure to hold extensions
static char * registrar
Definition: pbx_ael.c:78
int localized_add_extension2(struct ast_context *con, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar)
Definition: extconf.c:4898
static int replace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
Definition: func_strings.c:790

◆ ast_add_profile()

int ast_add_profile ( const char *  x,
uint64_t  scale 
)

support for event profiling

(note, this must be documented a lot more) ast_add_profile allocates a generic 'counter' with a given name, which can be shown with the command 'core show profile <name>'

The counter accumulates positive or negative values supplied by

See also
ast_add_profile(), dividing them by the 'scale' value passed in the create call, and also counts the number of 'events'. Values can also be taked by the TSC counter on ia32 architectures, in which case you can mark the start of an event calling ast_mark(id, 1) and then the end of the event with ast_mark(id, 0). For non-i386 architectures, these two calls return 0.

support for event profiling

Returns
Returns the identifier of the counter.

Definition at line 82 of file conf2ael.c.

References ast_log(), make_ari_stubs::file, and format.

Referenced by ao2_weakproxy_unsubscribe(), and extension_match_core().

82 { return 0;}

◆ ast_cli_unregister_multiple()

void ast_cli_unregister_multiple ( void  )

Definition at line 613 of file conf2ael.c.

References ast_walk_contexts().

Referenced by ast_module_unregister().

614 {
615 }

◆ ast_context_add_ignorepat2()

int ast_context_add_ignorepat2 ( struct ast_context con,
const char *  value,
const char *  registrar 
)

Definition at line 570 of file conf2ael.c.

References localized_context_add_ignorepat2().

Referenced by ast_compile_ael2(), and pbx_load_config().

571 {
572 
574 }
int localized_context_add_ignorepat2(struct ast_context *con, const char *value, const char *registrar)
Definition: extconf.c:4601
int value
Definition: syslog.c:37
static char * registrar
Definition: pbx_ael.c:78

◆ ast_context_add_include2()

int ast_context_add_include2 ( struct ast_context con,
const char *  value,
const char *  registrar 
)

Add a context include.

Parameters
concontext to add the include to
valueinclude value to add
registrarwho registered the context

Adds an include taking a struct ast_context as the first parameter

Return values
0on success
-1on failure

Definition at line 583 of file conf2ael.c.

References localized_context_add_include2().

Referenced by ast_compile_ael2(), and pbx_load_config().

585 {
586 
588 }
int value
Definition: syslog.c:37
int localized_context_add_include2(struct ast_context *con, const char *value, const char *registrar)
Definition: extconf.c:4559
static char * registrar
Definition: pbx_ael.c:78

◆ ast_context_add_switch2()

int ast_context_add_switch2 ( struct ast_context con,
const char *  value,
const char *  data,
int  eval,
const char *  registrar 
)

Adds a switch (first param is a ast_context)

Note
See ast_context_add_switch() for argument information, with the exception of the first argument. In this case, it's a pointer to an ast_context structure as opposed to the name.

Definition at line 576 of file conf2ael.c.

References localized_context_add_switch2().

Referenced by ast_compile_ael2(), lua_register_switches(), and pbx_load_config().

578 {
579 
580  return localized_context_add_switch2(con, value, data, eval, registrar);
581 }
int value
Definition: syslog.c:37
int localized_context_add_switch2(struct ast_context *con, const char *value, const char *data, int eval, const char *registrar)
Definition: extconf.c:4702
static char * registrar
Definition: pbx_ael.c:78

◆ ast_context_destroy()

void ast_context_destroy ( struct ast_context con,
const char *  registrar 
)

Destroy a context (matches the specified context or ANY context if NULL)

Parameters
concontext to destroy
registrarwho registered it

You can optionally leave out either parameter. It will find it based on either the ast_context or the registrar name.

Returns
nothing

Definition at line 625 of file conf2ael.c.

References ast_context_verify_includes(), and localized_context_destroy().

Referenced by AST_TEST_DEFINE(), ast_walk_contexts(), parking_lot_cfg_remove_extensions(), remove_all_configured_parking_lot_extensions(), remove_pending_parking_lot_extensions(), sla_destroy(), and unload_module().

626 {
628 }
static char * registrar
Definition: pbx_ael.c:78
void localized_context_destroy(struct ast_context *con, const char *registrar)
Definition: extconf.c:5565

◆ ast_context_find_or_create()

struct ast_context* ast_context_find_or_create ( struct ast_context **  extcontexts,
struct ast_hashtab exttable,
const char *  name,
const char *  registrar 
)

Register a new context or find an existing one.

Parameters
extcontextspointer to the ast_context structure pointer
exttablepointer to the hashtable that contains all the elements in extcontexts
namename of the new context
registrarregistrar of the context

This function allows you to play in two environments: the global contexts (active dialplan) or an external context set of your choosing. To act on the external set, make sure extcontexts and exttable are set; for the globals, make sure both extcontexts and exttable are NULL.

This will first search for a context with your name. If it exists already, it will not create a new one. If it does not exist, it will create a new one with the given name and registrar.

Returns
NULL on failure, and an ast_context structure on success

Definition at line 590 of file conf2ael.c.

References __ast_cli_register_multiple(), and localized_context_find_or_create().

Referenced by add_hints(), app_create(), ast_compile_ael2(), ast_sip_persistent_endpoint_add_to_regcontext(), AST_TEST_DEFINE(), config_parse_variables(), create_test_dialplan(), handle_cli_dialplan_add_extension(), handle_cli_dialplan_add_include(), load_module(), lua_register_hints(), lua_register_switches(), manager_dialplan_extension_add(), parking_duration_callback(), parking_lot_cfg_create_extensions(), pbx_load_config(), pbx_load_users(), reload_config(), set_config(), sla_build_station(), and sla_build_trunk().

591 {
592  printf("find/Creating context %s, registrar=%s\n", name, registrar);
593 
594  return localized_context_find_or_create(extcontexts, exttable, name, registrar);
595 }
struct ast_context * localized_context_find_or_create(struct ast_context **extcontexts, void *tab, const char *name, const char *registrar)
Definition: extconf.c:4989
static char * registrar
Definition: pbx_ael.c:78
static const char name[]
Definition: cdr_mysql.c:74

◆ ast_context_verify_includes()

int ast_context_verify_includes ( struct ast_context con)

Verifies includes in an ast_contect structure.

Parameters
concontext in which to verify the includes
Return values
0if no problems found
-1if there were any missing context

Definition at line 632 of file conf2ael.c.

References ast_merge_contexts_and_delete(), and localized_context_verify_includes().

Referenced by ast_context_destroy(), and pbx_load_module().

633 {
635 }
int localized_context_verify_includes(struct ast_context *con)
Definition: extconf.c:5640

◆ ast_custom_function_find()

struct ast_custom_function* ast_custom_function_find ( const char *  name)

Definition at line 242 of file conf2ael.c.

References events, ast_exten::name, and value.

Referenced by ast_compile_ael2(), AST_TEST_DEFINE(), chanavail_exec(), config_curl(), destroy_curl(), op_func(), realtime_curl(), realtime_multi_curl(), require_curl(), store_curl(), update2_curl(), and update_curl().

243 {
244  return 0; /* in "standalone" mode, functions are just not avail */
245 }

◆ ast_get_context_name()

const char* ast_get_context_name ( struct ast_context con)

◆ ast_hashtab_compare_contexts()

int ast_hashtab_compare_contexts ( const void *  ah_a,
const void *  ah_b 
)

hashtable functions for contexts

Definition at line 687 of file conf2ael.c.

References ast_hashtab_hash_contexts().

Referenced by lua_register_hints(), lua_register_switches(), pbx_find_extension(), and pbx_load_module().

688 {
689  return 0;
690 }

◆ ast_hashtab_hash_contexts()

unsigned int ast_hashtab_hash_contexts ( const void *  obj)

Definition at line 694 of file conf2ael.c.

References __ast_bt_get_addresses(), __ast_bt_get_symbols(), NULL, and type.

Referenced by ast_hashtab_compare_contexts(), lua_register_hints(), lua_register_switches(), and pbx_load_module().

695 {
696  return 0;
697 }

◆ ast_log()

void ast_log ( int  level,
const char *  file,
int  line,
const char *  function,
const char *  fmt,
  ... 
)

Used for sending a log message This is the standard logger function. Probably the only way you will invoke it would be something like this: ast_log(AST_LOG_WHATEVER, "Problem with the %s Captain. We should get some more. Will %d be enough?\n", "flux capacitor", 10); where WHATEVER is one of ERROR, DEBUG, EVENT, NOTICE, or WARNING depending on which log you wish to output to. These are implemented as macros, that will provide the function with the needed arguments.

Parameters
levelType of log event
fileWill be provided by the AST_LOG_* macro
lineWill be provided by the AST_LOG_* macro
functionWill be provided by the AST_LOG_* macro
fmtThis is what is important. The format is the same as your favorite breed of printf. You know how that works, right? :-)

Definition at line 86 of file conf2ael.c.

Referenced by ast_add_profile(), and main().

87 {
88  va_list vars;
89  va_start(vars,fmt);
90 
91  printf("LOG: lev:%d file:%s line:%d func: %s ",
92  level, file, line, function);
93  vprintf(fmt, vars);
94  fflush(stdout);
95  va_end(vars);
96 }

◆ ast_merge_contexts_and_delete()

void ast_merge_contexts_and_delete ( struct ast_context **  extcontexts,
struct ast_hashtab exttable,
const char *  registrar 
)

Merge the temporary contexts into a global contexts list and delete from the global list the ones that are being added.

Parameters
extcontextspointer to the ast_context structure
exttablepointer to the ast_hashtab structure that contains all the elements in extcontexts
registrarof the context; if it's set the routine will delete all contexts that belong to that registrar; if NULL only the contexts that are specified in extcontexts

Definition at line 639 of file conf2ael.c.

References ast_get_context_name(), and localized_merge_contexts_and_delete().

Referenced by ast_context_verify_includes(), lua_reload_extensions(), and pbx_load_module().

640 {
641  localized_merge_contexts_and_delete(extcontexts, exttable, registrar);
642 }
void localized_merge_contexts_and_delete(struct ast_context **extcontexts, void *tab, const char *registrar)
Definition: extconf.c:5618
static char * registrar
Definition: pbx_ael.c:78

◆ ast_module_register()

void ast_module_register ( const struct ast_module_info x)

Definition at line 603 of file conf2ael.c.

604 {
605 }

◆ ast_module_unregister()

void ast_module_unregister ( const struct ast_module_info x)

Definition at line 607 of file conf2ael.c.

References ast_cli_unregister_multiple().

608 {
609 }

◆ ast_walk_context_extensions()

struct ast_exten* ast_walk_context_extensions ( struct ast_context con,
struct ast_exten exten 
)

◆ ast_walk_context_includes()

const struct ast_include* ast_walk_context_includes ( const struct ast_context con,
const struct ast_include inc 
)

Definition at line 657 of file conf2ael.c.

References context, NULL, and pbx_find_extension().

Referenced by ast_walk_context_extensions().

658 {
659  return NULL;
660 }
#define NULL
Definition: resample.c:96

◆ ast_walk_contexts()

struct ast_context* ast_walk_contexts ( struct ast_context con)

◆ bit_at()

static int bit_at ( unsigned int *  word,
int  bitsperword,
int  bitnum 
)
static

Definition at line 262 of file conf2ael.c.

Referenced by get_start_stop().

263 {
264  return word[bitnum/bitsperword] & (1 << (bitnum % bitsperword));
265 }
short word

◆ get_start_stop()

void get_start_stop ( unsigned int *  word,
int  bitsperword,
int  totalbits,
int *  start,
int *  end 
)

Definition at line 267 of file conf2ael.c.

References bit_at().

Referenced by main().

268 {
269  int i;
270  int thisbit, thatbit = bit_at(word, bitsperword, totalbits-1);
271 
272  for (i=0; i<totalbits; i++) {
273  thisbit = bit_at(word, bitsperword, i);
274 
275  if (thisbit != thatbit ) {
276  if (thisbit) {
277  *start = i;
278  } else {
279  *end = i;
280  }
281  }
282  thatbit = thisbit;
283  }
284 }
char * end
Definition: eagi_proxy.c:73
static int bit_at(unsigned int *word, int bitsperword, int bitnum)
Definition: conf2ael.c:262
short word

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 305 of file conf2ael.c.

References ael2_print(), all_bits_set(), ast_context::alts, ast_exten::app, args, ast_config_AST_CONFIG_DIR, AST_LIST_FIRST, ast_log(), ast_strdup, config, ast_exten::data, ast_timing::daymask, days, ast_timing::dowmask, ast_exten::exten, free(), get_start_stop(), ast_include::hastime, ast_context::ignorepats, ast_context::includes, localized_pbx_load_module(), localized_use_conf_dir(), localized_walk_context_extensions(), localized_walk_context_switches(), localized_walk_contexts(), localized_walk_extension_priorities(), LOG_ERROR, min, ast_timing::minmask, ast_timing::monthmask, months, ast_sw::name, ast_include::name, ast_context::name, ast_include::next, ast_ignorepat::next, ast_ignorepat::pattern, ast_exten::peer, ast_exten::priority, PV_APPLICATION_CALL, PV_CONTEXT, PV_EXTENSION, PV_IGNOREPAT, PV_INCLUDES, PV_STATEMENTBLOCK, PV_SWITCHES, PV_WORD, pvalAppCallAddArg(), pvalAppCallSetAppName(), pvalContextAddStatement(), pvalContextSetName(), pvalCreateNode(), pvalExtenSetHints(), pvalExtenSetName(), pvalExtenSetStatement(), pvalIgnorePatSetPattern(), pvalIncludesAddInclude(), pvalIncludesAddIncludeWithTimeConstraints(), pvalStatementBlockAddStatement(), pvalSwitchesAddSwitch(), pvalTopLevAddObject(), pvalWordSetString(), strdup, ast_include::timing, and tmp().

306 {
307  struct ast_context *tmp;
308  struct ast_exten *e, *eroot;
309  pval *tree, *tmptree, *sws;
310  struct ast_include *tmpi;
311  struct ast_sw *sw = 0;
312  struct ast_ignorepat *ipi;
313  pval *incl=0;
314  int localdir = 0, i;
315 
316  tree = 0;
317  tmptree = 0;
318 
319  /* process the command line args */
320  for (i=1; i<argc; i++)
321  {
322  if (strcmp(argv[i],"-d")==0)
323  localdir =1;
324  }
325 
326  /* 3 simple steps: */
327  /* 1. read in the extensions.conf config file
328  * 2. traverse, and build an AEL tree
329  * 3. Output the AEL tree into a file
330  */
331  printf("WARNING: This is an EXTREMELY preliminary version of a program\n");
332  printf(" that will someday hopefully do a thoughful and intelligent\n");
333  printf(" job of transforming your extensions.conf file into an\n");
334  printf(" extensions.ael file.\n");
335  printf(" This version has absolutely no intelligence, and pretty\n");
336  printf(" much just does a direct conversion\n");
337  printf(" The result will most likely need careful attention to\n");
338  printf(" finish the job!!!!!\n");
339 
340  if (!localdir)
341  printf(" (You could use -d the use the extensions.conf in the current directory!)\n");
342 
343  printf("Loading %s/%s...\n", ast_config_AST_CONFIG_DIR, config);
344 
345  if (!localdir)
348 
349  printf("... Done!\n");
350 
351  tmp = 0;
352  while ((tmp = localized_walk_contexts(tmp)) ) {
353  printf("Context: %s\n", tmp->name);
354  }
355  printf("=========\n");
356  tmp = 0;
357  while ((tmp = localized_walk_contexts(tmp)) ) {
358  /* printf("Context: %s\n", tmp->name); */
359  tmptree = pvalCreateNode(PV_CONTEXT);
360  if (!tree)
361  tree = tmptree;
362  else
363  pvalTopLevAddObject(tree, tmptree);
364 
365  pvalContextSetName(tmptree, ast_strdup(tmp->name));
366 
367  if (tmp->includes) {
368  incl = pvalCreateNode(PV_INCLUDES);
369  pvalContextAddStatement(tmptree, incl);
370  for (tmpi = tmp->includes; tmpi; ) { /* includes */
371  if (strchr(tmpi->name,'|')==0) {
372  if (tmpi->hastime)
373  {
374  char timerange[15];
375  char dowrange[10];
376  char domrange[10];
377  char monrange[10];
378  int startbit=0, endbit=0;
379 
380  if (all_bits_set(tmpi->timing.minmask, 30, 720))
381  strcpy(timerange, "*");
382  else {
383  int hr, min;
384  char tbuf[20];
385  get_start_stop(tmpi->timing.minmask, 30, 720, &startbit, &endbit);
386  hr = startbit/30;
387  min = (startbit % 30) * 2;
388  sprintf(tbuf,"%02d:%02d", hr, min);
389  strcpy(timerange, tbuf);
390  hr = endbit/30;
391  min = (endbit % 30) * 2;
392  sprintf(tbuf,"%02d:%02d", hr, min);
393  strcat(timerange,"-");
394  strcat(timerange,tbuf);
395  }
396 
397  if (all_bits_set(&tmpi->timing.dowmask, 7, 7))
398  strcpy(dowrange, "*");
399  else {
400  get_start_stop(&tmpi->timing.dowmask, 7, 7, &startbit, &endbit);
401  strcpy(dowrange, days[startbit]);
402  strcat(dowrange,"-");
403  strcat(dowrange, days[endbit]);
404  }
405 
406  if (all_bits_set(&tmpi->timing.monthmask, 12, 12))
407  strcpy(monrange, "*");
408  else {
409  get_start_stop(&tmpi->timing.monthmask, 12, 12, &startbit, &endbit);
410  strcpy(monrange, months[startbit]);
411  strcat(monrange,"-");
412  strcat(monrange, months[endbit]);
413  }
414 
415  if (all_bits_set(&tmpi->timing.daymask, 31, 31))
416  strcpy(domrange, "*");
417  else {
418  char tbuf[20];
419  get_start_stop(&tmpi->timing.daymask, 31, 31, &startbit, &endbit);
420  sprintf(tbuf,"%d", startbit);
421  strcpy(domrange, tbuf);
422  strcat(domrange,"-");
423  sprintf(tbuf,"%d", endbit);
424  strcat(domrange, tbuf);
425  }
426  /* now all 4 fields are set; what do we do? */
427  pvalIncludesAddIncludeWithTimeConstraints(incl, strdup(tmpi->name), strdup(timerange), strdup(domrange), strdup(dowrange), strdup(monrange));
428 
429  } else {
430  pvalIncludesAddInclude(incl, strdup(tmpi->name));
431  }
432  } else { /* it appears the timing constraint info is tacked onto the name, carve it up and divvy it out */
433  char *dow,*dom,*mon;
434  char *all = strdup(tmpi->name);
435  char *hr = strchr(all,'|');
436  if (hr) {
437  *hr++ = 0;
438  dow = strchr(hr,'|');
439  if (dow) {
440  *dow++ = 0;
441  dom = strchr(dow,'|');
442  if (dom) {
443  *dom++ = 0;
444  mon = strchr(dom,'|');
445  if (mon) {
446  *mon++ = 0;
447  /* now all 4 fields are set; what do we do? */
448  pvalIncludesAddIncludeWithTimeConstraints(incl, strdup(all), strdup(hr), strdup(dow), strdup(dom), strdup(mon));
449  /* the original data is always best to keep (no 2-min rounding) */
450  } else {
451  ast_log(LOG_ERROR,"No month spec attached to include!\n");
452  }
453  } else {
454  ast_log(LOG_ERROR,"No day of month spec attached to include!\n");
455  }
456  } else {
457  ast_log(LOG_ERROR,"No day of week spec attached to include!\n");
458  }
459  }
460  free(all);
461  }
462  tmpi = tmpi->next;
463  }
464  }
465  for (ipi = tmp->ignorepats; ipi; ) { /* ignorepats */
467  pvalIgnorePatSetPattern(incl,(char *)ipi->pattern);
468  pvalContextAddStatement(tmptree, incl);
469  ipi = ipi->next;
470  }
471  eroot=0;
472  while ( (eroot = localized_walk_context_extensions(tmp, eroot)) ) {
474  pvalContextAddStatement(tmptree, exten);
475  pvalExtenSetName(exten, ast_strdup(eroot->exten));
476 
477  if (eroot->peer) {
479  pvalExtenSetStatement(exten, block);
480 
481  e = 0;
482  while ( (e = localized_walk_extension_priorities(eroot, e)) ) {
483 
486 
487  /* printf(" %s(%s)\n", e->app, (char*)e->data); */
488 
489  pvalAppCallSetAppName(statemnt, ast_strdup(e->app));
490  pvalWordSetString(args, ast_strdup(e->data));
491  pvalAppCallAddArg(statemnt, args);
492 
493  pvalStatementBlockAddStatement(block, statemnt);
494  }
495  } else if (eroot->priority == -1) {
496 
498  pval *args = pvalCreateNode(PV_WORD);
499 
500  /* printf("Mike, we have a hint on exten %s with data %s\n", eroot->exten, eroot->app); */
501 
502  pvalAppCallSetAppName(statemnt, "NoOp");
503  pvalWordSetString(args, ast_strdup(eroot->app));
504 
505 
506  pvalExtenSetStatement(exten, statemnt);
507  pvalExtenSetHints(exten, ast_strdup(eroot->app));
508  } else {
509 
511  pval *args = pvalCreateNode(PV_WORD);
512 
513  /* printf(" %s (%s)\n", eroot->app, (char *)eroot->data); */
514 
515  pvalAppCallSetAppName(statemnt, ast_strdup(eroot->app));
516  pvalWordSetString(args, ast_strdup(eroot->data));
517 
518 
519  pvalAppCallAddArg(statemnt, args);
520  pvalExtenSetStatement(exten, statemnt);
521  }
522 
523  /* printf(" extension: %s\n", eroot->exten); */
524  }
525  if (AST_LIST_FIRST(&tmp->alts)) {
527  pvalContextAddStatement(tmptree,sws);
528 
529  sw = 0;
530  while ((sw = localized_walk_context_switches(tmp,sw)) ) {
532  }
533  }
534  }
535  printf("Generating aelout.ael file...\n");
536 
537  ael2_print("aelout.ael", tree);
538 
539  printf("...Done!\n");
540  return 0;
541 }
ast_include: include= support in extensions.conf
Definition: pbx_include.c:37
void pvalTopLevAddObject(pval *p, pval *contextOrObj)
Definition: pval.c:5901
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
unsigned int daymask
Definition: pbx.h:174
struct ast_ignorepats ignorepats
Definition: pbx.c:291
const char pattern[0]
Definition: pbx_ignorepat.c:39
struct ast_exten * localized_walk_extension_priorities(struct ast_exten *exten, struct ast_exten *priority)
Definition: extconf.c:4071
void pvalAppCallAddArg(pval *p, pval *arg)
Definition: pval.c:5268
ast_exten: An extension The dialplan is saved as a linked list with each context having it&#39;s own link...
Definition: pbx.c:237
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:420
char * days[]
Definition: extconf.c:3777
struct ast_context * localized_walk_contexts(struct ast_context *con)
Definition: extconf.c:4032
void pvalExtenSetName(pval *p, char *name)
Definition: pval.c:5795
char * config
Definition: conf2ael.c:66
const char * name
Definition: pbx_sw.c:38
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: conf2ael.c:86
void pvalContextSetName(pval *p, char *name)
Definition: pval.c:5143
int all_bits_set(unsigned int *word, int bitsperword, int totalbits)
Definition: conf2ael.c:286
static int tmp()
Definition: bt_open.c:389
void pvalWordSetString(pval *p, char *str)
Definition: pval.c:5058
struct ast_ignorepat * next
Definition: conf2ael.c:169
void pvalIgnorePatSetPattern(pval *p, char *pat)
Definition: pval.c:5859
void pvalAppCallSetAppName(pval *p, char *name)
Definition: pval.c:5247
struct ast_exten * localized_walk_context_extensions(struct ast_context *con, struct ast_exten *exten)
Definition: extconf.c:4053
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
struct ast_include * next
Definition: conf2ael.c:151
const char * args
pval * pvalCreateNode(pvaltype type)
Definition: pval.c:5042
unsigned int minmask[48]
Definition: pbx.h:176
Definition: pval.h:8
struct ast_timing timing
Definition: pbx_include.c:46
unsigned int monthmask
Definition: pbx.h:173
int priority
Definition: pbx.c:243
struct ast_exten * peer
Definition: pbx.c:250
ast_sw: Switch statement in extensions.conf
Definition: pbx_sw.c:37
void free()
void get_start_stop(unsigned int *word, int bitsperword, int totalbits, int *start, int *end)
Definition: conf2ael.c:267
struct ast_sw * localized_walk_context_switches(struct ast_context *con, struct ast_sw *sw)
Definition: extconf.c:4152
void ael2_print(char *fname, pval *tree)
Definition: pval.c:382
struct ast_includes includes
Definition: pbx.c:290
Definition: pval.h:48
void pvalSwitchesAddSwitch(pval *p, char *name)
Definition: pval.c:5351
char * exten
Definition: pbx.c:238
unsigned int dowmask
Definition: pbx.h:175
#define LOG_ERROR
Definition: logger.h:285
char name[0]
Definition: pbx.c:297
ast_ignorepat: Ignore patterns in dial plan
Definition: pbx_ignorepat.c:37
void pvalExtenSetStatement(pval *p, pval *statement)
Definition: pval.c:5844
void pvalIncludesAddIncludeWithTimeConstraints(pval *p, const char *include, char *hour_range, char *dom_range, char *dow_range, char *month_range)
Definition: pval.c:5407
int localized_pbx_load_module(void)
Definition: extconf.c:5647
char * months[]
Definition: extconf.c:3789
const char * name
Definition: pbx_include.c:38
void pvalStatementBlockAddStatement(pval *p, pval *statement)
Definition: pval.c:5480
const char * app
Definition: pbx.c:246
void pvalIncludesAddInclude(pval *p, const char *include)
Definition: pval.c:5396
void pvalExtenSetHints(pval *p, char *hints)
Definition: pval.c:5830
void * data
Definition: pbx.c:248
const char * ast_config_AST_CONFIG_DIR
Definition: conf2ael.c:59
#define strdup(a)
Definition: astmm.h:165
struct ast_sws alts
Definition: pbx.c:292
#define min(a, b)
Definition: f2c.h:197
ast_context: An extension context - must remain in sync with fake_context
Definition: pbx.c:284
void pvalContextAddStatement(pval *p, pval *statement)
Definition: pval.c:5180
void localized_use_conf_dir(void)
Definition: extconf.c:3115

◆ pbx_builtin_setvar()

int pbx_builtin_setvar ( struct ast_channel chan,
const char *  data 
)

Parse and set a single channel variable, where the name and value are separated with an '=' character.

Note
Will lock the channel.

Definition at line 546 of file conf2ael.c.

References c, localized_pbx_builtin_setvar(), and pbx_substitute_variables_helper().

Referenced by ast_compile_ael2().

547 {
548  return localized_pbx_builtin_setvar(chan, data);
549 }
int localized_pbx_builtin_setvar(struct ast_channel *chan, const void *data)
Definition: extconf.c:2607

◆ pbx_find_extension()

struct ast_exten* pbx_find_extension ( struct ast_channel chan,
struct ast_context bypass,
struct pbx_find_info q,
const char *  context,
const char *  exten,
int  priority,
const char *  label,
const char *  callerid,
enum ext_match_t  action 
)

Definition at line 672 of file conf2ael.c.

References ast_hashtab_compare_contexts(), and localized_find_extension().

Referenced by add_extension(), ast_sip_persistent_endpoint_update_state(), ast_walk_context_includes(), check_goto(), check_pval_item(), conf_ended(), delete_extens(), parking_blind_transfer_park(), parking_duration_callback(), parking_is_exten_park(), parking_lot_cfg_create_extensions(), register_peer_exten(), and test_exten().

681 {
682  return localized_find_extension(bypass, q, context, exten, priority, label, callerid, action);
683 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
struct ast_exten * localized_find_extension(struct ast_context *bypass, struct pbx_find_info *q, const char *context, const char *exten, int priority, const char *label, const char *callerid, enum ext_match_t action)
Definition: extconf.c:4470
static int priority
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

◆ pbx_substitute_variables_helper()

void pbx_substitute_variables_helper ( struct ast_channel c,
const char *  cp1,
char *  cp2,
int  count 
)

Definition at line 552 of file conf2ael.c.

References AST_MAX_EXTENSION.

Referenced by add_extensions(), ast_add_extension2_lockopt(), escape_and_substitute(), function_eval(), get_mapping_weight(), import_helper(), launch_monitor_thread(), load_values_config(), manager_log(), pbx_builtin_importvar(), pbx_builtin_setvar(), pbx_extension_helper(), pbx_find_extension(), pbx_load_config(), realtime_exec(), rotate_file(), substituted(), test_chan_function(), test_chan_integer(), test_chan_integer_accessor(), test_chan_string(), test_chan_variable(), and write_cel().

553 {
554  if (cp1 && *cp1)
555  strncpy(cp2,cp1,AST_MAX_EXTENSION); /* Right now, this routine is ONLY being called for
556  a possible var substitution on extension names,
557  so....! */
558  else
559  *cp2 = 0;
560 }
#define AST_MAX_EXTENSION
Definition: channel.h:135

Variable Documentation

◆ ast_config_AST_CONFIG_DIR

const char* ast_config_AST_CONFIG_DIR = "/etc/asterisk"

◆ config

char* config = "extensions.conf"

Definition at line 66 of file conf2ael.c.

Referenced by __ast_sorcery_apply_config(), apply_list_configuration(), ast_ari_asterisk_get_info(), ast_ari_websocket_session_create(), ast_cel_set_config(), ast_config_new(), AST_TEST_DEFINE(), ast_variable_append(), asterisk_publication_config_alloc(), asterisk_publication_config_destroy(), asterisk_publication_devicestate_state_change(), asterisk_publication_mwi_state_change(), asterisk_publication_new(), config_alloc(), config_can_be_inherited(), custom_log(), do_reload(), hep_queue_cb(), hepv3_config_alloc(), hepv3_config_dtor(), hepv3_config_pre_apply(), hepv3_get_uuid_type(), hepv3_is_loaded(), hepv3_send_packet(), load_config(), load_module(), load_odbc_config(), load_pktccops_config(), main(), misdn_cfg_init(), module_config_alloc(), module_config_dtor(), parse_config(), process_config(), prometheus_config_pre_apply(), prometheus_general_config_alloc(), prometheus_general_config_dtor(), prometheus_show_status(), realtime_sqlite3_load(), regex_filter_handler(), reload_config(), reload_module(), send_refresh_cb(), sorcery_config_close(), sorcery_config_destructor(), sorcery_config_internal_load(), sorcery_config_open(), sorcery_config_retrieve_fields(), sorcery_config_retrieve_id(), sorcery_config_retrieve_multiple(), sorcery_config_retrieve_prefix(), sorcery_config_retrieve_regex(), sorcery_realtime_create(), sorcery_realtime_delete(), sorcery_realtime_open(), sorcery_realtime_retrieve_fields(), sorcery_realtime_retrieve_multiple(), and sorcery_realtime_update().

◆ contexts

static struct ast_context * contexts

Definition at line 4483 of file extconf.c.

Referenced by AST_TEST_DEFINE().

◆ days

char* days[]

Definition at line 3777 of file extconf.c.

Referenced by main().

◆ local_contexts

struct ast_context* local_contexts

◆ months

char* months[]

Definition at line 3789 of file extconf.c.

Referenced by main().