Debian Codegraph @

res/res_manager_presencestate.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2014, Digium, Inc.
5 *
6 * Mark Michelson <[email protected]>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19 /*** MODULEINFO
20 <support_level>core</support_level>
21 ***/
22
23 /*** DOCUMENTATION
24 <manager name="PresenceStateList" language="en_US">
25 <since>
26 <version>13.0.0</version>
27 </since>
28 <synopsis>
29 List the current known presence states.
30 </synopsis>
31 <syntax>
32 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
33 </syntax>
34 <description>
35 <para>This will list out all known presence states in a
36 sequence of <replaceable>PresenceStateChange</replaceable> events.
37 When finished, a <replaceable>PresenceStateListComplete</replaceable> event
38 will be emitted.</para>
39 </description>
40 <see-also>
41 <ref type="manager">PresenceState</ref>
42 <ref type="managerEvent">PresenceStatus</ref>
43 <ref type="function">PRESENCE_STATE</ref>
44 </see-also>
45 <responses>
46 <list-elements>
47 <xi:include xpointer="xpointer(/docs/managerEvent[@name='PresenceStateChange'])" />
48 </list-elements>
49 <managerEvent name="PresenceStateListComplete" language="en_US">
50 <managerEventInstance class="EVENT_FLAG_COMMAND">
51 <since>
52 <version>13.0.0</version>
53 </since>
54 <synopsis>
55 Indicates the end of the list the current known extension states.
56 </synopsis>
57 <syntax>
58 <parameter name="EventList">
59 <para>Conveys the status of the event list.</para>
60 </parameter>
61 <parameter name="ListItems">
62 <para>Conveys the number of statuses reported.</para>
63 </parameter>
64 </syntax>
65 </managerEventInstance>
66 </managerEvent>
67 </responses>
68 </manager>
69 ***/
70
71 #include "asterisk.h"
72 #include "asterisk/module.h"
73 #include "asterisk/manager.h"
74 #include "asterisk/stasis.h"
75 #include "asterisk/presencestate.h"
76
77 static struct stasis_forward *topic_forwarder;
78
79 static int action_presencestatelist(struct mansession *s, const struct message *m)
80 {
81 RAII_VAR(struct ao2_container *, presence_states, NULL, ao2_cleanup);
82 const char *action_id = astman_get_header(m, "ActionID");
83 struct stasis_message *msg;
84 struct ao2_iterator it_states;
85 int count = 0;
86
87 presence_states = stasis_cache_dump(ast_presence_state_cache(),
88 ast_presence_state_message_type());
89 if (!presence_states) {
90 astman_send_error(s, m, "Memory Allocation Failure");
91 return 0;
92 }
93
94 astman_send_listack(s, m, "Presence State Changes will follow", "start");
95
96 it_states = ao2_iterator_init(presence_states, 0);
97 for (; (msg = ao2_iterator_next(&it_states)); ao2_ref(msg, -1)) {
98 struct ast_manager_event_blob *blob = stasis_message_to_ami(msg);
99
100 if (!blob) {
101 continue;
102 }
103
104 count++;
105
106 astman_append(s, "Event: %s\r\n", blob->manager_event);
107 if (!ast_strlen_zero(action_id)) {
108 astman_append(s, "ActionID: %s\r\n", action_id);
109 }
110 astman_append(s, "%s\r\n", blob->extra_fields);
111 ao2_ref(blob, -1);
112 }
113 ao2_iterator_destroy(&it_states);
114
115 astman_send_list_complete_start(s, m, "PresenceStateListComplete", count);
116 astman_send_list_complete_end(s);
117
118 return 0;
119 }
120
121 static int unload_module(void)
122 {
123 ast_manager_unregister("PresenceStateList");
124 topic_forwarder = stasis_forward_cancel(topic_forwarder);
125 return 0;
126 }
127
128 static int load_module(void)
129 {
130 struct stasis_topic *manager_topic;
131
132 manager_topic = ast_manager_get_topic();
133 if (!manager_topic) {
134 return AST_MODULE_LOAD_DECLINE;
135 }
136 topic_forwarder = stasis_forward_all(ast_presence_state_topic_all(), manager_topic);
137 if (!topic_forwarder) {
138 return AST_MODULE_LOAD_DECLINE;
139 }
140
141 if (ast_manager_register_xml("PresenceStateList", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING,
142 action_presencestatelist)) {
143 topic_forwarder = stasis_forward_cancel(topic_forwarder);
144 return AST_MODULE_LOAD_DECLINE;
145 }
146
147 return AST_MODULE_LOAD_SUCCESS;
148 }
149
150 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Manager Presence State Topic Forwarder",
151 .support_level = AST_MODULE_SUPPORT_CORE,
152 .load = load_module,
153 .unload = unload_module,
154 .load_pri = AST_MODPRI_DEVSTATE_CONSUMER,
155 );