Search in sources :

Example 1 with StreamInitiation

use of org.jivesoftware.smackx.packet.StreamInitiation in project ecf by eclipse.

the class FileTransferManager method initListeners.

private void initListeners() {
    listeners = new ArrayList<FileTransferListener>();
    connection.addPacketListener(new PacketListener() {

        public void processPacket(Packet packet) {
            fireNewRequest((StreamInitiation) packet);
        }
    }, new AndFilter(new PacketTypeFilter(StreamInitiation.class), new IQTypeFilter(IQ.Type.SET)));
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) StreamInitiation(org.jivesoftware.smackx.packet.StreamInitiation) AndFilter(org.jivesoftware.smack.filter.AndFilter) IQTypeFilter(org.jivesoftware.smack.filter.IQTypeFilter) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) PacketListener(org.jivesoftware.smack.PacketListener)

Example 2 with StreamInitiation

use of org.jivesoftware.smackx.packet.StreamInitiation in project ecf by eclipse.

the class StreamNegotiator method initiateIncomingStream.

Packet initiateIncomingStream(Connection connection, StreamInitiation initiation) throws XMPPException {
    StreamInitiation response = createInitiationAccept(initiation, getNamespaces());
    // establish collector to await response
    PacketCollector collector = connection.createPacketCollector(getInitiationPacketFilter(initiation.getFrom(), initiation.getSessionID()));
    connection.sendPacket(response);
    Packet streamMethodInitiation = collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (streamMethodInitiation == null) {
        throw new XMPPException("No response from file transfer initiator");
    }
    return streamMethodInitiation;
}
Also used : StreamInitiation(org.jivesoftware.smackx.packet.StreamInitiation) Packet(org.jivesoftware.smack.packet.Packet) PacketCollector(org.jivesoftware.smack.PacketCollector) XMPPException(org.jivesoftware.smack.XMPPException)

Example 3 with StreamInitiation

use of org.jivesoftware.smackx.packet.StreamInitiation in project ecf by eclipse.

the class StreamNegotiator method createInitiationAccept.

/**
 * Creates the initiation acceptance packet to forward to the stream
 * initiator.
 *
 * @param streamInitiationOffer The offer from the stream initiator to connect for a stream.
 * @param namespaces            The namespace that relates to the accepted means of transfer.
 * @return The response to be forwarded to the initiator.
 */
public StreamInitiation createInitiationAccept(StreamInitiation streamInitiationOffer, String[] namespaces) {
    StreamInitiation response = new StreamInitiation();
    response.setTo(streamInitiationOffer.getFrom());
    response.setFrom(streamInitiationOffer.getTo());
    response.setType(IQ.Type.RESULT);
    response.setPacketID(streamInitiationOffer.getPacketID());
    DataForm form = new DataForm(Form.TYPE_SUBMIT);
    FormField field = new FormField(FileTransferNegotiator.STREAM_DATA_FIELD_NAME);
    for (String namespace : namespaces) {
        field.addValue(namespace);
    }
    form.addField(field);
    response.setFeatureNegotiationForm(form);
    return response;
}
Also used : StreamInitiation(org.jivesoftware.smackx.packet.StreamInitiation) DataForm(org.jivesoftware.smackx.packet.DataForm) FormField(org.jivesoftware.smackx.FormField)

Example 4 with StreamInitiation

use of org.jivesoftware.smackx.packet.StreamInitiation in project ecf by eclipse.

the class FileTransferManager method rejectIncomingFileTransfer.

protected void rejectIncomingFileTransfer(FileTransferRequest request) {
    StreamInitiation initiation = request.getStreamInitiation();
    IQ rejection = FileTransferNegotiator.createIQ(initiation.getPacketID(), initiation.getFrom(), initiation.getTo(), IQ.Type.ERROR);
    rejection.setError(new XMPPError(XMPPError.Condition.no_acceptable));
    connection.sendPacket(rejection);
}
Also used : StreamInitiation(org.jivesoftware.smackx.packet.StreamInitiation) IQ(org.jivesoftware.smack.packet.IQ) XMPPError(org.jivesoftware.smack.packet.XMPPError)

Example 5 with StreamInitiation

use of org.jivesoftware.smackx.packet.StreamInitiation in project ecf by eclipse.

the class FileTransferNegotiator method negotiateOutgoingTransfer.

/**
 * Send a request to another user to send them a file. The other user has
 * the option of, accepting, rejecting, or not responding to a received file
 * transfer request.
 * <p/>
 * If they accept, the packet will contain the other user's chosen stream
 * type to send the file across. The two choices this implementation
 * provides to the other user for file transfer are <a
 * href="http://www.jabber.org/jeps/jep-0065.html">SOCKS5 Bytestreams</a>,
 * which is the preferred method of transfer, and <a
 * href="http://www.jabber.org/jeps/jep-0047.html">In-Band Bytestreams</a>,
 * which is the fallback mechanism.
 * <p/>
 * The other user may choose to decline the file request if they do not
 * desire the file, their client does not support JEP-0096, or if there are
 * no acceptable means to transfer the file.
 * <p/>
 * Finally, if the other user does not respond this method will return null
 * after the specified timeout.
 *
 * @param userID          The userID of the user to whom the file will be sent.
 * @param streamID        The unique identifier for this file transfer.
 * @param fileName        The name of this file. Preferably it should include an
 *                        extension as it is used to determine what type of file it is.
 * @param size            The size, in bytes, of the file.
 * @param desc            A description of the file.
 * @param responseTimeout The amount of time, in milliseconds, to wait for the remote
 *                        user to respond. If they do not respond in time, this
 * @return Returns the stream negotiator selected by the peer.
 * @throws XMPPException Thrown if there is an error negotiating the file transfer.
 */
public StreamNegotiator negotiateOutgoingTransfer(final String userID, final String streamID, final String fileName, final long size, final String desc, int responseTimeout) throws XMPPException {
    StreamInitiation si = new StreamInitiation();
    si.setSesssionID(streamID);
    si.setMimeType(URLConnection.guessContentTypeFromName(fileName));
    StreamInitiation.File siFile = new StreamInitiation.File(fileName, size);
    siFile.setDesc(desc);
    si.setFile(siFile);
    si.setFeatureNegotiationForm(createDefaultInitiationForm());
    si.setFrom(connection.getUser());
    si.setTo(userID);
    si.setType(IQ.Type.SET);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(si.getPacketID()));
    connection.sendPacket(si);
    Packet siResponse = collector.nextResult(responseTimeout);
    collector.cancel();
    if (siResponse instanceof IQ) {
        IQ iqResponse = (IQ) siResponse;
        if (iqResponse.getType().equals(IQ.Type.RESULT)) {
            StreamInitiation response = (StreamInitiation) siResponse;
            return getOutgoingNegotiator(getStreamMethodField(response.getFeatureNegotiationForm()));
        } else if (iqResponse.getType().equals(IQ.Type.ERROR)) {
            throw new XMPPException(iqResponse.getError());
        } else {
            throw new XMPPException("File transfer response unreadable");
        }
    } else {
        return null;
    }
}
Also used : StreamInitiation(org.jivesoftware.smackx.packet.StreamInitiation) Packet(org.jivesoftware.smack.packet.Packet) PacketCollector(org.jivesoftware.smack.PacketCollector) IQ(org.jivesoftware.smack.packet.IQ) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Aggregations

StreamInitiation (org.jivesoftware.smackx.packet.StreamInitiation)7 XMPPException (org.jivesoftware.smack.XMPPException)3 IQ (org.jivesoftware.smack.packet.IQ)3 Packet (org.jivesoftware.smack.packet.Packet)3 PacketCollector (org.jivesoftware.smack.PacketCollector)2 XMPPError (org.jivesoftware.smack.packet.XMPPError)2 FormField (org.jivesoftware.smackx.FormField)2 DataForm (org.jivesoftware.smackx.packet.DataForm)2 ParseException (java.text.ParseException)1 Date (java.util.Date)1 PacketListener (org.jivesoftware.smack.PacketListener)1 AndFilter (org.jivesoftware.smack.filter.AndFilter)1 IQTypeFilter (org.jivesoftware.smack.filter.IQTypeFilter)1 PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)1 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)1 File (org.jivesoftware.smackx.packet.StreamInitiation.File)1