include/asterisk/app.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  * See http://www.asterisk.org for more information about
00008  * the Asterisk project. Please do not directly contact
00009  * any of the maintainers of this project for assistance;
00010  * the project provides a web site, mailing lists and IRC
00011  * channels for your use.
00012  *
00013  * This program is free software, distributed under the terms of
00014  * the GNU General Public License Version 2. See the LICENSE file
00015  * at the top of the source tree.
00016  */
00017 
00018 /*! \file
00019  * \brief Application convenience functions, designed to give consistent
00020  *        look and feel to Asterisk apps.
00021  */
00022 
00023 #ifndef _ASTERISK_APP_H
00024 #define _ASTERISK_APP_H
00025 
00026 #include "asterisk/stringfields.h"
00027 #include "asterisk/strings.h"
00028 #include "asterisk/threadstorage.h"
00029 #include "asterisk/file.h"
00030 #include "asterisk/linkedlists.h"
00031 #include "asterisk/utils.h"
00032 #include "asterisk/stasis.h"
00033 
00034 struct ast_flags64;
00035 
00036 #if defined(__cplusplus) || defined(c_plusplus)
00037 extern "C" {
00038 #endif
00039 
00040 AST_THREADSTORAGE_EXTERNAL(ast_str_thread_global_buf);
00041 
00042 /* IVR stuff */
00043 
00044 /*! \brief Callback function for IVR
00045     \return returns 0 on completion, -1 on hangup or digit if interrupted
00046   */
00047 typedef int (ast_ivr_callback)(struct ast_channel *chan, char *option, void *cbdata);
00048 
00049 typedef enum {
00050    AST_ACTION_UPONE, /*!< adata is unused */
00051    AST_ACTION_EXIT,  /*!< adata is the return value for ast_ivr_menu_run if channel was not hungup */
00052    AST_ACTION_CALLBACK, /*!< adata is an ast_ivr_callback */
00053    AST_ACTION_PLAYBACK, /*!< adata is file to play */
00054    AST_ACTION_BACKGROUND,  /*!< adata is file to play */
00055    AST_ACTION_PLAYLIST, /*!< adata is list of files, separated by ; to play */
00056    AST_ACTION_MENU,  /*!< adata is a pointer to an ast_ivr_menu */
00057    AST_ACTION_REPEAT,   /*!< adata is max # of repeats, cast to a pointer */
00058    AST_ACTION_RESTART,  /*!< adata is like repeat, but resets repeats to 0 */
00059    AST_ACTION_TRANSFER, /*!< adata is a string with exten\verbatim[@context]\endverbatim */
00060    AST_ACTION_WAITOPTION,  /*!< adata is a timeout, or 0 for defaults */
00061    AST_ACTION_NOOP,  /*!< adata is unused */
00062    AST_ACTION_BACKLIST, /*!< adata is list of files separated by ; allows interruption */
00063 } ast_ivr_action;
00064 
00065 /*!
00066     Special "options" are:
00067    \arg "s" - "start here (one time greeting)"
00068    \arg "g" - "greeting/instructions"
00069    \arg "t" - "timeout"
00070    \arg "h" - "hangup"
00071    \arg "i" - "invalid selection"
00072 
00073 */
00074 struct ast_ivr_option {
00075    char *option;
00076    ast_ivr_action action;
00077    void *adata;
00078 };
00079 
00080 struct ast_ivr_menu {
00081    char *title;      /*!< Title of menu */
00082    unsigned int flags;  /*!< Flags */
00083    struct ast_ivr_option *options;  /*!< All options */
00084 };
00085 
00086 /*!
00087  * \brief Structure used for ast_copy_recording_to_vm in order to cleanly supply
00088  * data needed for making the recording from the recorded file.
00089  */
00090 struct ast_vm_recording_data {
00091    AST_DECLARE_STRING_FIELDS(
00092       AST_STRING_FIELD(context);
00093       AST_STRING_FIELD(mailbox);
00094       AST_STRING_FIELD(folder);
00095       AST_STRING_FIELD(recording_file);
00096       AST_STRING_FIELD(recording_ext);
00097 
00098       AST_STRING_FIELD(call_context);
00099       AST_STRING_FIELD(call_macrocontext);
00100       AST_STRING_FIELD(call_extension);
00101       AST_STRING_FIELD(call_callerchan);
00102       AST_STRING_FIELD(call_callerid);
00103       );
00104    int call_priority;
00105 };
00106 
00107 #define AST_IVR_FLAG_AUTORESTART (1 << 0)
00108 
00109 #define AST_IVR_DECLARE_MENU(holder, title, flags, foo...) \
00110    static struct ast_ivr_option __options_##holder[] = foo;\
00111    static struct ast_ivr_menu holder = { title, flags, __options_##holder }
00112 
00113 enum ast_timelen {
00114    TIMELEN_HOURS,
00115    TIMELEN_MINUTES,
00116    TIMELEN_SECONDS,
00117    TIMELEN_MILLISECONDS,
00118 };
00119 
00120 /*!   \brief Runs an IVR menu
00121    \return returns 0 on successful completion, -1 on hangup, or -2 on user error in menu */
00122 int ast_ivr_menu_run(struct ast_channel *c, struct ast_ivr_menu *menu, void *cbdata);
00123 
00124 /*! \brief Plays a stream and gets DTMF data from a channel
00125  * \param c Which channel one is interacting with
00126  * \param prompt File to pass to ast_streamfile (the one that you wish to play).
00127  *        It is also valid for this to be multiple files concatenated by "&".
00128  *        For example, "file1&file2&file3".
00129  * \param s The location where the DTMF data will be stored
00130  * \param maxlen Max Length of the data
00131  * \param timeout Timeout length waiting for data(in milliseconds).  Set to 0 for standard timeout(six seconds), or -1 for no time out.
00132  *
00133  *  This function was designed for application programmers for situations where they need
00134  *  to play a message and then get some DTMF data in response to the message.  If a digit
00135  *  is pressed during playback, it will immediately break out of the message and continue
00136  *  execution of your code.
00137  */
00138 int ast_app_getdata(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout);
00139 
00140 /*! \brief Full version with audiofd and controlfd.  NOTE: returns '2' on ctrlfd available, not '1' like other full functions */
00141 int ast_app_getdata_full(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout, int audiofd, int ctrlfd);
00142 
00143 /*!
00144  * \brief Run a macro on a channel, placing an optional second channel into autoservice.
00145  * \since 11.0
00146  *
00147  * \details
00148  * This is a shorthand method that makes it very easy to run a
00149  * macro on any given channel.  It is perfectly reasonable to
00150  * supply a NULL autoservice_chan here in case there is no
00151  * channel to place into autoservice.
00152  *
00153  * \note Absolutely _NO_ channel locks should be held before calling this function.
00154  *
00155  * \param autoservice_chan A channel to place into autoservice while the macro is run
00156  * \param macro_chan Channel to execute macro on.
00157  * \param macro_args Macro application argument string.
00158  *
00159  * \retval 0 success
00160  * \retval -1 on error
00161  */
00162 int ast_app_exec_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const char *macro_args);
00163 
00164 /*!
00165  * \since 1.8
00166  * \brief Run a macro on a channel, placing an optional second channel into autoservice.
00167  *
00168  * \details
00169  * This is a shorthand method that makes it very easy to run a
00170  * macro on any given channel.  It is perfectly reasonable to
00171  * supply a NULL autoservice_chan here in case there is no
00172  * channel to place into autoservice.
00173  *
00174  * \note Absolutely _NO_ channel locks should be held before calling this function.
00175  *
00176  * \param autoservice_chan A channel to place into autoservice while the macro is run
00177  * \param macro_chan Channel to execute macro on.
00178  * \param macro_name The name of the macro to run.
00179  * \param macro_args The arguments to pass to the macro.
00180  *
00181  * \retval 0 success
00182  * \retval -1 on error
00183  */
00184 int ast_app_run_macro(struct ast_channel *autoservice_chan,
00185    struct ast_channel *macro_chan, const char *macro_name, const char *macro_args);
00186 
00187 /*!
00188  * \brief Stack applications callback functions.
00189  */
00190 struct ast_app_stack_funcs {
00191    /*!
00192     * Module reference pointer so the module will stick around
00193     * while a callback is active.
00194     */
00195    void *module;
00196 
00197    /*!
00198     * \brief Callback for the routine to run a subroutine on a channel.
00199     *
00200     * \note Absolutely _NO_ channel locks should be held before calling this function.
00201     *
00202     * \param chan Channel to execute subroutine on.
00203     * \param args Gosub application argument string.
00204     * \param ignore_hangup TRUE if a hangup does not stop execution of the routine.
00205     *
00206     * \retval 0 success
00207     * \retval -1 on error
00208     */
00209    int (*run_sub)(struct ast_channel *chan, const char *args, int ignore_hangup);
00210 
00211    /*!
00212     * \brief Add missing context/exten to Gosub application argument string.
00213     *
00214     * \param chan Channel to obtain context/exten.
00215     * \param args Gosub application argument string.
00216     *
00217     * \details
00218     * Fills in the optional context and exten from the given channel.
00219     *
00220     * \retval New-args Gosub argument string on success.  Must be freed.
00221     * \retval NULL on error.
00222     */
00223    const char *(*expand_sub_args)(struct ast_channel *chan, const char *args);
00224 
00225    /* Add new API calls to the end here. */
00226 };
00227 
00228 /*!
00229  * \since 11
00230  * \brief Set stack application function callbacks
00231  * \param funcs Stack applications callback functions.
00232  */
00233 void ast_install_stack_functions(const struct ast_app_stack_funcs *funcs);
00234 
00235 /*!
00236  * \brief Add missing context/exten to subroutine argument string.
00237  *
00238  * \param chan Channel to obtain context/exten.
00239  * \param args Gosub application argument string.
00240  *
00241  * \details
00242  * Fills in the optional context and exten from the given channel.
00243  *
00244  * \retval New-args Gosub argument string on success.  Must be freed.
00245  * \retval NULL on error.
00246  */
00247 const char *ast_app_expand_sub_args(struct ast_channel *chan, const char *args);
00248 
00249 /*!
00250  * \since 11
00251  * \brief Run a subroutine on a channel, placing an optional second channel into autoservice.
00252  *
00253  * \details
00254  * This is a shorthand method that makes it very easy to run a
00255  * subroutine on any given channel.  It is perfectly reasonable
00256  * to supply a NULL autoservice_chan here in case there is no
00257  * channel to place into autoservice.
00258  *
00259  * \note Absolutely _NO_ channel locks should be held before calling this function.
00260  *
00261  * \param autoservice_chan A channel to place into autoservice while the subroutine is run
00262  * \param sub_chan Channel to execute subroutine on.
00263  * \param sub_args Gosub application argument string.
00264  * \param ignore_hangup TRUE if a hangup does not stop execution of the routine.
00265  *
00266  * \retval 0 success
00267  * \retval -1 on error
00268  */
00269 int ast_app_exec_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_args, int ignore_hangup);
00270 
00271 /*!
00272  * \since 11
00273  * \brief Run a subroutine on a channel, placing an optional second channel into autoservice.
00274  *
00275  * \details
00276  * This is a shorthand method that makes it very easy to run a
00277  * subroutine on any given channel.  It is perfectly reasonable
00278  * to supply a NULL autoservice_chan here in case there is no
00279  * channel to place into autoservice.
00280  *
00281  * \note Absolutely _NO_ channel locks should be held before calling this function.
00282  *
00283  * \param autoservice_chan A channel to place into autoservice while the subroutine is run
00284  * \param sub_chan Channel to execute subroutine on.
00285  * \param sub_location The location of the subroutine to run.
00286  * \param sub_args The arguments to pass to the subroutine.
00287  * \param ignore_hangup TRUE if a hangup does not stop execution of the routine.
00288  *
00289  * \retval 0 success
00290  * \retval -1 on error
00291  */
00292 int ast_app_run_sub(struct ast_channel *autoservice_chan,
00293    struct ast_channel *sub_chan, const char *sub_location, const char *sub_args, int ignore_hangup);
00294 
00295 enum ast_vm_snapshot_sort_val {
00296    AST_VM_SNAPSHOT_SORT_BY_ID = 0,
00297    AST_VM_SNAPSHOT_SORT_BY_TIME,
00298 };
00299 
00300 struct ast_vm_msg_snapshot {
00301    AST_DECLARE_STRING_FIELDS(
00302       AST_STRING_FIELD(msg_id);
00303       AST_STRING_FIELD(callerid);
00304       AST_STRING_FIELD(callerchan);
00305       AST_STRING_FIELD(exten);
00306       AST_STRING_FIELD(origdate);
00307       AST_STRING_FIELD(origtime);
00308       AST_STRING_FIELD(duration);
00309       AST_STRING_FIELD(folder_name);
00310       AST_STRING_FIELD(flag);
00311    );
00312    unsigned int msg_number;
00313 
00314    AST_LIST_ENTRY(ast_vm_msg_snapshot) msg;
00315 };
00316 
00317 struct ast_vm_mailbox_snapshot {
00318    int total_msg_num;
00319    int folders;
00320    /* Things are not quite as they seem here.  This points to an allocated array of lists. */
00321    AST_LIST_HEAD_NOLOCK(, ast_vm_msg_snapshot) *snapshots;
00322 };
00323 
00324 /*!
00325  * \brief Voicemail playback callback function definition
00326  *
00327  * \param chan Channel to play the file back on.
00328  * \param playfile Location of file on disk
00329  * \param duration of file in seconds. This will be zero if msg is very short or
00330  * has an unknown duration.
00331  */
00332 typedef void (ast_vm_msg_play_cb)(struct ast_channel *chan, const char *playfile, int duration);
00333 
00334 /*!
00335  * \brief Determines if the given folder has messages.
00336  *
00337  * \param mailboxes Comma or & delimited list of mailboxes (user@context).
00338  *          If no context is found, uses 'default' for the context.
00339  * \param folder The folder to look in.  Default is INBOX if not provided.
00340  *
00341  * \retval 1 if the folder has one or more messages.
00342  * \retval 0 otherwise.
00343  */
00344 typedef int (ast_has_voicemail_fn)(const char *mailboxes, const char *folder);
00345 
00346 /*!
00347  * \brief Gets the number of messages that exist for the mailbox list.
00348  *
00349  * \param mailboxes Comma or space delimited list of mailboxes (user@context).
00350  *          If no context is found, uses 'default' for the context.
00351  * \param newmsgs Where to put the count of new messages. (Can be NULL)
00352  * \param oldmsgs Where to put the count of old messages. (Can be NULL)
00353  *
00354  * \details
00355  * Simultaneously determines the count of new + urgent and old
00356  * messages.  The total messages would then be the sum of these.
00357  *
00358  * \retval 0 on success
00359  * \retval -1 on failure
00360  */
00361 typedef int (ast_inboxcount_fn)(const char *mailboxes, int *newmsgs, int *oldmsgs);
00362 
00363 /*!
00364  * \brief Gets the number of messages that exist for the mailbox list.
00365  *
00366  * \param mailboxes Comma or space delimited list of mailboxes (user@context).
00367  *          If no context is found, uses 'default' for the context.
00368  * \param urgentmsgs Where to put the count of urgent messages. (Can be NULL)
00369  * \param newmsgs Where to put the count of new messages. (Can be NULL)
00370  * \param oldmsgs Where to put the count of old messages. (Can be NULL)
00371  *
00372  * \details
00373  * Simultaneously determines the count of new, old, and urgent
00374  * messages.  The total messages would then be the sum of these
00375  * three.
00376  *
00377  * \retval 0 on success
00378  * \retval -1 on failure
00379  */
00380 typedef int (ast_inboxcount2_fn)(const char *mailboxes, int *urgentmsgs, int *newmsgs, int *oldmsgs);
00381 
00382 /*!
00383  * \brief Gets the number of messages that exist in a mailbox folder.
00384  *
00385  * \param mailbox_id The mailbox name.
00386  * \param folder The folder to look in.  Default is INBOX if not provided.
00387  *
00388  * \note If requesting INBOX then the returned count is INBOX + Urgent.
00389  *
00390  * \return The number of messages in the mailbox folder (zero or more).
00391  */
00392 typedef int (ast_messagecount_fn)(const char *mailbox_id, const char *folder);
00393 
00394 /*!
00395  * \brief Play a recorded user name for the mailbox to the specified channel.
00396  *
00397  * \param chan Where to play the recorded name file.
00398  * \param mailbox_id The mailbox name.
00399  *
00400  * \retval 0 Name played without interruption
00401  * \retval dtmf ASCII value of the DTMF which interrupted playback.
00402  * \retval -1 Unable to locate mailbox or hangup occurred.
00403  */
00404 typedef int (ast_sayname_fn)(struct ast_channel *chan, const char *mailbox_id);
00405 
00406 /*!
00407  * \brief Creates a voicemail based on a specified file to a mailbox.
00408  *
00409  * \param vm_rec_data A record containing filename and voicemail txt info.
00410  *
00411  * \retval 0 on success
00412  * \retval -1 on failure
00413  */
00414 typedef int (ast_copy_recording_to_vm_fn)(struct ast_vm_recording_data *vm_rec_data);
00415 
00416 /*!
00417  * \brief Convert the mailbox folder id to a folder name.
00418  *
00419  * \param id Mailbox folder id to convert.
00420  *
00421  * \deprecated Nothing calls it and nothing ever should.
00422  *
00423  * \return The folder name associated with the id.
00424  */
00425 typedef const char *(ast_vm_index_to_foldername_fn)(int id);
00426 
00427 /*!
00428  * \brief Create a snapshot of a mailbox which contains information about every msg.
00429  *
00430  * \param user The user part of user@context.
00431  * \param context The context part of user@context.  Must be explicit.
00432  * \param folder When not NULL only msgs from the specified folder will be included.
00433  * \param descending list the msgs in descending order rather than ascending order.
00434  * \param sort_val What to sort in the snapshot.
00435  * \param combine_INBOX_and_OLD When this argument is set, The OLD folder will be represented
00436  *        in the INBOX folder of the snapshot. This allows the snapshot to represent the
00437  *        OLD and INBOX messages in sorted order merged together.
00438  *
00439  * \note Only used by voicemail unit tests.
00440  *
00441  * \retval snapshot on success
00442  * \retval NULL on failure
00443  */
00444 typedef struct ast_vm_mailbox_snapshot *(ast_vm_mailbox_snapshot_create_fn)(const char *user,
00445    const char *context, const char *folder, int descending,
00446    enum ast_vm_snapshot_sort_val sort_val, int combine_INBOX_and_OLD);
00447 
00448 /*!
00449  * \brief destroy a snapshot
00450  *
00451  * \param mailbox_snapshot The snapshot to destroy.
00452  *
00453  * \note Only used by voicemail unit tests.
00454  *
00455  * \retval NULL
00456  */
00457 typedef struct ast_vm_mailbox_snapshot *(ast_vm_mailbox_snapshot_destroy_fn)(struct ast_vm_mailbox_snapshot *mailbox_snapshot);
00458 
00459 /*!
00460  * \brief Move messages from one folder to another
00461  *
00462  * \param mailbox The mailbox to which the folders belong
00463  * \param context The voicemail context for the mailbox
00464  * \param num_msgs The number of messages to move
00465  * \param oldfolder The folder from where messages should be moved
00466  * \param old_msg_ids The message IDs of the messages to move
00467  * \param newfolder The folder to which messages should be moved
00468  *    new folder. This array must be num_msgs sized.
00469  *
00470  * \note Only used by voicemail unit tests.
00471  *
00472  * \retval -1 Failure
00473  * \retval 0 Success
00474  */
00475 typedef int (ast_vm_msg_move_fn)(const char *mailbox, const char *context, size_t num_msgs,
00476    const char *oldfolder, const char *old_msg_ids[], const char *newfolder);
00477 
00478 /*!
00479  * \brief Remove/delete messages from a mailbox folder.
00480  *
00481  * \param mailbox The mailbox from which to delete messages
00482  * \param context The voicemail context for the mailbox
00483  * \param num_msgs The number of messages to delete
00484  * \param folder The folder from which to remove messages
00485  * \param msgs The message IDs of the messages to delete
00486  *
00487  * \note Only used by voicemail unit tests.
00488  *
00489  * \retval -1 Failure
00490  * \retval 0 Success
00491  */
00492 typedef int (ast_vm_msg_remove_fn)(const char *mailbox, const char *context, size_t num_msgs,
00493    const char *folder, const char *msgs[]);
00494 
00495 /*!
00496  * \brief forward a message from one mailbox to another.
00497  *
00498  * \brief from_mailbox The original mailbox the message is being forwarded from
00499  * \brief from_context The voicemail context of the from_mailbox
00500  * \brief from_folder The folder from which the message is being forwarded
00501  * \brief to_mailbox The mailbox to forward the message to
00502  * \brief to_context The voicemail context of the to_mailbox
00503  * \brief to_folder The folder to which the message is being forwarded
00504  * \brief num_msgs The number of messages being forwarded
00505  * \brief msg_ids The message IDs of the messages in from_mailbox to forward
00506  * \brief delete_old If non-zero, the forwarded messages are also deleted from from_mailbox.
00507  * Otherwise, the messages will remain in the from_mailbox.
00508  *
00509  * \note Only used by voicemail unit tests.
00510  *
00511  * \retval -1 Failure
00512  * \retval 0 Success
00513  */
00514 typedef int (ast_vm_msg_forward_fn)(const char *from_mailbox, const char *from_context,
00515    const char *from_folder, const char *to_mailbox, const char *to_context,
00516    const char *to_folder, size_t num_msgs, const char *msg_ids[], int delete_old);
00517 
00518 /*!
00519  * \brief Play a voicemail msg back on a channel.
00520  *
00521  * \param chan
00522  * \param mailbox msg is in.
00523  * \param context of mailbox.
00524  * \param folder voicemail folder to look in.
00525  * \param msg_num message number in the voicemailbox to playback to the channel.
00526  * \param cb
00527  *
00528  * \note Only used by voicemail unit tests.
00529  *
00530  * \retval 0 success
00531  * \retval -1 failure
00532  */
00533 typedef int (ast_vm_msg_play_fn)(struct ast_channel *chan, const char *mailbox,
00534    const char *context, const char *folder, const char *msg_num, ast_vm_msg_play_cb *cb);
00535 
00536 #define VM_MODULE_VERSION 2
00537 
00538 /*! \brief Voicemail function table definition. */
00539 struct ast_vm_functions {
00540    /*!
00541     * \brief The version of this function table.
00542     *
00543     * \note If the ABI for this table changes, the module version
00544     * (\ref VM_MODULE_VERSION) should be incremented.
00545     */
00546    unsigned int module_version;
00547    /*! \brief The name of the module that provides the voicemail functionality */
00548    const char *module_name;
00549    /*! \brief The module for the voicemail provider */
00550    struct ast_module *module;
00551 
00552    ast_has_voicemail_fn *has_voicemail;
00553    ast_inboxcount_fn *inboxcount;
00554    ast_inboxcount2_fn *inboxcount2;
00555    ast_messagecount_fn *messagecount;
00556    ast_copy_recording_to_vm_fn *copy_recording_to_vm;
00557    ast_vm_index_to_foldername_fn *index_to_foldername;
00558    ast_vm_mailbox_snapshot_create_fn *mailbox_snapshot_create;
00559    ast_vm_mailbox_snapshot_destroy_fn *mailbox_snapshot_destroy;
00560    ast_vm_msg_move_fn *msg_move;
00561    ast_vm_msg_remove_fn *msg_remove;
00562    ast_vm_msg_forward_fn *msg_forward;
00563    ast_vm_msg_play_fn *msg_play;
00564 };
00565 
00566 /*!
00567  * \brief Determine if a voicemail provider is registered.
00568  * \since 12.0.0
00569  *
00570  * \retval 0 if no provider registered.
00571  * \retval 1 if a provider is registered.
00572  */
00573 int ast_vm_is_registered(void);
00574 
00575 /*!
00576  * \brief Set voicemail function callbacks
00577  *
00578  * \param vm_table Voicemail function table to install.
00579  * \param module Pointer to the module implementing the interface
00580  *
00581  * \retval 0 on success.
00582  * \retval -1 on error.
00583  */
00584 int __ast_vm_register(const struct ast_vm_functions *vm_table, struct ast_module *module);
00585 
00586 /*! \brief See \ref __ast_vm_register() */
00587 #define ast_vm_register(vm_table) __ast_vm_register(vm_table, ast_module_info ? ast_module_info->self : NULL)
00588 
00589 /*!
00590  * \brief Unregister the specified voicemail provider
00591  *
00592  * \param The module name of the provider to unregister
00593  *
00594  * \return Nothing
00595  */
00596 void ast_vm_unregister(const char *module_name);
00597 
00598 #ifdef TEST_FRAMEWORK
00599 /*!
00600  * \brief Swap out existing voicemail functions with a temporary set of functions for use with unit tests
00601  *
00602  * \param vm_table function table to use for testing
00603  *
00604  * \note ast_vm_test_swap_table_out should be called to restore the original set before testing concludes
00605  */
00606 void ast_vm_test_swap_table_in(const struct ast_vm_functions *vm_table);
00607 
00608 /*!
00609  * \brief Used after ast_vm_test_swap_table_in to restore the original set of voicemail functions
00610  */
00611 void ast_vm_test_swap_table_out(void);
00612 #endif
00613 
00614 #define VM_GREETER_MODULE_VERSION 1
00615 
00616 /*! \brief Voicemail greeter function table definition. */
00617 struct ast_vm_greeter_functions {
00618    /*!
00619     * \brief The version of this function table.
00620     *
00621     * \note If the ABI for this table changes, the module version
00622     * (\ref VM_GREETER_MODULE_VERSION) should be incremented.
00623     */
00624    unsigned int module_version;
00625    /*! \brief The name of the module that provides the voicemail greeter functionality */
00626    const char *module_name;
00627    /*! \brief The module for the voicemail greeter provider */
00628    struct ast_module *module;
00629 
00630    ast_sayname_fn *sayname;
00631 };
00632 
00633 /*!
00634  * \brief Determine if a voicemail greeter provider is registered.
00635  * \since 13.0.0
00636  *
00637  * \retval 0 if no provider registered.
00638  * \retval 1 if a provider is registered.
00639  */
00640 int ast_vm_greeter_is_registered(void);
00641 
00642 /*!
00643  * \brief Set voicemail greeter function callbacks
00644  * \since 13.0.0
00645  *
00646  * \param vm_table Voicemail greeter function table to install.
00647  * \param module Pointer to the module implementing the interface
00648  *
00649  * \retval 0 on success.
00650  * \retval -1 on error.
00651  */
00652 int __ast_vm_greeter_register(const struct ast_vm_greeter_functions *vm_table, struct ast_module *module);
00653 
00654 /*! \brief See \ref __ast_vm_greeter_register() */
00655 #define ast_vm_greeter_register(vm_table) __ast_vm_greeter_register(vm_table, ast_module_info ? ast_module_info->self : NULL)
00656 
00657 /*!
00658  * \brief Unregister the specified voicemail greeter provider
00659  * \since 13.0.0
00660  *
00661  * \param The module name of the provider to unregister
00662  *
00663  * \return Nothing
00664  */
00665 void ast_vm_greeter_unregister(const char *module_name);
00666 
00667 #ifdef TEST_FRAMEWORK
00668 typedef int (ast_vm_test_create_user_fn)(const char *context, const char *user);
00669 typedef int (ast_vm_test_destroy_user_fn)(const char *context, const char *user);
00670 
00671 void ast_install_vm_test_functions(ast_vm_test_create_user_fn *vm_test_create_user_func,
00672    ast_vm_test_destroy_user_fn *vm_test_destroy_user_func);
00673 
00674 void ast_uninstall_vm_test_functions(void);
00675 #endif
00676 
00677 /*!
00678  * \brief
00679  * param[in] vm_rec_data Contains data needed to make the recording.
00680  * retval 0 voicemail successfully created from recording.
00681  * retval -1 Failure
00682  */
00683 int ast_app_copy_recording_to_vm(struct ast_vm_recording_data *vm_rec_data);
00684 
00685 /*!
00686  * \brief Determine if a given mailbox has any voicemail
00687  * If folder is NULL, defaults to "INBOX".  If folder is "INBOX", includes the
00688  * number of messages in the "Urgent" folder.
00689  * \retval 1 Mailbox has voicemail
00690  * \retval 0 No new voicemail in specified mailbox
00691  * \retval -1 Failure
00692  * \since 1.0
00693  */
00694 int ast_app_has_voicemail(const char *mailboxes, const char *folder);
00695 
00696 /*!
00697  * \brief Determine number of new/old messages in a mailbox
00698  * \since 1.0
00699  * \param[in] mailboxes Mailbox specification in the format
00700  *    /code
00701  *  mbox[\@context][&mbox2[\@context2]][...]
00702  * /code
00703  * \param[out] newmsgs Number of messages in the "INBOX" folder.  Includes number of messages in the "Urgent" folder, if any.
00704  * \param[out] oldmsgs Number of messages in the "Old" folder.
00705  * \retval 0 Success
00706  * \retval -1 Failure
00707  */
00708 int ast_app_inboxcount(const char *mailboxes, int *newmsgs, int *oldmsgs);
00709 
00710 /*!
00711  * \brief Determine number of urgent/new/old messages in a mailbox
00712  * \param[in] mailboxes the mailbox context to use
00713  * \param[out] urgentmsgs the urgent message count
00714  * \param[out] newmsgs the new message count
00715  * \param[out] oldmsgs the old message count
00716  * \return Returns 0 for success, negative upon error
00717  * \since 1.6.1
00718  */
00719 int ast_app_inboxcount2(const char *mailboxes, int *urgentmsgs, int *newmsgs, int *oldmsgs);
00720 
00721 /*!
00722  * \brief Play a recorded user name for the mailbox to the specified channel.
00723  *
00724  * \param chan Where to play the recorded name file.
00725  * \param mailbox_id The mailbox name.
00726  *
00727  * \retval 0 Name played without interruption
00728  * \retval dtmf ASCII value of the DTMF which interrupted playback.
00729  * \retval -1 Unable to locate mailbox or hangup occurred.
00730  */
00731 int ast_app_sayname(struct ast_channel *chan, const char *mailbox_id);
00732 
00733 /*!
00734  * \brief Get the number of messages in a given mailbox folder
00735  *
00736  * \param[in] mailbox_id Mailbox name
00737  * \param[in] folder The folder to look in.  Default is INBOX if not provided.
00738  *
00739  * \note If requesting INBOX then the returned count is INBOX + Urgent.
00740  *
00741  * \return The number of messages in the mailbox folder (zero or more).
00742  */
00743 int ast_app_messagecount(const char *mailbox_id, const char *folder);
00744 
00745 /*!
00746  * \brief Return name of folder, given an id
00747  * \param[in] id Folder id
00748  * \return Name of folder
00749  */
00750 const char *ast_vm_index_to_foldername(int id);
00751 
00752 /*!
00753  * \brief Create a snapshot of a mailbox which contains information about every msg.
00754  *
00755  * \param mailbox, the mailbox to look for
00756  * \param context, the context to look for the mailbox in
00757  * \param folder, OPTIONAL.  When not NULL only msgs from the specified folder will be included.
00758  * \param descending, list the msgs in descending order rather than ascending order.
00759  * \param combine_INBOX_and_OLD, When this argument is set, The OLD folder will be represented
00760  *        in the INBOX folder of the snapshot. This allows the snapshot to represent the
00761  *        OLD and INBOX messages in sorted order merged together.
00762  *
00763  * \retval snapshot on success
00764  * \retval NULL on failure
00765  */
00766 struct ast_vm_mailbox_snapshot *ast_vm_mailbox_snapshot_create(const char *mailbox,
00767    const char *context,
00768    const char *folder,
00769    int descending,
00770    enum ast_vm_snapshot_sort_val sort_val,
00771    int combine_INBOX_and_OLD);
00772 
00773 /*!
00774  * \brief destroy a snapshot
00775  *
00776  * \param mailbox_snapshot The snapshot to destroy.
00777  * \retval NULL
00778  */
00779 struct ast_vm_mailbox_snapshot *ast_vm_mailbox_snapshot_destroy(struct ast_vm_mailbox_snapshot *mailbox_snapshot);
00780 
00781 /*!
00782  * \brief Move messages from one folder to another
00783  *
00784  * \param mailbox The mailbox to which the folders belong
00785  * \param context The voicemail context for the mailbox
00786  * \param num_msgs The number of messages to move
00787  * \param oldfolder The folder from where messages should be moved
00788  * \param old_msg_ids The message IDs of the messages to move
00789  * \param newfolder The folder to which messages should be moved
00790  * new folder. This array must be num_msgs sized.
00791  *
00792  * \retval -1 Failure
00793  * \retval 0 Success
00794  */
00795 int ast_vm_msg_move(const char *mailbox,
00796    const char *context,
00797    size_t num_msgs,
00798    const char *oldfolder,
00799    const char *old_msg_ids[],
00800    const char *newfolder);
00801 
00802 /*!
00803  * \brief Remove/delete messages from a mailbox folder.
00804  *
00805  * \param mailbox The mailbox from which to delete messages
00806  * \param context The voicemail context for the mailbox
00807  * \param num_msgs The number of messages to delete
00808  * \param folder The folder from which to remove messages
00809  * \param msgs The message IDs of the messages to delete
00810  *
00811  * \retval -1 Failure
00812  * \retval 0 Success
00813  */
00814 int ast_vm_msg_remove(const char *mailbox,
00815    const char *context,
00816    size_t num_msgs,
00817    const char *folder,
00818    const char *msgs[]);
00819 
00820 /*!
00821  * \brief forward a message from one mailbox to another.
00822  *
00823  * \brief from_mailbox The original mailbox the message is being forwarded from
00824  * \brief from_context The voicemail context of the from_mailbox
00825  * \brief from_folder The folder from which the message is being forwarded
00826  * \brief to_mailbox The mailbox to forward the message to
00827  * \brief to_context The voicemail context of the to_mailbox
00828  * \brief to_folder The folder to which the message is being forwarded
00829  * \brief num_msgs The number of messages being forwarded
00830  * \brief msg_ids The message IDs of the messages in from_mailbox to forward
00831  * \brief delete_old If non-zero, the forwarded messages are also deleted from from_mailbox.
00832  * Otherwise, the messages will remain in the from_mailbox.
00833  *
00834  * \retval -1 Failure
00835  * \retval 0 Success
00836  */
00837 int ast_vm_msg_forward(const char *from_mailbox,
00838    const char *from_context,
00839    const char *from_folder,
00840    const char *to_mailbox,
00841    const char *to_context,
00842    const char *to_folder,
00843    size_t num_msgs,
00844    const char *msg_ids[],
00845    int delete_old);
00846 
00847 /*!
00848  * \brief Play a voicemail msg back on a channel.
00849  *
00850  * \param chan
00851  * \param mailbox msg is in.
00852  * \param context of mailbox.
00853  * \param folder voicemail folder to look in.
00854  * \param msg_num message number in the voicemailbox to playback to the channel.
00855  * \param cb
00856  *
00857  * \retval 0 success
00858  * \retval -1 failure
00859  */
00860 int ast_vm_msg_play(struct ast_channel *chan,
00861    const char *mailbox,
00862    const char *context,
00863    const char *folder,
00864    const char *msg_num,
00865    ast_vm_msg_play_cb *cb);
00866 
00867 #ifdef TEST_FRAMEWORK
00868 int ast_vm_test_destroy_user(const char *context, const char *mailbox);
00869 int ast_vm_test_create_user(const char *context, const char *mailbox);
00870 #endif
00871 
00872 /*! \brief Safely spawn an external program while closing file descriptors
00873    \note This replaces the \b system call in all Asterisk modules
00874 */
00875 int ast_safe_system(const char *s);
00876 
00877 /*!
00878  * \brief Replace the SIGCHLD handler
00879  *
00880  * Normally, Asterisk has a SIGCHLD handler that is cleaning up all zombie
00881  * processes from forking elsewhere in Asterisk.  However, if you want to
00882  * wait*() on the process to retrieve information about it's exit status,
00883  * then this signal handler needs to be temporarily replaced.
00884  *
00885  * Code that executes this function *must* call ast_unreplace_sigchld()
00886  * after it is finished doing the wait*().
00887  */
00888 void ast_replace_sigchld(void);
00889 
00890 /*!
00891  * \brief Restore the SIGCHLD handler
00892  *
00893  * This function is called after a call to ast_replace_sigchld.  It restores
00894  * the SIGCHLD handler that cleans up any zombie processes.
00895  */
00896 void ast_unreplace_sigchld(void);
00897 
00898 /*!
00899   \brief Send DTMF to a channel
00900 
00901   \param chan    The channel that will receive the DTMF frames
00902   \param peer    (optional) Peer channel that will be autoserviced while the
00903                  primary channel is receiving DTMF
00904   \param digits  This is a string of characters representing the DTMF digits
00905                  to be sent to the channel.  Valid characters are
00906                  "0123456789*#abcdABCD".  Note: You can pass arguments 'f' or
00907                  'F', if you want to Flash the channel (if supported by the
00908                  channel), or 'w' to add a 500 millisecond pause to the DTMF
00909                  sequence.
00910   \param between This is the number of milliseconds to wait in between each
00911                  DTMF digit.  If zero milliseconds is specified, then the
00912                  default value of 100 will be used.
00913   \param duration This is the duration that each DTMF digit should have.
00914 */
00915 int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between, unsigned int duration);
00916 
00917 /*! \brief Stream a filename (or file descriptor) as a generator. */
00918 int ast_linear_stream(struct ast_channel *chan, const char *filename, int fd, int allowoverride);
00919 
00920 /*!
00921  * \brief Stream a file with fast forward, pause, reverse, restart.
00922  * \param chan Channel
00923  * \param file File to play.
00924  * \param fwd, rev, stop, pause, restart DTMF keys for media control
00925  * \param skipms Number of milliseconds to skip for fwd/rev.
00926  * \param offsetms Number of milliseconds to skip when starting the media.
00927  *
00928  * Before calling this function, set this to be the number
00929  * of ms to start from the beginning of the file.  When the function
00930  * returns, it will be the number of ms from the beginning where the
00931  * playback stopped.  Pass NULL if you don't care.
00932  *
00933  * \retval 0 on success
00934  * \retval Non-zero on failure
00935  */
00936 int ast_control_streamfile(struct ast_channel *chan, const char *file, const char *fwd, const char *rev, const char *stop, const char *pause, const char *restart, int skipms, long *offsetms);
00937 
00938 /*!
00939  * \brief Version of ast_control_streamfile() which allows the language of the
00940  * media file to be specified.
00941  *
00942  * \retval 0 on success
00943  * \retval Non-zero on failure
00944  */
00945 int ast_control_streamfile_lang(struct ast_channel *chan, const char *file,
00946    const char *fwd, const char *rev, const char *stop, const char *suspend,
00947    const char *restart, int skipms, const char *lang, long *offsetms);
00948 
00949 /*!
00950  * \brief Controls playback of a tone
00951  *
00952  * \retval 0 on success
00953  * \retval Non-zero on failure
00954  */
00955 int ast_control_tone(struct ast_channel *chan, const char *tone);
00956 
00957 /*!
00958  * \brief Stream a file with fast forward, pause, reverse, restart.
00959  * \param chan
00960  * \param file filename
00961  * \param fwd, rev, stop, pause, restart, skipms, offsetms
00962  * \param cb waitstream callback to invoke when fastforward or rewind occurrs.
00963  *
00964  * Before calling this function, set this to be the number
00965  * of ms to start from the beginning of the file.  When the function
00966  * returns, it will be the number of ms from the beginning where the
00967  * playback stopped.  Pass NULL if you don't care.
00968  */
00969 int ast_control_streamfile_w_cb(struct ast_channel *chan,
00970    const char *file,
00971    const char *fwd,
00972    const char *rev,
00973    const char *stop,
00974    const char *pause,
00975    const char *restart,
00976    int skipms,
00977    long *offsetms,
00978    ast_waitstream_fr_cb cb);
00979 
00980 /*! \brief Play a stream and wait for a digit, returning the digit that was pressed */
00981 int ast_play_and_wait(struct ast_channel *chan, const char *fn);
00982 
00983 /*!
00984  * Possible actions to take if a recording already exists
00985  * \since 12
00986  */
00987 enum ast_record_if_exists {
00988    /*! Return an Error State for IF_Exists */
00989    AST_RECORD_IF_EXISTS_ERROR = -1,
00990    /*! Fail the recording. */
00991    AST_RECORD_IF_EXISTS_FAIL,
00992    /*! Overwrite the existing recording. */
00993    AST_RECORD_IF_EXISTS_OVERWRITE,
00994    /*! Append to the existing recording. */
00995    AST_RECORD_IF_EXISTS_APPEND,
00996 };
00997 
00998 /*!
00999  * \brief Record a file based on input from a channel
01000  *        This function will play "auth-thankyou" upon successful recording if
01001  *        skip_confirmation_sound is false.
01002  *
01003  * \param chan the channel being recorded
01004  * \param playfile Filename of sound to play before recording begins. A beep is also played when playfile completes, before the recording begins.
01005  * \param recordfile Filename to save the recording
01006  * \param maxtime_sec Longest possible message length in seconds
01007  * \param fmt string containing all formats to be recorded delimited by '|'
01008  * \param duration pointer to integer for storing length of the recording
01009  * \param beep If true, play a beep before recording begins (and doesn't play \a playfile)
01010  * \param sound_duration pointer to integer for storing length of the recording minus all silence
01011  * \param silencethreshold tolerance of noise levels that can be considered silence for the purpose of silence timeout, -1 for default
01012  * \param maxsilence_ms Length of time in milliseconds which will trigger a timeout from silence, -1 for default
01013  * \param path Optional filesystem path to unlock
01014  * \param acceptdtmf Character of DTMF to end and accept the recording
01015  * \param canceldtmf Character of DTMF to end and cancel the recording
01016  * \param skip_confirmation_sound If true, don't play auth-thankyou at end. Nice for custom recording prompts in apps.
01017  * \param if_exists Action to take if recording already exists.
01018  *
01019  * \retval -1 failure or hangup
01020  * \retval 'S' Recording ended from silence timeout
01021  * \retval 't' Recording ended from the message exceeding the maximum duration
01022  * \retval dtmfchar Recording ended via the return value's DTMF character for either cancel or accept.
01023  */
01024 int ast_play_and_record_full(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime_sec, const char *fmt, int *duration, int *sound_duration, int beep, int silencethreshold, int maxsilence_ms, const char *path, const char *acceptdtmf, const char *canceldtmf, int skip_confirmation_sound, enum ast_record_if_exists if_exists);
01025 
01026 /*!
01027  * \brief Record a file based on input from a channel. Use default accept and cancel DTMF.
01028  *        This function will play "auth-thankyou" upon successful recording.
01029  *
01030  * \param chan the channel being recorded
01031  * \param playfile Filename of sound to play before recording begins
01032  * \param recordfile Filename to save the recording
01033  * \param maxtime_sec Longest possible message length in seconds
01034  * \param fmt string containing all formats to be recorded delimited by '|'
01035  * \param duration pointer to integer for storing length of the recording
01036  * \param sound_duration pointer to integer for storing length of the recording minus all silence
01037  * \param silencethreshold tolerance of noise levels that can be considered silence for the purpose of silence timeout, -1 for default
01038  * \param maxsilence_ms length of time in milliseconds which will trigger a timeout from silence, -1 for default
01039  * \param path Optional filesystem path to unlock
01040  *
01041  * \retval -1 failure or hangup
01042  * \retval 'S' Recording ended from silence timeout
01043  * \retval 't' Recording ended from the message exceeding the maximum duration
01044  * \retval dtmfchar Recording ended via the return value's DTMF character for either cancel or accept.
01045  */
01046 int ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime_sec, const char *fmt, int *duration, int *sound_duration, int silencethreshold, int maxsilence_ms, const char *path);
01047 
01048 /*!
01049  * \brief Record a file based on input frm a channel. Recording is performed in 'prepend' mode which works a little differently from normal recordings
01050  *        This function will not play a success message due to post-recording control in the application this was added for.
01051  *
01052  * \param chan the channel being recorded
01053  * \param playfile Filename of sound to play before recording begins
01054  * \param recordfile Filename to save the recording
01055  * \param maxtime_sec Longest possible message length in seconds
01056  * \param fmt string containing all formats to be recorded delimited by '|'
01057  * \param duration pointer to integer for storing length of the recording
01058  * \param sound_duration pointer to integer for storing length of the recording minus all silence
01059  * \param beep whether to play a beep to prompt the recording
01060  * \param silencethreshold tolerance of noise levels that can be considered silence for the purpose of silence timeout, -1 for default
01061  * \param maxsilence_ms length of time in milliseconds which will trigger a timeout from silence, -1 for default.
01062  *
01063  * \retval -1 failure or hangup
01064  * \retval 'S' Recording ended from silence timeout
01065  * \retval 't' Recording either exceeded maximum duration or the call was ended via DTMF
01066  */
01067 int ast_play_and_prepend(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime_sec, char *fmt, int *duration, int *sound_duration, int beep, int silencethreshold, int maxsilence_ms);
01068 
01069 enum ast_getdata_result {
01070    AST_GETDATA_FAILED = -1,
01071    AST_GETDATA_COMPLETE = 0,
01072    AST_GETDATA_TIMEOUT = 1,
01073    AST_GETDATA_INTERRUPTED = 2,
01074    /*! indicates a user terminated empty string rather than an empty string resulting
01075     * from a timeout or other factors */
01076    AST_GETDATA_EMPTY_END_TERMINATED = 3,
01077 };
01078 
01079 enum AST_LOCK_RESULT {
01080    AST_LOCK_SUCCESS = 0,
01081    AST_LOCK_TIMEOUT = -1,
01082    AST_LOCK_PATH_NOT_FOUND = -2,
01083    AST_LOCK_FAILURE = -3,
01084 };
01085 
01086 /*! \brief Type of locking to use in ast_lock_path / ast_unlock_path */
01087 enum AST_LOCK_TYPE {
01088    AST_LOCK_TYPE_LOCKFILE = 0,
01089    AST_LOCK_TYPE_FLOCK = 1,
01090 };
01091 
01092 /*!
01093  * \brief Set the type of locks used by ast_lock_path()
01094  * \param type the locking type to use
01095  */
01096 void ast_set_lock_type(enum AST_LOCK_TYPE type);
01097 
01098 /*!
01099  * \brief Lock a filesystem path.
01100  * \param path the path to be locked
01101  * \return one of \ref AST_LOCK_RESULT values
01102  */
01103 enum AST_LOCK_RESULT ast_lock_path(const char *path);
01104 
01105 /*! \brief Unlock a path */
01106 int ast_unlock_path(const char *path);
01107 
01108 /*! \brief Read a file into asterisk*/
01109 char *ast_read_textfile(const char *file);
01110 
01111 struct ast_group_info;
01112 
01113 /*! \brief Split a group string into group and category, returning a default category if none is provided. */
01114 int ast_app_group_split_group(const char *data, char *group, int group_max, char *category, int category_max);
01115 
01116 /*! \brief Set the group for a channel, splitting the provided data into group and category, if specified. */
01117 int ast_app_group_set_channel(struct ast_channel *chan, const char *data);
01118 
01119 /*! \brief Get the current channel count of the specified group and category. */
01120 int ast_app_group_get_count(const char *group, const char *category);
01121 
01122 /*! \brief Get the current channel count of all groups that match the specified pattern and category. */
01123 int ast_app_group_match_get_count(const char *groupmatch, const char *category);
01124 
01125 /*! \brief Discard all group counting for a channel */
01126 int ast_app_group_discard(struct ast_channel *chan);
01127 
01128 /*! \brief Update all group counting for a channel to a new one */
01129 int ast_app_group_update(struct ast_channel *oldchan, struct ast_channel *newchan);
01130 
01131 /*! \brief Write Lock the group count list */
01132 int ast_app_group_list_wrlock(void);
01133 
01134 /*! \brief Read Lock the group count list */
01135 int ast_app_group_list_rdlock(void);
01136 
01137 /*! \brief Get the head of the group count list */
01138 struct ast_group_info *ast_app_group_list_head(void);
01139 
01140 /*! \brief Unlock the group count list */
01141 int ast_app_group_list_unlock(void);
01142 
01143 /*!
01144   \brief Define an application argument
01145   \param name The name of the argument
01146 */
01147 #define AST_APP_ARG(name) char *name
01148 
01149 /*!
01150   \brief Declare a structure to hold an application's arguments.
01151   \param name The name of the structure
01152   \param arglist The list of arguments, defined using AST_APP_ARG
01153 
01154   This macro declares a structure intended to be used in a call
01155   to ast_app_separate_args(). The structure includes all the
01156   arguments specified, plus an argv array that overlays them and an
01157   argc argument counter. The arguments must be declared using AST_APP_ARG,
01158   and they will all be character pointers (strings).
01159 
01160   \note The structure is <b>not</b> initialized, as the call to
01161   ast_app_separate_args() will perform that function before parsing
01162   the arguments.
01163  */
01164 #define AST_DECLARE_APP_ARGS(name, arglist) AST_DEFINE_APP_ARGS_TYPE(, arglist) name = { 0, }
01165 
01166 /*!
01167   \brief Define a structure type to hold an application's arguments.
01168   \param type The name of the structure type
01169   \param arglist The list of arguments, defined using AST_APP_ARG
01170 
01171   This macro defines a structure type intended to be used in a call
01172   to ast_app_separate_args(). The structure includes all the
01173   arguments specified, plus an argv array that overlays them and an
01174   argc argument counter. The arguments must be declared using AST_APP_ARG,
01175   and they will all be character pointers (strings).
01176 
01177   \note This defines a structure type, but does not declare an instance
01178   of the structure. That must be done separately.
01179  */
01180 #define AST_DEFINE_APP_ARGS_TYPE(type, arglist) \
01181    struct type { \
01182       unsigned int argc; \
01183       char *argv[0]; \
01184       arglist \
01185    }
01186 
01187 /*!
01188   \brief Performs the 'standard' argument separation process for an application.
01189   \param args An argument structure defined using AST_DECLARE_APP_ARGS
01190   \param parse A modifiable buffer containing the input to be parsed
01191 
01192   This function will separate the input string using the standard argument
01193   separator character ',' and fill in the provided structure, including
01194   the argc argument counter field.
01195  */
01196 #define AST_STANDARD_APP_ARGS(args, parse) \
01197    args.argc = __ast_app_separate_args(parse, ',', 1, args.argv, ((sizeof(args) - offsetof(typeof(args), argv)) / sizeof(args.argv[0])))
01198 #define AST_STANDARD_RAW_ARGS(args, parse) \
01199    args.argc = __ast_app_separate_args(parse, ',', 0, args.argv, ((sizeof(args) - offsetof(typeof(args), argv)) / sizeof(args.argv[0])))
01200 
01201 /*!
01202   \brief Performs the 'nonstandard' argument separation process for an application.
01203   \param args An argument structure defined using AST_DECLARE_APP_ARGS
01204   \param parse A modifiable buffer containing the input to be parsed
01205   \param sep A nonstandard separator character
01206 
01207   This function will separate the input string using the nonstandard argument
01208   separator character and fill in the provided structure, including
01209   the argc argument counter field.
01210  */
01211 #define AST_NONSTANDARD_APP_ARGS(args, parse, sep) \
01212    args.argc = __ast_app_separate_args(parse, sep, 1, args.argv, ((sizeof(args) - offsetof(typeof(args), argv)) / sizeof(args.argv[0])))
01213 #define AST_NONSTANDARD_RAW_ARGS(args, parse, sep) \
01214    args.argc = __ast_app_separate_args(parse, sep, 0, args.argv, ((sizeof(args) - offsetof(typeof(args), argv)) / sizeof(args.argv[0])))
01215 
01216 /*!
01217   \brief Separate a string into arguments in an array
01218   \param buf The string to be parsed (this must be a writable copy, as it will be modified)
01219   \param delim The character to be used to delimit arguments
01220   \param remove_chars Remove backslashes and quote characters, while parsing
01221   \param array An array of 'char *' to be filled in with pointers to the found arguments
01222   \param arraylen The number of elements in the array (i.e. the number of arguments you will accept)
01223 
01224   Note: if there are more arguments in the string than the array will hold, the last element of
01225   the array will contain the remaining arguments, not separated.
01226 
01227   The array will be completely zeroed by this function before it populates any entries.
01228 
01229   \return The number of arguments found, or zero if the function arguments are not valid.
01230 */
01231 unsigned int __ast_app_separate_args(char *buf, char delim, int remove_chars, char **array, int arraylen);
01232 #define ast_app_separate_args(a,b,c,d) __ast_app_separate_args(a,b,1,c,d)
01233 
01234 /*!
01235   \brief A structure to hold the description of an application 'option'.
01236 
01237   Application 'options' are single-character flags that can be supplied
01238   to the application to affect its behavior; they can also optionally
01239   accept arguments enclosed in parenthesis.
01240 
01241   These structures are used by the ast_app_parse_options function, uses
01242   this data to fill in a flags structure (to indicate which options were
01243   supplied) and array of argument pointers (for those options that had
01244   arguments supplied).
01245  */
01246 struct ast_app_option {
01247    /*! \brief The flag bit that represents this option. */
01248    uint64_t flag;
01249    /*! \brief The index of the entry in the arguments array
01250      that should be used for this option's argument. */
01251    unsigned int arg_index;
01252 };
01253 
01254 #define BEGIN_OPTIONS {
01255 #define END_OPTIONS }
01256 
01257 /*!
01258   \brief Declares an array of options for an application.
01259   \param holder The name of the array to be created
01260   \param options The actual options to be placed into the array
01261   \sa ast_app_parse_options
01262 
01263   This macro declares a 'static const' array of \c struct \c ast_option
01264   elements to hold the list of available options for an application.
01265   Each option must be declared using either the AST_APP_OPTION()
01266   or AST_APP_OPTION_ARG() macros.
01267 
01268   Example usage:
01269   \code
01270   enum my_app_option_flags {
01271         OPT_JUMP = (1 << 0),
01272         OPT_BLAH = (1 << 1),
01273         OPT_BLORT = (1 << 2),
01274   };
01275 
01276   enum my_app_option_args {
01277         OPT_ARG_BLAH = 0,
01278         OPT_ARG_BLORT,
01279         !! this entry tells how many possible arguments there are,
01280            and must be the last entry in the list
01281         OPT_ARG_ARRAY_SIZE,
01282   };
01283 
01284   AST_APP_OPTIONS(my_app_options, {
01285         AST_APP_OPTION('j', OPT_JUMP),
01286         AST_APP_OPTION_ARG('b', OPT_BLAH, OPT_ARG_BLAH),
01287         AST_APP_OPTION_BLORT('B', OPT_BLORT, OPT_ARG_BLORT),
01288   });
01289 
01290   static int my_app_exec(struct ast_channel *chan, void *data)
01291   {
01292    char *options;
01293    struct ast_flags opts = { 0, };
01294    char *opt_args[OPT_ARG_ARRAY_SIZE];
01295 
01296    ... do any argument parsing here ...
01297 
01298    if (ast_app_parse_options(my_app_options, &opts, opt_args, options)) {
01299       return -1;
01300    }
01301   }
01302   \endcode
01303  */
01304 #define AST_APP_OPTIONS(holder, options...) \
01305    static const struct ast_app_option holder[128] = options
01306 
01307 /*!
01308   \brief Declares an application option that does not accept an argument.
01309   \param option The single character representing the option
01310   \param flagno The flag index to be set if this option is present
01311   \sa AST_APP_OPTIONS, ast_app_parse_options
01312  */
01313 #define AST_APP_OPTION(option, flagno) \
01314    [option] = { .flag = flagno }
01315 
01316 /*!
01317   \brief Declares an application option that accepts an argument.
01318   \param option The single character representing the option
01319   \param flagno The flag index to be set if this option is present
01320   \param argno The index into the argument array where the argument should
01321   be placed
01322   \sa AST_APP_OPTIONS, ast_app_parse_options
01323  */
01324 #define AST_APP_OPTION_ARG(option, flagno, argno) \
01325    [option] = { .flag = flagno, .arg_index = argno + 1 }
01326 
01327 /*!
01328   \brief Parses a string containing application options and sets flags/arguments.
01329   \param options The array of possible options declared with AST_APP_OPTIONS
01330   \param flags The flag structure to have option flags set
01331   \param args The array of argument pointers to hold arguments found
01332   \param optstr The string containing the options to be parsed
01333   \return zero for success, non-zero if an error occurs
01334   \sa AST_APP_OPTIONS
01335  */
01336 int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr);
01337 
01338    /*!
01339   \brief Parses a string containing application options and sets flags/arguments.
01340   \param options The array of possible options declared with AST_APP_OPTIONS
01341   \param flags The 64-bit flag structure to have option flags set
01342   \param args The array of argument pointers to hold arguments found
01343   \param optstr The string containing the options to be parsed
01344   \return zero for success, non-zero if an error occurs
01345   \sa AST_APP_OPTIONS
01346  */
01347 int ast_app_parse_options64(const struct ast_app_option *options, struct ast_flags64 *flags, char **args, char *optstr);
01348 
01349 /*! \brief Given a list of options array, return an option string based on passed flags
01350    \param options The array of possible options declared with AST_APP_OPTIONS
01351    \param flags The flags of the options that you wish to populate the buffer with
01352    \param buf The buffer to fill with the string of options
01353    \param len The maximum length of buf
01354 */
01355 void ast_app_options2str64(const struct ast_app_option *options, struct ast_flags64 *flags, char *buf, size_t len);
01356 
01357 /*! \brief Present a dialtone and collect a certain length extension.
01358     \return Returns 1 on valid extension entered, -1 on hangup, or 0 on invalid extension.
01359 \note Note that if 'collect' holds digits already, new digits will be appended, so be sure it's initialized properly */
01360 int ast_app_dtget(struct ast_channel *chan, const char *context, char *collect, size_t size, int maxlen, int timeout);
01361 
01362 /*! \brief Allow to record message and have a review option */
01363 int ast_record_review(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, const char *path);
01364 
01365 /*!
01366  * \brief Decode an encoded control or extended ASCII character
01367  * \param[in] stream String to decode
01368  * \param[out] result Decoded character
01369  * \param[out] consumed Number of characters used in stream to encode the character
01370  * \retval -1 Stream is of zero length
01371  * \retval 0 Success
01372  */
01373 int ast_get_encoded_char(const char *stream, char *result, size_t *consumed);
01374 
01375 /*!
01376  * \brief Decode a stream of encoded control or extended ASCII characters
01377  * \param[in] stream Encoded string
01378  * \param[out] result Decoded string
01379  * \param[in] result_len Maximum size of the result buffer
01380  * \return A pointer to the result string
01381  */
01382 char *ast_get_encoded_str(const char *stream, char *result, size_t result_len);
01383 
01384 /*! \brief Decode a stream of encoded control or extended ASCII characters */
01385 int ast_str_get_encoded_str(struct ast_str **str, int maxlen, const char *stream);
01386 
01387 /*!
01388  * \brief Common routine for child processes, to close all fds prior to exec(2)
01389  * \param[in] n starting file descriptor number for closing all higher file descriptors
01390  * \since 1.6.1
01391  */
01392 void ast_close_fds_above_n(int n);
01393 
01394 /*!
01395  * \brief Common routine to safely fork without a chance of a signal handler firing badly in the child
01396  * \param[in] stop_reaper flag to determine if sigchld handler is replaced or not
01397  * \since 1.6.1
01398  */
01399 int ast_safe_fork(int stop_reaper);
01400 
01401 /*!
01402  * \brief Common routine to cleanup after fork'ed process is complete (if reaping was stopped)
01403  * \since 1.6.1
01404  */
01405 void ast_safe_fork_cleanup(void);
01406 
01407 /*!
01408  * \brief Common routine to parse time lengths, with optional time unit specifier
01409  * \param[in] timestr String to parse
01410  * \param[in] defunit Default unit type
01411  * \param[out] result Resulting value, specified in milliseconds
01412  * \retval 0 Success
01413  * \retval -1 Failure
01414  * \since 1.8
01415  */
01416 int ast_app_parse_timelen(const char *timestr, int *result, enum ast_timelen defunit);
01417 
01418 /*!
01419  * \since 12
01420  * \brief Publish a MWI state update via stasis
01421  *
01422  * \param[in] mailbox The mailbox identifier string.
01423  * \param[in] context The context this mailbox resides in (NULL or "" if only using mailbox)
01424  * \param[in] new_msgs The number of new messages in this mailbox
01425  * \param[in] old_msgs The number of old messages in this mailbox
01426  *
01427  * \retval 0 Success
01428  * \retval -1 Failure
01429  */
01430 #define ast_publish_mwi_state(mailbox, context, new_msgs, old_msgs) \
01431    ast_publish_mwi_state_full(mailbox, context, new_msgs, old_msgs, NULL, NULL)
01432 
01433 /*!
01434  * \since 12
01435  * \brief Publish a MWI state update associated with some channel
01436  *
01437  * \param[in] mailbox The mailbox identifier string.
01438  * \param[in] context The context this mailbox resides in (NULL or "" if only using mailbox)
01439  * \param[in] new_msgs The number of new messages in this mailbox
01440  * \param[in] old_msgs The number of old messages in this mailbox
01441  * \param[in] channel_id A unique identifier for a channel associated with this
01442  * change in mailbox state
01443  *
01444  * \retval 0 Success
01445  * \retval -1 Failure
01446  */
01447 #define ast_publish_mwi_state_channel(mailbox, context, new_msgs, old_msgs, channel_id) \
01448    ast_publish_mwi_state_full(mailbox, context, new_msgs, old_msgs, channel_id, NULL)
01449 
01450 /*!
01451  * \since 12
01452  * \brief Publish a MWI state update via stasis with all parameters
01453  *
01454  * \param[in] mailbox The mailbox identifier string.
01455  * \param[in] context The context this mailbox resides in (NULL or "" if only using mailbox)
01456  * \param[in] new_msgs The number of new messages in this mailbox
01457  * \param[in] old_msgs The number of old messages in this mailbox
01458  * \param[in] channel_id A unique identifier for a channel associated with this
01459  * change in mailbox state
01460  * \param[in] eid The EID of the server that originally published the message
01461  *
01462  * \retval 0 Success
01463  * \retval -1 Failure
01464  */
01465 int ast_publish_mwi_state_full(
01466    const char *mailbox,
01467    const char *context,
01468    int new_msgs,
01469    int old_msgs,
01470    const char *channel_id,
01471    struct ast_eid *eid);
01472 
01473 /*!
01474  * \since 12.2.0
01475  * \brief Delete MWI state cached by stasis
01476  *
01477  * \param[in] mailbox The mailbox identifier string.
01478  * \param[in] context The context this mailbox resides in (NULL or "" if only using mailbox)
01479  *
01480  * \retval 0 Success
01481  * \retval -1 Failure
01482  */
01483 #define ast_delete_mwi_state(mailbox, context) \
01484    ast_delete_mwi_state_full(mailbox, context, NULL)
01485 
01486 /*!
01487  * \since 12.2.0
01488  * \brief Delete MWI state cached by stasis with all parameters
01489  *
01490  * \param[in] mailbox The mailbox identifier string.
01491  * \param[in] context The context this mailbox resides in (NULL or "" if only using mailbox)
01492  * \param[in] eid The EID of the server that originally published the message
01493  *
01494  * \retval 0 Success
01495  * \retval -1 Failure
01496  */
01497 int ast_delete_mwi_state_full(const char *mailbox, const char *context, struct ast_eid *eid);
01498 
01499 /*! \addtogroup StasisTopicsAndMessages
01500  * @{
01501  */
01502 
01503 /*!
01504  * \brief The structure that contains MWI state
01505  * \since 12
01506  */
01507 struct ast_mwi_state {
01508    AST_DECLARE_STRING_FIELDS(
01509       AST_STRING_FIELD(uniqueid);  /*!< Unique identifier for this mailbox */
01510    );
01511    int new_msgs;                    /*!< The current number of new messages for this mailbox */
01512    int old_msgs;                    /*!< The current number of old messages for this mailbox */
01513    /*! If applicable, a snapshot of the channel that caused this MWI change */
01514    struct ast_channel_snapshot *snapshot;
01515    struct ast_eid eid;              /*!< The EID of the server where this message originated */
01516 };
01517 
01518 /*!
01519  * \brief Object that represents an MWI update with some additional application
01520  * defined data
01521  */
01522 struct ast_mwi_blob {
01523    struct ast_mwi_state *mwi_state;    /*!< MWI state */
01524    struct ast_json *blob;              /*!< JSON blob of data */
01525 };
01526 
01527 /*!
01528  * \since 12
01529  * \brief Create a \ref ast_mwi_state object
01530  *
01531  * \param[in] mailbox The mailbox identifier string.
01532  * \param[in] context The context this mailbox resides in (NULL or "" if only using mailbox)
01533  *
01534  * \retval \ref ast_mwi_state object on success
01535  * \retval NULL on error
01536  */
01537 struct ast_mwi_state *ast_mwi_create(const char *mailbox, const char *context);
01538 
01539 /*!
01540  * \since 12
01541  * \brief Creates a \ref ast_mwi_blob message.
01542  *
01543  * The \a blob JSON object requires a \c "type" field describing the blob. It
01544  * should also be treated as immutable and not modified after it is put into the
01545  * message.
01546  *
01547  * \param mwi_state MWI state associated with the update
01548  * \param message_type The type of message to create
01549  * \param blob JSON object representing the data.
01550  * \return \ref ast_mwi_blob message.
01551  * \return \c NULL on error
01552  */
01553 struct stasis_message *ast_mwi_blob_create(struct ast_mwi_state *mwi_state,
01554                   struct stasis_message_type *message_type,
01555                   struct ast_json *blob);
01556 
01557 /*!
01558  * \brief Get the \ref stasis topic for MWI messages
01559  * \retval The topic structure for MWI messages
01560  * \retval NULL if it has not been allocated
01561  * \since 12
01562  */
01563 struct stasis_topic *ast_mwi_topic_all(void);
01564 
01565 /*!
01566  * \brief Get the \ref stasis topic for MWI messages on a unique ID
01567  * \param uniqueid The unique id for which to get the topic
01568  * \retval The topic structure for MWI messages for a given uniqueid
01569  * \retval NULL if it failed to be found or allocated
01570  * \since 12
01571  */
01572 struct stasis_topic *ast_mwi_topic(const char *uniqueid);
01573 
01574 /*!
01575  * \brief Get the \ref stasis caching topic for MWI messages
01576  * \retval The caching topic structure for MWI messages
01577  * \retval NULL if it has not been allocated
01578  * \since 12
01579  */
01580 struct stasis_topic *ast_mwi_topic_cached(void);
01581 
01582 /*!
01583  * \brief Backend cache for ast_mwi_topic_cached().
01584  * \retval Cache of \ref ast_mwi_state.
01585  */
01586 struct stasis_cache *ast_mwi_state_cache(void);
01587 
01588 /*!
01589  * \brief Get the \ref stasis message type for MWI messages
01590  * \retval The message type structure for MWI messages
01591  * \retval NULL on error
01592  * \since 12
01593  */
01594 struct stasis_message_type *ast_mwi_state_type(void);
01595 
01596 /*!
01597  * \brief Get the \ref stasis message type for voicemail application specific messages
01598  *
01599  * This message type exists for those messages a voicemail application may wish to send
01600  * that have no logical relationship with other voicemail applications. Voicemail apps
01601  * that use this message type must pass a \ref ast_mwi_blob. Any extraneous information
01602  * in the JSON blob must be packed as key/value pair tuples of strings.
01603  *
01604  * At least one key/value tuple must have a key value of "Event".
01605  *
01606  * \retval The \ref stasis_message_type for voicemail application specific messages
01607  * \retval NULL on error
01608  * \since 12
01609  */
01610 struct stasis_message_type *ast_mwi_vm_app_type(void);
01611 
01612 /*!
01613  * \brief Get the \ref stasis topic for queue messages
01614  * \retval The topic structure for queue messages
01615  * \retval NULL if it has not been allocated
01616  * \since 12
01617  */
01618 struct stasis_topic *ast_queue_topic_all(void);
01619 
01620 /*!
01621  * \brief Get the \ref stasis topic for queue messages for a particular queue name
01622  * \param queuename The name for which to get the topic
01623  * \retval The topic structure for queue messages for a given name
01624  * \retval NULL if it failed to be found or allocated
01625  * \since 12
01626  */
01627 struct stasis_topic *ast_queue_topic(const char *queuename);
01628 /*! @} */
01629 
01630 /*!
01631  * \brief Initialize the application core
01632  * \retval 0 Success
01633  * \retval -1 Failure
01634  * \since 12
01635  */
01636 int app_init(void);
01637 
01638 #define AST_MAX_MAILBOX_UNIQUEID (AST_MAX_EXTENSION + AST_MAX_CONTEXT + 2)
01639 #if defined(__cplusplus) || defined(c_plusplus)
01640 }
01641 #endif
01642 
01643 #endif /* _ASTERISK_APP_H */

Generated on Thu Apr 16 06:27:08 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6