static int teel_reader(void* ud) { TelnetState* ts = (TelnetState*) ud; int val = -1; ReadBuffer* input = &ts->in; do { ReadMark(input); CHECK_BREAK(val = ReadByte(input)); if (val == IAC) { CHECK_BREAK(val = ReadByte(input)); if (val >= WILL && val <= DONT) { int opt; CHECK_BREAK(opt = ReadByte(input)); parseoption(ts, val, opt); } else if (val == SB) { int sopt; CHECK_BREAK(sopt = ReadByte(input)); parsesuboption(ts, sopt, input); } else if (val == IP) { val = 3; break; } else if (val == SUSP) { val = 26; break; } else if (val == EOF_) { val = 4; break; } else if (val == IAC) // escape code { val = 255; break; } else printf("Telnet interpreter: unknown character code: 255, %d. Skipping it...\n", val); } else // standard char... break; } while (1); ReadMark(input); return val; }
QModelIndex GTUtilsSharedDatabaseDocument::getItemIndex(HI::GUITestOpStatus &os, Document *databaseDoc, const QString &itemPath, bool mustExist) { Q_UNUSED(os); GT_CHECK_RESULT(NULL != databaseDoc, "databaseDoc is NULL", QModelIndex()); GT_CHECK_RESULT(!itemPath.isEmpty(), "Folder path is empty", QModelIndex()); const QStringList folders = itemPath.split(U2ObjectDbi::PATH_SEP, QString::SkipEmptyParts); QModelIndex itemIndex = GTUtilsProjectTreeView::findIndex(os, databaseDoc->getName()); CHECK(!folders.isEmpty(), itemIndex); GTGlobals::FindOptions options; options.depth = 1; options.failIfNotFound = mustExist; foreach (const QString& folder, folders) { itemIndex = GTUtilsProjectTreeView::findIndex(os, folder, itemIndex, options); CHECK_OP_BREAK(os); CHECK_BREAK(itemIndex.isValid()); }
static InterpretCommand processlinemode(TelnetState* ts) { InterpretCommand cmd = IC_EOS; ReadBuffer* input = &ts->in; WriteBuffer* line = &ts->linemodebuffer; int val; while (1) { ReadMark(input); CHECK_BREAK(val = ReadByte(input)); if (val == IAC) { CHECK_BREAK(val = ReadByte(input)); if (val >= WILL && val <= DONT) { int opt; CHECK_BREAK(opt = ReadByte(input)); parseoption(ts, val, opt); } else if (val == SB) { int sopt; CHECK_BREAK(sopt = ReadByte(input)); parsesuboption(ts, sopt, input); } else if (val == IP) { WriteBytes(&ts->out, "\r\n", 2); FreeBuffer(line); cmd = IC_IP; break; } else if (val == SUSP) { WriteBytes(&ts->out, "\r\n", 2); FreeBuffer(line); cmd = IC_SUSP; break; } else if (val == EOF_) { if (!line->len) // only close if there the current line is empty ! { cmd = IC_CLOSE; break; } } else if (val == 255) { WriteByte(line, 255); } else { printf("Telnet interpreter: unknown character code: 255, %d. Skipping it...\n", val); } } else if (val == 10) // New line { WriteBytes(line, "\r\n", 2); // store and echo the newline cmd = IC_LINE; break; } else if (val == 13) // CR, NULL and CR/NL is interpreted as a new line { CHECK_BREAK(val = ReadByte(input)); if (val == 0 || val == 10) { WriteBytes(line, "\r\n", 2); // store and echo the newline cmd = IC_LINE; break; } else // false detection, just store and echo as is. { WriteByte(line, 10); WriteByte(line, val); } } else if (val == 4) // EOF the user requested to close the terminal { if (!line->len) // only close if there the current line is empty ! { cmd = IC_CLOSE; break; } } else if (val == 3) // IP (equivalent to IAC IP) { WriteBytes(&ts->out, "\r\n", 2); FreeBuffer(line); cmd = IC_IP; break; } else if (val == 19) // IP (equivalent to IAC SUSP) { WriteBytes(&ts->out, "\r\n", 2); FreeBuffer(line); cmd = IC_SUSP; break; } else // other char are just stored { WriteByte(line, val); } } return cmd; }
static int tstVDOpenCreateWriteMerge(PVDSNAPTEST pTest) { int rc; PVBOXHDD pVD = NULL; VDGEOMETRY PCHS = { 0, 0, 0 }; VDGEOMETRY LCHS = { 0, 0, 0 }; PVDINTERFACE pVDIfs = NULL; VDINTERFACEERROR VDIfError; /** Buffer storing the random test pattern. */ uint8_t *pbTestPattern = NULL; /** Number of disk segments */ uint32_t cDiskSegments; /** Array of disk segments */ PVDDISKSEG paDiskSeg = NULL; unsigned cDiffs = 0; unsigned idDiff = 0; /* Diff ID counter for the filename */ /* Delete all images from a previous run. */ RTFileDelete(pTest->pcszBaseImage); for (unsigned i = 0; i < pTest->cIterations; i++) { char *pszDiffFilename = NULL; rc = RTStrAPrintf(&pszDiffFilename, "tstVDSnapDiff%u.%s", i, pTest->pcszDiffSuff); if (RT_SUCCESS(rc)) { if (RTFileExists(pszDiffFilename)) RTFileDelete(pszDiffFilename); RTStrFree(pszDiffFilename); } } /* Create the virtual disk test data */ pbTestPattern = (uint8_t *)RTMemAlloc(pTest->cbTestPattern); RTRandAdvBytes(g_hRand, pbTestPattern, pTest->cbTestPattern); cDiskSegments = RTRandAdvU32Ex(g_hRand, pTest->cDiskSegsMin, pTest->cDiskSegsMax); uint64_t cbDisk = 0; paDiskSeg = (PVDDISKSEG)RTMemAllocZ(cDiskSegments * sizeof(VDDISKSEG)); if (!paDiskSeg) { RTPrintf("Failed to allocate memory for random disk segments\n"); g_cErrors++; return VERR_NO_MEMORY; } for (unsigned i = 0; i < cDiskSegments; i++) { paDiskSeg[i].off = cbDisk; paDiskSeg[i].cbSeg = RT_ALIGN_64(RTRandAdvU64Ex(g_hRand, 512, pTest->cbTestPattern), 512); if (tstVDSnapIsTrue(pTest->uAllocatedBlocks)) paDiskSeg[i].pbData = pbTestPattern + RT_ALIGN_64(RTRandAdvU64Ex(g_hRand, 0, pTest->cbTestPattern - paDiskSeg[i].cbSeg - 512), 512); else paDiskSeg[i].pbData = NULL; /* Not allocated initially */ cbDisk += paDiskSeg[i].cbSeg; } RTPrintf("Disk size is %llu bytes\n", cbDisk); #define CHECK(str) \ do \ { \ RTPrintf("%s rc=%Rrc\n", str, rc); \ if (RT_FAILURE(rc)) \ { \ if (pbTestPattern) \ RTMemFree(pbTestPattern); \ if (paDiskSeg) \ RTMemFree(paDiskSeg); \ VDDestroy(pVD); \ g_cErrors++; \ return rc; \ } \ } while (0) #define CHECK_BREAK(str) \ do \ { \ RTPrintf("%s rc=%Rrc\n", str, rc); \ if (RT_FAILURE(rc)) \ { \ g_cErrors++; \ break; \ } \ } while (0) /* Create error interface. */ /* Create error interface. */ VDIfError.pfnError = tstVDError; VDIfError.pfnMessage = tstVDMessage; rc = VDInterfaceAdd(&VDIfError.Core, "tstVD_Error", VDINTERFACETYPE_ERROR, NULL, sizeof(VDINTERFACEERROR), &pVDIfs); AssertRC(rc); rc = VDCreate(pVDIfs, VDTYPE_HDD, &pVD); CHECK("VDCreate()"); rc = VDCreateBase(pVD, pTest->pcszBackend, pTest->pcszBaseImage, cbDisk, VD_IMAGE_FLAGS_NONE, "Test image", &PCHS, &LCHS, NULL, VD_OPEN_FLAGS_NORMAL, NULL, NULL); CHECK("VDCreateBase()"); bool fInit = true; uint32_t cIteration = 0; /* Do the real work now */ while ( RT_SUCCESS(rc) && cIteration < pTest->cIterations) { /* Write */ rc = tstVDSnapWrite(pVD, paDiskSeg, cDiskSegments, cbDisk, fInit); CHECK_BREAK("tstVDSnapWrite()"); fInit = false; /* Write returned, do we want to create a new diff or merge them? */ bool fCreate = cDiffs < pTest->cDiffsMinBeforeMerge ? true : tstVDSnapIsTrue(pTest->uCreateDiffChance); if (fCreate) { char *pszDiffFilename = NULL; RTStrAPrintf(&pszDiffFilename, "tstVDSnapDiff%u.%s", idDiff, pTest->pcszDiffSuff); CHECK("RTStrAPrintf()"); idDiff++; cDiffs++; rc = VDCreateDiff(pVD, pTest->pcszBackend, pszDiffFilename, VD_IMAGE_FLAGS_NONE, "Test diff image", NULL, NULL, VD_OPEN_FLAGS_NORMAL, NULL, NULL); CHECK_BREAK("VDCreateDiff()"); RTStrFree(pszDiffFilename); VDDumpImages(pVD); /* Change data */ tstVDSnapSegmentsDice(pTest, paDiskSeg, cDiskSegments, pbTestPattern, pTest->cbTestPattern); } else { uint32_t uStartMerge = RTRandAdvU32Ex(g_hRand, 1, cDiffs - 1); uint32_t uEndMerge = RTRandAdvU32Ex(g_hRand, uStartMerge + 1, cDiffs); RTPrintf("Merging %u diffs from %u to %u...\n", uEndMerge - uStartMerge, uStartMerge, uEndMerge); if (pTest->fForward) rc = VDMerge(pVD, uStartMerge, uEndMerge, NULL); else rc = VDMerge(pVD, uEndMerge, uStartMerge, NULL); CHECK_BREAK("VDMerge()"); cDiffs -= uEndMerge - uStartMerge; VDDumpImages(pVD); /* Go through the disk segments and reset pointers. */ for (uint32_t i = 0; i < cDiskSegments; i++) { if (paDiskSeg[i].pbDataDiff) { paDiskSeg[i].pbData = paDiskSeg[i].pbDataDiff; paDiskSeg[i].pbDataDiff = NULL; } } /* Now compare the result with our test pattern */ rc = tstVDSnapReadVerify(pVD, paDiskSeg, cDiskSegments, cbDisk); CHECK_BREAK("tstVDSnapReadVerify()"); } cIteration++; } VDDumpImages(pVD); VDDestroy(pVD); if (paDiskSeg) RTMemFree(paDiskSeg); if (pbTestPattern) RTMemFree(pbTestPattern); RTFileDelete(pTest->pcszBaseImage); for (unsigned i = 0; i < idDiff; i++) { char *pszDiffFilename = NULL; RTStrAPrintf(&pszDiffFilename, "tstVDSnapDiff%u.%s", i, pTest->pcszDiffSuff); RTFileDelete(pszDiffFilename); RTStrFree(pszDiffFilename); } #undef CHECK return rc; }