1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
/*
* jingle-transport-iface.c - Source for GabbleJingleTransport interface
* Copyright (C) 2007-2008 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include "jingle-transport-iface.h"
#include <glib.h>
#include "connection.h"
#include "jingle-content.h"
#include "jingle-session.h"
GabbleJingleTransportIface *
gabble_jingle_transport_iface_new (GType type,
GabbleJingleContent *content,
const gchar *transport_ns)
{
g_return_val_if_fail (g_type_is_a (type, GABBLE_TYPE_JINGLE_TRANSPORT_IFACE),
NULL);
return g_object_new (type,
"content", content,
"transport-ns", transport_ns,
NULL);
}
void
gabble_jingle_transport_iface_parse_candidates (GabbleJingleTransportIface *self,
WockyNode *node, GError **error)
{
void (*virtual_method)(GabbleJingleTransportIface *,
WockyNode *, GError **) =
GABBLE_JINGLE_TRANSPORT_IFACE_GET_CLASS (self)->parse_candidates;
g_assert (virtual_method != NULL);
return virtual_method (self, node, error);
}
/* Takes in a list of slice-allocated JingleCandidate structs */
void
gabble_jingle_transport_iface_new_local_candidates (GabbleJingleTransportIface *self,
GList *candidates)
{
void (*virtual_method)(GabbleJingleTransportIface *,
GList *) =
GABBLE_JINGLE_TRANSPORT_IFACE_GET_CLASS (self)->new_local_candidates;
g_assert (virtual_method != NULL);
virtual_method (self, candidates);
}
/* Inserts candidates into the given <transport/> node, or equivalent, of a
* session-initiate, session-accept, content-add or content-accept action.
*/
void
gabble_jingle_transport_iface_inject_candidates (
GabbleJingleTransportIface *self,
WockyNode *transport_node)
{
void (*virtual_method)(GabbleJingleTransportIface *, WockyNode *) =
GABBLE_JINGLE_TRANSPORT_IFACE_GET_CLASS (self)->inject_candidates;
if (virtual_method != NULL)
virtual_method (self, transport_node);
}
/* Transmits outstanding or all candidates (if applicable and @all is set). */
void
gabble_jingle_transport_iface_send_candidates (
GabbleJingleTransportIface *self,
gboolean all)
{
void (*virtual_method) (GabbleJingleTransportIface *, gboolean) =
GABBLE_JINGLE_TRANSPORT_IFACE_GET_CLASS (self)->send_candidates;
if (virtual_method != NULL)
virtual_method (self, all);
}
/* Returns TRUE if and only if @self has enough candidates to inject into a
* {session,content}-accept, and is connected.
*/
gboolean
gabble_jingle_transport_iface_can_accept (GabbleJingleTransportIface *self)
{
JingleTransportState state;
gboolean (*m) (GabbleJingleTransportIface *) =
GABBLE_JINGLE_TRANSPORT_IFACE_GET_CLASS (self)->can_accept;
g_object_get (self, "state", &state, NULL);
if (state != JINGLE_TRANSPORT_STATE_CONNECTED)
return FALSE;
/* Only Raw UDP *needs* candidates in order to accept. */
if (m != NULL)
return m (self);
else
return TRUE;
}
GList *
gabble_jingle_transport_iface_get_remote_candidates (
GabbleJingleTransportIface *self)
{
GList * (*virtual_method)(GabbleJingleTransportIface *) =
GABBLE_JINGLE_TRANSPORT_IFACE_GET_CLASS (self)->get_remote_candidates;
g_assert (virtual_method != NULL);
return virtual_method (self);
}
GList *
gabble_jingle_transport_iface_get_local_candidates (
GabbleJingleTransportIface *self)
{
GList * (*virtual_method)(GabbleJingleTransportIface *) =
GABBLE_JINGLE_TRANSPORT_IFACE_GET_CLASS (self)->get_local_candidates;
g_assert (virtual_method != NULL);
return virtual_method (self);
}
gboolean
jingle_transport_get_credentials (GabbleJingleTransportIface *self,
gchar **ufrag, gchar **pwd)
{
GabbleJingleTransportIfaceClass *klass =
GABBLE_JINGLE_TRANSPORT_IFACE_GET_CLASS (self);
if (klass->get_credentials)
return klass->get_credentials (self, ufrag, pwd);
else
return FALSE;
}
JingleTransportType
gabble_jingle_transport_iface_get_transport_type (GabbleJingleTransportIface *self)
{
JingleTransportType (*virtual_method)(void) =
GABBLE_JINGLE_TRANSPORT_IFACE_GET_CLASS (self)->get_transport_type;
g_assert (virtual_method != NULL);
return virtual_method ();
}
static void
gabble_jingle_transport_iface_base_init (gpointer klass)
{
static gboolean initialized = FALSE;
if (!initialized)
{
GParamSpec *param_spec;
param_spec = g_param_spec_object (
"content",
"GabbleJingleContent object",
"Jingle content that's using this jingle transport object.",
GABBLE_TYPE_JINGLE_CONTENT,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB);
g_object_interface_install_property (klass, param_spec);
param_spec = g_param_spec_string (
"transport-ns",
"Transport namespace",
"Namespace identifying the transport type.",
NULL,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB);
g_object_interface_install_property (klass, param_spec);
param_spec = g_param_spec_uint (
"state",
"Connection state for the transport.",
"Enum specifying the connection state of the transport.",
JINGLE_TRANSPORT_STATE_DISCONNECTED,
JINGLE_TRANSPORT_STATE_CONNECTED,
JINGLE_TRANSPORT_STATE_DISCONNECTED,
G_PARAM_READWRITE |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB);
g_object_interface_install_property (klass, param_spec);
initialized = TRUE;
}
}
GType
gabble_jingle_transport_iface_get_type (void)
{
static GType type = 0;
if (type == 0) {
static const GTypeInfo info = {
sizeof (GabbleJingleTransportIfaceClass),
gabble_jingle_transport_iface_base_init, /* base_init */
NULL, /* base_finalize */
NULL, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL /* instance_init */
};
type = g_type_register_static (G_TYPE_INTERFACE, "GabbleJingleTransportIface",
&info, 0);
}
return type;
}
JingleCandidate *
jingle_candidate_new (JingleTransportProtocol protocol,
JingleCandidateType type, const gchar *id, int component,
const gchar *address, int port, int generation, int preference,
const gchar *username, const gchar *password, int network)
{
JingleCandidate *c = g_slice_new0 (JingleCandidate);
c->protocol = protocol;
c->type = type;
c->id = g_strdup (id);
c->address = g_strdup (address);
c->component = component;
c->port = port;
c->generation = generation;
c->preference = preference;
c->username = g_strdup (username);
c->password = g_strdup (password);
c->network = network;
return c;
}
void
jingle_candidate_free (JingleCandidate *c)
{
g_free (c->id);
g_free (c->address);
g_free (c->username);
g_free (c->password);
g_slice_free (JingleCandidate, c);
}
void
jingle_transport_free_candidates (GList *candidates)
{
while (candidates != NULL)
{
JingleCandidate *c = (JingleCandidate *) candidates->data;
jingle_candidate_free (c);
candidates = g_list_remove (candidates, c);
}
}
|