1 /* Copyright (C) 2009-2010, Martin Johansson <martin@fatbob.nu>
2 Copyright (C) 2005-2010, Thorvald Natvig <thorvald@natvig.com>
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
10 - Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 - Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
15 - Neither the name of the Developers nor the names of its contributors may
16 be used to endorse or promote products derived from this software without
17 specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "voicetarget.h"
35 void Voicetarget_add_session(client_t *client, int targetId, int sessionId)
40 list_iterate(itr, &client->voicetargets) {
41 if (targetId == list_get_entry(itr, voicetarget_t, node)->id) {
43 vt = list_get_entry(itr, voicetarget_t, node);
44 for (i = 0; i < TARGET_MAX_SESSIONS; i++) {
45 if (vt->sessions[i] == -1) {
46 vt->sessions[i] = sessionId;
47 Log_debug("Adding session ID %d to voicetarget ID %d", sessionId, targetId);
55 void Voicetarget_add_channel(client_t *client, int targetId, int channelId,
56 bool_t linked, bool_t children)
61 list_iterate(itr, &client->voicetargets) {
62 if (targetId == list_get_entry(itr, voicetarget_t, node)->id) {
64 vt = list_get_entry(itr, voicetarget_t, node);
65 for (i = 0; i < TARGET_MAX_CHANNELS; i++) {
66 if (vt->channels[i].channel == -1) {
67 vt->channels[i].channel = channelId;
68 vt->channels[i].linked = linked;
69 vt->channels[i].children = children;
70 Log_debug("Adding channel ID %d to voicetarget ID %d", channelId, targetId);
78 void Voicetarget_add_id(client_t *client, int targetId)
80 voicetarget_t *newtarget;
83 Voicetarget_del_id(client, targetId);
84 newtarget = malloc(sizeof(voicetarget_t));
86 Log_fatal("Out of memory");
87 memset(newtarget, 0, sizeof(voicetarget_t));
88 for (i = 0; i < TARGET_MAX_CHANNELS; i++)
89 newtarget->channels[i].channel = -1;
90 for (i = 0; i < TARGET_MAX_SESSIONS; i++)
91 newtarget->sessions[i] = -1;
92 newtarget->id = targetId;
93 list_add_tail(&newtarget->node, &client->voicetargets);
96 void Voicetarget_del_id(client_t *client, int targetId)
99 list_iterate(itr, &client->voicetargets) {
100 if (targetId == list_get_entry(itr, voicetarget_t, node)->id) {
101 list_del(&list_get_entry(itr, voicetarget_t, node)->node);
102 free(list_get_entry(itr, voicetarget_t, node));
103 Log_debug("Removing voicetarget ID %d", targetId);
108 voicetarget_t *Voicetarget_get_id(client_t *client, int targetId)
111 list_iterate(itr, &client->voicetargets) {
112 if (targetId == list_get_entry(itr, voicetarget_t, node)->id) {
113 return list_get_entry(itr, voicetarget_t, node);
120 void Voicetarget_free_all(client_t *client)
122 struct dlist *itr, *save;
124 list_iterate_safe(itr, save, &client->voicetargets) {
125 list_del(&list_get_entry(itr, voicetarget_t, node)->node);
126 free(list_get_entry(itr, voicetarget_t, node));