Java 类org.jivesoftware.smack.filter.PacketFilter 实例源码

项目:EIM    文件:AccountManager.java   
/**
 * Changes the password of the currently logged-in account. This operation can only
 * be performed after a successful login operation has been completed. Not all servers
 * support changing passwords; an XMPPException will be thrown when that is the case.
 *
 * @throws IllegalStateException if not currently logged-in to the server.
 * @throws XMPPException if an error occurs when changing the password.
 */
public void changePassword(String newPassword) throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(connection.getServiceName());
    Map<String, String> map = new HashMap<String, String>();
    map.put("username",StringUtils.parseName(connection.getUser()));
    map.put("password",newPassword);
    reg.setAttributes(map);
    PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
            new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
}
项目:EIM    文件:AccountManager.java   
/**
 * Deletes the currently logged-in account from the server. This operation can only
 * be performed after a successful login operation has been completed. Not all servers
 * support deleting accounts; an XMPPException will be thrown when that is the case.
 *
 * @throws IllegalStateException if not currently logged-in to the server.
 * @throws XMPPException if an error occurs when deleting the account.
 */
public void deleteAccount() throws XMPPException {
    if (!connection.isAuthenticated()) {
        throw new IllegalStateException("Must be logged in to delete a account.");
    }
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(connection.getServiceName());
    Map<String, String> attributes = new HashMap<String, String>();
    // To delete an account, we add a single attribute, "remove", that is blank.
    attributes.put("remove", "");
    reg.setAttributes(attributes);
    PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
            new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
}
项目:EIM    文件:AccountManager.java   
/**
 * Gets the account registration info from the server.
 *
 * @throws XMPPException if an error occurs.
 */
private synchronized void getRegistrationInfo() throws XMPPException {
    Registration reg = new Registration();
    reg.setTo(connection.getServiceName());
    PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
            new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
    else {
        info = (Registration)result;
    }
}
项目:EIM    文件:MultiUserChat.java   
/**
 * Returns the room's configuration form that the room's owner can use or <tt>null</tt> if
 * no configuration is possible. The configuration form allows to set the room's language,
 * enable logging, specify room's type, etc..
 *
 * @return the Form that contains the fields to complete together with the instrucions or
 * <tt>null</tt> if no configuration is possible.
 * @throws XMPPException if an error occurs asking the configuration form for the room.
 */
public Form getConfigurationForm() throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.GET);

    // Filter packets looking for an answer from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Request the configuration form to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
    return Form.getFormFrom(answer);
}
项目:EIM    文件:MultiUserChat.java   
/**
 * Sends the completed configuration form to the server. The room will be configured
 * with the new settings defined in the form. If the form is empty then the server
 * will create an instant room (will use default configuration).
 *
 * @param form the form with the new settings.
 * @throws XMPPException if an error occurs setting the new rooms' configuration.
 */
public void sendConfigurationForm(Form form) throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    iq.addExtension(form.getDataFormToSend());

    // Filter packets looking for an answer from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the completed configuration form to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
项目:EIM    文件:MultiUserChat.java   
/**
 * Returns the room's registration form that an unaffiliated user, can use to become a member
 * of the room or <tt>null</tt> if no registration is possible. Some rooms may restrict the
 * privilege to register members and allow only room admins to add new members.<p>
 *
 * If the user requesting registration requirements is not allowed to register with the room
 * (e.g. because that privilege has been restricted), the room will return a "Not Allowed"
 * error to the user (error code 405).
 *
 * @return the registration Form that contains the fields to complete together with the
 * instrucions or <tt>null</tt> if no registration is possible.
 * @throws XMPPException if an error occurs asking the registration form for the room or a
 * 405 error if the user is not allowed to register with the room.
 */
public Form getRegistrationForm() throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.GET);
    reg.setTo(room);

    PacketFilter filter =
        new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
    return Form.getFormFrom(result);
}
项目:EIM    文件:MultiUserChat.java   
/**
 * Sends the completed registration form to the server. After the user successfully submits
 * the form, the room may queue the request for review by the room admins or may immediately
 * add the user to the member list by changing the user's affiliation from "none" to "member.<p>
 *
 * If the desired room nickname is already reserved for that room, the room will return a
 * "Conflict" error to the user (error code 409). If the room does not support registration,
 * it will return a "Service Unavailable" error to the user (error code 503).
 *
 * @param form the completed registration form.
 * @throws XMPPException if an error occurs submitting the registration form. In particular, a
 *      409 error can occur if the desired room nickname is already reserved for that room;
 *      or a 503 error can occur if the room does not support registration.
 */
public void sendRegistrationForm(Form form) throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(room);
    reg.addExtension(form.getDataFormToSend());

    PacketFilter filter =
        new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
}
项目:EIM    文件:MultiUserChat.java   
private void changeAffiliationByOwner(String jid, String affiliation) throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    // Set the new affiliation.
    MUCOwner.Item item = new MUCOwner.Item(affiliation);
    item.setJid(jid);
    iq.addItem(item);

    // Wait for a response packet back from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the change request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
项目:androidPN-client.    文件:AgentRoster.java   
/**
 * Constructs a new AgentRoster.
 *
 * @param connection an XMPP connection.
 */
AgentRoster(Connection connection, String workgroupJID) {
    this.connection = connection;
    this.workgroupJID = workgroupJID;
    entries = new ArrayList<String>();
    listeners = new ArrayList<AgentRosterListener>();
    presenceMap = new HashMap<String, Map<String, Presence>>();
    // Listen for any roster packets.
    PacketFilter rosterFilter = new PacketTypeFilter(AgentStatusRequest.class);
    connection.addPacketListener(new AgentStatusListener(), rosterFilter);
    // Listen for any presence packets.
    connection.addPacketListener(new PresencePacketListener(),
            new PacketTypeFilter(Presence.class));

    // Send request for roster.
    AgentStatusRequest request = new AgentStatusRequest();
    request.setTo(workgroupJID);
    connection.sendPacket(request);
}
项目:EIM    文件:SyncPacketSend.java   
static public Packet getReply(Connection connection, Packet packet, long timeout)
    throws XMPPException
{
       PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
       PacketCollector response = connection.createPacketCollector(responseFilter);

       connection.sendPacket(packet);

       // Wait up to a certain number of seconds for a reply.
       Packet result = response.nextResult(timeout);

       // Stop queuing results
       response.cancel();

       if (result == null) {
           throw new XMPPException("No response from server.");
       }
       else if (result.getError() != null) {
           throw new XMPPException(result.getError());
       }
       return result;
}
项目:EIM    文件:AgentRoster.java   
/**
 * Constructs a new AgentRoster.
 *
 * @param connection an XMPP connection.
 */
AgentRoster(Connection connection, String workgroupJID) {
    this.connection = connection;
    this.workgroupJID = workgroupJID;
    entries = new ArrayList<String>();
    listeners = new ArrayList<AgentRosterListener>();
    presenceMap = new HashMap<String, Map<String, Presence>>();
    // Listen for any roster packets.
    PacketFilter rosterFilter = new PacketTypeFilter(AgentStatusRequest.class);
    connection.addPacketListener(new AgentStatusListener(), rosterFilter);
    // Listen for any presence packets.
    connection.addPacketListener(new PresencePacketListener(),
            new PacketTypeFilter(Presence.class));

    // Send request for roster.
    AgentStatusRequest request = new AgentStatusRequest();
    request.setTo(workgroupJID);
    connection.sendPacket(request);
}
项目:EIM    文件:SyncPacketSend.java   
static public Packet getReply(Connection connection, Packet packet, long timeout)
    throws XMPPException
{
       PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
       PacketCollector response = connection.createPacketCollector(responseFilter);

       connection.sendPacket(packet);

       // Wait up to a certain number of seconds for a reply.
       Packet result = response.nextResult(timeout);

       // Stop queuing results
       response.cancel();

       if (result == null) {
           throw new XMPPException("No response from server.");
       }
       else if (result.getError() != null) {
           throw new XMPPException(result.getError());
       }
       return result;
}
项目:EIM    文件:IMContactService.java   
/**
 * ���һ�����������������������
 */
private void addSubscriptionListener() {
    PacketFilter filter = new PacketFilter() {
        @Override
        public boolean accept(Packet packet) {
            if (packet instanceof Presence) {
                Presence presence = (Presence) packet;
                if (presence.getType().equals(Presence.Type.subscribe)) {
                    return true;
                }
            }
            return false;
        }
    };
    XmppConnectionManager.getInstance().getConnection()
            .addPacketListener(subscriptionPacketListener, filter);
}
项目:androidpn_enhanced_client    文件:AccountManager.java   
/**
 * Changes the password of the currently logged-in account. This operation can only
 * be performed after a successful login operation has been completed. Not all servers
 * support changing passwords; an XMPPException will be thrown when that is the case.
 *
 * @throws IllegalStateException if not currently logged-in to the server.
 * @throws XMPPException if an error occurs when changing the password.
 */
public void changePassword(String newPassword) throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(connection.getServiceName());
    reg.setUsername(StringUtils.parseName(connection.getUser()));
    reg.setPassword(newPassword);
    PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
            new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
}
项目:androidPN-client.    文件:SyncPacketSend.java   
static public Packet getReply(Connection connection, Packet packet, long timeout)
    throws XMPPException
{
       PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
       PacketCollector response = connection.createPacketCollector(responseFilter);

       connection.sendPacket(packet);

       // Wait up to a certain number of seconds for a reply.
       Packet result = response.nextResult(timeout);

       // Stop queuing results
       response.cancel();

       if (result == null) {
           throw new XMPPException("No response from server.");
       }
       else if (result.getError() != null) {
           throw new XMPPException(result.getError());
       }
       return result;
}
项目:androidPN-client.    文件:Roster.java   
/**
 * Reloads the entire roster from the server. This is an asynchronous operation,
 * which means the method will return immediately, and the roster will be
 * reloaded at a later point when the server responds to the reload request.
 * 
 * @throws IllegalStateException if connection is not logged in or logged in anonymously
 */
public void reload() {
    if (!connection.isAuthenticated()) {
        throw new IllegalStateException("Not logged in to server.");
    }
    if (connection.isAnonymous()) {
        throw new IllegalStateException("Anonymous users can't have a roster.");
    }

    RosterPacket packet = new RosterPacket();
    if(persistentStorage!=null){
        packet.setVersion(persistentStorage.getRosterVersion());
    }
    requestPacketId = packet.getPacketID();
    PacketFilter idFilter = new PacketIDFilter(requestPacketId);
    connection.addPacketListener(new RosterResultListener(), idFilter);
    connection.sendPacket(packet);
}
项目:androidPN-client.    文件:SyncPacketSend.java   
static public Packet getReply(Connection connection, Packet packet, long timeout)
    throws XMPPException
{
       PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
       PacketCollector response = connection.createPacketCollector(responseFilter);

       connection.sendPacket(packet);

       // Wait up to a certain number of seconds for a reply.
       Packet result = response.nextResult(timeout);

       // Stop queuing results
       response.cancel();

       if (result == null) {
           throw new XMPPException("No response from server.");
       }
       else if (result.getError() != null) {
           throw new XMPPException(result.getError());
       }
       return result;
}
项目:androidPN-client.    文件:AccountManager.java   
/**
 * Changes the password of the currently logged-in account. This operation can only
 * be performed after a successful login operation has been completed. Not all servers
 * support changing passwords; an XMPPException will be thrown when that is the case.
 *
 * @throws IllegalStateException if not currently logged-in to the server.
 * @throws XMPPException if an error occurs when changing the password.
 */
public void changePassword(String newPassword) throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(connection.getServiceName());
    Map<String, String> map = new HashMap<String, String>();
    map.put("username",StringUtils.parseName(connection.getUser()));
    map.put("password",newPassword);
    reg.setAttributes(map);
    PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
            new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
}
项目:androidPN-client.    文件:AccountManager.java   
/**
 * Deletes the currently logged-in account from the server. This operation can only
 * be performed after a successful login operation has been completed. Not all servers
 * support deleting accounts; an XMPPException will be thrown when that is the case.
 *
 * @throws IllegalStateException if not currently logged-in to the server.
 * @throws XMPPException if an error occurs when deleting the account.
 */
public void deleteAccount() throws XMPPException {
    if (!connection.isAuthenticated()) {
        throw new IllegalStateException("Must be logged in to delete a account.");
    }
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(connection.getServiceName());
    Map<String, String> attributes = new HashMap<String, String>();
    // To delete an account, we add a single attribute, "remove", that is blank.
    attributes.put("remove", "");
    reg.setAttributes(attributes);
    PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
            new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
}
项目:androidPN-client.    文件:AccountManager.java   
/**
 * Gets the account registration info from the server.
 *
 * @throws XMPPException if an error occurs.
 */
private synchronized void getRegistrationInfo() throws XMPPException {
    Registration reg = new Registration();
    reg.setTo(connection.getServiceName());
    PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
            new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
    else {
        info = (Registration)result;
    }
}
项目:androidPN-client.    文件:MultiUserChat.java   
/**
 * Returns the room's configuration form that the room's owner can use or <tt>null</tt> if
 * no configuration is possible. The configuration form allows to set the room's language,
 * enable logging, specify room's type, etc..
 *
 * @return the Form that contains the fields to complete together with the instrucions or
 * <tt>null</tt> if no configuration is possible.
 * @throws XMPPException if an error occurs asking the configuration form for the room.
 */
public Form getConfigurationForm() throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.GET);

    // Filter packets looking for an answer from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Request the configuration form to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
    return Form.getFormFrom(answer);
}
项目:androidPN-client.    文件:MultiUserChat.java   
/**
 * Sends the completed configuration form to the server. The room will be configured
 * with the new settings defined in the form. If the form is empty then the server
 * will create an instant room (will use default configuration).
 *
 * @param form the form with the new settings.
 * @throws XMPPException if an error occurs setting the new rooms' configuration.
 */
public void sendConfigurationForm(Form form) throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    iq.addExtension(form.getDataFormToSend());

    // Filter packets looking for an answer from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the completed configuration form to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
项目:androidPN-client.    文件:MultiUserChat.java   
/**
 * Returns the room's registration form that an unaffiliated user, can use to become a member
 * of the room or <tt>null</tt> if no registration is possible. Some rooms may restrict the
 * privilege to register members and allow only room admins to add new members.<p>
 *
 * If the user requesting registration requirements is not allowed to register with the room
 * (e.g. because that privilege has been restricted), the room will return a "Not Allowed"
 * error to the user (error code 405).
 *
 * @return the registration Form that contains the fields to complete together with the
 * instrucions or <tt>null</tt> if no registration is possible.
 * @throws XMPPException if an error occurs asking the registration form for the room or a
 * 405 error if the user is not allowed to register with the room.
 */
public Form getRegistrationForm() throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.GET);
    reg.setTo(room);

    PacketFilter filter =
        new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
    return Form.getFormFrom(result);
}
项目:androidPN-client.    文件:MultiUserChat.java   
/**
 * Sends the completed registration form to the server. After the user successfully submits
 * the form, the room may queue the request for review by the room admins or may immediately
 * add the user to the member list by changing the user's affiliation from "none" to "member.<p>
 *
 * If the desired room nickname is already reserved for that room, the room will return a
 * "Conflict" error to the user (error code 409). If the room does not support registration,
 * it will return a "Service Unavailable" error to the user (error code 503).
 *
 * @param form the completed registration form.
 * @throws XMPPException if an error occurs submitting the registration form. In particular, a
 *      409 error can occur if the desired room nickname is already reserved for that room;
 *      or a 503 error can occur if the room does not support registration.
 */
public void sendRegistrationForm(Form form) throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(room);
    reg.addExtension(form.getDataFormToSend());

    PacketFilter filter =
        new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
}
项目:androidPN-client.    文件:MultiUserChat.java   
private void changeAffiliationByOwner(String jid, String affiliation) throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    // Set the new affiliation.
    MUCOwner.Item item = new MUCOwner.Item(affiliation);
    item.setJid(jid);
    iq.addItem(item);

    // Wait for a response packet back from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the change request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
项目:SmackStudy    文件:XMPPUtil.java   
/**
 * 注册用户
 * @param xmppConnection
 * @param userName
 * @param password
 * @return 1、注册成功 0、服务器没有返回结果2、这个账号已经存在3、注册失败
 */
public static int regist(XMPPConnection xmppConnection, String userName, String password) {
    Registration registration = new Registration();
    registration.setType(IQ.Type.SET);
    registration.setTo(xmppConnection.getServiceName());
    registration.setUsername(userName);
    registration.setPassword(password);
    // 这边addAttribute不能为空,否则出错。所以做个标志是android手机创建的吧!!!!!
    registration.addAttribute("android", "fhr");
    PacketFilter filter = new AndFilter(new PacketIDFilter(registration.getPacketID()), new PacketTypeFilter(IQ.class));
    PacketCollector collector = xmppConnection.createPacketCollector(filter);
    xmppConnection.sendPacket(registration);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results停止请求results(是否成功的结果)
    collector.cancel();
    if (result == null) {
        Log.e("regist", "No response from server.");
        return 0;
    } else if (result.getType() == IQ.Type.RESULT) {
        Log.v("regist", "regist success.");
        return 1;
    } else {
        if (result.getError().toString().equalsIgnoreCase("conflict(409)")) {
            Log.e("regist", "IQ.Type.ERROR: " + result.getError().toString());
            return 2;
        } else {
            Log.e("regist", "IQ.Type.ERROR: " + result.getError().toString());
            return 3;
        }
    }
}
项目:AyoSunny    文件:XmppUtil.java   
/** 
 * 注册 
 *  
 * @param account 
 *            注册帐号 
 * @param password 
 *            注册密码 
 * @return 1、注册成功 0、服务器没有返回结果2、这个账号已经存在3、注册失败 
 */  
public static int register(XMPPConnection mXMPPConnection,String account, String password) {  
    Registration reg = new Registration();  
    reg.setType(IQ.Type.SET);  
    reg.setTo(mXMPPConnection.getServiceName());  
    // 注意这里createAccount注册时,参数是UserName,不是jid,是"@"前面的部分。  
    reg.setUsername(account);  
    reg.setPassword(password);  
    // 这边addAttribute不能为空,否则出错。所以做个标志是android手机创建的吧!!!!!  
    reg.addAttribute("android", "geolo_createUser_android");  
    PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));  
    PacketCollector collector =mXMPPConnection.createPacketCollector(filter);  
    mXMPPConnection.sendPacket(reg);  
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());  
    // Stop queuing results停止请求results(是否成功的结果)  
    collector.cancel();  
    if (result == null) {  
        return 0;  
    } else if (result.getType() == IQ.Type.RESULT) {  
        return 1;  
    } else {  
        if (result.getError().toString().equalsIgnoreCase("conflict(409)")) {  
            return 2;  
        } else {  
            return 3;  
        }  
    }  
}
项目:Smack    文件:IQTest.java   
/**
 * Check that the server responds a 503 error code when the client sends an IQ stanza(/packet) with an
 * invalid namespace.
 */
public void testInvalidNamespace() {
    IQ iq = new IQ() {
        public String getChildElementXML() {
            StringBuilder buf = new StringBuilder();
            buf.append("<query xmlns=\"jabber:iq:anything\">");
            buf.append("</query>");
            return buf.toString();
        }
    };

    PacketFilter filter = new AndFilter(new PacketIDFilter(iq.getStanzaId()),
            new StanzaTypeFilter(IQ.class));
    PacketCollector collector = getConnection(0).createPacketCollector(filter);
    // Send the iq packet with an invalid namespace
    getConnection(0).sendStanza(iq);

    IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        fail("No response from server");
    }
    else if (result.getType() != IQ.Type.error) {
        fail("The server didn't reply with an error packet");
    }
    else {
        assertEquals("Server answered an incorrect error code", 503, result.getError().getCode());
    }
}
项目:synergynet3.1    文件:MessagingManager.java   
/**
 * Sets the connection.
 *
 * @param xmpp
 *            the new connection
 */
public void setConnection(XMPPConnection xmpp)
{
    this.xmpp = xmpp;
    this.xmpp.addPacketListener(this, new PacketFilter()
    {
        @Override
        public boolean accept(Packet p)
        {
            return true;
        }
    });
}
项目:EIM    文件:ChatManager.java   
void sendMessage(Chat chat, Message message) {
    for(Map.Entry<PacketInterceptor, PacketFilter> interceptor : interceptors.entrySet()) {
        PacketFilter filter = interceptor.getValue();
        if(filter != null && filter.accept(message)) {
            interceptor.getKey().interceptPacket(message);
        }
    }
    // Ensure that messages being sent have a proper FROM value
    if (message.getFrom() == null) {
        message.setFrom(connection.getUser());
    }
    connection.sendPacket(message);
}
项目:androidPN-client.    文件:InBandBytestreamSession.java   
protected PacketFilter getDataPacketFilter() {
    /*
     * filter all IQ stanzas having type 'SET' (represented by Data class), containing a
     * data packet extension, matching session ID and recipient
     */
    return new AndFilter(new PacketTypeFilter(Data.class), new IBBDataPacketFilter());
}
项目:EIM    文件:AccountManager.java   
/**
 * Creates a new account using the specified username, password and account attributes.
 * The attributes Map must contain only String name/value pairs and must also have values
 * for all required attributes.
 *
 * @param username the username.
 * @param password the password.
 * @param attributes the account attributes.
 * @throws XMPPException if an error occurs creating the account.
 * @see #getAccountAttributes()
 */
public void createAccount(String username, String password, Map<String, String> attributes)
        throws XMPPException
{
    if (!supportsAccountCreation()) {
        throw new XMPPException("Server does not support account creation.");
    }
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(connection.getServiceName());
    attributes.put("username",username);
    attributes.put("password",password);
    reg.setAttributes(attributes);
    PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
            new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
}
项目:EIM    文件:MultiUserChat.java   
private void changeAffiliationByOwner(Collection<String> jids, String affiliation)
        throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    for (String jid : jids) {
        // Set the new affiliation.
        MUCOwner.Item item = new MUCOwner.Item(affiliation);
        item.setJid(jid);
        iq.addItem(item);
    }

    // Wait for a response packet back from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the change request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
项目:EIM    文件:MultiUserChat.java   
private void changeAffiliationByAdmin(String jid, String affiliation, String reason)
        throws XMPPException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    // Set the new affiliation.
    MUCAdmin.Item item = new MUCAdmin.Item(affiliation, null);
    item.setJid(jid);
    item.setReason(reason);
    iq.addItem(item);

    // Wait for a response packet back from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the change request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
项目:EIM    文件:MultiUserChat.java   
private void changeRole(String nickname, String role, String reason) throws XMPPException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    // Set the new role.
    MUCAdmin.Item item = new MUCAdmin.Item(null, role);
    item.setNick(nickname);
    item.setReason(reason);
    iq.addItem(item);

    // Wait for a response packet back from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the change request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
项目:EIM    文件:MultiUserChat.java   
private void changeRole(Collection<String> nicknames, String role) throws XMPPException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    for (String nickname : nicknames) {
        // Set the new role.
        MUCAdmin.Item item = new MUCAdmin.Item(null, role);
        item.setNick(nickname);
        iq.addItem(item);
    }

    // Wait for a response packet back from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the change request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
项目:EIM    文件:MultiUserChat.java   
/**
 * Returns a collection of <code>Affiliate</code> that have the specified room affiliation
 * sending a request in the owner namespace.
 *
 * @param affiliation the affiliation of the users in the room.
 * @return a collection of <code>Affiliate</code> that have the specified room affiliation.
 * @throws XMPPException if an error occured while performing the request to the server or you
 *         don't have enough privileges to get this information.
 */
private Collection<Affiliate> getAffiliatesByOwner(String affiliation) throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.GET);
    // Set the specified affiliation. This may request the list of owners/admins/members/outcasts.
    MUCOwner.Item item = new MUCOwner.Item(affiliation);
    iq.addItem(item);

    // Wait for a response packet back from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    MUCOwner answer = (MUCOwner) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
    // Get the list of affiliates from the server's answer
    List<Affiliate> affiliates = new ArrayList<Affiliate>();
    for (Iterator it = answer.getItems(); it.hasNext();) {
        affiliates.add(new Affiliate((MUCOwner.Item) it.next()));
    }
    return affiliates;
}
项目:EIM    文件:MultiUserChat.java   
/**
 * Returns a collection of <code>Affiliate</code> that have the specified room affiliation
 * sending a request in the admin namespace.
 *
 * @param affiliation the affiliation of the users in the room.
 * @return a collection of <code>Affiliate</code> that have the specified room affiliation.
 * @throws XMPPException if an error occured while performing the request to the server or you
 *         don't have enough privileges to get this information.
 */
private Collection<Affiliate> getAffiliatesByAdmin(String affiliation) throws XMPPException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.GET);
    // Set the specified affiliation. This may request the list of owners/admins/members/outcasts.
    MUCAdmin.Item item = new MUCAdmin.Item(affiliation, null);
    iq.addItem(item);

    // Wait for a response packet back from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    MUCAdmin answer = (MUCAdmin) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
    // Get the list of affiliates from the server's answer
    List<Affiliate> affiliates = new ArrayList<Affiliate>();
    for (Iterator it = answer.getItems(); it.hasNext();) {
        affiliates.add(new Affiliate((MUCAdmin.Item) it.next()));
    }
    return affiliates;
}
项目:EIM    文件:MultiUserChat.java   
/**
 * Returns a collection of <code>Occupant</code> that have the specified room role.
 *
 * @param role the role of the occupant in the room.
 * @return a collection of <code>Occupant</code> that have the specified room role.
 * @throws XMPPException if an error occured while performing the request to the server or you
 *         don't have enough privileges to get this information.
 */
private Collection<Occupant> getOccupants(String role) throws XMPPException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.GET);
    // Set the specified role. This may request the list of moderators/participants.
    MUCAdmin.Item item = new MUCAdmin.Item(null, role);
    iq.addItem(item);

    // Wait for a response packet back from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    MUCAdmin answer = (MUCAdmin) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
    // Get the list of participants from the server's answer
    List<Occupant> participants = new ArrayList<Occupant>();
    for (Iterator it = answer.getItems(); it.hasNext();) {
        participants.add(new Occupant((MUCAdmin.Item) it.next()));
    }
    return participants;
}
项目:androidPN-client.    文件:Socks5TransferNegotiator.java   
@Override
public PacketFilter getInitiationPacketFilter(final String from, String streamID) {
    /*
     * this method is always called prior to #negotiateIncomingStream() so the SOCKS5
     * InitiationListener must ignore the next SOCKS5 Bytestream request with the given session
     * ID
     */
    this.manager.ignoreBytestreamRequestOnce(streamID);

    return new AndFilter(new FromMatchesFilter(from), new BytestreamSIDFilter(streamID));
}