rename gamesdb public functions (linux only)

This commit is contained in:
Eric House 2020-09-24 20:56:46 -07:00
parent f0f2a598e0
commit d17ac7ea0b
10 changed files with 116 additions and 109 deletions

View file

@ -74,7 +74,7 @@ static void
addOne( CursGameList* cgl, sqlite3_int64 rowid )
{
GameInfo gib;
if ( getGameInfo( cgl->params->pDb, rowid, &gib ) ) {
if ( gdb_getGameInfo( cgl->params->pDb, rowid, &gib ) ) {
GameInfo* gibp = g_malloc( sizeof(*gibp) );
*gibp = gib;
cgl->games = g_slist_append( cgl->games, gibp );
@ -89,7 +89,7 @@ cgl_refresh( CursGameList* cgl )
cgl->games = NULL;
sqlite3* pDb = cgl->params->pDb;
GSList* games = listGames( pDb );
GSList* games = gdb_listGames( pDb );
for ( GSList* iter = games; !!iter; iter = iter->next ) {
sqlite3_int64* rowid = (sqlite3_int64*)iter->data;
addOne( cgl, *rowid );
@ -117,7 +117,7 @@ cgl_refreshOne( CursGameList* cgl, sqlite3_int64 rowid, bool select )
// elem
GameInfo gib;
if ( getGameInfo( cgl->params->pDb, rowid, &gib ) ) {
if ( gdb_getGameInfo( cgl->params->pDb, rowid, &gib ) ) {
GameInfo* found;
GSList* elem = findFor( cgl, rowid );
if ( !!elem ) {

View file

@ -671,7 +671,7 @@ cb_feedGame( CursesBoardState* cbState, XP_U32 gameID,
sqlite3_int64 rowids[4];
int nRows = VSIZE( rowids );
LaunchParams* params = cbState->params;
getRowsForGameID( params->pDb, gameID, rowids, &nRows );
gdb_getRowsForGameID( params->pDb, gameID, rowids, &nRows );
XP_LOGF( "%s(): found %d rows for gameID %d", __func__, nRows, gameID );
for ( int ii = 0; ii < nRows; ++ii ) {
#ifdef DEBUG

View file

@ -299,7 +299,7 @@ handleDeleteGame( void* closure, int XP_UNUSED(key) )
const GameInfo* gib = cgl_getSel( aGlobals->gameList );
if ( !!gib ) {
deleteGame( aGlobals->cag.params->pDb, gib->rowid );
gdb_deleteGame( aGlobals->cag.params->pDb, gib->rowid );
cgl_remove( aGlobals->gameList, gib->rowid );
}
}
@ -1160,7 +1160,7 @@ inviteReceivedCurses( void* closure, const NetLaunchInfo* invite,
CursesAppGlobals* aGlobals = (CursesAppGlobals*)closure;
sqlite3_int64 rowids[1];
int nRowIDs = VSIZE(rowids);
getRowsForGameID( aGlobals->cag.params->pDb, invite->gameID, rowids, &nRowIDs );
gdb_getRowsForGameID( aGlobals->cag.params->pDb, invite->gameID, rowids, &nRowIDs );
bool doIt = 0 == nRowIDs;
if ( ! doIt && !!aGlobals->mainWin ) {
const gchar* question = "Duplicate invitation received. Accept anyway?";
@ -1262,8 +1262,8 @@ curses_requestMsgs( gpointer data )
{
CursesAppGlobals* aGlobals = (CursesAppGlobals*)data;
XP_UCHAR devIDBuf[64] = {0};
db_fetch_safe( aGlobals->cag.params->pDb, KEY_RDEVID, NULL, devIDBuf,
sizeof(devIDBuf) );
gdb_fetch_safe( aGlobals->cag.params->pDb, KEY_RDEVID, NULL, devIDBuf,
sizeof(devIDBuf) );
if ( '\0' != devIDBuf[0] ) {
relaycon_requestMsgs( aGlobals->cag.params, devIDBuf );
} else {
@ -1303,17 +1303,17 @@ cursesDevIDReceived( void* closure, const XP_UCHAR* devID,
/* If we already have one, make sure it's the same! Else store. */
gchar buf[64];
XP_Bool have = db_fetch_safe( pDb, KEY_RDEVID, NULL, buf, sizeof(buf) )
XP_Bool have = gdb_fetch_safe( pDb, KEY_RDEVID, NULL, buf, sizeof(buf) )
&& 0 == strcmp( buf, devID );
if ( !have ) {
db_store( pDb, KEY_RDEVID, devID );
gdb_store( pDb, KEY_RDEVID, devID );
XP_LOGFF( "storing new devid: %s", devID );
cgl_draw( aGlobals->gameList );
}
(void)g_timeout_add_seconds( maxInterval, keepalive_timer, aGlobals );
} else {
XP_LOGFF( "bad relayid" );
db_remove( pDb, KEY_RDEVID );
gdb_remove( pDb, KEY_RDEVID );
DevIDType typ;
const XP_UCHAR* devID = linux_getDevID( aGlobals->cag.params, &typ );

View file

@ -38,8 +38,8 @@
static XP_Bool getColumnText( sqlite3_stmt *ppStmt, int iCol, XP_UCHAR* buf,
int* len );
static bool db_fetchInt( sqlite3* pDb, const gchar* key, int32_t* resultP );
static void db_storeInt( sqlite3* pDb, const gchar* key, int32_t val );
static bool fetchInt( sqlite3* pDb, const gchar* key, int32_t* resultP );
static void storeInt( sqlite3* pDb, const gchar* key, int32_t val );
static void createTables( sqlite3* pDb );
static bool gamesTableExists( sqlite3* pDb );
static void upgradeTables( sqlite3* pDb, int32_t oldVersion );
@ -61,7 +61,7 @@ static void assertPrintResult( sqlite3* pDb, int result, int expect );
#define CUR_DB_VERSION 1
sqlite3*
openGamesDB( const char* dbName )
gdb_open( const char* dbName )
{
#ifdef DEBUG
int result =
@ -78,7 +78,7 @@ openGamesDB( const char* dbName )
if ( gamesTableExists( pDb ) ) {
int32_t oldVersion;
if ( !db_fetchInt( pDb, KEY_DB_VERSION, &oldVersion ) ) {
if ( !fetchInt( pDb, KEY_DB_VERSION, &oldVersion ) ) {
oldVersion = 0;
XP_LOGFF( "no version found; assuming %d", oldVersion );
}
@ -119,7 +119,7 @@ upgradeTables( sqlite3* pDb, int32_t oldVersion )
}
g_strfreev( strs );
db_storeInt( pDb, KEY_DB_VERSION, CUR_DB_VERSION );
storeInt( pDb, KEY_DB_VERSION, CUR_DB_VERSION );
}
}
@ -176,11 +176,11 @@ createTables( sqlite3* pDb )
")";
(void)sqlite3_exec( pDb, createGamesStr, NULL, NULL, NULL );
db_storeInt( pDb, KEY_DB_VERSION, CUR_DB_VERSION );
storeInt( pDb, KEY_DB_VERSION, CUR_DB_VERSION );
}
void
closeGamesDB( sqlite3* pDb )
gdb_close( sqlite3* pDb )
{
sqlite3_close( pDb );
LOG_RETURN_VOID();
@ -254,14 +254,14 @@ writeBlobColumnStream( XWStreamCtxt* stream, sqlite3* pDb, sqlite3_int64 curRow,
}
sqlite3_int64
writeNewGameToDB( XWStreamCtxt* stream, sqlite3* pDb )
gdb_writeNewGame( XWStreamCtxt* stream, sqlite3* pDb )
{
sqlite3_int64 newRow = writeBlobColumnStream( stream, pDb, -1, "game" );
return newRow;
}
void
writeToDB( XWStreamCtxt* stream, XWEnv XP_UNUSED(xwe), void* closure )
gdb_write( XWStreamCtxt* stream, XWEnv XP_UNUSED(xwe), void* closure )
{
CommonGlobals* cGlobals = (CommonGlobals*)closure;
sqlite3_int64 selRow = cGlobals->rowid;
@ -308,7 +308,7 @@ addSnapshot( CommonGlobals* cGlobals )
#endif
void
summarize( CommonGlobals* cGlobals )
gdb_summarize( CommonGlobals* cGlobals )
{
const XWGame* game = &cGlobals->game;
XP_S16 nMoves = model_getNMoves( game->model );
@ -412,6 +412,7 @@ summarize( CommonGlobals* cGlobals )
pairs[indx++] = g_strdup_printf( "nPending=%d", nPending );
pairs[indx++] = g_strdup_printf( "role=%d", gi->serverRole);
pairs[indx++] = NULL;
XP_ASSERT( indx < VSIZE(pairs) );
gchar* vals = g_strjoinv( ",", pairs );
for ( int ii = 0; !!pairs[ii]; ++ii ) {
@ -440,7 +441,7 @@ summarize( CommonGlobals* cGlobals )
}
GSList*
listGames( sqlite3* pDb )
gdb_listGames( sqlite3* pDb )
{
GSList* list = NULL;
@ -479,13 +480,13 @@ dataKiller( gpointer data )
}
void
freeGamesList( GSList* games )
gdb_freeGamesList( GSList* games )
{
g_slist_free_full( games, dataKiller );
}
GHashTable*
getRelayIDsToRowsMap( sqlite3* pDb )
gdb_getRelayIDsToRowsMap( sqlite3* pDb )
{
GHashTable* table = g_hash_table_new( g_str_hash, g_str_equal );
sqlite3_stmt *ppStmt;
@ -520,7 +521,7 @@ getRelayIDsToRowsMap( sqlite3* pDb )
}
XP_Bool
getGameInfo( sqlite3* pDb, sqlite3_int64 rowid, GameInfo* gib )
gdb_getGameInfo( sqlite3* pDb, sqlite3_int64 rowid, GameInfo* gib )
{
XP_Bool success = XP_FALSE;
const char* fmt = "SELECT room, ended, turn, local, nmoves, ntotal, nmissing, "
@ -582,8 +583,8 @@ getGameInfo( sqlite3* pDb, sqlite3_int64 rowid, GameInfo* gib )
}
void
getRowsForGameID( sqlite3* pDb, XP_U32 gameID, sqlite3_int64* rowids,
int* nRowIDs )
gdb_getRowsForGameID( sqlite3* pDb, XP_U32 gameID, sqlite3_int64* rowids,
int* nRowIDs )
{
int maxRowIDs = *nRowIDs;
*nRowIDs = 0;
@ -638,27 +639,27 @@ loadBlobColumn( XWStreamCtxt* stream, sqlite3* pDb, sqlite3_int64 rowid,
}
XP_Bool
loadGame( XWStreamCtxt* stream, sqlite3* pDb, sqlite3_int64 rowid )
gdb_loadGame( XWStreamCtxt* stream, sqlite3* pDb, sqlite3_int64 rowid )
{
return loadBlobColumn( stream, pDb, rowid, "game" );
}
/* Used for rematch only. But do I need it? */
void
saveInviteAddrs( XWStreamCtxt* stream, sqlite3* pDb, sqlite3_int64 rowid )
gdb_saveInviteAddrs( XWStreamCtxt* stream, sqlite3* pDb, sqlite3_int64 rowid )
{
sqlite3_int64 row = writeBlobColumnStream( stream, pDb, rowid, "inviteInfo" );
assert( row == rowid );
}
XP_Bool
loadInviteAddrs( XWStreamCtxt* stream, sqlite3* pDb, sqlite3_int64 rowid )
gdb_loadInviteAddrs( XWStreamCtxt* stream, sqlite3* pDb, sqlite3_int64 rowid )
{
return loadBlobColumn( stream, pDb, rowid, "inviteInfo" );
}
void
deleteGame( sqlite3* pDb, sqlite3_int64 rowid )
gdb_deleteGame( sqlite3* pDb, sqlite3_int64 rowid )
{
XP_ASSERT( !!pDb );
char query[256];
@ -667,7 +668,7 @@ deleteGame( sqlite3* pDb, sqlite3_int64 rowid )
}
void
db_store( sqlite3* pDb, const gchar* key, const gchar* value )
gdb_store( sqlite3* pDb, const gchar* key, const gchar* value )
{
XP_ASSERT( !!pDb );
gchar* query =
@ -678,11 +679,11 @@ db_store( sqlite3* pDb, const gchar* key, const gchar* value )
}
static bool
db_fetchInt( sqlite3* pDb, const gchar* key, int32_t* resultP )
fetchInt( sqlite3* pDb, const gchar* key, int32_t* resultP )
{
gint buflen = 16;
gchar buf[buflen];
FetchResult fr = db_fetch( pDb, key, NULL, buf, &buflen );
FetchResult fr = gdb_fetch( pDb, key, NULL, buf, &buflen );
bool gotIt = SUCCESS == fr;
if ( gotIt ) {
buf[buflen] = '\0';
@ -692,15 +693,15 @@ db_fetchInt( sqlite3* pDb, const gchar* key, int32_t* resultP )
}
static void
db_storeInt( sqlite3* pDb, const gchar* key, int32_t val )
storeInt( sqlite3* pDb, const gchar* key, int32_t val )
{
gchar buf[32];
snprintf( buf, VSIZE(buf), "%x", val );
db_store( pDb, key, buf );
gdb_store( pDb, key, buf );
#ifdef DEBUG
int32_t tmp;
bool worked = db_fetchInt( pDb, key, &tmp );
bool worked = fetchInt( pDb, key, &tmp );
XP_ASSERT( worked && tmp == val );
#endif
}
@ -732,8 +733,8 @@ fetchQuery( sqlite3* pDb, const char* query, gchar* buf, gint* buflen )
}
FetchResult
db_fetch( sqlite3* pDb, const gchar* key, const XP_UCHAR* keySuffix,
gchar* buf, gint* buflen )
gdb_fetch( sqlite3* pDb, const gchar* key, const XP_UCHAR* keySuffix,
gchar* buf, gint* buflen )
{
XP_ASSERT( !!pDb );
FetchResult fetchRes = NOT_THERE;
@ -757,7 +758,7 @@ db_fetch( sqlite3* pDb, const gchar* key, const XP_UCHAR* keySuffix,
/* Let's rewrite it using the correct key so this code can eventually
go away */
if ( SUCCESS == fetchRes ) {
db_store( pDb, key, buf );
gdb_store( pDb, key, buf );
}
}
@ -765,18 +766,18 @@ db_fetch( sqlite3* pDb, const gchar* key, const XP_UCHAR* keySuffix,
}
XP_Bool
db_fetch_safe( sqlite3* pDb, const gchar* key, const gchar* keySuffix,
gchar* buf, gint buflen )
gdb_fetch_safe( sqlite3* pDb, const gchar* key, const gchar* keySuffix,
gchar* buf, gint buflen )
{
XP_ASSERT( !!pDb );
int tmp = buflen;
FetchResult result = db_fetch( pDb, key, keySuffix, buf, &tmp );
FetchResult result = gdb_fetch( pDb, key, keySuffix, buf, &tmp );
XP_ASSERT( result != BUFFER_TOO_SMALL );
return SUCCESS == result;
}
void
db_remove( sqlite3* pDb, const gchar* key )
gdb_remove( sqlite3* pDb, const gchar* key )
{
XP_ASSERT( !!pDb );
char query[256];

View file

@ -52,31 +52,31 @@ typedef struct _GameInfo {
XP_U16 role;
} GameInfo;
sqlite3* openGamesDB( const char* dbName );
void closeGamesDB( sqlite3* pDb );
sqlite3* gdb_open( const char* dbName );
void gdb_close( sqlite3* pDb );
void writeToDB( XWStreamCtxt* stream, XWEnv xwe, void* closure );
sqlite3_int64 writeNewGameToDB( XWStreamCtxt* stream, sqlite3* pDb );
void gdb_write( XWStreamCtxt* stream, XWEnv xwe, void* closure );
sqlite3_int64 gdb_writeNewGame( XWStreamCtxt* stream, sqlite3* pDb );
void summarize( CommonGlobals* cGlobals );
void gdb_summarize( CommonGlobals* cGlobals );
/* Return GSList whose data is (ptrs to) rowids */
GSList* listGames( sqlite3* pDb );
GSList* gdb_listGames( sqlite3* pDb );
/* free list and data allocated by above */
void freeGamesList( GSList* games );
void gdb_freeGamesList( GSList* games );
/* Mapping of relayID -> rowid */
GHashTable* getRelayIDsToRowsMap( sqlite3* pDb );
GHashTable* gdb_getRelayIDsToRowsMap( sqlite3* pDb );
XP_Bool getGameInfo( sqlite3* pDb, sqlite3_int64 rowid, GameInfo* gib );
void getRowsForGameID( sqlite3* pDb, XP_U32 gameID, sqlite3_int64* rowids,
int* nRowIDs );
XP_Bool loadGame( XWStreamCtxt* stream, sqlite3* pDb, sqlite3_int64 rowid );
void saveInviteAddrs( XWStreamCtxt* stream, sqlite3* pDb,
sqlite3_int64 rowid );
XP_Bool loadInviteAddrs( XWStreamCtxt* stream, sqlite3* pDb,
XP_Bool gdb_getGameInfo( sqlite3* pDb, sqlite3_int64 rowid, GameInfo* gib );
void gdb_getRowsForGameID( sqlite3* pDb, XP_U32 gameID, sqlite3_int64* rowids,
int* nRowIDs );
XP_Bool gdb_loadGame( XWStreamCtxt* stream, sqlite3* pDb, sqlite3_int64 rowid );
void gdb_saveInviteAddrs( XWStreamCtxt* stream, sqlite3* pDb,
sqlite3_int64 rowid );
XP_Bool gdb_loadInviteAddrs( XWStreamCtxt* stream, sqlite3* pDb,
sqlite3_int64 rowid );
void deleteGame( sqlite3* pDb, sqlite3_int64 rowid );
void gdb_deleteGame( sqlite3* pDb, sqlite3_int64 rowid );
#define KEY_RDEVID "RDEVID"
#define KEY_LDEVID "LDEVID"
@ -84,13 +84,13 @@ void deleteGame( sqlite3* pDb, sqlite3_int64 rowid );
#define KEY_SMSPORT "SMSPORT"
#define KEY_WIN_LOC "WIN_LOC"
void db_store( sqlite3* pDb, const gchar* key, const gchar* value );
void db_remove( sqlite3* pDb, const gchar* key );
void gdb_store( sqlite3* pDb, const gchar* key, const gchar* value );
void gdb_remove( sqlite3* pDb, const gchar* key );
typedef enum { NOT_THERE, BUFFER_TOO_SMALL, SUCCESS } FetchResult;
FetchResult db_fetch( sqlite3* pDb, const gchar* key, const gchar* keySuffix,
gchar* buf, gint* buflen );
XP_Bool db_fetch_safe( sqlite3* pDb, const gchar* key, const gchar* keySuffix,
gchar* buf, gint buflen );
FetchResult gdb_fetch( sqlite3* pDb, const gchar* key, const gchar* keySuffix,
gchar* buf, gint* buflen );
XP_Bool gdb_fetch_safe( sqlite3* pDb, const gchar* key, const gchar* keySuffix,
gchar* buf, gint buflen );
#endif

View file

@ -663,7 +663,8 @@ on_board_window_shown( GtkWidget* XP_UNUSED(widget), GtkGameGlobals* globals )
/* If it has pending invite info, send the invitation! */
XWStreamCtxt* stream = mem_stream_make_raw( MPPARM(cGlobals->util->mpool)
cGlobals->params->vtMgr );
if ( loadInviteAddrs( stream, cGlobals->params->pDb, cGlobals->rowid ) ) {
if ( gdb_loadInviteAddrs( stream, cGlobals->params->pDb,
cGlobals->rowid ) ) {
CommsAddrRec addr = {0};
addrFromStream( &addr, stream );
comms_augmentHostAddr( cGlobals->game.comms, NULL_XWE, &addr );
@ -2631,7 +2632,7 @@ loadGameNoDraw( GtkGameGlobals* globals, LaunchParams* params,
cGlobals->rowid = rowid;
XWStreamCtxt* stream = mem_stream_make_raw( MPPARM(cGlobals->util->mpool)
params->vtMgr );
XP_Bool loaded = loadGame( stream, pDb, rowid );
XP_Bool loaded = gdb_loadGame( stream, pDb, rowid );
if ( loaded ) {
if ( NULL == cGlobals->dict ) {
cGlobals->dict = makeDictForStream( cGlobals, stream );

View file

@ -246,8 +246,10 @@ add_to_list( GtkWidget* list, sqlite3_int64 rowid, XP_Bool isNew,
gchar timeStr[64];
formatSeconds( gib->lastMoveTime, timeStr, VSIZE(timeStr) );
gchar timerStr[64];
formatSeconds( gib->dupTimerExpires, timerStr, VSIZE(timeStr) );
gchar timerStr[64] = {0};
if ( gib->dupTimerExpires ) {
formatSeconds( gib->dupTimerExpires, timerStr, VSIZE(timeStr) );
}
gtk_list_store_set( store, &iter,
ROW_ITEM, rowid,
@ -348,7 +350,7 @@ make_rematch( GtkAppGlobals* apg, const CommonGlobals* cGlobals )
game_saveNewGame( MPPARM(cGlobals->util->mpool) NULL_XWE, &gi,
cGlobals->util, &cGlobals->cp, stream );
sqlite3_int64 rowID = writeNewGameToDB( stream, params->pDb );
sqlite3_int64 rowID = gdb_writeNewGame( stream, params->pDb );
stream_destroy( stream, NULL_XWE );
gi_disposePlayerInfo( MPPARM(cGlobals->util->mpool) &gi );
@ -378,7 +380,7 @@ make_rematch( GtkAppGlobals* apg, const CommonGlobals* cGlobals )
}
addrToStream( stream, &addrs[ii] );
}
saveInviteAddrs( stream, params->pDb, rowID );
gdb_saveInviteAddrs( stream, params->pDb, rowID );
stream_destroy( stream, NULL_XWE );
}
@ -413,14 +415,14 @@ handle_delete_button( GtkWidget* XP_UNUSED(widget), void* closure )
#ifdef DEBUG
XP_Bool success =
#endif
getGameInfo( params->pDb, rowid, &gib );
gdb_getGameInfo( params->pDb, rowid, &gib );
XP_ASSERT( success );
XP_U32 clientToken = makeClientToken( rowid, gib.seed );
removeRow( apg, rowid );
deleteGame( params->pDb, rowid );
gdb_deleteGame( params->pDb, rowid );
XP_UCHAR devIDBuf[64] = {0};
db_fetch_safe( params->pDb, KEY_RDEVID, NULL, devIDBuf, sizeof(devIDBuf) );
gdb_fetch_safe( params->pDb, KEY_RDEVID, NULL, devIDBuf, sizeof(devIDBuf) );
if ( '\0' != devIDBuf[0] ) {
relaycon_deleted( params, devIDBuf, clientToken );
} else {
@ -450,7 +452,7 @@ handle_destroy( GtkWidget* XP_UNUSED(widget), gpointer data )
sprintf( buf, "%d:%d:%d:%d", apg->lastConfigure.x,
apg->lastConfigure.y, apg->lastConfigure.width,
apg->lastConfigure.height );
db_store( apg->cag.params->pDb, KEY_WIN_LOC, buf );
gdb_store( apg->cag.params->pDb, KEY_WIN_LOC, buf );
gtk_main_quit();
}
@ -522,7 +524,7 @@ trySetWinConfig( GtkAppGlobals* apg )
int height = 400;
gchar buf[64];
if ( db_fetch_safe( apg->cag.params->pDb, KEY_WIN_LOC, NULL, buf, sizeof(buf)) ) {
if ( gdb_fetch_safe( apg->cag.params->pDb, KEY_WIN_LOC, NULL, buf, sizeof(buf)) ) {
sscanf( buf, "%d:%d:%d:%d", &xx, &yy, &width, &height );
}
@ -601,12 +603,12 @@ makeGamesWindow( GtkAppGlobals* apg )
gtk_widget_show( list );
if ( !!params->pDb ) {
GSList* games = listGames( params->pDb );
GSList* games = gdb_listGames( params->pDb );
for ( GSList* iter = games; !!iter; iter = iter->next ) {
sqlite3_int64* rowid = (sqlite3_int64*)iter->data;
onNewData( apg, *rowid, XP_TRUE );
}
freeGamesList( games );
gdb_freeGamesList( games );
}
GtkWidget* hbox = gtk_box_new( GTK_ORIENTATION_HORIZONTAL, 0 );
@ -661,7 +663,7 @@ static void
onNewData( GtkAppGlobals* apg, sqlite3_int64 rowid, XP_Bool isNew )
{
GameInfo gib;
if ( getGameInfo( apg->cag.params->pDb, rowid, &gib ) ) {
if ( gdb_getGameInfo( apg->cag.params->pDb, rowid, &gib ) ) {
add_to_list( apg->listWidget, rowid, isNew, &gib );
g_object_unref( gib.snap );
}
@ -734,7 +736,7 @@ relayInviteReceivedGTK( void* closure, const NetLaunchInfo* invite )
XP_U32 gameID = invite->gameID;
sqlite3_int64 rowids[1];
int nRowIDs = VSIZE(rowids);
getRowsForGameID( apg->cag.params->pDb, gameID, rowids, &nRowIDs );
gdb_getRowsForGameID( apg->cag.params->pDb, gameID, rowids, &nRowIDs );
bool doIt = 0 == nRowIDs;
if ( ! doIt ) {
@ -784,7 +786,7 @@ requestMsgs( gpointer data )
{
GtkAppGlobals* apg = (GtkAppGlobals*)data;
XP_UCHAR devIDBuf[64] = {0};
db_fetch_safe( apg->cag.params->pDb, KEY_RDEVID, NULL, devIDBuf, sizeof(devIDBuf) );
gdb_fetch_safe( apg->cag.params->pDb, KEY_RDEVID, NULL, devIDBuf, sizeof(devIDBuf) );
if ( '\0' != devIDBuf[0] ) {
relaycon_requestMsgs( apg->cag.params, devIDBuf );
} else {
@ -824,7 +826,7 @@ msgReceivedGTK( void* closure, const CommsAddrRec* from, XP_U32 gameID,
sqlite3_int64 rowids[4];
int nRowIDs = VSIZE(rowids);
getRowsForGameID( params->pDb, gameID, rowids, &nRowIDs );
gdb_getRowsForGameID( params->pDb, gameID, rowids, &nRowIDs );
XP_LOGF( "%s: found %d rows for gameID %d", __func__, nRowIDs, gameID );
if ( 0 == nRowIDs ) {
mqttc_notifyGameGone( params, &from->u.mqtt.devID, gameID );
@ -859,13 +861,13 @@ gtkDevIDReceived( void* closure, const XP_UCHAR* devID, XP_U16 maxInterval )
LaunchParams* params = apg->cag.params;
if ( !!devID ) {
XP_LOGF( "%s(devID=%s)", __func__, devID );
db_store( params->pDb, KEY_RDEVID, devID );
gdb_store( params->pDb, KEY_RDEVID, devID );
(void)g_timeout_add_seconds( maxInterval, keepalive_timer, apg );
setWindowTitle( apg );
} else {
XP_LOGF( "%s: bad relayid", __func__ );
db_remove( params->pDb, KEY_RDEVID );
gdb_remove( params->pDb, KEY_RDEVID );
DevIDType typ;
const XP_UCHAR* devID = linux_getDevID( params, &typ );

View file

@ -314,7 +314,7 @@ linux_dutil_storePtr( XW_DUtilCtxt* duc, XWEnv XP_UNUSED(xwe), const XP_UCHAR* k
sqlite3* pDb = params->pDb;
gchar* b64 = g_base64_encode( data, len);
db_store( pDb, key, b64 );
gdb_store( pDb, key, b64 );
g_free( b64 );
}
@ -326,14 +326,14 @@ linux_dutil_loadPtr( XW_DUtilCtxt* duc, XWEnv XP_UNUSED(xwe), const XP_UCHAR* ke
sqlite3* pDb = params->pDb;
gint buflen = 0;
FetchResult res = db_fetch( pDb, key, keySuffix, NULL, &buflen );
FetchResult res = gdb_fetch( pDb, key, keySuffix, NULL, &buflen );
if ( res == BUFFER_TOO_SMALL ) { /* expected: I passed 0 */
if ( 0 == *lenp ) {
*lenp = buflen;
} else {
gchar* tmp = XP_MALLOC( duc->mpool, buflen );
gint tmpLen = buflen;
res = db_fetch( pDb, key, keySuffix, tmp, &tmpLen );
res = gdb_fetch( pDb, key, keySuffix, tmp, &tmpLen );
XP_ASSERT( buflen == tmpLen );
XP_ASSERT( res == SUCCESS );
XP_ASSERT( tmp[buflen-1] == '\0' );
@ -390,7 +390,7 @@ linux_dutil_deviceRegistered( XW_DUtilCtxt* duc, XWEnv XP_UNUSED(xwe), DevIDType
case ID_TYPE_RELAY:
if ( !!params->pDb && 0 < strlen( idRelay ) ) {
XP_LOGF( "%s: new id: %s", __func__, idRelay );
db_store( params->pDb, KEY_RDEVID, idRelay );
gdb_store( params->pDb, KEY_RDEVID, idRelay );
}
break;
default:

View file

@ -193,7 +193,7 @@ linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs,
} else if ( !!params->pDb && 0 <= cGlobals->rowid ) {
stream = mem_stream_make_raw( MPPARM(cGlobals->util->mpool)
params->vtMgr );
if ( !loadGame( stream, params->pDb, cGlobals->rowid ) ) {
if ( !gdb_loadGame( stream, params->pDb, cGlobals->rowid ) ) {
stream_destroy( stream, NULL_XWE);
stream = NULL;
}
@ -461,7 +461,8 @@ requestMsgsIdle( gpointer data )
{
CommonGlobals* cGlobals = (CommonGlobals*)data;
XP_UCHAR devIDBuf[64] = {0};
db_fetch_safe( cGlobals->params->pDb, KEY_RDEVID, NULL, devIDBuf, sizeof(devIDBuf) );
gdb_fetch_safe( cGlobals->params->pDb, KEY_RDEVID, NULL, devIDBuf,
sizeof(devIDBuf) );
if ( '\0' != devIDBuf[0] ) {
relaycon_requestMsgs( cGlobals->params, devIDBuf );
} else {
@ -592,11 +593,11 @@ linuxSaveGame( CommonGlobals* cGlobals )
if ( doSave ) {
if ( !!pDb ) {
summarize( cGlobals );
gdb_summarize( cGlobals );
}
XWStreamCtxt* outStream;
MemStreamCloseCallback onClose = !!pDb? writeToDB : writeToFile;
MemStreamCloseCallback onClose = !!pDb? gdb_write : writeToFile;
outStream =
mem_stream_make_sized( MPPARM(cGlobals->util->mpool)
cGlobals->params->vtMgr,
@ -1195,7 +1196,7 @@ linux_getDevIDRelay( LaunchParams* params )
{
XP_U32 result = 0;
gchar buf[32];
if ( db_fetch_safe( params->pDb, KEY_RDEVID, NULL, buf, sizeof(buf) ) ) {
if ( gdb_fetch_safe( params->pDb, KEY_RDEVID, NULL, buf, sizeof(buf) ) ) {
sscanf( buf, "%X", &result );
/* XP_LOGF( "%s(): %s => %x", __func__, buf, result ); */
}
@ -1219,12 +1220,12 @@ linux_getDevID( LaunchParams* params, DevIDType* typ )
if ( !!params->lDevID ) {
result = params->lDevID;
*typ = ID_TYPE_LINUX;
} else if ( db_fetch_safe( params->pDb, KEY_RDEVID, NULL, params->devIDStore,
sizeof(params->devIDStore) ) ) {
} else if ( gdb_fetch_safe( params->pDb, KEY_RDEVID, NULL, params->devIDStore,
sizeof(params->devIDStore) ) ) {
result = params->devIDStore;
*typ = '\0' == result[0] ? ID_TYPE_ANON : ID_TYPE_RELAY;
} else if ( db_fetch_safe( params->pDb, KEY_LDEVID, NULL, params->devIDStore,
sizeof(params->devIDStore) ) ) {
} else if ( gdb_fetch_safe( params->pDb, KEY_LDEVID, NULL, params->devIDStore,
sizeof(params->devIDStore) ) ) {
result = params->devIDStore;
*typ = '\0' == result[0] ? ID_TYPE_ANON : ID_TYPE_LINUX;
} else if ( !params->noAnonDevid ) {
@ -1238,8 +1239,8 @@ void
linux_doInitialReg( LaunchParams* params, XP_Bool idIsNew )
{
gchar rDevIDBuf[64];
if ( !db_fetch_safe( params->pDb, KEY_RDEVID, NULL, rDevIDBuf,
sizeof(rDevIDBuf) ) ) {
if ( !gdb_fetch_safe( params->pDb, KEY_RDEVID, NULL, rDevIDBuf,
sizeof(rDevIDBuf) ) ) {
rDevIDBuf[0] = '\0';
}
DevIDType typ = ID_TYPE_NONE;
@ -1255,7 +1256,7 @@ linux_setupDevidParams( LaunchParams* params )
{
XP_Bool idIsNew = XP_TRUE;
gchar oldLDevID[256];
if ( db_fetch_safe( params->pDb, KEY_LDEVID, NULL, oldLDevID, sizeof(oldLDevID) )
if ( gdb_fetch_safe( params->pDb, KEY_LDEVID, NULL, oldLDevID, sizeof(oldLDevID) )
&& (!params->lDevID || 0 == strcmp( oldLDevID, params->lDevID )) ) {
idIsNew = XP_FALSE;
} else {
@ -1263,7 +1264,7 @@ linux_setupDevidParams( LaunchParams* params )
if ( NULL == lDevID ) {
lDevID = ""; /* we'll call this ANONYMOUS */
}
db_store( params->pDb, KEY_LDEVID, lDevID );
gdb_store( params->pDb, KEY_LDEVID, lDevID );
}
return idIsNew;
}
@ -1274,9 +1275,10 @@ parseSMSParams( LaunchParams* params, gchar** myPhone, XP_U16* myPort )
gchar buf[32];
const XP_UCHAR* phone = params->connInfo.sms.myPhone;
if ( !!phone ) {
db_store( params->pDb, KEY_SMSPHONE, phone );
gdb_store( params->pDb, KEY_SMSPHONE, phone );
*myPhone = g_strdup( phone );
} else if ( !phone && db_fetch_safe( params->pDb, KEY_SMSPHONE, NULL, buf, VSIZE(buf) ) ) {
} else if ( !phone && gdb_fetch_safe( params->pDb, KEY_SMSPHONE, NULL,
buf, VSIZE(buf) ) ) {
params->connInfo.sms.myPhone = *myPhone = g_strdup(buf);
} else {
*myPhone = NULL;
@ -1286,8 +1288,9 @@ parseSMSParams( LaunchParams* params, gchar** myPhone, XP_U16* myPort )
gchar portbuf[8];
if ( 0 < *myPort ) {
sprintf( portbuf, "%d", *myPort );
db_store( params->pDb, KEY_SMSPORT, portbuf );
} else if ( db_fetch_safe( params->pDb, KEY_SMSPORT, NULL, portbuf, VSIZE(portbuf) ) ) {
gdb_store( params->pDb, KEY_SMSPORT, portbuf );
} else if ( gdb_fetch_safe( params->pDb, KEY_SMSPORT, NULL, portbuf,
VSIZE(portbuf) ) ) {
params->connInfo.sms.port = *myPort = atoi( portbuf );
}
return NULL != *myPhone && 0 < *myPort;
@ -2590,7 +2593,7 @@ initParams( LaunchParams* params )
static void
freeParams( LaunchParams* params )
{
closeGamesDB( params->pDb );
gdb_close( params->pDb );
params->pDb = NULL;
vtmgr_destroy( MPPARM(params->mpool) params->vtMgr );
@ -3392,7 +3395,7 @@ main( int argc, char** argv )
}
XP_ASSERT( !!mainParams.dbName );
mainParams.pDb = openGamesDB( mainParams.dbName );
mainParams.pDb = gdb_open( mainParams.dbName );
if ( mainParams.useCurses ) {
/* if ( mainParams.needsNewGame ) { */

View file

@ -995,7 +995,7 @@ checkForMovesOnce( RelayConStorage* storage )
RelayTask* task = makeRelayTask( storage, QUERY );
sqlite3* dbp = storage->params->pDb;
task->u.query.map = getRelayIDsToRowsMap( dbp );
task->u.query.map = gdb_getRelayIDsToRowsMap( dbp );
addTask( storage, task );
}