-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Description
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
Labels
No labels