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
22 #include "nmconference.h"
24 static int conf_count
= 0;
29 /* The conference identifier */
32 /* The list of participants for the conference */
35 /* Flags for the conference */
38 /* User defined data */
41 /* Reference count for this object */
47 /*******************************************************************************
48 * Conference API -- see header file for comments
49 ******************************************************************************/
52 nm_create_conference(const char *guid
)
54 NMConference
*conf
= g_new0(NMConference
, 1);
57 conf
->guid
= g_strdup(guid
);
59 conf
->guid
= g_strdup(BLANK_GUID
);
63 purple_debug(PURPLE_DEBUG_INFO
, "novell",
64 "Creating a conference %p, total=%d\n",
71 nm_release_conference(NMConference
* conference
)
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
) {
91 NMUserRecord
*user_record
= node
->data
;
93 nm_release_user_record(user_record
);
98 g_slist_free(conference
->participants
);
106 nm_conference_is_instantiated(NMConference
* conference
)
108 if (conference
== NULL
)
111 return (strncmp(conference
->guid
, BLANK_GUID
, CONF_GUID_END
) != 0);
115 nm_conference_get_participant_count(NMConference
* conference
)
117 if (conference
== NULL
)
120 return g_slist_length(conference
->participants
);
124 nm_conference_get_participant(NMConference
* conference
, int index
)
126 if (conference
== NULL
)
129 return (NMUserRecord
*) g_slist_nth_data(conference
->participants
, index
);
133 nm_conference_add_participant(NMConference
* conference
,
134 NMUserRecord
* user_record
)
136 if (conference
== NULL
|| user_record
== NULL
) {
140 nm_user_record_add_ref(user_record
);
141 conference
->participants
= g_slist_append(conference
->participants
, user_record
);
145 nm_conference_remove_participant(NMConference
* conference
, const char *dn
)
147 GSList
*node
, *element
= NULL
;
149 if (conference
== NULL
|| dn
== NULL
) {
153 for (node
= conference
->participants
; node
; node
= node
->next
) {
154 NMUserRecord
*user_record
= node
->data
;
157 if (nm_utf8_str_equal(dn
, nm_user_record_get_dn(user_record
))) {
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
);
174 nm_conference_add_ref(NMConference
* conference
)
177 conference
->ref_count
++;
181 nm_conference_set_flags(NMConference
* conference
, guint32 flags
)
184 conference
->flags
= flags
;
189 nm_conference_set_guid(NMConference
* conference
, const char *guid
)
193 /* Release memory for old guid */
194 g_free(conference
->guid
);
196 /* Set the new guid */
198 conference
->guid
= g_strdup(guid
);
200 conference
->guid
= g_strdup(BLANK_GUID
);
205 nm_conference_set_data(NMConference
* conference
, gpointer data
)
207 if (conference
== NULL
)
210 conference
->data
= data
;
214 nm_conference_get_data(NMConference
* conference
)
216 if (conference
== NULL
)
219 return conference
->data
;
223 nm_conference_get_guid(NMConference
* conference
)
225 if (conference
== NULL
)
228 return conference
->guid
;