[svn-commits] mmichelson: branch mmichelson/pubsub_bodies r406293 - /team/mmichelson/pubsub...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jan 23 10:27:01 CST 2014


Author: mmichelson
Date: Thu Jan 23 10:26:49 2014
New Revision: 406293

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=406293
Log:
Move nonstandard PIDF body generation to a body supplement.

Tests still pass as expected.


Added:
    team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_nonstandard_body_supplement.c   (with props)
Modified:
    team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_body_generator.c

Modified: 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=diff&rev=406293&r1=406292&r2=406293
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_body_generator.c (original)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_body_generator.c Thu Jan 23 10:26:49 2014
@@ -35,43 +35,6 @@
 #include "asterisk/res_pjsip_presence_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 = ast_sip_presence_xml_create_node(pool, node, "pp:person");
-	pj_xml_node *status = ast_sip_presence_xml_create_node(pool, person, "status");
-
-	if (pidfstate[0] != '-') {
-		pj_xml_node *activities = ast_sip_presence_xml_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);
-	}
-
-	ast_sip_presence_xml_create_attr(pool, node, XMLNS_PP, XMLNS_PERSON);
-	ast_sip_presence_xml_create_attr(pool, node, XMLNS_ES, XMLNS_RPID_STATUS);
-	ast_sip_presence_xml_create_attr(pool, node, XMLNS_EP, XMLNS_RPID_PERSON);
-}
-
 static void *pidf_allocate_body(void *data)
 {
 	struct ast_sip_exten_state_data *state_data = data;
@@ -95,8 +58,6 @@
 
 	ast_sip_presence_exten_state_to_str(state_data->exten_state, &statestring,
 			&pidfstate, &pidfnote, &local_state);
-
-	add_non_standard(state_data->pool, pres, pidfstate);
 
 	if (!pjpidf_pres_add_note(state_data->pool, pres, pj_cstr(&note, pidfnote))) {
 		ast_log(LOG_WARNING, "Unable to add note to PIDF presence\n");

Added: team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_nonstandard_body_supplement.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_nonstandard_body_supplement.c?view=auto&rev=406293
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_nonstandard_body_supplement.c (added)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_nonstandard_body_supplement.c Thu Jan 23 10:26:49 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/module.h"
+#include "asterisk/res_pjsip.h"
+#include "asterisk/res_pjsip_pubsub.h"
+#include "asterisk/res_pjsip_presence_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 = ast_sip_presence_xml_create_node(pool, node, "pp:person");
+	pj_xml_node *status = ast_sip_presence_xml_create_node(pool, person, "status");
+
+	if (pidfstate[0] != '-') {
+		pj_xml_node *activities = ast_sip_presence_xml_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);
+	}
+
+	ast_sip_presence_xml_create_attr(pool, node, XMLNS_PP, XMLNS_PERSON);
+	ast_sip_presence_xml_create_attr(pool, node, XMLNS_ES, XMLNS_RPID_STATUS);
+	ast_sip_presence_xml_create_attr(pool, node, XMLNS_EP, XMLNS_RPID_PERSON);
+}
+
+static int pidf_supplement_body(void *body, void *data)
+{
+	pjpidf_pres *pres = body;
+	struct ast_sip_exten_state_data *state_data = data;
+	char *statestring = NULL, *pidfstate = NULL, *pidfnote = NULL;
+	enum ast_sip_pidf_state local_state;
+
+	ast_sip_presence_exten_state_to_str(state_data->exten_state, &statestring,
+			&pidfstate, &pidfnote, &local_state);
+
+	add_non_standard(state_data->pool, pres, pidfstate);
+	return 0;
+}
+
+static struct ast_sip_pubsub_body_supplement pidf_supplement = {
+	.type = "application",
+	.subtype = "pidf+xml",
+	.supplement_body = pidf_supplement_body,
+};
+
+static int load_module(void)
+{
+	if (ast_sip_pubsub_register_body_supplement(&pidf_supplement)) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+static int unload_module(void)
+{
+	ast_sip_pubsub_unregister_body_supplement(&pidf_supplement);
+	return 0;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP PIDF nonstandard supplement",
+		.load = load_module,
+		.unload = unload_module,
+		.load_pri = AST_MODPRI_CHANNEL_DEPEND,
+);

Propchange: team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_nonstandard_body_supplement.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_nonstandard_body_supplement.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mmichelson/pubsub_bodies/res/res_pjsip_pidf_nonstandard_body_supplement.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the svn-commits mailing list