1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-26 14:02:06 +01:00

Moved resource binding parsing as a core IQ packet. SMACK-124

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@3492 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2006-02-27 18:17:27 +00:00 committed by gato
parent 74ca03f5b3
commit 5247fce7ca
3 changed files with 28 additions and 36 deletions

View file

@ -121,13 +121,6 @@
<className>org.jivesoftware.smackx.packet.OfflineMessageInfo$Provider</className>
</extensionProvider>
<!-- Resource Binding -->
<iqProvider>
<elementName>bind</elementName>
<namespace>urn:ietf:params:xml:ns:xmpp-bind</namespace>
<className>org.jivesoftware.smack.packet.Bind$Provider</className>
</iqProvider>
<!-- Last Activity -->
<iqProvider>
<elementName>query</elementName>

View file

@ -29,8 +29,8 @@ import org.xmlpull.mxp1.MXParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.util.*;
import java.io.IOException;
import java.util.*;
/**
* Listens for XML traffic from the XMPP server and parses it into packet objects.
@ -585,6 +585,10 @@ class PacketReader {
else if (elementName.equals("query") && namespace.equals("jabber:iq:register")) {
iqPacket = parseRegistration(parser);
}
else if (elementName.equals("bind") &&
namespace.equals("urn:ietf:params:xml:ns:xmpp-bind")) {
iqPacket = parseResourceBinding(parser);
}
// Otherwise, see if there is a registered provider for
// this element name and namespace.
else {
@ -756,6 +760,29 @@ class PacketReader {
return registration;
}
private Bind parseResourceBinding(XmlPullParser parser) throws IOException,
XmlPullParserException {
Bind bind = new Bind();
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("resource")) {
bind.setResource(parser.nextText());
}
else if (parser.getName().equals("jid")) {
bind.setJid(parser.nextText());
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("bind")) {
done = true;
}
}
}
return bind;
}
/**
* A wrapper class to associate a packet collector with a listener.
*/

View file

@ -20,9 +20,6 @@
package org.jivesoftware.smack.packet;
import org.jivesoftware.smack.provider.IQProvider;
import org.xmlpull.v1.XmlPullParser;
/**
* IQ packet used by Smack to bind a resource and to obtain the jid assigned by the server.
* There are two ways to bind a resource. One is simply sending an empty Bind packet where the
@ -71,29 +68,4 @@ public class Bind extends IQ {
buf.append("</bind>");
return buf.toString();
}
public static class Provider implements IQProvider {
public IQ parseIQ(XmlPullParser parser) throws Exception {
Bind bind = new Bind();
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("resource")) {
bind.setResource(parser.nextText());
}
else if (parser.getName().equals("jid")) {
bind.setJid(parser.nextText());
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("bind")) {
done = true;
}
}
}
return bind;
}
}
}