From: Mark Michelson Date: Wed, 4 Apr 2012 19:26:30 +0000 (+0000) Subject: Add Digium phone changes for the include/asterisk directory X-Git-Tag: 10.4.0-digiumphones-rc1~3^2~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f612abf55c00c36ccde57ae9c4da9e790141a8d;p=thirdparty%2Fasterisk.git Add Digium phone changes for the include/asterisk directory git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/10-digiumphones@361206 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/include/asterisk/app.h b/include/asterisk/app.h index edc6530619..388aeac426 100644 --- a/include/asterisk/app.h +++ b/include/asterisk/app.h @@ -23,8 +23,10 @@ #ifndef _ASTERISK_APP_H #define _ASTERISK_APP_H +#include "asterisk/stringfields.h" #include "asterisk/strings.h" #include "asterisk/threadstorage.h" +#include "asterisk/file.h" struct ast_flags64; @@ -78,6 +80,27 @@ struct ast_ivr_menu { struct ast_ivr_option *options; /*!< All options */ }; +/*! + * \brief Structure used for ast_copy_recording_to_vm in order to cleanly supply + * data needed for making the recording from the recorded file. + */ +struct ast_vm_recording_data { + AST_DECLARE_STRING_FIELDS( + AST_STRING_FIELD(context); + AST_STRING_FIELD(mailbox); + AST_STRING_FIELD(folder); + AST_STRING_FIELD(recording_file); + AST_STRING_FIELD(recording_ext); + + AST_STRING_FIELD(call_context); + AST_STRING_FIELD(call_macrocontext); + AST_STRING_FIELD(call_extension); + AST_STRING_FIELD(call_callerchan); + AST_STRING_FIELD(call_callerid); + ); + int call_priority; +}; + #define AST_IVR_FLAG_AUTORESTART (1 << 0) #define AST_IVR_DECLARE_MENU(holder, title, flags, foo...) \ @@ -147,10 +170,19 @@ void ast_install_vm_functions(int (*has_voicemail_func)(const char *mailbox, con int (*inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs), int (*inboxcount2_func)(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs), int (*messagecount_func)(const char *context, const char *mailbox, const char *folder), - int (*sayname_func)(struct ast_channel *chan, const char *mailbox, const char *context)); + int (*sayname_func)(struct ast_channel *chan, const char *mailbox, const char *context), + int (*copy_recording_to_vm_func)(struct ast_vm_recording_data *vm_rec_data)); void ast_uninstall_vm_functions(void); +/*! + * \brief + * param[in] vm_rec_data Contains data needed to make the recording. + * retval 0 voicemail successfully created from recording. + * retval -1 Failure + */ +int ast_app_copy_recording_to_vm(struct ast_vm_recording_data *vm_rec_data); + /*! * \brief Determine if a given mailbox has any voicemail * If folder is NULL, defaults to "INBOX". If folder is "INBOX", includes the @@ -267,6 +299,29 @@ int ast_linear_stream(struct ast_channel *chan, const char *filename, int fd, in */ 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); +/*! + * \brief Stream a file with fast forward, pause, reverse, restart. + * \param chan + * \param file filename + * \param fwd, rev, stop, pause, restart, skipms, offsetms + * \param waitstream callback to invoke when fastforward or rewind occurrs. + * + * Before calling this function, set this to be the number + * of ms to start from the beginning of the file. When the function + * returns, it will be the number of ms from the beginning where the + * playback stopped. Pass NULL if you don't care. + */ +int ast_control_streamfile_w_cb(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, + ast_waitstream_fr_cb cb); + /*! \brief Play a stream and wait for a digit, returning the digit that was pressed */ int ast_play_and_wait(struct ast_channel *chan, const char *fn); diff --git a/include/asterisk/app_voicemail.h b/include/asterisk/app_voicemail.h new file mode 100644 index 0000000000..03a43d9040 --- /dev/null +++ b/include/asterisk/app_voicemail.h @@ -0,0 +1,194 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2011-2012, Digium, Inc. + * + * David Vossel + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +/*! \file + * \brief Voice Mail API + * \author David Vossel + */ + +#ifndef _ASTERISK_VM_H +#define _ASTERISK_VM_H + +#include "asterisk/stringfields.h" +#include "asterisk/linkedlists.h" + +#define AST_VM_FOLDER_NUMBER 12 + +enum ast_vm_snapshot_sort_val { + AST_VM_SNAPSHOT_SORT_BY_ID = 0, + AST_VM_SNAPSHOT_SORT_BY_TIME, +}; + +struct ast_vm_msg_snapshot { + AST_DECLARE_STRING_FIELDS( + AST_STRING_FIELD(msg_id); + AST_STRING_FIELD(callerid); + AST_STRING_FIELD(callerchan); + AST_STRING_FIELD(exten); + AST_STRING_FIELD(origdate); + AST_STRING_FIELD(origtime); + AST_STRING_FIELD(duration); + AST_STRING_FIELD(folder_name); + AST_STRING_FIELD(folder_dir); + AST_STRING_FIELD(flag); + ); + unsigned int msg_number; + + AST_LIST_ENTRY(ast_vm_msg_snapshot) msg; +}; + +struct ast_vm_mailbox_snapshot { + int total_msg_num; + AST_LIST_HEAD_NOLOCK(, ast_vm_msg_snapshot) snapshots[AST_VM_FOLDER_NUMBER]; +}; + +/* + * \brief Create a snapshot of a mailbox which contains information about every msg. + * + * \param mailbox, the mailbox to look for + * \param context, the context to look for the mailbox in + * \param folder, OPTIONAL. When not NULL only msgs from the specified folder will be included. + * \param desending, list the msgs in descending order rather than ascending order. + * \param combine_INBOX_and_OLD, When this argument is set, The OLD folder will be represented + * in the INBOX folder of the snapshot. This allows the snapshot to represent the + * OLD and INBOX messages in sorted order merged together. + * + * \retval snapshot on success + * \retval NULL on failure + */ +struct ast_vm_mailbox_snapshot *ast_vm_mailbox_snapshot_create(const char *mailbox, + const char *context, + const char *folder, + int descending, + enum ast_vm_snapshot_sort_val sort_val, + int combine_INBOX_and_OLD); + +/* + * \brief destroy a snapshot + * + * \param mailbox_snapshot The snapshot to destroy. + * \retval NULL + */ +struct ast_vm_mailbox_snapshot *ast_vm_mailbox_snapshot_destroy(struct ast_vm_mailbox_snapshot *mailbox_snapshot); + +/*! + * \brief Move messages from one folder to another + * + * \param mailbox The mailbox to which the folders belong + * \param context The voicemail context for the mailbox + * \param num_msgs The number of messages to move + * \param oldfolder The folder from where messages should be moved + * \param old_msg_nums The message IDs of the messages to move + * \param newfolder The folder to which messages should be moved + * \param new_msg_ids[out] An array of message IDs for the messages as they are in the + * new folder. This array must be num_msgs sized. + * + * \retval -1 Failure + * \retval 0 Success + */ +int ast_vm_msg_move(const char *mailbox, + const char *context, + size_t num_msgs, + const char *oldfolder, + int *old_msg_ids, + const char *newfolder, + int *new_msg_ids); + +/*! + * \brief Remove/delete messages from a mailbox folder. + * + * \param mailbox The mailbox from which to delete messages + * \param context The voicemail context for the mailbox + * \param num_msgs The number of messages to delete + * \param folder The folder from which to remove messages + * \param msgs The message IDs of the messages to delete + * + * \retval -1 Failure + * \retval 0 Success + */ +int ast_vm_msg_remove(const char *mailbox, + const char *context, + size_t num_msgs, + const char *folder, + int *msgs); + +/*! + * \brief forward a message from one mailbox to another. + * + * \brief from_mailbox The original mailbox the message is being forwarded from + * \brief from_context The voicemail context of the from_mailbox + * \brief from_folder The folder from which the message is being forwarded + * \brief to_mailbox The mailbox to forward the message to + * \brief to_context The voicemail context of the to_mailbox + * \brief to_folder The folder to which the message is being forwarded + * \brief num_msgs The number of messages being forwarded + * \brief msg_ids The message IDs of the messages in from_mailbox to forward + * \brief delete_old If non-zero, the forwarded messages are also deleted from from_mailbox. + * Otherwise, the messages will remain in the from_mailbox. + * + * \retval -1 Failure + * \retval 0 Success + */ +int ast_vm_msg_forward(const char *from_mailbox, + const char *from_context, + const char *from_folder, + const char *to_mailbox, + const char *to_context, + const char *to_folder, + size_t num_msgs, + int *msg_ids, + int delete_old); + +/*! + * \brief Voicemail playback callback function definition + * + * \param channel to play the file back on. + * \param location of file on disk + * \param duration of file in seconds. This will be zero if msg is very short or + * has an unknown duration. + */ +typedef void (ast_vm_msg_play_cb)(struct ast_channel *chan, const char *playfile, int duration); + +/*! + * \brief Play a voicemail msg back on a channel. + * + * \param mailbox msg is in. + * \param context of mailbox. + * \param voicemail folder to look in. + * \param message number in the voicemailbox to playback to the channel. + * + * \retval 0 success + * \retval -1 failure + */ +int ast_vm_msg_play(struct ast_channel *chan, + const char *mailbox, + const char *context, + const char *folder, + const char *msg_num, + ast_vm_msg_play_cb cb); + +/*! + * \brief Get the name of a folder given its numeric index + * + * \param index The integer value of the mailbox. + * \retval "" Invalid index provided + * \retval other The name of the mailbox + */ +const char *ast_vm_index_to_foldername(unsigned int index); +#endif + diff --git a/include/asterisk/config.h b/include/asterisk/config.h index 86c2bb5dd4..eb3ae79e6b 100644 --- a/include/asterisk/config.h +++ b/include/asterisk/config.h @@ -590,6 +590,65 @@ int config_text_file_save(const char *filename, const struct ast_config *cfg, co struct ast_config *ast_config_internal_load(const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked); +/*! + * \brief + * Copies the contents of one ast_config into another + * + * \note + * This creates a config on the heap. The caller of this must + * be prepared to free the memory returned. + * + * \param orig the config to copy + * \return The new config on success, NULL on failure. + */ +struct ast_config *ast_config_copy(const struct ast_config *orig); + +/*! + * \brief + * Flags that affect the behaviour of config hooks. + */ +enum config_hook_flags { + blah, +}; + +/* + * \brief Callback when configuration is updated + * + * \param cfg A copy of the configuration that is being changed. + * This MUST be freed by the callback before returning. + */ +typedef int (*config_hook_cb)(struct ast_config *cfg); + +/*! + * \brief + * Register a config hook for a particular file and module + * + * \param name The name of the hook you are registering. + * \param filename The file whose config you wish to hook into. + * \param module The module that is reloading the config. This + * can be useful if multiple modules may possibly + * reload the same file, but you are only interested + * when a specific module reloads the file + * \param flags Flags that affect the way hooks work. + * \param hook The callback to be called when config is loaded. + * return 0 Success + * return -1 Unsuccess, also known as UTTER AND COMPLETE FAILURE + */ +int ast_config_hook_register(const char *name, + const char *filename, + const char *module, + enum config_hook_flags flags, + config_hook_cb hook); + +/*! + * \brief + * Unregister a config hook + * + * \param name The name of the hook to unregister + */ +void ast_config_hook_unregister(const char *name); + + /*! * \brief Support code to parse config file arguments * diff --git a/include/asterisk/custom_control_frame.h b/include/asterisk/custom_control_frame.h new file mode 100644 index 0000000000..843f6fdbd7 --- /dev/null +++ b/include/asterisk/custom_control_frame.h @@ -0,0 +1,80 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2011-2012, Digium, Inc. + * + * David Vossel + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +/*! \file + * \brief Defines the use of the AST_CONTROL_CUSTOM control frame subclass. + */ + +#ifndef _ASTERISK_CUSTOM_FRAME_H +#define _ASTERISK_CUSTOM_FRAME_H + +#include "asterisk/config.h" + +/*! \brief this is the payload structure used in every AST_CONTROL_CUSTOM frame. */ +struct ast_custom_payload; + +enum ast_custom_payload_type { + /*! Custom SIP INFO payload type, used only in the sip channel driver. */ + AST_CUSTOM_SIP_INFO, +}; + +/*! + * \brief returns the type of payload the custom payload represents + * + * \retval payload type, on success + * \retval -1, on failure + */ +enum ast_custom_payload_type ast_custom_payload_type(struct ast_custom_payload *type); + +/*! + * \brief returns the length of a custom payload + * + * \retval len on success + * \retval -1 on failure + */ +size_t ast_custom_payload_len(struct ast_custom_payload *type); + +/*! + * \brief Encodes and allocates a sip info custom payload type + * + * \retval encoded custom payload on success + * \retval NULL on failure. + */ +struct ast_custom_payload *ast_custom_payload_sipinfo_encode(struct ast_variable *headers, + const char *content_type, + const char *content, + const char *useragent_filter); + +/*! + * \brief Decodes a sip info custom payload type, returns results in parameters. + * + * \note This is the reverse of the encode function. Pass in a payload, get the headers + * content type and content variables back out. Make sure to free all the variables + * this function returns. + * + * \retval 0, variables allocated and returned in output parameters + * \retval -1, failure no variables were allocated. + */ +int ast_custom_payload_sipinfo_decode(struct ast_custom_payload *pl, + struct ast_variable **headers, + char **content_type, + char **content, + char **useragent_filter); + +#endif + diff --git a/include/asterisk/event_defs.h b/include/asterisk/event_defs.h index 4d18922563..88b41699b2 100644 --- a/include/asterisk/event_defs.h +++ b/include/asterisk/event_defs.h @@ -54,8 +54,10 @@ enum ast_event_type { AST_EVENT_SECURITY = 0x08, /*! Used by res_stun_monitor to alert listeners to an exernal network address change. */ AST_EVENT_NETWORK_CHANGE = 0x09, + /*! The presence state for a presence provider */ + AST_EVENT_PRESENCE_STATE = 0x0a, /*! Number of event types. This should be the last event type + 1 */ - AST_EVENT_TOTAL = 0x0a, + AST_EVENT_TOTAL = 0x0b, }; /*! \brief Event Information Element types */ @@ -287,6 +289,10 @@ enum ast_event_ie_type { AST_EVENT_IE_RECEIVED_HASH = 0x0036, AST_EVENT_IE_USING_PASSWORD = 0x0037, AST_EVENT_IE_ATTEMPTED_TRANSPORT = 0x0038, + AST_EVENT_IE_PRESENCE_PROVIDER = 0x0039, + AST_EVENT_IE_PRESENCE_STATE = 0x003a, + AST_EVENT_IE_PRESENCE_SUBTYPE = 0x003b, + AST_EVENT_IE_PRESENCE_MESSAGE = 0x003c, /*! \brief Must be the last IE value +1 */ AST_EVENT_IE_TOTAL = 0x0039, diff --git a/include/asterisk/file.h b/include/asterisk/file.h index 4b03251011..5558afce14 100644 --- a/include/asterisk/file.h +++ b/include/asterisk/file.h @@ -48,7 +48,21 @@ struct ast_format; #define AST_DIGIT_ANYNUM "0123456789" #define SEEK_FORCECUR 10 - + +/*! The type of event associated with a ast_waitstream_fr_cb invocation */ +enum ast_waitstream_fr_cb_values { + AST_WAITSTREAM_CB_REWIND = 1, + AST_WAITSTREAM_CB_FASTFORWARD, + AST_WAITSTREAM_CB_START +}; + +/*! + * \brief callback used during dtmf controlled file playback to indicate + * location of playback in a file after rewinding or fastfowarding + * a file. + */ +typedef void (ast_waitstream_fr_cb)(struct ast_channel *chan, long ms, enum ast_waitstream_fr_cb_values val); + /*! * \brief Streams a file * \param c channel to stream the file to @@ -161,6 +175,28 @@ int ast_waitstream_exten(struct ast_channel *c, const char *context); */ int ast_waitstream_fr(struct ast_channel *c, const char *breakon, const char *forward, const char *rewind, int ms); +/*! + * \brief Same as waitstream_fr but allows a callback to be alerted when a user + * fastforwards or rewinds the file. + * \param c channel to waitstream on + * \param breakon string of DTMF digits to break upon + * \param forward DTMF digit to fast forward upon + * \param rewind DTMF digit to rewind upon + * \param ms How many milliseconds to skip forward/back + * \param cb to call when rewind or fastfoward occurs. + * Begins playback of a stream... + * Wait for a stream to stop or for any one of a given digit to arrive, + * \retval 0 if the stream finishes. + * \retval the character if it was interrupted. + * \retval -1 on error. + */ +int ast_waitstream_fr_w_cb(struct ast_channel *c, + const char *breakon, + const char *forward, + const char *rewind, + int ms, + ast_waitstream_fr_cb cb); + /*! * Same as waitstream, but with audio output to fd and monitored fd checking. * diff --git a/include/asterisk/frame.h b/include/asterisk/frame.h index 4e013534db..1bf22c4b81 100644 --- a/include/asterisk/frame.h +++ b/include/asterisk/frame.h @@ -263,6 +263,7 @@ enum ast_control_frame_type { AST_CONTROL_READ_ACTION = 27, /*!< Tell ast_read to take a specific action */ AST_CONTROL_AOC = 28, /*!< Advice of Charge with encoded generic AOC payload */ AST_CONTROL_END_OF_Q = 29, /*!< Indicate that this position was the end of the channel queue for a softhangup. */ + AST_CONTROL_CUSTOM = 200, /*!< Indicate a custom channel driver specific payload. Look in custom_control_frame.h for how to define and use this frame. */ AST_CONTROL_INCOMPLETE = 30, /*!< Indication that the extension dialed is incomplete */ AST_CONTROL_MCID = 31, /*!< Indicate that the caller is being malicious. */ AST_CONTROL_UPDATE_RTP_PEER = 32, /*!< Interrupt the bridge and have it update the peer */ diff --git a/include/asterisk/manager.h b/include/asterisk/manager.h index f30cc7329d..509cdfd510 100644 --- a/include/asterisk/manager.h +++ b/include/asterisk/manager.h @@ -86,6 +86,7 @@ #define EVENT_FLAG_CC (1 << 15) /* Call Completion events */ #define EVENT_FLAG_AOC (1 << 16) /* Advice Of Charge events */ #define EVENT_FLAG_TEST (1 << 17) /* Test event used to signal the Asterisk Test Suite */ +#define EVENT_FLAG_MESSAGE (1 << 30) /* MESSAGE events. */ /*@} */ /*! \brief Export manager structures */ diff --git a/include/asterisk/message.h b/include/asterisk/message.h index d989563e56..ce86e9c7a9 100644 --- a/include/asterisk/message.h +++ b/include/asterisk/message.h @@ -113,6 +113,11 @@ struct ast_msg *ast_msg_alloc(void); */ struct ast_msg *ast_msg_destroy(struct ast_msg *msg); +/*! + * \brief Bump a msg's ref count + */ +struct ast_msg *ast_msg_ref(struct ast_msg *msg); + /*! * \brief Set the 'to' URI of a message * @@ -170,6 +175,18 @@ int __attribute__((format(printf, 2, 3))) */ int ast_msg_set_var(struct ast_msg *msg, const char *name, const char *value); +/*! + * \brief Set a variable on the message being sent to a message tech directly. + * \note Setting a variable that already exists overwrites the existing variable value + * + * \param name Name of variable to set + * \param value Value of variable to set + * + * \retval 0 success + * \retval -1 failure + */ +int ast_msg_set_var_outbound(struct ast_msg *msg, const char *name, const char *value); + /*! * \brief Get the specified variable on the message * \note The return value is valid only as long as the ast_message is valid. Hold a reference @@ -200,6 +217,17 @@ const char *ast_msg_get_body(const struct ast_msg *msg); */ int ast_msg_queue(struct ast_msg *msg); +/*! + * \brief Send a msg directly to an endpoint. + * + * Regardless of the return value of this function, this funciton will take + * care of ensuring that the message object is properly destroyed when needed. + * + * \retval 0 message successfully queued to be sent out + * \retval non-zero failure, message not get sent out. + */ +int ast_msg_send(struct ast_msg *msg, const char *to, const char *from); + /*! * \brief Opaque iterator for msg variables */ diff --git a/include/asterisk/pbx.h b/include/asterisk/pbx.h index 02b0654f77..0a0a1685a3 100644 --- a/include/asterisk/pbx.h +++ b/include/asterisk/pbx.h @@ -26,6 +26,7 @@ #include "asterisk/channel.h" #include "asterisk/sched.h" #include "asterisk/devicestate.h" +#include "asterisk/presencestate.h" #include "asterisk/chanvars.h" #include "asterisk/hashtab.h" #include "asterisk/stringfields.h" @@ -75,8 +76,23 @@ struct ast_include; struct ast_ignorepat; struct ast_sw; +enum ast_state_cb_update_reason { + /*! The extension state update is a result of a device state changing on the extension. */ + AST_HINT_UPDATE_DEVICE = 1, + /*! The extension state update is a result of presence state changing on the extension. */ + AST_HINT_UPDATE_PRESENCE = 2, +}; + +struct ast_state_cb_info { + enum ast_state_cb_update_reason reason; + enum ast_extension_states exten_state; + enum ast_presence_state presence_state; + const char *presence_subtype; + const char *presence_message; +}; + /*! \brief Typedef for devicestate and hint callbacks */ -typedef int (*ast_state_cb_type)(const char *context, const char *exten, enum ast_extension_states state, void *data); +typedef int (*ast_state_cb_type)(char *context, char *id, struct ast_state_cb_info *info, void *data); /*! \brief Typedef for devicestate and hint callback removal indication callback */ typedef void (*ast_state_cb_destroy_type)(int id, void *data); @@ -401,6 +417,22 @@ enum ast_extension_states ast_devstate_to_extenstate(enum ast_device_state devst */ int ast_extension_state(struct ast_channel *c, const char *context, const char *exten); +/*! + * \brief Uses hint and presence state callback to get the presence state of an extension + * + * \param c this is not important + * \param context which context to look in + * \param exten which extension to get state + * \param[out] subtype Further information regarding the presence returned + * \param[out] message Custom message further describing current presence + * + * \note The subtype and message are dynamically allocated and must be freed by + * the caller of this function. + * + * \return returns the presence state value. + */ +int ast_hint_presence_state(struct ast_channel *c, const char *context, const char *exten, char **subtype, char **message); + /*! * \brief Return string representation of the state of an extension * diff --git a/include/asterisk/presencestate.h b/include/asterisk/presencestate.h new file mode 100644 index 0000000000..31499557ff --- /dev/null +++ b/include/asterisk/presencestate.h @@ -0,0 +1,96 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2011-2012, Digium, Inc. + * + * David Vossel + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +/*! \file + * \brief Presence state management + */ + +#ifndef _ASTERISK_PRESSTATE_H +#define _ASTERISK_PRESSTATE_H + +enum ast_presence_state { + AST_PRESENCE_NOT_SET = 0, + AST_PRESENCE_UNAVAILABLE, + AST_PRESENCE_AVAILABLE, + AST_PRESENCE_AWAY, + AST_PRESENCE_XA, + AST_PRESENCE_CHAT, + AST_PRESENCE_DND, +}; + +/*! \brief Presence state provider call back */ +typedef enum ast_presence_state (*ast_presence_state_prov_cb_type)(const char *data, char **subtype, char **message); + +/*! + * \brief Convert presence state to text string for output + * + * \param state Current presence state + */ +const char *ast_presence_state2str(enum ast_presence_state state); + +/*! + * \brief Convert presence state from text to integer value + * + * \param val The text representing the presence state. Valid values are anything + * that comes after AST_PRESENCE_ in one of the defined values. + * + * \return The AST_PRESENCE_ integer value + */ +enum ast_presence_state ast_presence_state_val(const char *val); + +/*! + * \brief Asks a presence state provider for the current presence state. + * + * \param presence_provider, The presence provider to retrieve the state from. + * \param subtype, The output paramenter to store the subtype string in. Must be freed if returned + * \param message, The output paramenter to store the message string in. Must be freed if returned + * + * \retval presence state value on success, + * \retval -1 on failure. + */ +enum ast_presence_state ast_presence_state(const char *presence_provider, char **subtype, char **message); + +/*! + * \brief Notify the world that a presence provider state changed. + */ +int ast_presence_state_changed(const char *presence_provider); + +/*! + * \brief Add presence state provider + * + * \param label to use in hint, like label:object + * \param callback Callback + * + * \retval 0 success + * \retval -1 failure + */ +int ast_presence_state_prov_add(const char *label, ast_presence_state_prov_cb_type callback); + +/*! + * \brief Remove presence state provider + * + * \param label to use in hint, like label:object + * + * \retval -1 on failure + * \retval 0 on success + */ +int ast_presence_state_prov_del(const char *label); + +int ast_presence_state_engine_init(void); +#endif +