static gboolean TestDebugValidateRpc3(RpcInData *data, gboolean ret) { TestPluginData pdata = { NULL, }; CU_ASSERT(XdrUtil_Deserialize(data->result, data->resultLen, xdr_TestPluginData, &pdata)); CU_ASSERT_STRING_EQUAL(pdata.data, "Hello World!"); CU_ASSERT_EQUAL(pdata.f_int, 8642); CU_ASSERT(pdata.f_bool); VMX_XDR_FREE(xdr_TestPluginData, &pdata); return ret; }
static gboolean RpcDebugSend(RpcChannel *chan, char const *data, size_t dataLen, char **result, size_t *resultLen) { char *copy; gpointer xdrdata = NULL; DbgChannelData *cdata = chan->_private; RpcDebugPlugin *plugin = cdata->plugin; RpcDebugRecvMapping *mapping = NULL; RpcDebugRecvFn recvFn = NULL; gboolean ret = TRUE; ASSERT(cdata->ctx != NULL); /* Be paranoid. Like the VMX, NULL-terminate the incoming data. */ copy = g_malloc(dataLen + 1); memcpy(copy, data, dataLen); copy[dataLen] = '\0'; /* Try to find a mapping the the command in the RPC. */ if (plugin->recvFns) { char *cmd; unsigned int idx = 0; cmd = StrUtil_GetNextToken(&idx, copy, " "); if (cmd != NULL) { RpcDebugRecvMapping *test; for (test = plugin->recvFns; test->name != NULL; test++) { if (strcmp(test->name, cmd) == 0) { mapping = test; break; } } } vm_free(cmd); } if (mapping != NULL) { recvFn = mapping->recvFn; if (mapping->xdrProc != NULL) { char *start; ASSERT(mapping->xdrSize > 0); /* Find out where the XDR data starts. */ start = strchr(copy, ' '); if (start == NULL) { RpcDebug_SetResult("Can't find command delimiter.", result, resultLen); ret = FALSE; goto exit; } start++; xdrdata = g_malloc0(mapping->xdrSize); if (!XdrUtil_Deserialize(start, dataLen - (start - copy), mapping->xdrProc, xdrdata)) { RpcDebug_SetResult("XDR deserialization failed.", result, resultLen); ret = FALSE; goto exit; } } } else { recvFn = plugin->dfltRecvFn; } if (recvFn != NULL) { ret = recvFn((xdrdata != NULL) ? xdrdata : copy, dataLen, result, resultLen); } else { RpcDebug_SetResult("", result, resultLen); } exit: if (xdrdata != NULL) { VMX_XDR_FREE(mapping->xdrProc, xdrdata); g_free(xdrdata); } g_free(copy); return ret; }
static Bool RpcChannelXdrWrapper(RpcInData *data, RpcChannelCallback *rpc) { Bool ret; RpcInData copy; void *xdrData = NULL; if (rpc->xdrIn != NULL) { xdrData = malloc(rpc->xdrInSize); if (xdrData == NULL) { ret = RPCIN_SETRETVALS(data, "Out of memory.", FALSE); goto exit; } memset(xdrData, 0, rpc->xdrInSize); if (!XdrUtil_Deserialize(data->args + 1, data->argsSize - 1, rpc->xdrIn, xdrData)) { ret = RPCIN_SETRETVALS(data, "XDR deserialization failed.", FALSE); free(xdrData); goto exit; } copy.name = data->name; copy.args = xdrData; copy.argsSize = rpc->xdrInSize; copy.result = data->result; copy.resultLen = data->resultLen; copy.freeResult = data->freeResult; copy.appCtx = data->appCtx; copy.clientData = rpc->clientData; } else { memcpy(©, data, sizeof copy); } ret = rpc->callback(©); if (rpc->xdrIn != NULL) { VMX_XDR_FREE(rpc->xdrIn, xdrData); free(xdrData); copy.args = NULL; data->result = copy.result; data->resultLen = copy.resultLen; data->freeResult = copy.freeResult; } if (rpc->xdrOut != NULL && copy.result != NULL) { XDR xdrs; xdrproc_t xdrProc = rpc->xdrOut; if (DynXdr_Create(&xdrs) == NULL) { ret = RPCIN_SETRETVALS(data, "Out of memory.", FALSE); goto exit; } if (!xdrProc(&xdrs, copy.result)) { ret = RPCIN_SETRETVALS(data, "XDR serialization failed.", FALSE); DynXdr_Destroy(&xdrs, TRUE); goto exit; } if (copy.freeResult) { VMX_XDR_FREE(rpc->xdrOut, copy.result); } data->result = DynXdr_Get(&xdrs); data->resultLen = XDR_GETPOS(&xdrs); data->freeResult = TRUE; DynXdr_Destroy(&xdrs, FALSE); } exit: if (copy.freeResult && copy.result != NULL) { g_free(copy.result); } return ret; }