[asterisk-commits] kharwell: branch kharwell/pimp_sip_state r387873 - in /team/kharwell/pimp_sip...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue May 7 18:06:47 CDT 2013
Author: kharwell
Date: Tue May 7 18:06:45 2013
New Revision: 387873
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387873
Log:
extension state provider(s) for some pidf types
Added:
team/kharwell/pimp_sip_state/res/res_sip_providers/
team/kharwell/pimp_sip_state/res/res_sip_providers/include/
team/kharwell/pimp_sip_state/res/res_sip_providers/include/res_sip_providers.h (with props)
team/kharwell/pimp_sip_state/res/res_sip_providers/res_sip_pidf.c (with props)
Removed:
team/kharwell/pimp_sip_state/res/res_sip_exten_state.exports.in
Modified:
team/kharwell/pimp_sip_state/include/asterisk/res_sip_exten_state.h
team/kharwell/pimp_sip_state/include/asterisk/res_sip_pubsub.h
team/kharwell/pimp_sip_state/res/Makefile
team/kharwell/pimp_sip_state/res/res_sip_exten_state.c
team/kharwell/pimp_sip_state/res/res_sip_pubsub.c
team/kharwell/pimp_sip_state/res/res_sip_pubsub.exports.in
Modified: team/kharwell/pimp_sip_state/include/asterisk/res_sip_exten_state.h
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_state/include/asterisk/res_sip_exten_state.h?view=diff&rev=387873&r1=387872&r2=387873
==============================================================================
--- team/kharwell/pimp_sip_state/include/asterisk/res_sip_exten_state.h (original)
+++ team/kharwell/pimp_sip_state/include/asterisk/res_sip_exten_state.h Tue May 7 18:06:45 2013
@@ -19,6 +19,8 @@
#ifndef _RES_SIP_EXTEN_STATE_H
#define _RES_SIP_EXTEN_STATE_H
+#include "asterisk/stringfields.h"
+#include "asterisk/linkedlists.h"
#include "asterisk/presencestate.h"
struct ast_exten_state {
@@ -33,12 +35,12 @@
};
/*!
- * \brief Extension state notifier.
+ * \brief Extension state provider.
*/
-struct ast_exten_state_notifier {
- /*! The name of the event this notifier registers for */
+struct ast_exten_state_provider {
+ /*! The name of the event this provider registers for */
const char *event_name;
- /*! The type of body this notifier accepts */
+ /*! The type of body this provider accepts */
const char *accept;
/*!
@@ -47,20 +49,11 @@
* Implementors use this to create body information within the given
* ast_str. That information is then added to the NOTIFY request.
*/
- void (*create_body)(struct ast_exten_state *data, struct ast_str **body_text);
+ void (*create_body)(struct ast_exten_state *data, const char *local,
+ const char *remote,struct ast_str **body_text);
/*! Next item in the list */
- AST_LIST_ENTRY(ast_exten_state_notifier) next;
+ AST_LIST_ENTRY(ast_exten_state_provider) next;
};
-/*!
- * \brief Register an extension state notifier.
- */
-int ast_register_exten_state_notifier(struct ast_exten_state_notifier *obj);
-
-/*!
- * \brief Unregister an extension state notifier.
- */
-void ast_unregister_exten_state_notifier(struct ast_exten_state_notifier *obj);
-
#endif
Modified: team/kharwell/pimp_sip_state/include/asterisk/res_sip_pubsub.h
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_state/include/asterisk/res_sip_pubsub.h?view=diff&rev=387873&r1=387872&r2=387873
==============================================================================
--- team/kharwell/pimp_sip_state/include/asterisk/res_sip_pubsub.h (original)
+++ team/kharwell/pimp_sip_state/include/asterisk/res_sip_pubsub.h Tue May 7 18:06:45 2013
@@ -261,6 +261,21 @@
* \retval non-NULL The underlying pjsip_evsub
*/
pjsip_evsub *ast_sip_subscription_get_evsub(struct ast_sip_subscription *sub);
+
+/*!
+ * \brief Get the underlying PJSIP dialog structure
+ *
+ * Call this function when information needs to be retrieved from the
+ * underlying pjsip dialog.
+ *
+ * This function, as well as all methods called on the pjsip_evsub should
+ * be done in a SIP servant thread.
+ *
+ * \param sub The subscription
+ * \retval NULL Failure
+ * \retval non-NULL The underlying pjsip_dialog
+ */
+pjsip_dialog *ast_sip_subscription_get_dlg(struct ast_sip_subscription *sub);
/*!
* \brief Send a request created via a PJSIP evsub method
Modified: team/kharwell/pimp_sip_state/res/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_state/res/Makefile?view=diff&rev=387873&r1=387872&r2=387873
==============================================================================
--- team/kharwell/pimp_sip_state/res/Makefile (original)
+++ team/kharwell/pimp_sip_state/res/Makefile Tue May 7 18:06:45 2013
@@ -46,6 +46,9 @@
$(if $(filter res_sip,$(EMBEDDED_MODS)),modules.link,res_sip.so): $(subst .c,.o,$(wildcard res_sip/*.c))
$(subst .c,.o,$(wildcard res_sip/*.c)): _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_sip)
+$(if $(filter res_sip_providers,$(EMBEDDED_MODS)),modules.link,res_sip_exten_state.so): $(subst .c,.o,$(wildcard res_sip_providers/*.c))
+$(subst .c,.o,$(wildcard res_sip_providers/*.c)): _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_sip_providers)
+
ifneq ($(findstring REBUILD_PARSERS,$(MENUSELECT_CFLAGS)),)
ael/ael_lex.c: ael/ael.flex
else
@@ -70,7 +73,7 @@
ael/pval.o: ael/pval.c
clean::
- rm -f snmp/*.[oi] ael/*.[oi] ais/*.[oi] stasis_http/*.[oi] res_sip/*.[oi]
+ rm -f snmp/*.[oi] ael/*.[oi] ais/*.[oi] stasis_http/*.[oi] res_sip/*.[oi] res_sip_providers/*.[oi]
# Dependencies for res_stasis_http_*.so are generated, so they're in this file
include stasis_http.make
Modified: team/kharwell/pimp_sip_state/res/res_sip_exten_state.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_state/res/res_sip_exten_state.c?view=diff&rev=387873&r1=387872&r2=387873
==============================================================================
--- team/kharwell/pimp_sip_state/res/res_sip_exten_state.c (original)
+++ team/kharwell/pimp_sip_state/res/res_sip_exten_state.c Tue May 7 18:06:45 2013
@@ -38,22 +38,23 @@
#include "asterisk/sorcery.h"
#include "asterisk/app.h"
#include "asterisk/pbx.h"
-
-AST_RWLIST_HEAD_STATIC(notifiers, ast_exten_state_notifier);
-
-int ast_register_exten_state_notifier(struct ast_exten_state_notifier *obj)
-{
- SCOPED_LOCK(lock, ¬ifiers, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
- AST_LIST_INSERT_TAIL(¬ifiers, obj, next);
+#include "res_sip_providers/include/res_sip_providers.h"
+
+AST_RWLIST_HEAD_STATIC(providers, ast_exten_state_provider);
+
+static int register_exten_state_provider(struct ast_exten_state_provider *obj)
+{
+ SCOPED_LOCK(lock, &providers, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
+ AST_RWLIST_INSERT_TAIL(&providers, obj, next);
ast_module_ref(ast_module_info->self);
return 0;
}
-void ast_unregister_exten_state_notifier(struct ast_exten_state_notifier *obj)
-{
- struct ast_exten_state_notifier *i;
- SCOPED_LOCK(lock, ¬ifiers, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
- AST_RWLIST_TRAVERSE_SAFE_BEGIN(¬ifiers, i, next) {
+static void unregister_exten_state_provider(struct ast_exten_state_provider *obj)
+{
+ struct ast_exten_state_provider *i;
+ SCOPED_LOCK(lock, &providers, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
+ AST_RWLIST_TRAVERSE_SAFE_BEGIN(&providers, i, next) {
if (i == obj) {
AST_RWLIST_REMOVE_CURRENT(next);
ast_module_unref(ast_module_info->self);
@@ -65,37 +66,35 @@
/*!
* \internal
- * \brief Find a notifier based on the given accept type.
- */
-static struct ast_exten_state_notifier *notifier_by_accept(const char *accept)
-{
- struct ast_exten_state_notifier *res = NULL;
- struct ast_exten_state_notifier *i;
- SCOPED_LOCK(lock, ¬ifiers, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
- AST_RWLIST_TRAVERSE_SAFE_BEGIN(¬ifiers, i, next) {
+ * \brief Find a provider based on the given accept type.
+ */
+static struct ast_exten_state_provider *provider_by_accept(const char *accept)
+{
+ struct ast_exten_state_provider *i;
+ SCOPED_LOCK(lock, &providers, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
+ AST_RWLIST_TRAVERSE_SAFE_BEGIN(&providers, i, next) {
if (!strcmp(i->accept, accept)) {
- res = i;
- break;
+ return i;
}
}
AST_RWLIST_TRAVERSE_SAFE_END;
- return res;
-}
-
-/*!
- * \internal
- * \brief Find a notifier based on a given message accept type.
+ return NULL;
+}
+
+/*!
+ * \internal
+ * \brief Find a provider based on a given message accept type.
*
* Attempts to locate accept headers in the given request data. If found
- * tries to find a notifier for the accept type.
- */
-static struct ast_exten_state_notifier *notifier_by_req(pjsip_rx_data *rdata)
+ * tries to find a provider for the accept type.
+ */
+static struct ast_exten_state_provider *provider_by_req(pjsip_rx_data *rdata)
{
int i;
char type[50];
pjsip_accept_hdr *hdr = (pjsip_accept_hdr*)
pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_ACCEPT, NULL);
- struct ast_exten_state_notifier *res;
+ struct ast_exten_state_provider *res;
if (!hdr) {
ast_log(LOG_WARNING, "No Accept header found in subscribe\n");
@@ -104,7 +103,7 @@
for (i = 0; i < hdr->count; ++i) {
ast_copy_pj_str(type, &hdr->values[i], sizeof(type));
- if ((res = notifier_by_accept(type))) {
+ if ((res = provider_by_accept(type))) {
return res;
}
}
@@ -114,16 +113,19 @@
static int sub_handler_hash(const void *obj, int flags)
{
const struct ast_sip_subscription_handler *handler = obj;
-
- return ast_str_hash(handler->event_name);
+ const char *event_name = obj;
+
+ return ast_str_hash(flags & OBJ_KEY ? event_name : handler->event_name);
}
static int sub_handler_cmp(void *obj, void *arg, int flags)
{
struct ast_sip_subscription_handler *handler1 = obj;
struct ast_sip_subscription_handler *handler2 = arg;
-
- return !strcmp(handler1->event_name, handler2->event_name);
+ const char *event_name = arg;
+
+ return !strcmp(handler1->event_name, flags & OBJ_KEY ?
+ event_name : handler2->event_name) ? CMP_MATCH | CMP_STOP : 0;
}
#define SUB_HANDLER_BUCKETS 5
@@ -134,14 +136,14 @@
* \brief A subscription for extension state
*
* This structure acts as the owner for the underlying SIP subscription. It
- * also keeps a pointer to an associated "notifier" so when a state changes
+ * also keeps a pointer to an associated "provider" so when a state changes
* a notify data creator is quickly accessible.
*/
struct state_sub {
/*! The SIP subscription */
struct ast_sip_subscription *sip_sub;
/*! The notify data creator */
- struct ast_exten_state_notifier *notifier;
+ struct ast_exten_state_provider *provider;
/*! Context in which subscription looks for updates */
const char *context;
/*! Extension within the context to receive updates from */
@@ -186,7 +188,7 @@
* \brief Allocates an state_sub object.
*
* Creates the underlying SIP subscription for the given request. First makes
- * sure that there are registered handler and notifier objects available.
+ * sure that there are registered handler and provider objects available.
*/
static struct state_sub *state_sub_alloc(struct ast_sip_endpoint *endpoint,
enum ast_sip_subscription_role role, pjsip_rx_data *rdata)
@@ -204,8 +206,8 @@
return NULL;
}
- if (!(sub->notifier = notifier_by_req(rdata))) {
- ast_log(LOG_WARNING, "Unable to locate subscription handler notifier\n");
+ if (!(sub->provider = provider_by_req(rdata))) {
+ ast_log(LOG_WARNING, "Unable to locate subscription handler provider\n");
ao2_cleanup(sub);
return NULL;
}
@@ -231,25 +233,30 @@
pj_str_t reason_str;
const pj_str_t *reason_str_ptr = NULL;
pjsip_tx_data *tdata;
+ pjsip_dialog *dlg;
struct ast_sip_body body;
- char type[50];
-
- if (!(body.subtype = strchr(ssub->notifier->accept, '/'))) {
- ast_log(LOG_WARNING, "Subtype not specified for notifier\n");
- return;
- }
-
- ast_copy_string(type, ssub->notifier->accept,
- body.subtype - ssub->notifier->accept);
+ char type[50], local[256], remote[256];
+
+ if (!(body.subtype = strchr(ssub->provider->accept, '/'))) {
+ ast_log(LOG_WARNING, "Subtype not specified for provider\n");
+ return;
+ }
+
+ ast_copy_string(type, ssub->provider->accept,
+ body.subtype - ssub->provider->accept);
body.type = type;
++body.subtype;
- if (!ssub->notifier->create_body) {
- ast_log(LOG_WARNING, "Body handler not specified for notifier\n");
- return;
- }
-
- ssub->notifier->create_body(data, &body_text);
+ if (!ssub->provider->create_body) {
+ ast_log(LOG_WARNING, "Body handler not specified for provider\n");
+ return;
+ }
+
+ dlg = ast_sip_subscription_get_dlg(ssub->sip_sub);
+ ast_copy_pj_str(local, &dlg->local.info_str, sizeof(local));
+ ast_copy_pj_str(remote, &dlg->remote.info_str, sizeof(remote));
+
+ ssub->provider->create_body(data, local, remote, &body_text);
body.body_text = ast_str_buffer(body_text);
if (reason) {
@@ -347,6 +354,8 @@
== AST_EXTENSION_REMOVED ? "removed" : "deactivated");
}
+ ast_log(LOG_VERBOSE, "state_changed: context=%s, exten=%s\n",context, exten);
+
ast_sip_push_task(ast_sip_subscription_get_serializer(udata->ssub->sip_sub),
serialized_notify, sdata);
return 0;
@@ -404,6 +413,8 @@
pjsip_uri *uri = rdata->msg_info.msg->line.req.uri;
pjsip_sip_uri *sip_uri = pjsip_uri_get_uri(uri);
struct state_sub *ssub;
+
+ ast_log(LOG_VERBOSE, "new_subscribe:\n");
if (!PJSIP_URI_SCHEME_IS_SIP(uri) && !PJSIP_URI_SCHEME_IS_SIPS(uri)) {
ast_log(LOG_WARNING, "Attempt to SUBSCRIBE to a non-SIP URI\n");
@@ -501,14 +512,14 @@
{
int i;
/* search all items or until we find a null/empty element */
- for (i = 0; i < sizeof(accept) ||
+ for (i = 0; i < sizeof(accept) &&
!ast_strlen_zero(accept[i]); ++i) {
-
if (!strcmp(accept[i], value)) {
- return 1;
+ return -1;
}
}
- return 0;
+ /* return the first empty element in the array */
+ return i;
}
/*!
@@ -518,14 +529,12 @@
*/
static void add_accept(const char* dest[], const char* accept)
{
- int i = 0;
-
- if (has_accept(dest, accept)) {
- return;
- }
-
- /* find the first empty element in the array */
- while (dest[i]) ++i;
+ int i = has_accept(dest, accept);
+
+ if (i < 0) {
+ /* already in list */
+ return;
+ }
if (i == sizeof(dest)) {
ast_log(LOG_WARNING, "Subcription handler's accept values full\n");
@@ -577,23 +586,24 @@
* This means all accept values must be specified before registering a
* subcription handler for an event_name with the pub/sub framework.
*
- * For every registered notifier create, or re-use, a subscription handler
+ * For every registered provider create, or re-use, a subscription handler
* based upon the event_name. If a handler does not exist for a particular
- * event_name one will be created adding the accept value from a notifier.
+ * event_name one will be created adding the accept value from a provider.
* If a handler already exists for an event_name then if the accept value
* has not been added to that handler it will be.
*/
static void create_sub_handlers(void)
{
- struct ast_exten_state_notifier *i;
- SCOPED_LOCK(lock, ¬ifiers, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
- AST_RWLIST_TRAVERSE_SAFE_BEGIN(¬ifiers, i, next) {
+ struct ast_exten_state_provider *i;
+ SCOPED_LOCK(lock, &providers, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
+
+ AST_RWLIST_TRAVERSE_SAFE_BEGIN(&providers, i, next) {
struct ast_sip_subscription_handler *handler =
ao2_find(sub_handlers, i->event_name, OBJ_NOLOCK | OBJ_KEY);
if (handler) {
/* if handler exists just assign those accept values to
- it from the notifier that have not already been set */
+ it from the provider that have not already been set */
add_accept(handler->accept, i->accept);
continue;
}
@@ -646,12 +656,14 @@
return AST_MODULE_LOAD_FAILURE;
}
- /* register notifiers - for now they have to be specifically added here
+ /* register providers - for now they have to be specifically added here
because of a limitation in pjsip. if pjsip ever gets modified these
can be moved to their respective module files */
- ast_register_exten_state_notifier(NULL);
-
- /* create the subscription handlers based upon the notifiers */
+ register_exten_state_provider(ast_sip_pidf_xml_provider());
+ register_exten_state_provider(ast_sip_xml_pidf_provider());
+ register_exten_state_provider(ast_sip_cpim_pidf_xml_provider());
+
+ /* create the subscription handlers based upon the providers */
create_sub_handlers();
/* register each subscription handler declaring success if
@@ -667,8 +679,10 @@
ao2_callback(sub_handlers, OBJ_NODATA | OBJ_NOLOCK,
unregister_sub_handlers, NULL);
- /* unregister notifiers here, again due to pjsip limitation */
- ast_unregister_exten_state_notifier(NULL);
+ /* unregister providers here, again due to pjsip limitation */
+ unregister_exten_state_provider(ast_sip_cpim_pidf_xml_provider());
+ unregister_exten_state_provider(ast_sip_xml_pidf_provider());
+ unregister_exten_state_provider(ast_sip_pidf_xml_provider());
ao2_cleanup(sub_handlers);
Added: team/kharwell/pimp_sip_state/res/res_sip_providers/include/res_sip_providers.h
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_state/res/res_sip_providers/include/res_sip_providers.h?view=auto&rev=387873
==============================================================================
--- team/kharwell/pimp_sip_state/res/res_sip_providers/include/res_sip_providers.h (added)
+++ team/kharwell/pimp_sip_state/res/res_sip_providers/include/res_sip_providers.h Tue May 7 18:06:45 2013
@@ -1,0 +1,42 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Kevin Harwell <kharwell at 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.
+ */
+
+#ifndef _RES_SIP_EXTEN_PROVIDERS_H
+#define _RES_SIP_EXTEN_PROVIDERS_H
+
+#include "asterisk/res_sip_exten_state.h"
+
+/* Currently pjsip only allows an event name and all supporting body type tuples
+ to be registered once. Meaning once an event name is registered no other
+ body types can be added to the list of body types currently associated for
+ the given event name.
+
+ So that means we can't do the normal "register function" within a provider's
+ module load since providers are not in themselves actual modules. However, in
+ the spirit of modularity, and in the hopes that one day pjsip will remove the
+ above mentioned limitation, providers are broken out into separate files.
+
+ Below are forward declarations of those providers. New providers need to be
+ added here in order to be accessible by res_sip_extern_state.
+*/
+
+struct ast_exten_state_provider *ast_sip_pidf_xml_provider(void);
+struct ast_exten_state_provider *ast_sip_xml_pidf_provider(void);
+struct ast_exten_state_provider *ast_sip_cpim_pidf_xml_provider(void);
+
+#endif
Propchange: team/kharwell/pimp_sip_state/res/res_sip_providers/include/res_sip_providers.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/kharwell/pimp_sip_state/res/res_sip_providers/include/res_sip_providers.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Rev URL
Propchange: team/kharwell/pimp_sip_state/res/res_sip_providers/include/res_sip_providers.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: team/kharwell/pimp_sip_state/res/res_sip_providers/res_sip_pidf.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_state/res/res_sip_providers/res_sip_pidf.c?view=auto&rev=387873
==============================================================================
--- team/kharwell/pimp_sip_state/res/res_sip_providers/res_sip_pidf.c (added)
+++ team/kharwell/pimp_sip_state/res/res_sip_providers/res_sip_pidf.c Tue May 7 18:06:45 2013
@@ -1,0 +1,190 @@
+/*
+ * asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Kevin Harwell <kharwell at 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.
+ */
+
+/*** MODULEINFO
+ <depend>pjproject</depend>
+ <depend>res_sip</depend>
+ <depend>res_sip_pubsub</depend>
+ <depend>res_sip_exten_state</depend>
+ <support_level>core</support_level>
+ ***/
+#include "asterisk.h"
+#include "asterisk/pbx.h"
+#include "asterisk/res_sip_exten_state.h"
+#include "include/res_sip_providers.h"
+
+enum state {
+ NOTIFY_OPEN,
+ NOTIFY_INUSE,
+ NOTIFY_CLOSED
+};
+
+static void exten_state_to_str(int state, char **statestring, char **pidfstate,
+ char **pidfnote, int *local_state)
+{
+ switch (state) {
+ /* case (AST_EXTENSION_RINGING | AST_EXTENSION_INUSE): */
+ /* statestring = (sip_cfg.notifyringing) ? "early" : "confirmed"; */
+ /* local_state = NOTIFY_INUSE; */
+ /* pidfstate = "busy"; */
+ /* pidfnote = "Ringing"; */
+ /* break; */
+ case AST_EXTENSION_RINGING:
+ *statestring = "early";
+ *local_state = NOTIFY_INUSE;
+ *pidfstate = "busy";
+ *pidfnote = "Ringing";
+ break;
+ case AST_EXTENSION_INUSE:
+ *statestring = "confirmed";
+ *local_state = NOTIFY_INUSE;
+ *pidfstate = "busy";
+ *pidfnote = "On the phone";
+ break;
+ case AST_EXTENSION_BUSY:
+ *statestring = "confirmed";
+ *local_state = NOTIFY_CLOSED;
+ *pidfstate = "busy";
+ *pidfnote = "On the phone";
+ break;
+ case AST_EXTENSION_UNAVAILABLE:
+ *statestring = "terminated";
+ *local_state = NOTIFY_CLOSED;
+ *pidfstate = "away";
+ *pidfnote = "Unavailable";
+ break;
+ case AST_EXTENSION_ONHOLD:
+ *statestring = "confirmed";
+ *local_state = NOTIFY_CLOSED;
+ *pidfstate = "busy";
+ *pidfnote = "On hold";
+ break;
+ case AST_EXTENSION_NOT_INUSE:
+ default:
+ /* Default setting */
+ *local_state = NOTIFY_OPEN;
+ break;
+ }
+}
+
+static void pidf_xml_create_body(struct ast_exten_state *data, const char *local,
+ const char *remote, struct ast_str **body_text)
+{
+ char *statestring = NULL, *pidfstate = NULL, *pidfnote = NULL;
+ int local_state;
+
+ exten_state_to_str(data->exten_state, &statestring, &pidfstate,
+ &pidfnote, &local_state);
+
+ ast_str_append(body_text, 0,
+ "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
+ "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\n"
+ "xmlns:pp=\"urn:ietf:params:xml:ns:pidf:person\"\n"
+ "xmlns:es=\"urn:ietf:params:xml:ns:pidf:rpid:status:rpid-status\"\n"
+ "xmlns:ep=\"urn:ietf:params:xml:ns:pidf:rpid:rpid-person\"\n"
+ "entity=\"%s\">\n", local);
+
+ ast_str_append(body_text, 0, "<pp:person><status>\n");
+ if (pidfstate[0] != '-') {
+ ast_str_append(body_text, 0, "<ep:activities><ep:%s/></ep:activities>\n", pidfstate);
+ }
+ ast_str_append(body_text, 0, "</status></pp:person>\n");
+ ast_str_append(body_text, 0, "<note>%s</note>\n", pidfnote);
+ ast_str_append(body_text, 0, "<tuple id=\"%s\">\n", data->exten); /* Tuple start */
+ ast_str_append(body_text, 0, "<contact priority=\"1\">%s</contact>\n", remote);
+ if (pidfstate[0] == 'b') /* Busy? Still open ... */
+ ast_str_append(body_text, 0, "<status><basic>open</basic></status>\n");
+ else
+ ast_str_append(body_text, 0, "<status><basic>%s</basic></status>\n", (local_state != NOTIFY_CLOSED) ? "open" : "closed");
+
+ /* if (allow_notify_user_presence(p) && (data->presence_state != AST_PRESENCE_INVALID) */
+ /* && (data->presence_state != AST_PRESENCE_NOT_SET)) { */
+ /* ast_str_append(body_text, 0, "</tuple>\n"); */
+ /* ast_str_append(body_text, 0, "<tuple id=\"digium-presence\">\n"); */
+ /* ast_str_append(body_text, 0, "<status>\n"); */
+ /* ast_str_append(body_text, 0, "<digium_presence type=\"%s\" subtype=\"%s\">%s</digium_presence>\n", */
+ /* ast_presence_state2str(data->presence_state), */
+ /* S_OR(data->presence_subtype, ""), */
+ /* S_OR(data->presence_message, "")); */
+ /* ast_str_append(body_text, 0, "</status>\n"); */
+ /* ast_test_suite_event_notify("DIGIUM_PRESENCE_SENT", */
+ /* "PresenceState: %s\r\n" */
+ /* "Subtype: %s\r\n" */
+ /* "Message: %s", */
+ /* ast_presence_state2str(data->presence_state), */
+ /* S_OR(data->presence_subtype, ""), */
+ /* S_OR(data->presence_message, "")); */
+ /* } */
+ ast_str_append(body_text, 0, "</tuple>\n</presence>\n");
+}
+
+static struct ast_exten_state_provider _pidf_xml_provider = {
+ .event_name = "presence",
+ .accept = "pidf+xml",
+ .create_body = pidf_xml_create_body
+};
+
+struct ast_exten_state_provider *ast_sip_pidf_xml_provider(void)
+{
+ return &_pidf_xml_provider;
+}
+
+static void xml_pidf_create_body(struct ast_exten_state *data, const char *local,
+ const char *remote, struct ast_str **body_text)
+{
+ char *statestring = NULL, *pidfstate = NULL, *pidfnote = NULL;
+ int local_state;
+
+ exten_state_to_str(data->exten_state, &statestring, &pidfstate,
+ &pidfnote, &local_state);
+
+ ast_str_append(body_text, 0,
+ "<?xml version=\"1.0\"?>\n"
+ "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
+ "<presence>\n");
+ ast_str_append(body_text, 0, "<presentity uri=\"%s;method=SUBSCRIBE\" />\n", local);
+ ast_str_append(body_text, 0, "<atom id=\"%s\">\n", data->exten);
+ ast_str_append(body_text, 0, "<address uri=\"%s;user=ip\" priority=\"0.800000\">\n", remote);
+ ast_str_append(body_text, 0, "<status status=\"%s\" />\n",
+ (local_state == NOTIFY_OPEN) ? "open" :
+ (local_state == NOTIFY_INUSE) ? "inuse" : "closed");
+ ast_str_append(body_text, 0, "<msnsubstatus substatus=\"%s\" />\n",
+ (local_state == NOTIFY_OPEN) ? "online" :
+ (local_state == NOTIFY_INUSE) ? "onthephone" : "offline");
+ ast_str_append(body_text, 0, "</address>\n</atom>\n</presence>\n");
+}
+
+static struct ast_exten_state_provider _xml_pidf_provider = {
+ .event_name = "presence",
+ .accept = "xml+pidf",
+ .create_body = xml_pidf_create_body
+};
+
+struct ast_exten_state_provider *ast_sip_xml_pidf_provider(void) {
+ return &_xml_pidf_provider;
+}
+
+static struct ast_exten_state_provider _cpim_pidf_xml_provider = {
+ .event_name = "presence",
+ .accept = "cpim+pidf+xml",
+ .create_body = xml_pidf_create_body
+};
+
+struct ast_exten_state_provider *ast_sip_cpim_pidf_xml_provider(void) {
+ return &_cpim_pidf_xml_provider;
+}
Propchange: team/kharwell/pimp_sip_state/res/res_sip_providers/res_sip_pidf.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/kharwell/pimp_sip_state/res/res_sip_providers/res_sip_pidf.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Rev URL
Propchange: team/kharwell/pimp_sip_state/res/res_sip_providers/res_sip_pidf.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: team/kharwell/pimp_sip_state/res/res_sip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_state/res/res_sip_pubsub.c?view=diff&rev=387873&r1=387872&r2=387873
==============================================================================
--- team/kharwell/pimp_sip_state/res/res_sip_pubsub.c (original)
+++ team/kharwell/pimp_sip_state/res/res_sip_pubsub.c Tue May 7 18:06:45 2013
@@ -239,6 +239,11 @@
return sub->evsub;
}
+pjsip_dialog *ast_sip_subscription_get_dlg(struct ast_sip_subscription *sub)
+{
+ return sub->dlg;
+}
+
int ast_sip_subscription_send_request(struct ast_sip_subscription *sub, pjsip_tx_data *tdata)
{
return pjsip_evsub_send_request(ast_sip_subscription_get_evsub(sub),
Modified: team/kharwell/pimp_sip_state/res/res_sip_pubsub.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_state/res/res_sip_pubsub.exports.in?view=diff&rev=387873&r1=387872&r2=387873
==============================================================================
--- team/kharwell/pimp_sip_state/res/res_sip_pubsub.exports.in (original)
+++ team/kharwell/pimp_sip_state/res/res_sip_pubsub.exports.in Tue May 7 18:06:45 2013
@@ -4,6 +4,7 @@
LINKER_SYMBOL_PREFIXast_sip_subsription_get_endpoint;
LINKER_SYMBOL_PREFIXast_sip_subscription_get_serializer;
LINKER_SYMBOL_PREFIXast_sip_subscription_get_evsub;
+ LINKER_SYMBOL_PREFIXast_sip_subscription_get_dlg;
LINKER_SYMBOL_PREFIXast_sip_subscription_send_request;
LINKER_SYMBOL_PREFIXast_sip_subscription_alloc_datastore;
LINKER_SYMBOL_PREFIXast_sip_subscription_add_datastore;
More information about the asterisk-commits
mailing list