@Override protected synchronized void writeToXML(DataPacketExtension data) throws IOException { // create IQ stanza containing data packet IQ iq = new Data(data); iq.setTo(remoteJID); try { SyncPacketSend.getReply(connection, iq); } catch (XMPPException e) { // close session unless it is already closed if (!this.isClosed) { InBandBytestreamSession.this.close(); throw new IOException("Error while sending Data: " + e.getMessage()); } } }
/** * Returns a list of stream hosts containing the IP address an the port for the given list of * SOCKS5 proxy JIDs. The order of the returned list is the same as the given list of JIDs * excluding all SOCKS5 proxies who's network settings could not be determined. If a local * SOCKS5 proxy is running it will be the first item in the list returned. * * @param proxies a list of SOCKS5 proxy JIDs * @return a list of stream hosts containing the IP address an the port */ private List<StreamHost> determineStreamHostInfos(List<String> proxies) { List<StreamHost> streamHosts = new ArrayList<StreamHost>(); // add local proxy on first position if exists List<StreamHost> localProxies = getLocalStreamHost(); if (localProxies != null) { streamHosts.addAll(localProxies); } // query SOCKS5 proxies for network settings for (String proxy : proxies) { Bytestream streamHostRequest = createStreamHostRequest(proxy); try { Bytestream response = (Bytestream) SyncPacketSend.getReply(this.connection, streamHostRequest); streamHosts.addAll(response.getStreamHosts()); } catch (XMPPException e) { // blacklist errornous proxies this.proxyBlacklist.add(proxy); } } return streamHosts; }
/** * Establishes an In-Band Bytestream with the given user using the given * session ID and returns the session to send/receive data to/from the user. * * @param targetJID * the JID of the user an In-Band Bytestream should be * established * @param sessionID * the session ID for the In-Band Bytestream request * @return the session to send/receive data to/from the user * @throws XMPPException * if the user doesn't support or accept in-band bytestreams, or * if the user prefers smaller block sizes */ public InBandBytestreamSession establishSession(String targetJID, String sessionID) throws XMPPException { Open byteStreamRequest = new Open(sessionID, this.defaultBlockSize, this.stanza); byteStreamRequest.setTo(targetJID); // sending packet will throw exception on timeout or error reply SyncPacketSend.getReply(this.connection, byteStreamRequest); InBandBytestreamSession inBandBytestreamSession = new InBandBytestreamSession( this.connection, byteStreamRequest, targetJID); this.sessions.put(sessionID, inBandBytestreamSession); return inBandBytestreamSession; }
/** * Returns a list of stream hosts containing the IP address an the port for * the given list of SOCKS5 proxy JIDs. The order of the returned list is * the same as the given list of JIDs excluding all SOCKS5 proxies who's * network settings could not be determined. If a local SOCKS5 proxy is * running it will be the first item in the list returned. * * @param proxies * a list of SOCKS5 proxy JIDs * @return a list of stream hosts containing the IP address an the port */ private List<StreamHost> determineStreamHostInfos(List<String> proxies) { List<StreamHost> streamHosts = new ArrayList<StreamHost>(); // add local proxy on first position if exists List<StreamHost> localProxies = getLocalStreamHost(); if (localProxies != null) { streamHosts.addAll(localProxies); } // query SOCKS5 proxies for network settings for (String proxy : proxies) { Bytestream streamHostRequest = createStreamHostRequest(proxy); try { Bytestream response = (Bytestream) SyncPacketSend.getReply( this.connection, streamHostRequest); streamHosts.addAll(response.getStreamHosts()); } catch (XMPPException e) { // blacklist errornous proxies this.proxyBlacklist.add(proxy); } } return streamHosts; }
/** * Establishes an In-Band Bytestream with the given user using the given session ID and returns * the session to send/receive data to/from the user. * * @param targetJID the JID of the user an In-Band Bytestream should be established * @param sessionID the session ID for the In-Band Bytestream request * @return the session to send/receive data to/from the user * @throws XMPPException if the user doesn't support or accept in-band bytestreams, or if the * user prefers smaller block sizes */ public InBandBytestreamSession establishSession(String targetJID, String sessionID) throws XMPPException { Open byteStreamRequest = new Open(sessionID, this.defaultBlockSize, this.stanza); byteStreamRequest.setTo(targetJID); // sending packet will throw exception on timeout or error reply SyncPacketSend.getReply(this.connection, byteStreamRequest); InBandBytestreamSession inBandBytestreamSession = new InBandBytestreamSession( this.connection, byteStreamRequest, targetJID); this.sessions.put(sessionID, inBandBytestreamSession); return inBandBytestreamSession; }
/** * This method is invoked if one of the streams has been closed locally, if an error occurred * locally or if the whole session should be closed. * * @throws IOException if an error occurs while sending the close request */ protected synchronized void closeByLocal(boolean in) throws IOException { if (this.isClosed) { return; } if (this.closeBothStreamsEnabled) { this.inputStream.closeInternal(); this.outputStream.closeInternal(true); } else { if (in) { this.inputStream.closeInternal(); } else { // close stream but try to send any data left this.outputStream.closeInternal(true); } } if (this.inputStream.isClosed && this.outputStream.isClosed) { this.isClosed = true; // send close request Close close = new Close(this.byteStreamRequest.getSessionID()); close.setTo(this.remoteJID); try { SyncPacketSend.getReply(this.connection, close); } catch (XMPPException e) { throw new IOException("Error while closing stream: " + e.getMessage()); } this.inputStream.cleanup(); // remove session from manager InBandBytestreamManager.getByteStreamManager(this.connection).getSessions().remove(this); } }
/** * This method is invoked if one of the streams has been closed locally, if * an error occurred locally or if the whole session should be closed. * * @throws IOException * if an error occurs while sending the close request */ protected synchronized void closeByLocal(boolean in) throws IOException { if (this.isClosed) { return; } if (this.closeBothStreamsEnabled) { this.inputStream.closeInternal(); this.outputStream.closeInternal(true); } else { if (in) { this.inputStream.closeInternal(); } else { // close stream but try to send any data left this.outputStream.closeInternal(true); } } if (this.inputStream.isClosed && this.outputStream.isClosed) { this.isClosed = true; // send close request Close close = new Close(this.byteStreamRequest.getSessionID()); close.setTo(this.remoteJID); try { SyncPacketSend.getReply(this.connection, close); } catch (XMPPException e) { throw new IOException("Error while closing stream: " + e.getMessage()); } this.inputStream.cleanup(); // remove session from manager InBandBytestreamManager.getByteStreamManager(this.connection) .getSessions().remove(this); } }
public void createAccount(String bareJid, String password, Map<String, String> attributes) throws XMPPException { checkAccountCreationSupported(); Registration reg = new Registration(); reg.setType(IQ.Type.set); XMPPConnection connection = getXMPPClient().getConnection(); reg.setTo(connection.getServiceName()); attributes.put("username", new JID(bareJid).getNode()); attributes.put("password", password); reg.setAttributes(attributes); SyncPacketSend.getReply(connection, reg); }
public void changePassword(String newPassword) throws XMPPException { Registration reg = new Registration(); reg.setType(IQ.Type.set); XMPPConnection connection = getXMPPClient().getConnection(); 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); SyncPacketSend.getReply(connection, reg); }
public void deleteAccount() throws XMPPException { XMPPConnection connection = getXMPPClient().getConnection(); 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>(); attributes.put("remove", ""); reg.setAttributes(attributes); SyncPacketSend.getReply(connection, reg); }
private synchronized Registration getRegistrationInfo() throws XMPPException { XMPPConnection connection = getXMPPClient().getConnection(); Registration reg = new Registration(); reg.setTo(connection.getServiceName()); return (Registration) SyncPacketSend.getReply(connection, reg); }
public Packet syncSend(Packet packet) throws XMPPException { return SyncPacketSend.getReply(connection, packet); }