1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 17:49:38 +02:00

Cleanup code

This commit is contained in:
vanitasvitae 2017-08-16 15:36:49 +02:00
parent e53165a96c
commit e1655aa344
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
30 changed files with 92 additions and 109 deletions

View file

@ -1,33 +0,0 @@
/**
*
* 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.callbacks;
import org.jivesoftware.smackx.jingle.JingleDescriptionController;
/**
* Created by vanitas on 27.07.17.
*/
public interface JingleCallback<P extends JingleCallback.Parameters> {
JingleDescriptionController accept(P parameters);
void decline();
class Parameters {
}
}

View file

@ -56,8 +56,8 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
private JingleSession parent;
private JingleContentElement.Creator creator;
private String name;
private String disposition;
private final String name;
private final String disposition;
private JingleContentElement.Senders senders;
private JingleDescription<?> description;
private JingleTransport<?> transport;
@ -120,6 +120,10 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
return new JingleContent(description, transport, security, content.getName(), content.getDisposition(), content.getCreator(), content.getSenders());
}
public void setSenders(JingleContentElement.Senders senders) {
this.senders = senders;
}
/* HANDLE_XYZ */
public IQ handleJingleRequest(JingleElement request, XMPPConnection connection) {
@ -145,12 +149,12 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
}
}
public void handleContentAccept(JingleElement request, XMPPConnection connection) {
void handleContentAccept(JingleElement request, XMPPConnection connection) {
start(connection);
}
public IQ handleSessionAccept(JingleElement request, XMPPConnection connection) {
IQ handleSessionAccept(JingleElement request, XMPPConnection connection) {
LOGGER.log(Level.INFO, "RECEIVED SESSION ACCEPT!");
JingleContentElement contentElement = null;
for (JingleContentElement c : request.getContents()) {
@ -169,26 +173,26 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
return IQ.createResultIQ(request);
}
public IQ handleContentModify(JingleElement request, XMPPConnection connection) {
private IQ handleContentModify(JingleElement request, XMPPConnection connection) {
return IQ.createErrorResponse(request, XMPPError.Condition.feature_not_implemented);
}
public IQ handleDescriptionInfo(JingleElement request, XMPPConnection connection) {
private IQ handleDescriptionInfo(JingleElement request, XMPPConnection connection) {
return IQ.createErrorResponse(request, XMPPError.Condition.feature_not_implemented);
}
public void handleContentRemove(JingleSession session, XMPPConnection connection) {
}
public IQ handleSecurityInfo(JingleElement request, XMPPConnection connection) {
private IQ handleSecurityInfo(JingleElement request, XMPPConnection connection) {
return IQ.createErrorResponse(request, XMPPError.Condition.feature_not_implemented);
}
public IQ handleSessionInfo(JingleElement request, XMPPConnection connection) {
private IQ handleSessionInfo(JingleElement request, XMPPConnection connection) {
return IQ.createResultIQ(request);
}
public IQ handleTransportAccept(JingleElement request, XMPPConnection connection) {
private IQ handleTransportAccept(JingleElement request, XMPPConnection connection) {
if (pendingReplacingTransport == null) {
LOGGER.log(Level.WARNING, "Received transport-accept, but apparently we did not try to replace the transport.");
@ -203,14 +207,14 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
return IQ.createResultIQ(request);
}
public IQ handleTransportInfo(JingleElement request, XMPPConnection connection) {
private IQ handleTransportInfo(JingleElement request, XMPPConnection connection) {
assert request.getContents().size() == 1;
JingleContentElement content = request.getContents().get(0);
return transport.handleTransportInfo(content.getTransport().getInfo(), request);
}
public IQ handleTransportReject(JingleElement request, XMPPConnection connection) {
private IQ handleTransportReject(JingleElement request, XMPPConnection connection) {
if (pendingReplacingTransport == null) {
throw new AssertionError("We didn't try to replace the transport.");
}
@ -224,7 +228,7 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
return IQ.createResultIQ(request);
}
public IQ handleTransportReplace(final JingleElement request, final XMPPConnection connection) {
private IQ handleTransportReplace(final JingleElement request, final XMPPConnection connection) {
//Tie Break?
if (pendingReplacingTransport != null) {
Async.go(new Runnable() {
@ -490,7 +494,7 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
connection.createStanzaCollectorAndSend(transportReplace).nextResultOrThrow();
}
public static String randomName() {
private static String randomName() {
return "cont-" + StringUtils.randomString(16);
}
}

View file

@ -370,7 +370,7 @@ public class JingleSession {
return content;
}
private JingleContent getSoleProposedContentOrThrow(JingleElement request) {
private static JingleContent getSoleProposedContentOrThrow(JingleElement request) {
if (request.getContents().size() != 1) {
throw new AssertionError("More/less than 1 content in request!");
}

View file

@ -44,7 +44,7 @@ public enum JingleAction {
transport_replace,
;
private static final Map<String, JingleAction> map = new HashMap<String, JingleAction>(
private static final Map<String, JingleAction> map = new HashMap<>(
JingleAction.values().length);
static {
for (JingleAction jingleAction : JingleAction.values()) {
@ -54,7 +54,7 @@ public enum JingleAction {
private final String asString;
private JingleAction() {
JingleAction() {
asString = this.name().replace('_', '-');
}

View file

@ -26,13 +26,13 @@ public final class JingleErrorElement implements ExtensionElement {
public static String NAMESPACE = "urn:xmpp:jingle:errors:1";
public static final JingleErrorElement OUT_OF_ORDER = new JingleErrorElement("out-of-order");
static final JingleErrorElement OUT_OF_ORDER = new JingleErrorElement("out-of-order");
public static final JingleErrorElement TIE_BREAK = new JingleErrorElement("tie-break");
static final JingleErrorElement TIE_BREAK = new JingleErrorElement("tie-break");
public static final JingleErrorElement UNKNOWN_SESSION = new JingleErrorElement("unknown-session");
static final JingleErrorElement UNKNOWN_SESSION = new JingleErrorElement("unknown-session");
public static final JingleErrorElement UNSUPPORTED_INFO = new JingleErrorElement("unsupported-info");
static final JingleErrorElement UNSUPPORTED_INFO = new JingleErrorElement("unsupported-info");
private final String errorName;

View file

@ -131,7 +131,7 @@ public class JingleReasonElement implements NamedElement {
public static class AlternativeSession extends JingleReasonElement {
public static final String SID = "sid";
public static final String ATTR_SID = "sid";
private final String sessionId;
public AlternativeSession(String sessionId) {
@ -148,9 +148,9 @@ public class JingleReasonElement implements NamedElement {
xml.rightAngleBracket();
xml.openElement(reason.asString);
xml.openElement(SID);
xml.openElement(ATTR_SID);
xml.append(sessionId);
xml.closeElement(SID);
xml.closeElement(ATTR_SID);
xml.closeElement(reason.asString);
xml.closeElement(this);

View file

@ -99,7 +99,7 @@ public class JingleProvider extends IQProvider<JingleElement> {
return builder.build();
}
public static JingleContentElement parseJingleContent(XmlPullParser parser, final int initialDepth)
private static JingleContentElement parseJingleContent(XmlPullParser parser, final int initialDepth)
throws Exception {
JingleContentElement.Builder builder = JingleContentElement.getBuilder();

View file

@ -18,7 +18,6 @@ package org.jivesoftware.smackx.jingle.transport.jingle_s5b;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
@ -234,7 +233,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
}
@SuppressWarnings("ReferenceEquality")
void establishBytestreamSession(XMPPConnection connection)
private void establishBytestreamSession(XMPPConnection connection)
throws SmackException.NotConnectedException, InterruptedException {
Socks5Proxy.getSocks5Proxy().addTransfer(ourDstAddr);
JingleS5BTransportManager transportManager = JingleS5BTransportManager.getInstanceFor(connection);
@ -254,7 +253,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
}
@SuppressWarnings("ReferenceEquality")
public JingleS5BTransportCandidate connectToCandidates(int timeout) {
private JingleS5BTransportCandidate connectToCandidates(int timeout) {
if (getTheirCandidates().size() == 0) {
LOGGER.log(Level.INFO, "They provided 0 candidates.");
@ -281,7 +280,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
}
@SuppressWarnings("ReferenceEquality")
void connectIfReady() {
private void connectIfReady() {
final JingleS5BTransportManager jingleS5BTransportManager = JingleS5BTransportManager.getInstanceFor(getParent().getParent().getJingleManager().getConnection());
final JingleSession session = getParent().getParent();
@ -427,9 +426,8 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
return;
}
Iterator<JingleTransportCandidate<?>> ourCandidates = getOurCandidates().iterator();
while (ourCandidates.hasNext()) {
JingleS5BTransportCandidate candidate = (JingleS5BTransportCandidate) ourCandidates.next();
for (JingleTransportCandidate<?> jingleTransportCandidate : getOurCandidates()) {
JingleS5BTransportCandidate candidate = (JingleS5BTransportCandidate) jingleTransportCandidate;
if (candidate.getCandidateId().equals(candidateId)) {
theirSelectedCandidate = candidate;
}

View file

@ -45,14 +45,14 @@ public class JingleS5BTransportCandidate extends JingleTransportCandidate<Jingle
private Socket socket;
public JingleS5BTransportCandidate(JingleS5BTransportCandidateElement element) {
JingleS5BTransportCandidate(JingleS5BTransportCandidateElement element) {
this(element.getCandidateId(), new Bytestream.StreamHost(element.getJid(), element.getHost(), element.getPort()), element.getPriority(), element.getType());
}
public JingleS5BTransportCandidate(String candidateId,
Bytestream.StreamHost streamHost,
int priority,
JingleS5BTransportCandidateElement.Type type) {
JingleS5BTransportCandidate(String candidateId,
Bytestream.StreamHost streamHost,
int priority,
JingleS5BTransportCandidateElement.Type type) {
this.candidateId = candidateId;
this.streamHost = streamHost;
this.type = type;
@ -60,18 +60,18 @@ public class JingleS5BTransportCandidate extends JingleTransportCandidate<Jingle
setPriority(priority);
}
public JingleS5BTransportCandidate(JingleS5BTransportCandidate other) {
JingleS5BTransportCandidate(JingleS5BTransportCandidate other) {
this(other.candidateId,
other.getStreamHost(),
other.getPriority(),
other.type);
}
public static JingleS5BTransportCandidate fromElement(JingleS5BTransportCandidateElement element) {
static JingleS5BTransportCandidate fromElement(JingleS5BTransportCandidateElement element) {
return new JingleS5BTransportCandidate(element.getCandidateId(), element.getStreamHost(), element.getPriority(), element.getType());
}
public String getCandidateId() {
String getCandidateId() {
return candidateId;
}

View file

@ -121,7 +121,7 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
return 10000; // SOCKS5 has a high priority
}
public List<JingleTransportCandidate<?>> collectCandidates() {
List<JingleTransportCandidate<?>> collectCandidates() {
List<JingleTransportCandidate<?>> candidates = new ArrayList<>();
//Local host
@ -156,21 +156,21 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
return socks5BytestreamManager.getLocalStreamHost();
}
public List<Bytestream.StreamHost> getServersStreamHosts() throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
private List<Bytestream.StreamHost> getServersStreamHosts() throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
if (availableStreamHosts == null) {
availableStreamHosts = queryServersStreamHosts();
}
return availableStreamHosts;
}
public List<Bytestream.StreamHost> getLocalStreamHosts() {
private List<Bytestream.StreamHost> getLocalStreamHosts() {
if (localStreamHosts == null) {
localStreamHosts = queryLocalStreamHosts();
}
return localStreamHosts;
}
public List<Bytestream.StreamHost> determineStreamHostInfo(List<Jid> proxies) {
private List<Bytestream.StreamHost> determineStreamHostInfo(List<Jid> proxies) {
List<Bytestream.StreamHost> streamHosts = new ArrayList<>();
Iterator<Jid> iterator = proxies.iterator();
@ -192,7 +192,7 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
return streamHosts;
}
private JingleElement createTransportInfo(JingleS5BTransport transport, JingleS5BTransportInfoElement info) {
private static JingleElement createTransportInfo(JingleS5BTransport transport, JingleS5BTransportInfoElement info) {
JingleContent content = transport.getParent();
JingleSession session = content.getParent();
@ -222,19 +222,19 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
return jingle;
}
JingleElement createCandidateUsed(JingleS5BTransport transport, JingleS5BTransportCandidate candidate) {
static JingleElement createCandidateUsed(JingleS5BTransport transport, JingleS5BTransportCandidate candidate) {
return createTransportInfo(transport, new JingleS5BTransportInfoElement.CandidateUsed(candidate.getCandidateId()));
}
JingleElement createCandidateError(JingleS5BTransport transport) {
static JingleElement createCandidateError(JingleS5BTransport transport) {
return createTransportInfo(transport, JingleS5BTransportInfoElement.CandidateError.INSTANCE);
}
JingleElement createProxyError(JingleS5BTransport transport) {
static JingleElement createProxyError(JingleS5BTransport transport) {
return createTransportInfo(transport, JingleS5BTransportInfoElement.ProxyError.INSTANCE);
}
JingleElement createCandidateActivated(JingleS5BTransport transport, JingleS5BTransportCandidate candidate) {
static JingleElement createCandidateActivated(JingleS5BTransport transport, JingleS5BTransportCandidate candidate) {
return createTransportInfo(transport, new JingleS5BTransportInfoElement.CandidateActivated(candidate.getCandidateId()));
}
@ -259,7 +259,7 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
return getPriority() > other.getPriority() ? 1 : -1;
}
private ConnectionListener connectionListener = new ConnectionListener() {
private final ConnectionListener connectionListener = new ConnectionListener() {
@Override
public void connected(XMPPConnection connection) {

View file

@ -32,7 +32,7 @@ public class S5BTransportException extends FailedTransportException {
public static class CandidateError extends S5BTransportException {
protected static final long serialVersionUID = 1L;
public CandidateError(Throwable throwable) {
CandidateError(Throwable throwable) {
super(throwable);
}
}
@ -40,7 +40,7 @@ public class S5BTransportException extends FailedTransportException {
public static class ProxyError extends S5BTransportException {
protected static final long serialVersionUID = 1L;
public ProxyError(Throwable throwable) {
ProxyError(Throwable throwable) {
super(throwable);
}
}

View file

@ -29,7 +29,7 @@ public abstract class JingleS5BTransportInfoElement extends JingleContentTranspo
private final String candidateId;
protected JingleS5BCandidateTransportInfoElement(String candidateId) {
JingleS5BCandidateTransportInfoElement(String candidateId) {
this.candidateId = candidateId;
}