3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #include "candidate.h"
25 * PurpleMediaCandidate:
27 * An opaque structure representing a network candidate (IP Address and port
30 struct _PurpleMediaCandidate
43 PurpleMediaNetworkProtocol proto
;
45 PurpleMediaCandidateType type
;
49 } PurpleMediaCandidatePrivate
;
67 G_DEFINE_TYPE_WITH_PRIVATE(PurpleMediaCandidate
, purple_media_candidate
,
71 purple_media_candidate_init(PurpleMediaCandidate
*info
)
73 PurpleMediaCandidatePrivate
*priv
=
74 purple_media_candidate_get_instance_private(info
);
75 priv
->foundation
= NULL
;
76 priv
->component_id
= 0;
80 priv
->proto
= PURPLE_MEDIA_NETWORK_PROTOCOL_UDP
;
82 priv
->type
= PURPLE_MEDIA_CANDIDATE_TYPE_HOST
;
83 priv
->username
= NULL
;
84 priv
->password
= NULL
;
89 purple_media_candidate_finalize(GObject
*info
)
91 PurpleMediaCandidatePrivate
*priv
=
92 purple_media_candidate_get_instance_private(
93 PURPLE_MEDIA_CANDIDATE(info
));
95 g_free(priv
->foundation
);
97 g_free(priv
->base_ip
);
98 g_free(priv
->username
);
99 g_free(priv
->password
);
101 G_OBJECT_CLASS(purple_media_candidate_parent_class
)->finalize(info
);
105 purple_media_candidate_set_property (GObject
*object
, guint prop_id
,
106 const GValue
*value
, GParamSpec
*pspec
)
108 PurpleMediaCandidatePrivate
*priv
;
109 g_return_if_fail(PURPLE_IS_MEDIA_CANDIDATE(object
));
111 priv
= purple_media_candidate_get_instance_private(
112 PURPLE_MEDIA_CANDIDATE(object
));
115 case PROP_FOUNDATION
:
116 g_free(priv
->foundation
);
117 priv
->foundation
= g_value_dup_string(value
);
119 case PROP_COMPONENT_ID
:
120 priv
->component_id
= g_value_get_uint(value
);
124 priv
->ip
= g_value_dup_string(value
);
127 priv
->port
= g_value_get_uint(value
);
130 g_free(priv
->base_ip
);
131 priv
->base_ip
= g_value_dup_string(value
);
134 priv
->base_port
= g_value_get_uint(value
);
137 priv
->proto
= g_value_get_enum(value
);
140 priv
->priority
= g_value_get_uint(value
);
143 priv
->type
= g_value_get_enum(value
);
146 g_free(priv
->username
);
147 priv
->username
= g_value_dup_string(value
);
150 g_free(priv
->password
);
151 priv
->password
= g_value_dup_string(value
);
154 priv
->ttl
= g_value_get_uint(value
);
157 G_OBJECT_WARN_INVALID_PROPERTY_ID(
158 object
, prop_id
, pspec
);
164 purple_media_candidate_get_property (GObject
*object
, guint prop_id
,
165 GValue
*value
, GParamSpec
*pspec
)
167 PurpleMediaCandidatePrivate
*priv
;
168 g_return_if_fail(PURPLE_IS_MEDIA_CANDIDATE(object
));
170 priv
= purple_media_candidate_get_instance_private(
171 PURPLE_MEDIA_CANDIDATE(object
));
174 case PROP_FOUNDATION
:
175 g_value_set_string(value
, priv
->foundation
);
177 case PROP_COMPONENT_ID
:
178 g_value_set_uint(value
, priv
->component_id
);
181 g_value_set_string(value
, priv
->ip
);
184 g_value_set_uint(value
, priv
->port
);
187 g_value_set_string(value
, priv
->base_ip
);
190 g_value_set_uint(value
, priv
->base_port
);
193 g_value_set_enum(value
, priv
->proto
);
196 g_value_set_uint(value
, priv
->priority
);
199 g_value_set_enum(value
, priv
->type
);
202 g_value_set_string(value
, priv
->username
);
205 g_value_set_string(value
, priv
->password
);
208 g_value_set_uint(value
, priv
->ttl
);
211 G_OBJECT_WARN_INVALID_PROPERTY_ID(
212 object
, prop_id
, pspec
);
218 purple_media_candidate_class_init(PurpleMediaCandidateClass
*klass
)
220 GObjectClass
*gobject_class
= (GObjectClass
*)klass
;
222 gobject_class
->finalize
= purple_media_candidate_finalize
;
223 gobject_class
->set_property
= purple_media_candidate_set_property
;
224 gobject_class
->get_property
= purple_media_candidate_get_property
;
226 g_object_class_install_property(gobject_class
, PROP_FOUNDATION
,
227 g_param_spec_string("foundation",
229 "The foundation of the candidate.",
231 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
));
233 g_object_class_install_property(gobject_class
, PROP_COMPONENT_ID
,
234 g_param_spec_uint("component-id",
236 "The component id of the candidate.",
238 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
));
240 g_object_class_install_property(gobject_class
, PROP_IP
,
241 g_param_spec_string("ip",
243 "The IP address of the candidate.",
245 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
));
247 g_object_class_install_property(gobject_class
, PROP_PORT
,
248 g_param_spec_uint("port",
250 "The port of the candidate.",
252 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
));
254 g_object_class_install_property(gobject_class
, PROP_BASE_IP
,
255 g_param_spec_string("base-ip",
257 "The internal IP address of the candidate.",
259 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
));
261 g_object_class_install_property(gobject_class
, PROP_BASE_PORT
,
262 g_param_spec_uint("base-port",
264 "The internal port of the candidate.",
266 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
));
268 g_object_class_install_property(gobject_class
, PROP_PROTOCOL
,
269 g_param_spec_enum("protocol",
271 "The protocol of the candidate.",
272 PURPLE_TYPE_MEDIA_NETWORK_PROTOCOL
,
273 PURPLE_MEDIA_NETWORK_PROTOCOL_UDP
,
274 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
));
276 g_object_class_install_property(gobject_class
, PROP_PRIORITY
,
277 g_param_spec_uint("priority",
279 "The priority of the candidate.",
281 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
));
283 g_object_class_install_property(gobject_class
, PROP_TYPE
,
284 g_param_spec_enum("type",
286 "The type of the candidate.",
287 PURPLE_TYPE_MEDIA_CANDIDATE_TYPE
,
288 PURPLE_MEDIA_CANDIDATE_TYPE_HOST
,
289 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
));
291 g_object_class_install_property(gobject_class
, PROP_USERNAME
,
292 g_param_spec_string("username",
294 "The username used to connect to the candidate.",
296 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
));
298 g_object_class_install_property(gobject_class
, PROP_PASSWORD
,
299 g_param_spec_string("password",
301 "The password use to connect to the candidate.",
303 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
));
305 g_object_class_install_property(gobject_class
, PROP_TTL
,
306 g_param_spec_uint("ttl",
308 "The TTL of the candidate.",
310 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
));
313 PurpleMediaCandidate
*
314 purple_media_candidate_new(const gchar
*foundation
, guint component_id
,
315 PurpleMediaCandidateType type
,
316 PurpleMediaNetworkProtocol proto
,
317 const gchar
*ip
, guint port
)
319 return g_object_new(PURPLE_TYPE_MEDIA_CANDIDATE
,
320 "foundation", foundation
,
321 "component-id", component_id
,
328 PurpleMediaCandidate
*
329 purple_media_candidate_copy(PurpleMediaCandidate
*candidate
)
331 PurpleMediaCandidatePrivate
*priv
;
332 PurpleMediaCandidate
*new_candidate
;
334 if (candidate
== NULL
)
337 priv
= purple_media_candidate_get_instance_private(candidate
);
339 new_candidate
= purple_media_candidate_new(priv
->foundation
,
340 priv
->component_id
, priv
->type
, priv
->proto
,
341 priv
->ip
, priv
->port
);
342 g_object_set(new_candidate
,
343 "base-ip", priv
->base_ip
,
344 "base-port", priv
->base_port
,
345 "priority", priv
->priority
,
346 "username", priv
->username
,
347 "password", priv
->password
,
348 "ttl", priv
->ttl
, NULL
);
349 return new_candidate
;
353 purple_media_candidate_list_copy(GList
*candidates
)
355 GList
*new_list
= NULL
;
357 for (; candidates
; candidates
= g_list_next(candidates
)) {
358 new_list
= g_list_prepend(new_list
,
359 purple_media_candidate_copy(candidates
->data
));
362 new_list
= g_list_reverse(new_list
);
367 purple_media_candidate_list_free(GList
*candidates
)
369 g_list_free_full(candidates
, g_object_unref
);
373 purple_media_candidate_get_foundation(PurpleMediaCandidate
*candidate
)
376 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), NULL
);
377 g_object_get(candidate
, "foundation", &foundation
, NULL
);
382 purple_media_candidate_get_component_id(PurpleMediaCandidate
*candidate
)
385 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), 0);
386 g_object_get(candidate
, "component-id", &component_id
, NULL
);
391 purple_media_candidate_get_ip(PurpleMediaCandidate
*candidate
)
394 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), NULL
);
395 g_object_get(candidate
, "ip", &ip
, NULL
);
400 purple_media_candidate_get_port(PurpleMediaCandidate
*candidate
)
403 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), 0);
404 g_object_get(candidate
, "port", &port
, NULL
);
409 purple_media_candidate_get_base_ip(PurpleMediaCandidate
*candidate
)
412 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), NULL
);
413 g_object_get(candidate
, "base-ip", &base_ip
, NULL
);
418 purple_media_candidate_get_base_port(PurpleMediaCandidate
*candidate
)
421 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), 0);
422 g_object_get(candidate
, "base_port", &base_port
, NULL
);
426 PurpleMediaNetworkProtocol
427 purple_media_candidate_get_protocol(PurpleMediaCandidate
*candidate
)
429 PurpleMediaNetworkProtocol protocol
;
430 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
),
431 PURPLE_MEDIA_NETWORK_PROTOCOL_UDP
);
432 g_object_get(candidate
, "protocol", &protocol
, NULL
);
437 purple_media_candidate_get_priority(PurpleMediaCandidate
*candidate
)
440 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), 0);
441 g_object_get(candidate
, "priority", &priority
, NULL
);
445 PurpleMediaCandidateType
446 purple_media_candidate_get_candidate_type(PurpleMediaCandidate
*candidate
)
448 PurpleMediaCandidateType type
;
449 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
),
450 PURPLE_MEDIA_CANDIDATE_TYPE_HOST
);
451 g_object_get(candidate
, "type", &type
, NULL
);
456 purple_media_candidate_get_username(PurpleMediaCandidate
*candidate
)
459 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), NULL
);
460 g_object_get(candidate
, "username", &username
, NULL
);
465 purple_media_candidate_get_password(PurpleMediaCandidate
*candidate
)
468 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), NULL
);
469 g_object_get(candidate
, "password", &password
, NULL
);
474 purple_media_candidate_get_ttl(PurpleMediaCandidate
*candidate
)
477 g_return_val_if_fail(PURPLE_IS_MEDIA_CANDIDATE(candidate
), 0);
478 g_object_get(candidate
, "ttl", &ttl
, NULL
);