Sat, 12 Nov 2005 15:27:41 +0000
[gaim-migrate @ 14345]
One parts doxygen one parts whitespace
| 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 | ||
| 75 | gaim_debug(GAIM_DEBUG_INFO, "novell", | |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
76 | "In release conference %p, refs=%d\n", |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
77 | conference, conference->ref_count); |
| 8675 | 78 | if (conference != NULL && (--conference->ref_count == 0)) { |
| 79 | ||
| 80 | gaim_debug(GAIM_DEBUG_INFO, "novell", | |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
81 | "Releasing conference %p, total=%d\n", |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
82 | conference, --conf_count); |
| 8675 | 83 | |
| 84 | if (conference->guid) | |
| 85 | g_free(conference->guid); | |
| 86 | ||
| 87 | if (conference->participants) { | |
| 88 | for (node = conference->participants; node; node = node->next) { | |
| 89 | if (node->data) { | |
| 90 | NMUserRecord *user_record = node->data; | |
| 91 | ||
| 92 | nm_release_user_record(user_record); | |
| 93 | node->data = NULL; | |
| 94 | } | |
| 95 | } | |
| 96 | ||
| 97 | g_slist_free(conference->participants); | |
| 98 | } | |
| 99 | ||
| 100 | g_free(conference); | |
| 101 | } | |
| 102 | } | |
| 103 | ||
| 104 | gboolean | |
| 105 | nm_conference_is_instantiated(NMConference * conference) | |
| 106 | { | |
| 107 | if (conference == NULL) | |
| 108 | return FALSE; | |
| 109 | ||
| 110 | return (strncmp(conference->guid, BLANK_GUID, CONF_GUID_END) != 0); | |
| 111 | } | |
| 112 | ||
| 113 | int | |
| 114 | nm_conference_get_participant_count(NMConference * conference) | |
| 115 | { | |
| 116 | if (conference == NULL) | |
| 117 | return 0; | |
| 118 | ||
| 119 | return g_slist_length(conference->participants); | |
| 120 | } | |
| 121 | ||
| 122 | NMUserRecord * | |
| 123 | nm_conference_get_participant(NMConference * conference, int index) | |
| 124 | { | |
| 125 | if (conference == NULL) | |
| 126 | return NULL; | |
| 127 | ||
| 128 | return (NMUserRecord *) g_slist_nth_data(conference->participants, index); | |
| 129 | } | |
| 130 | ||
| 131 | void | |
| 132 | nm_conference_add_participant(NMConference * conference, | |
| 133 | NMUserRecord * user_record) | |
| 134 | { | |
| 135 | if (conference == NULL || user_record == NULL) { | |
| 136 | return; | |
| 137 | } | |
| 138 | ||
| 139 | nm_user_record_add_ref(user_record); | |
| 140 | conference->participants = g_slist_append(conference->participants, user_record); | |
| 141 | } | |
| 142 | ||
| 143 | void | |
| 144 | nm_conference_remove_participant(NMConference * conference, const char *dn) | |
| 145 | { | |
| 146 | GSList *node, *element = NULL; | |
| 147 | ||
| 148 | if (conference == NULL || dn == NULL) { | |
| 149 | return; | |
| 150 | } | |
| 151 | ||
| 152 | for (node = conference->participants; node; node = node->next) { | |
| 153 | NMUserRecord *user_record = node->data; | |
| 154 | ||
| 155 | if (user_record) { | |
| 156 | if (nm_utf8_str_equal(dn, nm_user_record_get_dn(user_record))) { | |
| 157 | element = node; | |
| 158 | break; | |
| 159 | } | |
| 160 | } | |
| 161 | } | |
| 162 | ||
| 163 | if (element) { | |
| 164 | nm_release_user_record((NMUserRecord *) element->data); | |
| 165 | element->data = NULL; | |
| 166 | conference->participants = | |
| 167 | g_slist_remove_link(conference->participants, element); | |
| 168 | g_slist_free_1(element); | |
| 169 | } | |
| 170 | } | |
| 171 | ||
| 172 | void | |
| 173 | nm_conference_add_ref(NMConference * conference) | |
| 174 | { | |
| 175 | if (conference) | |
| 176 | conference->ref_count++; | |
| 177 | } | |
| 178 | ||
| 179 | void | |
| 180 | nm_conference_set_flags(NMConference * conference, guint32 flags) | |
| 181 | { | |
| 182 | if (conference) { | |
| 183 | conference->flags = flags; | |
| 184 | } | |
| 185 | } | |
| 186 | ||
| 187 | void | |
| 188 | nm_conference_set_guid(NMConference * conference, const char *guid) | |
| 189 | { | |
| 190 | if (conference) { | |
| 191 | ||
| 192 | /* Release memory for old guid */ | |
| 193 | if (conference->guid) { | |
| 194 | g_free(conference->guid); | |
| 195 | } | |
| 196 | ||
| 197 | /* Set the new guid */ | |
| 198 | if (guid) | |
| 199 | conference->guid = g_strdup(guid); | |
| 200 | else | |
| 201 | conference->guid = g_strdup(BLANK_GUID); | |
| 202 | } | |
| 203 | } | |
| 204 | ||
| 205 | void | |
| 206 | nm_conference_set_data(NMConference * conference, gpointer data) | |
| 207 | { | |
| 208 | if (conference == NULL) | |
| 209 | return; | |
| 210 | ||
| 211 | conference->data = data; | |
| 212 | } | |
| 213 | ||
| 214 | gpointer | |
| 215 | nm_conference_get_data(NMConference * conference) | |
| 216 | { | |
| 217 | if (conference == NULL) | |
| 218 | return NULL; | |
| 219 | ||
| 220 | return conference->data; | |
| 221 | } | |
| 222 | ||
| 223 | const char * | |
| 224 | nm_conference_get_guid(NMConference * conference) | |
| 225 | { | |
| 226 | if (conference == NULL) | |
| 227 | return NULL; | |
| 228 | ||
| 229 | return conference->guid; | |
| 230 | } |