2 * @file candidate.c Candidate for Media API
8 * Purple is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
27 #include "candidate.h"
29 /** @copydoc _PurpleMediaCandidateClass */
30 typedef struct _PurpleMediaCandidateClass PurpleMediaCandidateClass
;
31 /** @copydoc _PurpleMediaCandidatePrivate */
32 typedef struct _PurpleMediaCandidatePrivate PurpleMediaCandidatePrivate
;
34 #define PURPLE_MEDIA_CANDIDATE_GET_PRIVATE(obj) \
35 (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
36 PURPLE_TYPE_MEDIA_CANDIDATE, \
37 PurpleMediaCandidatePrivate))
40 struct _PurpleMediaCandidateClass
42 GObjectClass parent_class
;
45 struct _PurpleMediaCandidate
50 G_DEFINE_TYPE(PurpleMediaCandidate
, purple_media_candidate
, G_TYPE_OBJECT
);
52 struct _PurpleMediaCandidatePrivate
60 PurpleMediaNetworkProtocol proto
;
62 PurpleMediaCandidateType type
;
85 purple_media_candidate_init(PurpleMediaCandidate
*info
)
87 PurpleMediaCandidatePrivate
*priv
=
88 PURPLE_MEDIA_CANDIDATE_GET_PRIVATE(info
);
89 priv
->foundation
= NULL
;
90 priv
->component_id
= 0;
94 priv
->proto
= PURPLE_MEDIA_NETWORK_PROTOCOL_UDP
;
96 priv
->type
= PURPLE_MEDIA_CANDIDATE_TYPE_HOST
;
97 priv
->username
= NULL
;
98 priv
->password
= NULL
;
103 purple_media_candidate_finalize(GObject
*info
)
105 PurpleMediaCandidatePrivate
*priv
=
106 PURPLE_MEDIA_CANDIDATE_GET_PRIVATE(info
);
108 g_free(priv
->foundation
);
110 g_free(priv
->base_ip
);
111 g_free(priv
->username
);
112 g_free(priv
->password
);
116 purple_media_candidate_set_property (GObject
*object
, guint prop_id
,
117 const GValue
*value
, GParamSpec
*pspec
)
119 PurpleMediaCandidatePrivate
*priv
;
120 g_return_if_fail(PURPLE_IS_MEDIA_CANDIDATE(object
));
122 priv
= PURPLE_MEDIA_CANDIDATE_GET_PRIVATE(object
);
125 case PROP_FOUNDATION
:
126 g_free(priv
->foundation
);
127 priv
->foundation
= g_value_dup_string(value
);
129 case PROP_COMPONENT_ID
:
130 priv
->component_id
= g_value_get_uint(value
);
134 priv
->ip
= g_value_dup_string(value
);
137 priv
->port
= g_value_get_uint(value
);
140 g_free(priv
->base_ip
);
141 priv
->base_ip
= g_value_dup_string(value
);
144 priv
->base_port
= g_value_get_uint(value
);
147 priv
->proto
= g_value_get_enum(value
);
150 priv
->priority
= g_value_get_uint(value
);
153 priv
->type
= g_value_get_enum(value
);
156 g_free(priv
->username
);
157 priv
->username
= g_value_dup_string(value
);
160 g_free(priv
->password
);
161 priv
->password
= g_value_dup_string(value
);
164 priv
->ttl
= g_value_get_uint(value
);
167 G_OBJECT_WARN_INVALID_PROPERTY_ID(
168 object
, prop_id
, pspec
);
174 purple_media_candidate_get_property (GObject
*object
, guint prop_id
,
175 GValue
*value
, GParamSpec
*pspec
)
177 PurpleMediaCandidatePrivate
*priv
;
178 g_return_if_fail(PURPLE_IS_MEDIA_CANDIDATE(object
));
180 priv
= PURPLE_MEDIA_CANDIDATE_GET_PRIVATE(object
);
183 case PROP_FOUNDATION
:
184 g_value_set_string(value
, priv
->foundation
);
186 case PROP_COMPONENT_ID
:
187 g_value_set_uint(value
, priv
->component_id
);
190 g_value_set_string(value
, priv
->ip
);
193 g_value_set_uint(value
, priv
->port
);
196 g_value_set_string(value
, priv
->base_ip
);
199 g_value_set_uint(value
, priv
->base_port
);
202 g_value_set_enum(value
, priv
->proto
);
205 g_value_set_uint(value
, priv
->priority
);
208 g_value_set_enum(value
, priv
->type
);
211 g_value_set_string(value
, priv
->username
);
214 g_value_set_string(value
, priv
->password
);
217 g_value_set_uint(value
, priv
->ttl
);
220 G_OBJECT_WARN_INVALID_PROPERTY_ID(
221 object
, prop_id
, pspec
);
227 purple_media_candidate_class_init(PurpleMediaCandidateClass
*klass
)
229 GObjectClass
*gobject_class
= (GObjectClass
*)klass
;
231 gobject_class
->finalize
= purple_media_candidate_finalize
;
232 gobject_class
->set_property
= purple_media_candidate_set_property
;
233 gobject_class
->get_property
= purple_media_candidate_get_property
;
235 g_object_class_install_property(gobject_class
, PROP_FOUNDATION
,
236 g_param_spec_string("foundation",
238 "The foundation of the candidate.",
242 g_object_class_install_property(gobject_class
, PROP_COMPONENT_ID
,
243 g_param_spec_uint("component-id",
245 "The component id of the candidate.",
249 g_object_class_install_property(gobject_class
, PROP_IP
,
250 g_param_spec_string("ip",
252 "The IP address of the candidate.",
256 g_object_class_install_property(gobject_class
, PROP_PORT
,
257 g_param_spec_uint("port",
259 "The port of the candidate.",
263 g_object_class_install_property(gobject_class
, PROP_BASE_IP
,
264 g_param_spec_string("base-ip",
266 "The internal IP address of the candidate.",
270 g_object_class_install_property(gobject_class
, PROP_BASE_PORT
,
271 g_param_spec_uint("base-port",
273 "The internal port of the candidate.",
277 g_object_class_install_property(gobject_class
, PROP_PROTOCOL
,
278 g_param_spec_enum("protocol",
280 "The protocol of the candidate.",
281 PURPLE_TYPE_MEDIA_NETWORK_PROTOCOL
,
282 PURPLE_MEDIA_NETWORK_PROTOCOL_UDP
,
285 g_object_class_install_property(gobject_class
, PROP_PRIORITY
,
286 g_param_spec_uint("priority",
288 "The priority of the candidate.",
292 g_object_class_install_property(gobject_class
, PROP_TYPE
,
293 g_param_spec_enum("type",
295 "The type of the candidate.",
296 PURPLE_TYPE_MEDIA_CANDIDATE_TYPE
,
297 PURPLE_MEDIA_CANDIDATE_TYPE_HOST
,
300 g_object_class_install_property(gobject_class
, PROP_USERNAME
,
301 g_param_spec_string("username",
303 "The username used to connect to the candidate.",
307 g_object_class_install_property(gobject_class
, PROP_PASSWORD
,
308 g_param_spec_string("password",
310 "The password use to connect to the candidate.",
314 g_object_class_install_property(gobject_class
, PROP_TTL
,
315 g_param_spec_uint("ttl",
317 "The TTL of the candidate.",
321 g_type_class_add_private(klass
, sizeof(PurpleMediaCandidatePrivate
));
324 PurpleMediaCandidate
*
325 purple_media_candidate_new(const gchar
*foundation
, guint component_id
,
326 PurpleMediaCandidateType type
,
327 PurpleMediaNetworkProtocol proto
,
328 const gchar
*ip
, guint port
)
330 return g_object_new(PURPLE_TYPE_MEDIA_CANDIDATE
,
331 "foundation", foundation
,
332 "component-id", component_id
,
339 PurpleMediaCandidate
*
340 purple_media_candidate_copy(PurpleMediaCandidate
*candidate
)
342 PurpleMediaCandidatePrivate
*priv
;
343 PurpleMediaCandidate
*new_candidate
;
345 if (candidate
== NULL
)
348 priv
= PURPLE_MEDIA_CANDIDATE_GET_PRIVATE(candidate
);
350 new_candidate
= purple_media_candidate_new(priv
->foundation
,
351 priv
->component_id
, priv
->type
, priv
->proto
,
352 priv
->ip
, priv
->port
);
353 g_object_set(new_candidate
,
354 "base-ip", priv
->base_ip
,
355 "base-port", priv
->base_port
,
356 "priority", priv
->priority
,
357 "username", priv
->username
,
358 "password", priv
->password
,
359 "ttl", priv
->ttl
, NULL
);
360 return new_candidate
;
364 purple_media_candidate_list_copy(GList
*candidates
)
366 GList
*new_list
= NULL
;
368 for (; candidates
; candidates
= g_list_next(candidates
)) {
369 new_list
= g_list_prepend(new_list
,
370 purple_media_candidate_copy(candidates
->data
));
373 new_list
= g_list_reverse(new_list
);
378 purple_media_candidate_list_free(GList
*candidates
)
380 for (; candidates
; candidates
=
381 g_list_delete_link(candidates
, candidates
)) {
382 g_object_unref(candidates
->data
);
387 purple_media_candidate_get_foundation(PurpleMediaCandidate
*candidate
)
390 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), NULL
);
391 g_object_get(candidate
, "foundation", &foundation
, NULL
);
396 purple_media_candidate_get_component_id(PurpleMediaCandidate
*candidate
)
399 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), 0);
400 g_object_get(candidate
, "component-id", &component_id
, NULL
);
405 purple_media_candidate_get_ip(PurpleMediaCandidate
*candidate
)
408 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), NULL
);
409 g_object_get(candidate
, "ip", &ip
, NULL
);
414 purple_media_candidate_get_port(PurpleMediaCandidate
*candidate
)
417 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), 0);
418 g_object_get(candidate
, "port", &port
, NULL
);
423 purple_media_candidate_get_base_ip(PurpleMediaCandidate
*candidate
)
426 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), NULL
);
427 g_object_get(candidate
, "base-ip", &base_ip
, NULL
);
432 purple_media_candidate_get_base_port(PurpleMediaCandidate
*candidate
)
435 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), 0);
436 g_object_get(candidate
, "base_port", &base_port
, NULL
);
440 PurpleMediaNetworkProtocol
441 purple_media_candidate_get_protocol(PurpleMediaCandidate
*candidate
)
443 PurpleMediaNetworkProtocol protocol
;
444 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
),
445 PURPLE_MEDIA_NETWORK_PROTOCOL_UDP
);
446 g_object_get(candidate
, "protocol", &protocol
, NULL
);
451 purple_media_candidate_get_priority(PurpleMediaCandidate
*candidate
)
454 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), 0);
455 g_object_get(candidate
, "priority", &priority
, NULL
);
459 PurpleMediaCandidateType
460 purple_media_candidate_get_candidate_type(PurpleMediaCandidate
*candidate
)
462 PurpleMediaCandidateType type
;
463 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
),
464 PURPLE_MEDIA_CANDIDATE_TYPE_HOST
);
465 g_object_get(candidate
, "type", &type
, NULL
);
470 purple_media_candidate_get_username(PurpleMediaCandidate
*candidate
)
473 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), NULL
);
474 g_object_get(candidate
, "username", &username
, NULL
);
479 purple_media_candidate_get_password(PurpleMediaCandidate
*candidate
)
482 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), NULL
);
483 g_object_get(candidate
, "password", &password
, NULL
);
488 purple_media_candidate_get_ttl(PurpleMediaCandidate
*candidate
)
491 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), 0);
492 g_object_get(candidate
, "ttl", &ttl
, NULL
);