00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 1999 - 2006, Digium, Inc. 00005 * 00006 * Mark Spencer <markster@digium.com> 00007 * 00008 * See http://www.asterisk.org for more information about 00009 * the Asterisk project. Please do not directly contact 00010 * any of the maintainers of this project for assistance; 00011 * the project provides a web site, mailing lists and IRC 00012 * channels for your use. 00013 * 00014 * This program is free software, distributed under the terms of 00015 * the GNU General Public License Version 2. See the LICENSE file 00016 * at the top of the source tree. 00017 */ 00018 00019 /*! \file 00020 * \brief Core PBX routines and definitions. 00021 */ 00022 00023 #ifndef _ASTERISK_PBX_H 00024 #define _ASTERISK_PBX_H 00025 00026 #include "asterisk/channel.h" 00027 #include "asterisk/sched.h" 00028 #include "asterisk/devicestate.h" 00029 #include "asterisk/presencestate.h" 00030 #include "asterisk/chanvars.h" 00031 #include "asterisk/hashtab.h" 00032 #include "asterisk/stringfields.h" 00033 #include "asterisk/xmldoc.h" 00034 #include "asterisk/format.h" 00035 00036 #if defined(__cplusplus) || defined(c_plusplus) 00037 extern "C" { 00038 #endif 00039 00040 #define AST_MAX_APP 32 /*!< Max length of an application */ 00041 00042 #define AST_PBX_GOTO_FAILED -3 00043 #define AST_PBX_KEEP 0 00044 #define AST_PBX_REPLACE 1 00045 00046 /*! \brief Special return values from applications to the PBX 00047 * @{ */ 00048 #define AST_PBX_HANGUP -1 /*!< Jump to the 'h' exten */ 00049 #define AST_PBX_OK 0 /*!< No errors */ 00050 #define AST_PBX_ERROR 1 /*!< Jump to the 'e' exten */ 00051 #define AST_PBX_INCOMPLETE 12 /*!< Return to PBX matching, allowing more digits for the extension */ 00052 /*! @} */ 00053 00054 #define PRIORITY_HINT -1 /*!< Special Priority for a hint */ 00055 00056 /*! 00057 * \brief Extension states 00058 * \note States can be combined 00059 * \ref AstExtState 00060 */ 00061 enum ast_extension_states { 00062 AST_EXTENSION_REMOVED = -2, /*!< Extension removed */ 00063 AST_EXTENSION_DEACTIVATED = -1, /*!< Extension hint removed */ 00064 AST_EXTENSION_NOT_INUSE = 0, /*!< No device INUSE or BUSY */ 00065 AST_EXTENSION_INUSE = 1 << 0, /*!< One or more devices INUSE */ 00066 AST_EXTENSION_BUSY = 1 << 1, /*!< All devices BUSY */ 00067 AST_EXTENSION_UNAVAILABLE = 1 << 2, /*!< All devices UNAVAILABLE/UNREGISTERED */ 00068 AST_EXTENSION_RINGING = 1 << 3, /*!< All devices RINGING */ 00069 AST_EXTENSION_ONHOLD = 1 << 4, /*!< All devices ONHOLD */ 00070 }; 00071 00072 /*! 00073 * \brief extension matchcid types 00074 * \note matchcid in ast_exten retains 0/1, this adds 3rd state for functions to specify all 00075 * \see ast_context_remove_extension_callerid 00076 */ 00077 enum ast_ext_matchcid_types { 00078 AST_EXT_MATCHCID_OFF = 0, /*!< Match only extensions with matchcid=0 */ 00079 AST_EXT_MATCHCID_ON = 1, /*!< Match only extensions with matchcid=1 AND cidmatch matches */ 00080 AST_EXT_MATCHCID_ANY = 2, /*!< Match both - used only in functions manipulating ast_exten's */ 00081 }; 00082 00083 struct ast_context; 00084 struct ast_exten; 00085 struct ast_include; 00086 struct ast_ignorepat; 00087 struct ast_sw; 00088 00089 enum ast_state_cb_update_reason { 00090 /*! The extension state update is a result of a device state changing on the extension. */ 00091 AST_HINT_UPDATE_DEVICE = 1, 00092 /*! The extension state update is a result of presence state changing on the extension. */ 00093 AST_HINT_UPDATE_PRESENCE = 2, 00094 }; 00095 00096 struct ast_device_state_info { 00097 enum ast_device_state device_state; 00098 struct ast_channel *causing_channel; 00099 char device_name[1]; 00100 }; 00101 00102 struct ast_state_cb_info { 00103 enum ast_state_cb_update_reason reason; 00104 enum ast_extension_states exten_state; 00105 struct ao2_container *device_state_info; /* holds ast_device_state_info, must be referenced by callback if stored */ 00106 enum ast_presence_state presence_state; 00107 const char *presence_subtype; 00108 const char *presence_message; 00109 }; 00110 00111 /*! \brief Typedef for devicestate and hint callbacks */ 00112 typedef int (*ast_state_cb_type)(char *context, char *id, struct ast_state_cb_info *info, void *data); 00113 00114 /*! \brief Typedef for devicestate and hint callback removal indication callback */ 00115 typedef void (*ast_state_cb_destroy_type)(int id, void *data); 00116 00117 /*! \brief Data structure associated with a custom dialplan function */ 00118 struct ast_custom_function { 00119 const char *name; /*!< Name */ 00120 AST_DECLARE_STRING_FIELDS( 00121 AST_STRING_FIELD(synopsis); /*!< Synopsis text for 'show functions' */ 00122 AST_STRING_FIELD(desc); /*!< Description (help text) for 'show functions <name>' */ 00123 AST_STRING_FIELD(syntax); /*!< Syntax text for 'core show functions' */ 00124 AST_STRING_FIELD(arguments); /*!< Arguments description */ 00125 AST_STRING_FIELD(seealso); /*!< See also */ 00126 ); 00127 enum ast_doc_src docsrc; /*!< Where the documentation come from */ 00128 /*! Read function, if read is supported */ 00129 ast_acf_read_fn_t read; /*!< Read function, if read is supported */ 00130 /*! Read function, if read is supported. Note: only one of read or read2 00131 * needs to be implemented. In new code, read2 should be implemented as 00132 * the way forward, but they should return identical results, within the 00133 * constraints of buffer size, if both are implemented. That is, if the 00134 * read function is handed a 16-byte buffer, and the result is 17 bytes 00135 * long, then the first 15 bytes (remember NULL terminator) should be 00136 * the same for both the read and the read2 methods. */ 00137 ast_acf_read2_fn_t read2; 00138 /*! If no read2 function is provided, what maximum size? */ 00139 size_t read_max; 00140 /*! Write function, if write is supported */ 00141 ast_acf_write_fn_t write; /*!< Write function, if write is supported */ 00142 struct ast_module *mod; /*!< Module this custom function belongs to */ 00143 AST_RWLIST_ENTRY(ast_custom_function) acflist; 00144 }; 00145 00146 /*! \brief All switch functions have the same interface, so define a type for them */ 00147 typedef int (ast_switch_f)(struct ast_channel *chan, const char *context, 00148 const char *exten, int priority, const char *callerid, const char *data); 00149 00150 /*!< Data structure associated with an Asterisk switch */ 00151 struct ast_switch { 00152 AST_LIST_ENTRY(ast_switch) list; 00153 const char *name; /*!< Name of the switch */ 00154 const char *description; /*!< Description of the switch */ 00155 00156 ast_switch_f *exists; 00157 ast_switch_f *canmatch; 00158 ast_switch_f *exec; 00159 ast_switch_f *matchmore; 00160 }; 00161 00162 struct ast_timing { 00163 int hastime; /*!< If time construct exists */ 00164 unsigned int monthmask; /*!< Mask for month */ 00165 unsigned int daymask; /*!< Mask for date */ 00166 unsigned int dowmask; /*!< Mask for day of week (sun-sat) */ 00167 unsigned int minmask[48]; /*!< Mask for minute */ 00168 char *timezone; /*!< NULL, or zoneinfo style timezone */ 00169 }; 00170 00171 /*! 00172 * \brief Construct a timing bitmap, for use in time-based conditionals. 00173 * \param i Pointer to an ast_timing structure. 00174 * \param info Standard string containing a timerange, weekday range, monthday range, and month range, as well as an optional timezone. 00175 * \retval Returns 1 on success or 0 on failure. 00176 */ 00177 int ast_build_timing(struct ast_timing *i, const char *info); 00178 00179 /*! 00180 * \brief Evaluate a pre-constructed bitmap as to whether the current time falls within the range specified. 00181 * \param i Pointer to an ast_timing structure. 00182 * \retval Returns 1, if the time matches or 0, if the current time falls outside of the specified range. 00183 */ 00184 int ast_check_timing(const struct ast_timing *i); 00185 00186 /*! 00187 * \brief Evaluate a pre-constructed bitmap as to whether a particular time falls within the range specified. 00188 * \param i Pointer to an ast_timing structure. 00189 * \param tv Specified time 00190 * \retval Returns 1, if the time matches or 0, if the time falls outside of the specified range. 00191 */ 00192 int ast_check_timing2(const struct ast_timing *i, const struct timeval tv); 00193 00194 /*! 00195 * \brief Deallocates memory structures associated with a timing bitmap. 00196 * \param i Pointer to an ast_timing structure. 00197 * \retval 0 success 00198 * \retval non-zero failure (number suitable to pass to \see strerror) 00199 */ 00200 int ast_destroy_timing(struct ast_timing *i); 00201 00202 struct ast_pbx { 00203 int dtimeoutms; /*!< Timeout between digits (milliseconds) */ 00204 int rtimeoutms; /*!< Timeout for response (milliseconds) */ 00205 }; 00206 00207 00208 /*! 00209 * \brief Register an alternative dialplan switch 00210 * 00211 * \param sw switch to register 00212 * 00213 * This function registers a populated ast_switch structure with the 00214 * asterisk switching architecture. 00215 * 00216 * \retval 0 success 00217 * \retval non-zero failure 00218 */ 00219 int ast_register_switch(struct ast_switch *sw); 00220 00221 /*! 00222 * \brief Unregister an alternative switch 00223 * 00224 * \param sw switch to unregister 00225 * 00226 * Unregisters a switch from asterisk. 00227 * 00228 * \return nothing 00229 */ 00230 void ast_unregister_switch(struct ast_switch *sw); 00231 00232 /*! 00233 * \brief Look up an application 00234 * 00235 * \param app name of the app 00236 * 00237 * This function searches for the ast_app structure within 00238 * the apps that are registered for the one with the name 00239 * you passed in. 00240 * 00241 * \return the ast_app structure that matches on success, or NULL on failure 00242 */ 00243 struct ast_app *pbx_findapp(const char *app); 00244 00245 /*! 00246 * \brief Execute an application 00247 * 00248 * \param c channel to execute on 00249 * \param app which app to execute 00250 * \param data the data passed into the app 00251 * 00252 * This application executes an application on a given channel. It 00253 * saves the stack and executes the given application passing in 00254 * the given data. 00255 * 00256 * \retval 0 success 00257 * \retval -1 failure 00258 */ 00259 int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data); 00260 00261 /*! 00262 * \brief Register a new context or find an existing one 00263 * 00264 * \param extcontexts pointer to the ast_context structure pointer 00265 * \param exttable pointer to the hashtable that contains all the elements in extcontexts 00266 * \param name name of the new context 00267 * \param registrar registrar of the context 00268 * 00269 * This function allows you to play in two environments: the global contexts (active dialplan) 00270 * or an external context set of your choosing. To act on the external set, make sure extcontexts 00271 * and exttable are set; for the globals, make sure both extcontexts and exttable are NULL. 00272 * 00273 * This will first search for a context with your name. If it exists already, it will not 00274 * create a new one. If it does not exist, it will create a new one with the given name 00275 * and registrar. 00276 * 00277 * \return NULL on failure, and an ast_context structure on success 00278 */ 00279 struct ast_context *ast_context_find_or_create(struct ast_context **extcontexts, struct ast_hashtab *exttable, const char *name, const char *registrar); 00280 00281 /*! 00282 * \brief Merge the temporary contexts into a global contexts list and delete from the 00283 * global list the ones that are being added 00284 * 00285 * \param extcontexts pointer to the ast_context structure 00286 * \param exttable pointer to the ast_hashtab structure that contains all the elements in extcontexts 00287 * \param registrar of the context; if it's set the routine will delete all contexts 00288 * that belong to that registrar; if NULL only the contexts that are specified 00289 * in extcontexts 00290 */ 00291 void ast_merge_contexts_and_delete(struct ast_context **extcontexts, struct ast_hashtab *exttable, const char *registrar); 00292 00293 /*! 00294 * \brief Destroy a context (matches the specified context (or ANY context if NULL) 00295 * 00296 * \param con context to destroy 00297 * \param registrar who registered it 00298 * 00299 * You can optionally leave out either parameter. It will find it 00300 * based on either the ast_context or the registrar name. 00301 * 00302 * \return nothing 00303 */ 00304 void ast_context_destroy(struct ast_context *con, const char *registrar); 00305 00306 /*! 00307 * \brief Find a context 00308 * 00309 * \param name name of the context to find 00310 * 00311 * Will search for the context with the given name. 00312 * 00313 * \return the ast_context on success, NULL on failure. 00314 */ 00315 struct ast_context *ast_context_find(const char *name); 00316 00317 /*! 00318 * \brief The result codes when starting the PBX on a channel with ast_pbx_start. 00319 * \note AST_PBX_CALL_LIMIT refers to the maxcalls call limit in asterisk.conf 00320 * \see ast_pbx_start 00321 */ 00322 enum ast_pbx_result { 00323 AST_PBX_SUCCESS = 0, 00324 AST_PBX_FAILED = -1, 00325 AST_PBX_CALL_LIMIT = -2, 00326 }; 00327 00328 /*! 00329 * \brief Create a new thread and start the PBX 00330 * 00331 * \param c channel to start the pbx on 00332 * 00333 * \see ast_pbx_run for a synchronous function to run the PBX in the 00334 * current thread, as opposed to starting a new one. 00335 * 00336 * \retval Zero on success 00337 * \retval non-zero on failure 00338 */ 00339 enum ast_pbx_result ast_pbx_start(struct ast_channel *c); 00340 00341 /*! 00342 * \brief Execute the PBX in the current thread 00343 * 00344 * \param c channel to run the pbx on 00345 * 00346 * This executes the PBX on a given channel. It allocates a new 00347 * PBX structure for the channel, and provides all PBX functionality. 00348 * See ast_pbx_start for an asynchronous function to run the PBX in a 00349 * new thread as opposed to the current one. 00350 * 00351 * \retval Zero on success 00352 * \retval non-zero on failure 00353 */ 00354 enum ast_pbx_result ast_pbx_run(struct ast_channel *c); 00355 00356 /*! 00357 * \brief Options for ast_pbx_run() 00358 */ 00359 struct ast_pbx_args { 00360 union { 00361 /*! Pad this out so that we have plenty of room to add options 00362 * but still maintain ABI compatibility over time. */ 00363 uint64_t __padding; 00364 struct { 00365 /*! Do not hangup the channel when the PBX is complete. */ 00366 unsigned int no_hangup_chan:1; 00367 }; 00368 }; 00369 }; 00370 00371 /*! 00372 * \brief Execute the PBX in the current thread 00373 * 00374 * \param c channel to run the pbx on 00375 * \param args options for the pbx 00376 * 00377 * This executes the PBX on a given channel. It allocates a new 00378 * PBX structure for the channel, and provides all PBX functionality. 00379 * See ast_pbx_start for an asynchronous function to run the PBX in a 00380 * new thread as opposed to the current one. 00381 * 00382 * \retval Zero on success 00383 * \retval non-zero on failure 00384 */ 00385 enum ast_pbx_result ast_pbx_run_args(struct ast_channel *c, struct ast_pbx_args *args); 00386 00387 /*! 00388 * \brief Run the h exten from the given context. 00389 * \since 11.0 00390 * 00391 * \param chan Channel to run the h exten on. 00392 * \param context Context the h exten is in. 00393 * 00394 * \return Nothing 00395 */ 00396 void ast_pbx_h_exten_run(struct ast_channel *chan, const char *context); 00397 00398 /*! 00399 * \brief Run all hangup handlers on the channel. 00400 * \since 11.0 00401 * 00402 * \param chan Channel to run the hangup handlers on. 00403 * 00404 * \note Absolutely _NO_ channel locks should be held before calling this function. 00405 * 00406 * \retval Zero if no hangup handlers run. 00407 * \retval non-zero if hangup handlers were run. 00408 */ 00409 int ast_pbx_hangup_handler_run(struct ast_channel *chan); 00410 00411 /*! 00412 * \brief Init the hangup handler container on a channel. 00413 * \since 11.0 00414 * 00415 * \param chan Channel to init the hangup handler container on. 00416 * 00417 * \return Nothing 00418 */ 00419 void ast_pbx_hangup_handler_init(struct ast_channel *chan); 00420 00421 /*! 00422 * \brief Destroy the hangup handler container on a channel. 00423 * \since 11.0 00424 * 00425 * \param chan Channel to destroy the hangup handler container on. 00426 * 00427 * \return Nothing 00428 */ 00429 void ast_pbx_hangup_handler_destroy(struct ast_channel *chan); 00430 00431 /*! 00432 * \brief Pop the top of the channel hangup handler stack. 00433 * \since 11.0 00434 * 00435 * \param chan Channel to push the hangup handler onto. 00436 * 00437 * \retval TRUE if a handler was popped off of the stack. 00438 */ 00439 int ast_pbx_hangup_handler_pop(struct ast_channel *chan); 00440 00441 /*! 00442 * \brief Push the given hangup handler onto the channel hangup handler stack. 00443 * \since 11.0 00444 * 00445 * \param chan Channel to push the hangup handler onto. 00446 * \param handler Gosub application parameter string. 00447 * 00448 * \return Nothing 00449 */ 00450 void ast_pbx_hangup_handler_push(struct ast_channel *chan, const char *handler); 00451 00452 /*! 00453 * \brief Add and extension to an extension context. 00454 * 00455 * \param context context to add the extension to 00456 * \param replace 00457 * \param extension extension to add 00458 * \param priority priority level of extension addition 00459 * \param label extension label 00460 * \param callerid pattern to match CallerID, or NULL to match any CallerID 00461 * \param application application to run on the extension with that priority level 00462 * \param data data to pass to the application 00463 * \param datad 00464 * \param registrar who registered the extension 00465 * 00466 * \retval 0 success 00467 * \retval -1 failure 00468 */ 00469 int ast_add_extension(const char *context, int replace, const char *extension, 00470 int priority, const char *label, const char *callerid, 00471 const char *application, void *data, void (*datad)(void *), const char *registrar); 00472 00473 /*! 00474 * \brief Add an extension to an extension context, this time with an ast_context *. 00475 * 00476 * \note For details about the arguments, check ast_add_extension() 00477 */ 00478 int ast_add_extension2(struct ast_context *con, int replace, const char *extension, 00479 int priority, const char *label, const char *callerid, 00480 const char *application, void *data, void (*datad)(void *), const char *registrar); 00481 00482 /*! 00483 * \brief Map devstate to an extension state. 00484 * 00485 * \param[in] devstate device state 00486 * 00487 * \return the extension state mapping. 00488 */ 00489 enum ast_extension_states ast_devstate_to_extenstate(enum ast_device_state devstate); 00490 00491 /*! 00492 * \brief Uses hint and devicestate callback to get the state of an extension 00493 * 00494 * \param c this is not important 00495 * \param context which context to look in 00496 * \param exten which extension to get state 00497 * 00498 * \return extension state as defined in the ast_extension_states enum 00499 */ 00500 int ast_extension_state(struct ast_channel *c, const char *context, const char *exten); 00501 00502 /*! 00503 * \brief Uses hint and devicestate callback to get the extended state of an extension 00504 * \since 11 00505 * 00506 * \param c this is not important 00507 * \param context which context to look in 00508 * \param exten which extension to get state 00509 * \param[out] device_state_info ptr to an ao2_container with extended state info, must be unref'd after use. 00510 * 00511 * \return extension state as defined in the ast_extension_states enum 00512 */ 00513 int ast_extension_state_extended(struct ast_channel *c, const char *context, const char *exten, 00514 struct ao2_container **device_state_info); 00515 00516 /*! 00517 * \brief Uses hint and presence state callback to get the presence state of an extension 00518 * 00519 * \param c this is not important 00520 * \param context which context to look in 00521 * \param exten which extension to get state 00522 * \param[out] subtype Further information regarding the presence returned 00523 * \param[out] message Custom message further describing current presence 00524 * 00525 * \note The subtype and message are dynamically allocated and must be freed by 00526 * the caller of this function. 00527 * 00528 * \return returns the presence state value. 00529 */ 00530 int ast_hint_presence_state(struct ast_channel *c, const char *context, const char *exten, char **subtype, char **message); 00531 00532 /*! 00533 * \brief Return string representation of the state of an extension 00534 * 00535 * \param extension_state is the numerical state delivered by ast_extension_state 00536 * 00537 * \return the state of an extension as string 00538 */ 00539 const char *ast_extension_state2str(int extension_state); 00540 00541 /*! 00542 * \brief Registers a state change callback with destructor. 00543 * \since 1.8.9 00544 * \since 10.1.0 00545 * 00546 * \param context which context to look in 00547 * \param exten which extension to get state 00548 * \param change_cb callback to call if state changed 00549 * \param destroy_cb callback to call when registration destroyed. 00550 * \param data to pass to callback 00551 * 00552 * \note The change_cb is called if the state of an extension is changed. 00553 * 00554 * \note The destroy_cb is called when the registration is 00555 * deleted so the registerer can release any associated 00556 * resources. 00557 * 00558 * \retval -1 on failure 00559 * \retval ID on success 00560 */ 00561 int ast_extension_state_add_destroy(const char *context, const char *exten, 00562 ast_state_cb_type change_cb, ast_state_cb_destroy_type destroy_cb, void *data); 00563 00564 /*! 00565 * \brief Registers an extended state change callback with destructor. 00566 * \since 11 00567 * 00568 * \param context which context to look in 00569 * \param exten which extension to get state 00570 * \param change_cb callback to call if state changed 00571 * \param destroy_cb callback to call when registration destroyed. 00572 * \param data to pass to callback 00573 * 00574 * \note The change_cb is called if the state of an extension is changed. 00575 * The extended state is passed to the callback in the device_state_info 00576 * member of ast_state_cb_info. 00577 * 00578 * \note The destroy_cb is called when the registration is 00579 * deleted so the registerer can release any associated 00580 * resources. 00581 * 00582 * \retval -1 on failure 00583 * \retval ID on success 00584 */ 00585 int ast_extension_state_add_destroy_extended(const char *context, const char *exten, 00586 ast_state_cb_type change_cb, ast_state_cb_destroy_type destroy_cb, void *data); 00587 00588 /*! 00589 * \brief Registers a state change callback 00590 * 00591 * \param context which context to look in 00592 * \param exten which extension to get state 00593 * \param change_cb callback to call if state changed 00594 * \param data to pass to callback 00595 * 00596 * \note The change_cb is called if the state of an extension is changed. 00597 * 00598 * \retval -1 on failure 00599 * \retval ID on success 00600 */ 00601 int ast_extension_state_add(const char *context, const char *exten, 00602 ast_state_cb_type change_cb, void *data); 00603 00604 /*! 00605 * \brief Registers an extended state change callback 00606 * \since 11 00607 * 00608 * \param context which context to look in 00609 * \param exten which extension to get state 00610 * \param change_cb callback to call if state changed 00611 * \param data to pass to callback 00612 * 00613 * \note The change_cb is called if the state of an extension is changed. 00614 * The extended state is passed to the callback in the device_state_info 00615 * member of ast_state_cb_info. 00616 * 00617 * \retval -1 on failure 00618 * \retval ID on success 00619 */ 00620 int ast_extension_state_add_extended(const char *context, const char *exten, 00621 ast_state_cb_type change_cb, void *data); 00622 00623 /*! 00624 * \brief Deletes a registered state change callback by ID 00625 * 00626 * \param id of the registered state callback to delete 00627 * \param change_cb callback to call if state changed (Used if id == 0 (global)) 00628 * 00629 * \retval 0 success 00630 * \retval -1 failure 00631 */ 00632 int ast_extension_state_del(int id, ast_state_cb_type change_cb); 00633 00634 /*! 00635 * \brief If an extension hint exists, return non-zero 00636 * 00637 * \param hint buffer for hint 00638 * \param hintsize size of hint buffer, in bytes 00639 * \param name buffer for name portion of hint 00640 * \param namesize size of name buffer 00641 * \param c Channel from which to return the hint. This is only important when the hint or name contains an expression to be expanded. 00642 * \param context which context to look in 00643 * \param exten which extension to search for 00644 * 00645 * \return If an extension within the given context with the priority PRIORITY_HINT 00646 * is found, a non zero value will be returned. 00647 * Otherwise, 0 is returned. 00648 */ 00649 int ast_get_hint(char *hint, int hintsize, char *name, int namesize, 00650 struct ast_channel *c, const char *context, const char *exten); 00651 00652 /*! 00653 * \brief If an extension hint exists, return non-zero 00654 * 00655 * \param hint buffer for hint 00656 * \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) 00657 * \param name buffer for name portion of hint 00658 * \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) 00659 * \param c Channel from which to return the hint. This is only important when the hint or name contains an expression to be expanded. 00660 * \param context which context to look in 00661 * \param exten which extension to search for 00662 * 00663 * \return If an extension within the given context with the priority PRIORITY_HINT 00664 * is found, a non zero value will be returned. 00665 * Otherwise, 0 is returned. 00666 */ 00667 int ast_str_get_hint(struct ast_str **hint, ssize_t hintsize, struct ast_str **name, ssize_t namesize, 00668 struct ast_channel *c, const char *context, const char *exten); 00669 00670 /*! 00671 * \brief Determine whether an extension exists 00672 * 00673 * \param c this is not important 00674 * \param context which context to look in 00675 * \param exten which extension to search for 00676 * \param priority priority of the action within the extension 00677 * \param callerid callerid to search for 00678 * 00679 * \note It is possible for autoservice to be started and stopped on c during this 00680 * function call, it is important that c is not locked prior to calling this. Otherwise 00681 * a deadlock may occur 00682 * 00683 * \return If an extension within the given context(or callerid) with the given priority 00684 * is found a non zero value will be returned. Otherwise, 0 is returned. 00685 */ 00686 int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, 00687 int priority, const char *callerid); 00688 00689 /*! 00690 * \brief Find the priority of an extension that has the specified label 00691 * 00692 * \param c this is not important 00693 * \param context which context to look in 00694 * \param exten which extension to search for 00695 * \param label label of the action within the extension to match to priority 00696 * \param callerid callerid to search for 00697 * 00698 * \note It is possible for autoservice to be started and stopped on c during this 00699 * function call, it is important that c is not locked prior to calling this. Otherwise 00700 * a deadlock may occur 00701 * 00702 * \retval the priority which matches the given label in the extension 00703 * \retval -1 if not found. 00704 */ 00705 int ast_findlabel_extension(struct ast_channel *c, const char *context, 00706 const char *exten, const char *label, const char *callerid); 00707 00708 /*! 00709 * \brief Find the priority of an extension that has the specified label 00710 * 00711 * \note It is possible for autoservice to be started and stopped on c during this 00712 * function call, it is important that c is not locked prior to calling this. Otherwise 00713 * a deadlock may occur 00714 * 00715 * \note This function is the same as ast_findlabel_extension, except that it accepts 00716 * a pointer to an ast_context structure to specify the context instead of the 00717 * name of the context. Otherwise, the functions behave the same. 00718 */ 00719 int ast_findlabel_extension2(struct ast_channel *c, struct ast_context *con, 00720 const char *exten, const char *label, const char *callerid); 00721 00722 /*! 00723 * \brief Looks for a valid matching extension 00724 * 00725 * \param c not really important 00726 * \param context context to serach within 00727 * \param exten extension to check 00728 * \param priority priority of extension path 00729 * \param callerid callerid of extension being searched for 00730 * 00731 * \note It is possible for autoservice to be started and stopped on c during this 00732 * function call, it is important that c is not locked prior to calling this. Otherwise 00733 * a deadlock may occur 00734 * 00735 * \return If "exten" *could be* a valid extension in this context with or without 00736 * some more digits, return non-zero. Basically, when this returns 0, no matter 00737 * what you add to exten, it's not going to be a valid extension anymore 00738 */ 00739 int ast_canmatch_extension(struct ast_channel *c, const char *context, 00740 const char *exten, int priority, const char *callerid); 00741 00742 /*! 00743 * \brief Looks to see if adding anything to this extension might match something. (exists ^ canmatch) 00744 * 00745 * \param c not really important XXX 00746 * \param context context to serach within 00747 * \param exten extension to check 00748 * \param priority priority of extension path 00749 * \param callerid callerid of extension being searched for 00750 * 00751 * \note It is possible for autoservice to be started and stopped on c during this 00752 * function call, it is important that c is not locked prior to calling this. Otherwise 00753 * a deadlock may occur 00754 * 00755 * \return If "exten" *could match* a valid extension in this context with 00756 * some more digits, return non-zero. Does NOT return non-zero if this is 00757 * an exact-match only. Basically, when this returns 0, no matter 00758 * what you add to exten, it's not going to be a valid extension anymore 00759 */ 00760 int ast_matchmore_extension(struct ast_channel *c, const char *context, 00761 const char *exten, int priority, const char *callerid); 00762 00763 /*! 00764 * \brief Determine if a given extension matches a given pattern (in NXX format) 00765 * 00766 * \param pattern pattern to match 00767 * \param extension extension to check against the pattern. 00768 * 00769 * Checks whether or not the given extension matches the given pattern. 00770 * 00771 * \retval 1 on match 00772 * \retval 0 on failure 00773 */ 00774 int ast_extension_match(const char *pattern, const char *extension); 00775 00776 int ast_extension_close(const char *pattern, const char *data, int needmore); 00777 00778 /*! 00779 * \brief Determine if one extension should match before another 00780 * 00781 * \param a extension to compare with b 00782 * \param b extension to compare with a 00783 * 00784 * Checks whether or extension a should match before extension b 00785 * 00786 * \retval 0 if the two extensions have equal matching priority 00787 * \retval 1 on a > b 00788 * \retval -1 on a < b 00789 */ 00790 int ast_extension_cmp(const char *a, const char *b); 00791 00792 /*! 00793 * \brief Launch a new extension (i.e. new stack) 00794 * 00795 * \param c not important 00796 * \param context which context to generate the extension within 00797 * \param exten new extension to add 00798 * \param priority priority of new extension 00799 * \param callerid callerid of extension 00800 * \param found 00801 * \param combined_find_spawn 00802 * 00803 * This adds a new extension to the asterisk extension list. 00804 * 00805 * \note It is possible for autoservice to be started and stopped on c during this 00806 * function call, it is important that c is not locked prior to calling this. Otherwise 00807 * a deadlock may occur 00808 * 00809 * \retval 0 on success 00810 * \retval -1 on failure. 00811 */ 00812 int ast_spawn_extension(struct ast_channel *c, const char *context, 00813 const char *exten, int priority, const char *callerid, int *found, int combined_find_spawn); 00814 00815 /*! 00816 * \brief Add a context include 00817 * 00818 * \param context context to add include to 00819 * \param include new include to add 00820 * \param registrar who's registering it 00821 * 00822 * Adds an include taking a char * string as the context parameter 00823 * 00824 * \retval 0 on success 00825 * \retval -1 on error 00826 */ 00827 int ast_context_add_include(const char *context, const char *include, 00828 const char *registrar); 00829 00830 /*! 00831 * \brief Add a context include 00832 * 00833 * \param con context to add the include to 00834 * \param include include to add 00835 * \param registrar who registered the context 00836 * 00837 * Adds an include taking a struct ast_context as the first parameter 00838 * 00839 * \retval 0 on success 00840 * \retval -1 on failure 00841 */ 00842 int ast_context_add_include2(struct ast_context *con, const char *include, 00843 const char *registrar); 00844 00845 /*! 00846 * \brief Remove a context include 00847 * 00848 * \note See ast_context_add_include for information on arguments 00849 * 00850 * \retval 0 on success 00851 * \retval -1 on failure 00852 */ 00853 int ast_context_remove_include(const char *context, const char *include, 00854 const char *registrar); 00855 00856 /*! 00857 * \brief Removes an include by an ast_context structure 00858 * 00859 * \note See ast_context_add_include2 for information on arguments 00860 * 00861 * \retval 0 on success 00862 * \retval -1 on success 00863 */ 00864 int ast_context_remove_include2(struct ast_context *con, const char *include, 00865 const char *registrar); 00866 00867 /*! 00868 * \brief Verifies includes in an ast_contect structure 00869 * 00870 * \param con context in which to verify the includes 00871 * 00872 * \retval 0 if no problems found 00873 * \retval -1 if there were any missing context 00874 */ 00875 int ast_context_verify_includes(struct ast_context *con); 00876 00877 /*! 00878 * \brief Add a switch 00879 * 00880 * \param context context to which to add the switch 00881 * \param sw switch to add 00882 * \param data data to pass to switch 00883 * \param eval whether to evaluate variables when running switch 00884 * \param registrar whoever registered the switch 00885 * 00886 * This function registers a switch with the asterisk switch architecture 00887 * 00888 * \retval 0 on success 00889 * \retval -1 on failure 00890 */ 00891 int ast_context_add_switch(const char *context, const char *sw, const char *data, 00892 int eval, const char *registrar); 00893 00894 /*! 00895 * \brief Adds a switch (first param is a ast_context) 00896 * 00897 * \note See ast_context_add_switch() for argument information, with the exception of 00898 * the first argument. In this case, it's a pointer to an ast_context structure 00899 * as opposed to the name. 00900 */ 00901 int ast_context_add_switch2(struct ast_context *con, const char *sw, const char *data, 00902 int eval, const char *registrar); 00903 00904 /*! 00905 * \brief Remove a switch 00906 * 00907 * Removes a switch with the given parameters 00908 * 00909 * \retval 0 on success 00910 * \retval -1 on failure 00911 */ 00912 int ast_context_remove_switch(const char *context, const char *sw, 00913 const char *data, const char *registrar); 00914 00915 int ast_context_remove_switch2(struct ast_context *con, const char *sw, 00916 const char *data, const char *registrar); 00917 00918 /*! 00919 * \brief Simply remove extension from context 00920 * 00921 * \param context context to remove extension from 00922 * \param extension which extension to remove 00923 * \param priority priority of extension to remove (0 to remove all) 00924 * \param registrar registrar of the extension 00925 * 00926 * This function removes an extension from a given context. 00927 * 00928 * \retval 0 on success 00929 * \retval -1 on failure 00930 * 00931 * @{ 00932 */ 00933 int ast_context_remove_extension(const char *context, const char *extension, int priority, 00934 const char *registrar); 00935 00936 int ast_context_remove_extension2(struct ast_context *con, const char *extension, 00937 int priority, const char *registrar, int already_locked); 00938 00939 int ast_context_remove_extension_callerid(const char *context, const char *extension, 00940 int priority, const char *callerid, int matchcid, const char *registrar); 00941 00942 int ast_context_remove_extension_callerid2(struct ast_context *con, const char *extension, 00943 int priority, const char *callerid, int matchcid, const char *registrar, 00944 int already_locked); 00945 /*! @} */ 00946 00947 /*! 00948 * \brief Add an ignorepat 00949 * 00950 * \param context which context to add the ignorpattern to 00951 * \param ignorepat ignorepattern to set up for the extension 00952 * \param registrar registrar of the ignore pattern 00953 * 00954 * Adds an ignore pattern to a particular context. 00955 * 00956 * \retval 0 on success 00957 * \retval -1 on failure 00958 */ 00959 int ast_context_add_ignorepat(const char *context, const char *ignorepat, const char *registrar); 00960 00961 int ast_context_add_ignorepat2(struct ast_context *con, const char *ignorepat, const char *registrar); 00962 00963 /* 00964 * \brief Remove an ignorepat 00965 * 00966 * \param context context from which to remove the pattern 00967 * \param ignorepat the pattern to remove 00968 * \param registrar the registrar of the ignore pattern 00969 * 00970 * This removes the given ignorepattern 00971 * 00972 * \retval 0 on success 00973 * \retval -1 on failure 00974 */ 00975 int ast_context_remove_ignorepat(const char *context, const char *ignorepat, const char *registrar); 00976 00977 int ast_context_remove_ignorepat2(struct ast_context *con, const char *ignorepat, const char *registrar); 00978 00979 /*! 00980 * \brief Checks to see if a number should be ignored 00981 * 00982 * \param context context to search within 00983 * \param pattern to check whether it should be ignored or not 00984 * 00985 * Check if a number should be ignored with respect to dialtone cancellation. 00986 * 00987 * \retval 0 if the pattern should not be ignored 00988 * \retval non-zero if the pattern should be ignored 00989 */ 00990 int ast_ignore_pattern(const char *context, const char *pattern); 00991 00992 /* Locking functions for outer modules, especially for completion functions */ 00993 00994 /*! 00995 * \brief Write locks the context list 00996 * 00997 * \retval 0 on success 00998 * \retval -1 on error 00999 */ 01000 int ast_wrlock_contexts(void); 01001 01002 /*! 01003 * \brief Read locks the context list 01004 * 01005 * \retval 0 on success 01006 * \retval -1 on error 01007 */ 01008 int ast_rdlock_contexts(void); 01009 01010 /*! 01011 * \brief Unlocks contexts 01012 * 01013 * \retval 0 on success 01014 * \retval -1 on failure 01015 */ 01016 int ast_unlock_contexts(void); 01017 01018 /*! 01019 * \brief Write locks a given context 01020 * 01021 * \param con context to lock 01022 * 01023 * \retval 0 on success 01024 * \retval -1 on failure 01025 */ 01026 int ast_wrlock_context(struct ast_context *con); 01027 01028 /*! 01029 * \brief Read locks a given context 01030 * 01031 * \param con context to lock 01032 * 01033 * \retval 0 on success 01034 * \retval -1 on failure 01035 */ 01036 int ast_rdlock_context(struct ast_context *con); 01037 01038 /*! 01039 * \retval Unlocks the given context 01040 * 01041 * \param con context to unlock 01042 * 01043 * \retval 0 on success 01044 * \retval -1 on failure 01045 */ 01046 int ast_unlock_context(struct ast_context *con); 01047 01048 /*! 01049 * \brief locks the macrolock in the given given context 01050 * 01051 * \param macrocontext name of the macro-context to lock 01052 * 01053 * Locks the given macro-context to ensure only one thread (call) can execute it at a time 01054 * 01055 * \retval 0 on success 01056 * \retval -1 on failure 01057 */ 01058 int ast_context_lockmacro(const char *macrocontext); 01059 01060 /*! 01061 * \brief Unlocks the macrolock in the given context 01062 * 01063 * \param macrocontext name of the macro-context to unlock 01064 * 01065 * Unlocks the given macro-context so that another thread (call) can execute it 01066 * 01067 * \retval 0 on success 01068 * \retval -1 on failure 01069 */ 01070 int ast_context_unlockmacro(const char *macrocontext); 01071 01072 /*! 01073 * \brief Set the channel to next execute the specified dialplan location. 01074 * \see ast_async_parseable_goto, ast_async_goto_if_exists 01075 * 01076 * \note Do _NOT_ hold any channel locks when calling this function. 01077 */ 01078 int ast_async_goto(struct ast_channel *chan, const char *context, const char *exten, int priority); 01079 01080 /*! 01081 * \brief Set the channel to next execute the specified dialplan location. 01082 */ 01083 int ast_async_goto_by_name(const char *chan, const char *context, const char *exten, int priority); 01084 01085 /*! Synchronously or asynchronously make an outbound call and send it to a 01086 particular extension */ 01087 int ast_pbx_outgoing_exten(const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *context, const char *exten, int priority, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel, int early_media); 01088 01089 /*! Synchronously or asynchronously make an outbound call and send it to a 01090 particular application with given extension */ 01091 int ast_pbx_outgoing_app(const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *app, const char *appdata, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel); 01092 01093 /*! 01094 * \brief Evaluate a condition 01095 * 01096 * \retval 0 if the condition is NULL or of zero length 01097 * \retval int If the string is an integer, the integer representation of 01098 * the integer is returned 01099 * \retval 1 Any other non-empty string 01100 */ 01101 int pbx_checkcondition(const char *condition); 01102 01103 /*! @name 01104 * Functions for returning values from structures */ 01105 /*! @{ */ 01106 const char *ast_get_context_name(struct ast_context *con); 01107 const char *ast_get_extension_name(struct ast_exten *exten); 01108 struct ast_context *ast_get_extension_context(struct ast_exten *exten); 01109 const char *ast_get_include_name(struct ast_include *include); 01110 const char *ast_get_ignorepat_name(struct ast_ignorepat *ip); 01111 const char *ast_get_switch_name(struct ast_sw *sw); 01112 const char *ast_get_switch_data(struct ast_sw *sw); 01113 int ast_get_switch_eval(struct ast_sw *sw); 01114 01115 /*! @} */ 01116 01117 /*! @name Other Extension stuff */ 01118 /*! @{ */ 01119 int ast_get_extension_priority(struct ast_exten *exten); 01120 int ast_get_extension_matchcid(struct ast_exten *e); 01121 const char *ast_get_extension_cidmatch(struct ast_exten *e); 01122 const char *ast_get_extension_app(struct ast_exten *e); 01123 const char *ast_get_extension_label(struct ast_exten *e); 01124 void *ast_get_extension_app_data(struct ast_exten *e); 01125 /*! @} */ 01126 01127 /*! @name Registrar info functions ... */ 01128 /*! @{ */ 01129 const char *ast_get_context_registrar(struct ast_context *c); 01130 const char *ast_get_extension_registrar(struct ast_exten *e); 01131 const char *ast_get_include_registrar(struct ast_include *i); 01132 const char *ast_get_ignorepat_registrar(struct ast_ignorepat *ip); 01133 const char *ast_get_switch_registrar(struct ast_sw *sw); 01134 /*! @} */ 01135 01136 /*! @name Walking functions ... */ 01137 /*! @{ */ 01138 struct ast_context *ast_walk_contexts(struct ast_context *con); 01139 struct ast_exten *ast_walk_context_extensions(struct ast_context *con, 01140 struct ast_exten *priority); 01141 struct ast_exten *ast_walk_extension_priorities(struct ast_exten *exten, 01142 struct ast_exten *priority); 01143 struct ast_include *ast_walk_context_includes(struct ast_context *con, 01144 struct ast_include *inc); 01145 struct ast_ignorepat *ast_walk_context_ignorepats(struct ast_context *con, 01146 struct ast_ignorepat *ip); 01147 struct ast_sw *ast_walk_context_switches(struct ast_context *con, struct ast_sw *sw); 01148 /*! @} */ 01149 01150 /*! 01151 * \brief Create a human-readable string, specifying all variables and their corresponding values. 01152 * \param chan Channel from which to read variables 01153 * \param buf Dynamic string in which to place the result (should be allocated with ast_str_create). 01154 * \see ast_str_create 01155 * \note Will lock the channel. 01156 */ 01157 int pbx_builtin_serialize_variables(struct ast_channel *chan, struct ast_str **buf); 01158 01159 /*! 01160 * \brief Return a pointer to the value of the corresponding channel variable. 01161 * \note Will lock the channel. 01162 * 01163 * \note This function will return a pointer to the buffer inside the channel 01164 * variable. This value should only be accessed with the channel locked. If 01165 * the value needs to be kept around, it should be done by using the following 01166 * thread-safe code: 01167 * \code 01168 * const char *var; 01169 * 01170 * ast_channel_lock(chan); 01171 * if ((var = pbx_builtin_getvar_helper(chan, "MYVAR"))) { 01172 * var = ast_strdupa(var); 01173 * } 01174 * ast_channel_unlock(chan); 01175 * \endcode 01176 */ 01177 const char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name); 01178 01179 /*! 01180 * \brief Add a variable to the channel variable stack, without removing any previously set value. 01181 * \note Will lock the channel. 01182 */ 01183 void pbx_builtin_pushvar_helper(struct ast_channel *chan, const char *name, const char *value); 01184 01185 /*! 01186 * \brief Add a variable to the channel variable stack, removing the most recently set value for the same name. 01187 * \note Will lock the channel. May also be used to set a channel dialplan function to a particular value. 01188 * \see ast_func_write 01189 * \return -1 if the dialplan function fails to be set 01190 * \version 1.8 changed the function to return an error code 01191 */ 01192 int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value); 01193 01194 /*! 01195 * \brief Retrieve the value of a builtin variable or variable from the channel variable stack. 01196 * \note Will lock the channel. 01197 */ 01198 void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp); 01199 void pbx_builtin_clear_globals(void); 01200 01201 /*! 01202 * \brief Parse and set a single channel variable, where the name and value are separated with an '=' character. 01203 * \note Will lock the channel. 01204 */ 01205 int pbx_builtin_setvar(struct ast_channel *chan, const char *data); 01206 01207 /*! 01208 * \brief Parse and set multiple channel variables, where the pairs are separated by the ',' character, and name and value are separated with an '=' character. 01209 * \note Will lock the channel. 01210 */ 01211 int pbx_builtin_setvar_multiple(struct ast_channel *chan, const char *data); 01212 01213 int pbx_builtin_raise_exception(struct ast_channel *chan, const char *data); 01214 01215 /*! @name Substitution routines, using static string buffers 01216 * @{ */ 01217 void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count); 01218 void pbx_substitute_variables_varshead(struct varshead *headp, const char *cp1, char *cp2, int count); 01219 void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int cp2_size, size_t *used); 01220 /*! @} */ 01221 /*! @} */ 01222 01223 /*! @name Substitution routines, using dynamic string buffers */ 01224 01225 /*! 01226 * \param buf Result will be placed in this buffer. 01227 * \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. 01228 * \param chan Channel variables from which to extract values, and channel to pass to any dialplan functions. 01229 * \param headp If no channel is specified, a channel list from which to extract variable values 01230 * \param var Variable name to retrieve. 01231 */ 01232 const char *ast_str_retrieve_variable(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, struct varshead *headp, const char *var); 01233 01234 /*! 01235 * \param buf Result will be placed in this buffer. 01236 * \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. 01237 * \param chan Channel variables from which to extract values, and channel to pass to any dialplan functions. 01238 * \param templ Variable template to expand. 01239 */ 01240 void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ); 01241 01242 /*! 01243 * \param buf Result will be placed in this buffer. 01244 * \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. 01245 * \param headp If no channel is specified, a channel list from which to extract variable values 01246 * \param templ Variable template to expand. 01247 */ 01248 void ast_str_substitute_variables_varshead(struct ast_str **buf, ssize_t maxlen, struct varshead *headp, const char *templ); 01249 01250 /*! 01251 * \param buf Result will be placed in this buffer. 01252 * \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. 01253 * \param c Channel variables from which to extract values, and channel to pass to any dialplan functions. 01254 * \param headp If no channel is specified, a channel list from which to extract variable values 01255 * \param templ Variable template to expand. 01256 * \param used Number of bytes read from the template. 01257 */ 01258 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); 01259 /*! @} */ 01260 01261 int ast_extension_patmatch(const char *pattern, const char *data); 01262 01263 /*! Set "autofallthrough" flag, if newval is <0, does not actually set. If 01264 set to 1, sets to auto fall through. If newval set to 0, sets to no auto 01265 fall through (reads extension instead). Returns previous value. */ 01266 int pbx_set_autofallthrough(int newval); 01267 01268 /*! Set "extenpatternmatchnew" flag, if newval is <0, does not actually set. If 01269 set to 1, sets to use the new Trie-based pattern matcher. If newval set to 0, sets to use 01270 the old linear-search algorithm. Returns previous value. */ 01271 int pbx_set_extenpatternmatchnew(int newval); 01272 01273 /*! Set "overrideswitch" field. If set and of nonzero length, all contexts 01274 * will be tried directly through the named switch prior to any other 01275 * matching within that context. 01276 * \since 1.6.1 01277 */ 01278 void pbx_set_overrideswitch(const char *newval); 01279 01280 /*! 01281 * \note This function will handle locking the channel as needed. 01282 */ 01283 int ast_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority); 01284 01285 /*! 01286 * \note This function will handle locking the channel as needed. 01287 */ 01288 int ast_parseable_goto(struct ast_channel *chan, const char *goto_string); 01289 01290 /*! 01291 * \note This function will handle locking the channel as needed. 01292 */ 01293 int ast_async_parseable_goto(struct ast_channel *chan, const char *goto_string); 01294 01295 /*! 01296 * \note This function will handle locking the channel as needed. 01297 */ 01298 int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority); 01299 01300 /*! 01301 * \note This function will handle locking the channel as needed. 01302 */ 01303 int ast_async_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority); 01304 01305 struct ast_custom_function* ast_custom_function_find(const char *name); 01306 01307 /*! 01308 * \brief Unregister a custom function 01309 */ 01310 int ast_custom_function_unregister(struct ast_custom_function *acf); 01311 01312 /*! 01313 * \brief Description of the ways in which a function may escalate privileges. 01314 */ 01315 enum ast_custom_function_escalation { 01316 AST_CFE_NONE, 01317 AST_CFE_READ, 01318 AST_CFE_WRITE, 01319 AST_CFE_BOTH, 01320 }; 01321 01322 /*! 01323 * \brief Register a custom function 01324 */ 01325 #define ast_custom_function_register(acf) __ast_custom_function_register(acf, ast_module_info->self) 01326 01327 /*! 01328 * \brief Register a custom function which requires escalated privileges. 01329 * 01330 * Examples would be SHELL() (for which a read needs permission to execute 01331 * arbitrary code) or FILE() (for which write needs permission to change files 01332 * on the filesystem). 01333 */ 01334 #define ast_custom_function_register_escalating(acf, escalation) __ast_custom_function_register_escalating(acf, escalation, ast_module_info->self) 01335 01336 /*! 01337 * \brief Register a custom function 01338 */ 01339 int __ast_custom_function_register(struct ast_custom_function *acf, struct ast_module *mod); 01340 01341 /*! 01342 * \brief Register a custom function which requires escalated privileges. 01343 * 01344 * Examples would be SHELL() (for which a read needs permission to execute 01345 * arbitrary code) or FILE() (for which write needs permission to change files 01346 * on the filesystem). 01347 */ 01348 int __ast_custom_function_register_escalating(struct ast_custom_function *acf, enum ast_custom_function_escalation escalation, struct ast_module *mod); 01349 01350 /*! 01351 * \brief Retrieve the number of active calls 01352 */ 01353 int ast_active_calls(void); 01354 01355 /*! 01356 * \brief Retrieve the total number of calls processed through the PBX since last restart 01357 */ 01358 int ast_processed_calls(void); 01359 01360 /*! 01361 * \brief executes a read operation on a function 01362 * 01363 * \param chan Channel to execute on 01364 * \param function Data containing the function call string (will be modified) 01365 * \param workspace A pointer to safe memory to use for a return value 01366 * \param len the number of bytes in workspace 01367 * 01368 * This application executes a function in read mode on a given channel. 01369 * 01370 * \retval 0 success 01371 * \retval non-zero failure 01372 */ 01373 int ast_func_read(struct ast_channel *chan, const char *function, char *workspace, size_t len); 01374 01375 /*! 01376 * \brief executes a read operation on a function 01377 * 01378 * \param chan Channel to execute on 01379 * \param function Data containing the function call string (will be modified) 01380 * \param str A dynamic string buffer into which to place the result. 01381 * \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 01382 * 01383 * This application executes a function in read mode on a given channel. 01384 * 01385 * \retval 0 success 01386 * \retval non-zero failure 01387 */ 01388 int ast_func_read2(struct ast_channel *chan, const char *function, struct ast_str **str, ssize_t maxlen); 01389 01390 /*! 01391 * \brief executes a write operation on a function 01392 * 01393 * \param chan Channel to execute on 01394 * \param function Data containing the function call string (will be modified) 01395 * \param value A value parameter to pass for writing 01396 * 01397 * This application executes a function in write mode on a given channel. 01398 * 01399 * \retval 0 success 01400 * \retval non-zero failure 01401 */ 01402 int ast_func_write(struct ast_channel *chan, const char *function, const char *value); 01403 01404 /*! 01405 * \details 01406 * When looking up extensions, we can have different requests 01407 * identified by the 'action' argument, as follows. 01408 * 01409 * \note that the coding is such that the low 4 bits are the 01410 * third argument to extension_match_core. 01411 */ 01412 enum ext_match_t { 01413 E_MATCHMORE = 0x00, /* extension can match but only with more 'digits' */ 01414 E_CANMATCH = 0x01, /* extension can match with or without more 'digits' */ 01415 E_MATCH = 0x02, /* extension is an exact match */ 01416 E_MATCH_MASK = 0x03, /* mask for the argument to extension_match_core() */ 01417 E_SPAWN = 0x12, /* want to spawn an extension. Requires exact match */ 01418 E_FINDLABEL = 0x22 /* returns the priority for a given label. Requires exact match */ 01419 }; 01420 01421 #define STATUS_NO_CONTEXT 1 01422 #define STATUS_NO_EXTENSION 2 01423 #define STATUS_NO_PRIORITY 3 01424 #define STATUS_NO_LABEL 4 01425 #define STATUS_SUCCESS 5 01426 #define AST_PBX_MAX_STACK 128 01427 01428 /* request and result for pbx_find_extension */ 01429 struct pbx_find_info { 01430 #if 0 01431 const char *context; 01432 const char *exten; 01433 int priority; 01434 #endif 01435 01436 char *incstack[AST_PBX_MAX_STACK]; /* filled during the search */ 01437 int stacklen; /* modified during the search */ 01438 int status; /* set on return */ 01439 struct ast_switch *swo; /* set on return */ 01440 const char *data; /* set on return */ 01441 const char *foundcontext; /* set on return */ 01442 }; 01443 01444 struct ast_exten *pbx_find_extension(struct ast_channel *chan, 01445 struct ast_context *bypass, struct pbx_find_info *q, 01446 const char *context, const char *exten, int priority, 01447 const char *label, const char *callerid, enum ext_match_t action); 01448 01449 /*! \brief hashtable functions for contexts */ 01450 /*! @{ */ 01451 int ast_hashtab_compare_contexts(const void *ah_a, const void *ah_b); 01452 unsigned int ast_hashtab_hash_contexts(const void *obj); 01453 /*! @} */ 01454 01455 /*! 01456 * \brief Command completion for the list of installed applications. 01457 * 01458 * This can be called from a CLI command completion function that wants to 01459 * complete from the list of available applications. 01460 */ 01461 char *ast_complete_applications(const char *line, const char *word, int state); 01462 01463 /*! 01464 * \brief Enable/disable the execution of 'dangerous' functions from external 01465 * protocols (AMI, etc.). 01466 * 01467 * These dialplan functions (such as \c SHELL) provide an opportunity for 01468 * privilege escalation. They are okay to invoke from the dialplan, but external 01469 * protocols with permission controls should not normally invoke them. 01470 * 01471 * This function can globally enable/disable the execution of dangerous 01472 * functions from external protocols. 01473 * 01474 * \param new_live_dangerously If true, enable the execution of escalating 01475 * functions from external protocols. 01476 */ 01477 void pbx_live_dangerously(int new_live_dangerously); 01478 01479 /*! 01480 * \brief Inhibit (in the current thread) the execution of dialplan functions 01481 * which cause privilege escalations. If pbx_live_dangerously() has been 01482 * called, this function has no effect. 01483 * 01484 * \return 0 if successfuly marked current thread. 01485 * \return Non-zero if marking current thread failed. 01486 */ 01487 int ast_thread_inhibit_escalations(void); 01488 01489 #if defined(__cplusplus) || defined(c_plusplus) 01490 } 01491 #endif 01492 01493 #endif /* _ASTERISK_PBX_H */