mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-08 20:46:12 +01:00
test for stream size
This commit is contained in:
parent
abc0a8c78a
commit
2b58cc702a
1 changed files with 41 additions and 38 deletions
|
@ -559,47 +559,50 @@ dvc_parseMQTTPacket( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* topic,
|
||||||
XP_LOGFF( "bad message: too short" );
|
XP_LOGFF( "bad message: too short" );
|
||||||
} else if ( proto == PROTO_1 || proto == PROTO_3 ) {
|
} else if ( proto == PROTO_1 || proto == PROTO_3 ) {
|
||||||
MQTTDevID senderID;
|
MQTTDevID senderID;
|
||||||
stream_getBytes( stream, &senderID, sizeof(senderID) );
|
if ( stream_gotBytes( stream, &senderID, sizeof(senderID) ) ) {
|
||||||
senderID = be64toh( senderID );
|
senderID = be64toh( senderID );
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
XP_UCHAR tmp[32];
|
XP_UCHAR tmp[32];
|
||||||
formatMQTTDevID( &senderID, tmp, VSIZE(tmp) );
|
formatMQTTDevID( &senderID, tmp, VSIZE(tmp) );
|
||||||
XP_LOGFF( "senderID: %s", tmp );
|
XP_LOGFF( "senderID: %s", tmp );
|
||||||
#endif
|
#endif
|
||||||
if ( proto < PROTO_3 ) {
|
if ( proto < PROTO_3 ) {
|
||||||
gameID = stream_getU32( stream );
|
gameID = stream_getU32( stream );
|
||||||
|
} else {
|
||||||
|
XP_ASSERT( 0 != gameID );
|
||||||
|
}
|
||||||
|
|
||||||
|
MQTTCmd cmd = stream_getU8( stream );
|
||||||
|
|
||||||
|
/* Need to ack even if discarded/malformed */
|
||||||
|
ackMQTTMsg( dutil, xwe, topic, gameID, buf, len );
|
||||||
|
|
||||||
|
switch ( cmd ) {
|
||||||
|
case CMD_INVITE: {
|
||||||
|
NetLaunchInfo nli = {0};
|
||||||
|
if ( nli_makeFromStream( &nli, stream ) ) {
|
||||||
|
dutil_onInviteReceived( dutil, xwe, &nli );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CMD_DEVGONE:
|
||||||
|
case CMD_MSG: {
|
||||||
|
CommsAddrRec from = {0};
|
||||||
|
addr_addType( &from, COMMS_CONN_MQTT );
|
||||||
|
from.u.mqtt.devID = senderID;
|
||||||
|
if ( CMD_MSG == cmd ) {
|
||||||
|
dispatchMsgs( dutil, xwe, proto, stream, gameID, &from );
|
||||||
|
} else if ( CMD_DEVGONE == cmd ) {
|
||||||
|
dutil_onGameGoneReceived( dutil, xwe, gameID, &from );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
XP_LOGFF( "unknown command %d; dropping message", cmd );
|
||||||
|
// XP_ASSERT(0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
XP_ASSERT( 0 != gameID );
|
XP_LOGFF( "no senderID found; bailing" );
|
||||||
}
|
|
||||||
|
|
||||||
MQTTCmd cmd = stream_getU8( stream );
|
|
||||||
|
|
||||||
/* Need to ack even if discarded/malformed */
|
|
||||||
ackMQTTMsg( dutil, xwe, topic, gameID, buf, len );
|
|
||||||
|
|
||||||
switch ( cmd ) {
|
|
||||||
case CMD_INVITE: {
|
|
||||||
NetLaunchInfo nli = {0};
|
|
||||||
if ( nli_makeFromStream( &nli, stream ) ) {
|
|
||||||
dutil_onInviteReceived( dutil, xwe, &nli );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CMD_DEVGONE:
|
|
||||||
case CMD_MSG: {
|
|
||||||
CommsAddrRec from = {0};
|
|
||||||
addr_addType( &from, COMMS_CONN_MQTT );
|
|
||||||
from.u.mqtt.devID = senderID;
|
|
||||||
if ( CMD_MSG == cmd ) {
|
|
||||||
dispatchMsgs( dutil, xwe, proto, stream, gameID, &from );
|
|
||||||
} else if ( CMD_DEVGONE == cmd ) {
|
|
||||||
dutil_onGameGoneReceived( dutil, xwe, gameID, &from );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
XP_LOGFF( "unknown command %d; dropping message", cmd );
|
|
||||||
// XP_ASSERT(0);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
XP_LOGFF( "bad proto %d; dropping packet", proto );
|
XP_LOGFF( "bad proto %d; dropping packet", proto );
|
||||||
|
|
Loading…
Add table
Reference in a new issue