/* set file attributes */ int VMShfSetAttr( const shf_t *shf, uint32_t attrmask, const uint8_t unknown, const fileattr_t *fileattr, const char *filename, uint32_t *status) { uint32_t namelen, datalen; int ret; if (vmshf_debug) { fprintf(stderr, "VMSHF_SET_INFO name:'%s'\n", filename); fprintf(stderr, "mask:0x%04x ( %s%s%s%s%s%s)\n", attrmask, (attrmask & VMSHF_ATTRMASK_FSIZE) ? "fsize " : "", (attrmask & VMSHF_ATTRMASK_CTIME) ? "ctime " : "", (attrmask & VMSHF_ATTRMASK_ATIME) ? "atime " : "", (attrmask & VMSHF_ATTRMASK_UTIME) ? "utime " : "", (attrmask & VMSHF_ATTRMASK_XTIME) ? "?time " : "", (attrmask & VMSHF_ATTRMASK_FMODE) ? "fmode " : ""); PrintFileAttr(attrmask, fileattr ? fileattr : SETA_BUF(shf)); } *status = (uint32_t)-1; memcpy(shf->buf, shf_header, sizeof(shf_header)); *(uint32_t *)&shf->buf[ 6] = VMSHF_SET_ATTR; *(uint32_t *)&shf->buf[10] = attrmask; *&shf->buf[14] = unknown; if (fileattr) { memcpy(SETA_BUF(shf), fileattr, sizeof(fileattr_t)); } namelen = LocalToUtf8((char *)&shf->buf[60], filename); *(uint32_t *)&shf->buf[56] = namelen; ReplaceDelim((char *)&shf->buf[60], namelen, '\0'); datalen = 61 + namelen; ret = ExecuteRpc(shf, &datalen); if (ret != VMTOOL_SUCCESS) { return ret; } *status = *(uint32_t *)&shf->buf[6]; if (vmshf_debug) { fprintf(stderr, "-> status:%lu\n", *status); } return VMTOOL_SUCCESS; }
void ClientJsonRpc::Disconnect(bool stopServer) { // Stop server. if (m_client && stopServer) { Json::Value rpc; PrepareRpc(rpc, "david::StopServer"); Json::Value response; ExecuteRpc(response, rpc); } // Try to inform server that we disconnect. if (m_client) { try { Json::Value rpc; PrepareRpc(rpc, "david::Disconnect"); Json::Value response; ExecuteRpc(response, rpc); } catch (david::Exception&) {} } // Delete binary channel. if (m_binary) { m_binary->Close(); delete m_binary; m_binary = NULL; } // Delete JSON client interface. if (m_client) { m_client->Close(); delete m_client; m_client = NULL; } delete m_sls; m_sls = NULL; delete m_fusion; m_fusion = NULL; delete m_measure; m_measure = NULL; delete m_turntable; m_turntable = NULL; delete m_mainWindow; m_mainWindow = NULL; }
/* get host drive free space */ int VMShfGetDirSize( const shf_t *shf, const char *dirname, uint32_t *status, uint64_t *avail, uint64_t *total) { uint32_t namelen, datalen; int ret; if (vmshf_debug) { fprintf(stderr, "VMSHF_GET_FREESPACE name:'%s' -> ", dirname); fflush(stderr); } *status = (uint32_t)-1; memcpy(shf->buf, shf_header, sizeof(shf_header)); *(uint32_t *)&shf->buf[6] = VMSHF_GET_DIRSIZE; namelen = LocalToUtf8((char *)&shf->buf[14], dirname); *(uint32_t *)&shf->buf[10] = namelen; ReplaceDelim((char *)&shf->buf[14], namelen, '\0'); datalen = 15 + namelen; ret = ExecuteRpc(shf, &datalen); if (ret != VMTOOL_SUCCESS) { return ret; } *status = *(uint32_t *)&shf->buf[6]; if (datalen >= 26) { *avail = *(uint64_t *)&shf->buf[10]; *total = *(uint64_t *)&shf->buf[18]; } else { U64INIT(*avail, 0, 0); U64INIT(*total, 0, 0); } if (vmshf_debug) { fprintf(stderr, "status: %lu, free: %" I64D_FMT "u, total: %" I64D_FMT "u\n", *status, *avail, *total); } return VMTOOL_SUCCESS; }
/* get file attributes */ int VMShfGetAttr( const shf_t *shf, const char *filename, uint32_t *status, uint32_t *dirflag, fileattr_t **fileattr) { uint32_t namelen, datalen; int ret; if (vmshf_debug) { fprintf(stderr, "VMSHF_GET_INFO name:'%s' -> ", filename); fflush(stderr); } *status = (uint32_t)-1; memcpy(shf->buf, shf_header, sizeof(shf_header)); *(uint32_t *)&shf->buf[6] = VMSHF_GET_ATTR; namelen = LocalToUtf8((char *)&shf->buf[14], filename); *(uint32_t *)&shf->buf[10] = namelen; ReplaceDelim((char *)&shf->buf[14], namelen, '\0'); datalen = 15 + namelen; ret = ExecuteRpc(shf, &datalen); if (ret != VMTOOL_SUCCESS) { return ret; } *status = *(uint32_t *)&shf->buf[6]; if (vmshf_debug) { fprintf(stderr, "status:%lu\n", *status); } if (datalen >= 55) { *dirflag = *(uint32_t *)&shf->buf[10]; *fileattr = GETA_BUF(shf); if (vmshf_debug) { fprintf(stderr, "dflag: %d\n", *dirflag); PrintFileAttr(0xff, GETA_BUF(shf)); } } return VMTOOL_SUCCESS; }
/* open directory */ int VMShfOpenDir( const shf_t *shf, const char *dirname, uint32_t *status, uint32_t *handle) { uint32_t namelen, datalen; int ret; if (vmshf_debug) { fprintf(stderr, "VMSHF_OPEN_DIR name:'%s' -> ", dirname); fflush(stderr); } *status = (uint32_t)-1; memcpy(shf->buf, shf_header, sizeof(shf_header)); *(uint32_t *)&shf->buf[6] = VMSHF_OPEN_DIR; namelen = LocalToUtf8((char *)&shf->buf[14], dirname); ReplaceDelim((char *)&shf->buf[14], namelen, '\0'); *(uint32_t *)&shf->buf[10] = namelen; datalen = 15 + namelen; ret = ExecuteRpc(shf, &datalen); if (ret != VMTOOL_SUCCESS) { if (vmshf_debug) { fprintf(stderr, "rpc failed\n"); } return ret; } *status = *(uint32_t *)&shf->buf[6]; if (datalen >= 14) { *handle = *(uint32_t *)&shf->buf[10]; } else { *handle = (uint32_t)-1; } if (vmshf_debug) { fprintf(stderr, "status:%lu, handle:%lu\n", *status, *handle); } return VMTOOL_SUCCESS; }
/* write data to a host file */ int VMShfWriteFile( const shf_t *shf, uint32_t handle, /* 10: file handle returned by OPEN */ uint8_t unknown, /* 14: purpose unknown */ uint64_t offset, /* 15: byte offset to stat writing */ uint32_t *length, /* 23: number of bytes to write */ uint32_t *status) { uint32_t datalen; int ret; if (vmshf_debug) { fprintf(stderr, "VMSHF_WRITE_FILE handle:%lu, " "unknown:0x%02x, offset:%" I64D_FMT "u, length:%lu -> ", handle, unknown, offset, *length); fflush(stderr); } *status = (uint32_t)-1; memcpy(shf->buf, shf_header, sizeof(shf_header)); *(uint32_t *)&shf->buf[ 6] = VMSHF_WRITE_FILE; /* Shared folder command */ *(uint32_t *)&shf->buf[10] = handle; /* file handle */ shf->buf[14] = unknown; /* unknown */ *(uint64_t *)&shf->buf[15] = offset; /* start offset */ *(uint32_t *)&shf->buf[23] = *length; /* write length */ datalen = 27 + *length; ret = ExecuteRpc(shf, &datalen); if (ret != VMTOOL_SUCCESS) { return ret; } *status = *(uint32_t *)&shf->buf[6]; if (datalen >= 14) { *length = *(uint32_t *)&shf->buf[10]; } else { *length = (uint32_t)-1; } if (vmshf_debug) { fprintf(stderr, "status:%lu, length:%ld\n", *status, *length); } return VMTOOL_SUCCESS; }
/* read data from a host file */ int VMShfReadFile( const shf_t *shf, uint32_t handle, /* 10=> file handle returned by OPEN */ uint64_t offset, /* 14=> byte offset to stat reading */ uint32_t *length, /* 22-> number of bytes to read */ uint32_t *status) { uint32_t datalen; int ret; if (vmshf_debug) { fprintf(stderr, "VMSHF_READ_FILE handle:%lu, " "offset:%" I64D_FMT "u, length:%lu -> ", handle, offset, *length); fflush(stderr); } *status = (uint32_t)-1; memcpy(shf->buf, shf_header, sizeof(shf_header)); *(uint32_t *)&shf->buf[ 6] = VMSHF_READ_FILE; /* shared folder command */ *(uint32_t *)&shf->buf[10] = handle; /* file handle */ *(uint64_t *)&shf->buf[14] = offset; /* start offset */ *(uint32_t *)&shf->buf[22] = *length; /* read length */ datalen = 26; ret = ExecuteRpc(shf, &datalen); if (ret != VMTOOL_SUCCESS) { return ret; } *status = *(uint32_t *)&shf->buf[6]; if (datalen >= 14) { *length = *(uint32_t *)&shf->buf[10]; } else { *length = (uint32_t)-1; } if (vmshf_debug) { fprintf(stderr, "status:%lu, length:%ld\n", *status, *length); } return VMTOOL_SUCCESS; }
/* move/rename a host file/directory */ int VMShfMoveFile( const shf_t *shf, const char *srcname, const char *dstname, uint32_t *status) { uint32_t srclen, dstlen, datalen; int ret; if (vmshf_debug) { fprintf(stderr, "VMSHF_MOVE_FILE src:'%s', dst:'%s' -> ", srcname, dstname); fflush(stderr); } *status = (uint32_t)-1; memcpy(shf->buf, shf_header, sizeof(shf_header)); *(uint32_t *)&shf->buf[6] = VMSHF_MOVE_FILE; srclen = LocalToUtf8((char *)&shf->buf[14], srcname); *(uint32_t *)&shf->buf[10] = srclen; ReplaceDelim((char *)&shf->buf[14], srclen, '\0'); datalen = 15 + srclen; dstlen = LocalToUtf8((char *)&shf->buf[datalen + 4], dstname); *(uint32_t *)&shf->buf[datalen] = dstlen; ReplaceDelim((char *)&shf->buf[datalen + 4], dstlen, '\0'); datalen = datalen + 5 + dstlen; ret = ExecuteRpc(shf, &datalen); if (ret != VMTOOL_SUCCESS) { return ret; } *status = *(uint32_t *)&shf->buf[6]; if (vmshf_debug) { fprintf(stderr, "status:%lu\n", *status); } return VMTOOL_SUCCESS; }
/* create a host directory */ int VMShfCreateDir( const shf_t *shf, uint8_t dirmode, const char *dirname, uint32_t *status) { uint32_t namelen, datalen; int ret; if (vmshf_debug) { fprintf(stderr, "VMSHF_CREATE_DIR name:'%s', mode:%c%c%c (0x%02x) -> ", dirname, (dirmode & VMSHF_FILEMODE_READ) ? 'r' : '-', (dirmode & VMSHF_FILEMODE_WRITE) ? 'w' : '-', (dirmode & VMSHF_FILEMODE_EXEC) ? 'x' : '-', dirmode); fflush(stderr); } *status = (uint32_t)-1; memcpy(shf->buf, shf_header, sizeof(shf_header)); *(uint32_t *)&shf->buf[6] = VMSHF_CREATE_DIR; shf->buf[10] = dirmode; namelen = LocalToUtf8((char *)&shf->buf[15], dirname); *(uint32_t *)&shf->buf[11] = namelen; ReplaceDelim((char *)&shf->buf[15], namelen, '\0'); datalen = 16 + namelen; ret = ExecuteRpc(shf, &datalen); if (ret != VMTOOL_SUCCESS) { return ret; } *status = *(uint32_t *)&shf->buf[6]; if (vmshf_debug) { fprintf(stderr, "status:%lu\n", *status); } return VMTOOL_SUCCESS; }
/* delete a host directory */ int VMShfDeleteDir( const shf_t *shf, const char *dirname, uint32_t *status) { uint32_t namelen, datalen; int ret; if (vmshf_debug) { fprintf(stderr, "VMSHF_DELETE_DIR name:%s -> ", dirname); fflush(stderr); } *status = (uint32_t)-1; memcpy(shf->buf, shf_header, sizeof(shf_header)); *(uint32_t *)&shf->buf[6] = VMSHF_DELETE_DIR; namelen = LocalToUtf8((char *)&shf->buf[14], dirname); *(uint32_t *)&shf->buf[10] = namelen; ReplaceDelim((char *)&shf->buf[14], namelen, '\0'); datalen = 15 + namelen; ret = ExecuteRpc(shf, &datalen); if (ret != VMTOOL_SUCCESS) { return ret; } *status = *(uint32_t *)&shf->buf[6]; if (vmshf_debug) { fprintf(stderr, "status:%lu\n", *status); } return VMTOOL_SUCCESS; }
/* end directory listing */ int VMShfCloseDir( const shf_t *shf, uint32_t handle, uint32_t *status) { uint32_t datalen; int ret; if (vmshf_debug) { fprintf(stderr, "VMSHF_CLOSE_DIR handle:%lu -> ", handle); fflush(stderr); } *status = (uint32_t)-1; memcpy(shf->buf, shf_header, sizeof(shf_header)); *(uint32_t *)&shf->buf[ 6] = VMSHF_CLOSE_DIR; *(uint32_t *)&shf->buf[10] = handle; datalen = 14; ret = ExecuteRpc(shf, &datalen); if (ret != VMTOOL_SUCCESS) { return ret; } *status = *(uint32_t *)&shf->buf[6]; if (vmshf_debug) { fprintf(stderr, "status:%lu\n", *status); } return VMTOOL_SUCCESS; }
/* get a directory entry */ int VMShfReadDir( const shf_t *shf, uint32_t handle, /* 10: file handle returned by OPEN */ uint32_t index, uint32_t *status, uint32_t *dirflag, fileattr_t **fileattr, char **filename) { uint32_t datalen; int ret; if (vmshf_debug) { fprintf(stderr, "VMSHF_READ_DIR handle:%lu, index:%lu -> ", handle, index); fflush(stderr); } *status = (uint32_t)-1; *filename = NULL; memcpy(shf->buf, shf_header, sizeof(shf_header)); *(uint32_t *)&shf->buf[ 6] = VMSHF_READ_DIR; *(uint32_t *)&shf->buf[10] = handle; *(uint32_t *)&shf->buf[14] = index; datalen = 18; ret = ExecuteRpc(shf, &datalen); if (ret != VMTOOL_SUCCESS) { if (vmshf_debug) { fprintf(stderr, "rpc failed\n"); } return ret; } *status = *(uint32_t *)&shf->buf[6]; if (vmshf_debug) { fprintf(stderr, "\n len:%lu, status:%lu, dir:%ld, len:%lu, name:'%s'\n", datalen, *(uint32_t *)&shf->buf[6], *(uint32_t *)&shf->buf[10], *(uint32_t *)&shf->buf[55], *(uint32_t *)&shf->buf[55] ? (const char *)&shf->buf[59] : "(null)"); } if (datalen >= 59) { uint32_t namelen = *(uint32_t *)&shf->buf[55]; if (namelen) { *dirflag = *(uint32_t *)&shf->buf[10]; *fileattr = (fileattr_t *)&shf->buf[14]; shf->buf[59 + namelen] = '\0'; Utf8ToLocal((char *)&shf->buf[59], (char *)&shf->buf[59]); *filename = (char *)&shf->buf[59]; } } return VMTOOL_SUCCESS; }
/* open a host file */ int VMShfOpenFile( const shf_t *shf, uint32_t access, /* 10: one of VMSHF_ACCESS_* values */ uint32_t openmode, /* 14: one of VMSHF_OPENMODE_* values */ uint8_t filemode, /* 18: VMSHF_FILEMODE_* mask values */ const char *filename, /* 23: variable length file name */ uint32_t *status, /* 10: status */ uint32_t *handle) /* 14: file handle */ { uint32_t namelen, datalen; int ret; if (vmshf_debug) { const static char *access_name[] = { "ro", "??", "rw" }; const static char *openmode_name[] = { "o_exist", "?", "o_always", "c_new", "c_always" }; fprintf(stderr, "VMSHF_OPEN_FILE name:'%s'\n" "access:%lu (%s), openmode:%lu (%s), " "filemode:%c%c%c (0x%02x) -> ", filename, access, access_name[access < 3 ? access : 1], openmode, openmode_name[openmode < 5 ? openmode : 1], (filemode & VMSHF_FILEMODE_READ) ? 'r' : '-', (filemode & VMSHF_FILEMODE_WRITE) ? 'w' : '-', (filemode & VMSHF_FILEMODE_EXEC) ? 'x' : '-', filemode); fflush(stderr); } *status = (uint32_t)-1; *handle = (uint32_t)-1; memcpy(shf->buf, shf_header, sizeof(shf_header)); *(uint32_t *)&shf->buf[ 6] = VMSHF_OPEN_FILE; *(uint32_t *)&shf->buf[10] = access; *(uint32_t *)&shf->buf[14] = openmode; shf->buf[18] = filemode; namelen = LocalToUtf8((char *)&shf->buf[23], filename); *(uint32_t *)&shf->buf[19] = namelen; ReplaceDelim((char *)&shf->buf[23], namelen, '\0'); datalen = 24 + namelen; ret = ExecuteRpc(shf, &datalen); if (ret != VMTOOL_SUCCESS) { return ret; } *status = *(uint32_t *)&shf->buf[6]; if (datalen >= 14) { *handle = *(uint32_t *)&shf->buf[10]; } if (vmshf_debug) { fprintf(stderr, "status:%lu, handle:%ld\n", *status, *handle); } return VMTOOL_SUCCESS; }