bool cTriggerConsole::CheckData(cfBase *cmd, cTrigger &data) { if(data.mDefinition.empty()) { *cmd->mOS << _("The definition is empty or not specified. Please define it with -d option."); return false; } size_t pos = data.mDefinition.rfind("dbconfig"); if(pos != string::npos) { *cmd->mOS << _("It's not allowed to define dbconfig file as trigger.") << "\n"; cConnDC *conn = (cConnDC *) cmd->mConn; ostringstream message; message << autosprintf(_("User '%s' tried to define dbconfig as trigger"), conn->mpUser->mNick.c_str()); mOwner->mServer->ReportUserToOpchat(conn, message.str()); return false; } FilterPath(data.mDefinition); string vPath(mOwner->mServer->mConfigBaseDir), triggerPath, triggerName; ExpandPath(vPath); GetPath(data.mDefinition, triggerPath, triggerName); ReplaceVarInString(triggerPath, "CFG", triggerPath, vPath); ExpandPath(triggerPath); if ((triggerPath.substr(0, vPath.length()) != vPath)) { (*cmd->mOS) << autosprintf(_("The file %s for the trigger %s must be located in %s configuration folder, use %%[CFG] variable, for example: %%[CFG]/%s"), data.mDefinition.c_str(), data.mCommand.c_str(), HUB_VERSION_NAME, triggerName.c_str()); return false; } return true; }
// Returns the path of a ruby item. If it is an instance variable, assume // that there is an attr_accessor method for it. // For example, @foobar within instance obj is accessed as obj.foobar. // But don't strip off the @ for an instance variable with no path, // and leave a plain '@foobar' as it is. QString VarItem::fullName() const { QString itemName = text(VAR_NAME_COLUMN); QString vPath(""); const VarItem *item = this; if (item->parent()->rtti() != RTTI_VAR_ITEM) { return itemName; } // This stops at the root item (FrameRoot or GlobalRoot) while (item->rtti() == RTTI_VAR_ITEM) { QString itemName = item->text(VAR_NAME_COLUMN); if (vPath.startsWith("[")) { // If it's a Hash or an Array, then just insert the value. As // in adding '[0]' to foo.bar to give foo.bar[0] vPath.prepend(itemName); } else { if (vPath.isEmpty()) { vPath = itemName; } else { vPath.prepend(itemName + "."); } } item = (VarItem*) item->parent(); } // Change 'self.@foobar' to '@foobar' vPath.replace(QRegExp("^self\\.@"), "@"); // Use instance_variable_get() to access any '@var's in the middle of a path QRegExp re_instance_var("\\.(@[^\\[.]+)"); int pos = re_instance_var.search(vPath); while (pos != -1) { vPath.replace( pos, re_instance_var.matchedLength(), QString(".instance_variable_get(:") + re_instance_var.cap(1) + ")" ); pos = re_instance_var.search(vPath, pos); } return vPath; }
void interp(void) { char line[256]; char *p; while(1) { putchar('>'); putchar(' '); fflush(stdin); fflush(stdout); fflush(stderr); gets(line); /* p points to next word after verb on command line */ p = line; while (*p && *p!=' ') p++; if (!*p) p = 0; else { while(*p && *p==' ') p++; } switch(toupper(line[0])) { case 'N': vCreate(p); break; case 'A': error("VR_SetRegDirectory", VR_SetRegDirectory(p)); break; case 'C': error("VR_Close", VR_Close()); break; case 'I': vInstall(p); break; case 'R': error("VR_Remove", VR_Remove(p)); break; case 'X': error("VR_InRegistry", VR_InRegistry(p)); break; case 'T': error("VR_ValidateComponent", VR_ValidateComponent(p)); break; #if LATER case 'E': vEnum(p); break; case 'V': vVersion(p); break; case 'P': vPath(p); break; case 'F': vGetRefCount(p); break; case 'D': vGetDir(p); break; case 'S': puts("--Unsupported--"); #endif case 'H': default: vHelp(line); break; case 'Q': return; } /* switch */ } /* while */ assert(0); return; /* shouldn't get here */ } /* interp */
bool XmlProfileParser::ParseFile(const char *pszPath, Profile *pProfile, HMODULE hModule) { assert(pszPath != nullptr); assert(pProfile != nullptr); // import schema from the named resource HRSRC hSchemaXmlResource = FindResource(hModule, L"DISKSPD.XSD", RT_HTML); assert(hSchemaXmlResource != NULL); HGLOBAL hSchemaXml = LoadResource(hModule, hSchemaXmlResource); assert(hSchemaXml != NULL); LPVOID pSchemaXml = LockResource(hSchemaXml); assert(pSchemaXml != NULL); // convert from utf-8 produced by the xsd authoring tool to utf-16 int cchSchemaXml = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pSchemaXml, -1, NULL, 0); vector<WCHAR> vWideSchemaXml(cchSchemaXml); int dwcchWritten = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pSchemaXml, -1, vWideSchemaXml.data(), cchSchemaXml); UNREFERENCED_PARAMETER(dwcchWritten); assert(dwcchWritten == cchSchemaXml); // ... and finally, packed in a bstr for the loadXml interface CComBSTR bSchemaXml(vWideSchemaXml.data()); bool fComInitialized = false; HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); if (SUCCEEDED(hr)) { fComInitialized = true; CComPtr<IXMLDOMDocument2> spXmlDoc = nullptr; CComPtr<IXMLDOMDocument2> spXmlSchema = nullptr; CComPtr<IXMLDOMSchemaCollection2> spXmlSchemaColl = nullptr; CComPtr<IXMLDOMParseError> spXmlParseError = nullptr; // create com objects and decorate hr = CoCreateInstance(__uuidof(DOMDocument60), nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&spXmlSchema)); if (SUCCEEDED(hr)) { hr = spXmlSchema->put_async(VARIANT_FALSE); } if (SUCCEEDED(hr)) { hr = spXmlSchema->setProperty(CComBSTR("ProhibitDTD"), CComVariant(VARIANT_FALSE)); } if (SUCCEEDED(hr)) { hr = CoCreateInstance(__uuidof(XMLSchemaCache60), nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&spXmlSchemaColl)); } if (SUCCEEDED(hr)) { hr = spXmlSchemaColl->put_validateOnLoad(VARIANT_TRUE); } if (SUCCEEDED(hr)) { hr = CoCreateInstance(__uuidof(DOMDocument60), nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&spXmlDoc)); } if (SUCCEEDED(hr)) { hr = spXmlDoc->put_async(VARIANT_FALSE); } if (SUCCEEDED(hr)) { hr = spXmlDoc->put_validateOnParse(VARIANT_TRUE); } if (SUCCEEDED(hr)) { VARIANT_BOOL fvIsOk; hr = spXmlSchema->loadXML(bSchemaXml, &fvIsOk); if (FAILED(hr) || fvIsOk != VARIANT_TRUE) { hr = spXmlSchema->get_parseError(&spXmlParseError); if (SUCCEEDED(hr)) { ReportXmlError("schema", spXmlParseError); } hr = E_FAIL; } } if (SUCCEEDED(hr)) { CComVariant vXmlSchema(spXmlSchema); CComBSTR bNull(""); hr = spXmlSchemaColl->add(bNull, vXmlSchema); } if (SUCCEEDED(hr)) { CComVariant vSchemaCache(spXmlSchemaColl); hr = spXmlDoc->putref_schemas(vSchemaCache); } if (SUCCEEDED(hr)) { VARIANT_BOOL fvIsOk; CComVariant vPath(pszPath); hr = spXmlDoc->load(vPath, &fvIsOk); if (FAILED(hr) || fvIsOk != VARIANT_TRUE) { hr = spXmlDoc->get_parseError(&spXmlParseError); if (SUCCEEDED(hr)) { ReportXmlError("profile", spXmlParseError); } hr = E_FAIL; } } // now parse the specification, if correct if (SUCCEEDED(hr)) { bool fVerbose; hr = _GetVerbose(spXmlDoc, &fVerbose); if (SUCCEEDED(hr) && (hr != S_FALSE)) { pProfile->SetVerbose(fVerbose); } if (SUCCEEDED(hr)) { DWORD dwProgress; hr = _GetProgress(spXmlDoc, &dwProgress); if (SUCCEEDED(hr) && (hr != S_FALSE)) { pProfile->SetProgress(dwProgress); } } if (SUCCEEDED(hr)) { string sResultFormat; hr = _GetString(spXmlDoc, "//Profile/ResultFormat", &sResultFormat); if (SUCCEEDED(hr) && (hr != S_FALSE) && sResultFormat == "xml") { pProfile->SetResultsFormat(ResultsFormat::Xml); } } if (SUCCEEDED(hr)) { string sCreateFiles; hr = _GetString(spXmlDoc, "//Profile/PrecreateFiles", &sCreateFiles); if (SUCCEEDED(hr) && (hr != S_FALSE)) { if (sCreateFiles == "UseMaxSize") { pProfile->SetPrecreateFiles(PrecreateFiles::UseMaxSize); } else if (sCreateFiles == "CreateOnlyFilesWithConstantSizes") { pProfile->SetPrecreateFiles(PrecreateFiles::OnlyFilesWithConstantSizes); } else if (sCreateFiles == "CreateOnlyFilesWithConstantOrZeroSizes") { pProfile->SetPrecreateFiles(PrecreateFiles::OnlyFilesWithConstantOrZeroSizes); } else { hr = E_INVALIDARG; } } } if (SUCCEEDED(hr)) { hr = _ParseEtw(spXmlDoc, pProfile); } if (SUCCEEDED(hr)) { hr = _ParseTimeSpans(spXmlDoc, pProfile); } } } if (fComInitialized) { CoUninitialize(); } return SUCCEEDED(hr); }