mark PurpleImageClass as private
[pidgin-git.git] / libpurple / protocols / novell / nmconference.c
blob7fc024b7c0a66d450ec051cbf13046117aa87f5a
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_remove_link(conference->participants, element);
169 g_slist_free_1(element);
173 void
174 nm_conference_add_ref(NMConference * conference)
176 if (conference)
177 conference->ref_count++;
180 void
181 nm_conference_set_flags(NMConference * conference, guint32 flags)
183 if (conference) {
184 conference->flags = flags;
188 void
189 nm_conference_set_guid(NMConference * conference, const char *guid)
191 if (conference) {
193 /* Release memory for old guid */
194 g_free(conference->guid);
196 /* Set the new guid */
197 if (guid)
198 conference->guid = g_strdup(guid);
199 else
200 conference->guid = g_strdup(BLANK_GUID);
204 void
205 nm_conference_set_data(NMConference * conference, gpointer data)
207 if (conference == NULL)
208 return;
210 conference->data = data;
213 gpointer
214 nm_conference_get_data(NMConference * conference)
216 if (conference == NULL)
217 return NULL;
219 return conference->data;
222 const char *
223 nm_conference_get_guid(NMConference * conference)
225 if (conference == NULL)
226 return NULL;
228 return conference->guid;