static gboolean TestDebugReceiveVersion(char *data, size_t dataLen, char **result, size_t *resultLen) { g_debug("Received tools version message: %s\n", data); RpcDebug_SetResult("", result, resultLen); return TRUE; }
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; }