正在查看: 95爱播免登录版 v3.1.9 应用的 BOSHConnection.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 95爱播免登录版 v3.1.9 应用的 BOSHConnection.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package org.jivesoftware.smack;
import com.kenai.jbosh.BOSHClient;
import com.kenai.jbosh.BOSHClientConfig;
import com.kenai.jbosh.BOSHClientConnListener;
import com.kenai.jbosh.BOSHClientRequestListener;
import com.kenai.jbosh.BOSHClientResponseListener;
import com.kenai.jbosh.BOSHException;
import com.kenai.jbosh.BOSHMessageEvent;
import com.kenai.jbosh.BodyQName;
import com.kenai.jbosh.ComposableBody;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.xiaomi.mipush.sdk.Constants;
import java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.Iterator;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import org.apache.commons.httpclient.cookie.CookieSpec;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.util.StringUtils;
public class BOSHConnection extends Connection {
public static final String BOSH_URI = "http://jabber.org/protocol/httpbind";
public static final String XMPP_BOSH_NS = "urn:xmpp:xbosh";
private boolean anonymous;
protected String authID;
private boolean authenticated;
private BOSHClient client;
private final BOSHConfiguration config;
private boolean connected;
private boolean done;
private boolean isFirstInitialization;
private ExecutorService listenerExecutor;
private Thread readerConsumer;
private PipedWriter readerPipe;
private Roster roster;
protected String sessionID;
private String user;
private boolean wasAuthenticated;
private class BOSHConnectionListener implements BOSHClientConnListener {
private final BOSHConnection connection;
public BOSHConnectionListener(BOSHConnection bOSHConnection) {
this.connection = bOSHConnection;
}
public void connectionEvent(com.kenai.jbosh.BOSHClientConnEvent r4) {
throw new UnsupportedOperationException("Method not decompiled: org.jivesoftware.smack.BOSHConnection.BOSHConnectionListener.connectionEvent(com.kenai.jbosh.BOSHClientConnEvent):void");
}
}
private class ListenerNotification implements Runnable {
private Packet packet;
public ListenerNotification(Packet packet) {
this.packet = packet;
}
@Override
public void run() {
Iterator<Connection.ListenerWrapper> it = BOSHConnection.this.recvListeners.values().iterator();
while (it.hasNext()) {
it.next().notifyListener(this.packet);
}
}
}
public BOSHConnection(boolean z, String str, int i2, String str2, String str3) {
super(new BOSHConfiguration(z, str, i2, str2, str3));
this.connected = false;
this.authenticated = false;
this.anonymous = false;
this.isFirstInitialization = true;
this.wasAuthenticated = false;
this.done = false;
this.authID = null;
this.sessionID = null;
this.user = null;
this.roster = null;
this.config = (BOSHConfiguration) getConfiguration();
}
private void setWasAuthenticated(boolean z) {
if (this.wasAuthenticated) {
return;
}
this.wasAuthenticated = z;
}
@Override
public void connect() throws XMPPException {
if (this.connected) {
throw new IllegalStateException("Already connected to a server.");
}
this.done = false;
try {
BOSHClient bOSHClient = this.client;
if (bOSHClient != null) {
bOSHClient.close();
this.client = null;
}
this.saslAuthentication.init();
this.sessionID = null;
this.authID = null;
BOSHClientConfig.Builder create = BOSHClientConfig.Builder.create(this.config.getURI(), this.config.getServiceName());
if (this.config.isProxyEnabled()) {
create.setProxy(this.config.getProxyAddress(), this.config.getProxyPort());
}
this.client = BOSHClient.create(create.build());
this.listenerExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable runnable) {
Thread thread = new Thread(runnable, "Smack Listener Processor (" + BOSHConnection.this.connectionCounterValue + ")");
thread.setDaemon(true);
return thread;
}
});
this.client.addBOSHClientConnListener(new BOSHConnectionListener(this));
this.client.addBOSHClientResponseListener(new BOSHPacketReader(this));
if (this.config.isDebuggerEnabled()) {
initDebugger();
if (this.isFirstInitialization) {
if (this.debugger.getReaderListener() != null) {
addPacketListener(this.debugger.getReaderListener(), null);
}
if (this.debugger.getWriterListener() != null) {
addPacketSendingListener(this.debugger.getWriterListener(), null);
}
}
}
this.client.send(ComposableBody.builder().setNamespaceDefinition("xmpp", XMPP_BOSH_NS).setAttribute(BodyQName.createWithPrefix(XMPP_BOSH_NS, "version", "xmpp"), "1.0").build());
synchronized (this) {
long currentTimeMillis = System.currentTimeMillis() + (SmackConfiguration.getPacketReplyTimeout() * 6);
while (!this.connected && System.currentTimeMillis() < currentTimeMillis) {
try {
wait(Math.abs(currentTimeMillis - System.currentTimeMillis()));
} catch (InterruptedException unused) {
}
}
}
if (this.connected || this.done) {
return;
}
this.done = true;
String str = "Timeout reached for the connection to " + getHost() + Constants.COLON_SEPARATOR + getPort() + ".";
throw new XMPPException(str, new XMPPError(XMPPError.Condition.remote_server_timeout, str));
} catch (Exception e2) {
throw new XMPPException("Can't connect to " + getServiceName(), e2);
}
}
@Override
public void disconnect(Presence presence) {
if (this.connected) {
shutdown(presence);
Roster roster = this.roster;
if (roster != null) {
roster.cleanup();
this.roster = null;
}
this.sendListeners.clear();
this.recvListeners.clear();
this.collectors.clear();
this.interceptors.clear();
this.wasAuthenticated = false;
this.isFirstInitialization = true;
Iterator<ConnectionListener> it = getConnectionListeners().iterator();
while (it.hasNext()) {
try {
it.next().connectionClosed();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
@Override
public String getConnectionID() {
if (!this.connected) {
return null;
}
String str = this.authID;
return str != null ? str : this.sessionID;
}
@Override
public Roster getRoster() {
if (this.roster == null) {
return null;
}
if (!this.config.isRosterLoadedAtLogin()) {
this.roster.reload();
}
Roster roster = this.roster;
if (!roster.rosterInitialized) {
try {
synchronized (roster) {
long packetReplyTimeout = SmackConfiguration.getPacketReplyTimeout();
long currentTimeMillis = System.currentTimeMillis();
while (true) {
Roster roster2 = this.roster;
if (roster2.rosterInitialized || packetReplyTimeout <= 0) {
break;
}
roster2.wait(packetReplyTimeout);
long currentTimeMillis2 = System.currentTimeMillis();
packetReplyTimeout -= currentTimeMillis2 - currentTimeMillis;
currentTimeMillis = currentTimeMillis2;
}
}
} catch (InterruptedException unused) {
}
}
return this.roster;
}
@Override
public String getUser() {
return this.user;
}
@Override
protected void initDebugger() {
this.writer = new Writer() {
@Override
public void close() {
}
@Override
public void flush() {
}
@Override
public void write(char[] cArr, int i2, int i3) {
}
};
try {
this.readerPipe = new PipedWriter();
this.reader = new PipedReader(this.readerPipe);
} catch (IOException unused) {
}
super.initDebugger();
this.client.addBOSHClientResponseListener(new BOSHClientResponseListener() {
public void responseReceived(BOSHMessageEvent bOSHMessageEvent) {
if (bOSHMessageEvent.getBody() != null) {
try {
BOSHConnection.this.readerPipe.write(bOSHMessageEvent.getBody().toXML());
BOSHConnection.this.readerPipe.flush();
} catch (Exception unused2) {
}
}
}
});
this.client.addBOSHClientRequestListener(new BOSHClientRequestListener() {
public void requestSent(BOSHMessageEvent bOSHMessageEvent) {
if (bOSHMessageEvent.getBody() != null) {
try {
BOSHConnection.this.writer.write(bOSHMessageEvent.getBody().toXML());
} catch (Exception unused2) {
}
}
}
});
Thread thread = new Thread() {
private Thread thread = this;
private int bufferLength = WXMediaMessage.DESCRIPTION_LENGTH_LIMIT;
@Override
public void run() {
try {
char[] cArr = new char[this.bufferLength];
while (BOSHConnection.this.readerConsumer == this.thread && !BOSHConnection.this.done) {
BOSHConnection.this.reader.read(cArr, 0, this.bufferLength);
}
} catch (IOException unused2) {
}
}
};
this.readerConsumer = thread;
thread.setDaemon(true);
this.readerConsumer.start();
}
@Override
public boolean isAnonymous() {
return this.anonymous;
}
@Override
public boolean isAuthenticated() {
return this.authenticated;
}
@Override
public boolean isConnected() {
return this.connected;
}
@Override
public boolean isSecureConnection() {
return false;
}
@Override
public boolean isUsingCompression() {
return false;
}
@Override
public void login(String str, String str2, String str3) throws XMPPException {
SmackDebugger smackDebugger;
if (!isConnected()) {
throw new IllegalStateException("Not connected to server.");
}
if (this.authenticated) {
throw new IllegalStateException("Already logged in to server.");
}
String trim = str.toLowerCase().trim();
String authenticate = (this.config.isSASLAuthenticationEnabled() && this.saslAuthentication.hasNonAnonymousAuthentication()) ? str2 != null ? this.saslAuthentication.authenticate(trim, str2, str3) : this.saslAuthentication.authenticate(trim, str3, this.config.getCallbackHandler()) : new NonSASLAuthentication(this).authenticate(trim, str2, str3);
if (authenticate != null) {
this.user = authenticate;
this.config.setServiceName(StringUtils.parseServer(authenticate));
} else {
String str4 = String.valueOf(trim) + "@" + getServiceName();
this.user = str4;
if (str3 != null) {
this.user = String.valueOf(str4) + CookieSpec.PATH_DELIM + str3;
}
}
if (this.roster == null) {
if (this.rosterStorage == null) {
this.roster = new Roster(this);
} else {
this.roster = new Roster(this, this.rosterStorage);
}
}
if (this.config.isSendPresence()) {
sendPacket(new Presence(Presence.Type.available));
}
this.authenticated = true;
this.anonymous = false;
if (this.config.isRosterLoadedAtLogin()) {
this.roster.reload();
}
this.config.setLoginInfo(trim, str2, str3);
if (!this.config.isDebuggerEnabled() || (smackDebugger = this.debugger) == null) {
return;
}
smackDebugger.userHasLogged(this.user);
}
@Override
public void loginAnonymously() throws XMPPException {
SmackDebugger smackDebugger;
if (!isConnected()) {
throw new IllegalStateException("Not connected to server.");
}
if (this.authenticated) {
throw new IllegalStateException("Already logged in to server.");
}
String authenticateAnonymously = (this.config.isSASLAuthenticationEnabled() && this.saslAuthentication.hasAnonymousAuthentication()) ? this.saslAuthentication.authenticateAnonymously() : new NonSASLAuthentication(this).authenticateAnonymously();
this.user = authenticateAnonymously;
this.config.setServiceName(StringUtils.parseServer(authenticateAnonymously));
this.roster = null;
if (this.config.isSendPresence()) {
sendPacket(new Presence(Presence.Type.available));
}
this.authenticated = true;
this.anonymous = true;
if (!this.config.isDebuggerEnabled() || (smackDebugger = this.debugger) == null) {
return;
}
smackDebugger.userHasLogged(this.user);
}
protected void notifyConnectionError(Exception exc) {
shutdown(new Presence(Presence.Type.unavailable));
exc.printStackTrace();
Iterator<ConnectionListener> it = getConnectionListeners().iterator();
while (it.hasNext()) {
try {
it.next().connectionClosedOnError(exc);
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
protected void processPacket(Packet packet) {
if (packet == null) {
return;
}
Iterator<PacketCollector> it = getPacketCollectors().iterator();
while (it.hasNext()) {
it.next().processPacket(packet);
}
this.listenerExecutor.submit(new ListenerNotification(packet));
}
protected void send(ComposableBody composableBody) throws BOSHException {
if (!this.connected) {
throw new IllegalStateException("Not connected to a server!");
}
Objects.requireNonNull(composableBody, "Body mustn't be null!");
if (this.sessionID != null) {
composableBody = composableBody.rebuild().setAttribute(BodyQName.create(BOSH_URI, "sid"), this.sessionID).build();
}
this.client.send(composableBody);
}
@Override
public void sendPacket(Packet packet) {
if (!isConnected()) {
throw new IllegalStateException("Not connected to server.");
}
Objects.requireNonNull(packet, "Packet is null.");
if (this.done) {
return;
}
firePacketInterceptors(packet);
try {
send(ComposableBody.builder().setPayloadXML(packet.toXML()).build());
firePacketSendingListeners(packet);
} catch (BOSHException e2) {
e2.printStackTrace();
}
}
@Override
public void setRosterStorage(RosterStorage rosterStorage) throws IllegalStateException {
if (this.roster != null) {
throw new IllegalStateException("Roster is already initialized");
}
this.rosterStorage = rosterStorage;
}
protected void shutdown(Presence presence) {
setWasAuthenticated(this.authenticated);
this.authID = null;
this.sessionID = null;
this.done = true;
this.authenticated = false;
this.connected = false;
this.isFirstInitialization = false;
try {
this.client.disconnect(ComposableBody.builder().setNamespaceDefinition("xmpp", XMPP_BOSH_NS).setPayloadXML(presence.toXML()).build());
Thread.sleep(150L);
} catch (Exception unused) {
}
PipedWriter pipedWriter = this.readerPipe;
if (pipedWriter != null) {
try {
pipedWriter.close();
} catch (Throwable unused2) {
}
this.reader = null;
}
Reader reader = this.reader;
if (reader != null) {
try {
reader.close();
} catch (Throwable unused3) {
}
this.reader = null;
}
Writer writer = this.writer;
if (writer != null) {
try {
writer.close();
} catch (Throwable unused4) {
}
this.writer = null;
}
ExecutorService executorService = this.listenerExecutor;
if (executorService != null) {
executorService.shutdown();
}
this.readerConsumer = null;
}
public BOSHConnection(BOSHConfiguration bOSHConfiguration) {
super(bOSHConfiguration);
this.connected = false;
this.authenticated = false;
this.anonymous = false;
this.isFirstInitialization = true;
this.wasAuthenticated = false;
this.done = false;
this.authID = null;
this.sessionID = null;
this.user = null;
this.roster = null;
this.config = bOSHConfiguration;
}
}