/** Creates a new instance of IqRegister */
  public IqRegister(String username, String password, String id) {
    super(null, Iq.TYPE_SET, id);

    JabberDataBlock qB = addChildNs("query", "jabber:iq:register");
    qB.addChild("username", username);
    qB.addChild("password", password);
  }
  public static void join(String name, String pass, int maxStanzas) {
    StaticData sd = StaticData.getInstance();

    ConferenceGroup grp = sd.roster.initMuc(name, pass);
    // требуется для возможности нормального выхода
    // sd.roster.mucContact(name, Contact.ORIGIN_GC_MYSELF);
    // sd.roster.activeRooms.addElement(jid);

    JabberDataBlock x = new JabberDataBlock("x", null, null);
    x.setNameSpace("http://jabber.org/protocol/muc");
    if (pass.length() != 0) {
      // adding password to presence
      x.addChild("password", pass);
    }

    JabberDataBlock history = x.addChild("history", null);
    history.setAttribute("maxstanzas", String.valueOf(maxStanzas));
    history.setAttribute("maxchars", "32768");
    try {
      long last = grp.getConference().lastMessageTime;
      long delay = (grp.conferenceJoinTime - last) / 1000;
      if (last != 0)
        history.setAttribute("seconds", String.valueOf(delay)); // todo: change to since
    } catch (Exception e) {
    }
    ;

    // sd.roster.groups.getGroup(name.substring(0,
    // name.indexOf('@'))).imageExpandedIndex=ImageList.ICON_GCJOIN_INDEX;
    sd.roster.sendPresence(name, null, x);
    sd.roster.reEnumRoster();
  }
예제 #3
0
  public void commandAction(Command command, Displayable displayable) {
    if (command == cmdOk) {
      JabberDataBlock resultForm = new JabberDataBlock("x", null, null);
      resultForm.setNameSpace("jabber:x:data");
      resultForm.setTypeAttribute("submit");

      for (Enumeration e = items.elements(); e.hasMoreElements(); ) {
        JabberDataBlock ch = ((XDataField) e.nextElement()).constructJabberDataBlock();
        if (ch != null) resultForm.addChild(ch);
      }
      XDataFormSubmit(resultForm);
    }
    BombusQD.sd.canvas.show(parentView);
  }
  // send shortcut
  void send(JabberDataBlock data, boolean async) {
    // StaticData.getInstance().roster.theStream.send(data);
    try {
      StringBuffer sb = new StringBuffer();
      data.constructXML(sb);
      StaticData.getInstance().roster.theStream.sendBuf(sb);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public int blockArrived(JabberDataBlock data) {
    if (data instanceof Iq) {
      String id = data.getAttribute("id");

      JabberDataBlock si = data.getChildBlock("si");
      if (si != null) {
        // stream initiating
        String sid = si.getAttribute("id");

        JabberDataBlock file = si.getChildBlock("file");
        JabberDataBlock feature = si.getChildBlock("feature");

        String type = data.getTypeAttribute();
        if (type.equals("set")) {
          // sender initiates file sending process
          TransferTask task =
              new TransferTask(
                  data.getAttribute("from"),
                  id,
                  sid,
                  file.getAttribute("name"),
                  file.getChildBlockText("desc"),
                  Integer.parseInt(file.getAttribute("size")),
                  null);

          synchronized (taskList) {
            taskList.addElement(task);
          }

          eventNotify();
          StaticData.getInstance().roster.playNotify(0);
          return BLOCK_PROCESSED;
        }
        if (type.equals("result")) {
          // our file were accepted
          TransferTask task = getTransferBySid(id);
          task.initIBB();

          eventNotify();
          return BLOCK_PROCESSED;
        }
      }
      JabberDataBlock open = data.getChildBlock("open");
      if (open != null) {
        String sid = open.getAttribute("sid");
        TransferTask task = getTransferBySid(sid);

        JabberDataBlock accept = new Iq(task.jid, Iq.TYPE_RESULT, id);
        send(accept, true);
        eventNotify();
        return BLOCK_PROCESSED;
      }
      JabberDataBlock close = data.getChildBlock("close");
      if (close != null) {
        String sid = close.getAttribute("sid");
        TransferTask task = getTransferBySid(sid);

        JabberDataBlock done = new Iq(task.jid, Iq.TYPE_RESULT, id);
        send(done, true);
        task.closeFile();
        eventNotify();
        return BLOCK_PROCESSED;
      }
      if (data.getTypeAttribute().equals("result")) {
        TransferTask task = getTransferBySid(id);
        if (task != null) {
          task.startTransfer();
        }
      }
      if (data.getTypeAttribute().equals("error")) {
        TransferTask task = getTransferBySid(id);
        if (task != null) {
          task.cancel();
        }
      }
    }
    if (data instanceof Message) {
      JabberDataBlock bdata = data.getChildBlock("data");
      if (bdata == null) return BLOCK_REJECTED;
      if (!bdata.isJabberNameSpace("http://jabber.org/protocol/ibb")) return BLOCK_REJECTED;
      String sid = bdata.getAttribute("sid");
      TransferTask task = getTransferBySid(sid);

      byte b[] = strconv.fromBase64(bdata.getText());
      System.out.println("data chunk received");
      repaintNotify();
      task.writeFile(b);
    }
    return BLOCK_REJECTED;
  }
예제 #6
0
  private void setMucMod() {
    JabberDataBlock iq = new Iq(victim.jid.getBareJid(), Iq.TYPE_SET, "itemmuc");
    JabberDataBlock query = iq.addChildNs("query", "http://jabber.org/protocol/muc#admin");
    // TODO: separate usecases to muc#owner, muc#admin and muc#moderator
    JabberDataBlock item = new JabberDataBlock("item", null, null);
    query.addChild(item);

    try {
      String rzn = reason.getValue();
      String Nick = "";
      if (rzn.charAt(0) == '!') {
        rzn = rzn.substring(1);
      } else {
        Nick = (myNick == null) ? myNick : myNick + ": ";
      }
      if (rzn.length() != 0 && myNick != null) {
        item.addChild("reason", Nick + rzn);
      } else {
        item.addChild("reason", Nick);
      }
    } catch (Exception e) {
    }

    switch (action) {
      case KICK:
        item.setAttribute("role", "none");
        item.setAttribute("nick", victim.getNick());
        break;

      case OUTCAST:
        item.setAttribute("affiliation", "outcast");
        item.setAttribute("jid", victim.realJid);
        break;

      case PARTICIPANT:
        item.setAttribute("role", "participant");
        item.setAttribute("nick", victim.getNick());
        break;

      case VISITOR:
        item.setAttribute("role", "visitor");
        item.setAttribute("nick", victim.getNick());
        break;

      case MODERATOR:
        item.setAttribute("role", "moderator");
        item.setAttribute("nick", victim.getNick());
        break;

      case MEMBER:
        item.setAttribute("affiliation", "member");
        item.setAttribute("jid", victim.realJid);
        break;

      case NONE:
        item.setAttribute("affiliation", "none");
        item.setAttribute("jid", victim.realJid);
        break;

      case ADMIN:
        item.setAttribute("affiliation", "admin");
        item.setAttribute("jid", victim.realJid);
        break;

      case OWNER:
        item.setAttribute("affiliation", "owner");
        item.setAttribute("jid", victim.realJid);
    }

    StaticData.getInstance().roster.theStream.send(iq);
  }
예제 #7
0
  public XDataForm(JabberDataBlock data, String id, String from) {
    this.id = id;
    this.from = from;

    cmdOk = new Command(SR.get(SR.MS_SEND), Command.OK /*Command.SCREEN*/, 1);
    cmdCancel = new Command(SR.get(SR.MS_BACK), Command.BACK, 99);
    // #ifdef DEBUG_CONSOLE
    // #         midlet.BombusQD.debug.add("captcha<<< " + data.toString(),10);
    // #endif

    JabberDataBlock challenge = data.findNamespace("captcha", "urn:xmpp:captcha");
    JabberDataBlock xdata = challenge.findNamespace("x", "jabber:x:data");
    JabberDataBlock oob = data.findNamespace("x", "jabber:x:oob");

    String url = oob.getChildBlockText("url");
    String title = xdata.getChildBlockText("title");

    Vector xData = xdata.getChildBlocks();

    if (null == title) title = "";

    f = new Form(title);
    items = new Vector(0);

    if (url.length() > 0) {
      TextField formItem = new TextField("URL", url, url.length(), TextField.UNEDITABLE);
      f.append(formItem);
    }

    XDataField field;
    String msgcid = "";

    int size = xData.size();
    for (int i = 0; i < size; ++i) {
      JabberDataBlock ch = (JabberDataBlock) xData.elementAt(i);

      if (ch.getTagName().equals("instructions")) {
        f.append(ch.getText());
        f.append("\n");
        continue;
      }
      ;
      if (!ch.getTagName().equals("field")) continue;

      field = new XDataField(ch);
      items.addElement(field);

      if (field.hidden) continue;

      if (field.media != null) msgcid = field.mediaUri.substring(4);
      f.append(field.formItem);
    }

    JabberDataBlock dataImage = data.findNamespace("data", "urn:xmpp:bob");
    String cid = dataImage.getAttribute("cid");
    if (cid.indexOf(msgcid) == 0) {
      try {
        byte[] bytes = Strconv.fromBase64(dataImage.getText());
        Image img = Image.createImage(bytes, 0, bytes.length);
        f.append(new ImageItem(null, img, Item.LAYOUT_CENTER, null));
      } catch (OutOfMemoryError eom) {
        // #ifdef DEBUG_CONSOLE
        // #                 midlet.BombusQD.debug.add("XDataForm OutOfMem",10);
        // #endif
      } catch (Exception e) {
      }
    }

    f.setCommandListener(this);
    f.addCommand(cmdOk);
    f.addCommand(cmdCancel);

    this.parentView = BombusQD.sd.canvas.getCanvas();
    BombusQD.setCurrentView(f);
  }
예제 #8
0
 public void XDataFormSubmit(JabberDataBlock form) {
   JabberDataBlock reply = new Iq(from, Iq.TYPE_SET, id);
   reply.addChildNs("captcha", "urn:xmpp:captcha").addChild(form);
   midlet.BombusQD.sd.roster.theStream.send(reply);
 }
예제 #9
0
  public JabberDataBlock constructVCard() {
    JabberDataBlock vcardIq = new Iq(null, Iq.TYPE_SET, "vcard-set");
    JabberDataBlock vcardTemp = vcardIq.addChildNs("vCard", "vcard-temp");

    int itemsCount = getCount();

    for (int i = 0; i < itemsCount; i++) {
      String field = getVCardData(i);
      if (field == null) continue;

      String f1 = (String) VCard.vCardFields.elementAt(i);
      String f2 = (String) VCard.vCardFields2.elementAt(i);

      JabberDataBlock subLevel = vcardTemp;
      if (f2 != null) {
        subLevel = vcardTemp.getChildBlock(f2);
        if (subLevel == null) subLevel = vcardTemp.addChild(f2, null);
      }
      subLevel.addChild(f1, field);
    }
    if (photo != null) {
      String mime = getPhotoMIMEType();
      if (mime != null) {
        JabberDataBlock ph = vcardTemp.addChild("PHOTO", null);
        ph.addChild("BINVAL", strconv.toBase64(photo, -1));
        ph.addChild("TYPE", mime);
      }
    }
    // System.out.println(vcard.toString());
    return vcardIq;
  }
예제 #10
0
  public VCard(JabberDataBlock data) {
    this();
    jid = data.getAttribute("from");
    id = data.getAttribute("id");
    int itemsCount = getCount();
    vCardData = new Vector(itemsCount);
    vCardData.setSize(itemsCount);

    if (data == null) return;
    if (data.getTypeAttribute().equals("error")) return;
    JabberDataBlock vcard = data.findNamespace("vcard-temp");
    if (vcard == null) return; // "No vCard available"

    empty = false;

    for (int i = 0; i < itemsCount; i++) {
      try {
        String f1 = (String) VCard.vCardFields.elementAt(i);
        String f2 = (String) VCard.vCardFields2.elementAt(i);

        JabberDataBlock d2 = (f2 == null) ? vcard : vcard.getChildBlock(f2);

        String field = d2.getChildBlockText(f1);

        if (field.length() > 0) setVCardData(i, field);
      } catch (Exception e) {
        /**/
      }
    }

    try {
      JabberDataBlock photoXML = vcard.getChildBlock("PHOTO").getChildBlock("BINVAL");
      photo = (byte[]) photoXML.getChildBlocks().lastElement();
    } catch (Exception e) {
    }
    ;
  }
예제 #11
0
  public static JabberDataBlock getQueryVCard(String to, String id) {
    JabberDataBlock req = new Iq(to, Iq.TYPE_GET, id);
    req.addChildNs("vCard", "vcard-temp");

    return req;
  }