diff --git a/xwords4/android/XWords4/jni/Android.mk b/xwords4/android/XWords4/jni/Android.mk index c37ba7dc2..007c6877b 100644 --- a/xwords4/android/XWords4/jni/Android.mk +++ b/xwords4/android/XWords4/jni/Android.mk @@ -84,7 +84,7 @@ COMMON_SRC_FILES += \ $(COMMON_PATH)/memstream.c \ $(COMMON_PATH)/movestak.c \ $(COMMON_PATH)/dbgutil.c \ - $(COMMON_PATH)/invit.c \ + $(COMMON_PATH)/nli.c \ LOCAL_CFLAGS+=$(LOCAL_C_INCLUDES) $(LOCAL_DEFINES) -Wall -std=c99 LOCAL_SRC_FILES := $(linux_SRC_FILES) $(LOCAL_SRC_FILES) $(COMMON_SRC_FILES) diff --git a/xwords4/android/XWords4/jni/xwjni.c b/xwords4/android/XWords4/jni/xwjni.c index 468ee7406..26445bc1b 100644 --- a/xwords4/android/XWords4/jni/xwjni.c +++ b/xwords4/android/XWords4/jni/xwjni.c @@ -32,7 +32,7 @@ #include "dictnry.h" #include "dictiter.h" #include "dictmgr.h" -#include "invit.h" +#include "nli.h" #include "utilwrapper.h" #include "drawwrapper.h" @@ -510,7 +510,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_nli_1to_1stream XWStreamCtxt* stream = mem_stream_make( MPPARM(mpool) vtMgr, NULL, 0, NULL ); - invit_saveToStream( &nli, stream ); + nli_saveToStream( &nli, stream ); result = streamToBArray( env, stream ); stream_destroy( stream ); @@ -534,7 +534,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_nli_1from_1stream XWStreamCtxt* stream = streamFromJStream( MPPARM(mpool) env, vtMgr, jstream ); NetLaunchInfo nli = {0}; - if ( invit_makeFromStream( &nli, stream ) ) { + if ( nli_makeFromStream( &nli, stream ) ) { setNLI( env, jnli, &nli ); } else { XP_LOGF( "%s: game_makeFromStream failed", __func__ ); diff --git a/xwords4/common/config.mk b/xwords4/common/config.mk index be10c90ab..022fe1b2c 100644 --- a/xwords4/common/config.mk +++ b/xwords4/common/config.mk @@ -40,7 +40,7 @@ COMMONSRC = \ $(COMMONDIR)/engine.c \ $(COMMONDIR)/memstream.c \ $(COMMONDIR)/comms.c \ - $(COMMONDIR)/invit.c \ + $(COMMONDIR)/nli.c \ $(COMMONDIR)/mempool.c \ $(COMMONDIR)/movestak.c \ $(COMMONDIR)/strutils.c \ @@ -75,7 +75,7 @@ COMMON4 = \ $(COMMONOBJDIR)/dragdrpp.o \ $(COMMONOBJDIR)/memstream.o \ $(COMMONOBJDIR)/comms.o \ - $(COMMONOBJDIR)/invit.o \ + $(COMMONOBJDIR)/nli.o \ $(COMMONOBJDIR)/mempool.o \ COMMON5 = \ diff --git a/xwords4/common/invit.c b/xwords4/common/invit.c deleted file mode 100644 index 81ef8d275..000000000 --- a/xwords4/common/invit.c +++ /dev/null @@ -1,169 +0,0 @@ -/* -*- compile-command: "cd ../linux && make MEMDEBUG=TRUE -j3"; -*- */ -/* - * Copyright 2001 - 2015 by Eric House (xwords@eehouse.org). All rights - * reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef NATIVE_NLI - -#include "invit.h" -#include "comms.h" -#include "strutils.h" - -void -invit_init( NetLaunchInfo* invit, const CurGameInfo* gi, const CommsAddrRec* addr, - XP_U16 nPlayers, XP_U16 forceChannel ) -{ - XP_MEMSET( invit, 0, sizeof(*invit) ); - invit->gameID = gi->gameID; - XP_STRCAT( invit->dict, gi->dictName ); - invit->lang = gi->dictLang; - invit->nPlayersT = gi->nPlayers; - invit->nPlayersH = nPlayers; - invit->forceChannel = forceChannel; - - if ( addr_hasType( addr, COMMS_CONN_RELAY ) ) { - types_addType( &invit->_conTypes, COMMS_CONN_RELAY ); - XP_STRCAT( invit->room, addr->u.ip_relay.invite ); - } - -} - -static XP_U32 -gameID( const NetLaunchInfo* invit ) -{ - XP_U32 gameID = invit->gameID; - if ( 0 == gameID ) { - sscanf( invit->inviteID, "%X", &gameID ); - } - return gameID; -} - -void -invit_setDevID( NetLaunchInfo* invit, XP_U32 devID ) -{ - invit->devID = devID; - types_addType( &invit->_conTypes, COMMS_CONN_RELAY ); -} - -void -invit_saveToStream( const NetLaunchInfo* invit, XWStreamCtxt* stream ) -{ - LOG_FUNC(); - stream_putU8( stream, invit->version ); - stream_putU16( stream, invit->_conTypes ); - XP_LOGF( "%s: wrote _conTypes: %x", __func__, invit->_conTypes ); - stream_putU16( stream, invit->lang ); - stringToStream( stream, invit->dict ); - stringToStream( stream, invit->gameName ); - stream_putU8( stream, invit->nPlayersT ); - stream_putU8( stream, invit->nPlayersH ); - stream_putU32( stream, gameID( invit ) ); - stream_putU8( stream, invit->forceChannel ); - - if ( types_hasType( invit->_conTypes, COMMS_CONN_RELAY ) ) { - XP_LOGF( "%s: writing relay stuff", __func__ ); - stringToStream( stream, invit->room ); - XP_LOGF( "%s: writing room: %s", __func__, invit->room ); - stringToStream( stream, invit->inviteID ); - stream_putU32( stream, invit->devID ); - } - if ( types_hasType( invit->_conTypes, COMMS_CONN_BT ) ) { - XP_LOGF( "%s: writing bt stuff", __func__ ); - stringToStream( stream, invit->btName ); - stringToStream( stream, invit->btAddress ); - } - if ( types_hasType( invit->_conTypes, COMMS_CONN_SMS ) ) { - XP_LOGF( "%s: writing sms stuff", __func__ ); - stringToStream( stream, invit->phone ); - stream_putU8( stream, invit->isGSM ); - stream_putU8( stream, invit->osType ); - stream_putU32( stream, invit->osVers ); - } - LOG_RETURN_VOID(); -} - -XP_Bool -invit_makeFromStream( NetLaunchInfo* invit, XWStreamCtxt* stream ) -{ - LOG_FUNC(); - XP_MEMSET( invit, 0, sizeof(*invit) ); - invit->version = stream_getU8( stream ); - XP_Bool success = 0 == invit->version; - if ( success ) { - invit->_conTypes = stream_getU16( stream ); - XP_LOGF( "%s: read _conTypes: %x", __func__, invit->_conTypes ); - invit->lang = stream_getU16( stream ); - stringFromStreamHere( stream, invit->dict, sizeof(invit->dict) ); - stringFromStreamHere( stream, invit->gameName, sizeof(invit->gameName) ); - invit->nPlayersT = stream_getU8( stream ); - invit->nPlayersH = stream_getU8( stream ); - invit->gameID = stream_getU32( stream ); - invit->forceChannel = stream_getU8( stream ); - - if ( types_hasType( invit->_conTypes, COMMS_CONN_RELAY ) ) { - XP_LOGF( "%s: reading relay stuff", __func__ ); - stringFromStreamHere( stream, invit->room, sizeof(invit->room) ); - XP_LOGF( "%s: read room: %s", __func__, invit->room ); - stringFromStreamHere( stream, invit->inviteID, sizeof(invit->inviteID) ); - invit->devID = stream_getU32( stream ); - } - if ( types_hasType( invit->_conTypes, COMMS_CONN_BT ) ) { - XP_LOGF( "%s: reading bt stuff", __func__ ); - stringFromStreamHere( stream, invit->btName, sizeof(invit->btName) ); - stringFromStreamHere( stream, invit->btAddress, sizeof(invit->btAddress) ); - } - if ( types_hasType( invit->_conTypes, COMMS_CONN_SMS ) ) { - XP_LOGF( "%s: reading sms stuff", __func__ ); - stringFromStreamHere( stream, invit->phone, sizeof(invit->phone) ); - invit->isGSM = stream_getU8( stream ); - invit->osType= stream_getU8( stream ); - invit->osVers = stream_getU32( stream ); - } - } - LOG_RETURNF( "%d", success ); - return success; -} - -void -invit_makeAddrRec( const NetLaunchInfo* invit, CommsAddrRec* addr ) -{ - XP_U32 state = 0; - CommsConnType type; - while ( types_iter( invit->_conTypes, &type, &state ) ) { - addr_addType( addr, type ); - switch( type ) { - case COMMS_CONN_RELAY: - XP_STRCAT( addr->u.ip_relay.invite, invit->room ); - /* String relayName = XWPrefs.getDefaultRelayHost( context ); */ - /* int relayPort = XWPrefs.getDefaultRelayPort( context ); */ - /* result.setRelayParams( relayName, relayPort, room ); */ - break; - case COMMS_CONN_BT: - XP_STRCAT( addr->u.bt.btAddr.chars, invit->btAddress ); - XP_STRCAT( addr->u.bt.hostName, invit->btName ); - break; - case COMMS_CONN_SMS: - XP_STRCAT( addr->u.sms.phone, invit->phone ); - break; - default: - XP_ASSERT(0); - break; - } - } -} -#endif diff --git a/xwords4/common/nli.c b/xwords4/common/nli.c new file mode 100644 index 000000000..1119def61 --- /dev/null +++ b/xwords4/common/nli.c @@ -0,0 +1,169 @@ +/* -*- compile-command: "cd ../linux && make MEMDEBUG=TRUE -j3"; -*- */ +/* + * Copyright 2001 - 2015 by Eric House (xwords@eehouse.org). All rights + * reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef NATIVE_NLI + +#include "nli.h" +#include "comms.h" +#include "strutils.h" + +void +nli_init( NetLaunchInfo* nli, const CurGameInfo* gi, const CommsAddrRec* addr, + XP_U16 nPlayers, XP_U16 forceChannel ) +{ + XP_MEMSET( nli, 0, sizeof(*nli) ); + nli->gameID = gi->gameID; + XP_STRCAT( nli->dict, gi->dictName ); + nli->lang = gi->dictLang; + nli->nPlayersT = gi->nPlayers; + nli->nPlayersH = nPlayers; + nli->forceChannel = forceChannel; + + if ( addr_hasType( addr, COMMS_CONN_RELAY ) ) { + types_addType( &nli->_conTypes, COMMS_CONN_RELAY ); + XP_STRCAT( nli->room, addr->u.ip_relay.invite ); + } + +} + +static XP_U32 +gameID( const NetLaunchInfo* nli ) +{ + XP_U32 gameID = nli->gameID; + if ( 0 == gameID ) { + sscanf( nli->inviteID, "%X", &gameID ); + } + return gameID; +} + +void +nli_setDevID( NetLaunchInfo* nli, XP_U32 devID ) +{ + nli->devID = devID; + types_addType( &nli->_conTypes, COMMS_CONN_RELAY ); +} + +void +nli_saveToStream( const NetLaunchInfo* nli, XWStreamCtxt* stream ) +{ + LOG_FUNC(); + stream_putU8( stream, nli->version ); + stream_putU16( stream, nli->_conTypes ); + XP_LOGF( "%s: wrote _conTypes: %x", __func__, nli->_conTypes ); + stream_putU16( stream, nli->lang ); + stringToStream( stream, nli->dict ); + stringToStream( stream, nli->gameName ); + stream_putU8( stream, nli->nPlayersT ); + stream_putU8( stream, nli->nPlayersH ); + stream_putU32( stream, gameID( nli ) ); + stream_putU8( stream, nli->forceChannel ); + + if ( types_hasType( nli->_conTypes, COMMS_CONN_RELAY ) ) { + XP_LOGF( "%s: writing relay stuff", __func__ ); + stringToStream( stream, nli->room ); + XP_LOGF( "%s: writing room: %s", __func__, nli->room ); + stringToStream( stream, nli->inviteID ); + stream_putU32( stream, nli->devID ); + } + if ( types_hasType( nli->_conTypes, COMMS_CONN_BT ) ) { + XP_LOGF( "%s: writing bt stuff", __func__ ); + stringToStream( stream, nli->btName ); + stringToStream( stream, nli->btAddress ); + } + if ( types_hasType( nli->_conTypes, COMMS_CONN_SMS ) ) { + XP_LOGF( "%s: writing sms stuff", __func__ ); + stringToStream( stream, nli->phone ); + stream_putU8( stream, nli->isGSM ); + stream_putU8( stream, nli->osType ); + stream_putU32( stream, nli->osVers ); + } + LOG_RETURN_VOID(); +} + +XP_Bool +nli_makeFromStream( NetLaunchInfo* nli, XWStreamCtxt* stream ) +{ + LOG_FUNC(); + XP_MEMSET( nli, 0, sizeof(*nli) ); + nli->version = stream_getU8( stream ); + XP_Bool success = 0 == nli->version; + if ( success ) { + nli->_conTypes = stream_getU16( stream ); + XP_LOGF( "%s: read _conTypes: %x", __func__, nli->_conTypes ); + nli->lang = stream_getU16( stream ); + stringFromStreamHere( stream, nli->dict, sizeof(nli->dict) ); + stringFromStreamHere( stream, nli->gameName, sizeof(nli->gameName) ); + nli->nPlayersT = stream_getU8( stream ); + nli->nPlayersH = stream_getU8( stream ); + nli->gameID = stream_getU32( stream ); + nli->forceChannel = stream_getU8( stream ); + + if ( types_hasType( nli->_conTypes, COMMS_CONN_RELAY ) ) { + XP_LOGF( "%s: reading relay stuff", __func__ ); + stringFromStreamHere( stream, nli->room, sizeof(nli->room) ); + XP_LOGF( "%s: read room: %s", __func__, nli->room ); + stringFromStreamHere( stream, nli->inviteID, sizeof(nli->inviteID) ); + nli->devID = stream_getU32( stream ); + } + if ( types_hasType( nli->_conTypes, COMMS_CONN_BT ) ) { + XP_LOGF( "%s: reading bt stuff", __func__ ); + stringFromStreamHere( stream, nli->btName, sizeof(nli->btName) ); + stringFromStreamHere( stream, nli->btAddress, sizeof(nli->btAddress) ); + } + if ( types_hasType( nli->_conTypes, COMMS_CONN_SMS ) ) { + XP_LOGF( "%s: reading sms stuff", __func__ ); + stringFromStreamHere( stream, nli->phone, sizeof(nli->phone) ); + nli->isGSM = stream_getU8( stream ); + nli->osType= stream_getU8( stream ); + nli->osVers = stream_getU32( stream ); + } + } + LOG_RETURNF( "%d", success ); + return success; +} + +void +nli_makeAddrRec( const NetLaunchInfo* nli, CommsAddrRec* addr ) +{ + XP_U32 state = 0; + CommsConnType type; + while ( types_iter( nli->_conTypes, &type, &state ) ) { + addr_addType( addr, type ); + switch( type ) { + case COMMS_CONN_RELAY: + XP_STRCAT( addr->u.ip_relay.invite, nli->room ); + /* String relayName = XWPrefs.getDefaultRelayHost( context ); */ + /* int relayPort = XWPrefs.getDefaultRelayPort( context ); */ + /* result.setRelayParams( relayName, relayPort, room ); */ + break; + case COMMS_CONN_BT: + XP_STRCAT( addr->u.bt.btAddr.chars, nli->btAddress ); + XP_STRCAT( addr->u.bt.hostName, nli->btName ); + break; + case COMMS_CONN_SMS: + XP_STRCAT( addr->u.sms.phone, nli->phone ); + break; + default: + XP_ASSERT(0); + break; + } + } +} +#endif diff --git a/xwords4/common/invit.h b/xwords4/common/nli.h similarity index 81% rename from xwords4/common/invit.h rename to xwords4/common/nli.h index 449aefc78..7b0d0fd7b 100644 --- a/xwords4/common/invit.h +++ b/xwords4/common/nli.h @@ -66,16 +66,16 @@ typedef struct _InviteInfo { } NetLaunchInfo; void -invit_init( NetLaunchInfo* invit, const CurGameInfo* gi, const CommsAddrRec* addr, - XP_U16 nPlayers, XP_U16 forceChannel ); +nli_init( NetLaunchInfo* invit, const CurGameInfo* gi, const CommsAddrRec* addr, + XP_U16 nPlayers, XP_U16 forceChannel ); -XP_Bool invit_makeFromStream( NetLaunchInfo* invit, XWStreamCtxt* stream ); -void invit_saveToStream( const NetLaunchInfo* invit, XWStreamCtxt* stream ); +XP_Bool nli_makeFromStream( NetLaunchInfo* invit, XWStreamCtxt* stream ); +void nli_saveToStream( const NetLaunchInfo* invit, XWStreamCtxt* stream ); -void invit_makeAddrRec( const NetLaunchInfo* invit, CommsAddrRec* addr ); +void nli_makeAddrRec( const NetLaunchInfo* invit, CommsAddrRec* addr ); -void invit_setDevID( NetLaunchInfo* invit, XP_U32 devID ); +void nli_setDevID( NetLaunchInfo* invit, XP_U32 devID ); #endif diff --git a/xwords4/linux/gtkboard.c b/xwords4/linux/gtkboard.c index 36af6746c..c87ee3a96 100644 --- a/xwords4/linux/gtkboard.c +++ b/xwords4/linux/gtkboard.c @@ -1650,20 +1650,20 @@ send_invites( CommonGlobals* cGlobals, const CommsAddrRec* inviteAddr, gint forceChannel = 0; /* PENDING */ - NetLaunchInfo invit = {0}; - invit_init( &invit, cGlobals->gi, &addr, nPlayers, forceChannel ); - invit_setDevID( &invit, linux_getDevIDRelay( cGlobals->params ) ); + NetLaunchInfo nli = {0}; + nli_init( &nli, cGlobals->gi, &addr, nPlayers, forceChannel ); + nli_setDevID( &nli, linux_getDevIDRelay( cGlobals->params ) ); #ifdef DEBUG { XWStreamCtxt* stream = mem_stream_make( MPPARM(cGlobals->util->mpool) cGlobals->params->vtMgr, NULL, CHANNEL_NONE, NULL ); - invit_saveToStream( &invit, stream ); + nli_saveToStream( &nli, stream ); NetLaunchInfo tmp; - invit_makeFromStream( &tmp, stream ); + nli_makeFromStream( &tmp, stream ); stream_destroy( stream ); - XP_ASSERT( 0 == memcmp( &invit, &tmp, sizeof(invit) ) ); + XP_ASSERT( 0 == memcmp( &nli, &tmp, sizeof(nli) ) ); } #endif @@ -1676,7 +1676,7 @@ send_invites( CommonGlobals* cGlobals, const CommsAddrRec* inviteAddr, if ( addr_hasType( inviteAddr, COMMS_CONN_RELAY ) ) { XP_U32 devID = inviteAddr->u.ip_relay.devID; XP_ASSERT( 0 != devID || (!!relayID && !!relayID[0]) ); - relaycon_invite( cGlobals->params, devID, relayID, &invit ); + relaycon_invite( cGlobals->params, devID, relayID, &nli ); } /* while ( gtkaskm( "Invite how many and how?", infos, VSIZE(infos) ) ) { */ diff --git a/xwords4/linux/gtkmain.c b/xwords4/linux/gtkmain.c index b0df6af8b..a2e7fd27c 100644 --- a/xwords4/linux/gtkmain.c +++ b/xwords4/linux/gtkmain.c @@ -587,7 +587,7 @@ relayInviteReceived( void* closure, NetLaunchInfo* invite ) params->needsNewGame = XP_FALSE; initGlobals( globals, params, &gi ); - invit_makeAddrRec( invite, &globals->cGlobals.addr ); + nli_makeAddrRec( invite, &globals->cGlobals.addr ); // globals->cGlobals.addr = *returnAddr; GtkWidget* gameWindow = globals->window; diff --git a/xwords4/linux/relaycon.c b/xwords4/linux/relaycon.c index e10bfeca9..2096e1bc0 100644 --- a/xwords4/linux/relaycon.c +++ b/xwords4/linux/relaycon.c @@ -138,7 +138,7 @@ relaycon_invite( LaunchParams* params, XP_U32 destDevID, XWStreamCtxt* stream = mem_stream_make( MPPARM(params->mpool) params->vtMgr, params, CHANNEL_NONE, NULL ); - invit_saveToStream( invit, stream ); + nli_saveToStream( invit, stream ); XP_U16 len = stream_getSize( stream ); indx += writeShort( &tmpbuf[indx], sizeof(tmpbuf) - indx, len ); XP_ASSERT( indx + len < sizeof(tmpbuf) ); @@ -343,7 +343,7 @@ relaycon_receive( GIOChannel* source, GIOCondition XP_UNUSED_DBG(condition), gpo CHANNEL_NONE, NULL ); stream_putBytes( stream, ptr, len ); NetLaunchInfo invit; - XP_Bool success = invit_makeFromStream( &invit, stream ); + XP_Bool success = nli_makeFromStream( &invit, stream ); XP_LOGF( "sender: %d; invit.devID: %d", sender, invit.devID ); XP_ASSERT( sender == invit.devID ); stream_destroy( stream ); diff --git a/xwords4/linux/relaycon.h b/xwords4/linux/relaycon.h index 205842069..a8b0ef424 100644 --- a/xwords4/linux/relaycon.h +++ b/xwords4/linux/relaycon.h @@ -22,7 +22,7 @@ #define _RELAYCON_H_ #include "main.h" -#include "invit.h" +#include "nli.h" typedef struct _Procs { void (*msgReceived)( void* closure, const CommsAddrRec* from,