1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 09:39:39 +02:00

Added stream compression support. SMACK-112

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@3306 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2006-01-16 17:34:56 +00:00 committed by gato
parent 86ce253883
commit 15defec50f
3 changed files with 221 additions and 46 deletions

View file

@ -320,10 +320,17 @@ class PacketReader {
resetParser();
}
else if (parser.getName().equals("failure")) {
if ("urn:ietf:params:xml:ns:xmpp-tls".equals(parser.getNamespace(null))) {
String namespace = parser.getNamespace(null);
if ("urn:ietf:params:xml:ns:xmpp-tls".equals(namespace)) {
// TLS negotiation has failed. The server will close the connection
throw new Exception("TLS negotiation has failed");
}
else if ("http://jabber.org/protocol/compress".equals(namespace)) {
// Stream compression has been denied. This is a recoverable
// situation. It is still possible to authenticate and
// use the connection but using an uncompressed connection
connection.streamCompressionDenied();
}
else {
// SASL authentication has failed. The server may close the connection
// depending on the number of retries
@ -347,6 +354,14 @@ class PacketReader {
// will be to bind the resource
connection.getSASLAuthentication().authenticated();
}
else if (parser.getName().equals("compressed")) {
// Server confirmed that it's possible to use stream compression. Start
// stream compression
connection.startStreamCompression();
// Reset the state of the parser since a new stream element is going
// to be sent by the server
resetParser();
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("stream")) {
@ -464,6 +479,10 @@ class PacketReader {
// The server supports sessions
connection.getSASLAuthentication().sessionsSupported();
}
else if (parser.getName().equals("compression")) {
// The server supports stream compression
connection.setAvailableCompressionMethods(parseCompressionMethods(parser));
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("features")) {
@ -504,6 +523,28 @@ class PacketReader {
return mechanisms;
}
private Collection parseCompressionMethods(XmlPullParser parser)
throws IOException, XmlPullParserException {
List methods = new ArrayList();
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
String elementName = parser.getName();
if (elementName.equals("method")) {
methods.add(parser.nextText());
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("compression")) {
done = true;
}
}
}
return methods;
}
/**
* Parses an IQ packet.
*