mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-28 07:58:08 +01:00
cleanup
This commit is contained in:
parent
93b78bc3f6
commit
326a639ea5
1 changed files with 34 additions and 22 deletions
|
@ -113,6 +113,21 @@ processHeartbeat( unsigned char* buf, int bufLen, int socket )
|
||||||
}
|
}
|
||||||
} /* processHeartbeat */
|
} /* processHeartbeat */
|
||||||
|
|
||||||
|
static int
|
||||||
|
readCookie( unsigned char** bufp, const unsigned char* end,
|
||||||
|
char* outBuf )
|
||||||
|
{
|
||||||
|
unsigned char clen = **bufp;
|
||||||
|
++*bufp;
|
||||||
|
if ( *bufp < end && clen > 0 && clen < MAX_COOKIE_LEN ) {
|
||||||
|
memcpy( outBuf, *bufp, clen );
|
||||||
|
outBuf[clen] = '\0';
|
||||||
|
*bufp += clen;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
} /* readCookie */
|
||||||
|
|
||||||
/* A CONNECT message from a device gives us the hostID and socket we'll
|
/* A CONNECT message from a device gives us the hostID and socket we'll
|
||||||
* associate with one participant in a relayed session. We'll store this
|
* associate with one participant in a relayed session. We'll store this
|
||||||
* information with the cookie where other participants can find it when they
|
* information with the cookie where other participants can find it when they
|
||||||
|
@ -124,31 +139,28 @@ processHeartbeat( unsigned char* buf, int bufLen, int socket )
|
||||||
* outstanding. Otherwise close down the socket. And maybe the others in the
|
* outstanding. Otherwise close down the socket. And maybe the others in the
|
||||||
* game?
|
* game?
|
||||||
*/
|
*/
|
||||||
static CookieRef*
|
static void
|
||||||
processConnect( unsigned char* bufp, int bufLen, int socket )
|
processConnect( unsigned char* bufp, int bufLen, int socket )
|
||||||
{
|
{
|
||||||
logf( "processConnect" );
|
char cookie[MAX_COOKIE_LEN+1];
|
||||||
CookieRef* cref = NULL;
|
|
||||||
unsigned char* end = bufp + bufLen;
|
unsigned char* end = bufp + bufLen;
|
||||||
unsigned char clen = *bufp++;
|
|
||||||
if ( bufp < end && clen < MAX_COOKIE_LEN ) {
|
|
||||||
char cookie[MAX_COOKIE_LEN+1];
|
|
||||||
memcpy( cookie, bufp, clen );
|
|
||||||
cookie[clen] = '\0';
|
|
||||||
logf( "got cookie: %s", cookie );
|
|
||||||
bufp += clen;
|
|
||||||
|
|
||||||
if ( bufp < end ) {
|
logf( "processConnect" );
|
||||||
HostID srcID = getNetShort( &bufp );
|
|
||||||
CookieID cookieID = getNetLong( &bufp );
|
if ( readCookie( &bufp, end, cookie ) ) {
|
||||||
if ( bufp == end ) {
|
|
||||||
cref = get_make_cookieRef( cookie, cookieID );
|
HostID srcID;
|
||||||
assert( cref != NULL );
|
CookieID cookieID;
|
||||||
cref->Connect( socket, srcID );
|
|
||||||
}
|
if ( bufp + sizeof(srcID) + sizeof(cookieID) == end ) {
|
||||||
|
srcID = getNetShort( &bufp );
|
||||||
|
cookieID = getNetLong( &bufp );
|
||||||
|
|
||||||
|
CookieRef* cref = get_make_cookieRef( cookie, cookieID );
|
||||||
|
assert( cref != NULL );
|
||||||
|
cref->Connect( socket, srcID );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cref;
|
|
||||||
} /* processConnect */
|
} /* processConnect */
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -190,13 +202,11 @@ forwardMessage( unsigned char* buf, int buflen, int srcSocket )
|
||||||
static void
|
static void
|
||||||
processMessage( unsigned char* buf, int bufLen, int socket )
|
processMessage( unsigned char* buf, int bufLen, int socket )
|
||||||
{
|
{
|
||||||
CookieRef* cref;
|
|
||||||
|
|
||||||
XWRELAY_Cmd cmd = *buf;
|
XWRELAY_Cmd cmd = *buf;
|
||||||
switch( cmd ) {
|
switch( cmd ) {
|
||||||
case XWRELAY_CONNECT:
|
case XWRELAY_CONNECT:
|
||||||
logf( "processMessage got XWRELAY_CONNECT" );
|
logf( "processMessage got XWRELAY_CONNECT" );
|
||||||
cref = processConnect( buf+1, bufLen-1, socket );
|
processConnect( buf+1, bufLen-1, socket );
|
||||||
break;
|
break;
|
||||||
case XWRELAY_CONNECTRESP:
|
case XWRELAY_CONNECTRESP:
|
||||||
logf( "bad: processMessage got XWRELAY_CONNECTRESP" );
|
logf( "bad: processMessage got XWRELAY_CONNECTRESP" );
|
||||||
|
@ -215,6 +225,8 @@ processMessage( unsigned char* buf, int bufLen, int socket )
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
}
|
}
|
||||||
} /* processMessage */
|
} /* processMessage */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue