Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package at.yawk.dbus.protocol.auth;
import at.yawk.dbus.protocol.auth.command.AgreeUnixFd;
import at.yawk.dbus.protocol.auth.command.Auth;
import at.yawk.dbus.protocol.auth.command.Begin;
import at.yawk.dbus.protocol.auth.command.Cancel;
import at.yawk.dbus.protocol.auth.command.Command;
import at.yawk.dbus.protocol.auth.command.Data;
import at.yawk.dbus.protocol.auth.command.Error;
import at.yawk.dbus.protocol.auth.command.NegotiateUnixFd;
import at.yawk.dbus.protocol.auth.command.Ok;
import at.yawk.dbus.protocol.auth.command.Rejected;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.DecoderException;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.util.ByteProcessor;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import lombok.extern.slf4j.Slf4j;
/**
* @author yawkat
*/
@Slf4j
public class CommandCodec extends ChannelDuplexHandler {
/*
* This is a custom ChannelHandlerAdapter instead of a ByteToMessageCodec since ByteToMessageCodec has a bug
* (https://github.com/netty/netty/issues/4087) where it will discard data on removal from pipeline.
*/
private static final Charset CHARSET = StandardCharsets.US_ASCII;
private static final byte[] CRLF = new byte[]{ '\r', '\n' };
private static final Map, Command>> FACTORIES = new HashMap<>();
static {
FACTORIES.put(AgreeUnixFd.NAME, AgreeUnixFd::parse);
FACTORIES.put(Auth.NAME, Auth::parse);
FACTORIES.put(Begin.NAME, Begin::parse);
FACTORIES.put(Cancel.NAME, Cancel::parse);
FACTORIES.put(Data.NAME, Data::parse);
FACTORIES.put(Error.NAME, Error::parse);
FACTORIES.put(NegotiateUnixFd.NAME, NegotiateUnixFd::parse);
FACTORIES.put(Ok.NAME, Ok::parse);
FACTORIES.put(Rejected.NAME, Rejected::parse);
}
private final ByteToMessageDecoder decoder = new ByteToMessageDecoder() {
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List