mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 20:42:06 +01:00
Fix jingle ft
This commit is contained in:
commit
3a4f758b6a
5 changed files with 41 additions and 9 deletions
|
@ -142,12 +142,26 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
|
|||
if (!target.exists()) {
|
||||
target.createNewFile();
|
||||
}
|
||||
int s = ((JingleFileTransferChildElement)jingle.getContents().get(0).getDescription().getJinglePayloadTypes().get(0))
|
||||
.getSize();
|
||||
JingleFileTransferChildElement payload = (JingleFileTransferChildElement) jingle.getContents().get(0).getDescription().getJingleContentDescriptionChildren().get(0);
|
||||
JingleInBandByteStreamTransport transport = (JingleInBandByteStreamTransport) jingle.getContents().get(0).getJingleTransports().get(0);
|
||||
int s = payload.getSize();
|
||||
int bs = transport.getBlockSize();
|
||||
byte[] recv = new byte[s];
|
||||
|
||||
FileOutputStream o = new FileOutputStream(target);
|
||||
InputStream i = request.accept().getInputStream();
|
||||
i.read(recv);
|
||||
InBandBytestreamSession ibs = request.accept();
|
||||
InputStream i = ibs.getInputStream();
|
||||
int read = 0;
|
||||
int count = 0;
|
||||
while (read > -1 && read < s) {
|
||||
byte[] buf = new byte[bs];
|
||||
int r = i.read(buf);
|
||||
read += r;
|
||||
|
||||
LOGGER.log(Level.INFO, "Read " + r + " (" + read + ") bytes of " + s + " (" + count + " of size " + bs + ")");
|
||||
System.arraycopy(buf, 0, recv,bs * count, r);
|
||||
count++;
|
||||
}
|
||||
i.close();
|
||||
o.write(recv);
|
||||
o.close();
|
||||
|
@ -210,10 +224,11 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
|
|||
}
|
||||
LOGGER.log(Level.INFO, "Received session-accept");
|
||||
// Remote accepts our session-initiate
|
||||
InBandBytestreamManager ibm = InBandBytestreamManager.getByteStreamManager(connection());
|
||||
ibm.setMaximumBlockSize(4096);
|
||||
InBandBytestreamSession ibs;
|
||||
try {
|
||||
ibs = InBandBytestreamManager.getByteStreamManager(connection())
|
||||
.establishSession(jingle.getResponder(), sessionId);
|
||||
ibs = ibm.establishSession(jingle.getResponder(), sessionId);
|
||||
} catch (SmackException.NoResponseException | InterruptedException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
|
||||
LOGGER.log(Level.SEVERE, "Fail in handle request: " + e, e);
|
||||
return null;
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Paul Schaub
|
||||
*
|
||||
* 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.jingle_filetransfer;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
|
|
|
@ -78,7 +78,7 @@ public class JingleFileTransferContentDescriptionTest extends SmackTestSuite {
|
|||
.parse(TestUtils.getParser(xml));
|
||||
assertEquals(xml, parsed.toXML().toString());
|
||||
|
||||
JingleFileTransferChildElement payload = (JingleFileTransferChildElement) parsed.getJinglePayloadTypes().get(0);
|
||||
JingleFileTransferChildElement payload = (JingleFileTransferChildElement) parsed.getJingleContentDescriptionChildren().get(0);
|
||||
assertEquals(date, payload.getDate());
|
||||
assertEquals(descriptionString, payload.getDescription());
|
||||
assertEquals(mediaTypeString, payload.getMediaType());
|
||||
|
@ -88,7 +88,7 @@ public class JingleFileTransferContentDescriptionTest extends SmackTestSuite {
|
|||
assertEquals(hashElement, payload.getHash());
|
||||
|
||||
JingleFileTransferContentDescription descriptionFileTransfer1 = new JingleFileTransferContentDescription(null);
|
||||
assertNotNull(descriptionFileTransfer1.getJinglePayloadTypes());
|
||||
assertNotNull(descriptionFileTransfer1.getJingleContentDescriptionChildren());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -78,6 +78,7 @@ public final class Jingle extends IQ {
|
|||
else {
|
||||
this.contents = Collections.emptyList();
|
||||
}
|
||||
setType(Type.set);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,7 +46,7 @@ public abstract class JingleContentDescription implements ExtensionElement {
|
|||
return ELEMENT;
|
||||
}
|
||||
|
||||
public List<JingleContentDescriptionChildElement> getJinglePayloadTypes() {
|
||||
public List<JingleContentDescriptionChildElement> getJingleContentDescriptionChildren() {
|
||||
return payloads;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue