Esempio n. 1
0
 protected void changeStatus(int nextStatus) {
   if (account.getStatus() != nextStatus) {
     if ((nextStatus == Account.STATUS_OFFLINE)
         && (account.getStatus() != Account.STATUS_CONNECTING)
         && (account.getStatus() != Account.STATUS_ONLINE)) {
       return;
     }
     account.setStatus(nextStatus);
     if (statusListener != null) {
       statusListener.onStatusChanged(account);
     }
   }
 }
Esempio n. 2
0
 private void processStream(Tag currentTag)
     throws XmlPullParserException, IOException, NoSuchAlgorithmException {
   Tag nextTag = tagReader.readTag();
   while ((nextTag != null) && (!nextTag.isEnd("stream"))) {
     if (nextTag.isStart("error")) {
       processStreamError(nextTag);
     } else if (nextTag.isStart("features")) {
       processStreamFeatures(nextTag);
       if ((streamFeatures.getChildren().size() == 1)
           && (streamFeatures.hasChild("starttls"))
           && (!account.isOptionSet(Account.OPTION_USETLS))) {
         changeStatus(Account.STATUS_SERVER_REQUIRES_TLS);
       }
     } else if (nextTag.isStart("proceed")) {
       switchOverToTls(nextTag);
     } else if (nextTag.isStart("compressed")) {
       switchOverToZLib(nextTag);
     } else if (nextTag.isStart("success")) {
       Log.d(LOGTAG, account.getJid() + ": logged in");
       tagReader.readTag();
       tagReader.reset();
       sendStartStream();
       processStream(tagReader.readTag());
       break;
     } else if (nextTag.isStart("failure")) {
       Element failure = tagReader.readElement(nextTag);
       changeStatus(Account.STATUS_UNAUTHORIZED);
     } else if (nextTag.isStart("challenge")) {
       String challange = tagReader.readElement(nextTag).getContent();
       Element response = new Element("response");
       response.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl");
       response.setContent(CryptoHelper.saslDigestMd5(account, challange));
       tagWriter.writeElement(response);
     } else if (nextTag.isStart("enabled")) {
       this.stanzasSent = 0;
       Element enabled = tagReader.readElement(nextTag);
       if ("true".equals(enabled.getAttribute("resume"))) {
         this.streamId = enabled.getAttribute("id");
         Log.d(
             LOGTAG,
             account.getJid() + ": stream managment(" + smVersion + ") enabled (resumable)");
       } else {
         Log.d(LOGTAG, account.getJid() + ": stream managment(" + smVersion + ") enabled");
       }
       this.lastSessionStarted = SystemClock.elapsedRealtime();
       this.stanzasReceived = 0;
       RequestPacket r = new RequestPacket(smVersion);
       tagWriter.writeStanzaAsync(r);
     } else if (nextTag.isStart("resumed")) {
       tagReader.readElement(nextTag);
       sendPing();
       changeStatus(Account.STATUS_ONLINE);
       Log.d(LOGTAG, account.getJid() + ": session resumed");
     } else if (nextTag.isStart("r")) {
       tagReader.readElement(nextTag);
       AckPacket ack = new AckPacket(this.stanzasReceived, smVersion);
       // Log.d(LOGTAG,ack.toString());
       tagWriter.writeStanzaAsync(ack);
     } else if (nextTag.isStart("a")) {
       Element ack = tagReader.readElement(nextTag);
       lastPaketReceived = SystemClock.elapsedRealtime();
       int serverSequence = Integer.parseInt(ack.getAttribute("h"));
       if (serverSequence > this.stanzasSent) {
         this.stanzasSent = serverSequence;
       }
       // Log.d(LOGTAG,"server ack"+ack.toString()+" ("+this.stanzasSent+")");
     } else if (nextTag.isStart("failed")) {
       tagReader.readElement(nextTag);
       Log.d(LOGTAG, account.getJid() + ": resumption failed");
       streamId = null;
       if (account.getStatus() != Account.STATUS_ONLINE) {
         sendBindRequest();
       }
     } else if (nextTag.isStart("iq")) {
       processIq(nextTag);
     } else if (nextTag.isStart("message")) {
       processMessage(nextTag);
     } else if (nextTag.isStart("presence")) {
       processPresence(nextTag);
     } else {
       Log.d(
           LOGTAG,
           "found unexpected tag: " + nextTag.getName() + " as child of " + currentTag.getName());
     }
     nextTag = tagReader.readTag();
   }
   if (account.getStatus() == Account.STATUS_ONLINE) {
     account.setStatus(Account.STATUS_OFFLINE);
     if (statusListener != null) {
       statusListener.onStatusChanged(account);
     }
   }
 }