comparison src/protocols/novell/nmconference.c @ 8675:9ee2542d1104

[gaim-migrate @ 9428] A GroupWise plugin from Novell. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Sat, 17 Apr 2004 13:55:28 +0000
parents
children 046dd8ef2920
comparison
equal deleted inserted replaced
8674:8c7da2e36136 8675:9ee2542d1104
1 /*
2 * nmconference.c
3 *
4 * Copyright © 2004 Unpublished Work of Novell, Inc. All Rights Reserved.
5 *
6 * THIS WORK IS AN UNPUBLISHED WORK OF NOVELL, INC. NO PART OF THIS WORK MAY BE
7 * USED, PRACTICED, PERFORMED, COPIED, DISTRIBUTED, REVISED, MODIFIED,
8 * TRANSLATED, ABRIDGED, CONDENSED, EXPANDED, COLLECTED, COMPILED, LINKED,
9 * RECAST, TRANSFORMED OR ADAPTED WITHOUT THE PRIOR WRITTEN CONSENT OF NOVELL,
10 * INC. ANY USE OR EXPLOITATION OF THIS WORK WITHOUT AUTHORIZATION COULD SUBJECT
11 * THE PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY.
12 *
13 * AS BETWEEN [GAIM] AND NOVELL, NOVELL GRANTS [GAIM] THE RIGHT TO REPUBLISH
14 * THIS WORK UNDER THE GPL (GNU GENERAL PUBLIC LICENSE) WITH ALL RIGHTS AND
15 * LICENSES THEREUNDER. IF YOU HAVE RECEIVED THIS WORK DIRECTLY OR INDIRECTLY
16 * FROM [GAIM] AS PART OF SUCH A REPUBLICATION, YOU HAVE ALL RIGHTS AND LICENSES
17 * GRANTED BY [GAIM] UNDER THE GPL. IN CONNECTION WITH SUCH A REPUBLICATION, IF
18 * ANYTHING IN THIS NOTICE CONFLICTS WITH THE TERMS OF THE GPL, SUCH TERMS
19 * PREVAIL.
20 *
21 */
22
23 #include <string.h>
24 #include "nmconference.h"
25
26 static int conf_count = 0;
27
28 struct _NMConference
29 {
30
31 /* The conference identifier */
32 char *guid;
33
34 /* The list of participants for the conference */
35 GSList *participants;
36
37 /* Flags for the conference */
38 guint32 flags;
39
40 /* User defined data */
41 gpointer data;
42
43 /* Reference count for this object */
44 int ref_count;
45
46 };
47
48
49 /*******************************************************************************
50 * Conference API -- see header file for comments
51 ******************************************************************************/
52
53 NMConference *
54 nm_create_conference(const char *guid)
55 {
56 NMConference *conf = g_new0(NMConference, 1);
57
58 if (guid) {
59 conf->guid = g_strdup(guid);
60 } else {
61 conf->guid = g_strdup(BLANK_GUID);
62 }
63 conf->ref_count = 1;
64
65 gaim_debug(GAIM_DEBUG_INFO, "novell",
66 "Creating a conference 0x%x, total=%d\n",
67 (guint32) conf, conf_count++);
68
69 return conf;
70 }
71
72 void
73 nm_release_conference(NMConference * conference)
74 {
75 GSList *node;
76
77 gaim_debug(GAIM_DEBUG_INFO, "novell",
78 "In release conference 0x%x, refs=%d\n",
79 (guint32) conference, conference->ref_count);
80 if (conference != NULL && (--conference->ref_count == 0)) {
81
82 gaim_debug(GAIM_DEBUG_INFO, "novell",
83 "Releasing conference 0x%x, total=%d\n",
84 (guint32) conference, --conf_count);
85
86 if (conference->guid)
87 g_free(conference->guid);
88
89 if (conference->participants) {
90 for (node = conference->participants; node; node = node->next) {
91 if (node->data) {
92 NMUserRecord *user_record = node->data;
93
94 nm_release_user_record(user_record);
95 node->data = NULL;
96 }
97 }
98
99 g_slist_free(conference->participants);
100 }
101
102 g_free(conference);
103 }
104 }
105
106 gboolean
107 nm_conference_is_instantiated(NMConference * conference)
108 {
109 if (conference == NULL)
110 return FALSE;
111
112 return (strncmp(conference->guid, BLANK_GUID, CONF_GUID_END) != 0);
113 }
114
115 int
116 nm_conference_get_participant_count(NMConference * conference)
117 {
118 if (conference == NULL)
119 return 0;
120
121 return g_slist_length(conference->participants);
122 }
123
124 NMUserRecord *
125 nm_conference_get_participant(NMConference * conference, int index)
126 {
127 if (conference == NULL)
128 return NULL;
129
130 return (NMUserRecord *) g_slist_nth_data(conference->participants, index);
131 }
132
133 void
134 nm_conference_add_participant(NMConference * conference,
135 NMUserRecord * user_record)
136 {
137 if (conference == NULL || user_record == NULL) {
138 return;
139 }
140
141 nm_user_record_add_ref(user_record);
142 conference->participants = g_slist_append(conference->participants, user_record);
143 }
144
145 void
146 nm_conference_remove_participant(NMConference * conference, const char *dn)
147 {
148 GSList *node, *element = NULL;
149
150 if (conference == NULL || dn == NULL) {
151 return;
152 }
153
154 for (node = conference->participants; node; node = node->next) {
155 NMUserRecord *user_record = node->data;
156
157 if (user_record) {
158 if (nm_utf8_str_equal(dn, nm_user_record_get_dn(user_record))) {
159 element = node;
160 break;
161 }
162 }
163 }
164
165 if (element) {
166 nm_release_user_record((NMUserRecord *) element->data);
167 element->data = NULL;
168 conference->participants =
169 g_slist_remove_link(conference->participants, element);
170 g_slist_free_1(element);
171 }
172 }
173
174 void
175 nm_conference_add_ref(NMConference * conference)
176 {
177 if (conference)
178 conference->ref_count++;
179 }
180
181 void
182 nm_conference_set_flags(NMConference * conference, guint32 flags)
183 {
184 if (conference) {
185 conference->flags = flags;
186 }
187 }
188
189 void
190 nm_conference_set_guid(NMConference * conference, const char *guid)
191 {
192 if (conference) {
193
194 /* Release memory for old guid */
195 if (conference->guid) {
196 g_free(conference->guid);
197 }
198
199 /* Set the new guid */
200 if (guid)
201 conference->guid = g_strdup(guid);
202 else
203 conference->guid = g_strdup(BLANK_GUID);
204 }
205 }
206
207 void
208 nm_conference_set_data(NMConference * conference, gpointer data)
209 {
210 if (conference == NULL)
211 return;
212
213 conference->data = data;
214 }
215
216 gpointer
217 nm_conference_get_data(NMConference * conference)
218 {
219 if (conference == NULL)
220 return NULL;
221
222 return conference->data;
223 }
224
225 const char *
226 nm_conference_get_guid(NMConference * conference)
227 {
228 if (conference == NULL)
229 return NULL;
230
231 return conference->guid;
232 }