void CRpcMessage::add_attr(const char * path, const char * name, const char * value, IProperties & attrs) { if ((path && *path) || (name && *name)) { CSoapValue *par=m_params.get(); if(path) par = par->get_value(path); if (name) par = par->get_value(name); if (par) { Owned<IPropertyIterator> piter = attrs.getIterator(); for (piter->first(); piter->isValid(); piter->next()) { const char *propkey = piter->getPropKey(); par->add_attribute(propkey, attrs.queryProp(propkey)); } } } else { Owned<IPropertyIterator> piter = attrs.getIterator(); for (piter->first(); piter->isValid(); piter->next()) { const char *propkey = piter->getPropKey(); add_attribute(propkey, attrs.queryProp(propkey)); } } }
void CFileSpraySoapBindingEx::xsltTransform(const char* xml, const char* sheet, IProperties *params, StringBuffer& ret) { StringBuffer xsl; if (!checkFileExists(sheet)) throw MakeStringException(ECLWATCH_FILE_NOT_EXIST, "Cannot open stylesheet %s",sheet); Owned<IXslProcessor> proc = getXslProcessor(); Owned<IXslTransform> trans = proc->createXslTransform(); trans->setXmlSource(xml, strlen(xml)); trans->loadXslFromFile(sheet); if (params) { Owned<IPropertyIterator> it = params->getIterator(); for (it->first(); it->isValid(); it->next()) { const char *key = it->getPropKey(); //set parameter in the XSL transform skipping over the @ prefix, if any const char* paramName = *key == '@' ? key+1 : key; trans->setParameter(paramName, StringBuffer().append('\'').append(params->queryProp(key)).append('\'').str()); } } trans->transform(ret); }
virtual ISecResource* clone() { CSecurityResource* _res = new CSecurityResource(m_name.get()); if(!_res) return NULL; _res->setResourceType(m_resourcetype); _res->setDescription(m_description.str()); _res->setValue(m_value.str()); _res->setRequiredAccessFlags(getRequiredAccessFlags()); _res->setAccessFlags(getAccessFlags()); if(!m_parameters) return _res; Owned<IPropertyIterator> Itr = m_parameters->getIterator(); Itr->first(); while(Itr->isValid()) { _res->addParameter(Itr->getPropKey(),m_parameters->queryProp(Itr->getPropKey())); Itr->next(); } return _res; }
void CLdapSecResource::copy(ISecResource* from) { if(!from) return; CLdapSecResource* ldapfrom = dynamic_cast<CLdapSecResource*>(from); if(!ldapfrom) return; m_access = ldapfrom->m_access; setDescription(ldapfrom->m_description.str()); if(m_parameters.get()) { m_parameters.clear(); } if(!ldapfrom->m_parameters.get()) return; Owned<IPropertyIterator> Itr = ldapfrom->m_parameters->getIterator(); Itr->first(); while(Itr->isValid()) { addParameter(Itr->getPropKey(), ldapfrom->m_parameters->queryProp(Itr->getPropKey())); Itr->next(); } return; }
virtual void copyTo(ISecUser& destination) { destination.setAuthenticateStatus(getAuthenticateStatus()); destination.setName(getName()); destination.setFullName(getFullName()); destination.setFirstName(getFirstName()); destination.setLastName(getLastName()); destination.setRealm(getRealm()); destination.setFqdn(getFqdn()); destination.setPeer(getPeer()); destination.credentials().setPassword(credentials().getPassword()); CDateTime tmpTime; destination.setPasswordExpiration(getPasswordExpiration(tmpTime)); destination.setStatus(getStatus()); if(m_parameters.get()==NULL) return; CriticalBlock b(crit); Owned<IPropertyIterator> Itr = m_parameters->getIterator(); Itr->first(); while(Itr->isValid()) { destination.setProperty(Itr->getPropKey(),m_parameters->queryProp(Itr->getPropKey())); Itr->next(); } //addToken is not currently implemented.... // DBGLOG("Copied name %s to %s",getName(),destination.getName()); }
// Load mergedEnvironment from local XML node void CPackageNode::loadEnvironment() { mergedEnvironment.setown(createProperties(true)); Owned<IPropertyTreeIterator> envIterator = node->getElements("Environment"); ForEach(*envIterator) { IPropertyTree &env = envIterator->query(); const char *id = env.queryProp("@id"); const char *val = env.queryProp("@value"); if (!val) val = env.queryProp("@val"); // Historically we used val here - not sure why... other parts of package file used value if (id && val) mergedEnvironment->setProp(id, val); else { StringBuffer s; toXML(&env, s); throw MakeStringException(PACKAGE_MISSING_ID, "PACKAGE_ERROR: Environment element missing id or value: %s", s.str()); } } Owned<IAttributeIterator> attrs = node->getAttributes(); for(attrs->first(); attrs->isValid(); attrs->next()) { StringBuffer s("control:"); s.append(attrs->queryName()+1); // queryName() has a leading @, hence the +1 mergedEnvironment->setProp(s.str(), attrs->queryValue()); } }
IHqlExpression * XmlEclRepository::doLoadSymbol(IPropertyTree * repository, IAtom * modname, IAtom * attrname) { StringBuffer s; IPropertyTree* module = repository->queryPropTree(s.append("./Module[@name=\"").append(*modname).append("\"]").str()); if(!module) { if (logging()) DBGLOG("No data for module %s",modname->getAtomNamePtr()); return 0; } int access = module->getPropInt("@access",cs_full); s.clear().append("./Attribute[@name=\"").append(*attrname).append("\"]"); Owned<IPropertyTreeIterator> it = module->getElements(s.str()); for(it->first();it->isValid();it->next()) { Owned<IHqlExpression> item = toNamedSymbol(&it->query(), *modname,access); CHqlNamedSymbol* cur = QUERYINTERFACE(item.get(), CHqlNamedSymbol); if(cur) return LINK(cur); } return 0; }
void RemoteXmlEclRepository::checkCacheValid() { ConcreteEclRepository::checkCacheValid(); DBGLOG("check cache"); Owned<IPropertyTree> repository = getModules(cachestamp); if(!repository) { DBGLOG("getModules returned null"); //process error return; } Owned<IPropertyTreeIterator> it = repository->getElements("./Module"); bool somethingChanged = false; for (it->first(); it->isValid(); it->next()) { IPropertyTree & cur = it->query(); Owned<IHqlRemoteScope> rScope = createModule(&cur); timestamp_t timestamp = (timestamp_t)cur.getPropInt64("@timestamp"); if (timestamp > cachestamp) cachestamp = timestamp; somethingChanged = true; } if(somethingChanged) rootScope->invalidateParsed(); }
bool CLogThread::IsArray(IPropertyTree& tree) { // If the node have more than one children, and all have the same name, // then it is an array. StringBuffer name, temp; Owned<IPropertyTreeIterator> itr = tree.getElements("*"); int count = 0; for (itr->first(); itr->isValid(); itr->next()) { if (count==0) itr->query().getName(name); else { itr->query().getName(temp); if (stricmp(name,temp)!=0) return false; temp.clear(); } count++; } //Loophole in code above if there is only 1 item in the array if(count==1) { if (name!=NULL && stricmp(name,"Item")==0) return true; } return count>1; }
void cleanupSchedulerList(IPropertyTree * schedule) { Owned<IRemoteConnection> conn = querySDS().connect("/Schedulers", myProcessSession(), RTM_LOCK_WRITE, connectionTimeout); if(!conn) return; Owned<IPropertyTree> root(conn->queryRoot()->getBranch(".")); Owned<IPropertyTreeIterator> iter = root->getElements("*"); for(iter->first(); iter->isValid(); iter->next()) if(!schedule->hasProp(iter->query().queryName())) iter->query().setProp("@remove", "yes"); bool more; do more = root->removeProp("*[@remove=\"yes\"]"); while(more); }
bool updateDaliEnv(IPropertyTree *env, bool forceGroupUpdate, const char *daliIp) { Owned<IPropertyTreeIterator> dalis = env->getElements("Software/DaliServerProcess/Instance"); if (!dalis||!dalis->first()) { fprintf(stderr,"Could not find DaliServerProcess\n"); return false; } SocketEndpoint daliep; loop { const char *ps = dalis->get().queryProp("@port"); unsigned port = ps?atoi(ps):0; if (!port) port = DALI_SERVER_PORT; daliep.set(dalis->get().queryProp("@netAddress"),port); if (daliIp && *daliIp) { SocketEndpoint testep; testep.set(daliIp,DALI_SERVER_PORT); if (testep.equals(daliep)) break; daliep.set(NULL,0); } if (!dalis->next()) break; if (!daliep.isNull()) { fprintf(stderr,"Ambiguous DaliServerProcess instance\n"); return false; } } if (daliep.isNull()) { fprintf(stderr,"Could not find DaliServerProcess instance\n"); return false; } SocketEndpointArray epa; epa.append(daliep); Owned<IGroup> group = createIGroup(epa); bool ret = true; initClientProcess(group, DCR_Util); StringBuffer response; if (querySDS().updateEnvironment(env, forceGroupUpdate, response)) { StringBuffer tmp; PROGLOG("Environment and node groups updated in dali at %s",daliep.getUrlStr(tmp).str()); } else ret = false; if (response.length()) WARNLOG("%s", response.str()); closedownClientProcess(); return ret; }
void CLogThread::addLogInfo(IArrayOf<IEspLogInfo>& valueArray,IPropertyTree& logInfo) { StringBuffer dataStr,nameStr,valueStr; Owned<IPropertyTreeIterator> itr = logInfo.getElements("*"); itr->first(); while(itr->isValid()) { IPropertyTree &node = itr->query(); const char* name = node.queryName(); if (getTreeFlattening()==true && node.hasChildren() == true) { if(IsArray(node)==true) { FlattenArray(valueArray,node,nameStr); } else { FlattenTree(valueArray,node,nameStr); } // logElement.setName(node.queryName()); // dataStr.clear(); /*toXML(&node,dataStr); //DOM temporary work about for the lack of XML decoding in esp arrays StringBuffer encodedData; JBASE64_Encode(dataStr.str(), dataStr.length() , encodedData); logElement.setData(encodedData.str()); */ } else if (getTreeFlattening()==false && node.hasChildren() == true) { IClientLogInfo& logElement = addLogInfoElement(valueArray); logElement.setName(node.queryName()); dataStr.clear(); toXML(&node,dataStr); //DOM temporary work about for the lack of XML decoding in esp arrays StringBuffer encodedData; JBASE64_Encode(dataStr.str(), dataStr.length() , encodedData); logElement.setData(encodedData.str()); } else if (node.queryProp("") != 0 && ( strcmp(node.queryProp(""),"0") != 0 )) { IClientLogInfo& logElement = addLogInfoElement(valueArray); logElement.setName(node.queryName()); logElement.setValue(node.queryProp("")); } itr->next(); } }
void recursiveCleanup(IPropertyTree * tree, unsigned level) { Owned<IPropertyTreeIterator> iter = tree->getElements("*"); for(iter->first(); iter->isValid(); iter->next()) { if(level) recursiveCleanup(&iter->query(), level-1); if(!iter->query().hasChildren()) iter->query().setProp("@remove", "yes"); } bool more; do more = tree->removeProp("*[@remove=\"yes\"]"); while(more); }
void CLogThread::deserializeLogInfo(IArrayOf<IEspLogInfo>& valueArray,IPropertyTree& logInfo) { Owned<IPropertyTreeIterator> itr = logInfo.getElements("LogInfo"); itr->first(); while(itr->isValid()) { IPropertyTree &node = itr->query(); IClientLogInfo& logElement = addLogInfoElement(valueArray); logElement.setName(node.queryProp("Name")); logElement.setValue(node.queryProp("Value")); logElement.setData(node.queryProp("Data")); itr->next(); } }
void CBaseSecurityManager::init(const char *serviceName, IPropertyTree *config) { if(config == NULL) return; m_config.set(config); m_permissionsCache.setCacheTimeout( 60 * config->getPropInt("@cacheTimeout", 5) ); m_dbserver.appendf("%s",config->queryProp("@serverName")); m_dbuser.appendf("%s",config->queryProp("@systemUser")); if(config->hasProp("@ConnectionPoolSize")) m_poolsize = atoi(config->queryProp("@connectionPoolSize")); else m_poolsize = 2; StringBuffer encodedPass,encryptedPass; encodedPass.appendf("%s",config->queryProp("@systemPassword")); decrypt(m_dbpassword, encodedPass.str()); m_dbpasswordEncoding = SecPwEnc_plain_text; StringBuffer strPasswordEncoding; const char* encodingType = config->queryProp("@encodePassword"); if(encodingType && strcmp(encodingType,"MD5") == 0) m_dbpasswordEncoding=SecPwEnc_salt_md5; else if (encodingType && strcmp(encodingType,"Rijndael") == 0) m_dbpasswordEncoding=SecPwEnc_Rijndael; else if (encodingType && strcmp(encodingType,"Accurint MD5") == 0) m_dbpasswordEncoding = SecPwEnc_salt_accurint_md5; if(m_dbserver.length() == 0 || m_dbuser.length() == 0) throw MakeStringException(-1, "CBaseSecurityManager() - db server or user is missing"); IPropertyTree* pNonRestrictedIPTree = config->queryBranch("SafeIPList"); if(pNonRestrictedIPTree) { Owned<IPropertyTreeIterator> Itr = pNonRestrictedIPTree->getElements("ip"); for(Itr->first();Itr->isValid();Itr->next()) { IPropertyTree& tree = Itr->query(); m_safeIPList[tree.queryProp("")]=true; } } m_enableIPRoaming = config->getPropBool("@enableIPRoaming"); m_enableOTP = config->getPropBool("@enableOTP",false); m_passwordExpirationWarningDays = config->getPropInt(".//@passwordExpirationWarningDays", 10); //Default to 10 days }
void MessageGenerator::initCfgDefValues(const char* method) { if (m_cfg.get()) { m_cfgDefValues.clear(); // Common Owned<IPropertyTreeIterator> fs = m_cfg->getElements("Common/Field"); for (fs->first(); fs->isValid(); fs->next()) { IPropertyTree& f = fs->query(); m_cfgDefValues[f.queryProp("@name")] = f.queryProp("@value"); } // Service specific fs.setown(m_cfg->getElements(VStringBuffer("Services/Service[@name='%s']/Field",method))); for (fs->first(); fs->isValid(); fs->next()) { IPropertyTree& f = fs->query(); m_cfgDefValues[f.queryProp("@name")] = f.queryProp("@value"); } } }
static void serializeAttributes(StringBuffer& outbuf, IProperties* attrs) { if (attrs) { Owned<IPropertyIterator> it = attrs->getIterator(); for (it->first(); it->isValid(); it->next()) { const char* k = it->getPropKey(); const char* v = attrs->queryProp(k); outbuf.append(' ').append(k).append("=\""); encodeUtf8XML(v,outbuf); outbuf.append('"'); } } }
//--------------------------------------------------------------------------- // check //--------------------------------------------------------------------------- void CEspDeploymentEngine::check() { CDeploymentEngine::check(); // Make sure all protocol and service referenced by bindings are valid Owned<IPropertyTreeIterator> iter = m_process.getElements("EspBinding"); for (iter->first(); iter->isValid(); iter->next()) { IPropertyTree* pBinding = &iter->query(); const char* service = pBinding->queryProp("@service"); if (service) { if (!lookupProcess("EspService", service)) throw MakeStringException(0, "Process %s references unknown service %s", m_name.get(), service); } else throw MakeStringException(-1, "The ESP binding %s for ESP %s has missing service information!", pBinding->queryProp("@name"), m_name.get()); } // Make sure DaliServers are valid iter.setown(m_process.getElements(".//*[@daliServers]")); ForEach(*iter) { const char* name = iter->query().queryProp("@daliServers"); if (name && *name && !lookupProcess("DaliServerProcess", name)) throw MakeStringException(0, "Process %s references unknown DaliServers %s", m_name.get(), name); } // Make sure EclServer is valid iter.setown(m_process.getElements(".//*[@eclServer]")); ForEach(*iter) { const char* name = iter->query().queryProp("@eclServer"); if (name && *name && !lookupProcess("EclServerProcess", name)) throw MakeStringException(0, "Process %s references unknown EclServer %s", m_name.get(), name); } // Make sure AttributeServer is valid iter.setown(m_process.getElements(".//*[@attributeServer]")); ForEach(*iter) { const char* name = iter->query().queryProp("@attributeServer"); if (name && *name && !lookupProcess("AttrServerProcess", name)) throw MakeStringException(0, "Process %s references unknown AttributeServer %s", m_name.get(), name); } }
//--------------------------------------------------------------------------- // processCustomMethod //--------------------------------------------------------------------------- void CEspDeploymentEngine::processCustomMethod(const char *method, const char *source, const char *outputFile, const char *instanceName, EnvMachineOS os) { if (!stricmp(method, "ssl_certificate")) { //we only need to worry about SSL certificates and private keys if https is being used //by any of our bindings // Owned<IPropertyTreeIterator> it = m_process.getElements("EspBinding[@protocol='https']"); if (!it->first()) return; } CDeploymentEngine::processCustomMethod(method, source, outputFile, instanceName, os); }
bool CLogThread::FlattenTree(IArrayOf<IEspLogInfo>& valueArray,IPropertyTree& tree,StringBuffer& RootName) { StringBuffer Value,Name; if (tree.hasChildren() == true) { Owned<IPropertyTreeIterator> itr = tree.getElements("*"); itr->first(); while(itr->isValid()) { IPropertyTree &node = itr->query(); if(RootName.length() > 0) Name.appendf("%s_",RootName.str()); Name.appendf("%s",node.queryName()); if (node.hasChildren() == true) { if(IsArray(node)==true) FlattenArray(valueArray,node,Name); else FlattenTree(valueArray,node,Name); } else { const char* _value = tree.queryProp(node.queryName()); if(tree.hasProp(node.queryName())==true && _value!=0 && _value!='\0') { Value.appendf("%s",tree.queryProp(node.queryName())); IClientLogInfo& logElement = addLogInfoElement(valueArray); logElement.setName(Name.str()); logElement.setValue(Value.str()); //DBGLOG("Add log element: %s, %s", Name.str(), Value.str()); Value.clear(); } } Name.clear(); itr->next(); } } else { return false; } return true; }
bool XmlEclRepository::doLoadModule(IPropertyTree * repository, IHqlRemoteScope * rScope, IErrorReceiver *errs) { IHqlScope * scope = rScope->queryScope(); const char * scopeName = scope->queryName()->getAtomNamePtr(); StringBuffer s; const char * modName = scope->queryFullName(); IPropertyTree* module = repository->queryPropTree(s.append("./Module[@name=\"").append(modName).append("\"]").str()); if(!module) { if (logging()) DBGLOG("No data for module %s",scopeName); return false; } int access = module->getPropInt("@access",cs_full); if(module->queryProp("Text")) { const char * path = module->queryProp("@sourcePath"); Owned<ISourcePath> sourcePath = createSourcePath(path ? path : modName); Owned<IFileContents> text = createFileContentsFromText(module->queryProp("Text"), sourcePath); rScope->setText(text); } else { StringBuffer buf("./Attribute"); Owned<IPropertyTreeIterator> it = module->getElements(buf.str()); if (it->first()) { for(;it->isValid();it->next()) { Owned<IHqlExpression> item = toNamedSymbol(&it->query(), *scope->queryName(), access); ((CHqlScope*)scope)->defineSymbol(LINK(item)); } } else { if (logging()) DBGLOG("No definitions were added for module %s", scopeName); } } return true; }
bool CLogThread::FlattenArray(IArrayOf<IEspLogInfo>& valueArray,IPropertyTree& tree,StringBuffer& RootName) { StringBuffer Value,Name; if (tree.hasChildren() == true) { Name.appendf("%s",tree.queryName()); Owned<IPropertyTreeIterator> itrItem = tree.getElements("./*"); itrItem->first(); while(itrItem->isValid()==true) { IPropertyTree &node = itrItem->query(); if(Value.length()!=0) Value.append(","); Value.appendf("%s",node.queryProp("")); itrItem->next(); } IClientLogInfo& logElement = addLogInfoElement(valueArray); logElement.setName(Name.str()); logElement.setValue(Value.str()); } return true; }
virtual void copy(ISecResource* from) { if(!from) return; CSecurityResource* _res = (CSecurityResource*)(from); if(!_res) return; setDescription(_res->m_description.str()); setValue(_res->m_value.str()); setAccessFlags(_res->getAccessFlags()); if(!_res->m_parameters) return; Owned<IPropertyIterator> Itr = _res->m_parameters->getIterator(); Itr->first(); while(Itr->isValid()) { addParameter(Itr->getPropKey(), _res->m_parameters->queryProp(Itr->getPropKey())); Itr->next(); } return; }
void CFileSpraySoapBindingEx::downloadFile(IEspContext &context, CHttpRequest* request, CHttpResponse* response) { try { StringBuffer netAddressStr, osStr, pathStr, nameStr; request->getParameter("NetAddress", netAddressStr); request->getParameter("OS", osStr); request->getParameter("Path", pathStr); request->getParameter("Name", nameStr); #if 0 StringArray files; IProperties* params = request->queryParameters(); Owned<IPropertyIterator> iter = params->getIterator(); if (iter && iter->first()) { while (iter->isValid()) { const char *keyname=iter->getPropKey(); if (!keyname || strncmp(keyname, "Names", 5)) continue; files.append(params->queryProp(iter->getPropKey())); iter->next(); } } #endif if (netAddressStr.length() < 1) throw MakeStringException(ECLWATCH_INVALID_INPUT, "Network address not specified."); if (pathStr.length() < 1) throw MakeStringException(ECLWATCH_INVALID_INPUT, "Path not specified."); if (nameStr.length() < 1) throw MakeStringException(ECLWATCH_INVALID_INPUT,"File name not specified."); char pathSep = '/'; if ((osStr.length() > 1) && (atoi(osStr.str())== OS_WINDOWS)) { pathSep = '\\'; } pathStr.replace(pathSep=='\\'?'/':'\\', pathSep); if (*(pathStr.str() + pathStr.length() -1) != pathSep) pathStr.append( pathSep ); StringBuffer fullName; fullName.appendf("%s%s", pathStr.str(), nameStr.str()); StringBuffer headerStr("attachment;"); headerStr.appendf("filename=%s", nameStr.str()); RemoteFilename rfn; rfn.setRemotePath(fullName.str()); SocketEndpoint ep(netAddressStr.str()); rfn.setIp(ep); Owned<IFile> rFile = createIFile(rfn); if (!rFile) throw MakeStringException(ECLWATCH_CANNOT_OPEN_FILE,"Cannot open file %s.",fullName.str()); OwnedIFileIO rIO = rFile->openShared(IFOread,IFSHfull); if (!rIO) throw MakeStringException(ECLWATCH_CANNOT_READ_FILE,"Cannot read file %s.",fullName.str()); IFileIOStream* ioS = createIOStream(rIO); context.addCustomerHeader("Content-disposition", headerStr.str()); response->setContent(ioS); response->setContentType(HTTP_TYPE_OCTET_STREAM); response->send(); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return; }
int main(int argc, const char **argv) { #ifdef _WIN32 _setmode( _fileno( stdout ), _O_BINARY ); _setmode( _fileno( stdin ), _O_BINARY ); #endif Owned<IProperties> globals = createProperties("dumpkey.ini", true); for (int i = 1; i < argc; i++) { if (argv[i][0] == '-') doOption(argv[i]); else if (strchr(argv[i], '=')) globals->loadProp(argv[i]); else globals->setProp("keyfile", argv[i]); } try { StringBuffer logname("dumpkey."); logname.append(GetCachedHostName()).append("."); StringBuffer lf; openLogFile(lf, logname.append("log").str()); Owned <IKeyIndex> index; const char * keyName = globals->queryProp("keyfile"); if (keyName) index.setown(createKeyIndex(keyName, 0, false, false)); else usage(); Owned <IKeyCursor> cursor = index->getCursor(NULL); size32_t key_size = index->keySize(); Owned<IFile> in = createIFile(keyName); Owned<IFileIO> io = in->open(IFOread); if (!io) throw MakeStringException(999, "Failed to open file %s", keyName); Owned<CKeyHdr> header = new CKeyHdr; MemoryAttr block(sizeof(KeyHdr)); io->read(0, sizeof(KeyHdr), (void *)block.get()); header->load(*(KeyHdr*)block.get()); unsigned nodeSize = header->getNodeSize(); if (!optRaw) { printf("Key '%s'\nkeySize=%d NumParts=%x, Top=%d\n", keyName, key_size, index->numParts(), index->isTopLevelKey()); printf("File size = %"I64F"d, nodes = %"I64F"d\n", in->size(), in->size() / nodeSize - 1); printf("rootoffset=%"I64F"d[%"I64F"d]\n", header->getRootFPos(), header->getRootFPos()/nodeSize); } char *buffer = (char*)alloca(key_size); if (globals->hasProp("node")) { if (stricmp(globals->queryProp("node"), "all")==0) { } else { int node = globals->getPropInt("node"); if (node != 0) index->dumpNode(stdout, node * nodeSize, globals->getPropInt("recs", 0), optRaw); } } else if (globals->hasProp("fpos")) { index->dumpNode(stdout, globals->getPropInt("fpos"), globals->getPropInt("recs", 0), optRaw); } else { bool backwards=false; bool ok; if (globals->hasProp("end")) { memset(buffer, 0, key_size); strcpy(buffer, globals->queryProp("end")); ok = cursor->ltEqual(buffer, buffer); backwards = true; } else if (globals->hasProp("start")) { memset(buffer, 0, key_size); strcpy(buffer, globals->queryProp("start")); ok = cursor->gtEqual(buffer, buffer); } else ok = cursor->first(buffer); unsigned count = globals->getPropInt("recs", 1); while (ok && count--) { offset_t pos = cursor->getFPos(); unsigned __int64 seq = cursor->getSequence(); size32_t size = cursor->getSize(); if (optRaw) { fwrite(buffer, 1, size, stdout); } else if (optHex) { for (unsigned i = 0; i < size; i++) printf("%02x", ((unsigned char) buffer[i]) & 0xff); printf(" :%"I64F"u:%012"I64F"x\n", seq, pos); } else printf("%.*s :%"I64F"u:%012"I64F"x\n", size, buffer, seq, pos); if (backwards) ok = cursor->prev(buffer); else ok = cursor->next(buffer); } } } catch (IException *E) { StringBuffer msg; E->errorMessage(msg); E->Release(); fatal("%s", msg.str()); } releaseAtoms(); ExitModuleObjects(); return 0; }
void prepareKey(IDistributedFile *index) { IDistributedFile *f = index; IDistributedSuperFile *super = f->querySuperFile(); unsigned nparts = f->numParts(); // includes tlks if any, but unused in array performPartLookup.ensure(nparts); bool checkTLKConsistency = (nullptr != super) && !localKey && (0 != (TIRsorted & indexBaseHelper->getFlags())); if (nofilter) { while (nparts--) performPartLookup.append(true); if (!checkTLKConsistency) return; } else { while (nparts--) performPartLookup.append(false); // parts to perform lookup set later } Owned<IDistributedFileIterator> iter; if (super) { iter.setown(super->getSubFileIterator(true)); verifyex(iter->first()); f = &iter->query(); } unsigned width = f->numParts(); if (!localKey) --width; assertex(width); unsigned tlkCrc = 0; bool first = true; unsigned superSubIndex=0; bool fileCrc = false, rowCrc = false; for (;;) { Owned<IDistributedFilePart> part = f->getPart(width); if (checkTLKConsistency) { unsigned _tlkCrc; if (part->getCrc(_tlkCrc)) fileCrc = true; else if (part->queryAttributes().hasProp("@crc")) // NB: key "@crc" is not a crc on the file, but data within. { _tlkCrc = part->queryAttributes().getPropInt("@crc"); rowCrc = true; } else if (part->queryAttributes().hasProp("@tlkCrc")) // backward compat. { _tlkCrc = part->queryAttributes().getPropInt("@tlkCrc"); rowCrc = true; } else { if (rowCrc || fileCrc) { checkTLKConsistency = false; Owned<IException> e = MakeActivityWarning(&container, 0, "Cannot validate that tlks in superfile %s match, some crc attributes are missing", super->queryLogicalName()); queryJobChannel().fireException(e); } } if (rowCrc && fileCrc) { checkTLKConsistency = false; Owned<IException> e = MakeActivityWarning(&container, 0, "Cannot validate that tlks in superfile %s match, due to mixed crc types.", super->queryLogicalName()); queryJobChannel().fireException(e); } if (checkTLKConsistency) { if (first) { tlkCrc = _tlkCrc; first = false; } else if (tlkCrc != _tlkCrc) throw MakeActivityException(this, 0, "Sorted output on super files comprising of non coparitioned sub keys is not supported (TLK's do not match)"); } } if (!nofilter) { Owned<IKeyIndex> keyIndex; unsigned copy; for (copy=0; copy<part->numCopies(); copy++) { RemoteFilename rfn; OwnedIFile ifile = createIFile(part->getFilename(rfn,copy)); if (ifile->exists()) { StringBuffer remotePath; rfn.getRemotePath(remotePath); unsigned crc = 0; part->getCrc(crc); keyIndex.setown(createKeyIndex(remotePath.str(), crc, false, false)); break; } } if (!keyIndex) throw MakeThorException(TE_FileNotFound, "Top level key part does not exist, for key: %s", index->queryLogicalName()); unsigned fixedSize = indexBaseHelper->queryDiskRecordSize()->querySerializedDiskMeta()->getFixedSize(); // used only if fixed Owned <IKeyManager> tlk = createLocalKeyManager(keyIndex, fixedSize, NULL); indexBaseHelper->createSegmentMonitors(tlk); tlk->finishSegmentMonitors(); tlk->reset(); while (tlk->lookup(false)) { if (tlk->queryFpos()) performPartLookup.replace(true, (aindex_t)(super?super->numSubFiles(true)*(tlk->queryFpos()-1)+superSubIndex:tlk->queryFpos()-1)); } } if (!super||!iter->next()) break; superSubIndex++; f = &iter->query(); if (width != f->numParts()-1) throw MakeActivityException(this, 0, "Super key %s, with mixture of sub key width are not supported.", f->queryLogicalName()); } }
void MessageGenerator::doType(StringStack& parent, int indent, const char* tag, IXmlType* type, IPTree* tmplat, StringBuffer& buf) { const char* typeName = type->queryName(); if (type->isComplexType()) { if (typeName && std::find(parent.begin(),parent.end(),typeName) != parent.end()) { //DBGLOG("Recursive type: %s, ignored", typeName); } else { int flds = type->getFieldCount(); for (int i=0; i<flds; i++) { const char* fldName = type->queryFieldName(i); buf.appendf("<%s>", fldName); IPTree* existing = tmplat->queryBranch(fldName); if (typeName) parent.push_back(typeName); if (existing) doType(parent,indent+1,fldName, type->queryFieldType(i), existing, buf); else doType(parent,indent+1,fldName,type->queryFieldType(i),buf); buf.appendf("</%s>", fldName); if (typeName) parent.pop_back(); } } } else if (type->isArray()) { if (typeName && std::find(parent.begin(),parent.end(),typeName) != parent.end()) { //DBGLOG("Recursive type: %s, ignored", typeName); } else { const char* itemName = type->queryFieldName(0); IXmlType* itemType = type->queryFieldType(0); int childCount = tmplat->numChildren(); if (typeName) parent.push_back(typeName); if (childCount>0) { Owned<IPTreeIterator> items = tmplat->getElements(itemName); for (items->first(); items->isValid(); items->next()) { buf.appendf("<%s>", itemName); doType(parent,indent+2,itemName,itemType,&items->query(),buf); buf.appendf("</%s>", itemName); } } else { for (int i=0; i<m_items; i++) { buf.appendf("<%s>", itemName); doType(parent,indent+2,itemName, itemType, buf); buf.appendf("</%s>", itemName); } if (m_ecl2esp) buf.appendf("<%s/>", itemName); } if (typeName) parent.pop_back(); } } else { const char* existing = tmplat->queryProp("."); if (existing && isNotBlank(existing)) encodeXML(existing,buf); else if (m_gx) buf.append("*** MISSING ***"); else { DefValMap::const_iterator it = m_cfgDefValues.find(tag); if (it != m_cfgDefValues.end()) buf.append(it->second.c_str()); else type->getSampleValue(buf,tag); } } }
MessageGenerator::MessageGenerator(const char* path, bool keepfile, SchemaType st, IProperties* globals) : m_keepfile(keepfile), m_schemaType(st) { if(globals) m_globals = globals; m_items = globals->queryProp("items")?atoi(globals->queryProp("items")):1; m_isRoxie = globals->queryProp("roxie") ? true : false; m_genAllDatasets = globals->queryProp("alldataset") ? true : false; m_gx = globals->queryProp("gx") ? true : false; m_soapWrap = globals->queryProp("gs") ? false: true; m_ecl2esp = globals->getPropBool("ECL2ESP", false); if (m_ecl2esp) m_items = 1; if (globals->queryProp("gf")) m_gfile.set(globals->queryProp("gf")); if (globals->queryProp("cfg")) { StringBuffer cfg; if (loadFile(cfg, globals->queryProp("cfg"))) m_cfg.setown(createPTreeFromXMLString(cfg)); else ERRLOG("Can not load cfg file; ignored"); } m_logfile = stdout; if(!path || !*path) { throw MakeStringException(-1, "please provide the path of wsdl"); } m_path.append(path); if(strnicmp(path, "http:", 5) == 0 || strnicmp(path, "https:", 6) == 0) { HttpClient client(NULL, path); StringBuffer requestbuf; client.generateGetRequest(requestbuf); client.sendRequest(requestbuf, NULL, NULL, NULL, &m_schema); const char* ptr = m_schema.str(); if(ptr) { ptr = strchr(ptr, '<'); if(!ptr) { if(http_tracelevel > 0) fprintf(m_logfile, "The schema is not valid xml%s", LT); return; } else m_schema.remove(0, ptr - m_schema.str()); } } else { m_schema.loadFile(path); if(http_tracelevel >= 10) fprintf(m_logfile, "Loaded schema:\n%s\n", m_schema.str()); } if(m_schema.length() == 0) { throw MakeStringException(-1, "wsdl is empty"); } Owned<IPropertyTree> schema = createPTreeFromXMLString(m_schema.str()); if (m_isRoxie) m_roxieSchemaRoot.set(schema->queryBranch("//Result")); else m_schemaTree.set(schema); if(!m_schemaTree.get() && !m_roxieSchemaRoot.get()) throw MakeStringException(-1, "can't generate property tree from schema"); setXsdNamespace(); if (!m_isRoxie) { if(m_schemaType == WSDL) { Owned<IPropertyTreeIterator> mi = m_schemaTree->getElements("portType/operation"); if(mi.get()) { std::set<std::string> methods; for (mi->first(); mi->isValid(); mi->next()) { const char *name = mi->query().queryProp("@name"); if(!name || !*name) continue; StringBuffer xpath; xpath.clear().append("portType/operation[@name='").append(name).append("']/input/@message"); const char* input = m_schemaTree->queryProp(xpath.str()); if(!input || !*input) throw MakeStringException(-1, "can't find input message for method %s", name); if(strncmp(input, "tns:", 4) == 0) input += 4; xpath.clear().append("message[@name='").append(input).append("']/part/@element"); const char* element = m_schemaTree->queryProp(xpath.str()); if(!element || !*element) throw MakeStringException(-1, "can't find message %s\n", input); if(strncmp(element, "tns:", 4) == 0) element += 4; if(methods.find(element) == methods.end()) { methods.insert(element); m_methods.append(element); } xpath.clear().append("portType/operation[@name='").append(name).append("']/output/@message"); const char* output = m_schemaTree->queryProp(xpath.str()); if(!output || !*output) throw MakeStringException(-1, "can't find output message for method %s", name); if(strncmp(output, "tns:", 4) == 0) output += 4; xpath.clear().append("message[@name='").append(output).append("']/part/@element"); element = m_schemaTree->queryProp(xpath.str()); if(!element || !*element) throw MakeStringException(-1, "can't find message %s\n", output); if(strncmp(element, "tns:", 4) == 0) element += 4; if(methods.find(element) == methods.end()) { methods.insert(element); m_methods.append(element); } } } } else { Owned<IPropertyTreeIterator> mi = m_schemaTree->getElements(VStringBuffer("%s:element",xsdNs())); if(mi.get()) { for (mi->first(); mi->isValid(); mi->next()) { const char *name = mi->query().queryProp("@name"); if(name && *name) m_methods.append(name); } } } } initDefaultValues(); }
void MessageGenerator::genRoxieMessage(const char* templatemsg, StringBuffer& message) { Owned<IPropertyTree> tmplat; StringBuffer root; if (templatemsg) { tmplat.setown(createPTreeFromXMLString(templatemsg)); if(!tmplat.get()) throw MakeStringException(-1, "can't generate property tree from input, please make sure it's valid xml."); root = tmplat->queryName(); tmplat.setown(tmplat->getPropTree(VStringBuffer("//Results/Result"))); if (!tmplat.get()) throw MakeStringException(-1, "can't find Results/Result in input XML"); } else root = "Unknown"; // TODO: find out the root? message.appendf("<!-- <%s> --> %s", root.str(), LT); message.appendf(" <!-- <Results> --> %s", LT); message.appendf(" <Result>%s", LT); Owned<IPropertyTreeIterator> it = m_roxieSchemaRoot->getElements(VStringBuffer("XmlSchema")); for (it->first(); it->isValid(); it->next()) { IPropertyTree* ds = &it->query(); const char* name = ds->queryProp("@name"); if (!name) { ERRLOG("XmlSchema without name"); continue; } IPropertyTree* p = ds->queryBranch(VStringBuffer("%s:schema", xsdNs())); m_schemaTree.setown(LINK(p)); IXmlSchema* xs = createXmlSchemaFromPTree(m_schemaTree); IXmlType* type = xs->queryElementType("Dataset"); if (!type) { ERRLOG("Can not find type '%s'", name); continue; } // get the Row type type = type->queryFieldType(0); if (!type) { ERRLOG("The root element for %s is not an array", name); continue; } IPropertyTree* dsTmplat = tmplat.get() ? tmplat->queryPropTree(VStringBuffer("Dataset[@name='%s']",name)) : NULL; if (dsTmplat && dsTmplat->numChildren()>0) { message.appendf(" <Dataset name=\"%s\">%s", name, LT); Owned<IPropertyTreeIterator> row = dsTmplat->getElements("Row"); for (row->first(); row->isValid(); row->next()) { message.appendf(" <Row>%s", LT); StringStack parent; doType(parent,5,"Row",type, &row->query(), message); message.appendf(" </Row>%s", LT); } message.appendf(" </Dataset>%s", LT); } else if (m_genAllDatasets) { message.appendf(" <Dataset name=\"%s\">%s", name, LT); for (int i=0; i < m_items; i++) { message.appendf(" <Row>%s", LT); StringStack parent; doType(parent,6,"Row",type,message); message.appendf(" </Row>%s", LT); } if (m_ecl2esp) message.appendf(" <Row/>%s", LT); message.appendf(" </Dataset>%s", LT); } } message.appendf(" </Result>%s", LT); message.appendf(" <!-- </Results> --> %s", LT); message.appendf("<!-- </%s> --> %s", root.str(), LT); }