[asterisk-commits] mmichelson: branch mmichelson/pubsub_bodies r405986 - in /team/mmichelson/pub...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jan 20 17:30:36 CST 2014
Author: mmichelson
Date: Mon Jan 20 17:30:34 2014
New Revision: 405986
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=405986
Log:
Separate body generators into their own files.
At this point, what needs to be done is to clean things
up, audit for usability, and ^*_TEST_*^
Added:
team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_body_generator_types.h (with props)
team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_xml.h (with props)
team/mmichelson/pubsub_bodies/res/res_pjsip_mwi_body_generator.c (with props)
team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_body_generator.c (with props)
team/mmichelson/pubsub_bodies/res/res_pjsip_xpidf_body_generator.c (with props)
Modified:
team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_exten_state.h
team/mmichelson/pubsub_bodies/res/res_pjsip_exten_state.c
team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c
team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c
Added: team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_body_generator_types.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_body_generator_types.h?view=auto&rev=405986
==============================================================================
--- team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_body_generator_types.h (added)
+++ team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_body_generator_types.h Mon Jan 20 17:30:34 2014
@@ -1,0 +1,48 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2014, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson 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.
+ */
+
+/*!
+ * \brief structure used for presence XML bodies
+ *
+ * This is used for the following body types:
+ * \li application/pidf+xml
+ * \li application/xpidf+xml
+ * \li application/cpim-pidf+xml
+ */
+struct exten_state_body_generator_data {
+ /*! Extension state data. See res_pjsip_exten_state.h */
+ struct ast_sip_exten_state_data *exten_data;
+ /*! Local dialog URI */
+ const char *local;
+ /*! Remote dialog URI */
+ const char *remote;
+ /*! Allocation pool */
+ pj_pool_t *pool;
+};
+
+/*!
+ * \brief Message counter used for message-summary XML bodies
+ *
+ * This is used for application/simple-message-summary bodies.
+ */
+struct message_accumulator {
+ /*! Number of old messages */
+ int old_msgs;
+ /*! Number of new messages */
+ int new_msgs;
+};
Propchange: team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_body_generator_types.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_body_generator_types.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_body_generator_types.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_exten_state.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_exten_state.h?view=diff&rev=405986&r1=405985&r2=405986
==============================================================================
--- team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_exten_state.h (original)
+++ team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_exten_state.h Mon Jan 20 17:30:34 2014
@@ -75,13 +75,6 @@
AST_LIST_ENTRY(ast_sip_exten_state_provider) next;
};
-struct exten_state_body_generator_data {
- struct ast_sip_exten_state_data *exten_data;
- const char *local;
- const char *remote;
- pj_pool_t *pool;
-};
-
/*!
* \brief Registers an extension state provider.
*
Added: team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_xml.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_xml.h?view=auto&rev=405986
==============================================================================
--- team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_xml.h (added)
+++ team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_xml.h Mon Jan 20 17:30:34 2014
@@ -1,0 +1,35 @@
+/*
+ * asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2014, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson 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.
+ */
+
+enum state {
+ NOTIFY_OPEN,
+ NOTIFY_INUSE,
+ NOTIFY_CLOSED
+};
+
+void exten_state_to_str(int state, char **statestring, char **pidfstate,
+ char **pidfnote, int *local_state);
+
+pj_xml_attr *create_attr(pj_pool_t *pool, pj_xml_node *node,
+ const char *name, const char *value);
+
+pj_xml_node *create_node(pj_pool_t *pool, pj_xml_node *parent,
+ const char* name);
+
+pj_xml_attr *find_node_attr(pj_pool_t* pool, pj_xml_node *parent,
+ const char *node_name, const char *attr_name);
Propchange: team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_xml.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_xml.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_xml.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: team/mmichelson/pubsub_bodies/res/res_pjsip_exten_state.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/res/res_pjsip_exten_state.c?view=diff&rev=405986&r1=405985&r2=405986
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_exten_state.c (original)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_exten_state.c Mon Jan 20 17:30:34 2014
@@ -32,6 +32,7 @@
#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_pubsub.h"
#include "asterisk/res_pjsip_exten_state.h"
+#include "asterisk/res_pjsip_body_generator_types.h"
#include "asterisk/module.h"
#include "asterisk/logger.h"
#include "asterisk/astobj2.h"
@@ -553,102 +554,31 @@
#define DEFAULT_PRESENCE_BODY "application/pidf+xml"
-/*!
- * \internal
- * \brief Create and register a subscription handler.
- *
- * Creates a subscription handler that can be registered with the pub/sub
- * framework for the given event_name and accept value.
- */
-static struct ast_sip_subscription_handler *create_and_register_handler(
- const char *event_name, const char *accept)
-{
- struct ast_sip_subscription_handler *handler =
- ao2_alloc(sizeof(*handler), NULL);
-
- if (!handler) {
- return NULL;
- }
-
- handler->event_name = event_name;
- handler->accept[0] = accept;
- handler->default_accept = DEFAULT_PRESENCE_BODY;
- handler->subscription_shutdown = subscription_shutdown;
- handler->new_subscribe = new_subscribe;
- handler->resubscribe = resubscribe;
- handler->subscription_timeout = subscription_timeout;
- handler->subscription_terminated = subscription_terminated;
- handler->to_ami = to_ami;
-
- if (ast_sip_register_subscription_handler(handler)) {
+struct ast_sip_subscription_handler presence_handler = {
+ .event_name = "presence",
+ .accept = { DEFAULT_PRESENCE_BODY, },
+ .default_accept = DEFAULT_PRESENCE_BODY,
+ .subscription_shutdown = subscription_shutdown,
+ .new_subscribe = new_subscribe,
+ .resubscribe = resubscribe,
+ .subscription_timeout = subscription_timeout,
+ .subscription_terminated = subscription_terminated,
+ .to_ami = to_ami,
+};
+
+static int load_module(void)
+{
+ if (ast_sip_register_subscription_handler(&presence_handler)) {
ast_log(LOG_WARNING, "Unable to register subscription handler %s\n",
- handler->event_name);
- ao2_cleanup(handler);
- return NULL;
- }
-
- return handler;
-}
-
-int ast_sip_register_exten_state_provider(struct ast_sip_exten_state_provider *obj)
-{
- if (ast_strlen_zero(obj->type)) {
- ast_log(LOG_WARNING, "Type not specified on provider for event %s\n",
- obj->event_name);
- return -1;
- }
-
- if (ast_strlen_zero(obj->subtype)) {
- ast_log(LOG_WARNING, "Subtype not specified on provider for event %s\n",
- obj->event_name);
- return -1;
- }
-
- if (!obj->create_body) {
- ast_log(LOG_WARNING, "Body handler not specified on provide for event %s\n",
- obj->event_name);
- return -1;
- }
-
- if (!(obj->handler = create_and_register_handler(obj->event_name, obj->body_type))) {
- ast_log(LOG_WARNING, "Handler could not be registered for provider event %s\n",
- obj->event_name);
- return -1;
- }
-
- /* scope to avoid mix declarations */
- {
- 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_sip_unregister_exten_state_provider(struct ast_sip_exten_state_provider *obj)
-{
- struct ast_sip_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_sip_unregister_subscription_handler(i->handler);
- ao2_cleanup(i->handler);
- AST_RWLIST_REMOVE_CURRENT(next);
- ast_module_unref(ast_module_info->self);
- break;
- }
- }
- AST_RWLIST_TRAVERSE_SAFE_END;
-}
-
-static int load_module(void)
-{
+ presence_handler.event_name);
+ return AST_MODULE_LOAD_DECLINE;
+ }
return AST_MODULE_LOAD_SUCCESS;
}
static int unload_module(void)
{
+ ast_sip_unregister_subscription_handler(&presence_handler);
return 0;
}
Modified: team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c?view=diff&rev=405986&r1=405985&r2=405986
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c (original)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c Mon Jan 20 17:30:34 2014
@@ -31,6 +31,7 @@
#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_pubsub.h"
+#include "asterisk/res_pjsip_body_generator_types.h"
#include "asterisk/module.h"
#include "asterisk/logger.h"
#include "asterisk/astobj2.h"
@@ -73,21 +74,6 @@
.notify_request = mwi_notify_request,
.refresh_subscription = mwi_refresh_subscription,
.to_ami = mwi_to_ami,
-};
-
-static void *mwi_allocate_body(void *data);
-static int mwi_generate_body_content(void *body, void *data);
-static void mwi_to_string(void *body, struct ast_str **str);
-static void mwi_destroy_body(void *body);
-
-static struct ast_sip_pubsub_body_generator mwi_generator = {
- .type = MWI_TYPE,
- .subtype = MWI_SUBTYPE,
- .generator_type = AST_SIP_PUBSUB_BODY_GENERATOR_PRIMARY,
- .allocate_body = mwi_allocate_body,
- .generate_body_content = mwi_generate_body_content,
- .to_string = mwi_to_string,
- .destroy_body = mwi_destroy_body,
};
/*!
@@ -242,12 +228,6 @@
return strcmp(mwi_sub1->id, mwi_sub2->id) ? 0 : CMP_MATCH;
}
-struct message_accumulator {
- int old_msgs;
- int new_msgs;
- const char *reason;
-};
-
static int get_message_count(void *obj, void *arg, int flags)
{
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
@@ -380,50 +360,6 @@
ao2_callback(contacts, OBJ_NODATA, send_unsolicited_mwi_notify_to_contact, &mwi_data);
}
-}
-
-static void *mwi_allocate_body(void *data)
-{
- struct ast_str **mwi_str;
-
- mwi_str = ast_malloc(sizeof(*mwi_str));
- if (!mwi_str) {
- return NULL;
- }
- *mwi_str = ast_str_create(64);
- if (*mwi_str) {
- ast_free(mwi_str);
- return NULL;
- }
- return mwi_str;
-}
-
-static int mwi_generate_body_content(void *body, void *data)
-{
- struct ast_str **mwi = body;
- struct message_accumulator *counter = data;
-
- ast_str_append(mwi, 0, "Messages-Waiting: %s\r\n",
- counter->new_msgs ? "yes" : "no");
- ast_str_append(mwi, 0, "Voice-Message: %d/%d (0/0)\r\n",
- counter->new_msgs, counter->old_msgs);
-
- return 0;
-}
-
-static void mwi_to_string(void *body, struct ast_str **str)
-{
- struct ast_str **mwi = body;
-
- ast_str_set(str, 0, "%s", ast_str_buffer(*mwi));
-}
-
-static void mwi_destroy_body(void *body)
-{
- struct ast_str **mwi = body;
-
- ast_free(*mwi);
- ast_free(mwi);
}
static void send_mwi_notify(struct mwi_subscription *sub, pjsip_evsub_state state, const char *reason)
@@ -808,10 +744,6 @@
if (ast_sip_register_subscription_handler(&mwi_handler)) {
return AST_MODULE_LOAD_DECLINE;
}
- if (ast_sip_pubsub_register_body_generator(&mwi_generator)) {
- ast_sip_unregister_subscription_handler(&mwi_handler);
- return AST_MODULE_LOAD_DECLINE;
- }
create_mwi_subscriptions();
return AST_MODULE_LOAD_SUCCESS;
}
@@ -824,7 +756,6 @@
ao2_global_obj_release(unsolicited_mwi);
}
ast_sip_unregister_subscription_handler(&mwi_handler);
- ast_sip_pubsub_unregister_body_generator(&mwi_generator);
return 0;
}
Added: team/mmichelson/pubsub_bodies/res/res_pjsip_mwi_body_generator.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/res/res_pjsip_mwi_body_generator.c?view=auto&rev=405986
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_mwi_body_generator.c (added)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_mwi_body_generator.c Mon Jan 20 17:30:34 2014
@@ -1,0 +1,113 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2014, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson 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_pjsip</depend>
+ <depend>res_pjsip_pubsub</depend>
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+#include <pjsip.h>
+#include <pjsip_simple.h>
+#include <pjlib.h>
+
+#include "asterisk/res_pjsip.h"
+#include "asterisk/res_pjsip_pubsub.h"
+#include "asterisk/res_pjsip_body_generator_types.h"
+#include "asterisk/module.h"
+#include "asterisk/strings.h"
+
+#define MWI_TYPE "application"
+#define MWI_SUBTYPE "simple-message-summary"
+
+static void *mwi_allocate_body(void *data)
+{
+ struct ast_str **mwi_str;
+
+ mwi_str = ast_malloc(sizeof(*mwi_str));
+ if (!mwi_str) {
+ return NULL;
+ }
+ *mwi_str = ast_str_create(64);
+ if (*mwi_str) {
+ ast_free(mwi_str);
+ return NULL;
+ }
+ return mwi_str;
+}
+
+static int mwi_generate_body_content(void *body, void *data)
+{
+ struct ast_str **mwi = body;
+ struct message_accumulator *counter = data;
+
+ ast_str_append(mwi, 0, "Messages-Waiting: %s\r\n",
+ counter->new_msgs ? "yes" : "no");
+ ast_str_append(mwi, 0, "Voice-Message: %d/%d (0/0)\r\n",
+ counter->new_msgs, counter->old_msgs);
+
+ return 0;
+}
+
+static void mwi_to_string(void *body, struct ast_str **str)
+{
+ struct ast_str **mwi = body;
+
+ ast_str_set(str, 0, "%s", ast_str_buffer(*mwi));
+}
+
+static void mwi_destroy_body(void *body)
+{
+ struct ast_str **mwi = body;
+
+ ast_free(*mwi);
+ ast_free(mwi);
+}
+
+static struct ast_sip_pubsub_body_generator mwi_generator = {
+ .type = MWI_TYPE,
+ .subtype = MWI_SUBTYPE,
+ .generator_type = AST_SIP_PUBSUB_BODY_GENERATOR_PRIMARY,
+ .allocate_body = mwi_allocate_body,
+ .generate_body_content = mwi_generate_body_content,
+ .to_string = mwi_to_string,
+ .destroy_body = mwi_destroy_body,
+};
+
+static int load_module(void)
+{
+ if (ast_sip_pubsub_register_body_generator(&mwi_generator)) {
+ return AST_MODULE_LOAD_DECLINE;
+ }
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+static int unload_module(void)
+{
+ ast_sip_pubsub_unregister_body_generator(&mwi_generator);
+ return 0;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP MWI resource",
+ .load = load_module,
+ .unload = unload_module,
+ .load_pri = AST_MODPRI_CHANNEL_DEPEND,
+);
Propchange: team/mmichelson/pubsub_bodies/res/res_pjsip_mwi_body_generator.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/mmichelson/pubsub_bodies/res/res_pjsip_mwi_body_generator.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/mmichelson/pubsub_bodies/res/res_pjsip_mwi_body_generator.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c?view=diff&rev=405986&r1=405985&r2=405986
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c (original)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c Mon Jan 20 17:30:34 2014
@@ -34,14 +34,10 @@
#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_exten_state.h"
#include "asterisk/res_pjsip_pubsub.h"
+#include "asterisk/res_pjsip_xml.h"
+#include "asterisk/res_pjsip_body_generator_types.h"
-enum state {
- NOTIFY_OPEN,
- NOTIFY_INUSE,
- NOTIFY_CLOSED
-};
-
-static void exten_state_to_str(int state, char **statestring, char **pidfstate,
+void exten_state_to_str(int state, char **statestring, char **pidfstate,
char **pidfnote, int *local_state)
{
switch (state) {
@@ -87,7 +83,7 @@
}
}
-static pj_xml_attr *create_attr(pj_pool_t *pool, pj_xml_node *node,
+pj_xml_attr *create_attr(pj_pool_t *pool, pj_xml_node *node,
const char *name, const char *value)
{
pj_xml_attr *attr = PJ_POOL_ALLOC_T(pool, pj_xml_attr);
@@ -99,7 +95,7 @@
return attr;
}
-static pj_xml_node *create_node(pj_pool_t *pool, pj_xml_node *parent,
+pj_xml_node *create_node(pj_pool_t *pool, pj_xml_node *parent,
const char* name)
{
pj_xml_node *node = PJ_POOL_ALLOC_T(pool, pj_xml_node);
@@ -116,7 +112,7 @@
return node;
}
-static pj_xml_attr *find_node_attr(pj_pool_t* pool, pj_xml_node *parent,
+pj_xml_attr *find_node_attr(pj_pool_t* pool, pj_xml_node *parent,
const char *node_name, const char *attr_name)
{
pj_str_t name;
@@ -133,293 +129,3 @@
return attr;
}
-
-/*!
- * \internal
- * \brief Adds non standard elements to the xml body
- *
- * This is some code that was part of the original chan_sip implementation
- * that is not part of the RFC 3863 definition, but we are keeping available
- * for backward compatability. The original comment stated that Eyebeam
- * supports this format.
-
- */
-static void add_non_standard(pj_pool_t *pool, pj_xml_node *node, const char *pidfstate)
-{
- static const char *XMLNS_PP = "xmlns:pp";
- static const char *XMLNS_PERSON = "urn:ietf:params:xml:ns:pidf:person";
-
- static const char *XMLNS_ES = "xmlns:es";
- static const char *XMLNS_RPID_STATUS = "urn:ietf:params:xml:ns:pidf:rpid:status:rpid-status";
-
- static const char *XMLNS_EP = "xmlns:ep";
- static const char *XMLNS_RPID_PERSON = "urn:ietf:params:xml:ns:pidf:rpid:rpid-person";
-
- pj_xml_node *person = create_node(pool, node, "pp:person");
- pj_xml_node *status = create_node(pool, person, "status");
-
- if (pidfstate[0] != '-') {
- pj_xml_node *activities = create_node(pool, status, "ep:activities");
- size_t str_size = sizeof("ep:") + strlen(pidfstate);
-
- activities->content.ptr = pj_pool_alloc(pool, str_size);
- activities->content.slen = pj_ansi_snprintf(activities->content.ptr, str_size,
- "ep:%s", pidfstate);
- }
-
- create_attr(pool, node, XMLNS_PP, XMLNS_PERSON);
- create_attr(pool, node, XMLNS_ES, XMLNS_RPID_STATUS);
- create_attr(pool, node, XMLNS_EP, XMLNS_RPID_PERSON);
-}
-
-/*!
- * \internal
- * \brief Convert angle brackets in input into escaped forms suitable for XML
- *
- * \param input Raw input string
- * \param output Sanitized string
- * \param len Size of output buffer
- */
-static void sanitize_xml(const char *input, char *output, size_t len)
-{
- char *copy = ast_strdupa(input);
- char *break_point;
-
- output[0] = '\0';
-
- while ((break_point = strpbrk(copy, "<>"))) {
- char bracket = *break_point;
-
- *break_point = '\0';
- strncat(output, copy, len);
-
- if (bracket == '<') {
- strncat(output, "<", len);
- } else {
- strncat(output, "&rt;", len);
- }
-
- copy = break_point + 1;
- }
-
- /* Be sure to copy everything after the final bracket */
- if (*copy) {
- strncat(output, copy, len);
- }
-}
-
-static void *pidf_allocate_body(void *data)
-{
- struct exten_state_body_generator_data *gen_data = data;
- pjpidf_pres *pres;
- pj_str_t entity;
-
- pres = pjpidf_create(gen_data->pool, pj_cstr(&entity, gen_data->local));
-
- return pres;
-}
-
-static int pidf_generate_body_content(void *body, void *data)
-{
- pjpidf_tuple *tuple;
- pj_str_t note, id, contact, priority;
- char *statestring = NULL, *pidfstate = NULL, *pidfnote = NULL;
- int local_state;
- char sanitized[PJSIP_MAX_URL_SIZE];
- pjpidf_pres *pres = body;
- struct exten_state_body_generator_data *gen_data = data;
-
- exten_state_to_str(gen_data->exten_data->exten_state, &statestring, &pidfstate,
- &pidfnote, &local_state);
-
- add_non_standard(gen_data->pool, pres, pidfstate);
-
- if (!pjpidf_pres_add_note(gen_data->pool, pres, pj_cstr(¬e, pidfnote))) {
- ast_log(LOG_WARNING, "Unable to add note to PIDF presence\n");
- return -1;
- }
-
- if (!(tuple = pjpidf_pres_add_tuple(gen_data->pool, pres,
- pj_cstr(&id, gen_data->exten_data->exten)))) {
- ast_log(LOG_WARNING, "Unable to create PIDF tuple\n");
- return -1;
- }
-
- sanitize_xml(gen_data->remote, sanitized, sizeof(sanitized));
- pjpidf_tuple_set_contact(gen_data->pool, tuple, pj_cstr(&contact, sanitized));
- pjpidf_tuple_set_contact_prio(gen_data->pool, tuple, pj_cstr(&priority, "1"));
- pjpidf_status_set_basic_open(pjpidf_tuple_get_status(tuple),
- (pidfstate[0] == 'b') || (local_state != NOTIFY_CLOSED));
-
- return 0;
-}
-
-#define MAX_STRING_GROWTHS 3
-
-static void pidf_to_string(void *body, struct ast_str **str)
-{
- int size;
- int growths = 0;
- pjpidf_pres *pres = body;
-
- do {
- size = pjpidf_print(pres, ast_str_buffer(*str), ast_str_size(*str) - 1);
- if (size < 0) {
- ast_str_make_space(str, ast_str_size(*str) * 2);
- ++growths;
- return;
- }
- } while (size < 0 && growths < MAX_STRING_GROWTHS);
-
- if (size < 0) {
- ast_log(LOG_WARNING, "PIDF body text too large\n");
- return;
- }
-
- *(ast_str_buffer(*str) + size) = '\0';
- ast_str_update(*str);
-}
-
-static struct ast_sip_pubsub_body_generator pidf_body_generator = {
- .type = "application",
- .subtype = "pidf+xml",
- .generator_type = AST_SIP_PUBSUB_BODY_GENERATOR_PRIMARY,
- .allocate_body = pidf_allocate_body,
- .generate_body_content = pidf_generate_body_content,
- .to_string = pidf_to_string,
- /* No need for a destroy_body callback since we use a pool */
-};
-
-static void *xpidf_allocate_body(void *data)
-{
- struct exten_state_body_generator_data *gen_data = data;
- pjxpidf_pres *pres;
- pj_str_t name;
-
- pres = pjxpidf_create(gen_data->pool, pj_cstr(&name, gen_data->local));
- return pres;
-}
-
-static int xpidf_generate_body_content(void *body, void *data)
-{
- pjxpidf_pres *pres = body;
- struct exten_state_body_generator_data *gen_data = data;
- static pj_str_t STR_ADDR_PARAM = { ";user=ip", 8 };
- char *statestring = NULL, *pidfstate = NULL, *pidfnote = NULL;
- pj_xml_attr *attr;
- int local_state;
- pj_str_t name, uri;
-
- exten_state_to_str(gen_data->exten_data->exten_state, &statestring, &pidfstate,
- &pidfnote, &local_state);
-
- attr = find_node_attr(gen_data->pool, pres, "atom", "id");
- pj_strdup2(gen_data->pool, &attr->value, gen_data->exten_data->exten);
-
- attr = find_node_attr(gen_data->pool, pres, "address", "uri");
-
- uri.ptr = (char*) pj_pool_alloc(gen_data->pool, strlen(gen_data->remote) + STR_ADDR_PARAM.slen);
- pj_strcpy2( &uri, gen_data->remote);
- pj_strcat( &uri, &STR_ADDR_PARAM);
- pj_strdup(gen_data->pool, &attr->value, &uri);
-
- create_attr(gen_data->pool, pj_xml_find_node(pres, pj_cstr(&name, "address")),
- "priority", "0.80000");
-
- attr = find_node_attr(gen_data->pool, pres, "status", "status");
- pj_strdup2(gen_data->pool, &attr->value,
- (local_state == NOTIFY_OPEN) ? "open" :
- (local_state == NOTIFY_INUSE) ? "inuse" : "closed");
-
- attr = find_node_attr(gen_data->pool, pres, "msnsubstatus", "substatus");
- pj_strdup2(gen_data->pool, &attr->value,
- (local_state == NOTIFY_OPEN) ? "online" :
- (local_state == NOTIFY_INUSE) ? "onthephone" : "offline");
-
- return 0;
-}
-
-static void xpidf_to_string(void *body, struct ast_str **str)
-{
- pjxpidf_pres *pres = body;
- int growths = 0;
- int size;
-
- do {
-
- size = pjxpidf_print(pres, ast_str_buffer(*str), ast_str_size(*str));
- if (size < 0) {
- ast_str_make_space(str, ast_str_size(*str) * 2);
- ++growths;
- return;
- }
- } while (size < 0 && growths < MAX_STRING_GROWTHS);
-
- if (size < 0) {
- ast_log(LOG_WARNING, "XPIDF body text too large\n");
- return;
- }
-
- *(ast_str_buffer(*str) + size) = '\0';
- ast_str_update(*str);
-}
-
-static struct ast_sip_pubsub_body_generator xpidf_body_generator = {
- .type = "application",
- .subtype = "xpidf+xml",
- .generator_type = AST_SIP_PUBSUB_BODY_GENERATOR_PRIMARY,
- .allocate_body = xpidf_allocate_body,
- .generate_body_content = xpidf_generate_body_content,
- .to_string = xpidf_to_string,
- /* No need for a destroy_body callback since we use a pool */
-};
-
-static struct ast_sip_pubsub_body_generator cpim_pidf_body_generator = {
- .type = "application",
- .subtype = "cpim-pidf+xml",
- .generator_type = AST_SIP_PUBSUB_BODY_GENERATOR_PRIMARY,
- .allocate_body = xpidf_allocate_body,
- .generate_body_content = xpidf_generate_body_content,
- .to_string = xpidf_to_string,
- /* No need for a destroy_body callback since we use a pool */
-};
-
-static void unregister_all(void)
-{
- ast_sip_pubsub_unregister_body_generator(&cpim_pidf_body_generator);
- ast_sip_pubsub_unregister_body_generator(&xpidf_body_generator);
- ast_sip_pubsub_unregister_body_generator(&pidf_body_generator);
-}
-
-static int load_module(void)
-{
- if (ast_sip_pubsub_register_body_generator(&pidf_body_generator)) {
- goto fail;
- }
-
- if (ast_sip_pubsub_register_body_generator(&xpidf_body_generator)) {
- goto fail;
- }
-
- if (ast_sip_pubsub_register_body_generator(&cpim_pidf_body_generator)) {
- goto fail;
- }
-
- return AST_MODULE_LOAD_SUCCESS;
-
-fail:
- unregister_all();
- return AST_MODULE_LOAD_DECLINE;
-}
-
-static int unload_module(void)
-{
- unregister_all();
- return 0;
-}
-
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Extension State PIDF Provider",
- .load = load_module,
- .unload = unload_module,
- .load_pri = AST_MODPRI_CHANNEL_DEPEND,
-);
Added: team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_body_generator.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_body_generator.c?view=auto&rev=405986
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_body_generator.c (added)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_body_generator.c Mon Jan 20 17:30:34 2014
@@ -1,0 +1,212 @@
+/*
+ * asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2014, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson 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_pjsip</depend>
+ <depend>res_pjsip_pubsub</depend>
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+#include <pjsip.h>
+#include <pjsip_simple.h>
+#include <pjlib.h>
+
+#include "asterisk/module.h"
+#include "asterisk/res_pjsip.h"
+#include "asterisk/res_pjsip_exten_state.h"
+#include "asterisk/res_pjsip_pubsub.h"
+#include "asterisk/res_pjsip_xml.h"
+#include "asterisk/res_pjsip_body_generator_types.h"
+
+/*!
+ * \internal
+ * \brief Adds non standard elements to the xml body
+ *
+ * This is some code that was part of the original chan_sip implementation
+ * that is not part of the RFC 3863 definition, but we are keeping available
+ * for backward compatability. The original comment stated that Eyebeam
+ * supports this format.
+ */
+static void add_non_standard(pj_pool_t *pool, pj_xml_node *node, const char *pidfstate)
+{
+ static const char *XMLNS_PP = "xmlns:pp";
+ static const char *XMLNS_PERSON = "urn:ietf:params:xml:ns:pidf:person";
+
+ static const char *XMLNS_ES = "xmlns:es";
+ static const char *XMLNS_RPID_STATUS = "urn:ietf:params:xml:ns:pidf:rpid:status:rpid-status";
+
+ static const char *XMLNS_EP = "xmlns:ep";
+ static const char *XMLNS_RPID_PERSON = "urn:ietf:params:xml:ns:pidf:rpid:rpid-person";
+
+ pj_xml_node *person = create_node(pool, node, "pp:person");
+ pj_xml_node *status = create_node(pool, person, "status");
+
+ if (pidfstate[0] != '-') {
+ pj_xml_node *activities = create_node(pool, status, "ep:activities");
+ size_t str_size = sizeof("ep:") + strlen(pidfstate);
+
+ activities->content.ptr = pj_pool_alloc(pool, str_size);
+ activities->content.slen = pj_ansi_snprintf(activities->content.ptr, str_size,
+ "ep:%s", pidfstate);
+ }
+
+ create_attr(pool, node, XMLNS_PP, XMLNS_PERSON);
+ create_attr(pool, node, XMLNS_ES, XMLNS_RPID_STATUS);
+ create_attr(pool, node, XMLNS_EP, XMLNS_RPID_PERSON);
+}
+
+/*!
+ * \internal
+ * \brief Convert angle brackets in input into escaped forms suitable for XML
+ *
+ * \param input Raw input string
+ * \param output Sanitized string
+ * \param len Size of output buffer
+ */
+static void sanitize_xml(const char *input, char *output, size_t len)
+{
+ char *copy = ast_strdupa(input);
+ char *break_point;
+
+ output[0] = '\0';
+
+ while ((break_point = strpbrk(copy, "<>"))) {
+ char bracket = *break_point;
+
+ *break_point = '\0';
+ strncat(output, copy, len);
+
+ if (bracket == '<') {
+ strncat(output, "<", len);
+ } else {
+ strncat(output, "&rt;", len);
+ }
+
+ copy = break_point + 1;
+ }
+
+ /* Be sure to copy everything after the final bracket */
+ if (*copy) {
+ strncat(output, copy, len);
+ }
+}
+
+static void *pidf_allocate_body(void *data)
+{
+ struct exten_state_body_generator_data *gen_data = data;
+ pjpidf_pres *pres;
+ pj_str_t entity;
+
+ pres = pjpidf_create(gen_data->pool, pj_cstr(&entity, gen_data->local));
+
+ return pres;
+}
+
+static int pidf_generate_body_content(void *body, void *data)
+{
+ pjpidf_tuple *tuple;
+ pj_str_t note, id, contact, priority;
+ char *statestring = NULL, *pidfstate = NULL, *pidfnote = NULL;
+ int local_state;
+ char sanitized[PJSIP_MAX_URL_SIZE];
+ pjpidf_pres *pres = body;
+ struct exten_state_body_generator_data *gen_data = data;
+
+ exten_state_to_str(gen_data->exten_data->exten_state, &statestring, &pidfstate,
+ &pidfnote, &local_state);
+
+ add_non_standard(gen_data->pool, pres, pidfstate);
+
+ if (!pjpidf_pres_add_note(gen_data->pool, pres, pj_cstr(¬e, pidfnote))) {
+ ast_log(LOG_WARNING, "Unable to add note to PIDF presence\n");
+ return -1;
+ }
+
+ if (!(tuple = pjpidf_pres_add_tuple(gen_data->pool, pres,
+ pj_cstr(&id, gen_data->exten_data->exten)))) {
+ ast_log(LOG_WARNING, "Unable to create PIDF tuple\n");
+ return -1;
+ }
+
+ sanitize_xml(gen_data->remote, sanitized, sizeof(sanitized));
+ pjpidf_tuple_set_contact(gen_data->pool, tuple, pj_cstr(&contact, sanitized));
+ pjpidf_tuple_set_contact_prio(gen_data->pool, tuple, pj_cstr(&priority, "1"));
+ pjpidf_status_set_basic_open(pjpidf_tuple_get_status(tuple),
+ (pidfstate[0] == 'b') || (local_state != NOTIFY_CLOSED));
+
+ return 0;
+}
+
+#define MAX_STRING_GROWTHS 3
+
+static void pidf_to_string(void *body, struct ast_str **str)
+{
+ int size;
+ int growths = 0;
+ pjpidf_pres *pres = body;
+
+ do {
+ size = pjpidf_print(pres, ast_str_buffer(*str), ast_str_size(*str) - 1);
+ if (size < 0) {
+ ast_str_make_space(str, ast_str_size(*str) * 2);
+ ++growths;
+ return;
+ }
+ } while (size < 0 && growths < MAX_STRING_GROWTHS);
+
+ if (size < 0) {
+ ast_log(LOG_WARNING, "PIDF body text too large\n");
+ return;
+ }
+
+ *(ast_str_buffer(*str) + size) = '\0';
+ ast_str_update(*str);
+}
+
+static struct ast_sip_pubsub_body_generator pidf_body_generator = {
+ .type = "application",
+ .subtype = "pidf+xml",
+ .generator_type = AST_SIP_PUBSUB_BODY_GENERATOR_PRIMARY,
+ .allocate_body = pidf_allocate_body,
+ .generate_body_content = pidf_generate_body_content,
+ .to_string = pidf_to_string,
+ /* No need for a destroy_body callback since we use a pool */
+};
+
+static int load_module(void)
+{
+ if (ast_sip_pubsub_register_body_generator(&pidf_body_generator)) {
+ return AST_MODULE_LOAD_DECLINE;
+ }
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+static int unload_module(void)
+{
+ ast_sip_pubsub_unregister_body_generator(&pidf_body_generator);
+ return 0;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Extension State PIDF Provider",
+ .load = load_module,
+ .unload = unload_module,
+ .load_pri = AST_MODPRI_CHANNEL_DEPEND,
+);
Propchange: team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_body_generator.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_body_generator.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_body_generator.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: team/mmichelson/pubsub_bodies/res/res_pjsip_xpidf_body_generator.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/res/res_pjsip_xpidf_body_generator.c?view=auto&rev=405986
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_xpidf_body_generator.c (added)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_xpidf_body_generator.c Mon Jan 20 17:30:34 2014
@@ -1,0 +1,169 @@
+/*
+ * asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2014, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson 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_pjsip</depend>
+ <depend>res_pjsip_pubsub</depend>
+ <depend>res_pjsip_exten_state</depend>
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+#include <pjsip.h>
+#include <pjsip_simple.h>
+#include <pjlib.h>
+
+#include "asterisk/module.h"
+#include "asterisk/res_pjsip.h"
+#include "asterisk/res_pjsip_exten_state.h"
+#include "asterisk/res_pjsip_pubsub.h"
+#include "asterisk/res_pjsip_xml.h"
+#include "asterisk/res_pjsip_body_generator_types.h"
+
+static void *xpidf_allocate_body(void *data)
+{
+ struct exten_state_body_generator_data *gen_data = data;
+ pjxpidf_pres *pres;
+ pj_str_t name;
+
+ pres = pjxpidf_create(gen_data->pool, pj_cstr(&name, gen_data->local));
+ return pres;
+}
+
+static int xpidf_generate_body_content(void *body, void *data)
+{
+ pjxpidf_pres *pres = body;
+ struct exten_state_body_generator_data *gen_data = data;
+ static pj_str_t STR_ADDR_PARAM = { ";user=ip", 8 };
+ char *statestring = NULL, *pidfstate = NULL, *pidfnote = NULL;
+ pj_xml_attr *attr;
+ int local_state;
+ pj_str_t name, uri;
+
+ exten_state_to_str(gen_data->exten_data->exten_state, &statestring, &pidfstate,
+ &pidfnote, &local_state);
+
+ attr = find_node_attr(gen_data->pool, pres, "atom", "id");
+ pj_strdup2(gen_data->pool, &attr->value, gen_data->exten_data->exten);
+
+ attr = find_node_attr(gen_data->pool, pres, "address", "uri");
+
+ uri.ptr = (char*) pj_pool_alloc(gen_data->pool, strlen(gen_data->remote) + STR_ADDR_PARAM.slen);
+ pj_strcpy2( &uri, gen_data->remote);
+ pj_strcat( &uri, &STR_ADDR_PARAM);
+ pj_strdup(gen_data->pool, &attr->value, &uri);
+
+ create_attr(gen_data->pool, pj_xml_find_node(pres, pj_cstr(&name, "address")),
+ "priority", "0.80000");
+
+ attr = find_node_attr(gen_data->pool, pres, "status", "status");
+ pj_strdup2(gen_data->pool, &attr->value,
+ (local_state == NOTIFY_OPEN) ? "open" :
+ (local_state == NOTIFY_INUSE) ? "inuse" : "closed");
+
+ attr = find_node_attr(gen_data->pool, pres, "msnsubstatus", "substatus");
+ pj_strdup2(gen_data->pool, &attr->value,
+ (local_state == NOTIFY_OPEN) ? "online" :
+ (local_state == NOTIFY_INUSE) ? "onthephone" : "offline");
+
+ return 0;
+}
+
+#define MAX_STRING_GROWTHS 3
+
+static void xpidf_to_string(void *body, struct ast_str **str)
+{
+ pjxpidf_pres *pres = body;
+ int growths = 0;
+ int size;
+
+ do {
+
+ size = pjxpidf_print(pres, ast_str_buffer(*str), ast_str_size(*str));
+ if (size < 0) {
+ ast_str_make_space(str, ast_str_size(*str) * 2);
+ ++growths;
+ return;
+ }
+ } while (size < 0 && growths < MAX_STRING_GROWTHS);
+
+ if (size < 0) {
+ ast_log(LOG_WARNING, "XPIDF body text too large\n");
+ return;
+ }
+
+ *(ast_str_buffer(*str) + size) = '\0';
+ ast_str_update(*str);
+}
+
+static struct ast_sip_pubsub_body_generator xpidf_body_generator = {
+ .type = "application",
+ .subtype = "xpidf+xml",
+ .generator_type = AST_SIP_PUBSUB_BODY_GENERATOR_PRIMARY,
+ .allocate_body = xpidf_allocate_body,
+ .generate_body_content = xpidf_generate_body_content,
+ .to_string = xpidf_to_string,
+ /* No need for a destroy_body callback since we use a pool */
+};
+
+static struct ast_sip_pubsub_body_generator cpim_pidf_body_generator = {
+ .type = "application",
+ .subtype = "cpim-pidf+xml",
+ .generator_type = AST_SIP_PUBSUB_BODY_GENERATOR_PRIMARY,
+ .allocate_body = xpidf_allocate_body,
+ .generate_body_content = xpidf_generate_body_content,
+ .to_string = xpidf_to_string,
+ /* No need for a destroy_body callback since we use a pool */
[... 49 lines stripped ...]
More information about the asterisk-commits
mailing list