fix to store mqtt id using properly-named key

And throw in temporary code so those of us testing the stuff don't have
all our existing games stop working.
This commit is contained in:
Eric House 2020-06-19 11:50:44 -07:00
parent cfd988d998
commit fe7e85c93d
2 changed files with 22 additions and 6 deletions

View file

@ -81,7 +81,9 @@ dvc_store( XW_DUtilCtxt* dutil, XWEnv xwe )
#endif
#define MQTT_DEVID_KEY "mqtt_devid_key"
#define SUPPORT_OLD /* only needed for a short while */
#define MQTT_DEVID_KEY_OLD "mqtt_devid_key"
#define MQTT_DEVID_KEY PERSIST_KEY("mqtt_devid_key")
void
dvc_getMQTTDevID( XW_DUtilCtxt* dutil, XWEnv xwe, MQTTDevID* devID )
@ -89,8 +91,20 @@ dvc_getMQTTDevID( XW_DUtilCtxt* dutil, XWEnv xwe, MQTTDevID* devID )
MQTTDevID tmp = 0;
XP_U16 len = sizeof(tmp);
dutil_loadPtr( dutil, xwe, MQTT_DEVID_KEY, &tmp, &len );
#ifdef SUPPORT_OLD
if ( len == 0 ) {
len = sizeof(tmp);
dutil_loadPtr( dutil, xwe, MQTT_DEVID_KEY_OLD, &tmp, &len );
if ( len == sizeof(tmp) ) { /* got the old key; now store it */
XP_LOGFF( "storing using new key" );
dutil_storePtr( dutil, xwe, MQTT_DEVID_KEY, &tmp, sizeof(tmp) );
}
}
#endif
// XP_LOGFF( "len: %d; sizeof(tmp): %d", len, sizeof(tmp) );
if ( len != sizeof(tmp) ) { /* we have it!!! */
if ( len != sizeof(tmp) ) { /* not found, or bogus somehow */
tmp = XP_RANDOM();
tmp <<= 32;
tmp |= XP_RANDOM();

View file

@ -330,18 +330,20 @@ linux_dutil_loadPtr( XW_DUtilCtxt* duc, XWEnv XP_UNUSED(xwe), const XP_UCHAR* ke
*lenp = buflen;
} else {
gchar* tmp = XP_MALLOC( duc->mpool, buflen );
res = db_fetch( pDb, key, tmp, &buflen );
gint tmpLen = buflen;
res = db_fetch( pDb, key, tmp, &tmpLen );
XP_ASSERT( buflen == tmpLen );
XP_ASSERT( res == SUCCESS );
XP_ASSERT( tmp[buflen-1] == '\0' );
gsize out_len;
guchar* txt = g_base64_decode( (const gchar*)tmp, &out_len );
guchar* binp = g_base64_decode( tmp, &out_len );
if ( out_len <= *lenp ) {
XP_MEMCPY( data, txt, out_len );
XP_MEMCPY( data, binp, out_len );
*lenp = out_len;
}
XP_FREEP( duc->mpool, &tmp );
g_free( txt );
g_free( binp );
}
} else {
*lenp = 0; /* doesn't exist */