pbx.h 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2006, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. * \brief Core PBX routines and definitions.
  20. */
  21. #ifndef _ASTERISK_PBX_H
  22. #define _ASTERISK_PBX_H
  23. #include "asterisk/channel.h"
  24. #include "asterisk/sched.h"
  25. #include "asterisk/devicestate.h"
  26. #include "asterisk/presencestate.h"
  27. #include "asterisk/chanvars.h"
  28. #include "asterisk/hashtab.h"
  29. #include "asterisk/stringfields.h"
  30. #include "asterisk/xmldoc.h"
  31. #include "asterisk/format.h"
  32. #if defined(__cplusplus) || defined(c_plusplus)
  33. extern "C" {
  34. #endif
  35. #define AST_MAX_APP 32 /*!< Max length of an application */
  36. #define AST_PBX_GOTO_FAILED -3
  37. #define AST_PBX_KEEP 0
  38. #define AST_PBX_REPLACE 1
  39. /*! \brief Special return values from applications to the PBX
  40. * @{ */
  41. #define AST_PBX_HANGUP -1 /*!< Jump to the 'h' exten */
  42. #define AST_PBX_OK 0 /*!< No errors */
  43. #define AST_PBX_ERROR 1 /*!< Jump to the 'e' exten */
  44. #define AST_PBX_INCOMPLETE 12 /*!< Return to PBX matching, allowing more digits for the extension */
  45. /*! @} */
  46. #define PRIORITY_HINT -1 /*!< Special Priority for a hint */
  47. /*!
  48. * \brief Extension states
  49. * \note States can be combined
  50. * \ref AstExtState
  51. */
  52. enum ast_extension_states {
  53. AST_EXTENSION_REMOVED = -2, /*!< Extension removed */
  54. AST_EXTENSION_DEACTIVATED = -1, /*!< Extension hint removed */
  55. AST_EXTENSION_NOT_INUSE = 0, /*!< No device INUSE or BUSY */
  56. AST_EXTENSION_INUSE = 1 << 0, /*!< One or more devices INUSE */
  57. AST_EXTENSION_BUSY = 1 << 1, /*!< All devices BUSY */
  58. AST_EXTENSION_UNAVAILABLE = 1 << 2, /*!< All devices UNAVAILABLE/UNREGISTERED */
  59. AST_EXTENSION_RINGING = 1 << 3, /*!< All devices RINGING */
  60. AST_EXTENSION_ONHOLD = 1 << 4, /*!< All devices ONHOLD */
  61. };
  62. /*!
  63. * \brief extension matchcid types
  64. * \note matchcid in ast_exten retains 0/1, this adds 3rd state for functions to specify all
  65. * \see ast_context_remove_extension_callerid
  66. */
  67. enum ast_ext_matchcid_types {
  68. AST_EXT_MATCHCID_OFF = 0, /*!< Match only extensions with matchcid=0 */
  69. AST_EXT_MATCHCID_ON = 1, /*!< Match only extensions with matchcid=1 AND cidmatch matches */
  70. AST_EXT_MATCHCID_ANY = 2, /*!< Match both - used only in functions manipulating ast_exten's */
  71. };
  72. struct ast_context;
  73. struct ast_exten;
  74. struct ast_include;
  75. struct ast_ignorepat;
  76. struct ast_sw;
  77. enum ast_state_cb_update_reason {
  78. /*! The extension state update is a result of a device state changing on the extension. */
  79. AST_HINT_UPDATE_DEVICE = 1,
  80. /*! The extension state update is a result of presence state changing on the extension. */
  81. AST_HINT_UPDATE_PRESENCE = 2,
  82. };
  83. struct ast_device_state_info {
  84. enum ast_device_state device_state;
  85. struct ast_channel *causing_channel;
  86. char device_name[1];
  87. };
  88. struct ast_state_cb_info {
  89. enum ast_state_cb_update_reason reason;
  90. enum ast_extension_states exten_state;
  91. struct ao2_container *device_state_info; /* holds ast_device_state_info, must be referenced by callback if stored */
  92. enum ast_presence_state presence_state;
  93. const char *presence_subtype;
  94. const char *presence_message;
  95. };
  96. /*! \brief Typedef for devicestate and hint callbacks */
  97. typedef int (*ast_state_cb_type)(char *context, char *id, struct ast_state_cb_info *info, void *data);
  98. /*! \brief Typedef for devicestate and hint callback removal indication callback */
  99. typedef void (*ast_state_cb_destroy_type)(int id, void *data);
  100. /*! \brief Data structure associated with a custom dialplan function */
  101. struct ast_custom_function {
  102. const char *name; /*!< Name */
  103. AST_DECLARE_STRING_FIELDS(
  104. AST_STRING_FIELD(synopsis); /*!< Synopsis text for 'show functions' */
  105. AST_STRING_FIELD(desc); /*!< Description (help text) for 'show functions &lt;name&gt;' */
  106. AST_STRING_FIELD(syntax); /*!< Syntax text for 'core show functions' */
  107. AST_STRING_FIELD(arguments); /*!< Arguments description */
  108. AST_STRING_FIELD(seealso); /*!< See also */
  109. );
  110. enum ast_doc_src docsrc; /*!< Where the documentation come from */
  111. /*! Read function, if read is supported */
  112. ast_acf_read_fn_t read; /*!< Read function, if read is supported */
  113. /*! Read function, if read is supported. Note: only one of read or read2
  114. * needs to be implemented. In new code, read2 should be implemented as
  115. * the way forward, but they should return identical results, within the
  116. * constraints of buffer size, if both are implemented. That is, if the
  117. * read function is handed a 16-byte buffer, and the result is 17 bytes
  118. * long, then the first 15 bytes (remember NULL terminator) should be
  119. * the same for both the read and the read2 methods. */
  120. ast_acf_read2_fn_t read2;
  121. /*! If no read2 function is provided, what maximum size? */
  122. size_t read_max;
  123. /*! Write function, if write is supported */
  124. ast_acf_write_fn_t write; /*!< Write function, if write is supported */
  125. struct ast_module *mod; /*!< Module this custom function belongs to */
  126. unsigned int read_escalates:1; /*!< The read function is to be considered
  127. * 'dangerous', and should not be run directly
  128. * from external interfaces (AMI, ARI, etc.)
  129. * \since 12 */
  130. unsigned int write_escalates:1; /*!< The write function is to be considerd
  131. * 'dangerous', and should not be run directly
  132. * from external interfaces (AMI, ARI, etc.)
  133. * \since 12 */
  134. AST_RWLIST_ENTRY(ast_custom_function) acflist;
  135. };
  136. /*! \brief All switch functions have the same interface, so define a type for them */
  137. typedef int (ast_switch_f)(struct ast_channel *chan, const char *context,
  138. const char *exten, int priority, const char *callerid, const char *data);
  139. /*!< Data structure associated with an Asterisk switch */
  140. struct ast_switch {
  141. AST_LIST_ENTRY(ast_switch) list;
  142. const char *name; /*!< Name of the switch */
  143. const char *description; /*!< Description of the switch */
  144. ast_switch_f *exists;
  145. ast_switch_f *canmatch;
  146. ast_switch_f *exec;
  147. ast_switch_f *matchmore;
  148. };
  149. struct ast_timing {
  150. int hastime; /*!< If time construct exists */
  151. unsigned int monthmask; /*!< Mask for month */
  152. unsigned int daymask; /*!< Mask for date */
  153. unsigned int dowmask; /*!< Mask for day of week (sun-sat) */
  154. unsigned int minmask[48]; /*!< Mask for minute */
  155. char *timezone; /*!< NULL, or zoneinfo style timezone */
  156. };
  157. /*!
  158. * \brief Construct a timing bitmap, for use in time-based conditionals.
  159. * \param i Pointer to an ast_timing structure.
  160. * \param info Standard string containing a timerange, weekday range, monthday range, and month range, as well as an optional timezone.
  161. * \retval Returns 1 on success or 0 on failure.
  162. */
  163. int ast_build_timing(struct ast_timing *i, const char *info);
  164. /*!
  165. * \brief Evaluate a pre-constructed bitmap as to whether the current time falls within the range specified.
  166. * \param i Pointer to an ast_timing structure.
  167. * \retval Returns 1, if the time matches or 0, if the current time falls outside of the specified range.
  168. */
  169. int ast_check_timing(const struct ast_timing *i);
  170. /*!
  171. * \brief Evaluate a pre-constructed bitmap as to whether a particular time falls within the range specified.
  172. * \param i Pointer to an ast_timing structure.
  173. * \param tv Specified time
  174. * \retval Returns 1, if the time matches or 0, if the time falls outside of the specified range.
  175. */
  176. int ast_check_timing2(const struct ast_timing *i, const struct timeval tv);
  177. /*!
  178. * \brief Deallocates memory structures associated with a timing bitmap.
  179. * \param i Pointer to an ast_timing structure.
  180. * \retval 0 success
  181. * \retval non-zero failure (number suitable to pass to \see strerror)
  182. */
  183. int ast_destroy_timing(struct ast_timing *i);
  184. struct ast_pbx {
  185. int dtimeoutms; /*!< Timeout between digits (milliseconds) */
  186. int rtimeoutms; /*!< Timeout for response (milliseconds) */
  187. };
  188. /*!
  189. * \brief Register an alternative dialplan switch
  190. *
  191. * \param sw switch to register
  192. *
  193. * This function registers a populated ast_switch structure with the
  194. * asterisk switching architecture.
  195. *
  196. * \retval 0 success
  197. * \retval non-zero failure
  198. */
  199. int ast_register_switch(struct ast_switch *sw);
  200. /*!
  201. * \brief Unregister an alternative switch
  202. *
  203. * \param sw switch to unregister
  204. *
  205. * Unregisters a switch from asterisk.
  206. *
  207. * \return nothing
  208. */
  209. void ast_unregister_switch(struct ast_switch *sw);
  210. /*!
  211. * \brief Look up an application
  212. *
  213. * \param app name of the app
  214. *
  215. * This function searches for the ast_app structure within
  216. * the apps that are registered for the one with the name
  217. * you passed in.
  218. *
  219. * \return the ast_app structure that matches on success, or NULL on failure
  220. */
  221. struct ast_app *pbx_findapp(const char *app);
  222. /*!
  223. * \brief Execute an application
  224. *
  225. * \param c channel to execute on
  226. * \param app which app to execute
  227. * \param data the data passed into the app
  228. *
  229. * This application executes an application on a given channel. It
  230. * saves the stack and executes the given application passing in
  231. * the given data.
  232. *
  233. * \retval 0 success
  234. * \retval -1 failure
  235. */
  236. int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data);
  237. /*!
  238. * \brief Register a new context or find an existing one
  239. *
  240. * \param extcontexts pointer to the ast_context structure pointer
  241. * \param exttable pointer to the hashtable that contains all the elements in extcontexts
  242. * \param name name of the new context
  243. * \param registrar registrar of the context
  244. *
  245. * This function allows you to play in two environments: the global contexts (active dialplan)
  246. * or an external context set of your choosing. To act on the external set, make sure extcontexts
  247. * and exttable are set; for the globals, make sure both extcontexts and exttable are NULL.
  248. *
  249. * This will first search for a context with your name. If it exists already, it will not
  250. * create a new one. If it does not exist, it will create a new one with the given name
  251. * and registrar.
  252. *
  253. * \return NULL on failure, and an ast_context structure on success
  254. */
  255. struct ast_context *ast_context_find_or_create(struct ast_context **extcontexts, struct ast_hashtab *exttable, const char *name, const char *registrar);
  256. /*!
  257. * \brief Merge the temporary contexts into a global contexts list and delete from the
  258. * global list the ones that are being added
  259. *
  260. * \param extcontexts pointer to the ast_context structure
  261. * \param exttable pointer to the ast_hashtab structure that contains all the elements in extcontexts
  262. * \param registrar of the context; if it's set the routine will delete all contexts
  263. * that belong to that registrar; if NULL only the contexts that are specified
  264. * in extcontexts
  265. */
  266. void ast_merge_contexts_and_delete(struct ast_context **extcontexts, struct ast_hashtab *exttable, const char *registrar);
  267. /*!
  268. * \brief Destroy a context by name
  269. *
  270. * \param context Name of the context to destroy
  271. * \param registrar who registered it
  272. *
  273. * You can optionally leave out the registrar parameter. It will find it
  274. * based on the context name.
  275. *
  276. * \retval -1 context not found
  277. * \retval 0 Success
  278. */
  279. int ast_context_destroy_by_name(const char *context, const char *registrar);
  280. /*!
  281. * \brief Destroy a context (matches the specified context or ANY context if NULL)
  282. *
  283. * \param con context to destroy
  284. * \param registrar who registered it
  285. *
  286. * You can optionally leave out either parameter. It will find it
  287. * based on either the ast_context or the registrar name.
  288. *
  289. * \return nothing
  290. */
  291. void ast_context_destroy(struct ast_context *con, const char *registrar);
  292. /*!
  293. * \brief Find a context
  294. *
  295. * \param name name of the context to find
  296. *
  297. * Will search for the context with the given name.
  298. *
  299. * \return the ast_context on success, NULL on failure.
  300. */
  301. struct ast_context *ast_context_find(const char *name);
  302. /*!
  303. * \brief The result codes when starting the PBX on a channel with ast_pbx_start.
  304. * \note AST_PBX_CALL_LIMIT refers to the maxcalls call limit in asterisk.conf
  305. * \see ast_pbx_start
  306. */
  307. enum ast_pbx_result {
  308. AST_PBX_SUCCESS = 0,
  309. AST_PBX_FAILED = -1,
  310. AST_PBX_CALL_LIMIT = -2,
  311. };
  312. /*!
  313. * \brief Create a new thread and start the PBX
  314. *
  315. * \param c channel to start the pbx on
  316. *
  317. * \see ast_pbx_run for a synchronous function to run the PBX in the
  318. * current thread, as opposed to starting a new one.
  319. *
  320. * \retval Zero on success
  321. * \retval non-zero on failure
  322. */
  323. enum ast_pbx_result ast_pbx_start(struct ast_channel *c);
  324. /*!
  325. * \brief Execute the PBX in the current thread
  326. *
  327. * \param c channel to run the pbx on
  328. *
  329. * This executes the PBX on a given channel. It allocates a new
  330. * PBX structure for the channel, and provides all PBX functionality.
  331. * See ast_pbx_start for an asynchronous function to run the PBX in a
  332. * new thread as opposed to the current one.
  333. *
  334. * \retval Zero on success
  335. * \retval non-zero on failure
  336. */
  337. enum ast_pbx_result ast_pbx_run(struct ast_channel *c);
  338. /*!
  339. * \brief Options for ast_pbx_run()
  340. */
  341. struct ast_pbx_args {
  342. union {
  343. /*! Pad this out so that we have plenty of room to add options
  344. * but still maintain ABI compatibility over time. */
  345. uint64_t __padding;
  346. struct {
  347. /*! Do not hangup the channel when the PBX is complete. */
  348. unsigned int no_hangup_chan:1;
  349. };
  350. };
  351. };
  352. /*!
  353. * \brief Execute the PBX in the current thread
  354. *
  355. * \param c channel to run the pbx on
  356. * \param args options for the pbx
  357. *
  358. * This executes the PBX on a given channel. It allocates a new
  359. * PBX structure for the channel, and provides all PBX functionality.
  360. * See ast_pbx_start for an asynchronous function to run the PBX in a
  361. * new thread as opposed to the current one.
  362. *
  363. * \retval Zero on success
  364. * \retval non-zero on failure
  365. */
  366. enum ast_pbx_result ast_pbx_run_args(struct ast_channel *c, struct ast_pbx_args *args);
  367. /*!
  368. * \brief Run the h exten from the given context.
  369. * \since 11.0
  370. *
  371. * \param chan Channel to run the h exten on.
  372. * \param context Context the h exten is in.
  373. *
  374. * \return Nothing
  375. */
  376. void ast_pbx_h_exten_run(struct ast_channel *chan, const char *context);
  377. /*!
  378. * \brief Run all hangup handlers on the channel.
  379. * \since 11.0
  380. *
  381. * \param chan Channel to run the hangup handlers on.
  382. *
  383. * \note Absolutely _NO_ channel locks should be held before calling this function.
  384. *
  385. * \retval Zero if no hangup handlers run.
  386. * \retval non-zero if hangup handlers were run.
  387. */
  388. int ast_pbx_hangup_handler_run(struct ast_channel *chan);
  389. /*!
  390. * \brief Init the hangup handler container on a channel.
  391. * \since 11.0
  392. *
  393. * \param chan Channel to init the hangup handler container on.
  394. *
  395. * \return Nothing
  396. */
  397. void ast_pbx_hangup_handler_init(struct ast_channel *chan);
  398. /*!
  399. * \brief Destroy the hangup handler container on a channel.
  400. * \since 11.0
  401. *
  402. * \param chan Channel to destroy the hangup handler container on.
  403. *
  404. * \return Nothing
  405. */
  406. void ast_pbx_hangup_handler_destroy(struct ast_channel *chan);
  407. /*!
  408. * \brief Pop the top of the channel hangup handler stack.
  409. * \since 11.0
  410. *
  411. * \param chan Channel to push the hangup handler onto.
  412. *
  413. * \retval TRUE if a handler was popped off of the stack.
  414. */
  415. int ast_pbx_hangup_handler_pop(struct ast_channel *chan);
  416. /*!
  417. * \brief Push the given hangup handler onto the channel hangup handler stack.
  418. * \since 11.0
  419. *
  420. * \param chan Channel to push the hangup handler onto.
  421. * \param handler Gosub application parameter string.
  422. *
  423. * \return Nothing
  424. */
  425. void ast_pbx_hangup_handler_push(struct ast_channel *chan, const char *handler);
  426. /*!
  427. * \brief Add and extension to an extension context.
  428. *
  429. * \param context context to add the extension to
  430. * \param replace
  431. * \param extension extension to add
  432. * \param priority priority level of extension addition
  433. * \param label extension label
  434. * \param callerid pattern to match CallerID, or NULL to match any CallerID
  435. * \param application application to run on the extension with that priority level
  436. * \param data data to pass to the application
  437. * \param datad
  438. * \param registrar who registered the extension
  439. *
  440. * \retval 0 success
  441. * \retval -1 failure
  442. */
  443. int ast_add_extension(const char *context, int replace, const char *extension,
  444. int priority, const char *label, const char *callerid,
  445. const char *application, void *data, void (*datad)(void *), const char *registrar);
  446. /*!
  447. * \brief Add an extension to an extension context, this time with an ast_context *.
  448. *
  449. * \note For details about the arguments, check ast_add_extension()
  450. */
  451. int ast_add_extension2(struct ast_context *con, int replace, const char *extension,
  452. int priority, const char *label, const char *callerid,
  453. const char *application, void *data, void (*datad)(void *), const char *registrar);
  454. /*!
  455. * \brief Same as ast_add_extension2, but assumes you have already locked context
  456. * \since 12.0.0
  457. *
  458. * \note con must be write locked prior to calling. For details about the arguments,
  459. * check ast_add_extension2()
  460. */
  461. int ast_add_extension2_nolock(struct ast_context *con, int replace, const char *extension,
  462. int priority, const char *label, const char *callerid,
  463. const char *application, void *data, void (*datad)(void *), const char *registrar);
  464. /*!
  465. * \brief Map devstate to an extension state.
  466. *
  467. * \param[in] devstate device state
  468. *
  469. * \return the extension state mapping.
  470. */
  471. enum ast_extension_states ast_devstate_to_extenstate(enum ast_device_state devstate);
  472. /*!
  473. * \brief Uses hint and devicestate callback to get the state of an extension
  474. *
  475. * \param c this is not important
  476. * \param context which context to look in
  477. * \param exten which extension to get state
  478. *
  479. * \return extension state as defined in the ast_extension_states enum
  480. */
  481. int ast_extension_state(struct ast_channel *c, const char *context, const char *exten);
  482. /*!
  483. * \brief Uses hint and devicestate callback to get the extended state of an extension
  484. * \since 11
  485. *
  486. * \param c this is not important
  487. * \param context which context to look in
  488. * \param exten which extension to get state
  489. * \param[out] device_state_info ptr to an ao2_container with extended state info, must be unref'd after use.
  490. *
  491. * \return extension state as defined in the ast_extension_states enum
  492. */
  493. int ast_extension_state_extended(struct ast_channel *c, const char *context, const char *exten,
  494. struct ao2_container **device_state_info);
  495. /*!
  496. * \brief Uses hint and presence state callback to get the presence state of an extension
  497. *
  498. * \param c this is not important
  499. * \param context which context to look in
  500. * \param exten which extension to get state
  501. * \param[out] subtype Further information regarding the presence returned
  502. * \param[out] message Custom message further describing current presence
  503. *
  504. * \note The subtype and message are dynamically allocated and must be freed by
  505. * the caller of this function.
  506. *
  507. * \return returns the presence state value.
  508. */
  509. int ast_hint_presence_state(struct ast_channel *c, const char *context, const char *exten, char **subtype, char **message);
  510. /*!
  511. * \brief Return string representation of the state of an extension
  512. *
  513. * \param extension_state is the numerical state delivered by ast_extension_state
  514. *
  515. * \return the state of an extension as string
  516. */
  517. const char *ast_extension_state2str(int extension_state);
  518. /*!
  519. * \brief Add watcher for extension states with destructor.
  520. * \since 1.8.9
  521. * \since 10.1.0
  522. *
  523. * \param context which context to look in
  524. * \param exten which extension to get state
  525. * \param change_cb callback to call if state changed
  526. * \param destroy_cb callback to call when the watcher is destroyed.
  527. * \param data to pass to callbacks
  528. *
  529. * \note If context and exten are NULL then the added watcher is global.
  530. * The change_cb is called for every extension's state change.
  531. *
  532. * \note The change_cb is called if the state of an extension is changed.
  533. *
  534. * \note The destroy_cb is called when the watcher is deleted so the
  535. * watcher can release any associated resources.
  536. *
  537. * \retval -1 on failure
  538. * \retval 0 Global watcher added successfully
  539. * \retval ID on success
  540. */
  541. int ast_extension_state_add_destroy(const char *context, const char *exten,
  542. ast_state_cb_type change_cb, ast_state_cb_destroy_type destroy_cb, void *data);
  543. /*!
  544. * \brief Add watcher for extended extension states with destructor.
  545. * \since 11
  546. *
  547. * \param context which context to look in
  548. * \param exten which extension to get state
  549. * \param change_cb callback to call if state changed
  550. * \param destroy_cb callback to call when the watcher is destroyed.
  551. * \param data to pass to callbacks
  552. *
  553. * \note If context and exten are NULL then the added watcher is global.
  554. * The change_cb is called for every extension's state change.
  555. *
  556. * \note The change_cb is called if the state of an extension is changed.
  557. * The extended state is passed to the callback in the device_state_info
  558. * member of ast_state_cb_info.
  559. *
  560. * \note The destroy_cb is called when the watcher is deleted so the
  561. * watcher can release any associated resources.
  562. *
  563. * \retval -1 on failure
  564. * \retval 0 Global watcher added successfully
  565. * \retval ID on success
  566. */
  567. int ast_extension_state_add_destroy_extended(const char *context, const char *exten,
  568. ast_state_cb_type change_cb, ast_state_cb_destroy_type destroy_cb, void *data);
  569. /*!
  570. * \brief Add watcher for extension states.
  571. *
  572. * \param context which context to look in
  573. * \param exten which extension to get state
  574. * \param change_cb callback to call if state changed
  575. * \param data to pass to callback
  576. *
  577. * \note If context and exten are NULL then the added watcher is global.
  578. * The change_cb is called for every extension's state change.
  579. *
  580. * \note The change_cb is called if the state of an extension is changed.
  581. *
  582. * \retval -1 on failure
  583. * \retval 0 Global watcher added successfully
  584. * \retval ID on success
  585. */
  586. int ast_extension_state_add(const char *context, const char *exten,
  587. ast_state_cb_type change_cb, void *data);
  588. /*!
  589. * \brief Add watcher for extended extension states.
  590. * \since 11
  591. *
  592. * \param context which context to look in
  593. * \param exten which extension to get state
  594. * \param change_cb callback to call if state changed
  595. * \param data to pass to callback
  596. *
  597. * \note If context and exten are NULL then the added watcher is global.
  598. * The change_cb is called for every extension's state change.
  599. *
  600. * \note The change_cb is called if the state of an extension is changed.
  601. * The extended state is passed to the callback in the device_state_info
  602. * member of ast_state_cb_info.
  603. *
  604. * \retval -1 on failure
  605. * \retval 0 Global watcher added successfully
  606. * \retval ID on success
  607. */
  608. int ast_extension_state_add_extended(const char *context, const char *exten,
  609. ast_state_cb_type change_cb, void *data);
  610. /*!
  611. * \brief Deletes a state change watcher by ID
  612. *
  613. * \param id of the state watcher to delete (0 for global watcher)
  614. * \param change_cb callback to call if state changed (Used if id == 0 (global))
  615. *
  616. * \retval 0 success
  617. * \retval -1 failure
  618. */
  619. int ast_extension_state_del(int id, ast_state_cb_type change_cb);
  620. /*!
  621. * \brief If an extension hint exists, return non-zero
  622. *
  623. * \param hint buffer for hint
  624. * \param hintsize size of hint buffer, in bytes
  625. * \param name buffer for name portion of hint
  626. * \param namesize size of name buffer
  627. * \param c Channel from which to return the hint. This is only important when the hint or name contains an expression to be expanded.
  628. * \param context which context to look in
  629. * \param exten which extension to search for
  630. *
  631. * \return If an extension within the given context with the priority PRIORITY_HINT
  632. * is found, a non zero value will be returned.
  633. * Otherwise, 0 is returned.
  634. */
  635. int ast_get_hint(char *hint, int hintsize, char *name, int namesize,
  636. struct ast_channel *c, const char *context, const char *exten);
  637. /*!
  638. * \brief If an extension hint exists, return non-zero
  639. *
  640. * \param hint buffer for hint
  641. * \param hintsize Maximum size of hint buffer (<0 to prevent growth, >0 to limit growth to that number of bytes, or 0 for unlimited growth)
  642. * \param name buffer for name portion of hint
  643. * \param namesize Maximum size of name buffer (<0 to prevent growth, >0 to limit growth to that number of bytes, or 0 for unlimited growth)
  644. * \param c Channel from which to return the hint. This is only important when the hint or name contains an expression to be expanded.
  645. * \param context which context to look in
  646. * \param exten which extension to search for
  647. *
  648. * \return If an extension within the given context with the priority PRIORITY_HINT
  649. * is found, a non zero value will be returned.
  650. * Otherwise, 0 is returned.
  651. */
  652. int ast_str_get_hint(struct ast_str **hint, ssize_t hintsize, struct ast_str **name, ssize_t namesize,
  653. struct ast_channel *c, const char *context, const char *exten);
  654. /*!
  655. * \brief Determine whether an extension exists
  656. *
  657. * \param c this is not important
  658. * \param context which context to look in
  659. * \param exten which extension to search for
  660. * \param priority priority of the action within the extension
  661. * \param callerid callerid to search for
  662. *
  663. * \note It is possible for autoservice to be started and stopped on c during this
  664. * function call, it is important that c is not locked prior to calling this. Otherwise
  665. * a deadlock may occur
  666. *
  667. * \return If an extension within the given context(or callerid) with the given priority
  668. * is found a non zero value will be returned. Otherwise, 0 is returned.
  669. */
  670. int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten,
  671. int priority, const char *callerid);
  672. /*!
  673. * \brief Find the priority of an extension that has the specified label
  674. *
  675. * \param c this is not important
  676. * \param context which context to look in
  677. * \param exten which extension to search for
  678. * \param label label of the action within the extension to match to priority
  679. * \param callerid callerid to search for
  680. *
  681. * \note It is possible for autoservice to be started and stopped on c during this
  682. * function call, it is important that c is not locked prior to calling this. Otherwise
  683. * a deadlock may occur
  684. *
  685. * \retval the priority which matches the given label in the extension
  686. * \retval -1 if not found.
  687. */
  688. int ast_findlabel_extension(struct ast_channel *c, const char *context,
  689. const char *exten, const char *label, const char *callerid);
  690. /*!
  691. * \brief Find the priority of an extension that has the specified label
  692. *
  693. * \note It is possible for autoservice to be started and stopped on c during this
  694. * function call, it is important that c is not locked prior to calling this. Otherwise
  695. * a deadlock may occur
  696. *
  697. * \note This function is the same as ast_findlabel_extension, except that it accepts
  698. * a pointer to an ast_context structure to specify the context instead of the
  699. * name of the context. Otherwise, the functions behave the same.
  700. */
  701. int ast_findlabel_extension2(struct ast_channel *c, struct ast_context *con,
  702. const char *exten, const char *label, const char *callerid);
  703. /*!
  704. * \brief Looks for a valid matching extension
  705. *
  706. * \param c not really important
  707. * \param context context to serach within
  708. * \param exten extension to check
  709. * \param priority priority of extension path
  710. * \param callerid callerid of extension being searched for
  711. *
  712. * \note It is possible for autoservice to be started and stopped on c during this
  713. * function call, it is important that c is not locked prior to calling this. Otherwise
  714. * a deadlock may occur
  715. *
  716. * \return If "exten" *could be* a valid extension in this context with or without
  717. * some more digits, return non-zero. Basically, when this returns 0, no matter
  718. * what you add to exten, it's not going to be a valid extension anymore
  719. */
  720. int ast_canmatch_extension(struct ast_channel *c, const char *context,
  721. const char *exten, int priority, const char *callerid);
  722. /*!
  723. * \brief Looks to see if adding anything to this extension might match something. (exists ^ canmatch)
  724. *
  725. * \param c not really important XXX
  726. * \param context context to serach within
  727. * \param exten extension to check
  728. * \param priority priority of extension path
  729. * \param callerid callerid of extension being searched for
  730. *
  731. * \note It is possible for autoservice to be started and stopped on c during this
  732. * function call, it is important that c is not locked prior to calling this. Otherwise
  733. * a deadlock may occur
  734. *
  735. * \return If "exten" *could match* a valid extension in this context with
  736. * some more digits, return non-zero. Does NOT return non-zero if this is
  737. * an exact-match only. Basically, when this returns 0, no matter
  738. * what you add to exten, it's not going to be a valid extension anymore
  739. */
  740. int ast_matchmore_extension(struct ast_channel *c, const char *context,
  741. const char *exten, int priority, const char *callerid);
  742. /*!
  743. * \brief Determine if a given extension matches a given pattern (in NXX format)
  744. *
  745. * \param pattern pattern to match
  746. * \param extension extension to check against the pattern.
  747. *
  748. * Checks whether or not the given extension matches the given pattern.
  749. *
  750. * \retval 1 on match
  751. * \retval 0 on failure
  752. */
  753. int ast_extension_match(const char *pattern, const char *extension);
  754. int ast_extension_close(const char *pattern, const char *data, int needmore);
  755. /*!
  756. * \brief Determine if one extension should match before another
  757. *
  758. * \param a extension to compare with b
  759. * \param b extension to compare with a
  760. *
  761. * Checks whether or extension a should match before extension b
  762. *
  763. * \retval 0 if the two extensions have equal matching priority
  764. * \retval 1 on a > b
  765. * \retval -1 on a < b
  766. */
  767. int ast_extension_cmp(const char *a, const char *b);
  768. /*!
  769. * \brief Launch a new extension (i.e. new stack)
  770. *
  771. * \param c not important
  772. * \param context which context to generate the extension within
  773. * \param exten new extension to add
  774. * \param priority priority of new extension
  775. * \param callerid callerid of extension
  776. * \param found
  777. * \param combined_find_spawn
  778. *
  779. * This adds a new extension to the asterisk extension list.
  780. *
  781. * \note It is possible for autoservice to be started and stopped on c during this
  782. * function call, it is important that c is not locked prior to calling this. Otherwise
  783. * a deadlock may occur
  784. *
  785. * \retval 0 on success
  786. * \retval -1 on failure.
  787. */
  788. int ast_spawn_extension(struct ast_channel *c, const char *context,
  789. const char *exten, int priority, const char *callerid, int *found, int combined_find_spawn);
  790. /*!
  791. * \brief Add a context include
  792. *
  793. * \param context context to add include to
  794. * \param include new include to add
  795. * \param registrar who's registering it
  796. *
  797. * Adds an include taking a char * string as the context parameter
  798. *
  799. * \retval 0 on success
  800. * \retval -1 on error
  801. */
  802. int ast_context_add_include(const char *context, const char *include,
  803. const char *registrar);
  804. /*!
  805. * \brief Add a context include
  806. *
  807. * \param con context to add the include to
  808. * \param value include value to add
  809. * \param registrar who registered the context
  810. *
  811. * Adds an include taking a struct ast_context as the first parameter
  812. *
  813. * \retval 0 on success
  814. * \retval -1 on failure
  815. */
  816. int ast_context_add_include2(struct ast_context *con, const char *include,
  817. const char *registrar);
  818. /*!
  819. * \brief Remove a context include
  820. *
  821. * \note See ast_context_add_include for information on arguments
  822. *
  823. * \retval 0 on success
  824. * \retval -1 on failure
  825. */
  826. int ast_context_remove_include(const char *context, const char *include,
  827. const char *registrar);
  828. /*!
  829. * \brief Removes an include by an ast_context structure
  830. *
  831. * \note See ast_context_add_include2 for information on arguments
  832. *
  833. * \retval 0 on success
  834. * \retval -1 on success
  835. */
  836. int ast_context_remove_include2(struct ast_context *con, const char *include,
  837. const char *registrar);
  838. /*!
  839. * \brief Verifies includes in an ast_contect structure
  840. *
  841. * \param con context in which to verify the includes
  842. *
  843. * \retval 0 if no problems found
  844. * \retval -1 if there were any missing context
  845. */
  846. int ast_context_verify_includes(struct ast_context *con);
  847. /*!
  848. * \brief Add a switch
  849. *
  850. * \param context context to which to add the switch
  851. * \param sw switch to add
  852. * \param data data to pass to switch
  853. * \param eval whether to evaluate variables when running switch
  854. * \param registrar whoever registered the switch
  855. *
  856. * This function registers a switch with the asterisk switch architecture
  857. *
  858. * \retval 0 on success
  859. * \retval -1 on failure
  860. */
  861. int ast_context_add_switch(const char *context, const char *sw, const char *data,
  862. int eval, const char *registrar);
  863. /*!
  864. * \brief Adds a switch (first param is a ast_context)
  865. *
  866. * \note See ast_context_add_switch() for argument information, with the exception of
  867. * the first argument. In this case, it's a pointer to an ast_context structure
  868. * as opposed to the name.
  869. */
  870. int ast_context_add_switch2(struct ast_context *con, const char *sw, const char *data,
  871. int eval, const char *registrar);
  872. /*!
  873. * \brief Remove a switch
  874. *
  875. * Removes a switch with the given parameters
  876. *
  877. * \retval 0 on success
  878. * \retval -1 on failure
  879. */
  880. int ast_context_remove_switch(const char *context, const char *sw,
  881. const char *data, const char *registrar);
  882. int ast_context_remove_switch2(struct ast_context *con, const char *sw,
  883. const char *data, const char *registrar);
  884. /*!
  885. * \brief Simply remove extension from context
  886. *
  887. * \param context context to remove extension from
  888. * \param extension which extension to remove
  889. * \param priority priority of extension to remove (0 to remove all)
  890. * \param registrar registrar of the extension
  891. *
  892. * This function removes an extension from a given context.
  893. *
  894. * \retval 0 on success
  895. * \retval -1 on failure
  896. *
  897. * @{
  898. */
  899. int ast_context_remove_extension(const char *context, const char *extension, int priority,
  900. const char *registrar);
  901. int ast_context_remove_extension2(struct ast_context *con, const char *extension,
  902. int priority, const char *registrar, int already_locked);
  903. int ast_context_remove_extension_callerid(const char *context, const char *extension,
  904. int priority, const char *callerid, int matchcid, const char *registrar);
  905. int ast_context_remove_extension_callerid2(struct ast_context *con, const char *extension,
  906. int priority, const char *callerid, int matchcid, const char *registrar,
  907. int already_locked);
  908. /*! @} */
  909. /*!
  910. * \brief Add an ignorepat
  911. *
  912. * \param context which context to add the ignorpattern to
  913. * \param ignorepat ignorepattern to set up for the extension
  914. * \param registrar registrar of the ignore pattern
  915. *
  916. * Adds an ignore pattern to a particular context.
  917. *
  918. * \retval 0 on success
  919. * \retval -1 on failure
  920. */
  921. int ast_context_add_ignorepat(const char *context, const char *ignorepat, const char *registrar);
  922. int ast_context_add_ignorepat2(struct ast_context *con, const char *ignorepat, const char *registrar);
  923. /*
  924. * \brief Remove an ignorepat
  925. *
  926. * \param context context from which to remove the pattern
  927. * \param ignorepat the pattern to remove
  928. * \param registrar the registrar of the ignore pattern
  929. *
  930. * This removes the given ignorepattern
  931. *
  932. * \retval 0 on success
  933. * \retval -1 on failure
  934. */
  935. int ast_context_remove_ignorepat(const char *context, const char *ignorepat, const char *registrar);
  936. int ast_context_remove_ignorepat2(struct ast_context *con, const char *ignorepat, const char *registrar);
  937. /*!
  938. * \brief Checks to see if a number should be ignored
  939. *
  940. * \param context context to search within
  941. * \param pattern to check whether it should be ignored or not
  942. *
  943. * Check if a number should be ignored with respect to dialtone cancellation.
  944. *
  945. * \retval 0 if the pattern should not be ignored
  946. * \retval non-zero if the pattern should be ignored
  947. */
  948. int ast_ignore_pattern(const char *context, const char *pattern);
  949. /* Locking functions for outer modules, especially for completion functions */
  950. /*!
  951. * \brief Write locks the context list
  952. *
  953. * \retval 0 on success
  954. * \retval -1 on error
  955. */
  956. int ast_wrlock_contexts(void);
  957. /*!
  958. * \brief Read locks the context list
  959. *
  960. * \retval 0 on success
  961. * \retval -1 on error
  962. */
  963. int ast_rdlock_contexts(void);
  964. /*!
  965. * \brief Unlocks contexts
  966. *
  967. * \retval 0 on success
  968. * \retval -1 on failure
  969. */
  970. int ast_unlock_contexts(void);
  971. /*!
  972. * \brief Write locks a given context
  973. *
  974. * \param con context to lock
  975. *
  976. * \retval 0 on success
  977. * \retval -1 on failure
  978. */
  979. int ast_wrlock_context(struct ast_context *con);
  980. /*!
  981. * \brief Read locks a given context
  982. *
  983. * \param con context to lock
  984. *
  985. * \retval 0 on success
  986. * \retval -1 on failure
  987. */
  988. int ast_rdlock_context(struct ast_context *con);
  989. /*!
  990. * \retval Unlocks the given context
  991. *
  992. * \param con context to unlock
  993. *
  994. * \retval 0 on success
  995. * \retval -1 on failure
  996. */
  997. int ast_unlock_context(struct ast_context *con);
  998. /*!
  999. * \brief locks the macrolock in the given context
  1000. *
  1001. * \param macrocontext name of the macro-context to lock
  1002. *
  1003. * Locks the given macro-context to ensure only one thread (call) can execute it at a time
  1004. *
  1005. * \retval 0 on success
  1006. * \retval -1 on failure
  1007. */
  1008. int ast_context_lockmacro(const char *macrocontext);
  1009. /*!
  1010. * \brief Unlocks the macrolock in the given context
  1011. *
  1012. * \param macrocontext name of the macro-context to unlock
  1013. *
  1014. * Unlocks the given macro-context so that another thread (call) can execute it
  1015. *
  1016. * \retval 0 on success
  1017. * \retval -1 on failure
  1018. */
  1019. int ast_context_unlockmacro(const char *macrocontext);
  1020. /*!
  1021. * \brief Set the channel to next execute the specified dialplan location.
  1022. * \see ast_async_parseable_goto, ast_async_goto_if_exists
  1023. *
  1024. * \note Do _NOT_ hold any channel locks when calling this function.
  1025. */
  1026. int ast_async_goto(struct ast_channel *chan, const char *context, const char *exten, int priority);
  1027. /*!
  1028. * \brief Set the channel to next execute the specified dialplan location.
  1029. */
  1030. int ast_async_goto_by_name(const char *chan, const char *context, const char *exten, int priority);
  1031. enum ast_pbx_outgoing_sync {
  1032. AST_OUTGOING_NO_WAIT = 0, /*!< Don't wait for originated call to answer */
  1033. AST_OUTGOING_WAIT = 1, /*!< Wait for originated call to answer */
  1034. AST_OUTGOING_WAIT_COMPLETE = 2, /*!< Wait for originated call to answer and hangup */
  1035. };
  1036. /*!
  1037. * \brief Synchronously or asynchronously make an outbound call and send it to a
  1038. * particular extension
  1039. *
  1040. * \param type The channel technology to create
  1041. * \param cap The format capabilities for the channel
  1042. * \param addr Address data to pass to the channel technology driver
  1043. * \param timeout How long we should attempt to dial the outbound channel
  1044. * \param context The destination context for the outbound channel
  1045. * \param exten The destination extension for the outbound channel
  1046. * \param priority The destination priority for the outbound channel
  1047. * \param reason Optional. If provided, the dialed status of the outgoing channel.
  1048. * Codes are AST_CONTROL_xxx values. Valid only if synchronous is non-zero.
  1049. * \param synchronous defined by the ast_pbx_outgoing_sync enum.
  1050. * If \c AST_OUTGOING_NO_WAIT then don't wait for anything.
  1051. * If \c AST_OUTGOING_WAIT then block until the outbound channel answers or
  1052. * the call fails.
  1053. * If \c AST_OUTGOING_WAIT_COMPLETE then wait for the call to complete or
  1054. * fail.
  1055. * If \c AST_OUTGOING_WAIT or \c AST_OUTGOING_WAIT_COMPLETE is specified,
  1056. * the call doesn't answer, and \c failed@context exists then run a channel
  1057. * named \c OutgoingSpoolFailed at \c failed@context.
  1058. * \param cid_num The caller ID number to set on the outbound channel
  1059. * \param cid_name The caller ID name to set on the outbound channel
  1060. * \param vars Variables to set on the outbound channel
  1061. * \param account The accountcode for the outbound channel
  1062. * \param locked_channel Optional. The outbound channel that was created if success
  1063. * is returned. Otherwise it is set to NULL. This is returned both locked
  1064. * and reference bumped.
  1065. * \param early_media If non-zero the channel "answers" when progress is indicated.
  1066. * \param assignedids Optional. The uniqueid(s) to assign the channel(s) that are created.
  1067. *
  1068. * \retval 0 on success
  1069. * \retval -1 on failure
  1070. */
  1071. int ast_pbx_outgoing_exten(const char *type, struct ast_format_cap *cap, const char *addr,
  1072. int timeout, const char *context, const char *exten, int priority, int *reason,
  1073. int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars,
  1074. const char *account, struct ast_channel **locked_channel, int early_media,
  1075. const struct ast_assigned_ids *assignedids);
  1076. /*!
  1077. * \brief Synchronously or asynchronously make an outbound call and execute an
  1078. * application on the channel.
  1079. *
  1080. * Note that when the application stops executing, the channel is hungup.
  1081. *
  1082. * \param type The channel technology to create
  1083. * \param cap The format capabilities for the channel
  1084. * \param addr Address data to pass to the channel technology driver
  1085. * \param timeout How long we should attempt to dial the outbound channel
  1086. * \param app The name of the application to execute
  1087. * \param appdata Data to pass to the application
  1088. * \param reason Optional. If provided, the dialed status of the outgoing channel.
  1089. * Codes are AST_CONTROL_xxx values. Valid only if synchronous is non-zero.
  1090. * \param synchronous defined by the ast_pbx_outgoing_sync enum.
  1091. * If \c AST_OUTGOING_NO_WAIT then don't wait for anything.
  1092. * If \c AST_OUTGOING_WAIT then block until the outbound channel answers or
  1093. * the call fails.
  1094. * If \c AST_OUTGOING_WAIT_COMPLETE then wait for the call to complete or
  1095. * fail.
  1096. * \param cid_num The caller ID number to set on the outbound channel
  1097. * \param cid_name The caller ID name to set on the outbound channel
  1098. * \param vars Variables to set on the outbound channel
  1099. * \param account The accountcode for the outbound channel
  1100. * \param locked_channel Optional. The outbound channel that was created if success
  1101. * is returned. Otherwise it is set to NULL. This is returned both locked
  1102. * and reference bumped.
  1103. * \param assignedids Optional. The uniqueid(s) to assign the channel(s) that are created.
  1104. *
  1105. * \retval 0 on success
  1106. * \retval -1 on failure
  1107. */
  1108. int ast_pbx_outgoing_app(const char *type, struct ast_format_cap *cap, const char *addr,
  1109. int timeout, const char *app, const char *appdata, int *reason, int synchronous,
  1110. const char *cid_num, const char *cid_name, struct ast_variable *vars,
  1111. const char *account, struct ast_channel **locked_channel,
  1112. const struct ast_assigned_ids *assignedids);
  1113. /*!
  1114. * \brief Evaluate a condition
  1115. *
  1116. * \retval 0 if the condition is NULL or of zero length
  1117. * \retval int If the string is an integer, the integer representation of
  1118. * the integer is returned
  1119. * \retval 1 Any other non-empty string
  1120. */
  1121. int pbx_checkcondition(const char *condition);
  1122. /*! @name
  1123. * Functions for returning values from structures */
  1124. /*! @{ */
  1125. const char *ast_get_context_name(struct ast_context *con);
  1126. const char *ast_get_extension_name(struct ast_exten *exten);
  1127. struct ast_context *ast_get_extension_context(struct ast_exten *exten);
  1128. const char *ast_get_include_name(struct ast_include *include);
  1129. const char *ast_get_ignorepat_name(struct ast_ignorepat *ip);
  1130. const char *ast_get_switch_name(struct ast_sw *sw);
  1131. const char *ast_get_switch_data(struct ast_sw *sw);
  1132. int ast_get_switch_eval(struct ast_sw *sw);
  1133. /*! @} */
  1134. /*! @name Other Extension stuff */
  1135. /*! @{ */
  1136. int ast_get_extension_priority(struct ast_exten *exten);
  1137. int ast_get_extension_matchcid(struct ast_exten *e);
  1138. const char *ast_get_extension_cidmatch(struct ast_exten *e);
  1139. const char *ast_get_extension_app(struct ast_exten *e);
  1140. const char *ast_get_extension_label(struct ast_exten *e);
  1141. void *ast_get_extension_app_data(struct ast_exten *e);
  1142. /*! @} */
  1143. /*! @name Registrar info functions ... */
  1144. /*! @{ */
  1145. const char *ast_get_context_registrar(struct ast_context *c);
  1146. const char *ast_get_extension_registrar(struct ast_exten *e);
  1147. const char *ast_get_include_registrar(struct ast_include *i);
  1148. const char *ast_get_ignorepat_registrar(struct ast_ignorepat *ip);
  1149. const char *ast_get_switch_registrar(struct ast_sw *sw);
  1150. /*! @} */
  1151. /*! @name Walking functions ... */
  1152. /*! @{ */
  1153. struct ast_context *ast_walk_contexts(struct ast_context *con);
  1154. struct ast_exten *ast_walk_context_extensions(struct ast_context *con,
  1155. struct ast_exten *priority);
  1156. struct ast_exten *ast_walk_extension_priorities(struct ast_exten *exten,
  1157. struct ast_exten *priority);
  1158. struct ast_include *ast_walk_context_includes(struct ast_context *con,
  1159. struct ast_include *inc);
  1160. struct ast_ignorepat *ast_walk_context_ignorepats(struct ast_context *con,
  1161. struct ast_ignorepat *ip);
  1162. struct ast_sw *ast_walk_context_switches(struct ast_context *con, struct ast_sw *sw);
  1163. /*! @} */
  1164. /*!
  1165. * \brief Create a human-readable string, specifying all variables and their corresponding values.
  1166. * \param chan Channel from which to read variables
  1167. * \param buf Dynamic string in which to place the result (should be allocated with ast_str_create).
  1168. * \see ast_str_create
  1169. * \note Will lock the channel.
  1170. */
  1171. int pbx_builtin_serialize_variables(struct ast_channel *chan, struct ast_str **buf);
  1172. /*!
  1173. * \brief Return a pointer to the value of the corresponding channel variable.
  1174. * \note Will lock the channel.
  1175. *
  1176. * \note This function will return a pointer to the buffer inside the channel
  1177. * variable. This value should only be accessed with the channel locked. If
  1178. * the value needs to be kept around, it should be done by using the following
  1179. * thread-safe code:
  1180. * \code
  1181. * const char *var;
  1182. *
  1183. * ast_channel_lock(chan);
  1184. * if ((var = pbx_builtin_getvar_helper(chan, "MYVAR"))) {
  1185. * var = ast_strdupa(var);
  1186. * }
  1187. * ast_channel_unlock(chan);
  1188. * \endcode
  1189. */
  1190. const char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name);
  1191. /*!
  1192. * \brief Add a variable to the channel variable stack, without removing any previously set value.
  1193. * \note Will lock the channel.
  1194. */
  1195. void pbx_builtin_pushvar_helper(struct ast_channel *chan, const char *name, const char *value);
  1196. /*!
  1197. * \brief Add a variable to the channel variable stack, removing the most recently set value for the same name.
  1198. * \note Will lock the channel. May also be used to set a channel dialplan function to a particular value.
  1199. * \see ast_func_write
  1200. * \return -1 if the dialplan function fails to be set
  1201. * \version 1.8 changed the function to return an error code
  1202. */
  1203. int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value);
  1204. /*!
  1205. * \brief Retrieve the value of a builtin variable or variable from the channel variable stack.
  1206. * \note Will lock the channel.
  1207. */
  1208. void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp);
  1209. void pbx_builtin_clear_globals(void);
  1210. /*!
  1211. * \brief Parse and set a single channel variable, where the name and value are separated with an '=' character.
  1212. * \note Will lock the channel.
  1213. */
  1214. int pbx_builtin_setvar(struct ast_channel *chan, const char *data);
  1215. /*!
  1216. * \brief Parse and set multiple channel variables, where the pairs are separated by the ',' character, and name and value are separated with an '=' character.
  1217. * \note Will lock the channel.
  1218. */
  1219. int pbx_builtin_setvar_multiple(struct ast_channel *chan, const char *data);
  1220. int pbx_builtin_raise_exception(struct ast_channel *chan, const char *data);
  1221. /*! @name Substitution routines, using static string buffers
  1222. * @{ */
  1223. void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count);
  1224. void pbx_substitute_variables_varshead(struct varshead *headp, const char *cp1, char *cp2, int count);
  1225. void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int cp2_size, size_t *used);
  1226. /*! @} */
  1227. /*! @} */
  1228. /*! @name Substitution routines, using dynamic string buffers */
  1229. /*!
  1230. * \param buf Result will be placed in this buffer.
  1231. * \param maxlen -1 if the buffer should not grow, 0 if the buffer may grow to any size, and >0 if the buffer should grow only to that number of bytes.
  1232. * \param chan Channel variables from which to extract values, and channel to pass to any dialplan functions.
  1233. * \param headp If no channel is specified, a channel list from which to extract variable values
  1234. * \param var Variable name to retrieve.
  1235. */
  1236. const char *ast_str_retrieve_variable(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, struct varshead *headp, const char *var);
  1237. /*!
  1238. * \param buf Result will be placed in this buffer.
  1239. * \param maxlen -1 if the buffer should not grow, 0 if the buffer may grow to any size, and >0 if the buffer should grow only to that number of bytes.
  1240. * \param chan Channel variables from which to extract values, and channel to pass to any dialplan functions.
  1241. * \param templ Variable template to expand.
  1242. */
  1243. void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ);
  1244. /*!
  1245. * \param buf Result will be placed in this buffer.
  1246. * \param maxlen -1 if the buffer should not grow, 0 if the buffer may grow to any size, and >0 if the buffer should grow only to that number of bytes.
  1247. * \param headp If no channel is specified, a channel list from which to extract variable values
  1248. * \param templ Variable template to expand.
  1249. */
  1250. void ast_str_substitute_variables_varshead(struct ast_str **buf, ssize_t maxlen, struct varshead *headp, const char *templ);
  1251. /*!
  1252. * \param buf Result will be placed in this buffer.
  1253. * \param maxlen -1 if the buffer should not grow, 0 if the buffer may grow to any size, and >0 if the buffer should grow only to that number of bytes.
  1254. * \param c Channel variables from which to extract values, and channel to pass to any dialplan functions.
  1255. * \param headp If no channel is specified, a channel list from which to extract variable values
  1256. * \param templ Variable template to expand.
  1257. * \param used Number of bytes read from the template. (May be NULL)
  1258. */
  1259. void ast_str_substitute_variables_full(struct ast_str **buf, ssize_t maxlen, struct ast_channel *c, struct varshead *headp, const char *templ, size_t *used);
  1260. /*! @} */
  1261. int ast_extension_patmatch(const char *pattern, const char *data);
  1262. /*! Set "autofallthrough" flag, if newval is <0, does not actually set. If
  1263. set to 1, sets to auto fall through. If newval set to 0, sets to no auto
  1264. fall through (reads extension instead). Returns previous value. */
  1265. int pbx_set_autofallthrough(int newval);
  1266. /*! Set "extenpatternmatchnew" flag, if newval is <0, does not actually set. If
  1267. set to 1, sets to use the new Trie-based pattern matcher. If newval set to 0, sets to use
  1268. the old linear-search algorithm. Returns previous value. */
  1269. int pbx_set_extenpatternmatchnew(int newval);
  1270. /*! Set "overrideswitch" field. If set and of nonzero length, all contexts
  1271. * will be tried directly through the named switch prior to any other
  1272. * matching within that context.
  1273. * \since 1.6.1
  1274. */
  1275. void pbx_set_overrideswitch(const char *newval);
  1276. /*!
  1277. * \note This function will handle locking the channel as needed.
  1278. */
  1279. int ast_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority);
  1280. /*!
  1281. * \note This function will handle locking the channel as needed.
  1282. */
  1283. int ast_parseable_goto(struct ast_channel *chan, const char *goto_string);
  1284. /*!
  1285. * \note This function will handle locking the channel as needed.
  1286. */
  1287. int ast_async_parseable_goto(struct ast_channel *chan, const char *goto_string);
  1288. /*!
  1289. * \note This function will handle locking the channel as needed.
  1290. */
  1291. int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority);
  1292. /*!
  1293. * \note This function will handle locking the channel as needed.
  1294. */
  1295. int ast_async_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority);
  1296. struct ast_custom_function* ast_custom_function_find(const char *name);
  1297. /*!
  1298. * \brief Unregister a custom function
  1299. */
  1300. int ast_custom_function_unregister(struct ast_custom_function *acf);
  1301. /*!
  1302. * \brief Description of the ways in which a function may escalate privileges.
  1303. */
  1304. enum ast_custom_function_escalation {
  1305. AST_CFE_NONE,
  1306. AST_CFE_READ,
  1307. AST_CFE_WRITE,
  1308. AST_CFE_BOTH,
  1309. };
  1310. /*!
  1311. * \brief Register a custom function
  1312. */
  1313. #define ast_custom_function_register(acf) __ast_custom_function_register(acf, ast_module_info->self)
  1314. /*!
  1315. * \brief Register a custom function which requires escalated privileges.
  1316. *
  1317. * Examples would be SHELL() (for which a read needs permission to execute
  1318. * arbitrary code) or FILE() (for which write needs permission to change files
  1319. * on the filesystem).
  1320. */
  1321. #define ast_custom_function_register_escalating(acf, escalation) __ast_custom_function_register_escalating(acf, escalation, ast_module_info->self)
  1322. /*!
  1323. * \brief Register a custom function
  1324. */
  1325. int __ast_custom_function_register(struct ast_custom_function *acf, struct ast_module *mod);
  1326. /*!
  1327. * \brief Register a custom function which requires escalated privileges.
  1328. *
  1329. * Examples would be SHELL() (for which a read needs permission to execute
  1330. * arbitrary code) or FILE() (for which write needs permission to change files
  1331. * on the filesystem).
  1332. */
  1333. int __ast_custom_function_register_escalating(struct ast_custom_function *acf, enum ast_custom_function_escalation escalation, struct ast_module *mod);
  1334. /*!
  1335. * \brief Retrieve the number of active calls
  1336. */
  1337. int ast_active_calls(void);
  1338. /*!
  1339. * \brief Retrieve the total number of calls processed through the PBX since last restart
  1340. */
  1341. int ast_processed_calls(void);
  1342. /*!
  1343. * \brief executes a read operation on a function
  1344. *
  1345. * \param chan Channel to execute on
  1346. * \param function Data containing the function call string (will be modified)
  1347. * \param workspace A pointer to safe memory to use for a return value
  1348. * \param len the number of bytes in workspace
  1349. *
  1350. * This application executes a function in read mode on a given channel.
  1351. *
  1352. * \retval 0 success
  1353. * \retval non-zero failure
  1354. */
  1355. int ast_func_read(struct ast_channel *chan, const char *function, char *workspace, size_t len);
  1356. /*!
  1357. * \brief executes a read operation on a function
  1358. *
  1359. * \param chan Channel to execute on
  1360. * \param function Data containing the function call string (will be modified)
  1361. * \param str A dynamic string buffer into which to place the result.
  1362. * \param maxlen <0 if the dynamic buffer should not grow; >0 if the dynamic buffer should be limited to that number of bytes; 0 if the dynamic buffer has no upper limit
  1363. *
  1364. * This application executes a function in read mode on a given channel.
  1365. *
  1366. * \retval 0 success
  1367. * \retval non-zero failure
  1368. */
  1369. int ast_func_read2(struct ast_channel *chan, const char *function, struct ast_str **str, ssize_t maxlen);
  1370. /*!
  1371. * \brief executes a write operation on a function
  1372. *
  1373. * \param chan Channel to execute on
  1374. * \param function Data containing the function call string (will be modified)
  1375. * \param value A value parameter to pass for writing
  1376. *
  1377. * This application executes a function in write mode on a given channel.
  1378. *
  1379. * \retval 0 success
  1380. * \retval non-zero failure
  1381. */
  1382. int ast_func_write(struct ast_channel *chan, const char *function, const char *value);
  1383. /*!
  1384. * \details
  1385. * When looking up extensions, we can have different requests
  1386. * identified by the 'action' argument, as follows.
  1387. *
  1388. * \note that the coding is such that the low 4 bits are the
  1389. * third argument to extension_match_core.
  1390. */
  1391. enum ext_match_t {
  1392. E_MATCHMORE = 0x00, /* extension can match but only with more 'digits' */
  1393. E_CANMATCH = 0x01, /* extension can match with or without more 'digits' */
  1394. E_MATCH = 0x02, /* extension is an exact match */
  1395. E_MATCH_MASK = 0x03, /* mask for the argument to extension_match_core() */
  1396. E_SPAWN = 0x12, /* want to spawn an extension. Requires exact match */
  1397. E_FINDLABEL = 0x22 /* returns the priority for a given label. Requires exact match */
  1398. };
  1399. #define STATUS_NO_CONTEXT 1
  1400. #define STATUS_NO_EXTENSION 2
  1401. #define STATUS_NO_PRIORITY 3
  1402. #define STATUS_NO_LABEL 4
  1403. #define STATUS_SUCCESS 5
  1404. #define AST_PBX_MAX_STACK 128
  1405. /* request and result for pbx_find_extension */
  1406. struct pbx_find_info {
  1407. #if 0
  1408. const char *context;
  1409. const char *exten;
  1410. int priority;
  1411. #endif
  1412. char *incstack[AST_PBX_MAX_STACK]; /* filled during the search */
  1413. int stacklen; /* modified during the search */
  1414. int status; /* set on return */
  1415. struct ast_switch *swo; /* set on return */
  1416. const char *data; /* set on return */
  1417. const char *foundcontext; /* set on return */
  1418. };
  1419. struct ast_exten *pbx_find_extension(struct ast_channel *chan,
  1420. struct ast_context *bypass, struct pbx_find_info *q,
  1421. const char *context, const char *exten, int priority,
  1422. const char *label, const char *callerid, enum ext_match_t action);
  1423. /*! \brief hashtable functions for contexts */
  1424. /*! @{ */
  1425. int ast_hashtab_compare_contexts(const void *ah_a, const void *ah_b);
  1426. unsigned int ast_hashtab_hash_contexts(const void *obj);
  1427. /*! @} */
  1428. /*!
  1429. * \brief Command completion for the list of installed applications.
  1430. *
  1431. * This can be called from a CLI command completion function that wants to
  1432. * complete from the list of available applications.
  1433. */
  1434. char *ast_complete_applications(const char *line, const char *word, int state);
  1435. /*!
  1436. * \brief Enable/disable the execution of 'dangerous' functions from external
  1437. * protocols (AMI, etc.).
  1438. *
  1439. * These dialplan functions (such as \c SHELL) provide an opportunity for
  1440. * privilege escalation. They are okay to invoke from the dialplan, but external
  1441. * protocols with permission controls should not normally invoke them.
  1442. *
  1443. * This function can globally enable/disable the execution of dangerous
  1444. * functions from external protocols.
  1445. *
  1446. * \param new_live_dangerously If true, enable the execution of escalating
  1447. * functions from external protocols.
  1448. */
  1449. void pbx_live_dangerously(int new_live_dangerously);
  1450. /*!
  1451. * \brief Inhibit (in the current thread) the execution of dialplan functions
  1452. * which cause privilege escalations. If pbx_live_dangerously() has been
  1453. * called, this function has no effect.
  1454. *
  1455. * \return 0 if successfuly marked current thread.
  1456. * \return Non-zero if marking current thread failed.
  1457. */
  1458. int ast_thread_inhibit_escalations(void);
  1459. /*!
  1460. * \brief Swap the current thread escalation inhibit setting.
  1461. * \since 11.24.0
  1462. *
  1463. * \param inhibit New setting. Non-zero to inhibit.
  1464. *
  1465. * \retval 1 if dangerous function execution was inhibited.
  1466. * \retval 0 if dangerous function execution was allowed.
  1467. * \retval -1 on error.
  1468. */
  1469. int ast_thread_inhibit_escalations_swap(int inhibit);
  1470. #if defined(__cplusplus) || defined(c_plusplus)
  1471. }
  1472. #endif
  1473. #endif /* _ASTERISK_PBX_H */