mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-22 07:28:16 +01:00
new API for general-purpose web api sends
Will later expand to include a callback for when the (async) web API returns.
This commit is contained in:
parent
1320064824
commit
ab8d3d168c
3 changed files with 40 additions and 4 deletions
|
@ -495,6 +495,26 @@ dispatchMsgs( XW_DUtilCtxt* dutil, XWEnv xwe, XP_U8 proto, XWStreamCtxt* stream,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ackMQTTMsg( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* topic,
|
||||
XP_U32 gameID, const XP_U8* buf, XP_U16 len )
|
||||
{
|
||||
cJSON* params = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject( params, "topic", topic );
|
||||
|
||||
Md5SumBuf sb;
|
||||
dutil_md5sum( dutil, xwe, buf, len, &sb );
|
||||
cJSON_AddStringToObject( params, "sum", sb.buf );
|
||||
|
||||
XP_UCHAR gid16[16];
|
||||
XP_SNPRINTF( gid16, VSIZE(gid16), "%08X", gameID );
|
||||
cJSON_AddStringToObject( params, "gid16", gid16 );
|
||||
|
||||
dutil_sendViaWeb( dutil, xwe, "ack", params );
|
||||
cJSON_Delete( params );
|
||||
}
|
||||
|
||||
void
|
||||
dvc_parseMQTTPacket( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* topic,
|
||||
const XP_U8* buf, XP_U16 len )
|
||||
|
@ -530,7 +550,8 @@ dvc_parseMQTTPacket( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* topic,
|
|||
MQTTCmd cmd = stream_getU8( stream );
|
||||
|
||||
/* Need to ack even if discarded/malformed */
|
||||
dutil_ackMQTTMsg( dutil, xwe, topic, gameID, &senderID, buf, len );
|
||||
// dutil_ackMQTTMsg( dutil, xwe, topic, gameID, &senderID, buf, len );
|
||||
ackMQTTMsg( dutil, xwe, topic, gameID, buf, len );
|
||||
|
||||
switch ( cmd ) {
|
||||
case CMD_INVITE: {
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "vtabmgr.h"
|
||||
#include "commstyp.h"
|
||||
#include "nlityp.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
typedef enum { UNPAUSED,
|
||||
PAUSED,
|
||||
|
@ -105,6 +106,8 @@ typedef struct _DUtilVtable {
|
|||
void (*m_dutil_ackMQTTMsg)( XW_DUtilCtxt* duc, XWEnv xwe, const XP_UCHAR* topic,
|
||||
XP_U32 gameID, const MQTTDevID* senderID,
|
||||
const XP_U8* msg, XP_U16 len );
|
||||
void (*m_dutil_sendViaWeb)( XW_DUtilCtxt* duc, XWEnv xwe, const XP_UCHAR* api,
|
||||
const cJSON* params );
|
||||
} DUtilVtable;
|
||||
|
||||
struct XW_DUtilCtxt {
|
||||
|
@ -182,9 +185,9 @@ void dutil_super_init( MPFORMAL XW_DUtilCtxt* dutil );
|
|||
(duc)->vtable.m_dutil_onCtrlReceived((duc),(xwe),(buf),(len))
|
||||
#define dutil_onGameGoneReceived(duc, xwe, gameID, from) \
|
||||
(duc)->vtable.m_dutil_onGameGoneReceived((duc),(xwe),(gameID),(from))
|
||||
|
||||
#define dutil_ackMQTTMsg( duc, xwe, topic, gameID, senderID, msg, len ) \
|
||||
(duc)->vtable.m_dutil_ackMQTTMsg( (duc), (xwe), (topic), (gameID), \
|
||||
(senderID), (msg), (len) )
|
||||
|
||||
#define dutil_sendViaWeb( duc, xwe, api, params ) \
|
||||
(duc)->vtable.m_dutil_sendViaWeb((duc), (xwe), (api), (params))
|
||||
#endif
|
||||
|
|
|
@ -309,7 +309,18 @@ linux_dutil_ackMQTTMsg( XW_DUtilCtxt* duc, XWEnv XP_UNUSED(xwe),
|
|||
sendViaCurl( lduc, adp );
|
||||
#endif
|
||||
/* LOG_RETURN_VOID(); */
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
linux_dutil_sendViaWeb( XW_DUtilCtxt* duc, XWEnv xwe, const XP_UCHAR* api,
|
||||
const cJSON* params )
|
||||
{
|
||||
XP_USE(duc);
|
||||
XP_USE(xwe);
|
||||
char* pstr = cJSON_PrintUnformatted( params );
|
||||
XP_LOGFF( "(api: %s, params: %s)", api, pstr );
|
||||
free( pstr );
|
||||
}
|
||||
|
||||
XW_DUtilCtxt*
|
||||
linux_dutils_init( MPFORMAL VTableMgr* vtMgr, void* closure )
|
||||
|
@ -361,6 +372,7 @@ linux_dutils_init( MPFORMAL VTableMgr* vtMgr, void* closure )
|
|||
SET_PROC(onCtrlReceived);
|
||||
SET_PROC(onGameGoneReceived);
|
||||
SET_PROC(ackMQTTMsg);
|
||||
SET_PROC(sendViaWeb);
|
||||
|
||||
# undef SET_PROC
|
||||
|
||||
|
|
Loading…
Reference in a new issue