1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-07 13:41:08 +01:00

applied patches for extracted api for socks5 bytestreams and in-band bytestream

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/improve_bytestreams@11818 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Henning Staib 2010-08-15 10:49:11 +00:00 committed by henning
parent 0540662db2
commit 8cb01900c9
72 changed files with 11761 additions and 1893 deletions

View file

@ -0,0 +1,65 @@
/**
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.ibb.packet;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.ibb.InBandBytestreamManager;
/**
* Represents a request to close an In-Band Bytestream.
*
* @author Henning Staib
*/
public class Close extends IQ {
/* unique session ID identifying this In-Band Bytestream */
private final String sessionID;
/**
* Creates a new In-Band Bytestream close request packet.
*
* @param sessionID unique session ID identifying this In-Band Bytestream
*/
public Close(String sessionID) {
if (sessionID == null || "".equals(sessionID)) {
throw new IllegalArgumentException("Session ID must not be null or empty");
}
this.sessionID = sessionID;
setType(Type.SET);
}
/**
* Returns the unique session ID identifying this In-Band Bytestream.
*
* @return the unique session ID identifying this In-Band Bytestream
*/
public String getSessionID() {
return sessionID;
}
@Override
public String getChildElementXML() {
StringBuilder buf = new StringBuilder();
buf.append("<close ");
buf.append("xmlns=\"");
buf.append(InBandBytestreamManager.NAMESPACE);
buf.append("\" ");
buf.append("sid=\"");
buf.append(sessionID);
buf.append("\"");
buf.append("/>");
return buf.toString();
}
}

View file

@ -0,0 +1,64 @@
/**
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.ibb.packet;
import org.jivesoftware.smack.packet.IQ;
/**
* Represents a chunk of data sent over an In-Band Bytestream encapsulated in an
* IQ stanza.
*
* @author Henning Staib
*/
public class Data extends IQ {
/* the data packet extension */
private final DataPacketExtension dataPacketExtension;
/**
* Constructor.
*
* @param data data packet extension containing the encoded data
*/
public Data(DataPacketExtension data) {
if (data == null) {
throw new IllegalArgumentException("Data must not be null");
}
this.dataPacketExtension = data;
/*
* also set as packet extension so that data packet extension can be
* retrieved from IQ stanza and message stanza in the same way
*/
addExtension(data);
setType(IQ.Type.SET);
}
/**
* Returns the data packet extension.
* <p>
* Convenience method for <code>packet.getExtension("data",
* "http://jabber.org/protocol/ibb")</code>.
*
* @return the data packet extension
*/
public DataPacketExtension getDataPacketExtension() {
return this.dataPacketExtension;
}
public String getChildElementXML() {
return this.dataPacketExtension.toXML();
}
}

View file

@ -0,0 +1,149 @@
/**
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.ibb.packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.ibb.InBandBytestreamManager;
/**
* Represents a chunk of data of an In-Band Bytestream within an IQ stanza or a
* message stanza
*
* @author Henning Staib
*/
public class DataPacketExtension implements PacketExtension {
/**
* The element name of the data packet extension.
*/
public final static String ELEMENT_NAME = "data";
/* unique session ID identifying this In-Band Bytestream */
private final String sessionID;
/* sequence of this packet in regard to the other data packets */
private final long seq;
/* the data contained in this packet */
private final String data;
private byte[] decodedData;
/**
* Creates a new In-Band Bytestream data packet.
*
* @param sessionID unique session ID identifying this In-Band Bytestream
* @param seq sequence of this packet in regard to the other data packets
* @param data the base64 encoded data contained in this packet
*/
public DataPacketExtension(String sessionID, long seq, String data) {
if (sessionID == null || "".equals(sessionID)) {
throw new IllegalArgumentException("Session ID must not be null or empty");
}
if (seq < 0 || seq > 65535) {
throw new IllegalArgumentException("Sequence must not be between 0 and 65535");
}
if (data == null) {
throw new IllegalArgumentException("Data must not be null");
}
this.sessionID = sessionID;
this.seq = seq;
this.data = data;
}
/**
* Returns the unique session ID identifying this In-Band Bytestream.
*
* @return the unique session ID identifying this In-Band Bytestream
*/
public String getSessionID() {
return sessionID;
}
/**
* Returns the sequence of this packet in regard to the other data packets.
*
* @return the sequence of this packet in regard to the other data packets.
*/
public long getSeq() {
return seq;
}
/**
* Returns the data contained in this packet.
*
* @return the data contained in this packet.
*/
public String getData() {
return data;
}
/**
* Returns the decoded data or null if data could not be decoded.
* <p>
* The encoded data is invalid if it contains bad Base64 input characters or
* if it contains the pad ('=') character on a position other than the last
* character(s) of the data. See <a
* href="http://xmpp.org/extensions/xep-0047.html#sec">XEP-0047</a> Section
* 6.
*
* @return the decoded data
*/
public byte[] getDecodedData() {
// return cached decoded data
if (this.decodedData != null) {
return this.decodedData;
}
// data must not contain the pad (=) other than end of data
if (data.matches(".*={1,2}+.+")) {
return null;
}
// decodeBase64 will return null if bad characters are included
this.decodedData = StringUtils.decodeBase64(data);
return this.decodedData;
}
public String getElementName() {
return ELEMENT_NAME;
}
public String getNamespace() {
return InBandBytestreamManager.NAMESPACE;
}
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<");
buf.append(getElementName());
buf.append(" ");
buf.append("xmlns=\"");
buf.append(InBandBytestreamManager.NAMESPACE);
buf.append("\" ");
buf.append("seq=\"");
buf.append(seq);
buf.append("\" ");
buf.append("sid=\"");
buf.append(sessionID);
buf.append("\">");
buf.append(data);
buf.append("</");
buf.append(getElementName());
buf.append(">");
return buf.toString();
}
}

View file

@ -0,0 +1,126 @@
/**
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.ibb.packet;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.ibb.InBandBytestreamManager;
import org.jivesoftware.smackx.ibb.InBandBytestreamManager.StanzaType;
/**
* Represents a request to open an In-Band Bytestream.
*
* @author Henning Staib
*/
public class Open extends IQ {
/* unique session ID identifying this In-Band Bytestream */
private final String sessionID;
/* block size in which the data will be fragmented */
private final int blockSize;
/* stanza type used to encapsulate the data */
private final StanzaType stanza;
/**
* Creates a new In-Band Bytestream open request packet.
* <p>
* The data sent over this In-Band Bytestream will be fragmented in blocks
* with the given block size. The block size should not be greater than
* 65535. A recommended default value is 4096.
* <p>
* The data can be sent using IQ stanzas or message stanzas.
*
* @param sessionID unique session ID identifying this In-Band Bytestream
* @param blockSize block size in which the data will be fragmented
* @param stanza stanza type used to encapsulate the data
*/
public Open(String sessionID, int blockSize, StanzaType stanza) {
if (sessionID == null || "".equals(sessionID)) {
throw new IllegalArgumentException("Session ID must not be null or empty");
}
if (blockSize <= 0) {
throw new IllegalArgumentException("Block size must be greater than zero");
}
this.sessionID = sessionID;
this.blockSize = blockSize;
this.stanza = stanza;
setType(Type.SET);
}
/**
* Creates a new In-Band Bytestream open request packet.
* <p>
* The data sent over this In-Band Bytestream will be fragmented in blocks
* with the given block size. The block size should not be greater than
* 65535. A recommended default value is 4096.
* <p>
* The data will be sent using IQ stanzas.
*
* @param sessionID unique session ID identifying this In-Band Bytestream
* @param blockSize block size in which the data will be fragmented
*/
public Open(String sessionID, int blockSize) {
this(sessionID, blockSize, StanzaType.IQ);
}
/**
* Returns the unique session ID identifying this In-Band Bytestream.
*
* @return the unique session ID identifying this In-Band Bytestream
*/
public String getSessionID() {
return sessionID;
}
/**
* Returns the block size in which the data will be fragmented.
*
* @return the block size in which the data will be fragmented
*/
public int getBlockSize() {
return blockSize;
}
/**
* Returns the stanza type used to encapsulate the data.
*
* @return the stanza type used to encapsulate the data
*/
public StanzaType getStanza() {
return stanza;
}
@Override
public String getChildElementXML() {
StringBuilder buf = new StringBuilder();
buf.append("<open ");
buf.append("xmlns=\"");
buf.append(InBandBytestreamManager.NAMESPACE);
buf.append("\" ");
buf.append("block-size=\"");
buf.append(blockSize);
buf.append("\" ");
buf.append("sid=\"");
buf.append(sessionID);
buf.append("\" ");
buf.append("stanza=\"");
buf.append(stanza.toString().toLowerCase());
buf.append("\"");
buf.append("/>");
return buf.toString();
}
}