use of com.zx.sms.codec.cmpp.msg.CmppConnectRequestMessage in project SMSGate by Lihuanghe.
the class SessionLoginManager method doLoginSuccess.
@Override
protected void doLoginSuccess(ChannelHandlerContext ctx, EndpointEntity entity, Object msg) {
CMPPServerChildEndpointEntity childentity = (CMPPServerChildEndpointEntity) entity;
CmppConnectRequestMessage message = (CmppConnectRequestMessage) msg;
// channelHandler已绑定完成,给客户端发resp.
CmppConnectResponseMessage resp = new CmppConnectResponseMessage(message.getHeader().getSequenceId());
resp.setVersion(childentity.getVersion());
resp.setStatus(0);
resp.setAuthenticatorISMG(DigestUtils.md5(Bytes.concat(Ints.toByteArray((int) resp.getStatus()), message.getAuthenticatorSource(), childentity.getPassword().getBytes(childentity.getChartset()))));
ctx.channel().writeAndFlush(resp);
}
use of com.zx.sms.codec.cmpp.msg.CmppConnectRequestMessage in project SMSGate by Lihuanghe.
the class CmppConnectRequestMessageCodec method decode.
@Override
protected void decode(ChannelHandlerContext ctx, Message msg, List<Object> out) throws Exception {
int commandId = msg.getHeader().getCommandId();
if (packetType.getCommandId() != commandId) {
// 不解析,交给下一个codec
out.add(msg);
return;
}
CmppConnectRequestMessage requestMessage = new CmppConnectRequestMessage(msg.getHeader());
ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
requestMessage.setSourceAddr(bodyBuffer.readCharSequence(CmppConnectRequest.SOURCEADDR.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
requestMessage.setAuthenticatorSource(toArray(bodyBuffer, CmppConnectRequest.AUTHENTICATORSOURCE.getLength()));
requestMessage.setVersion(bodyBuffer.readUnsignedByte());
requestMessage.setTimestamp(bodyBuffer.readUnsignedInt());
ReferenceCountUtil.release(bodyBuffer);
out.add(requestMessage);
}
use of com.zx.sms.codec.cmpp.msg.CmppConnectRequestMessage in project SMSGate by Lihuanghe.
the class TestCmppConnectRequestMessageCodec method testCode.
@Test
public void testCode() {
CmppConnectRequestMessage msg = new CmppConnectRequestMessage();
msg.setSourceAddr("106581");
// 长度为16
msg.setAuthenticatorSource("passwordpassword".getBytes());
ByteBuf buf = encode(msg);
ByteBuf copybuf = buf.copy();
int length = buf.readableBytes();
int expectLength = CmppConnectRequest.AUTHENTICATORSOURCE.getBodyLength() + CmppHead.COMMANDID.getHeadLength();
Assert.assertEquals(expectLength, length);
Assert.assertEquals(expectLength, buf.readInt());
Assert.assertEquals(msg.getPacketType().getCommandId(), buf.readInt());
Assert.assertEquals(msg.getHeader().getSequenceId(), buf.readInt());
CmppConnectRequestMessage result = decode(copybuf);
Assert.assertEquals(msg.getHeader().getSequenceId(), result.getHeader().getSequenceId());
Assert.assertEquals(msg.getSourceAddr(), result.getSourceAddr());
Assert.assertArrayEquals(msg.getAuthenticatorSource(), result.getAuthenticatorSource());
}
use of com.zx.sms.codec.cmpp.msg.CmppConnectRequestMessage in project SMSGate by Lihuanghe.
the class SessionLoginManager method queryEndpointEntityByMsg.
@Override
protected EndpointEntity queryEndpointEntityByMsg(Object msg) {
if (msg instanceof CmppConnectRequestMessage) {
CmppConnectRequestMessage message = (CmppConnectRequestMessage) msg;
String username = message.getSourceAddr();
if (entity instanceof ServerEndpoint) {
ServerEndpoint serverEntity = (ServerEndpoint) entity;
return serverEntity.getChild(username.trim());
}
}
return null;
}
use of com.zx.sms.codec.cmpp.msg.CmppConnectRequestMessage in project SMSGate by Lihuanghe.
the class SessionLoginManager method changeProtoVersion.
@Override
protected void changeProtoVersion(ChannelHandlerContext ctx, EndpointEntity entity, Object msg) throws Exception {
CmppConnectRequestMessage message = (CmppConnectRequestMessage) msg;
final short clientVersion = message.getVersion();
short aim_ver = clientVersion;
if (entity != null) {
CMPPServerChildEndpointEntity childentity = (CMPPServerChildEndpointEntity) entity;
// 以服务端配置的版本为准
aim_ver = childentity.getVersion();
// 发送ConnectRequest里的Version跟配置的不同
if (aim_ver != clientVersion) {
logger.warn("receive version code {} ,expected version is {} .I would use version {}", clientVersion, aim_ver, aim_ver);
}
}
if ((short) 0x30 != aim_ver) {
// 以配置的协议版本为准
// 更换协议解析器
logger.info("changeCodec to version:{}", aim_ver);
ctx.pipeline().replace(GlobalConstance.codecName, GlobalConstance.codecName, CMPPCodecChannelInitializer.getCodecHandler(aim_ver));
}
}
Aggregations