Add support for Digium Phones.

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8-digiumphones@357459 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Jason Parker
2012-02-28 21:52:48 +00:00
parent f11923e651
commit f9834fd128
41 changed files with 6074 additions and 153 deletions

View File

@@ -47,6 +47,7 @@ int ast_cel_engine_init(void); /*!< Provided by cel.c */
int ast_cel_engine_reload(void); /*!< Provided by cel.c */
int ast_ssl_init(void); /*!< Provided by ssl.c */
int ast_test_init(void); /*!< Provided by test.c */
int ast_msg_init(void); /*!< Provided by message.c */
/*!
* \brief Reload asterisk modules.

View File

@@ -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);

View File

@@ -0,0 +1,193 @@
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2011, Digium, Inc.
*
* David Vossel <dvossel@digium.com>
*
* 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 <dvossel@digium.com>
*/
#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

View File

@@ -3500,4 +3500,14 @@ int ast_channel_get_cc_agent_type(struct ast_channel *chan, char *agent_type, si
}
#endif
/*!
* \brief Remove a channel from the global channels container
*
* \param chan channel to remove
*
* In a case where it is desired that a channel not be available in any lookups
* in the global channels conatiner, use this function.
*/
void ast_channel_unlink(struct ast_channel *chan);
#endif /* _ASTERISK_CHANNEL_H */

View File

@@ -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 {
butt,
};
/*
* \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
*

View File

@@ -0,0 +1,79 @@
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2011, Digium, Inc.
*
* David Vossel <dvossel@digium.com>
*
* 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

View File

@@ -54,8 +54,11 @@ 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 */
@@ -283,8 +286,12 @@ enum ast_event_ie_type {
AST_EVENT_IE_CHALLENGE = 0x0032,
AST_EVENT_IE_RESPONSE = 0x0033,
AST_EVENT_IE_EXPECTED_RESPONSE = 0x0034,
AST_EVENT_IE_PRESENCE_PROVIDER = 0x0035,
AST_EVENT_IE_PRESENCE_STATE = 0x0036,
AST_EVENT_IE_PRESENCE_SUBTYPE = 0x0037,
AST_EVENT_IE_PRESENCE_MESSAGE = 0x0038,
/*! \brief Must be the last IE value +1 */
AST_EVENT_IE_TOTAL = 0x0035,
AST_EVENT_IE_TOTAL = 0x0039,
};
/*!

View File

@@ -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
@@ -160,6 +174,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.
*

View File

@@ -334,6 +334,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_UPDATE_RTP_PEER = 31, /*!< Interrupt the bridge and have it update the peer */
};

View File

@@ -157,6 +157,7 @@ struct aji_client {
char name_space[256];
char sid[10]; /* Session ID */
char mid[6]; /* Message ID */
char context[AST_MAX_CONTEXT];
iksid *jid;
iksparser *p;
iksfilter *f;
@@ -179,6 +180,7 @@ struct aji_client {
int message_timeout;
int authorized;
int distribute_events;
int send_to_dialplan;
struct ast_flags flags;
int component; /* 0 client, 1 component */
struct aji_buddy_container buddies;

View File

@@ -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 */

272
include/asterisk/message.h Normal file
View File

@@ -0,0 +1,272 @@
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2010, Digium, Inc.
*
* Russell Bryant <russell@digium.com>
*
* 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 Out-of-call text message support
*
* \author Russell Bryant <russell@digium.com>
*
* The purpose of this API is to provide support for text messages that
* are not session based. The messages are passed into the Asterisk core
* to be routed through the dialplan and potentially sent back out through
* a message technology that has been registered through this API.
*/
#ifndef __AST_MESSAGE_H__
#define __AST_MESSAGE_H__
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
/*!
* \brief A text message.
*
* This is an opaque type that represents a text message.
*/
struct ast_msg;
/*!
* \brief A message technology
*
* A message technology is capable of transmitting text messages.
*/
struct ast_msg_tech {
/*!
* \brief Name of this message technology
*
* This is the name that comes at the beginning of a URI for messages
* that should be sent to this message technology implementation.
* For example, messages sent to "xmpp:rbryant@digium.com" would be
* passed to the ast_msg_tech with a name of "xmpp".
*/
const char * const name;
/*!
* \brief Send a message.
*
* \param msg the message to send
* \param to the URI of where the message is being sent
* \param from the URI of where the message was sent from
*
* The fields of the ast_msg are guaranteed not to change during the
* duration of this function call.
*
* \retval 0 success
* \retval non-zero failure
*/
int (* const msg_send)(const struct ast_msg *msg, const char *to, const char *from);
};
/*!
* \brief Register a message technology
*
* \retval 0 success
* \retval non-zero failure
*/
int ast_msg_tech_register(const struct ast_msg_tech *tech);
/*!
* \brief Unregister a message technology.
*
* \retval 0 success
* \retval non-zero failure
*/
int ast_msg_tech_unregister(const struct ast_msg_tech *tech);
/*!
* \brief Allocate a message.
*
* Allocate a message for the purposes of passing it into the Asterisk core
* to be routed through the dialplan. If ast_msg_queue() is not called, this
* message must be destroyed using ast_msg_destroy(). Otherwise, the message
* core code will take care of it.
*
* \return A message object. This function will return NULL if an allocation
* error occurs.
*/
struct ast_msg *ast_msg_alloc(void);
/*!
* \brief Destroy an ast_msg
*
* This should only be called on a message if it was not
* passed on to ast_msg_queue().
*
* \return NULL, always.
*/
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
*
* \retval 0 success
* \retval -1 failure
*/
int __attribute__((format(printf, 2, 3)))
ast_msg_set_to(struct ast_msg *msg, const char *fmt, ...);
/*!
* \brief Set the 'from' URI of a message
*
* \retval 0 success
* \retval -1 failure
*/
int __attribute__((format(printf, 2, 3)))
ast_msg_set_from(struct ast_msg *msg, const char *fmt, ...);
/*!
* \brief Set the 'body' text of a message (in UTF-8)
*
* \retval 0 success
* \retval -1 failure
*/
int __attribute__((format(printf, 2, 3)))
ast_msg_set_body(struct ast_msg *msg, const char *fmt, ...);
/*!
* \brief Set the dialplan context for this message
*
* \retval 0 success
* \retval -1 failure
*/
int __attribute__((format(printf, 2, 3)))
ast_msg_set_context(struct ast_msg *msg, const char *fmt, ...);
/*!
* \brief Set the dialplan extension for this message
*
* \retval 0 success
* \retval -1 failure
*/
int __attribute__((format(printf, 2, 3)))
ast_msg_set_exten(struct ast_msg *msg, const char *fmt, ...);
/*!
* \brief Set a variable on the message going to the dialplan
* \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(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
* to the message if you plan on storing the return value. Do re-set the same
* message var name while holding a pointer to the result of this function.
*
* \return The value associated with variable "name". NULL if variable not found.
*/
const char *ast_msg_get_var(struct ast_msg *msg, const char *name);
/*!
* \brief Get the body of a message.
* \note The return value is valid only as long as the ast_message is valid. Hold a reference
* to the message if you plan on storing the return value.
*
* \return The body of the messsage, encoded in UTF-8.
*/
const char *ast_msg_get_body(const struct ast_msg *msg);
/*!
* \brief Queue a message for routing through the dialplan.
*
* 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
* \retval non-zero failure, message not sent to dialplan
*/
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
*/
struct ast_msg_var_iterator;
/*!
* \brief Create a new message variable iterator
* \param msg A message whose variables are to be iterated over
*
* \return An opaque pointer to the new iterator
*/
struct ast_msg_var_iterator *ast_msg_var_iterator_init(const struct ast_msg *msg);
/*!
* \brief Get the next variable name and value that is set for sending outbound
* \param msg The message with the variables
* \param i An iterator created with ast_msg_var_iterator_init
* \param name A pointer to the name result pointer
* \param value A pointer to the value result pointer
*
* \retval 0 No more entries
* \retval 1 Valid entry
*/
int ast_msg_var_iterator_next(const struct ast_msg *msg, struct ast_msg_var_iterator *i, const char **name, const char **value);
/*!
* \brief Destroy a message variable iterator
* \param i Iterator to be destroyed
*/
void ast_msg_var_iterator_destroy(struct ast_msg_var_iterator *i);
/*!
* \brief Unref a message var from inside an iterator loop
*/
void ast_msg_var_unref_current(struct ast_msg_var_iterator *i);
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
#endif /* __AST_MESSAGE_H__ */

View File

@@ -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)(char *context, char *id, 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
*

View File

@@ -0,0 +1,95 @@
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2011, Digium, Inc.
*
* David Vossel <dvossel@digium.com>
*
* 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