[asterisk-commits] kharwell: branch 12 r408882 - in /branches/12: include/asterisk/ res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Feb 25 11:50:57 CST 2014


Author: kharwell
Date: Tue Feb 25 11:50:54 2014
New Revision: 408882

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=408882
Log:
res_pjsip_exten_state: Presence for digium phones

Added presence support for digium phones.

Review: https://reviewboard.asterisk.org/r/3239/

Added:
    branches/12/res/res_pjsip_pidf_digium_body_supplement.c   (with props)
Modified:
    branches/12/include/asterisk/res_pjsip_body_generator_types.h
    branches/12/res/res_pjsip_exten_state.c

Modified: branches/12/include/asterisk/res_pjsip_body_generator_types.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/include/asterisk/res_pjsip_body_generator_types.h?view=diff&rev=408882&r1=408881&r2=408882
==============================================================================
--- branches/12/include/asterisk/res_pjsip_body_generator_types.h (original)
+++ branches/12/include/asterisk/res_pjsip_body_generator_types.h Tue Feb 25 11:50:54 2014
@@ -36,6 +36,12 @@
 	enum ast_extension_states exten_state;
 	/*! The presence state of the change */
 	enum ast_presence_state presence_state;
+	/*! The presence subtype of the change */
+	char *presence_subtype;
+	/*! The presence message of the change */
+	char *presence_message;
+	/*! Subscriber user agent */
+	char *user_agent;
 	/*! Current device state information */
 	struct ao2_container *device_state_info;
 	/*! Local dialog URI */

Modified: branches/12/res/res_pjsip_exten_state.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip_exten_state.c?view=diff&rev=408882&r1=408881&r2=408882
==============================================================================
--- branches/12/res/res_pjsip_exten_state.c (original)
+++ branches/12/res/res_pjsip_exten_state.c Tue Feb 25 11:50:54 2014
@@ -57,8 +57,12 @@
 	char context[AST_MAX_CONTEXT];
 	/*! Extension within the context to receive updates from */
 	char exten[AST_MAX_EXTENSION];
+	/*! The subscription's user agent */
+	char *user_agent;
 	/*! The last known extension state */
 	enum ast_extension_states last_exten_state;
+	/*! The last known presence state */
+	enum ast_presence_state last_presence_state;
 };
 
 #define DEFAULT_PRESENCE_BODY "application/pidf+xml"
@@ -90,7 +94,27 @@
 {
 	struct exten_state_subscription *sub = obj;
 
+	ast_free(sub->user_agent);
 	ao2_cleanup(sub->sip_sub);
+}
+
+static char *get_user_agent(pjsip_rx_data *rdata)
+{
+	static const pj_str_t USER_AGENT = { "User-Agent", 10 };
+
+	size_t size;
+	char *user_agent = NULL;
+	pjsip_user_agent_hdr *user_agent_hdr = pjsip_msg_find_hdr_by_name(
+		rdata->msg_info.msg, &USER_AGENT, NULL);
+
+	if (!user_agent_hdr) {
+		return NULL;
+	}
+
+	size = pj_strlen(&user_agent_hdr->hvalue) + 1;
+	user_agent = ast_malloc(size);
+	ast_copy_pj_str(user_agent, &user_agent_hdr->hvalue, size);
+	return ast_str_to_lower(user_agent);
 }
 
 /*!
@@ -125,7 +149,8 @@
 	}
 
 	exten_state_sub->last_exten_state = INITIAL_LAST_EXTEN_STATE;
-
+	exten_state_sub->last_presence_state = AST_PRESENCE_NOT_SET;
+	exten_state_sub->user_agent = get_user_agent(rdata);
 	ao2_ref(exten_state_sub, +1);
 	return exten_state_sub;
 }
@@ -190,6 +215,9 @@
 		.exten = exten_state_sub->exten,
 		.presence_state = ast_hint_presence_state(NULL, exten_state_sub->context,
 							  exten_state_sub->exten, &subtype, &message),
+		.presence_subtype = subtype,
+		.presence_message = message,
+		.user_agent = exten_state_sub->user_agent
 	};
 
 	dlg = ast_sip_subscription_get_dlg(exten_state_sub->sip_sub);
@@ -226,6 +254,9 @@
 
 	ao2_ref(task_data->exten_state_sub, -1);
 	ao2_cleanup(task_data->exten_state_data.device_state_info);
+	ast_free(task_data->exten_state_data.presence_subtype);
+	ast_free(task_data->exten_state_data.presence_message);
+	ast_free(task_data->exten_state_data.user_agent);
 }
 
 static struct notify_task_data *alloc_notify_task_data(char *exten, struct exten_state_subscription *exten_state_sub,
@@ -243,11 +274,15 @@
 	task_data->evsub_state = PJSIP_EVSUB_STATE_ACTIVE;
 	task_data->exten_state_sub = exten_state_sub;
 	task_data->exten_state_sub->last_exten_state = info->exten_state;
+	task_data->exten_state_sub->last_presence_state = info->presence_state;
 	ao2_ref(task_data->exten_state_sub, +1);
 
 	task_data->exten_state_data.exten = exten_state_sub->exten;
 	task_data->exten_state_data.exten_state = info->exten_state;
 	task_data->exten_state_data.presence_state = info->presence_state;
+	task_data->exten_state_data.presence_subtype = ast_strdup(info->presence_subtype);
+	task_data->exten_state_data.presence_message = ast_strdup(info->presence_message);
+	task_data->exten_state_data.user_agent = ast_strdup(exten_state_sub->user_agent);
 	task_data->exten_state_data.device_state_info = info->device_state_info;
 
 	if (task_data->exten_state_data.device_state_info) {
@@ -299,7 +334,8 @@
 	struct notify_task_data *task_data;
 	struct exten_state_subscription *exten_state_sub = data;
 
-	if (exten_state_sub->last_exten_state == info->exten_state) {
+	if (exten_state_sub->last_exten_state == info->exten_state &&
+		exten_state_sub->last_presence_state == info->presence_state) {
 		return 0;
 	}
 

Added: branches/12/res/res_pjsip_pidf_digium_body_supplement.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip_pidf_digium_body_supplement.c?view=auto&rev=408882
==============================================================================
--- branches/12/res/res_pjsip_pidf_digium_body_supplement.c (added)
+++ branches/12/res/res_pjsip_pidf_digium_body_supplement.c Tue Feb 25 11:50:54 2014
@@ -1,0 +1,113 @@
+/*
+ * asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2014, 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_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/presencestate.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"
+
+static int pidf_supplement_body(void *body, void *data)
+{
+	struct ast_sip_exten_state_data *state_data = data;
+	pj_xml_node *node;
+
+	if (ast_strlen_zero(state_data->user_agent) ||
+	    !strstr(state_data->user_agent, "digium")) {
+		/* not a digium phone */
+		return 0;
+	}
+
+	if (!(node = ast_sip_presence_xml_create_node(
+		      state_data->pool, body, "tuple"))) {
+		ast_log(LOG_WARNING, "Unable to create PIDF tuple\n");
+		return -1;
+	}
+
+	ast_sip_presence_xml_create_attr(
+		state_data->pool, node, "id", "digium-presence");
+
+	if (!(node = ast_sip_presence_xml_create_node(
+		      state_data->pool, node, "status"))) {
+		ast_log(LOG_WARNING, "Unable to create PIDF tuple status\n");
+		return -1;
+	}
+
+	if (!(node = ast_sip_presence_xml_create_node(
+		      state_data->pool, node, "digium_presence"))) {
+		ast_log(LOG_WARNING, "Unable to create digium presence\n");
+		return -1;
+	}
+
+	if (!ast_strlen_zero(state_data->presence_message)) {
+			pj_strdup2(state_data->pool, &node->content,
+				   state_data->presence_message);
+	}
+
+	ast_sip_presence_xml_create_attr(
+		state_data->pool, node, "type", ast_presence_state2str(
+			state_data->presence_state));
+
+	if (!ast_strlen_zero(state_data->presence_subtype)) {
+		ast_sip_presence_xml_create_attr(
+			state_data->pool, node, "subtype",
+			state_data->presence_subtype);
+	}
+
+	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 Digium presence supplement",
+		.load = load_module,
+		.unload = unload_module,
+		.load_pri = AST_MODPRI_CHANNEL_DEPEND,
+);

Propchange: branches/12/res/res_pjsip_pidf_digium_body_supplement.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: branches/12/res/res_pjsip_pidf_digium_body_supplement.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Rev URL

Propchange: branches/12/res/res_pjsip_pidf_digium_body_supplement.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list