[asterisk-commits] mmichelson: branch mmichelson/trunk-digiumphones r361327 - /team/mmichelson/t...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 5 17:06:48 CDT 2012


Author: mmichelson
Date: Thu Apr  5 17:06:44 2012
New Revision: 361327

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=361327
Log:
Add a manager action to get presence state.

This aligns similarly to the ExtensionState manager action,
except that this takes a presence provider directly rather
than an extension and context. This works since presence
states are not aggregated the same way that device states
are.


Modified:
    team/mmichelson/trunk-digiumphones/main/manager.c

Modified: team/mmichelson/trunk-digiumphones/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/main/manager.c?view=diff&rev=361327&r1=361326&r2=361327
==============================================================================
--- team/mmichelson/trunk-digiumphones/main/manager.c (original)
+++ team/mmichelson/trunk-digiumphones/main/manager.c Thu Apr  5 17:06:44 2012
@@ -82,6 +82,7 @@
 #include "asterisk/security_events.h"
 #include "asterisk/aoc.h"
 #include "asterisk/stringfields.h"
+#include "asterisk/presencestate.h"
 
 /*** DOCUMENTATION
 	<manager name="Ping" language="en_US">
@@ -508,6 +509,22 @@
 			will use devicestate to check the status of the device connected to the extension.</para>
 			<para>Will return an <literal>Extension Status</literal> message. The response will include
 			the hint for the extension and the status.</para>
+		</description>
+	</manager>
+	<manager name="PresenceState" language="en_US">
+		<synopsis>
+			Check Presence State
+		</synopsis>
+		<syntax>
+			<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
+			<parameter name="Provider" required="true">
+				<para>Presence Provider to check the state of</para>
+			</parameter>
+		</syntax>
+		<description>
+			<para>Report the presence state for the given presence provider.</para>
+			<para>Will return a <literal>Presence State</literal> message. The response will include the
+			presence state and, if set, a presence subtype and custom message.</para>
 		</description>
 	</manager>
 	<manager name="AbsoluteTimeout" language="en_US">
@@ -4331,6 +4348,43 @@
 	return 0;
 }
 
+static int action_presencestate(struct mansession *s, const struct message *m)
+{
+	const char *provider = astman_get_header(m, "Provider");
+	enum ast_presence_state state;
+	char *subtype;
+	char *message;
+	char subtype_header[256] = "";
+	char message_header[256] = "";
+
+	if (ast_strlen_zero(provider)) {
+		astman_send_error(s, m, "No provider specified");
+		return 0;
+	}
+
+	state = ast_presence_state(provider, &subtype, &message);
+
+	if (!ast_strlen_zero(subtype)) {
+		snprintf(subtype_header, sizeof(subtype_header),
+				"Subtype: %s\r\n", subtype);
+	}
+
+	if (!ast_strlen_zero(message)) {
+		snprintf(message_header, sizeof(message_header),
+				"Message: %s\r\n", message);
+	}
+
+	astman_append(s, "Message: Presence State\r\n"
+			"State: %s\r\n"
+			"%s"
+			"%s"
+			"\r\n",
+			ast_presence_state2str(state),
+			subtype_header,
+			message_header);
+	return 0;
+}
+
 static int action_timeout(struct mansession *s, const struct message *m)
 {
 	struct ast_channel *c;
@@ -6792,6 +6846,7 @@
 		ast_manager_register_xml_core("Originate", EVENT_FLAG_ORIGINATE, action_originate);
 		ast_manager_register_xml_core("Command", EVENT_FLAG_COMMAND, action_command);
 		ast_manager_register_xml_core("ExtensionState", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING, action_extensionstate);
+		ast_manager_register_xml_core("PresenceState", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING, action_presencestate);
 		ast_manager_register_xml_core("AbsoluteTimeout", EVENT_FLAG_SYSTEM | EVENT_FLAG_CALL, action_timeout);
 		ast_manager_register_xml_core("MailboxStatus", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING, action_mailboxstatus);
 		ast_manager_register_xml_core("MailboxCount", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING, action_mailboxcount);




More information about the asterisk-commits mailing list