Wed Oct 28 13:31:06 2009

Asterisk developer's documentation


pbx.h

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

Generated on Wed Oct 28 13:31:06 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6