Replace functions which called once with their bodies
[pidgin-git.git] / libpurple / protocols / novell / nmconference.c
blobd5977388429da8fab75e7ba7e929aea9e69a0b24
1 /*
2 * nmconference.c
4 * Copyright (c) 2004 Novell, Inc. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
21 #include <string.h>
22 #include "nmconference.h"
24 static int conf_count = 0;
26 struct _NMConference
29 /* The conference identifier */
30 char *guid;
32 /* The list of participants for the conference */
33 GSList *participants;
35 /* Flags for the conference */
36 guint32 flags;
38 /* User defined data */
39 gpointer data;
41 /* Reference count for this object */
42 int ref_count;
47 /*******************************************************************************
48 * Conference API -- see header file for comments
49 ******************************************************************************/
51 NMConference *
52 nm_create_conference(const char *guid)
54 NMConference *conf = g_new0(NMConference, 1);
56 if (guid) {
57 conf->guid = g_strdup(guid);
58 } else {
59 conf->guid = g_strdup(BLANK_GUID);
61 conf->ref_count = 1;
63 purple_debug(PURPLE_DEBUG_INFO, "novell",
64 "Creating a conference %p, total=%d\n",
65 conf, conf_count++);
67 return conf;
70 void
71 nm_release_conference(NMConference * conference)
73 GSList *node;
75 g_return_if_fail(conference != NULL);
77 purple_debug(PURPLE_DEBUG_INFO, "novell",
78 "In release conference %p, refs=%d\n",
79 conference, conference->ref_count);
80 if (--conference->ref_count == 0) {
82 purple_debug(PURPLE_DEBUG_INFO, "novell",
83 "Releasing conference %p, total=%d\n",
84 conference, --conf_count);
86 g_free(conference->guid);
88 if (conference->participants) {
89 for (node = conference->participants; node; node = node->next) {
90 if (node->data) {
91 NMUserRecord *user_record = node->data;
93 nm_release_user_record(user_record);
94 node->data = NULL;
98 g_slist_free(conference->participants);
101 g_free(conference);
105 gboolean
106 nm_conference_is_instantiated(NMConference * conference)
108 if (conference == NULL)
109 return FALSE;
111 return (strncmp(conference->guid, BLANK_GUID, CONF_GUID_END) != 0);
115 nm_conference_get_participant_count(NMConference * conference)
117 if (conference == NULL)
118 return 0;
120 return g_slist_length(conference->participants);
123 NMUserRecord *
124 nm_conference_get_participant(NMConference * conference, int index)
126 if (conference == NULL)
127 return NULL;
129 return (NMUserRecord *) g_slist_nth_data(conference->participants, index);
132 void
133 nm_conference_add_participant(NMConference * conference,
134 NMUserRecord * user_record)
136 if (conference == NULL || user_record == NULL) {
137 return;
140 nm_user_record_add_ref(user_record);
141 conference->participants = g_slist_append(conference->participants, user_record);
144 void
145 nm_conference_remove_participant(NMConference * conference, const char *dn)
147 GSList *node, *element = NULL;
149 if (conference == NULL || dn == NULL) {
150 return;
153 for (node = conference->participants; node; node = node->next) {
154 NMUserRecord *user_record = node->data;
156 if (user_record) {
157 if (nm_utf8_str_equal(dn, nm_user_record_get_dn(user_record))) {
158 element = node;
159 break;
164 if (element) {
165 nm_release_user_record((NMUserRecord *) element->data);
166 element->data = NULL;
167 conference->participants =
168 g_slist_delete_link(conference->participants, element);
172 void
173 nm_conference_add_ref(NMConference * conference)
175 if (conference)
176 conference->ref_count++;
179 void
180 nm_conference_set_flags(NMConference * conference, guint32 flags)
182 if (conference) {
183 conference->flags = flags;
187 void
188 nm_conference_set_guid(NMConference * conference, const char *guid)
190 if (conference) {
192 /* Release memory for old guid */
193 g_free(conference->guid);
195 /* Set the new guid */
196 if (guid)
197 conference->guid = g_strdup(guid);
198 else
199 conference->guid = g_strdup(BLANK_GUID);
203 void
204 nm_conference_set_data(NMConference * conference, gpointer data)
206 if (conference == NULL)
207 return;
209 conference->data = data;
212 gpointer
213 nm_conference_get_data(NMConference * conference)
215 if (conference == NULL)
216 return NULL;
218 return conference->data;
221 const char *
222 nm_conference_get_guid(NMConference * conference)
224 if (conference == NULL)
225 return NULL;
227 return conference->guid;