Пример #1
0
 public void parseGroupsFromElement(Element item) {
   this.groups = new JSONArray();
   for (Element element : item.getChildren()) {
     if (element.getName().equals("group") && element.getContent() != null) {
       this.groups.put(element.getContent());
     }
   }
 }
Пример #2
0
 private void parseEvent(final Element event, final Jid from, final Account account) {
   Element items = event.findChild("items");
   String node = items == null ? null : items.getAttribute("node");
   if ("urn:xmpp:avatar:metadata".equals(node)) {
     Avatar avatar = Avatar.parseMetadata(items);
     if (avatar != null) {
       avatar.owner = from.toBareJid();
       if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
         if (account.getJid().toBareJid().equals(from)) {
           if (account.setAvatar(avatar.getFilename())) {
             mXmppConnectionService.databaseBackend.updateAccount(account);
           }
           mXmppConnectionService.getAvatarService().clear(account);
           mXmppConnectionService.updateConversationUi();
           mXmppConnectionService.updateAccountUi();
         } else {
           Contact contact = account.getRoster().getContact(from);
           contact.setAvatar(avatar);
           mXmppConnectionService.getAvatarService().clear(contact);
           mXmppConnectionService.updateConversationUi();
           mXmppConnectionService.updateRosterUi();
         }
       } else {
         mXmppConnectionService.fetchAvatar(account, avatar);
       }
     }
   } else if ("http://jabber.org/protocol/nick".equals(node)) {
     Element i = items.findChild("item");
     Element nick = i == null ? null : i.findChild("nick", "http://jabber.org/protocol/nick");
     if (nick != null && nick.getContent() != null) {
       Contact contact = account.getRoster().getContact(from);
       contact.setPresenceName(nick.getContent());
       mXmppConnectionService.getAvatarService().clear(account);
       mXmppConnectionService.updateConversationUi();
       mXmppConnectionService.updateAccountUi();
     }
   } else if (AxolotlService.PEP_DEVICE_LIST.equals(node)) {
     Log.d(
         Config.LOGTAG,
         AxolotlService.getLogprefix(account)
             + "Received PEP device list update from "
             + from
             + ", processing...");
     Element item = items.findChild("item");
     Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item);
     AxolotlService axolotlService = account.getAxolotlService();
     axolotlService.registerDevices(from, deviceIds);
     mXmppConnectionService.updateAccountUi();
   }
 }
Пример #3
0
 private List<String> extractMechanisms(Element stream) {
   ArrayList<String> mechanisms = new ArrayList<String>(stream.getChildren().size());
   for (Element child : stream.getChildren()) {
     mechanisms.add(child.getContent());
   }
   return mechanisms;
 }
Пример #4
0
 protected String avatarData(Element items) {
   Element item = items.findChild("item");
   if (item == null) {
     return null;
   }
   Element data = item.findChild("data", "urn:xmpp:avatar:data");
   if (data == null) {
     return null;
   }
   return data.getContent();
 }
Пример #5
0
 private Invite extractInvite(Element message) {
   Element x = message.findChild("x", "http://jabber.org/protocol/muc#user");
   if (x != null) {
     Element invite = x.findChild("invite");
     if (invite != null) {
       Element pw = x.findChild("password");
       return new Invite(message.getAttributeAsJid("from"), pw != null ? pw.getContent() : null);
     }
   } else {
     x = message.findChild("x", "jabber:x:conference");
     if (x != null) {
       return new Invite(x.getAttributeAsJid("jid"), x.getAttribute("password"));
     }
   }
   return null;
 }
Пример #6
0
  private boolean compressionAvailable() {
    if (!this.streamFeatures.hasChild("compression", "http://jabber.org/features/compress"))
      return false;
    if (!ZLibOutputStream.SUPPORTED) return false;
    if (!account.isOptionSet(Account.OPTION_USECOMPRESSION)) return false;

    Element compression =
        this.streamFeatures.findChild("compression", "http://jabber.org/features/compress");
    for (Element child : compression.getChildren()) {
      if (!"method".equals(child.getName())) continue;

      if ("zlib".equalsIgnoreCase(child.getContent())) {
        return true;
      }
    }
    return false;
  }
Пример #7
0
 public void processPacket(PresencePacket packet, PgpEngine pgp) {
   final Jid from = packet.getFrom();
   if (!from.isBareJid()) {
     final String name = from.getResourcepart();
     String type = packet.getAttribute("type");
     if (type == null) {
       User user = new User();
       Element x = packet.findChild("x", "http://jabber.org/protocol/muc#user");
       if (x != null) {
         Element item = x.findChild("item");
         if (item != null) {
           user.setName(name);
           user.setAffiliation(item.getAttribute("affiliation"));
           user.setRole(item.getAttribute("role"));
           user.setJid(item.getAttributeAsJid("jid"));
           user.setName(name);
           if (name.equals(this.joinnick)) {
             this.isOnline = true;
             this.error = ERROR_NO_ERROR;
             self = user;
             if (aboutToRename) {
               if (renameListener != null) {
                 renameListener.onRename(true);
               }
               aboutToRename = false;
             }
           } else {
             addUser(user);
           }
           if (pgp != null) {
             Element signed = packet.findChild("x", "jabber:x:signed");
             if (signed != null) {
               Element status = packet.findChild("status");
               String msg;
               if (status != null) {
                 msg = status.getContent();
               } else {
                 msg = "";
               }
               user.setPgpKeyId(pgp.fetchKeyId(account, msg, signed.getContent()));
             }
           }
         }
       }
     } else if (type.equals("unavailable") && name.equals(this.joinnick)) {
       Element x = packet.findChild("x", "http://jabber.org/protocol/muc#user");
       if (x != null) {
         Element status = x.findChild("status");
         if (status != null) {
           String code = status.getAttribute("code");
           if (STATUS_CODE_KICKED.equals(code)) {
             this.isOnline = false;
             this.error = KICKED_FROM_ROOM;
           } else if (STATUS_CODE_BANNED.equals(code)) {
             this.isOnline = false;
             this.error = ERROR_BANNED;
           }
         }
       }
     } else if (type.equals("unavailable")) {
       deleteUser(packet.getAttribute("from").split("/", 2)[1]);
     } else if (type.equals("error")) {
       Element error = packet.findChild("error");
       if (error != null && error.hasChild("conflict")) {
         if (aboutToRename) {
           if (renameListener != null) {
             renameListener.onRename(false);
           }
           aboutToRename = false;
           this.setJoinNick(getActualNick());
         } else {
           this.error = ERROR_NICK_IN_USE;
         }
       } else if (error != null && error.hasChild("not-authorized")) {
         this.error = ERROR_PASSWORD_REQUIRED;
       } else if (error != null && error.hasChild("forbidden")) {
         this.error = ERROR_BANNED;
       } else if (error != null && error.hasChild("registration-required")) {
         this.error = ERROR_MEMBERS_ONLY;
       }
     }
   }
 }
 private void processConferencePresence(PresencePacket packet, MucOptions mucOptions) {
   final Jid from = packet.getFrom();
   if (!from.isBareJid()) {
     final String type = packet.getAttribute("type");
     final Element x = packet.findChild("x", "http://jabber.org/protocol/muc#user");
     Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update"));
     final List<String> codes = getStatusCodes(x);
     if (type == null) {
       if (x != null) {
         Element item = x.findChild("item");
         if (item != null && !from.isBareJid()) {
           mucOptions.setError(MucOptions.ERROR_NO_ERROR);
           MucOptions.User user = new MucOptions.User(mucOptions, from);
           user.setAffiliation(item.getAttribute("affiliation"));
           user.setRole(item.getAttribute("role"));
           user.setJid(item.getAttributeAsJid("jid"));
           if (codes.contains(MucOptions.STATUS_CODE_SELF_PRESENCE)
               || packet.getFrom().equals(mucOptions.getConversation().getJid())) {
             mucOptions.setOnline();
             mucOptions.setSelf(user);
             if (mucOptions.mNickChangingInProgress) {
               if (mucOptions.onRenameListener != null) {
                 mucOptions.onRenameListener.onSuccess();
               }
               mucOptions.mNickChangingInProgress = false;
             }
           } else {
             mucOptions.addUser(user);
           }
           if (mXmppConnectionService.getPgpEngine() != null) {
             Element signed = packet.findChild("x", "jabber:x:signed");
             if (signed != null) {
               Element status = packet.findChild("status");
               String msg = status == null ? "" : status.getContent();
               long keyId =
                   mXmppConnectionService
                       .getPgpEngine()
                       .fetchKeyId(mucOptions.getAccount(), msg, signed.getContent());
               if (keyId != 0) {
                 user.setPgpKeyId(keyId);
               }
             }
           }
           if (avatar != null) {
             avatar.owner = from;
             if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
               if (user.setAvatar(avatar)) {
                 mXmppConnectionService.getAvatarService().clear(user);
               }
             } else {
               mXmppConnectionService.fetchAvatar(mucOptions.getAccount(), avatar);
             }
           }
         }
       }
     } else if (type.equals("unavailable")) {
       if (codes.contains(MucOptions.STATUS_CODE_SELF_PRESENCE)
           || packet.getFrom().equals(mucOptions.getConversation().getJid())) {
         if (codes.contains(MucOptions.STATUS_CODE_CHANGED_NICK)) {
           mucOptions.mNickChangingInProgress = true;
         } else if (codes.contains(MucOptions.STATUS_CODE_KICKED)) {
           mucOptions.setError(MucOptions.KICKED_FROM_ROOM);
         } else if (codes.contains(MucOptions.STATUS_CODE_BANNED)) {
           mucOptions.setError(MucOptions.ERROR_BANNED);
         } else if (codes.contains(MucOptions.STATUS_CODE_LOST_MEMBERSHIP)) {
           mucOptions.setError(MucOptions.ERROR_MEMBERS_ONLY);
         } else {
           mucOptions.setError(MucOptions.ERROR_UNKNOWN);
           Log.d(Config.LOGTAG, "unknown error in conference: " + packet);
         }
       } else if (!from.isBareJid()) {
         MucOptions.User user = mucOptions.deleteUser(from.getResourcepart());
         if (user != null) {
           mXmppConnectionService.getAvatarService().clear(user);
         }
       }
     } else if (type.equals("error")) {
       Element error = packet.findChild("error");
       if (error != null && error.hasChild("conflict")) {
         if (mucOptions.online()) {
           if (mucOptions.onRenameListener != null) {
             mucOptions.onRenameListener.onFailure();
           }
         } else {
           mucOptions.setError(MucOptions.ERROR_NICK_IN_USE);
         }
       } else if (error != null && error.hasChild("not-authorized")) {
         mucOptions.setError(MucOptions.ERROR_PASSWORD_REQUIRED);
       } else if (error != null && error.hasChild("forbidden")) {
         mucOptions.setError(MucOptions.ERROR_BANNED);
       } else if (error != null && error.hasChild("registration-required")) {
         mucOptions.setError(MucOptions.ERROR_MEMBERS_ONLY);
       }
     }
   }
 }
  public void parseContactPresence(final PresencePacket packet, final Account account) {
    final PresenceGenerator mPresenceGenerator = mXmppConnectionService.getPresenceGenerator();
    final Jid from = packet.getFrom();
    if (from == null) {
      return;
    }
    final String type = packet.getAttribute("type");
    final Contact contact = account.getRoster().getContact(from);
    if (type == null) {
      final String resource = from.isBareJid() ? "" : from.getResourcepart();
      contact.setPresenceName(packet.findChildContent("nick", "http://jabber.org/protocol/nick"));
      Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update"));
      if (avatar != null && !contact.isSelf()) {
        avatar.owner = from.toBareJid();
        if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
          if (contact.setAvatar(avatar)) {
            mXmppConnectionService.getAvatarService().clear(contact);
            mXmppConnectionService.updateConversationUi();
            mXmppConnectionService.updateRosterUi();
          }
        } else {
          mXmppConnectionService.fetchAvatar(account, avatar);
        }
      }
      int sizeBefore = contact.getPresences().size();

      final Element show = packet.findChild("show");
      final Element caps = packet.findChild("c", "http://jabber.org/protocol/caps");
      final Presence presence = Presence.parse(show, caps);
      contact.updatePresence(resource, presence);
      if (presence.hasCaps() && Config.REQUEST_DISCO) {
        mXmppConnectionService.fetchCaps(account, from, presence);
      }

      PgpEngine pgp = mXmppConnectionService.getPgpEngine();
      Element x = packet.findChild("x", "jabber:x:signed");
      if (pgp != null && x != null) {
        Element status = packet.findChild("status");
        String msg = status != null ? status.getContent() : "";
        contact.setPgpKeyId(pgp.fetchKeyId(account, msg, x.getContent()));
      }
      boolean online = sizeBefore < contact.getPresences().size();
      updateLastseen(packet, account, false);
      mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, online);
    } else if (type.equals("unavailable")) {
      if (from.isBareJid()) {
        contact.clearPresences();
      } else {
        contact.removePresence(from.getResourcepart());
      }
      mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, false);
    } else if (type.equals("subscribe")) {
      if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
        mXmppConnectionService.sendPresencePacket(
            account, mPresenceGenerator.sendPresenceUpdatesTo(contact));
      } else {
        contact.setOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST);
        final Conversation conversation =
            mXmppConnectionService.findOrCreateConversation(
                account, contact.getJid().toBareJid(), false);
        final String statusMessage = packet.findChildContent("status");
        if (statusMessage != null
            && !statusMessage.isEmpty()
            && conversation.countMessages() == 0) {
          conversation.add(
              new Message(
                  conversation, statusMessage, Message.ENCRYPTION_NONE, Message.STATUS_RECEIVED));
        }
      }
    }
    mXmppConnectionService.updateRosterUi();
  }