[asterisk-commits] mmichelson: branch mmichelson/direct_media r383613 - in /team/mmichelson/dire...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Mar 22 14:43:21 CDT 2013
Author: mmichelson
Date: Fri Mar 22 14:43:18 2013
New Revision: 383613
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383613
Log:
Resolve conflicts and reset automerge.
Added:
team/mmichelson/direct_media/configs/stasis_core.conf.sample
- copied unchanged from r383581, team/group/pimp_my_sip/configs/stasis_core.conf.sample
team/mmichelson/direct_media/include/asterisk/stasis_message_router.h
- copied unchanged from r383581, team/group/pimp_my_sip/include/asterisk/stasis_message_router.h
team/mmichelson/direct_media/main/json.c
- copied unchanged from r383581, team/group/pimp_my_sip/main/json.c
team/mmichelson/direct_media/main/manager_channels.c
- copied unchanged from r383581, team/group/pimp_my_sip/main/manager_channels.c
team/mmichelson/direct_media/main/stasis_message_router.c
- copied unchanged from r383581, team/group/pimp_my_sip/main/stasis_message_router.c
Removed:
team/mmichelson/direct_media/res/res_json.c
team/mmichelson/direct_media/res/res_json.exports.in
Modified:
team/mmichelson/direct_media/ (props changed)
team/mmichelson/direct_media/CHANGES
team/mmichelson/direct_media/apps/app_minivm.c
team/mmichelson/direct_media/apps/app_userevent.c
team/mmichelson/direct_media/apps/app_voicemail.c
team/mmichelson/direct_media/channels/chan_dahdi.c
team/mmichelson/direct_media/channels/chan_gulp.c
team/mmichelson/direct_media/channels/chan_iax2.c
team/mmichelson/direct_media/channels/chan_mgcp.c
team/mmichelson/direct_media/channels/chan_sip.c
team/mmichelson/direct_media/channels/chan_skinny.c
team/mmichelson/direct_media/channels/chan_unistim.c
team/mmichelson/direct_media/channels/sig_pri.c
team/mmichelson/direct_media/channels/sig_pri.h
team/mmichelson/direct_media/channels/sip/include/sip.h
team/mmichelson/direct_media/codecs/Makefile
team/mmichelson/direct_media/configure
team/mmichelson/direct_media/configure.ac
team/mmichelson/direct_media/funcs/func_curl.c
team/mmichelson/direct_media/include/asterisk/app.h
team/mmichelson/direct_media/include/asterisk/astobj2.h
team/mmichelson/direct_media/include/asterisk/channel.h
team/mmichelson/direct_media/include/asterisk/manager.h
team/mmichelson/direct_media/include/asterisk/res_sip.h
team/mmichelson/direct_media/include/asterisk/res_sip_session.h
team/mmichelson/direct_media/include/asterisk/sorcery.h
team/mmichelson/direct_media/include/asterisk/stasis.h
team/mmichelson/direct_media/include/asterisk/xmpp.h
team/mmichelson/direct_media/main/app.c
team/mmichelson/direct_media/main/asterisk.c
team/mmichelson/direct_media/main/channel.c
team/mmichelson/direct_media/main/channel_internal_api.c
team/mmichelson/direct_media/main/http.c
team/mmichelson/direct_media/main/manager.c
team/mmichelson/direct_media/main/pbx.c
team/mmichelson/direct_media/main/sorcery.c
team/mmichelson/direct_media/main/stasis.c
team/mmichelson/direct_media/main/stasis_cache.c
team/mmichelson/direct_media/main/stasis_message.c
team/mmichelson/direct_media/main/tcptls.c
team/mmichelson/direct_media/pbx/pbx_realtime.c
team/mmichelson/direct_media/res/res_jabber.c
team/mmichelson/direct_media/res/res_sip.c
team/mmichelson/direct_media/res/res_sip.exports.in
team/mmichelson/direct_media/res/res_sip/config_transport.c
team/mmichelson/direct_media/res/res_sip/sip_configuration.c
team/mmichelson/direct_media/res/res_sip/sip_distributor.c
team/mmichelson/direct_media/res/res_sip_endpoint_identifier_ip.c
team/mmichelson/direct_media/res/res_sip_sdp_audio.c
team/mmichelson/direct_media/res/res_sip_session.c
team/mmichelson/direct_media/res/res_sorcery_memory.c
team/mmichelson/direct_media/res/res_xmpp.c
team/mmichelson/direct_media/tests/test_json.c
team/mmichelson/direct_media/tests/test_sorcery.c
team/mmichelson/direct_media/tests/test_stasis.c
Propchange: team/mmichelson/direct_media/
------------------------------------------------------------------------------
automerge = *
Propchange: team/mmichelson/direct_media/
------------------------------------------------------------------------------
Binary property 'branch-11-merged' - no diff available.
Propchange: team/mmichelson/direct_media/
------------------------------------------------------------------------------
--- direct_media-integrated (original)
+++ direct_media-integrated Fri Mar 22 14:43:18 2013
@@ -1,1 +1,1 @@
-/team/group/pimp_my_sip:1-383135
+/team/group/pimp_my_sip:1-383605
Propchange: team/mmichelson/direct_media/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Mar 22 14:43:18 2013
@@ -1,1 +1,1 @@
-/trunk:1-383127
+/trunk:1-383580
Modified: team/mmichelson/direct_media/CHANGES
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/direct_media/CHANGES?view=diff&rev=383613&r1=383612&r2=383613
==============================================================================
--- team/mmichelson/direct_media/CHANGES (original)
+++ team/mmichelson/direct_media/CHANGES Fri Mar 22 14:43:18 2013
@@ -41,6 +41,15 @@
mechanisms (such as the Playback application), the audio can be stopped,
reversed, or skipped forward.
+ * Channel related events now contain a snapshot of channel state, adding new
+ fields to many of these events.
+
+ * The AMI event 'Newexten' field 'Extension' is deprecated, and may be removed
+ in a future release. Please use the common 'Exten' field instead.
+
+ * The AMI event 'UserEvent' from app_userevent now contains the channel state
+ fields. The channel state fields will come before the body fields.
+
Channel Drivers
------------------
@@ -116,6 +125,14 @@
* ICE/STUN/TURN support in res_rtp_asterisk has been made optional. To enable
them, an Asterisk-specific version of pjproject needs to be installed.
Tarballs are available from https://github.com/asterisk/pjproject/tags/.
+
+XMPP
+------------------
+ * Device state for XMPP buddies is now available using the following format:
+ XMPP/<client name>/<buddy address>
+ If any resource is available the device state is considered to be not in use.
+ If no resources exist or all are unavailable the device state is considered
+ to be unavailable.
------------------------------------------------------------------------------
--- Functionality changes from Asterisk 10 to Asterisk 11 --------------------
Modified: team/mmichelson/direct_media/apps/app_minivm.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/direct_media/apps/app_minivm.c?view=diff&rev=383613&r1=383612&r2=383613
==============================================================================
--- team/mmichelson/direct_media/apps/app_minivm.c (original)
+++ team/mmichelson/direct_media/apps/app_minivm.c Fri Mar 22 14:43:18 2013
@@ -2013,7 +2013,6 @@
* \brief Queue a message waiting event */
static void queue_mwi_event(const char *mbx, const char *ctx, int urgent, int new, int old)
{
- struct ast_event *event;
char *mailbox, *context;
mailbox = ast_strdupa(mbx);
@@ -2022,16 +2021,7 @@
context = "default";
}
- if (!(event = ast_event_new(AST_EVENT_MWI,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
- AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, (new+urgent),
- AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, old,
- AST_EVENT_IE_END))) {
- return;
- }
-
- ast_event_queue_and_cache(event);
+ stasis_publish_mwi_state(mailbox, context, new + urgent, old);
}
/*!\internal
Modified: team/mmichelson/direct_media/apps/app_userevent.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/direct_media/apps/app_userevent.c?view=diff&rev=383613&r1=383612&r2=383613
==============================================================================
--- team/mmichelson/direct_media/apps/app_userevent.c (original)
+++ team/mmichelson/direct_media/apps/app_userevent.c Fri Mar 22 14:43:18 2013
@@ -33,6 +33,7 @@
#include "asterisk/module.h"
#include "asterisk/manager.h"
#include "asterisk/app.h"
+#include "asterisk/json.h"
/*** DOCUMENTATION
<application name="UserEvent" language="en_US">
@@ -68,11 +69,12 @@
AST_APP_ARG(eventname);
AST_APP_ARG(extra)[100];
);
- struct ast_str *body = ast_str_create(16);
+ RAII_VAR(struct ast_str *, body, ast_str_create(16), ast_free);
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+ RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "UserEvent requires an argument (eventname,optional event body)\n");
- ast_free(body);
return -1;
}
@@ -89,24 +91,21 @@
ast_str_append(&body, 0, "%s\r\n", args.extra[x]);
}
- /*** DOCUMENTATION
- <managerEventInstance>
- <synopsis>A user defined event raised from the dialplan.</synopsis>
- <parameter name="UserEvent">
- <para>The event name, as specified in the dialplan.</para>
- </parameter>
- <see-also>
- <ref type="application">UserEvent</ref>
- </see-also>
- </managerEventInstance>
- ***/
- manager_event(EVENT_FLAG_USER, "UserEvent",
- "UserEvent: %s\r\n"
- "Uniqueid: %s\r\n"
- "%s",
- args.eventname, ast_channel_uniqueid(chan), ast_str_buffer(body));
+ blob = ast_json_pack("{s: s, s: s, s: s}",
+ "type", "userevent",
+ "eventname", args.eventname,
+ "body", ast_str_buffer(body));
+ if (!blob) {
+ ast_log(LOG_WARNING, "Unable to create message buffer\n");
+ return -1;
+ }
- ast_free(body);
+ msg = ast_channel_blob_create(chan, blob);
+ if (!msg) {
+ return -1;
+ }
+
+ stasis_publish(ast_channel_topic(chan), msg);
return 0;
}
Modified: team/mmichelson/direct_media/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/direct_media/apps/app_voicemail.c?view=diff&rev=383613&r1=383612&r2=383613
==============================================================================
--- team/mmichelson/direct_media/apps/app_voicemail.c (original)
+++ team/mmichelson/direct_media/apps/app_voicemail.c Fri Mar 22 14:43:18 2013
@@ -974,10 +974,8 @@
static pthread_t poll_thread = AST_PTHREADT_NULL;
static unsigned char poll_thread_run;
-/*! Subscription to ... MWI event subscriptions */
-static struct ast_event_sub *mwi_sub_sub;
-/*! Subscription to ... MWI event un-subscriptions */
-static struct ast_event_sub *mwi_unsub_sub;
+/*! Subscription to MWI event subscription changes */
+static struct stasis_subscription *mwi_sub_sub;
/*!
* \brief An MWI subscription
@@ -991,15 +989,23 @@
int old_urgent;
int old_new;
int old_old;
- uint32_t uniqueid;
+ char *uniqueid;
char mailbox[1];
};
struct mwi_sub_task {
const char *mailbox;
const char *context;
- uint32_t uniqueid;
+ const char *uniqueid;
};
+
+static void mwi_sub_task_dtor(struct mwi_sub_task *mwist)
+{
+ ast_free((void *) mwist->mailbox);
+ ast_free((void *) mwist->context);
+ ast_free((void *) mwist->uniqueid);
+ ast_free(mwist);
+}
static struct ast_taskprocessor *mwi_subscription_tps;
@@ -7721,25 +7727,16 @@
static void queue_mwi_event(const char *box, int urgent, int new, int old)
{
- struct ast_event *event;
char *mailbox, *context;
/* Strip off @default */
context = mailbox = ast_strdupa(box);
strsep(&context, "@");
- if (ast_strlen_zero(context))
+ if (ast_strlen_zero(context)) {
context = "default";
-
- if (!(event = ast_event_new(AST_EVENT_MWI,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
- AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, (new+urgent),
- AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, old,
- AST_EVENT_IE_END))) {
- return;
- }
-
- ast_event_queue_and_cache(event);
+ }
+
+ stasis_publish_mwi_state(mailbox, context, new + urgent, old);
}
/*!
@@ -12533,28 +12530,28 @@
static void mwi_sub_destroy(struct mwi_sub *mwi_sub)
{
+ ast_free(mwi_sub->uniqueid);
ast_free(mwi_sub);
}
static int handle_unsubscribe(void *datap)
{
struct mwi_sub *mwi_sub;
- uint32_t *uniqueid = datap;
-
+ char *uniqueid = datap;
+
AST_RWLIST_WRLOCK(&mwi_subs);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&mwi_subs, mwi_sub, entry) {
- if (mwi_sub->uniqueid == *uniqueid) {
+ if (!strcmp(mwi_sub->uniqueid, uniqueid)) {
AST_LIST_REMOVE_CURRENT(entry);
- break;
+ /* Don't break here since a duplicate uniqueid
+ * may have been added as a result of a cache dump. */
+ mwi_sub_destroy(mwi_sub);
}
}
AST_RWLIST_TRAVERSE_SAFE_END
AST_RWLIST_UNLOCK(&mwi_subs);
- if (mwi_sub)
- mwi_sub_destroy(mwi_sub);
-
- ast_free(uniqueid);
+ ast_free(uniqueid);
return 0;
}
@@ -12574,7 +12571,7 @@
if (!(mwi_sub = ast_calloc(1, len)))
return -1;
- mwi_sub->uniqueid = p->uniqueid;
+ mwi_sub->uniqueid = ast_strdup(p->uniqueid);
if (!ast_strlen_zero(p->mailbox))
strcpy(mwi_sub->mailbox, p->mailbox);
@@ -12586,75 +12583,85 @@
AST_RWLIST_WRLOCK(&mwi_subs);
AST_RWLIST_INSERT_TAIL(&mwi_subs, mwi_sub, entry);
AST_RWLIST_UNLOCK(&mwi_subs);
- ast_free((void *) p->mailbox);
- ast_free((void *) p->context);
- ast_free(p);
+ mwi_sub_task_dtor(p);
poll_subscribed_mailbox(mwi_sub);
return 0;
}
-static void mwi_unsub_event_cb(const struct ast_event *event, void *userdata)
-{
- uint32_t u, *uniqueid = ast_calloc(1, sizeof(*uniqueid));
+static void mwi_unsub_event_cb(struct stasis_subscription_change *change)
+{
+ char *uniqueid = ast_strdup(change->uniqueid);
if (!uniqueid) {
ast_log(LOG_ERROR, "Unable to allocate memory for uniqueid\n");
return;
}
- if (ast_event_get_type(event) != AST_EVENT_UNSUB) {
- ast_free(uniqueid);
- return;
- }
-
- if (ast_event_get_ie_uint(event, AST_EVENT_IE_EVENTTYPE) != AST_EVENT_MWI) {
- ast_free(uniqueid);
- return;
- }
-
- u = ast_event_get_ie_uint(event, AST_EVENT_IE_UNIQUEID);
- *uniqueid = u;
if (ast_taskprocessor_push(mwi_subscription_tps, handle_unsubscribe, uniqueid) < 0) {
ast_free(uniqueid);
}
}
-static void mwi_sub_event_cb(const struct ast_event *event, void *userdata)
+static void mwi_sub_event_cb(struct stasis_subscription_change *change)
{
struct mwi_sub_task *mwist;
-
- if (ast_event_get_type(event) != AST_EVENT_SUB)
+ char *context = ast_strdupa(stasis_topic_name(change->topic));
+ char *mailbox;
+
+ if ((mwist = ast_calloc(1, (sizeof(*mwist)))) == NULL) {
return;
-
- if (ast_event_get_ie_uint(event, AST_EVENT_IE_EVENTTYPE) != AST_EVENT_MWI)
+ }
+
+ mailbox = strsep(&context, "@");
+
+ mwist->mailbox = ast_strdup(mailbox);
+ mwist->context = ast_strdup(context);
+ mwist->uniqueid = ast_strdup(change->uniqueid);
+
+ if (ast_taskprocessor_push(mwi_subscription_tps, handle_subscribe, mwist) < 0) {
+ mwi_sub_task_dtor(mwist);
+ }
+}
+
+static void mwi_event_cb(void *userdata, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
+{
+ struct stasis_subscription_change *change;
+ /* Only looking for subscription change notices here */
+ if (stasis_message_type(msg) != stasis_subscription_change()) {
return;
-
- if ((mwist = ast_calloc(1, (sizeof(*mwist)))) == NULL) {
- ast_log(LOG_ERROR, "could not allocate a mwi_sub_task\n");
+ }
+
+ change = stasis_message_data(msg);
+ if (change->topic == stasis_mwi_topic_all()) {
return;
}
- mwist->mailbox = ast_strdup(ast_event_get_ie_str(event, AST_EVENT_IE_MAILBOX));
- mwist->context = ast_strdup(ast_event_get_ie_str(event, AST_EVENT_IE_CONTEXT));
- mwist->uniqueid = ast_event_get_ie_uint(event, AST_EVENT_IE_UNIQUEID);
-
- if (ast_taskprocessor_push(mwi_subscription_tps, handle_subscribe, mwist) < 0) {
- ast_free(mwist);
- }
+
+ if (!strcmp(change->description, "Subscribe")) {
+ mwi_sub_event_cb(change);
+ } else if (!strcmp(change->description, "Unsubscribe")) {
+ mwi_unsub_event_cb(change);
+ }
+}
+
+static int dump_cache(void *obj, void *arg, int flags)
+{
+ struct stasis_message *msg = obj;
+ mwi_event_cb(NULL, NULL, NULL, msg);
+ return 0;
}
static void start_poll_thread(void)
{
int errcode;
- mwi_sub_sub = ast_event_subscribe(AST_EVENT_SUB, mwi_sub_event_cb, "Voicemail MWI subscription", NULL,
- AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_MWI,
- AST_EVENT_IE_END);
-
- mwi_unsub_sub = ast_event_subscribe(AST_EVENT_UNSUB, mwi_unsub_event_cb, "Voicemail MWI subscription", NULL,
- AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_MWI,
- AST_EVENT_IE_END);
-
- if (mwi_sub_sub)
- ast_event_report_subs(mwi_sub_sub);
+ mwi_sub_sub = stasis_subscribe(stasis_mwi_topic_all(), mwi_event_cb, NULL);
+
+ if (mwi_sub_sub) {
+ struct ao2_container *cached = stasis_cache_dump(stasis_mwi_topic_cached(), stasis_subscription_change());
+ if (cached) {
+ ao2_callback(cached, OBJ_MULTIPLE | OBJ_NODATA, dump_cache, NULL);
+ }
+ ao2_cleanup(cached);
+ }
poll_thread_run = 1;
@@ -12668,13 +12675,7 @@
poll_thread_run = 0;
if (mwi_sub_sub) {
- ast_event_unsubscribe(mwi_sub_sub);
- mwi_sub_sub = NULL;
- }
-
- if (mwi_unsub_sub) {
- ast_event_unsubscribe(mwi_unsub_sub);
- mwi_unsub_sub = NULL;
+ mwi_sub_sub = stasis_unsubscribe(mwi_sub_sub);
}
ast_mutex_lock(&poll_lock);
Modified: team/mmichelson/direct_media/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/direct_media/channels/chan_dahdi.c?view=diff&rev=383613&r1=383612&r2=383613
==============================================================================
--- team/mmichelson/direct_media/channels/chan_dahdi.c (original)
+++ team/mmichelson/direct_media/channels/chan_dahdi.c Fri Mar 22 14:43:18 2013
@@ -502,7 +502,7 @@
static int dahdi_sendtext(struct ast_channel *c, const char *text);
-static void mwi_event_cb(const struct ast_event *event, void *userdata)
+static void mwi_event_cb(void *userdata, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
{
/* This module does not handle MWI in an event-based manner. However, it
* subscribes to MWI for each mailbox that is configured so that the core
@@ -1215,7 +1215,7 @@
*/
char mailbox[AST_MAX_EXTENSION];
/*! \brief Opaque event subscription parameters for message waiting indication support. */
- struct ast_event_sub *mwi_event_sub;
+ struct stasis_subscription *mwi_event_sub;
/*! \brief Delayed dialing for E911. Overlap digits for ISDN. */
char dialdest[256];
#ifdef HAVE_DAHDI_LINEREVERSE_VMWI
@@ -3753,7 +3753,6 @@
static void notify_message(char *mailbox_full, int thereornot)
{
char s[sizeof(mwimonitornotify) + 80];
- struct ast_event *event;
char *mailbox, *context;
/* Strip off @default */
@@ -3762,16 +3761,7 @@
if (ast_strlen_zero(context))
context = "default";
- if (!(event = ast_event_new(AST_EVENT_MWI,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
- AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, thereornot,
- AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, thereornot,
- AST_EVENT_IE_END))) {
- return;
- }
-
- ast_event_queue_and_cache(event);
+ stasis_publish_mwi_state(mailbox, context, thereornot, thereornot);
if (!ast_strlen_zero(mailbox) && !ast_strlen_zero(mwimonitornotify)) {
snprintf(s, sizeof(s), "%s %s %d", mwimonitornotify, mailbox, thereornot);
@@ -5413,24 +5403,25 @@
static int has_voicemail(struct dahdi_pvt *p)
{
int new_msgs;
- struct ast_event *event;
char *mailbox, *context;
+ RAII_VAR(struct stasis_message *, mwi_message, NULL, ao2_cleanup);
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
mailbox = context = ast_strdupa(p->mailbox);
strsep(&context, "@");
- if (ast_strlen_zero(context))
+ if (ast_strlen_zero(context)) {
context = "default";
-
- event = ast_event_get_cached(AST_EVENT_MWI,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
- AST_EVENT_IE_END);
-
- if (event) {
- new_msgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
- ast_event_destroy(event);
- } else
+ }
+
+ ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
+ mwi_message = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_message(), ast_str_buffer(uniqueid));
+
+ if (mwi_message) {
+ struct stasis_mwi_state *mwi_state = stasis_message_data(mwi_message);
+ new_msgs = mwi_state->new_msgs;
+ } else {
new_msgs = ast_app_has_voicemail(p->mailbox, NULL);
+ }
return new_msgs;
}
@@ -5965,10 +5956,12 @@
}
}
ast_free(p->cidspill);
- if (p->use_smdi)
+ if (p->use_smdi) {
ast_smdi_interface_unref(p->smdi_iface);
- if (p->mwi_event_sub)
- ast_event_unsubscribe(p->mwi_event_sub);
+ }
+ if (p->mwi_event_sub) {
+ p->mwi_event_sub = stasis_unsubscribe(p->mwi_event_sub);
+ }
if (p->vars) {
ast_variables_destroy(p->vars);
}
@@ -5981,8 +5974,9 @@
ast_mutex_destroy(&p->lock);
dahdi_close_sub(p, SUB_REAL);
- if (p->owner)
+ if (p->owner) {
ast_channel_tech_pvt_set(p->owner, NULL);
+ }
ast_free(p);
}
@@ -13226,15 +13220,20 @@
ast_copy_string(tmp->mailbox, conf->chan.mailbox, sizeof(tmp->mailbox));
if (channel != CHAN_PSEUDO && !ast_strlen_zero(tmp->mailbox)) {
char *mailbox, *context;
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
+ struct stasis_topic *mailbox_specific_topic;
+
mailbox = context = ast_strdupa(tmp->mailbox);
strsep(&context, "@");
if (ast_strlen_zero(context))
context = "default";
- tmp->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, "Dahdi MWI subscription", NULL,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
- AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
- AST_EVENT_IE_END);
+
+ ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
+
+ mailbox_specific_topic = stasis_mwi_topic(ast_str_buffer(uniqueid));
+ if (mailbox_specific_topic) {
+ tmp->mwi_event_sub = stasis_subscribe(mailbox_specific_topic, mwi_event_cb, NULL);
+ }
}
#ifdef HAVE_DAHDI_LINEREVERSE_VMWI
tmp->mwisend_setting = conf->chan.mwisend_setting;
Modified: team/mmichelson/direct_media/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/direct_media/channels/chan_gulp.c?view=diff&rev=383613&r1=383612&r2=383613
==============================================================================
--- team/mmichelson/direct_media/channels/chan_gulp.c (original)
+++ team/mmichelson/direct_media/channels/chan_gulp.c Fri Mar 22 14:43:18 2013
@@ -57,8 +57,59 @@
#include "asterisk/res_sip.h"
#include "asterisk/res_sip_session.h"
+/*** DOCUMENTATION
+ <function name="GULP_DIAL_CONTACTS" language="en_US">
+ <synopsis>
+ Return a dial string for dialing all contacts on an AOR.
+ </synopsis>
+ <syntax>
+ <parameter name="endpoint" required="true">
+ <para>Name of the endpoint</para>
+ </parameter>
+ <parameter name="aor" required="false">
+ <para>Name of an AOR to use, if not specified the configured AORs on the endpoint are used</para>
+ </parameter>
+ <parameter name="request_user" required="false">
+ <para>Optional request user to use in the request URI</para>
+ </parameter>
+ </syntax>
+ <description>
+ <para>Returns a properly formatted dial string for dialing all contacts on an AOR.</para>
+ </description>
+ </function>
+ ***/
+
static const char desc[] = "Gulp SIP Channel";
static const char channel_type[] = "Gulp";
+
+/*!
+ * \brief Positions of various media
+ */
+enum sip_session_media_position {
+ /*! \brief First is audio */
+ SIP_MEDIA_AUDIO = 0,
+ /*! \brief Second is video */
+ SIP_MEDIA_VIDEO,
+ /*! \brief Last is the size for media details */
+ SIP_MEDIA_SIZE,
+};
+
+struct gulp_pvt {
+ struct ast_sip_session *session;
+ struct ast_sip_session_media *media[SIP_MEDIA_SIZE];
+};
+
+static void gulp_pvt_dtor(void *obj)
+{
+ struct gulp_pvt *pvt = obj;
+ int i;
+ ao2_cleanup(pvt->session);
+ pvt->session = NULL;
+ for (i = 0; i < SIP_MEDIA_SIZE; ++i) {
+ ao2_cleanup(pvt->media[i]);
+ pvt->media[i] = NULL;
+ }
+}
/* \brief Asterisk core interaction functions */
static struct ast_channel *gulp_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *data, int *cause);
@@ -116,18 +167,98 @@
.incoming_request = gulp_incoming_ack,
};
+/*! \brief Dialplan function for constructing a dial string for calling all contacts */
+static int gulp_dial_contacts(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
+{
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(endpoint_name);
+ AST_APP_ARG(aor_name);
+ AST_APP_ARG(request_user);
+ );
+ RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
+ const char *aor_name;
+ char *rest;
+ RAII_VAR(struct ast_str *, dial, NULL, ast_free_ptr);
+
+ AST_STANDARD_APP_ARGS(args, data);
+
+ if (ast_strlen_zero(args.endpoint_name)) {
+ ast_log(LOG_WARNING, "An endpoint name must be specified when using the '%s' dialplan function\n", cmd);
+ return -1;
+ } else if (!(endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", args.endpoint_name))) {
+ ast_log(LOG_WARNING, "Specified endpoint '%s' was not found\n", args.endpoint_name);
+ return -1;
+ }
+
+ aor_name = S_OR(args.aor_name, endpoint->aors);
+
+ if (ast_strlen_zero(aor_name)) {
+ ast_log(LOG_WARNING, "No AOR has been provided and no AORs are configured on endpoint '%s'\n", args.endpoint_name);
+ return -1;
+ } else if (!(dial = ast_str_create(len))) {
+ ast_log(LOG_WARNING, "Could not get enough buffer space for dialing contacts\n");
+ return -1;
+ } else if (!(rest = ast_strdupa(aor_name))) {
+ ast_log(LOG_WARNING, "Could not duplicate provided AORs\n");
+ return -1;
+ }
+
+ while ((aor_name = strsep(&rest, ","))) {
+ RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
+ RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
+ struct ao2_iterator it_contacts;
+ struct ast_sip_contact *contact;
+
+ if (!aor) {
+ /* If the AOR provided is not found skip it, there may be more */
+ continue;
+ } else if (!(contacts = ast_sip_location_retrieve_aor_contacts(aor))) {
+ /* No contacts are available, skip it as well */
+ continue;
+ } else if (!ao2_container_count(contacts)) {
+ /* We were given a container but no contacts are in it... */
+ continue;
+ }
+
+ it_contacts = ao2_iterator_init(contacts, 0);
+ for (; (contact = ao2_iterator_next(&it_contacts)); ao2_ref(contact, -1)) {
+ ast_str_append(&dial, -1, "Gulp/");
+
+ if (!ast_strlen_zero(args.request_user)) {
+ ast_str_append(&dial, -1, "%s@", args.request_user);
+ }
+ ast_str_append(&dial, -1, "%s/%s&", args.endpoint_name, contact->uri);
+ }
+ ao2_iterator_destroy(&it_contacts);
+ }
+
+ /* Trim the '&' at the end off */
+ ast_str_truncate(dial, ast_str_strlen(dial) - 1);
+
+ ast_copy_string(buf, ast_str_buffer(dial), len);
+
+ return 0;
+}
+
+static struct ast_custom_function gulp_dial_contacts_function = {
+ .name = "GULP_DIAL_CONTACTS",
+ .read = gulp_dial_contacts,
+};
+
/*! \brief Function called by RTP engine to get local audio RTP peer */
static enum ast_rtp_glue_result gulp_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
{
- struct ast_sip_session *session = ast_channel_tech_pvt(chan);
- struct ast_sip_endpoint *endpoint = session->endpoint;
-
- if (!session || !session->media[AST_SIP_MEDIA_AUDIO].rtp) {
+ struct gulp_pvt *pvt = ast_channel_tech_pvt(chan);
+ struct ast_sip_endpoint *endpoint;
+
+ if (!pvt || !pvt->session || !pvt->media[SIP_MEDIA_AUDIO]->rtp) {
return AST_RTP_GLUE_RESULT_FORBID;
}
- ao2_ref(session->media[AST_SIP_MEDIA_AUDIO].rtp, +1);
- *instance = session->media[AST_SIP_MEDIA_AUDIO].rtp;
+ endpoint = pvt->session->endpoint;
+
+ *instance = pvt->media[SIP_MEDIA_AUDIO]->rtp;
+ ao2_ref(*instance, +1);
ast_assert(endpoint != NULL);
if (endpoint->direct_media) {
@@ -140,6 +271,8 @@
/*! \brief Function called by RTP engine to get peer capabilities */
static void gulp_get_codec(struct ast_channel *chan, struct ast_format_cap *result)
{
+ struct gulp_pvt *pvt = ast_channel_tech_pvt(chan);
+ ast_format_cap_copy(result, pvt->session->endpoint->codecs);
}
static int send_direct_media_request(void *data)
@@ -210,18 +343,33 @@
const struct ast_format_cap *cap,
int nat_active)
{
- struct ast_sip_session *session = ast_channel_tech_pvt(chan);
+ struct gulp_pvt *pvt = ast_channel_tech_pvt(chan);
+ struct ast_sip_session *session = pvt->session;
int changed = 0;
+
+ /* Don't try to do any direct media shenanigans on early bridges */
+ if ((rtp || vrtp || tpeer) && !ast_bridged_channel(chan)) {
+ return 0;
+ }
if (nat_active && session->endpoint->disable_direct_media_on_nat) {
return 0;
}
- changed |= check_for_rtp_changes(chan, rtp, &session->media[AST_SIP_MEDIA_AUDIO], 1);
- changed |= check_for_rtp_changes(chan, vrtp, &session->media[AST_SIP_MEDIA_VIDEO], 3);
+ if (pvt->media[SIP_MEDIA_AUDIO]) {
+ changed |= check_for_rtp_changes(chan, rtp, pvt->media[SIP_MEDIA_AUDIO], 1);
+ }
+ if (pvt->media[SIP_MEDIA_VIDEO]) {
+ changed |= check_for_rtp_changes(chan, vrtp, pvt->media[SIP_MEDIA_VIDEO], 3);
+ }
if (direct_media_mitigate_glare(session)) {
return 0;
+ }
+
+ if (cap && !ast_format_cap_is_empty(cap) && !ast_format_cap_identical(session->direct_media_cap, cap)) {
+ ast_format_cap_copy(session->direct_media_cap, cap);
+ changed = 1;
}
if (changed) {
@@ -245,16 +393,28 @@
{
struct ast_channel *chan;
struct ast_format fmt;
+ struct gulp_pvt *pvt;
+
+ if (!(pvt = ao2_alloc(sizeof(*pvt), gulp_pvt_dtor))) {
+ return NULL;
+ }
if (!(chan = ast_channel_alloc(1, state, "", S_OR(cid_name, ""), "", "", "", linkedid, 0, "Gulp/%s-%.*s", ast_sorcery_object_get_id(session->endpoint),
(int)session->inv_session->dlg->call_id->id.slen, session->inv_session->dlg->call_id->id.ptr))) {
+ ao2_cleanup(pvt);
return NULL;
}
ast_channel_tech_set(chan, &gulp_tech);
ao2_ref(session, +1);
- ast_channel_tech_pvt_set(chan, session);
+ pvt->session = session;
+ /* If res_sip_session is ever updated to create/destroy ast_sip_session_media
+ * during a call such as if multiple same-type stream support is introduced,
+ * these will need to be recaptured as well */
+ pvt->media[SIP_MEDIA_AUDIO] = ao2_find(session->media, "audio", OBJ_KEY);
+ pvt->media[SIP_MEDIA_VIDEO] = ao2_find(session->media, "video", OBJ_KEY);
+ ast_channel_tech_pvt_set(chan, pvt);
ast_format_cap_copy(ast_channel_nativeformats(chan), session->endpoint->codecs);
ast_codec_choose(&session->endpoint->prefs, session->endpoint->codecs, 1, &fmt);
@@ -294,7 +454,8 @@
/*! \brief Function called by core when we should answer a Gulp session */
static int gulp_answer(struct ast_channel *ast)
{
- struct ast_sip_session *session = ast_channel_tech_pvt(ast);
+ struct gulp_pvt *pvt = ast_channel_tech_pvt(ast);
+ struct ast_sip_session *session = pvt->session;
if (ast_channel_state(ast) == AST_STATE_UP) {
return 0;
@@ -314,15 +475,20 @@
/*! \brief Function called by core to read any waiting frames */
static struct ast_frame *gulp_read(struct ast_channel *ast)
{
- struct ast_sip_session *session = ast_channel_tech_pvt(ast);
+ struct gulp_pvt *pvt = ast_channel_tech_pvt(ast);
struct ast_frame *f;
+ struct ast_sip_session_media *media = pvt->media[SIP_MEDIA_AUDIO];
+
+ if (!media) {
+ return &ast_null_frame;
+ }
switch (ast_channel_fdno(ast)) {
case 0:
- f = ast_rtp_instance_read(session->media[AST_SIP_MEDIA_AUDIO].rtp, 0);
+ f = ast_rtp_instance_read(media->rtp, 0);
break;
case 1:
- f = ast_rtp_instance_read(session->media[AST_SIP_MEDIA_AUDIO].rtp, 1);
+ f = ast_rtp_instance_read(media->rtp, 1);
break;
default:
f = &ast_null_frame;
@@ -343,11 +509,17 @@
/*! \brief Function called by core to write frames */
static int gulp_write(struct ast_channel *ast, struct ast_frame *frame)
{
- struct ast_sip_session *session = ast_channel_tech_pvt(ast);
+ struct gulp_pvt *pvt = ast_channel_tech_pvt(ast);
int res = 0;
+ struct ast_sip_session_media *media;
switch (frame->frametype) {
case AST_FRAME_VOICE:
+ media = pvt->media[SIP_MEDIA_AUDIO];
+
+ if (!media) {
+ return 0;
+ }
if (!(ast_format_cap_iscompatible(ast_channel_nativeformats(ast), &frame->subclass.format))) {
char buf[256];
@@ -359,8 +531,8 @@
ast_getformatname(ast_channel_writeformat(ast)));
return 0;
}
- if (session->media[AST_SIP_MEDIA_AUDIO].rtp) {
- res = ast_rtp_instance_write(session->media[AST_SIP_MEDIA_AUDIO].rtp, frame);
+ if (media->rtp) {
+ res = ast_rtp_instance_write(media->rtp, frame);
}
break;
default:
@@ -386,7 +558,8 @@
/*! \brief Function called by core to change the underlying owner channel */
static int gulp_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
{
- struct ast_sip_session *session = ast_channel_tech_pvt(newchan);
+ struct gulp_pvt *pvt = ast_channel_tech_pvt(newchan);
+ struct ast_sip_session *session = pvt->session;
struct fixup_data fix_data;
fix_data.session = session;
fix_data.chan = newchan;
@@ -458,7 +631,8 @@
static int gulp_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
{
int res = 0;
- struct ast_sip_session *session = ast_channel_tech_pvt(ast);
+ struct gulp_pvt *pvt = ast_channel_tech_pvt(ast);
+ struct ast_sip_session *session = pvt->session;
int response_code = 0;
switch (condition) {
@@ -547,14 +721,18 @@
/*! \brief Function called by core to start a DTMF digit */
static int gulp_digit_begin(struct ast_channel *chan, char digit)
{
- struct ast_sip_session *session = ast_channel_tech_pvt(chan);
+ struct gulp_pvt *pvt = ast_channel_tech_pvt(chan);
+ struct ast_sip_session *session = pvt->session;
int res = 0;
+ struct ast_sip_session_media *media = pvt->media[SIP_MEDIA_AUDIO];
switch (session->endpoint->dtmf) {
case AST_SIP_DTMF_RFC_4733:
- if (session->media[AST_SIP_MEDIA_AUDIO].rtp) {
- ast_rtp_instance_dtmf_begin(session->media[AST_SIP_MEDIA_AUDIO].rtp, digit);
- }
+ if (!media || !media->rtp) {
+ return -1;
+ }
+
+ ast_rtp_instance_dtmf_begin(media->rtp, digit);
case AST_SIP_DTMF_NONE:
break;
case AST_SIP_DTMF_INBAND:
@@ -570,17 +748,21 @@
/*! \brief Function called by core to stop a DTMF digit */
static int gulp_digit_end(struct ast_channel *ast, char digit, unsigned int duration)
{
- struct ast_sip_session *session = ast_channel_tech_pvt(ast);
+ struct gulp_pvt *pvt = ast_channel_tech_pvt(ast);
+ struct ast_sip_session *session = pvt->session;
int res = 0;
+ struct ast_sip_session_media *media = pvt->media[SIP_MEDIA_AUDIO];
switch (session->endpoint->dtmf) {
case AST_SIP_DTMF_INFO:
/* TODO: Send INFO dtmf here */
break;
case AST_SIP_DTMF_RFC_4733:
- if (session->media[AST_SIP_MEDIA_AUDIO].rtp) {
- ast_rtp_instance_dtmf_end_with_duration(session->media[AST_SIP_MEDIA_AUDIO].rtp, digit, duration);
- }
+ if (!media || !media->rtp) {
+ return -1;
+ }
+
+ ast_rtp_instance_dtmf_end_with_duration(media->rtp, digit, duration);
case AST_SIP_DTMF_NONE:
break;
case AST_SIP_DTMF_INBAND:
@@ -609,7 +791,8 @@
/*! \brief Function called by core to actually start calling a remote party */
static int gulp_call(struct ast_channel *ast, const char *dest, int timeout)
{
- struct ast_sip_session *session = ast_channel_tech_pvt(ast);
+ struct gulp_pvt *pvt = ast_channel_tech_pvt(ast);
+ struct ast_sip_session *session = pvt->session;
ao2_ref(session, +1);
if (ast_sip_push_task_synchronous(session->serializer, call, session)) {
@@ -696,7 +879,8 @@
pjsip_tx_data *packet = NULL;
struct hangup_data *h_data = data;
struct ast_channel *ast = h_data->chan;
- struct ast_sip_session *session = ast_channel_tech_pvt(ast);
+ struct gulp_pvt *pvt = ast_channel_tech_pvt(ast);
+ struct ast_sip_session *session = pvt->session;
int cause = h_data->cause;
if (((status = pjsip_inv_end_session(session->inv_session, cause ? cause : 603, NULL, &packet)) == PJ_SUCCESS) && packet) {
@@ -710,7 +894,7 @@
session->channel = NULL;
ast_channel_tech_pvt_set(ast, NULL);
- ao2_cleanup(session);
+ ao2_cleanup(pvt);
ao2_cleanup(h_data);
return 0;
}
@@ -718,7 +902,8 @@
/*! \brief Function called by core to hang up a Gulp session */
static int gulp_hangup(struct ast_channel *ast)
{
- struct ast_sip_session *session = ast_channel_tech_pvt(ast);
+ struct gulp_pvt *pvt = ast_channel_tech_pvt(ast);
+ struct ast_sip_session *session = pvt->session;
int cause = hangup_cause2sip(ast_channel_hangupcause(session->channel));
struct hangup_data *h_data = hangup_data_alloc(cause, ast);
if (!h_data) {
@@ -739,34 +924,54 @@
session->channel = NULL;
ast_channel_tech_pvt_set(ast, NULL);
- ao2_cleanup(session);
+ ao2_cleanup(pvt);
return -1;
}
struct request_data {
struct ast_sip_session *session;
const char *dest;
+ int cause;
};
static int request(void *obj)
{
struct request_data *req_data = obj;
- RAII_VAR(struct ast_sip_endpoint *, endpoint, ast_sip_endpoint_alloc("constant"), ao2_cleanup);
+ char *tmp = ast_strdupa(req_data->dest), *endpoint_name = NULL, *request_user = NULL;
+ RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
struct ast_sip_session *session = NULL;
-
- if (!endpoint) {
- return -1;
- }
-
- /* TODO: This needs to actually grab a proper endpoint and such */
- ast_string_field_set(endpoint, context, "default");
- ast_parse_allow_disallow(&endpoint->prefs, endpoint->codecs, "ulaw", 1);
- endpoint->min_se = 90;
- endpoint->sess_expires = 1800;
- endpoint->direct_media = 1;
- endpoint->direct_media_method = AST_SIP_SESSION_REFRESH_METHOD_UPDATE;
-
- if (!(session = ast_sip_session_create_outgoing(endpoint, req_data->dest))) {
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(endpoint);
+ AST_APP_ARG(aor);
+ );
+
+ if (ast_strlen_zero(tmp)) {
+ ast_log(LOG_ERROR, "Unable to create Gulp channel with empty destination\n");
+ req_data->cause = AST_CAUSE_CHANNEL_UNACCEPTABLE;
+ return -1;
+ }
+
+ AST_NONSTANDARD_APP_ARGS(args, tmp, '/');
+
+ /* If a request user has been specified extract it from the endpoint name portion */
+ if ((endpoint_name = strchr(args.endpoint, '@'))) {
+ request_user = args.endpoint;
+ *endpoint_name++ = '\0';
+ } else {
+ endpoint_name = args.endpoint;
+ }
+
+ if (ast_strlen_zero(endpoint_name)) {
+ ast_log(LOG_ERROR, "Unable to create Gulp channel with empty endpoint name\n");
+ req_data->cause = AST_CAUSE_CHANNEL_UNACCEPTABLE;
+ } else if (!(endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", endpoint_name))) {
+ ast_log(LOG_ERROR, "Unable to create Gulp channel - endpoint '%s' was not found\n", endpoint_name);
+ req_data->cause = AST_CAUSE_NO_ROUTE_DESTINATION;
+ return -1;
+ }
+
+ if (!(session = ast_sip_session_create_outgoing(endpoint, args.aor, request_user))) {
+ req_data->cause = AST_CAUSE_NO_ROUTE_DESTINATION;
return -1;
}
@@ -783,6 +988,7 @@
req_data.dest = data;
if (ast_sip_push_task_synchronous(NULL, request, &req_data)) {
+ *cause = req_data.cause;
return NULL;
}
@@ -976,6 +1182,10 @@
{
struct pjsip_status_line status = rdata->msg_info.msg->line.status;
+ if (!session->channel) {
+ return;
+ }
+
switch (status.code) {
case 180:
ast_queue_control(session->channel, AST_CONTROL_RINGING);
@@ -1029,6 +1239,11 @@
goto end;
}
+ if (ast_custom_function_register(&gulp_dial_contacts_function)) {
+ ast_log(LOG_ERROR, "Unable to register GULP_DIAL_CONTACTS dialplan function\n");
+ goto end;
+ }
+
if (ast_sip_session_register_supplement(&gulp_supplement)) {
[... 5484 lines stripped ...]
More information about the asterisk-commits
mailing list