Skip to content

SipMessageStreamDecoder needs to be updated to work with the latest pkts.sip code #5

@joesaby

Description

@joesaby

I am not sure if there is a plan to update the versioning dependency with pkts-sip lib. If thats done, the example UAS, UAC will need to be updated because of the change in the builder patterns.

SipMessageStreamDecoder needs to be updated to work with the latest pkts.sip code. I put a small workaround in my repo, putting it in here for my own tracking

/**
 * 
 */
package io.sipstack.netty.codec.sip;

import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.pkts.packet.sip.impl.*;
import java.net.InetSocketAddress;
import java.util.List;

/**
 * @author jonas
 * 
 */
public class SipMessageStreamDecoder extends ByteToMessageDecoder {

    private final Clock clock;

    private SipMessageStreamBuilder builder;

    public SipMessageStreamDecoder(final Clock clock) {
        this.clock = clock;
        reset();
    }

    public SipMessageStreamDecoder() {
        this(new SystemClock());
    }

    @Override
    public boolean isSingleDecode() {
        return true;
    }

    @Override
    protected void decode(final ChannelHandlerContext ctx, final ByteBuf buffer, final List<Object> out)
            throws Exception {
        byte[] bytes = new byte[buffer.readableBytes()];
        buffer.readBytes(bytes);
        builder.process(bytes);
        if (builder.isDone()){
            long arrivalTime = this.clock.getCurrentTimeMillis();
            final Channel channel = ctx.channel();
            final Connection connection = new TcpConnection(channel, (InetSocketAddress) channel.remoteAddress());
            out.add(new DefaultSipMessageEvent(connection, builder.build(), arrivalTime));
            while (builder.hasUnprocessData()){
                if (builder.process()) {
                    out.add(new DefaultSipMessageEvent(connection, builder.build(), arrivalTime));
                    reset();
                }
            }
        }
    }

    private void reset() {
        final SipMessageStreamBuilder.Configuration config = new SipMessageStreamBuilder.DefaultConfiguration();
        this.builder = new SipMessageStreamBuilder(config);
    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions