use of com.zx.sms.codec.cmpp.msg.CmppConnectResponseMessage 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.CmppConnectResponseMessage in project SMSGate by Lihuanghe.
the class CmppConnectResponseMessageCodec method decode.
@Override
protected void decode(ChannelHandlerContext ctx, Message msg, List<Object> out) throws Exception {
int commandId = msg.getHeader().getCommandId();
if (commandId != packetType.getCommandId()) {
// 不解析,交给下一个codec
out.add(msg);
return;
}
CmppConnectResponseMessage responseMessage = new CmppConnectResponseMessage(msg.getHeader());
byte[] body = msg.getBodyBuffer();
if (body.length == 21) {
ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
responseMessage.setStatus(bodyBuffer.readUnsignedInt());
responseMessage.setAuthenticatorISMG(toArray(bodyBuffer, CmppConnectResponse.AUTHENTICATORISMG.getLength()));
responseMessage.setVersion(bodyBuffer.readUnsignedByte());
ReferenceCountUtil.release(bodyBuffer);
out.add(responseMessage);
} else {
if (body.length == 18) {
ByteBuf bodyBuffer = Unpooled.wrappedBuffer(body);
responseMessage.setStatus(bodyBuffer.readUnsignedByte());
responseMessage.setAuthenticatorISMG(toArray(bodyBuffer, Cmpp20ConnectResponse.AUTHENTICATORISMG.getLength()));
responseMessage.setVersion(bodyBuffer.readUnsignedByte());
ReferenceCountUtil.release(bodyBuffer);
out.add(responseMessage);
logger.warn("error CmppConnectResponseMessage body length. dump:{}", ByteBufUtil.hexDump(body));
} else {
throw new NotSupportedException("error cmpp CmppConnectResponseMessage data .");
}
}
}
use of com.zx.sms.codec.cmpp.msg.CmppConnectResponseMessage in project SMSGate by Lihuanghe.
the class Cmpp20ConnectResponseMessageCodec method decode.
@Override
protected void decode(ChannelHandlerContext ctx, Message msg, List<Object> out) throws Exception {
int commandId = msg.getHeader().getCommandId();
if (commandId != packetType.getCommandId()) {
// 不解析,交给下一个codec
out.add(msg);
return;
}
CmppConnectResponseMessage responseMessage = new CmppConnectResponseMessage(msg.getHeader());
byte[] body = msg.getBodyBuffer();
if (body.length == 18) {
ByteBuf bodyBuffer = Unpooled.wrappedBuffer(body);
responseMessage.setStatus(bodyBuffer.readUnsignedByte());
responseMessage.setAuthenticatorISMG(toArray(bodyBuffer, Cmpp20ConnectResponse.AUTHENTICATORISMG.getLength()));
responseMessage.setVersion(bodyBuffer.readUnsignedByte());
ReferenceCountUtil.release(bodyBuffer);
out.add(responseMessage);
} else {
if (body.length == 21) {
ByteBuf bodyBuffer = Unpooled.wrappedBuffer(body);
responseMessage.setStatus(bodyBuffer.readUnsignedInt());
responseMessage.setAuthenticatorISMG(toArray(bodyBuffer, CmppConnectResponse.AUTHENTICATORISMG.getLength()));
responseMessage.setVersion(bodyBuffer.readUnsignedByte());
ReferenceCountUtil.release(bodyBuffer);
out.add(responseMessage);
logger.warn("error Cmpp20ConnectResponseMessageCodec body length. dump:{}", ByteBufUtil.hexDump(body));
} else {
throw new NotSupportedException("error cmpp CmppConnectResponseMessage data .");
}
}
}
use of com.zx.sms.codec.cmpp.msg.CmppConnectResponseMessage in project SMSGate by Lihuanghe.
the class SessionLoginManager method failedLogin.
@Override
protected /**
* 状态 0:正确 1:消息结构错 2:非法源地址 3:认证错 4:版本太高 5~ :其他错误
*/
void failedLogin(ChannelHandlerContext ctx, Object msg, long status) {
if (msg instanceof CmppConnectRequestMessage) {
logger.error("Connected error status :{},msg : {}", status, msg);
CmppConnectRequestMessage message = (CmppConnectRequestMessage) msg;
// 认证失败
CmppConnectResponseMessage resp = new CmppConnectResponseMessage(message.getHeader().getSequenceId());
resp.setAuthenticatorISMG(new byte[16]);
resp.setStatus(status);
ChannelFuture promise = ctx.writeAndFlush(resp);
final ChannelHandlerContext finalctx = ctx;
promise.addListener(new GenericFutureListener() {
public void operationComplete(Future future) throws Exception {
finalctx.close();
}
});
} else {
logger.error("connect msg type error : {}", msg);
ctx.close();
}
}
use of com.zx.sms.codec.cmpp.msg.CmppConnectResponseMessage in project SMSGate by Lihuanghe.
the class TestCmppConnectResponseMessageCodec method testCode.
@Test
public void testCode() {
CmppConnectResponseMessage msg = new CmppConnectResponseMessage(238);
// 长度为16
msg.setAuthenticatorISMG("passwordpassword".getBytes());
ByteBuf buf = encode(msg);
ByteBuf copybuf = buf.copy();
int length = buf.readableBytes();
int expectLength = (getVersion() == 0x30 ? CmppConnectResponse.AUTHENTICATORISMG.getBodyLength() : Cmpp20ConnectResponse.AUTHENTICATORISMG.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());
CmppConnectResponseMessage result = decode(copybuf);
Assert.assertEquals(msg.getHeader().getSequenceId(), result.getHeader().getSequenceId());
Assert.assertArrayEquals(msg.getAuthenticatorISMG(), result.getAuthenticatorISMG());
}
Aggregations