1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 18:59:41 +02:00

Merge of 3.2 stream back into trunk

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@12965 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
rcollier 2012-02-07 04:32:59 +00:00
commit 6dc64671e2
21 changed files with 254 additions and 91 deletions

View file

@ -44,14 +44,14 @@ import java.util.*;
*/
public final class SmackConfiguration {
private static final String SMACK_VERSION = "3.2.1";
private static final String SMACK_VERSION = "3.2.2";
private static int packetReplyTimeout = 5000;
private static int keepAliveInterval = 30000;
private static Vector<String> defaultMechs = new Vector<String>();
private static boolean localSocks5ProxyEnabled = true;
private static int localSocks5ProxyPort = 7778;
private static int localSocks5ProxyPort = 7777;
private static int packetCollectorSize = 5000;
private SmackConfiguration() {

View file

@ -0,0 +1,109 @@
/**
* 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.smack.provider;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.pubsub.provider.ItemProvider;
import org.jivesoftware.smackx.pubsub.provider.ItemsProvider;
import org.xmlpull.v1.XmlPullParser;
/**
*
* This class simplifies parsing of embedded elements by using the
* <a href="http://en.wikipedia.org/wiki/Template_method_pattern">Template Method Pattern</a>.
* After extracting the current element attributes and content of any child elements, the template method
* ({@link #createReturnExtension(String, String, Map, List)} is called. Subclasses
* then override this method to create the specific return type.
*
* <p>To use this class, you simply register your subclasses as extension providers in the
* <b>smack.properties</b> file. Then they will be automatically picked up and used to parse
* any child elements.
*
* <pre>
* For example, given the following message
*
* &lt;message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo&gt;
* &lt;event xmlns='http://jabber.org/protocol/pubsub#event&gt;
* &lt;items node='princely_musings'&gt;
* &lt;item id='asdjkwei3i34234n356'&gt;
* &lt;entry xmlns='http://www.w3.org/2005/Atom'&gt;
* &lt;title&gt;Soliloquy&lt;/title&gt;
* &lt;link rel='alternative' type='text/html'/&gt;
* &lt;id>tag:denmark.lit,2003:entry-32397&lt;/id&gt;
* &lt;/entry&gt;
* &lt;/item&gt;
* &lt;/items&gt;
* &lt;/event&gt;
* &lt;/message&gt;
*
* I would have a classes
* {@link ItemsProvider} extends {@link EmbeddedExtensionProvider}
* {@link ItemProvider} extends {@link EmbeddedExtensionProvider}
* and
* AtomProvider extends {@link PacketExtensionProvider}
*
* These classes are then registered in the meta-inf/smack.providers file
* as follows.
*
* &lt;extensionProvider&gt;
* &lt;elementName&gt;items&lt;/elementName&gt;
* &lt;namespace&gt;http://jabber.org/protocol/pubsub#event&lt;/namespace&gt;
* &lt;className&gt;org.jivesoftware.smackx.provider.ItemsEventProvider&lt;/className&gt;
* &lt;/extensionProvider&gt;
* &lt;extensionProvider&gt;
* &lt;elementName&gt;item&lt;/elementName&gt;
* &lt;namespace&gt;http://jabber.org/protocol/pubsub#event&lt;/namespace&gt;
* &lt;className&gt;org.jivesoftware.smackx.provider.ItemProvider&lt;/className&gt;
* &lt;/extensionProvider&gt;
*
* </pre>
*
* @author Robin Collier
*/
abstract public class EmbeddedExtensionProvider implements PacketExtensionProvider
{
final public PacketExtension parseExtension(XmlPullParser parser) throws Exception
{
String namespace = parser.getNamespace();
String name = parser.getName();
Map<String, String> attMap = new HashMap<String, String>();
for(int i=0; i<parser.getAttributeCount(); i++)
{
attMap.put(parser.getAttributeName(i), parser.getAttributeValue(i));
}
List<PacketExtension> extensions = new ArrayList<PacketExtension>();
do
{
int tag = parser.next();
if (tag == XmlPullParser.START_TAG)
extensions.add(PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser));
} while (!name.equals(parser.getName()));
return createReturnExtension(name, namespace, attMap, extensions);
}
abstract protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content);
}

View file

@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.packet;
package org.jivesoftware.smack.util;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;

View file

@ -27,11 +27,11 @@ import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.util.SyncPacketSend;
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
import org.jivesoftware.smackx.bytestreams.BytestreamManager;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
import org.jivesoftware.smackx.filetransfer.FileTransferManager;
import org.jivesoftware.smackx.packet.SyncPacketSend;
/**
* The InBandBytestreamManager class handles establishing In-Band Bytestreams as specified in the <a

View file

@ -33,12 +33,12 @@ import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.SyncPacketSend;
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Close;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Data;
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
import org.jivesoftware.smackx.packet.SyncPacketSend;
/**
* InBandBytestreamSession class represents an In-Band Bytestream session.
@ -594,7 +594,7 @@ public class InBandBytestreamSession implements BytestreamSession {
* Constructor.
*/
public IBBOutputStream() {
this.buffer = new byte[byteStreamRequest.getBlockSize()];
this.buffer = new byte[(byteStreamRequest.getBlockSize()/4)*3];
}
/**

View file

@ -33,6 +33,7 @@ import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.util.SyncPacketSend;
import org.jivesoftware.smackx.ServiceDiscoveryManager;
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
import org.jivesoftware.smackx.bytestreams.BytestreamManager;
@ -42,7 +43,6 @@ import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHostUs
import org.jivesoftware.smackx.filetransfer.FileTransferManager;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.packet.DiscoverItems;
import org.jivesoftware.smackx.packet.SyncPacketSend;
import org.jivesoftware.smackx.packet.DiscoverInfo.Identity;
import org.jivesoftware.smackx.packet.DiscoverItems.Item;

View file

@ -20,9 +20,9 @@ import java.util.concurrent.TimeoutException;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.SyncPacketSend;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
import org.jivesoftware.smackx.packet.SyncPacketSend;
/**
* Implementation of a SOCKS5 client used on the initiators side. This is needed because connecting

View file

@ -170,7 +170,7 @@ public class EnhancedDebugger implements SmackDebugger {
// the GUI. This is what we call "interpreted" packet data, since it's the packet
// data as Smack sees it and not as it's coming in as raw XML.
packetReaderListener = new PacketListener() {
SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss aaa");
SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss:SS aaa");
public void processPacket(final Packet packet) {
SwingUtilities.invokeLater(new Runnable() {
@ -185,7 +185,7 @@ public class EnhancedDebugger implements SmackDebugger {
// Create a thread that will listen for all outgoing packets and write them to
// the GUI.
packetWriterListener = new PacketListener() {
SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss aaa");
SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss:SS aaa");
public void processPacket(final Packet packet) {
SwingUtilities.invokeLater(new Runnable() {
@ -276,7 +276,7 @@ public class EnhancedDebugger implements SmackDebugger {
table.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);
// Set the column "timestamp" size
table.getColumnModel().getColumn(1).setMaxWidth(300);
table.getColumnModel().getColumn(1).setPreferredWidth(70);
table.getColumnModel().getColumn(1).setPreferredWidth(90);
// Set the column "direction" icon size
table.getColumnModel().getColumn(2).setMaxWidth(50);
table.getColumnModel().getColumn(2).setPreferredWidth(30);
@ -625,7 +625,7 @@ public class EnhancedDebugger implements SmackDebugger {
connPanel.add(
label,
new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
field = new JFormattedTextField(new SimpleDateFormat("yyyy.MM.dd hh:mm:ss aaa"));
field = new JFormattedTextField(new SimpleDateFormat("yyyy.MM.dd hh:mm:ss:SS aaa"));
field.setMinimumSize(new java.awt.Dimension(150, 20));
field.setMaximumSize(new java.awt.Dimension(150, 20));
field.setValue(creationTime);

View file

@ -79,8 +79,9 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
connection.sendPacket(super.createInitiationAccept(initiation, getNamespaces()));
ExecutorService threadPoolExecutor = Executors.newFixedThreadPool(2);
CompletionService<InputStream> service
= new ExecutorCompletionService<InputStream>(Executors.newFixedThreadPool(2));
= new ExecutorCompletionService<InputStream>(threadPoolExecutor);
List<Future<InputStream>> futures = new ArrayList<Future<InputStream>>();
InputStream stream = null;
XMPPException exception = null;
@ -119,6 +120,7 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
future.cancel(true);
}
collector.cancel();
threadPoolExecutor.shutdownNow();
}
if (stream == null) {
if (exception != null) {

View file

@ -130,10 +130,10 @@ public abstract class FileTransfer {
/**
* Returns true if the transfer has been cancelled, if it has stopped because
* of a an error, or the transfer completed succesfully.
* of a an error, or the transfer completed successfully.
*
* @return Returns true if the transfer has been cancelled, if it has stopped
* because of a an error, or the transfer completed succesfully.
* because of a an error, or the transfer completed successfully.
*/
public boolean isDone() {
return status == Status.cancelled || status == Status.error
@ -141,9 +141,9 @@ public abstract class FileTransfer {
}
/**
* Retuns the current status of the file transfer.
* Returns the current status of the file transfer.
*
* @return Retuns the current status of the file transfer.
* @return Returns the current status of the file transfer.
*/
public Status getStatus() {
return status;
@ -158,7 +158,7 @@ public abstract class FileTransfer {
* during the transfer, the type of error can be retrieved through this
* method.
*
* @return Returns the type of error that occured if one has occured.
* @return Returns the type of error that occurred if one has occurred.
*/
public Error getError() {
return error;
@ -166,9 +166,9 @@ public abstract class FileTransfer {
/**
* If an exception occurs asynchronously it will be stored for later
* retrival. If there is an error there maybe an exception set.
* retrieval. If there is an error there maybe an exception set.
*
* @return The exception that occured or null if there was no exception.
* @return The exception that occurred or null if there was no exception.
* @see #getError()
*/
public Exception getException() {
@ -246,7 +246,7 @@ public abstract class FileTransfer {
public enum Status {
/**
* An error occured during the transfer.
* An error occurred during the transfer.
*
* @see FileTransfer#getError()
*/
@ -259,7 +259,7 @@ public abstract class FileTransfer {
/**
* The file transfer is being negotiated with the peer. The party
* recieving the file has the option to accept or refuse a file transfer
* Receiving the file has the option to accept or refuse a file transfer
* request. If they accept, then the process of stream negotiation will
* begin. If they refuse the file will not be transfered.
*
@ -283,7 +283,7 @@ public abstract class FileTransfer {
negotiating_stream("Negotiating Stream"),
/**
* After the stream negotitation has completed the intermediate state
* After the stream negotiation has completed the intermediate state
* between the time when the negotiation is finished and the actual
* transfer begins.
*/
@ -302,7 +302,7 @@ public abstract class FileTransfer {
complete("Complete"),
/**
* The file transfer was canceled
* The file transfer was cancelled
*/
cancelled("Cancelled");
@ -348,12 +348,12 @@ public abstract class FileTransfer {
no_response("The remote user did not respond or the connection timed out."),
/**
* An error occured over the socket connected to send the file.
* An error occurred over the socket connected to send the file.
*/
connection("An error occured over the socket connected to send the file."),
/**
* An error occured while sending or recieving the file
* An error occurred while sending or receiving the file
*/
stream("An error occured while sending or recieving the file.");

View file

@ -172,7 +172,7 @@ public class FileTransferManager {
IQ rejection = FileTransferNegotiator.createIQ(
initiation.getPacketID(), initiation.getFrom(), initiation
.getTo(), IQ.Type.ERROR);
rejection.setError(new XMPPError(XMPPError.Condition.forbidden));
rejection.setError(new XMPPError(XMPPError.Condition.no_acceptable));
connection.sendPacket(rejection);
}
}

View file

@ -52,7 +52,7 @@ import org.jivesoftware.smackx.packet.StreamInitiation;
* will be sent.
*
* @author Alexander Wenckus
* @see <a href="http://www.jabber.org/jeps/jep-0096.html">JEP-0096: File Transfer</a>
* @see <a href="http://xmpp.org/extensions/xep-0096.html">XEP-0096: SI File Transfer</a>
*/
public class FileTransferNegotiator {
@ -76,7 +76,7 @@ public class FileTransferNegotiator {
* set this variable to true for testing purposes as IBB is the backup file transfer method
* and shouldn't be used as the only transfer method in production systems.
*/
public static boolean IBB_ONLY = false;
public static boolean IBB_ONLY = (System.getProperty("ibb") != null);//true;
/**
* Returns the file transfer negotiator related to a particular connection.

View file

@ -80,7 +80,7 @@ public class OutgoingFileTransfer extends FileTransfer {
/**
* Returns the output stream connected to the peer to transfer the file. It
* is only available after it has been succesfully negotiated by the
* is only available after it has been successfully negotiated by the
* {@link StreamNegotiator}.
*
* @return Returns the output stream connected to the peer to transfer the
@ -120,6 +120,7 @@ public class OutgoingFileTransfer extends FileTransfer {
+ " been attempted on this file transfer");
}
try {
setFileInfo(fileName, fileSize);
this.outputStream = negotiateStream(fileName, fileSize, description);
} catch (XMPPException e) {
handleXMPPException(e);
@ -159,6 +160,7 @@ public class OutgoingFileTransfer extends FileTransfer {
"The negotation process has already"
+ " been attempted for this file transfer");
}
setFileInfo(fileName, fileSize);
this.callback = progress;
transferThread = new Thread(new Runnable() {
public void run() {
@ -184,7 +186,7 @@ public class OutgoingFileTransfer extends FileTransfer {
/**
* This method handles the stream negotiation process and transmits the file
* to the remote user. It returns immediatly and the progress of the file
* to the remote user. It returns immediately and the progress of the file
* transfer can be monitored through several methods:
*
* <UL>
@ -257,7 +259,7 @@ public class OutgoingFileTransfer extends FileTransfer {
/**
* This method handles the stream negotiation process and transmits the file
* to the remote user. It returns immediatly and the progress of the file
* to the remote user. It returns immediately and the progress of the file
* transfer can be monitored through several methods:
*
* <UL>
@ -274,6 +276,7 @@ public class OutgoingFileTransfer extends FileTransfer {
public synchronized void sendStream(final InputStream in, final String fileName, final long fileSize, final String description){
checkTransferThread();
setFileInfo(fileName, fileSize);
transferThread = new Thread(new Runnable() {
public void run() {
//Create packet filter
@ -339,7 +342,7 @@ public class OutgoingFileTransfer extends FileTransfer {
* -1 if the file transfer has not started.
* <p>
* Note: This method is only useful when the {@link #sendFile(File, String)}
* method is called, as it is the only method that actualy transmits the
* method is called, as it is the only method that actually transmits the
* file.
*
* @return Returns the amount of bytes that have been sent for the file
@ -410,7 +413,7 @@ public class OutgoingFileTransfer extends FileTransfer {
}
/**
* A callback class to retrive the status of an outgoing transfer
* A callback class to retrieve the status of an outgoing transfer
* negotiation process.
*
* @author Alexander Wenckus
@ -438,7 +441,7 @@ public class OutgoingFileTransfer extends FileTransfer {
/**
* Called when an exception occurs during the negotiation progress.
*
* @param e the exception that occured.
* @param e the exception that occurred.
*/
void errorEstablishingStream(Exception e);
}

View file

@ -90,10 +90,10 @@ public class RoomInfo {
Form form = Form.getFormFrom(info);
if (form != null) {
FormField descField = form.getField("muc#roominfo_description");
this.description = descField == null ? "" : descField.getValues().next();
this.description = ( descField == null || !(descField.getValues().hasNext()) )? "" : descField.getValues().next();
FormField subjField = form.getField("muc#roominfo_subject");
this.subject = subjField == null ? "" : subjField.getValues().next();
this.subject = ( subjField == null || !(subjField.getValues().hasNext()) ) ? "" : subjField.getValues().next();
FormField occCountField = form.getField("muc#roominfo_occupants");
this.occupantsCount = occCountField == null ? -1 : Integer.parseInt(occCountField.getValues()

View file

@ -78,6 +78,8 @@ import org.xmlpull.v1.XmlPullParser;
* </pre>
*
* @author Robin Collier
*
* @deprecated This has been moved to {@link org.jivesoftware.smack.provider.EmbeddedExtensionProvider}
*/
abstract public class EmbeddedExtensionProvider implements PacketExtensionProvider
{