bool CLogThread::queueLog(IEspContext & context,const char* serviceName,int RecordsReturned, IArrayOf<IEspLogInfo>& LogArray, IInterface& logInfo) { StringBuffer dataStr; serializeRequest(context,logInfo,dataStr); Owned<IPropertyTree> pLogTreeInfo = createPTreeFromXMLString(dataStr.str(), ipt_none, ptr_none); return queueLog(context,serviceName,RecordsReturned,LogArray, *pLogTreeInfo); }
bool CLogThread::queueLog(IEspContext & context,const char* serviceName, const char* request, const char* response) { IProperties* pProperties = context.queryRequestParameters(); StringBuffer UserID, UserRealm, UserReference, peer; if(pProperties != NULL && pProperties->hasProp("userid_")) UserID.appendf("%s",pProperties->queryProp("userid_")); else context.getUserID(UserID); if(pProperties != NULL && pProperties->hasProp("fqdn_")) UserRealm.appendf("%s",pProperties->queryProp("fqdn_")); else context.getRealm(UserRealm); Owned<IPropertyTree> pLogTreeInfo = createPTreeFromXMLString(request, ipt_none, ptr_none); IArrayOf<IEspLogInfo> LogArray; addLogInfo(LogArray, *pLogTreeInfo.get()); if(pProperties != NULL && pProperties->hasProp("referencecode_")) { //lets manually add the reference number.... IClientLogInfo& LogInfoTransaction = addLogInfoElement(LogArray); LogInfoTransaction.setName("referencenumber"); LogInfoTransaction.setValue(pProperties->queryProp("referencecode_")); } LOG_INFO _LogStruct(serviceName,-1,false); return queueLog(UserID.str(), UserRealm.str() , context.getPeer(peer).str(),_LogStruct, LogArray ); }
IPropertyTree* RemoteXmlEclRepository::getAttributes(const char *module, const char *attr, int version, unsigned char infoLevel) { IPropertyTree* repositoryTree = 0; StringBuffer xml; try { StringBuffer snapshot; getProp("snapshot",snapshot); bool sandbox4snapshot = getPropInt("sandbox4snapshot", 0) != 0; repository.getAttributes(xml, user, module, attr, version, infoLevel, snapshot.length() ? snapshot.str() : NULL, sandbox4snapshot); if (xml.length()) repositoryTree = createPTreeFromXMLString(xml, ipt_caseInsensitive); } catch(IException *e) { logException(e); if (xml.length()) DBGLOG("Xml: %s", xml.str()); e->Release(); } catch (...) { logException(NULL); } return repositoryTree; }
//--------------------------------------------------------------------------- // CWizardInputs //--------------------------------------------------------------------------- CWizardInputs::CWizardInputs(const char* xmlArg,const char *service, IPropertyTree * cfg, MapStringTo<StringBuffer>* dirMap): m_service(service), m_cfg(cfg), m_overrideDirs(dirMap), m_roxieOnDemand(true), m_supportNodes(0) { m_pXml.setown(createPTreeFromXMLString(xmlArg && *xmlArg ? xmlArg : "<XmlArgs/>")); }
CBaseSecurityManager::CBaseSecurityManager(const char *serviceName, const char *config) { Owned<IPropertyTree> cfg = createPTreeFromXMLString(config, ipt_caseInsensitive); if(cfg.get() == NULL) throw MakeStringException(-1, "createPTreeFromXMLString() failed for %s", config); init(serviceName,cfg); cfg->Release(); }
IPropertyTree& CXRefNode::getDataTree() { if(m_XRefDataTree.get() == 0) m_XRefDataTree.setown(createPTreeFromXMLString(m_dataStr.str())); return *m_XRefDataTree.get(); }
IPropertyTree * SWProcess::addComputer(const char* ip) { Hardware *hd = (Hardware*) m_envHelper->getEnvComp("hardware"); StringBuffer sbTask; sbTask.clear().append("<Task operation=\"add\" category=\"hardware\" component=\"Computer\">"); sbTask.appendf("<Attributes><Attribute name=\"ip\" value=\"%s\"/></Attributes></Task>", ip); Owned<IPropertyTree> params = createPTreeFromXMLString(sbTask.str()); IPropertyTree * pComputer = hd->addComputer(params); return pComputer; }
void ResourceManager::addManifestFromArchive(IPropertyTree *archive) { if (!archive) return; if (finalized) throwError1(HQLERR_ResourceAddAfterFinalManifest, "MANIFEST"); ensureManifestInfo(); Owned<IPropertyTreeIterator> manifests = archive->getElements("AdditionalFiles/Manifest"); ForEach(*manifests) { const char *xml = manifests->query().queryProp(NULL); Owned<IPropertyTree> manifestSrc = createPTreeFromXMLString(xml); Owned<IAttributeIterator> aiter = manifestSrc->getAttributes(); ForEach (*aiter) manifest->setProp(aiter->queryName(), aiter->queryValue()); StringBuffer manifestDir; if (manifestSrc->hasProp("@originalFilename")) splitDirTail(manifestSrc->queryProp("@originalFilename"), manifestDir); Owned<IPropertyTreeIterator> iter = manifestSrc->getElements("*"); ForEach(*iter) { IPropertyTree &item = iter->query(); if (streq(item.queryName(), "Resource") && item.hasProp("@filename")) { if (!item.hasProp("@type")) item.setProp("@type", "UNKNOWN"); const char *filename; if (item.hasProp("@originalFilename")) filename = item.queryProp("@originalFilename"); else filename = item.queryProp("@filename"); int id; if (getDuplicateResourceId(item.queryProp("@type"), NULL, filename, id)) { item.setPropInt("@id", (int)id); manifest->addPropTree("Resource", LINK(&item)); } else { VStringBuffer xpath("AdditionalFiles/Resource[@originalFilename=\"%s\"]", filename); MemoryBuffer content; archive->getPropBin(xpath.str(), content); addCompress(item.queryProp("@type"), content.length(), content.toByteArray(), &item); } } else manifest->addPropTree(item.queryName(), LINK(&item)); } } }
bool CLogThread::queueLog(IEspContext & context,const char* serviceName,int RecordsReturned,bool bBlind,bool bEncrypt, IArrayOf<IEspLogInfo>& LogArray, IInterface& logInfo, IConstModelLogInformation* pModelLogInfo) { LOG_INFO _LogStruct(serviceName,RecordsReturned,bBlind); _LogStruct.Encrypt = bEncrypt; serializeRequest(context,logInfo,_LogStruct.RequestStr); Owned<IPropertyTree> pLogTreeInfo = createPTreeFromXMLString(_LogStruct.RequestStr.str(), ipt_none, ptr_none); addLogInfo(LogArray,*pLogTreeInfo.get()); return queueLog(context,_LogStruct, LogArray,pModelLogInfo); }
bool CLogThread::queueLog(IEspContext & context,const char* serviceName,int RecordsReturned, const char* logInfo) { try { Owned<IPropertyTree> pLogTreeInfo = createPTreeFromXMLString(logInfo, ipt_none, ptr_none); return queueLog(context,serviceName,RecordsReturned,*pLogTreeInfo); } catch (IException* e) { StringBuffer msg; e->errorMessage(msg); DBGLOG("Exception caught in CLogThread::queueLog: %s", msg.str()); return false; } catch (...) { DBGLOG("Unknown exception caught in CLogThread::queueLog()"); return false; } }
void createPart(const char *partname, const char *xml) { if (!partname || !*partname) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "No PackageMap Part name provided"); if (!xml || !*xml) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "No PackageMap content provided"); pmPart.setown(createPTreeFromXMLString(xml)); if (!pmPart) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "Invalid PackageMap content"); pmPart->addProp("@id", partname); StringBuffer lcPmid(pmid); pmid = lcPmid.toLowerCase().str(); fixPackageMapFileIds(pmPart, checkFlag(PKGADD_PRELOAD_ALL)); }
void createPart(const char *partname, const char *xml) { if (!partname || !*partname) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "No PackageMap Part name provided"); if (!xml || !*xml) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "No PackageMap content provided"); pmPart.setown(createPTreeFromXMLString(xml)); if (!pmPart) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "Invalid PackageMap content"); pmPart->addProp("@id", partname); StringBuffer lcPmid(pmid); pmid = lcPmid.toLowerCase().str(); Owned<IPropertyTreeIterator> iter = pmPart->getElements("Package"); ForEach(*iter) { IPropertyTree &item = iter->query(); if (checkFlag(PKGADD_PRELOAD_ALL)) item.setPropBool("@preload", true); Owned<IPropertyTreeIterator> superFiles = item.getElements("SuperFile"); ForEach(*superFiles) { IPropertyTree &superFile = superFiles->query(); StringBuffer lc(superFile.queryProp("@id")); const char *id = lc.toLowerCase().str(); if (*id == '~') id++; superFile.setProp("@id", id); Owned<IPropertyTreeIterator> subFiles = superFile.getElements("SubFile"); ForEach(*subFiles) { IPropertyTree &subFile = subFiles->query(); id = subFile.queryProp("@value"); if (id && *id == '~') { StringAttr value(id+1); subFile.setProp("@value", value.get()); } } } } }
virtual int processCMD() { loadServiceDef(); StringBuffer xml("<esdl>"); Owned<IEsdlDefObjectIterator> structs = cmdHelper.esdlDef->getDependencies( optService.get(), optMethod.get(), ESDLOPTLIST_DELIMITER, 0, nullptr, 0 ); cmdHelper.defHelper->toXML(*structs, xml, 0, NULL, 0); xml.append("</esdl>"); Owned<IPropertyTree> depTree = createPTreeFromXMLString(xml, ipt_ordered); removeEclHidden(depTree); toXML(depTree, xml.clear()); StringBuffer monTemplate; createMonitoringTemplate(monTemplate, depTree, optMethod); VStringBuffer templatefile("monitor_template_%s.xml", optMethod.str()); saveAsFile(".", templatefile, monTemplate); return 0; }
bool CESPServerLoggingAgent::getTransactionSeed(StringBuffer& soapreq, int& statusCode, StringBuffer& statusMessage, StringBuffer& seedID) { StringBuffer status, response; if (!sendHTTPRequest(soapreq, response, status) || !response.length() || !status.length()) throw MakeStringException(EspLoggingErrors::GetTransactionSeedFailed, "Failed to send Transaction Seed request to %s", serverUrl.str()); if (!strieq(status, "200 OK")) throw MakeStringException(EspLoggingErrors::GetTransactionSeedFailed, "%s", status.str()); Owned<IPropertyTree> pTree = createPTreeFromXMLString(response.str()); if (!pTree) throw MakeStringException(EspLoggingErrors::GetTransactionSeedFailed, "Failed to read response from %s", serverUrl.str()); statusCode = pTree->getPropInt("soap:Body/GetTransactionSeedResponse/StatusCode"); statusMessage.set(pTree->queryProp("soap:Body/GetTransactionSeedResponse/StatusMessage")); seedID.set(pTree->queryProp("soap:Body/GetTransactionSeedResponse/SeedId")); if (statusCode || !seedID.length()) throw MakeStringException(EspLoggingErrors::GetTransactionSeedFailed, "Failed to get Transaction Seed from %s", serverUrl.str()); return true; }
IPropertyTree* RemoteXmlEclRepository::getModules(timestamp_t from) { StringBuffer modNames; IPropertyTree* repositoryTree = 0; try { repository.getModules(modNames, user, from); repositoryTree = createPTreeFromXMLString(modNames.str(), ipt_caseInsensitive); } catch(IException *e) { logException(e); e->Release(); } catch (...) { logException(NULL); } return repositoryTree; }
void doStuff() { Owned<IRemoteConnection> conn = querySDS().connect("/Orbit", myProcessSession(), RTM_LOCK_WRITE|RTM_CREATE_QUERY, DALI_TIMEOUT); IPropertyTree *root = conn->queryRoot(); StringBuffer s; if (root->getProp("TestBranch1",s)) { printf("TestBranch1: read %s\n",s.str()); } else { // save as string printf("TestBranch1: set (as string)\n",s.str()); root->setProp("TestBranch1",MyTestXML); } MemoryBuffer m; if (root->getPropBin("TestBranch2",m)) { m.append((byte)0); // add a NULL to returned data const char *str = m.toByteArray(); printf("TestBranch2: read %s\n",str); } else { // save as raw binary printf("TestBranch2: set (as blob)\n",s.str()); root->setPropBin("TestBranch2",strlen(MyTestXML),MyTestXML); // include NULL } IPropertyTree *br3 = root->queryPropTree("TestBranch3"); if (br3) { printf("read TestBranch3 as tree\n"); printf("Hello = %s\n",br3->queryProp("Hello")); int n = br3->getPropInt("Bye/@num"); // update printf("Bye num = %d\n",n); br3->setPropInt("Bye/@num",n+1); } else { // save as tree printf("TestBranch3: set (as tree)\n",s.str()); br3 = createPTreeFromXMLString(MyTestXML); // parses and creates object tree root->setPropTree("TestBranch3", br3); } }
size32_t getMaxRequestEntityLength(EclCmdCommon &cmd) { if(cmd.optServer.isEmpty()) throw MakeStringException(-1, "Server IP not specified"); EclCmdURL url("?config_", cmd.optServer, cmd.optPort, cmd.optSSL); Owned<IHttpClientContext> httpCtx = getHttpClientContext(); StringBuffer request; //empty StringBuffer response; StringBuffer status; Owned<IHttpClient> httpclient = httpCtx->createHttpClient(NULL, url); if (cmd.optUsername.length()) httpclient->setUserID(cmd.optUsername); if (cmd.optPassword.length()) httpclient->setPassword(cmd.optPassword); if (0 > httpclient->sendRequest("GET", NULL, request, response, status) || !response.length() || strncmp("200", status, 3)) throw MakeStringException(-1, "Error checking ESP configuration: %s:%s %s", cmd.optServer.str(), cmd.optPort.str(), status.str()); Owned<IPropertyTree> config = createPTreeFromXMLString(response); return config->getPropInt("Software[1]/EspProcess[1]/EspProtocol[@type='http_protocol'][1]/@maxRequestEntityLength"); }
void CEnvGen::addUpdateTaskFromFile(const char * inFile) { Owned<IPropertyTree> inPTree; if ((String(inFile).toLowerCase())->endsWith(".json")) { StringBuffer sbFile; sbFile.loadFile(inFile); inPTree.setown(createPTreeFromJSONString(sbFile.str())); } else { inPTree.setown(createPTreeFromXMLFile(inFile)); } // add Config attributies to params IPropertyTree *pCfg = m_params->queryPropTree("Config"); assert(pCfg); Owned<IAttributeIterator> attrIter = inPTree->getAttributes(); ForEach(*attrIter) { const char* propName = attrIter->queryName(); if (!(*propName)) continue; pCfg->setProp(propName, attrIter->queryValue()); } // add Tasks to params Owned<IPropertyTreeIterator> taskIter = inPTree->getElements("Task"); ForEach(*taskIter) { IPropertyTree* task = &taskIter->query(); StringBuffer sb; toXML(task, sb); pCfg->addPropTree("Task", createPTreeFromXMLString(sb.str())); } }
IHpccPackageMap *createPackageMapFromXml(const char *xml, const char *queryset, const char *id) { Owned<IPropertyTree> t = createPTreeFromXMLString(xml); return createPackageMapFromPtree(t, queryset, id); }
bool QueryHelper::doit(FILE * fp) { Owned<IClientWUCreateRequest> creq = wuclient->createWUCreateRequest(); Owned<IClientWUCreateResponse> cresp = wuclient->WUCreate(creq); const IMultiException* excep = &cresp->getExceptions(); if(excep != NULL && excep->ordinality() > 0) { StringBuffer msg; excep->errorMessage(msg); printf("%s\n", msg.str()); return false; } IConstECLWorkunit* wu = &cresp->getWorkunit(); if(!wu) { printf("can't create workunit\n"); return false; } Owned<IClientWUUpdateRequest> ureq = wuclient->createWUUpdateRequest(); ureq->setWuid(wu->getWuid()); // Make a workUnit StringBuffer jobname; if(globals->hasProp("jobname")) jobname.append(globals->queryProp("jobname")); StringBuffer ecl; if (globals->getProp("ecl", ecl)) { if (ecl.length() && ecl.charAt(0)=='@') { StringBuffer filename(ecl.str()+1); ecl.clear().loadFile(filename); if (jobname.length() == 0) splitFilename(filename, NULL, NULL, &jobname, NULL); } ureq->setQueryText(ecl.str()); } else if (globals->hasProp("main")) ureq->setQueryMainDefinition(globals->queryProp("main")); else if (globals->hasProp("attr")) ureq->setQueryText(globals->queryProp("attr")); if (globals->getPropInt("compileOnly", 0)!=0) ureq->setAction(WUActionCompile); if (jobname.length()) ureq->setJobname(jobname); IArrayOf<IEspDebugValue> dvals; IArrayOf<IEspApplicationValue> avals; StringBuffer xmlParams; Owned<IPropertyIterator> it = globals->getIterator(); bool xmlSeen = false; ForEach(*it) { const char * key = it->getPropKey(); if (key && strlen(key)>1) { if(key[0] == '-') { if (key[1] == 'f') { Owned<IEspDebugValue> dval = createDebugValue(); dval->setName(&key[2]); dval->setValue(globals->queryProp(key)); dvals.append(*dval.getLink()); } //All other options are ignored. } else if(key[0] == '_') { Owned<IEspApplicationValue> aval = createApplicationValue(); aval->setApplication("eclplus"); aval->setName(&key[1]); aval->setValue(globals->queryProp(key)); avals.append(*aval.getLink()); } else if(key[0] == '/') { if (xmlSeen) throw MakeStringException(0, "query option must not be used with stored or /, and cannot appear more than once"); // The / form is expected to be used for scalars, so xmlEncode is appropriate. // To pass sets or datasets, use the xml= version xmlParams.appendf("<%s>", &key[1]); encodeXML(globals->queryProp(key), xmlParams); xmlParams.appendf("</%s>", &key[1]); } else if(stricmp(key, "stored")==0) { if (xmlSeen) throw MakeStringException(0, "query option must not be used with stored or /, and cannot appear more than once"); const char *xml = globals->queryProp(key); try { Owned<IPropertyTree> checkValid = createPTreeFromXMLString(xml); } catch (IException *E) { StringBuffer msg; E->errorMessage(msg); E->Release(); throw MakeStringException(0, "Invalid xml: %s", msg.str()); } xmlParams.append(xml); } else if(stricmp(key, "query")==0) { if (xmlSeen || xmlParams.length()) throw MakeStringException(0, "query option must not be used with stored or /, and cannot appear more than once"); xmlSeen = true; StringBuffer xml; if (!globals->getProp(key, xml)) throw MakeStringException(0, "Invalid value for query= parameter"); if (xml.length() && xml.charAt(0)=='@') { StringBuffer filename(xml.str()+1); xml.clear().loadFile(filename); } try { Owned<IPropertyTree> checkValid = createPTreeFromXMLString(xml); } catch (IException *E) { StringBuffer msg; E->errorMessage(msg); E->Release(); throw MakeStringException(0, "Invalid xml: %s", msg.str()); } xmlParams.append(xml); } } } if(dvals.length() > 0) ureq->setDebugValues(dvals); if(avals.length() > 0) ureq->setApplicationValues(avals); if (xmlParams.length()) { if (!xmlSeen) { xmlParams.insert(0, "<Query>"); xmlParams.append("</Query>"); } ureq->setXmlParams(xmlParams); } Owned<IClientWUUpdateResponse> uresp = wuclient->WUUpdate(ureq); const IMultiException* uexcep = &uresp->getExceptions(); if(uexcep != NULL && uexcep->ordinality() > 0) { StringBuffer msg; uexcep->errorMessage(msg); printf("%s\n", msg.str()); return false; } // Execute it return doSubmitWorkUnit(fp, wu->getWuid(), globals->queryProp("cluster")); }
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); }
void MessageGenerator::genNonRoxieMessage(const char* method, const char* templatemsg, StringBuffer& message) { if (m_soapWrap) message.appendf("<?xml version=\"1.0\" encoding=\"utf-8\"?>" "%s<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" " xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"" " xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"" " xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/04/secext\"><soap:Body>%s", LT, LT); const char* element = method; IPTree* schema = NULL; if(m_schemaType == WSDL) schema = m_schemaTree->queryPropTree("types/xsd:schema"); else schema = m_schemaTree; if (schema) { const char* ns = schema->queryProp("@targetNamespace"); if(ns && ns && !m_ecl2esp) message.appendf(" <%s xmlns=\"%s\">", element, ns); else message.appendf(" <%s>", element); Owned<IXmlSchema> s = createXmlSchemaFromPTree(LINK(schema)); if (s.get()) { IXmlType* type = s->queryElementType(element); if (type) { StringStack parent; if (templatemsg && *templatemsg) { Owned<IPropertyTree> tmplat = createPTreeFromXMLString(templatemsg); if(!tmplat.get()) throw MakeStringException(-1, "can't generate property tree from input, please make sure it's valid xml."); IPropertyTree* tmp = NULL; if (strcmp(tmplat->queryName(),element)==0) tmp = tmplat; else tmp = tmplat->queryPropTree(VStringBuffer("//%s",element)); if (tmp) doType(parent,2, element, type, tmp, message); else doType(parent,2, element, type, message); } else doType(parent,2, element, type, message); } } message.appendf("</%s>%s", element, LT); } if (m_soapWrap) message.append("</soap:Body></soap:Envelope>"); }
void CXmlScope::loadXML(const char * text, const char * element) { IPropertyTree * ptree = createPTreeFromXMLString(text, ipt_caseInsensitive); root->setPropTree(element, ptree); }
void SWEspProcess::addBinding(IPropertyTree *parent, IPropertyTree * attrs) { StringBuffer xpath; xpath.clear().append("Attribute[@name='name']/@value"); const char * bindingName = attrs->queryProp(xpath); if (!bindingName || !(*bindingName)) throw MakeStringException(CfgEnvErrorCode::InvalidParams, "Miss esp binding name in adding binding"); xpath.clear().append("Attribute[@name='service']/@value"); const char * serviceName = attrs->queryProp(xpath); if (!serviceName || !(*serviceName)) throw MakeStringException(CfgEnvErrorCode::InvalidParams, "Miss esp service name in adding binding"); IPropertyTree * envTree = m_envHelper->getEnvTree(); xpath.clear().appendf(XML_TAG_SOFTWARE "/" XML_TAG_ESPSERVICE "[@name=\"%s\"]", serviceName); IPropertyTree * pEspService = envTree->queryPropTree(xpath.str()); if (!pEspService) { const char* task="<Task category=\"Software\" component=\"esdl\" key=\"dynamicesdl\" operation=\"add\"/>"; Owned<IPropertyTree> taskPT = createPTreeFromXMLString(task); ((SWEspService*)m_envHelper->getEnvSWComp("DynamicESDL"))->add(taskPT); pEspService = envTree->queryPropTree(xpath.str()); assert(pEspService); // throw MakeStringException(CfgEnvErrorCode::InvalidParams, "Can't find EspService with name %s.", serviceName); } IPropertyTree *pBinding = createPTree(XML_TAG_ESPBINDING); if (attrs) updateNode(pBinding, attrs, NULL); // check attributes if (!(pBinding->queryProp(XML_ATTR_PROTOCOL))) pBinding->addProp(XML_ATTR_PROTOCOL, "http"); const char* protocol = pBinding->queryProp(XML_ATTR_PROTOCOL); if (!stricmp(protocol, "https")) xpath.clear().append("Properties/@defaultSecurePort"); else xpath.clear().append("Properties/@defaultPort"); const char* defaultPort = pEspService->queryProp(xpath.str()); const char* port = pBinding->queryProp(XML_ATTR_PORT); if (!port || !(*port)) { pBinding->addProp(XML_ATTR_PORT, defaultPort); } const char* defaultForPort = pBinding->queryProp("@defaultForPort"); if (!stricmp(defaultPort, pBinding->queryProp(XML_ATTR_PORT))) { if (!defaultForPort || !(*defaultForPort) || !defaultForPort) pBinding->setProp("@defaultForPort", "true"); } else { if (!defaultForPort || !(*defaultForPort) || defaultForPort) pBinding->setProp("@defaultForPort", "true"); } if (!(pBinding->queryProp("@defaultServiceVersion"))) pBinding->addProp("@defaultServiceVersion", ""); if (!(pBinding->queryProp("@resourcesBasedn"))) pBinding->addProp("@resourcesBasedn", pEspService->queryProp("Properties/@defaultResourcesBasedn")); if (!(pBinding->queryProp(XML_ATTR_TYPE))) pBinding->addProp(XML_ATTR_TYPE, ""); if (!(pBinding->queryProp("@workunitsBasedn"))) pBinding->addProp("@workunitsBasedn", "ou=workunits,ou=ecl"); if (!(pBinding->queryProp("@wsdlServiceAddress"))) pBinding->addProp("@wsdlServiceAddress", ""); // Add AuthenticateFeature Owned<IPropertyTreeIterator> afIter = pEspService->getElements("Properties/AuthenticateFeature"); ForEach (*afIter) { pBinding->addPropTree("AuthenticateFeature", m_envHelper->clonePTree(&afIter->query())); } // Add Authenticate Owned<IPropertyTreeIterator> authIter = pEspService->getElements("Properties/Authenticate"); ForEach (*authIter) { pBinding->addPropTree("Authenticate", m_envHelper->clonePTree(&authIter->query())); } parent->addPropTree(XML_TAG_ESPBINDING, pBinding); }
bool CLogThread::queueLog(IEspContext & context,const char* serviceName,int RecordsReturned,IArrayOf<IEspLogInfo>& LogArray, StringBuffer& logInfo) { Owned<IPropertyTree> pLogTreeInfo = createPTreeFromXMLString(logInfo, ipt_none, ptr_none); return queueLog(context,serviceName,RecordsReturned,LogArray, *pLogTreeInfo.get()); }
int doSendQuery(const char * ip, unsigned port, const char * base) { Owned<ISocket> socket; Owned<ISecureSocketContext> secureContext; __int64 starttime, endtime; StringBuffer ipstr; try { if (strcmp(ip, ".")==0) ip = GetCachedHostName(); else { const char *dash = strchr(ip, '-'); if (dash && isdigit(dash[1]) && dash>ip && isdigit(dash[-1])) { if (persistConnections) UNIMPLEMENTED; const char *startrange = dash-1; while (isdigit(startrange[-1])) startrange--; char *endptr; unsigned firstnum = atoi(startrange); unsigned lastnum = strtol(dash+1, &endptr, 10); if (lastnum > firstnum) { static unsigned counter; static CriticalSection counterCrit; CriticalBlock b(counterCrit); ipstr.append(startrange - ip, ip).append((counter++ % (lastnum+1-firstnum)) + firstnum).append(endptr); ip = ipstr.str(); printf("Sending to %s\n", ip); } } } starttime= get_cycles_now(); if (persistConnections) { if (!persistSocket) { SocketEndpoint ep(ip,port); persistSocket.setown(ISocket::connect_timeout(ep, 1000)); if (useSSL) { #ifdef _USE_OPENSSL if (!persistSecureContext) persistSecureContext.setown(createSecureSocketContext(ClientSocket)); persistSSock.setown(persistSecureContext->createSecureSocket(persistSocket.getClear())); persistSSock->secure_connect(); persistSocket.setown(persistSSock.getClear()); #else throw MakeStringException(-1, "OpenSSL disabled in build"); #endif } } socket = persistSocket; } else { SocketEndpoint ep(ip,port); socket.setown(ISocket::connect_timeout(ep, 100000)); if (useSSL) { #ifdef _USE_OPENSSL secureContext.setown(createSecureSocketContext(ClientSocket)); Owned<ISecureSocket> ssock = secureContext->createSecureSocket(socket.getClear()); ssock->secure_connect(); socket.setown(ssock.getClear()); #else throw MakeStringException(1, "OpenSSL disabled in build"); #endif } } } catch(IException * e) { pexception("failed to connect to server", e); return 1; } StringBuffer fullQuery; bool useHTTP = forceHTTP || strstr(base, "<soap:Envelope") != NULL; if (useHTTP) { StringBuffer newQuery; Owned<IPTree> p = createPTreeFromXMLString(base, ipt_none, ptr_none); const char *queryName = p->queryName(); if ((stricmp(queryName, "envelope") != 0) && (stricmp(queryName, "envelope") != 0)) { if (queryNameOverride.length()) queryName = queryNameOverride; newQuery.appendf("<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><Body><%sRequest>", queryName); Owned<IPTreeIterator> elements = p->getElements("./*"); ForEach(*elements) { IPTree &elem = elements->query(); toXML(&elem, newQuery, 0, XML_SingleQuoteAttributeValues); } newQuery.appendf("</%sRequest></Body></Envelope>", queryName); base = newQuery.str(); } // note - don't support queryname override unless original query is xml fullQuery.appendf("POST /doc HTTP/1.0\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %d\r\n\r\n", (int) strlen(base)).append(base); } else { if (sendToSocket)
int readResults(ISocket * socket, bool readBlocked, bool useHTTP, StringBuffer &result, const char *query, size32_t queryLen) { if (readBlocked) socket->set_block_mode(BF_SYNC_TRANSFER_PULL,0,60*1000); MemoryBuffer remoteReadCursorMb; unsigned len; bool is_status; bool isBlockedResult; for (;;) { if (delay) MilliSleep(delay); is_status = false; isBlockedResult = false; try { if (useHTTP) len = 0x10000; else if (readBlocked) len = socket->receive_block_size(); else { socket->read(&len, sizeof(len)); _WINREV(len); } } catch(IException * e) { if (manyResults) showMessage("End of result multiple set\n"); else pexception("failed to read len data", e); e->Release(); return 1; } if (len == 0) { if (manyResults) { showMessage("----End of result set----\n"); continue; } break; } bool isSpecial = false; bool pluginRequest = false; bool dataBlockRequest = false; bool remoteReadRequest = false; if (len & 0x80000000) { unsigned char flag; isSpecial = true; socket->read(&flag, sizeof(flag)); switch (flag) { case '-': if (echoResults) fputs("Error:", stdout); if (saveResults && trace != NULL) fputs("Error:", trace); break; case 'D': showMessage("request for datablock\n"); dataBlockRequest = true; break; case 'P': showMessage("request for plugin\n"); pluginRequest = true; break; case 'S': if (showStatus) showMessage("Status:"); is_status=true; break; case 'T': showMessage("Timing:\n"); break; case 'X': showMessage("---Compound query finished---\n"); return 1; case 'R': isBlockedResult = true; break; case 'J': remoteReadRequest = true; break; } len &= 0x7FFFFFFF; len--; // flag already read } MemoryBuffer mb; mb.setEndian(__BIG_ENDIAN); char *mem = (char *)mb.reserveTruncate(len+1); char * t = mem; size32_t sendlen = len; t[len]=0; try { if (useHTTP) { try { socket->read(t, 0, len, sendlen); } catch (IException *E) { if (E->errorCode()!= JSOCKERR_graceful_close) throw; E->Release(); break; } if (!sendlen) break; } else if (readBlocked) socket->receive_block(t, len); else socket->read(t, len); } catch(IException * e) { pexception("failed to read data", e); e->Release(); return 1; } if (pluginRequest) { //Not very robust! A poor man's implementation for testing... StringBuffer dllname, libname; const char * dot = strchr(t, '.'); dllname.append("\\edata\\bin\\debug\\").append(t); libname.append("\\edata\\bin\\debug\\").append(dot-t,t).append(".lib"); sendFile(dllname.str(), socket); sendFile(libname.str(), socket); } else if (dataBlockRequest) { //Not very robust! A poor man's implementation for testing... offset_t offset; mb.read(offset); sendFileChunk((const char *)mb.readDirect(offset), offset, socket); } else if (remoteReadRequest) { Owned<IPropertyTree> requestTree = createPTreeFromJSONString(queryLen, query); Owned<IPropertyTree> responseTree; // used if response is xml or json const char *outputFmtStr = requestTree->queryProp("format"); const char *response = nullptr; if (!outputFmtStr || strieq("xml", outputFmtStr)) { response = (const char *)mb.readDirect(len); responseTree.setown(createPTreeFromXMLString(len, response)); } else if (strieq("json", outputFmtStr)) { response = (const char *)mb.readDirect(len); responseTree.setown(createPTreeFromJSONString(len, response)); } unsigned cursorHandle; if (responseTree) cursorHandle = responseTree->getPropInt("cursor"); else mb.read(cursorHandle); bool retrySend = false; if (cursorHandle) { PROGLOG("Got handle back: %u; len=%u", cursorHandle, len); StringBuffer xml; if (responseTree) { if (echoResults && response) { fputs(response, stdout); fflush(stdout); } if (!responseTree->getPropBin("cursorBin", remoteReadCursorMb.clear())) break; } else { size32_t dataLen; mb.read(dataLen); if (!dataLen) break; const void *rowData = mb.readDirect(dataLen); // JCSMORE - output binary row data? // cursor size32_t cursorLen; mb.read(cursorLen); if (!cursorLen) break; const void *cursor = mb.readDirect(cursorLen); memcpy(remoteReadCursorMb.clear().reserveTruncate(cursorLen), cursor, cursorLen); } if (remoteStreamForceResend) cursorHandle = NotFound; // fake that it's a handle dafilesrv doesn't know about Owned<IPropertyTree> requestTree = createPTree(); requestTree->setPropInt("cursor", cursorHandle); // Only the handle is needed for continuation, but this tests the behaviour of some clients which may send cursor per request (e.g. to refresh) if (remoteStreamSendCursor) requestTree->setPropBin("cursorBin", remoteReadCursorMb.length(), remoteReadCursorMb.toByteArray()); requestTree->setProp("format", outputFmtStr); StringBuffer requestStr; toJSON(requestTree, requestStr); #ifdef _DEBUG fputs(requestStr, stdout); #endif sendlen = requestStr.length(); _WINREV(sendlen); try { if (!rawSend && !useHTTP) socket->write(&sendlen, sizeof(sendlen)); socket->write(requestStr.str(), requestStr.length()); } catch (IJSOCK_Exception *e) { retrySend = true; EXCLOG(e, nullptr); e->Release(); } } else // dafilesrv didn't know who I was, resent query + serialized cursor retrySend = true; if (retrySend) { PROGLOG("Retry send for handle: %u", cursorHandle); requestTree->setPropBin("cursorBin", remoteReadCursorMb.length(), remoteReadCursorMb.toByteArray()); StringBuffer requestStr; toJSON(requestTree, requestStr); PROGLOG("requestStr = %s", requestStr.str()); sendlen = requestStr.length(); _WINREV(sendlen); if (!rawSend && !useHTTP) socket->write(&sendlen, sizeof(sendlen)); socket->write(requestStr.str(), requestStr.length()); } } else { if (isBlockedResult) { t += 8; t += strlen(t)+1; sendlen -= (t - mem); } if (echoResults && (!is_status || showStatus)) { fwrite(t, sendlen, 1, stdout); fflush(stdout); } if (!is_status) result.append(sendlen, t); } if (abortAfterFirst) return 0; } return 0; }
HQL_API IXmlScope* loadXML(const char* xml) { assertex(xml); IPropertyTree * ptree = createPTreeFromXMLString(xml, ipt_caseInsensitive); return ptree ? new CXmlScope(ptree, NULL) : NULL; }
void addPackageMapInfo(const char *xml, StringArray &filesNotFound, const char *process, const char *target, const char *pmid, const char *packageSetName, const char *lookupDaliIp, const char *srcCluster, const char *prefix, bool activate, bool overWrite, IUserDescriptor* userdesc, bool allowForeignFiles, bool preloadAll) { if (!xml || !*xml) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "PackageMap info not provided"); if (srcCluster && *srcCluster) { if (!isProcessCluster(lookupDaliIp, srcCluster)) throw MakeStringException(PKG_INVALID_CLUSTER_TYPE, "Process cluster %s not found on %s DALI", srcCluster, lookupDaliIp ? lookupDaliIp : "local"); } Owned<IConstWUClusterInfo> clusterInfo = getTargetClusterInfo(target); if (!clusterInfo) throw MakeStringException(PKG_TARGET_NOT_DEFINED, "Could not find information about target cluster %s ", target); Owned<IPropertyTree> pmTree = createPTreeFromXMLString(xml); if (!pmTree) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "Invalid PackageMap info"); StringBuffer lcPmid(pmid); pmid = lcPmid.toLowerCase().str(); pmTree->setProp("@id", pmid); Owned<IPropertyTreeIterator> iter = pmTree->getElements("Package"); ForEach(*iter) { IPropertyTree &item = iter->query(); if (preloadAll) item.setPropBool("@preload", true); Owned<IPropertyTreeIterator> superFiles = item.getElements("SuperFile"); ForEach(*superFiles) { IPropertyTree &superFile = superFiles->query(); StringBuffer lc(superFile.queryProp("@id")); const char *id = lc.toLowerCase().str(); if (*id == '~') id++; superFile.setProp("@id", id); Owned<IPropertyTreeIterator> subFiles = superFile.getElements("SubFile"); ForEach(*subFiles) { IPropertyTree &subFile = subFiles->query(); id = subFile.queryProp("@value"); if (id && *id == '~') { StringAttr value(id+1); subFile.setProp("@value", value.get()); } } } } VStringBuffer xpath("PackageMap[@id='%s']", pmid); Owned<IRemoteConnection> globalLock = querySDS().connect("/PackageMaps", myProcessSession(), RTM_LOCK_WRITE|RTM_CREATE_QUERY, SDS_LOCK_TIMEOUT); IPropertyTree *packageMaps = globalLock->queryRoot(); IPropertyTree *pmExisting = packageMaps->queryPropTree(xpath); xpath.appendf("[@querySet='%s']", target); Owned<IPropertyTree> pkgSet = getPkgSetRegistry(process, false); IPropertyTree *psEntry = pkgSet->queryPropTree(xpath); if (!overWrite && (psEntry || pmExisting)) throw MakeStringException(PKG_NAME_EXISTS, "Package name %s already exists, either delete it or specify overwrite", pmid); cloneFileInfoToDali(filesNotFound, pmTree, lookupDaliIp, clusterInfo, srcCluster, prefix, overWrite, userdesc, allowForeignFiles); if (pmExisting) packageMaps->removeTree(pmExisting); packageMaps->addPropTree("PackageMap", pmTree.getClear()); if (!psEntry) { psEntry = pkgSet->addPropTree("PackageMap", createPTree("PackageMap")); psEntry->setProp("@id", pmid); psEntry->setProp("@querySet", target); } makePackageActive(pkgSet, psEntry, target, activate); }