2 * Asterisk -- A telephony toolkit for Linux.
4 * Core PBX routines and definitions.
6 * Copyright (C) 1999, Mark Spencer
8 * Mark Spencer <markster@linux-support.net>
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License
13 #ifndef _ASTERISK_PBX_H
14 #define _ASTERISK_PBX_H
16 #include <asterisk/sched.h>
17 #include <asterisk/channel.h>
19 #if defined(__cplusplus) || defined(c_plusplus)
23 #define AST_PBX_KEEP 0
24 #define AST_PBX_REPLACE 1
26 /* Max length of an application */
27 #define AST_MAX_APP 32
29 /* Special return values from applications to the PBX */
30 #define AST_PBX_KEEPALIVE 10 /* Destroy the thread, but don't hang up the channel */
39 struct ast_switch *next; /* NULL */
40 char *name; /* Name of the switch */
41 char *description; /* Description of the switch */
42 int (*exists)(struct ast_channel *chan, char *context, char *exten, int priority, char *callerid, char *data);
43 int (*canmatch)(struct ast_channel *chan, char *context, char *exten, int priority, char *callerid, char *data);
44 int (*exec)(struct ast_channel *chan, char *context, char *exten, int priority, char *callerid, int newstack, char *data);
47 /* Register an alternative switch */
48 extern int ast_register_switch(struct ast_switch *sw);
50 /* Unregister an alternative switch */
51 extern void ast_unregister_switch(struct ast_switch *sw);
53 /* Look up an application */
54 extern struct ast_app *pbx_findapp(char *app);
56 int pbx_exec(struct ast_channel *c, struct ast_app *app, void *data, int newstack);
58 /* Register a new context */
59 struct ast_context *ast_context_create(char *name, char *registrar);
61 /* Destroy a context (matches the specified context (or ANY context if
63 void ast_context_destroy(struct ast_context *, char *registrar);
66 struct ast_context *ast_context_find(char *name);
68 /* Create a new thread and start the PBX (or whatever) */
69 int ast_pbx_start(struct ast_channel *c);
71 /* Execute the PBX in the current thread */
72 int ast_pbx_run(struct ast_channel *c);
74 /* Add and extension to an extension context. Callerid is a pattern to match CallerID, or NULL to match any
76 int ast_add_extension(char *context, int replace, char *extension, int priority, char *callerid,
77 char *application, void *data, void (*datad)(void *), char *registrar);
79 /* Add an extension to an extension context, this time with an ast_context *. CallerID is a pattern to match
80 on callerid, or NULL to not care about callerid */
81 int ast_add_extension2(struct ast_context *con,
82 int replace, char *extension, int priority, char *callerid,
83 char *application, void *data, void (*datad)(void *),
86 /* Add an application. The function 'execute' should return non-zero if the line needs to be hung up.
87 Include a one-line synopsis (e.g. 'hangs up a channel') and a more lengthy, multiline
88 description with more detail, including under what conditions the application
89 will return 0 or -1. */
90 int ast_register_application(char *app, int (*execute)(struct ast_channel *, void *),
91 char *synopsis, char *description);
93 /* Remove an application */
94 int ast_unregister_application(char *app);
96 /* If an extension exists, return non-zero */
97 int ast_exists_extension(struct ast_channel *c, char *context, char *exten, int priority, char *callerid);
99 /* If "exten" *could be* a valid extension in this context with or without
100 some more digits, return non-zero. Basically, when this returns 0, no matter
101 what you add to exten, it's not going to be a valid extension anymore */
102 int ast_canmatch_extension(struct ast_channel *c, char *context, char *exten, int priority, char *callerid);
104 /* Determine if a given extension matches a given pattern (in NXX format) */
105 int ast_extension_match(char *pattern, char *extension);
107 /* Launch a new extension (i.e. new stack) */
108 int ast_spawn_extension(struct ast_channel *c, char *context, char *exten, int priority, char *callerid);
110 /* Execute an extension. If it's not available, do whatever you should do for
111 default extensions and halt the thread if necessary. This function does not
112 return, except on error. */
113 int ast_exec_extension(struct ast_channel *c, char *context, char *exten, int priority, char *callerid);
116 int ast_context_add_include(char *context, char *include, char *registrar);
117 int ast_context_add_include2(struct ast_context *con, char *include, char *registrar);
119 /* Remove an include */
120 int ast_context_remove_include(char *context, char *include, char *registrar);
121 int ast_context_remove_include2(struct ast_context *con, char *include, char *registrar);
124 int ast_context_add_switch(char *context, char *sw, char *data, char *registrar);
125 int ast_context_add_switch2(struct ast_context *con, char *sw, char *data, char *registrar);
127 /* Remove a switch */
128 int ast_context_remove_switch(char *context, char *sw, char *data, char *registrar);
129 int ast_context_remove_switch2(struct ast_context *con, char *sw, char *data, char *registrar);
131 /* Simply remove extension from context */
132 int ast_context_remove_extension(char *context, char *extension, int priority,
134 int ast_context_remove_extension2(struct ast_context *con, char *extension,
135 int priority, char *registrar);
137 /* Add an ignorepat */
138 int ast_context_add_ignorepat(char *context, char *ignorepat, char *registrar);
139 int ast_context_add_ignorepat2(struct ast_context *con, char *ignorepat, char *registrar);
141 /* Remove an ignorepat */
142 int ast_context_remove_ignorepat(char *context, char *ignorepat, char *registrar);
143 int ast_context_remove_ignorepat2(struct ast_context *con, char *ignorepat, char *registrar);
145 /* Check if a number should be ignored with respect to dialtone cancellation. Returns 0 if
146 the pattern should not be ignored, or non-zero if the pattern should be ignored */
147 int ast_ignore_pattern(char *context, char *pattern);
149 /* Locking functions for outer modules, especially for completion functions */
150 int ast_lock_contexts(void);
151 int ast_unlock_contexts(void);
153 int ast_lock_context(struct ast_context *con);
154 int ast_unlock_context(struct ast_context *con);
156 /* Functions for returning values from structures */
157 char *ast_get_context_name(struct ast_context *con);
158 char *ast_get_extension_name(struct ast_exten *exten);
159 char *ast_get_include_name(struct ast_include *include);
160 char *ast_get_ignorepat_name(struct ast_ignorepat *ip);
161 char *ast_get_switch_name(struct ast_sw *sw);
162 char *ast_get_switch_data(struct ast_sw *sw);
164 /* Other extension stuff */
165 int ast_get_extension_priority(struct ast_exten *exten);
166 char *ast_get_extension_app(struct ast_exten *e);
167 void *ast_get_extension_app_data(struct ast_exten *e);
169 /* Registrar info functions ... */
170 char *ast_get_context_registrar(struct ast_context *c);
171 char *ast_get_extension_registrar(struct ast_exten *e);
172 char *ast_get_include_registrar(struct ast_include *i);
173 char *ast_get_ignorepat_registrar(struct ast_ignorepat *ip);
174 char *ast_get_switch_registrar(struct ast_sw *sw);
176 /* Walking functions ... */
177 struct ast_context *ast_walk_contexts(struct ast_context *con);
178 struct ast_exten *ast_walk_context_extensions(struct ast_context *con,
179 struct ast_exten *priority);
180 struct ast_exten *ast_walk_extension_priorities(struct ast_exten *exten,
181 struct ast_exten *priority);
182 struct ast_include *ast_walk_context_includes(struct ast_context *con,
183 struct ast_include *inc);
184 struct ast_ignorepat *ast_walk_context_ignorepats(struct ast_context *con,
185 struct ast_ignorepat *ip);
186 struct ast_sw *ast_walk_context_switches(struct ast_context *con, struct ast_sw *sw);
187 #if defined(__cplusplus) || defined(c_plusplus)