private void refreshRegisterInfo(){ Registration packet = new Registration(); packet.setFrom(connection.getUser()); packet.setType(IQ.Type.GET); packet.setTo(entityJID); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(packet.getPacketID())); connection.sendPacket(packet); Packet result = collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if(result instanceof Registration && result.getError()==null){ Registration register = (Registration)result; this.registerInfo = register; } }
private static Registration parseRegistration(XmlPullParser parser) throws Exception { Registration registration = new Registration(); Map<String, String> fields = null; boolean done = false; registration.setInstructions(value); registration.addExtension( PacketParserUtils.parsePacketExtension( parser.getName(), registration.setAttributes(fields); return registration;
/** * Returns the value of a given account attribute or <tt>null</tt> if the account * attribute wasn't found. * * @param name the name of the account attribute to return its value. * @return the value of the account attribute or <tt>null</tt> if an account * attribute wasn't found for the requested name. */ public String getAccountAttribute(String name) { try { if (info == null) { getRegistrationInfo(); } return (String) info.getAttributes().get(name); } catch (XMPPException xe) { } return null; }
if(getRegisterInfo().isRegistered()) { throw new IllegalStateException("You are already registered with this gateway"); Registration register = new Registration(); register.setFrom(connection.getUser()); register.setTo(entityJID); register.setType(IQ.Type.SET); register.setUsername(username); register.setPassword(password); for(String s : fields.keySet()){ register.addAttribute(s, fields.get(s)); connection.createPacketCollector(new PacketIDFilter(register.getPacketID())); connection.sendPacket(register); Packet result =
/** * 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; } } }
/** * Returns instructions for registering with this gateway * @return String containing instructions */ public String getInstructions(){ return getRegisterInfo().getInstructions(); }
public String getChildElementXML() { StringBuilder buf = new StringBuilder(); buf.append("<query xmlns=\"jabber:iq:register\">"); if (instructions != null) { buf.append("<instructions>").append(instructions).append("</instructions>"); } if (attributes != null && attributes.size() > 0) { for (String name : attributes.keySet()) { String value = attributes.get(name); buf.append("<").append(name).append(">"); buf.append(value); buf.append("</").append(name).append(">"); } } // Add packet extensions, if any are defined. buf.append(getExtensionsXML()); buf.append("</query>"); return buf.toString(); } }
/** * Returns true if the server supports creating new accounts. Many servers require * that you not be currently authenticated when creating new accounts, so the safest * behavior is to only create new accounts before having logged in to a server. * * @return true if the server support creating new accounts. */ public boolean supportsAccountCreation() { try { if (info == null) { getRegistrationInfo(); } return info.getType() != IQ.Type.ERROR; } catch (XMPPException xe) { return false; } }
/** * 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; } } }
/** * Returns the instructions for creating a new account, or <tt>null</tt> if there * are no instructions. If present, instructions should be displayed to the end-user * that will complete the registration process. * * @return the account creation instructions, or <tt>null</tt> if there are none. */ public String getAccountInstructions() { try { if (info == null) { getRegistrationInfo(); } return info.getInstructions(); } catch (XMPPException xe) { return null; } }
public String getChildElementXML() { StringBuilder buf = new StringBuilder(); buf.append("<query xmlns=\"jabber:iq:register\">"); if (instructions != null && !remove) { buf.append("<instructions>").append(instructions).append("</instructions>"); } if (attributes != null && attributes.size() > 0 && !remove) { for (String name : attributes.keySet()) { String value = attributes.get(name); buf.append("<").append(name).append(">"); buf.append(value); buf.append("</").append(name).append(">"); } } else if(remove){ buf.append("</remove>"); } // Add packet extensions, if any are defined. buf.append(getExtensionsXML()); buf.append("</query>"); return buf.toString(); } }
/** * Returns true if the server supports creating new accounts. Many servers require * that you not be currently authenticated when creating new accounts, so the safest * behavior is to only create new accounts before having logged in to a server. * * @return true if the server support creating new accounts. */ public boolean supportsAccountCreation() { // Check if we already know that the server supports creating new accounts if (accountCreationSupported) { return true; } // No information is known yet (e.g. no stream feature was received from the server // indicating that it supports creating new accounts) so send an IQ packet as a way // to discover if this feature is supported try { if (info == null) { getRegistrationInfo(); accountCreationSupported = info.getType() != IQ.Type.ERROR; } return accountCreationSupported; } catch (XMPPException xe) { return false; } }
Registration register = new Registration(); register.setFrom(connection.getUser()); register.setTo(entityJID); register.setType(IQ.Type.SET); register.setRemove(true); PacketCollector resultCollector = connection.createPacketCollector(new PacketIDFilter(register.getPacketID())); connection.sendPacket(register); Packet result = resultCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
private static Registration parseRegistration(XmlPullParser parser) throws Exception { Registration registration = new Registration(); Map<String, String> fields = null; boolean done = false; fields.put(name, value); } else { registration.setInstructions(value); registration.addExtension( PacketParserUtils.parsePacketExtension( parser.getName(), registration.setAttributes(fields); return registration;
/** * 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; } } }
getRegistrationInfo(); Map attributes = info.getAttributes(); if (attributes != null) { return attributes.keySet().iterator();
/** * Returns the instructions for creating a new account, or <tt>null</tt> if there * are no instructions. If present, instructions should be displayed to the end-user * that will complete the registration process. * * @return the account creation instructions, or <tt>null</tt> if there are none. */ public String getAccountInstructions() { try { if (info == null) { getRegistrationInfo(); } return info.getInstructions(); } catch (XMPPException xe) { return null; } }
public String getChildElementXML() { StringBuilder buf = new StringBuilder(); buf.append("<query xmlns=\"jabber:iq:register\">"); if (instructions != null) { buf.append("<instructions>").append(instructions).append("</instructions>"); } if (attributes != null && attributes.size() > 0) { for (String name : attributes.keySet()) { String value = attributes.get(name); buf.append("<").append(name).append(">"); buf.append(value); buf.append("</").append(name).append(">"); } } // Add packet extensions, if any are defined. buf.append(getExtensionsXML()); buf.append("</query>"); return buf.toString(); } }
/** * Returns true if the server supports creating new accounts. Many servers require * that you not be currently authenticated when creating new accounts, so the safest * behavior is to only create new accounts before having logged in to a server. * * @return true if the server support creating new accounts. */ public boolean supportsAccountCreation() { // Check if we already know that the server supports creating new accounts if (accountCreationSupported) { return true; } // No information is known yet (e.g. no stream feature was received from the server // indicating that it supports creating new accounts) so send an IQ packet as a way // to discover if this feature is supported try { if (info == null) { getRegistrationInfo(); accountCreationSupported = info.getType() != IQ.Type.ERROR; } return accountCreationSupported; } catch (XMPPException xe) { return false; } }
/** * 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()); } }