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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.impl.protocol.jabber.extensions.jingle;
import net.java.sip.communicator.impl.protocol.jabber.extensions.*;
import net.java.sip.communicator.impl.protocol.jabber.extensions.jitsimeet.*;
import net.java.sip.communicator.service.protocol.jabber.*;
import org.jivesoftware.smack.provider.*;
import org.xmlpull.v1.*;
/**
* An implementation of a Jingle IQ provider that parses incoming Jingle IQs.
*
* @author Emil Ivov
*/
public class JingleIQProvider implements IQProvider
{
/**
* Creates a new instance of the <tt>JingleIQProvider</tt> and register all
* jingle related extension providers. It is the responsibility of the
* application to register the <tt>JingleIQProvider</tt> itself.
*/
public JingleIQProvider()
{
AbstractSmackInteroperabilityLayer smackInteroperabilityLayer =
AbstractSmackInteroperabilityLayer.getInstance();
//<description/> provider
smackInteroperabilityLayer.addExtensionProvider(
RtpDescriptionPacketExtension.ELEMENT_NAME,
RtpDescriptionPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider
<RtpDescriptionPacketExtension>(
RtpDescriptionPacketExtension.class));
//<payload-type/> provider
smackInteroperabilityLayer.addExtensionProvider(
PayloadTypePacketExtension.ELEMENT_NAME,
RtpDescriptionPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider
<PayloadTypePacketExtension>(
PayloadTypePacketExtension.class));
//<parameter/> provider
smackInteroperabilityLayer.addExtensionProvider(
ParameterPacketExtension.ELEMENT_NAME,
RtpDescriptionPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider
<ParameterPacketExtension>
(ParameterPacketExtension.class));
//<rtp-hdrext/> provider
smackInteroperabilityLayer.addExtensionProvider(
RTPHdrExtPacketExtension.ELEMENT_NAME,
RTPHdrExtPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider
<RTPHdrExtPacketExtension>
(RTPHdrExtPacketExtension.class));
// <sctpmap/> provider
smackInteroperabilityLayer.addExtensionProvider(
SctpMapExtension.ELEMENT_NAME,
SctpMapExtension.NAMESPACE,
new SctpMapExtensionProvider());
//<encryption/> provider
smackInteroperabilityLayer.addExtensionProvider(
EncryptionPacketExtension.ELEMENT_NAME,
RtpDescriptionPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider
<EncryptionPacketExtension>
(EncryptionPacketExtension.class));
//<zrtp-hash/> provider
smackInteroperabilityLayer.addExtensionProvider(
ZrtpHashPacketExtension.ELEMENT_NAME,
ZrtpHashPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider
<ZrtpHashPacketExtension>
(ZrtpHashPacketExtension.class));
//<crypto/> provider
smackInteroperabilityLayer.addExtensionProvider(
CryptoPacketExtension.ELEMENT_NAME,
RtpDescriptionPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider
<CryptoPacketExtension>
(CryptoPacketExtension.class));
// <bundle/> provider
smackInteroperabilityLayer.addExtensionProvider(
BundlePacketExtension.ELEMENT_NAME,
BundlePacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider
<BundlePacketExtension>
(BundlePacketExtension.class));
// <group/> provider
smackInteroperabilityLayer.addExtensionProvider(
GroupPacketExtension.ELEMENT_NAME,
GroupPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider
<GroupPacketExtension>(GroupPacketExtension.class));
//ice-udp transport
smackInteroperabilityLayer.addExtensionProvider(
IceUdpTransportPacketExtension.ELEMENT_NAME,
IceUdpTransportPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider
<IceUdpTransportPacketExtension>(
IceUdpTransportPacketExtension.class));
//<raw-udp/> provider
smackInteroperabilityLayer.addExtensionProvider(
RawUdpTransportPacketExtension.ELEMENT_NAME,
RawUdpTransportPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider
<RawUdpTransportPacketExtension>(
RawUdpTransportPacketExtension.class));
//ice-udp <candidate/> provider
smackInteroperabilityLayer.addExtensionProvider(
CandidatePacketExtension.ELEMENT_NAME,
IceUdpTransportPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider
<CandidatePacketExtension>(
CandidatePacketExtension.class));
//raw-udp <candidate/> provider
smackInteroperabilityLayer.addExtensionProvider(
CandidatePacketExtension.ELEMENT_NAME,
RawUdpTransportPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider
<CandidatePacketExtension>(
CandidatePacketExtension.class));
//ice-udp <remote-candidate/> provider
smackInteroperabilityLayer.addExtensionProvider(
RemoteCandidatePacketExtension.ELEMENT_NAME,
IceUdpTransportPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider
<RemoteCandidatePacketExtension>(
RemoteCandidatePacketExtension.class));
//inputevt <inputevt/> provider
smackInteroperabilityLayer.addExtensionProvider(
InputEvtPacketExtension.ELEMENT_NAME,
InputEvtPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider<InputEvtPacketExtension>(
InputEvtPacketExtension.class));
//coin <conference-info/> provider
smackInteroperabilityLayer.addExtensionProvider(
CoinPacketExtension.ELEMENT_NAME,
CoinPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider<CoinPacketExtension>(
CoinPacketExtension.class));
// DTLS-SRTP
smackInteroperabilityLayer.addExtensionProvider(
DtlsFingerprintPacketExtension.ELEMENT_NAME,
DtlsFingerprintPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider
<DtlsFingerprintPacketExtension>(
DtlsFingerprintPacketExtension.class));
/*
* XEP-0251: Jingle Session Transfer <transfer/> and <transferred>
* providers
*/
smackInteroperabilityLayer.addExtensionProvider(
TransferPacketExtension.ELEMENT_NAME,
TransferPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider<TransferPacketExtension>(
TransferPacketExtension.class));
smackInteroperabilityLayer.addExtensionProvider(
TransferredPacketExtension.ELEMENT_NAME,
TransferredPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider<TransferredPacketExtension>(
TransferredPacketExtension.class));
//conference description <callid/> provider
smackInteroperabilityLayer.addExtensionProvider(
ConferenceDescriptionPacketExtension.CALLID_ELEM_NAME,
ConferenceDescriptionPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider<CallIdPacketExtension>(
CallIdPacketExtension.class));
//rtcp-fb
smackInteroperabilityLayer.addExtensionProvider(
RtcpFbPacketExtension.ELEMENT_NAME,
RtcpFbPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider<RtcpFbPacketExtension>(
RtcpFbPacketExtension.class));
//rtcp-mux
smackInteroperabilityLayer.addExtensionProvider(
RtcpmuxPacketExtension.ELEMENT_NAME,
IceUdpTransportPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider<RtcpmuxPacketExtension>(
RtcpmuxPacketExtension.class));
//ssrcInfo
smackInteroperabilityLayer.addExtensionProvider(
SSRCInfoPacketExtension.ELEMENT_NAME,
SSRCInfoPacketExtension.NAMESPACE,
new DefaultPacketExtensionProvider<SSRCInfoPacketExtension>(
SSRCInfoPacketExtension.class));
}
/**
* Parses a Jingle IQ sub-document and returns a {@link JingleIQ} instance.
*
* @param parser an XML parser.
*
* @return a new {@link JingleIQ} instance.
*
* @throws Exception if an error occurs parsing the XML.
*/
public JingleIQ parseIQ(XmlPullParser parser)
throws Exception
{
JingleIQ jingleIQ = new JingleIQ();
//let's first handle the "jingle" element params.
JingleAction action = JingleAction.parseString(parser
.getAttributeValue("", JingleIQ.ACTION_ATTR_NAME));
String initiator = parser
.getAttributeValue("", JingleIQ.INITIATOR_ATTR_NAME);
String responder = parser
.getAttributeValue("", JingleIQ.RESPONDER_ATTR_NAME);
String sid = parser
.getAttributeValue("", JingleIQ.SID_ATTR_NAME);
jingleIQ.setAction(action);
jingleIQ.setInitiator(initiator);
jingleIQ.setResponder(responder);
jingleIQ.setSID(sid);
boolean done = false;
// Sub-elements providers
DefaultPacketExtensionProvider<ContentPacketExtension> contentProvider
= new DefaultPacketExtensionProvider<ContentPacketExtension>(
ContentPacketExtension.class);
ReasonProvider reasonProvider = new ReasonProvider();
DefaultPacketExtensionProvider<TransferPacketExtension> transferProvider
= new DefaultPacketExtensionProvider<TransferPacketExtension>(
TransferPacketExtension.class);
DefaultPacketExtensionProvider<CoinPacketExtension> coinProvider
= new DefaultPacketExtensionProvider<CoinPacketExtension>(
CoinPacketExtension.class);
DefaultPacketExtensionProvider<CallIdPacketExtension> callidProvider
= new DefaultPacketExtensionProvider<CallIdPacketExtension>(
CallIdPacketExtension.class);
// Now go on and parse the jingle element's content.
int eventType;
String elementName;
String namespace;
while (!done)
{
eventType = parser.next();
elementName = parser.getName();
namespace = parser.getNamespace();
if (eventType == XmlPullParser.START_TAG)
{
// <content/>
if (elementName.equals(ContentPacketExtension.ELEMENT_NAME))
{
ContentPacketExtension content
= contentProvider.parseExtension(parser);
jingleIQ.addContent(content);
}
// <reason/>
else if(elementName.equals(ReasonPacketExtension.ELEMENT_NAME))
{
ReasonPacketExtension reason
= reasonProvider.parseExtension(parser);
jingleIQ.setReason(reason);
}
// <transfer/>
else if (elementName.equals(
TransferPacketExtension.ELEMENT_NAME)
&& namespace.equals(TransferPacketExtension.NAMESPACE))
{
jingleIQ.addExtension(
transferProvider.parseExtension(parser));
}
else if(elementName.equals(CoinPacketExtension.ELEMENT_NAME))
{
jingleIQ.addExtension(coinProvider.parseExtension(parser));
}
else if (elementName.equals(
ConferenceDescriptionPacketExtension.CALLID_ELEM_NAME))
{
jingleIQ.addExtension(callidProvider.parseExtension(parser));
}
//<mute/> <active/> and other session-info elements
if (namespace.equals( SessionInfoPacketExtension.NAMESPACE))
{
SessionInfoType type = SessionInfoType.valueOf(elementName);
//<mute/>
if( type == SessionInfoType.mute
|| type == SessionInfoType.unmute)
{
String name = parser.getAttributeValue("",
MuteSessionInfoPacketExtension.NAME_ATTR_VALUE);
jingleIQ.setSessionInfo(
new MuteSessionInfoPacketExtension(
type == SessionInfoType.mute, name));
}
//<hold/>, <unhold/>, <active/>, etc.
else
{
jingleIQ.setSessionInfo(
new SessionInfoPacketExtension(type));
}
}
}
if ((eventType == XmlPullParser.END_TAG)
&& parser.getName().equals(JingleIQ.ELEMENT_NAME))
{
done = true;
}
}
return jingleIQ;
}
}
|