导航菜单

页面标题

页面副标题

95爱播免登录版 v3.1.9 - InBandBytestreamManager.java 源代码

正在查看: 95爱播免登录版 v3.1.9 应用的 InBandBytestreamManager.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package org.jivesoftware.smackx.bytestreams.ibb;

import com.zego.zegoliveroom.constants.ZegoConstants;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.smack.AbstractConnectionListener;
import org.jivesoftware.smack.Connection;
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;

public class InBandBytestreamManager implements BytestreamManager {
    public static final int MAXIMUM_BLOCK_SIZE = 65535;
    public static final String NAMESPACE = "http://jabber.org/protocol/ibb";
    private static final String SESSION_ID_PREFIX = "jibb_";
    private static final Map<Connection, InBandBytestreamManager> managers;
    private static final Random randomGenerator;
    private final CloseListener closeListener;
    private final Connection connection;
    private final DataListener dataListener;
    private final InitiationListener initiationListener;
    private final Map<String, BytestreamListener> userListeners = new ConcurrentHashMap();
    private final List<BytestreamListener> allRequestListeners = Collections.synchronizedList(new LinkedList());
    private final Map<String, InBandBytestreamSession> sessions = new ConcurrentHashMap();
    private int defaultBlockSize = ZegoConstants.ErrorMask.NerworkErrorMask;
    private int maximumBlockSize = MAXIMUM_BLOCK_SIZE;
    private StanzaType stanza = StanzaType.IQ;
    private List<String> ignoredBytestreamRequests = Collections.synchronizedList(new LinkedList());

    public enum StanzaType {
        IQ,
        MESSAGE;

        public static StanzaType[] valuesCustom() {
            StanzaType[] valuesCustom = values();
            int length = valuesCustom.length;
            StanzaType[] stanzaTypeArr = new StanzaType[length];
            System.arraycopy(valuesCustom, 0, stanzaTypeArr, 0, length);
            return stanzaTypeArr;
        }
    }

    static {
        Connection.addConnectionCreationListener(new ConnectionCreationListener() {
            @Override
            public void connectionCreated(Connection connection) {
                final InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);
                connection.addConnectionListener(new AbstractConnectionListener() {
                    @Override
                    public void connectionClosed() {
                        byteStreamManager.disableService();
                    }
                });
            }
        });
        randomGenerator = new Random();
        managers = new HashMap();
    }

    private InBandBytestreamManager(Connection connection) {
        this.connection = connection;
        InitiationListener initiationListener = new InitiationListener(this);
        this.initiationListener = initiationListener;
        connection.addPacketListener(initiationListener, initiationListener.getFilter());
        DataListener dataListener = new DataListener(this);
        this.dataListener = dataListener;
        connection.addPacketListener(dataListener, dataListener.getFilter());
        CloseListener closeListener = new CloseListener(this);
        this.closeListener = closeListener;
        connection.addPacketListener(closeListener, closeListener.getFilter());
    }

    public void disableService() {
        managers.remove(this.connection);
        this.connection.removePacketListener(this.initiationListener);
        this.connection.removePacketListener(this.dataListener);
        this.connection.removePacketListener(this.closeListener);
        this.initiationListener.shutdown();
        this.userListeners.clear();
        this.allRequestListeners.clear();
        this.sessions.clear();
        this.ignoredBytestreamRequests.clear();
    }

    public static synchronized InBandBytestreamManager getByteStreamManager(Connection connection) {
        synchronized (InBandBytestreamManager.class) {
            if (connection == null) {
                return null;
            }
            Map<Connection, InBandBytestreamManager> map = managers;
            InBandBytestreamManager inBandBytestreamManager = map.get(connection);
            if (inBandBytestreamManager == null) {
                inBandBytestreamManager = new InBandBytestreamManager(connection);
                map.put(connection, inBandBytestreamManager);
            }
            return inBandBytestreamManager;
        }
    }

    private String getNextSessionID() {
        return SESSION_ID_PREFIX + Math.abs(randomGenerator.nextLong());
    }

    @Override
    public void addIncomingBytestreamListener(BytestreamListener bytestreamListener) {
        this.allRequestListeners.add(bytestreamListener);
    }

    protected List<BytestreamListener> getAllRequestListeners() {
        return this.allRequestListeners;
    }

    protected Connection getConnection() {
        return this.connection;
    }

    public int getDefaultBlockSize() {
        return this.defaultBlockSize;
    }

    protected List<String> getIgnoredBytestreamRequests() {
        return this.ignoredBytestreamRequests;
    }

    public int getMaximumBlockSize() {
        return this.maximumBlockSize;
    }

    protected Map<String, InBandBytestreamSession> getSessions() {
        return this.sessions;
    }

    public StanzaType getStanza() {
        return this.stanza;
    }

    protected BytestreamListener getUserListener(String str) {
        return this.userListeners.get(str);
    }

    public void ignoreBytestreamRequestOnce(String str) {
        this.ignoredBytestreamRequests.add(str);
    }

    @Override
    public void removeIncomingBytestreamListener(BytestreamListener bytestreamListener) {
        this.allRequestListeners.remove(bytestreamListener);
    }

    protected void replyItemNotFoundPacket(IQ iq) {
        this.connection.sendPacket(IQ.createErrorResponse(iq, new XMPPError(XMPPError.Condition.item_not_found)));
    }

    protected void replyRejectPacket(IQ iq) {
        this.connection.sendPacket(IQ.createErrorResponse(iq, new XMPPError(XMPPError.Condition.no_acceptable)));
    }

    protected void replyResourceConstraintPacket(IQ iq) {
        this.connection.sendPacket(IQ.createErrorResponse(iq, new XMPPError(XMPPError.Condition.resource_constraint)));
    }

    public void setDefaultBlockSize(int i2) {
        if (i2 <= 0 || i2 > 65535) {
            throw new IllegalArgumentException("Default block size must be between 1 and 65535");
        }
        this.defaultBlockSize = i2;
    }

    public void setMaximumBlockSize(int i2) {
        if (i2 <= 0 || i2 > 65535) {
            throw new IllegalArgumentException("Maximum block size must be between 1 and 65535");
        }
        this.maximumBlockSize = i2;
    }

    public void setStanza(StanzaType stanzaType) {
        this.stanza = stanzaType;
    }

    @Override
    public void addIncomingBytestreamListener(BytestreamListener bytestreamListener, String str) {
        this.userListeners.put(str, bytestreamListener);
    }

    @Override
    public void removeIncomingBytestreamListener(String str) {
        this.userListeners.remove(str);
    }

    @Override
    public InBandBytestreamSession establishSession(String str) throws XMPPException {
        return establishSession(str, getNextSessionID());
    }

    @Override
    public InBandBytestreamSession establishSession(String str, String str2) throws XMPPException {
        Open open = new Open(str2, this.defaultBlockSize, this.stanza);
        open.setTo(str);
        SyncPacketSend.getReply(this.connection, open);
        InBandBytestreamSession inBandBytestreamSession = new InBandBytestreamSession(this.connection, open, str);
        this.sessions.put(str2, inBandBytestreamSession);
        return inBandBytestreamSession;
    }
}