Wed, 12 Nov 2008 05:14:03 +0000
merge of '77693555855fe9cd3215414f79964dba346cc5fa'
and '19a87e98e5857ad0289f2c760d460f7f1dbbb42d'
| 8675 | 1 | /* |
| 2 | * nmconference.c | |
| 3 | * | |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
4 | * Copyright (c) 2004 Novell, Inc. All Rights Reserved. |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
5 | * |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
6 | * This program is free software; you can redistribute it and/or modify |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
7 | * it under the terms of the GNU General Public License as published by |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
8 | * the Free Software Foundation; version 2 of the License. |
| 8675 | 9 | * |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
13 | * GNU General Public License for more details. |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
14 | * |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
16 | * along with this program; if not, write to the Free Software |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 8675 | 18 | * |
| 19 | */ | |
| 20 | ||
| 21 | #include <string.h> | |
| 22 | #include "nmconference.h" | |
| 23 | ||
| 24 | static int conf_count = 0; | |
| 25 | ||
| 26 | struct _NMConference | |
| 27 | { | |
| 28 | ||
| 29 | /* The conference identifier */ | |
| 30 | char *guid; | |
| 31 | ||
| 32 | /* The list of participants for the conference */ | |
| 33 | GSList *participants; | |
| 34 | ||
| 35 | /* Flags for the conference */ | |
| 36 | guint32 flags; | |
| 37 | ||
| 38 | /* User defined data */ | |
| 39 | gpointer data; | |
| 40 | ||
| 41 | /* Reference count for this object */ | |
| 42 | int ref_count; | |
| 43 | ||
| 44 | }; | |
| 45 | ||
| 46 | ||
| 47 | /******************************************************************************* | |
| 48 | * Conference API -- see header file for comments | |
| 49 | ******************************************************************************/ | |
| 50 | ||
| 51 | NMConference * | |
| 52 | nm_create_conference(const char *guid) | |
| 53 | { | |
| 54 | NMConference *conf = g_new0(NMConference, 1); | |
| 55 | ||
| 56 | if (guid) { | |
| 57 | conf->guid = g_strdup(guid); | |
| 58 | } else { | |
| 59 | conf->guid = g_strdup(BLANK_GUID); | |
| 60 | } | |
| 61 | conf->ref_count = 1; | |
| 62 | ||
| 63 | gaim_debug(GAIM_DEBUG_INFO, "novell", | |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
64 | "Creating a conference %p, total=%d\n", |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
65 | conf, conf_count++); |
| 8675 | 66 | |
| 67 | return conf; | |
| 68 | } | |
| 69 | ||
| 70 | void | |
| 71 | nm_release_conference(NMConference * conference) | |
| 72 | { | |
| 73 | GSList *node; | |
| 74 | ||
| 13440 | 75 | g_return_if_fail(conference != NULL); |
| 76 | ||
| 8675 | 77 | gaim_debug(GAIM_DEBUG_INFO, "novell", |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
78 | "In release conference %p, refs=%d\n", |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
79 | conference, conference->ref_count); |
| 13440 | 80 | if (--conference->ref_count == 0) { |
| 8675 | 81 | |
| 82 | gaim_debug(GAIM_DEBUG_INFO, "novell", | |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
83 | "Releasing conference %p, total=%d\n", |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
84 | conference, --conf_count); |
| 8675 | 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 | } |