Package tigase.server

Examples of tigase.server.Packet


          params.put(TOKEN, token);
          params.put(AUTH_TIME, ""+authTime);
          Element check_session_el = ClusterElement.createClusterMethodCall(
            getComponentId(), cluster_node, StanzaType.set,
            ClusterMethods.SESSION_TRANSFER.toString(), params).getClusterElement();
          fastAddOutPacket(new Packet(check_session_el));
        } catch (Exception e) {
          log.log(Level.WARNING, "Problem with session transfer process, ", e);
        }
      }
    }
View Full Code Here


    }
    int cnt = 0;
    for (String node: nodes) {
      message += "" + (++cnt) + ". " + node;
    }
    Packet p_msg = Packet.getMessage("",
      JIDUtils.getJID(getName(), getDefHostName(), null), StanzaType.normal,
      message, subject, "xyz");
    sendToAdmins(p_msg);
  }
View Full Code Here

              "<email/>", 1));
          break;
        case result:
          // It might be a registration request from transport for example...
          Element elem_res = packet.getElement().clone();
          Packet pack_res = new Packet(elem_res);
          pack_res.setTo(session.getConnectionId());
          results.offer(pack_res);
          break;
        default:
          results.offer(Authorization.BAD_REQUEST.getResponseMessage(packet,
              "Message type is incorrect", true));
          break;
        } // end of switch (type)
      } else {
        if (id.equals(session.getUserId())) {
          // It might be a registration request from transport for example...
          Element elem_res = packet.getElement().clone();
          Packet pack_res = new Packet(elem_res);
          pack_res.setTo(session.getConnectionId());
          results.offer(pack_res);
        } else {
          Element result = packet.getElement().clone();
          results.offer(new Packet(result));
        }
      }
    } catch (NotAuthorizedException e) {
      results.offer(Authorization.NOT_AUTHORIZED.getResponseMessage(packet,
          "You are not authorized to change registration settings.", true));
View Full Code Here

    } // end of if (session == null)

    if (packet.getElement().getName().equals("starttls")) {
      session.putSessionData(TLS_STARTED_KEY, "true");
      //results.offer(packet.swapFromTo(proceed));
      Packet result = Command.STARTTLS.getPacket(packet.getTo(),
        packet.getFrom(), StanzaType.set, "1", "submit");
      Command.setData(result, new Element("proceed",
          new String[] {"xmlns"},
          new String[] {"urn:ietf:params:xml:ns:xmpp-tls"}));
      results.offer(result);
View Full Code Here

    }

    try {
      if (id.equals(session.getUserId())) {
        Element elem = packet.getElement().clone();
        Packet result = new Packet(elem);
        result.setTo(session.getConnectionId(packet.getElemTo()));
        result.setFrom(packet.getTo());
        results.offer(result);
      } else {
        Element result = packet.getElement().clone();
        results.offer(new Packet(result));
      }
    } catch (NotAuthorizedException e) {
      log.warning("NotAuthorizedException for packet: " + packet.getStringData());
    }
  }
View Full Code Here

      // retrieve server version information, so this part is executed
      // after checking if this message is just to local server
      if (id.equals(session.getUserId())) {
        // Yes this is message to 'this' client
        Element elem = packet.getElement().clone();
        Packet result = new Packet(elem);
        result.setTo(session.getConnectionId(packet.getElemTo()));
        result.setFrom(packet.getTo());
        results.offer(result);
      } else {
        // This is message to some other client so I need to
        // set proper 'from' attribute whatever it is set to now.
        // Actually processor should not modify request but in this
        // case it is absolutely safe and recommended to set 'from'
        // attribute
        Element result = packet.getElement().clone();
        // According to spec we must set proper FROM attribute
        //        result.setAttribute("from", session.getJID());
        results.offer(new Packet(result));
      } // end of else
    } catch (NotAuthorizedException e) {
      // Do nothing, shouldn't happen....
      log.warning("NotAuthorizedException for packet: "
        + packet.getStringData());
View Full Code Here

          item.addAttribute("units", record.getUnit());
          item.addAttribute("value", record.getValue());
          query.addChild(item);
        } // end of for ()
      } // end of if (stats != null && stats.count() > 0)
      Packet result = new Packet(iq);
      //      Command.setData(result, statistics);
      results.offer(result);
      break;
    }
    case OTHER: {
      if (packet.getStrCommand() == null) return;
      String nick = JIDUtils.getNodeNick(packet.getTo());
      if (nick == null || !getName().equals(nick)) return;
      Command.Action action = Command.getAction(packet);
      if (action == Command.Action.cancel) {
        Packet result = packet.commandResult(null);
        results.offer(result);
        return;
      }
      log.finest("Command received: " + packet.getStringData());
      List<StatRecord> stats = null;
      if (packet.getStrCommand().equals("stats")) {
        stats = getAllStats();
      } else {
        String[] spl = packet.getStrCommand().split("/");
        stats = getComponent(spl[1]).getStatistics();
      }
      String tmp_val = Command.getFieldValue(packet, "Stats level");
      if (tmp_val != null) {
        statsLevel = Level.parse(tmp_val);
      }
      if (stats != null && stats.size() > 0) {
        Packet result = packet.commandResult("result");
        Command.setStatus(result, Command.Status.executing);
        Command.addAction(result, Command.Action.next);
        for (StatRecord rec: stats) {
          if (rec.getLevel().intValue() >= statsLevel.intValue()) {
            if (rec.getType() == StatisticType.LIST) {
View Full Code Here

      if (sub != SubscriptionType.none && (type == null || !type.equals(ANON))) {
        Element pres = new Element("presence");
        pres.setAttribute("to", buddy);
        pres.setAttribute("from", session.getUserId());
        pres.setAttribute("type", "unsubscribe");
        results.offer(new Packet(pres));
        pres = new Element("presence");
        pres.setAttribute("to", buddy);
        pres.setAttribute("from", session.getUserId());
        pres.setAttribute("type", "unsubscribed");
        results.offer(new Packet(pres));
        pres = new Element("presence");
        pres.setAttribute("to", buddy);
        pres.setAttribute("from", session.getJID());
        pres.setAttribute("type", "unavailable");
        results.offer(new Packet(pres));
      }
      // It happens sometimes that the client still think the buddy
      // is in the roster while he isn't. In such a case just ensure the
      // client that the buddy has been removed for sure
      Element it = new Element("item");
      it.setAttribute("jid", buddy);
      it.setAttribute("subscription", "remove");
      roster_util.updateBuddyChange(session, results, it);
      roster_util.removeBuddy(session, buddy);
      results.offer(packet.okResult((String)null, 0));
    } else {
      String name = request.getAttribute("/iq/query/item", "name");
//       if (name == null) {
//         name = buddy;
//       } // end of if (name == null)
      List<Element> groups = item.getChildren();
      String[] gr = null;
      if (groups != null && groups.size() > 0) {
        gr = new String[groups.size()];
        int cnt = 0;
        for (Element group : groups) {
          gr[cnt++] = (group.getCData() == null ? "" : group.getCData());
        } // end of for (ElementData group : groups)
      }
      //roster_util.setBuddyGroups(session, buddy, gr);
      roster_util.addBuddy(session, buddy, name, gr);
      String type = request.getAttribute("/iq/query/item", "type");
      if (type != null && type.equals(ANON)) {
        roster_util.setBuddySubscription(session, SubscriptionType.both, buddy);
        Element pres = (Element)session.getSessionData(Presence.PRESENCE_KEY);
        if (pres == null) {
          pres = new Element("presence");
        } else {
          pres = pres.clone();
        }
        pres.setAttribute("to", buddy);
        pres.setAttribute("from", session.getJID());
        results.offer(new Packet(pres));
      }
      if (roster_util.getBuddySubscription(session, buddy) == null) {
        roster_util.setBuddySubscription(session, SubscriptionType.none, buddy);
      } // end of if (getBuddySubscription(session, buddy) == null)
      results.offer(packet.okResult((String)null, 0));
View Full Code Here

        iq.addChild(query);
        query.addChild(items.poll());
        while (query.getChildren().size() < 20 && items.size() > 0) {
          query.addChild(items.poll());
        }
        Packet rost_res = new Packet(iq);
        rost_res.setTo(session.getConnectionId());
        rost_res.setFrom(packet.getTo());
        results.offer(rost_res);
      }
    }
//     if (session.isAnonymous()) {
//       log.finest("Anonymous session: " + session.getUserId());
View Full Code Here

    update.addChild(query);
    for (XMPPResourceConnection conn: session.getActiveSessions()) {
      Element conn_update = update.clone();
      conn_update.setAttribute("to", conn.getJID());
      conn_update.setAttribute("id", "rst"+session.nextStanzaId());
      Packet pack_update = new Packet(conn_update);
      pack_update.setTo(conn.getConnectionId());
      pack_update.setFrom(session.getJID());
      results.offer(pack_update);
    } // end of for (XMPPResourceConnection conn: sessions)
  }
View Full Code Here

TOP

Related Classes of tigase.server.Packet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.