From 1d0acb246783f1baacd70e206156f2d88b4a75ab Mon Sep 17 00:00:00 2001 From: Tim Klemm Date: Wed, 20 Sep 2023 09:45:10 -0400 Subject: [PATCH] additional cleanup --- esp/services/esdl_svc_engine/esdl_binding.cpp | 76 +++++++++---------- esp/services/esdl_svc_engine/esdl_binding.hpp | 21 ++--- 2 files changed, 41 insertions(+), 56 deletions(-) diff --git a/esp/services/esdl_svc_engine/esdl_binding.cpp b/esp/services/esdl_svc_engine/esdl_binding.cpp index 3776c20367c..8e2f11eab7d 100755 --- a/esp/services/esdl_svc_engine/esdl_binding.cpp +++ b/esp/services/esdl_svc_engine/esdl_binding.cpp @@ -1393,16 +1393,21 @@ EsdlServiceImpl::IUpdatableGateway* EsdlServiceImpl::createInlineGateway(const I return new CLegacyUrlGateway(gw, gwName, gwUrl); } -EsdlServiceImpl::IGatewayUpdater* EsdlServiceImpl::getGatewayUpdater(IPTree& gw, const UpdatableGateways& updatables, GatewayUpdaters& updaters, Secrets& secrets) const +void EsdlServiceImpl::applyGatewayUpdates(IPTreeIterator& gwIt, const UpdatableGateways& updatables, GatewayUpdaters& updaters, Secrets& secrets) const { - const char* name = gw.queryProp("@name"); - if (isEmptyString(name)) - return nullptr; - std::string key(name); - UpdatableGateways::const_iterator it = updatables.find(key); - if (updatables.end() == it) - return nullptr; - return it->second->getUpdater(updaters, secrets); + ForEach(gwIt) + { + IPTree& gw = gwIt.query(); + const char* name = gw.queryProp("@name"); + if (isEmptyString(name)) + continue; + UpdatableGateways::const_iterator ugIt = updatables.find(name); + if (updatables.end() == ugIt) + continue; + Owned updater(ugIt->second->getUpdater(updaters, secrets)); + if (updater) + updater->updateGateway(gw, "allowPublishedGatewayUsage"); + } } void EsdlServiceImpl::transformGatewaysConfig( IPTreeIterator* inputs, IPropertyTree* forRoxie, const char* altElementName ) const @@ -1776,27 +1781,22 @@ void EsdlServiceImpl::prepareFinalRequest(IEspContext &context, reqProcessed.append("<").append(tgtQueryName).append(">"); reqProcessed.appendf("<_TransactionId>%s", context.queryTransactionID()); - GatewaysCache::const_iterator mit = m_methodGatewaysCache.find(mthName); + GatewaysCache::const_iterator mgcIt = m_methodGatewaysCache.find(mthName); + Owned gwIt; GatewayUpdaters updaters; Secrets secrets; if (tgtctx) { - // The target context is based on a copy of the target configuration. One copy per - // transaction. It will have already been copied into the script context, so local - // secret and inline URL resolutions can be made in the given property tree. - if (mit != m_methodGatewaysCache.end() && !mit->second.targetContext.empty()) + if (mgcIt != m_methodGatewaysCache.end() && !mgcIt->second.targetContext.empty()) { + // The target context is based on a copy of the target configuration. One copy + // per transaction. It will have already been copied into the script context, + // so gateway updates can be made in the given property tree. IPTree* ctxGateways = tgtctx->queryBranch("Gateways"); if (ctxGateways) { - Owned it(ctxGateways->getElements("Gateway")); - ForEach(*it) - { - IPTree& gw = it->query(); - Owned updater(getGatewayUpdater(gw, mit->second.targetContext, updaters, secrets)); - if (updater) - updater->updateGateway(gw, "allowPublishedGatewayUsage"); - } + gwIt.setown(ctxGateways->getElements("Gateway")); + applyGatewayUpdates(*gwIt, mgcIt->second.targetContext, updaters, secrets); } } toXML(tgtctx.get(), reqProcessed); @@ -1812,34 +1812,28 @@ void EsdlServiceImpl::prepareFinalRequest(IEspContext &context, StringBuffer xpath(cfgGateways->queryProp("@legacyTransformTarget")); if (!xpath.isEmpty()) { - Owned it; - if (mit != m_methodGatewaysCache.end() && !mit->second.legacyTransform.empty()) + if (mgcIt != m_methodGatewaysCache.end() && !mgcIt->second.legacyTransform.empty()) { - // The target configuration is shared by all transactions. Local secret and - // inline URL resolutions must be made to a copy of the gateways, to avoid - // contaminating values used in subsequent transactions. + // The target configuration is shared by all transactions.gateway updates + // must be made to a copy of the gateways, to avoid contaminating values + // used in subsequent transactions. Owned copy(createPTreeFromIPT(cfgGateways)); - it.setown(copy->getElements("Gateway")); - ForEach(*it) - { - IPTree& gw = it->query(); - Owned updater(getGatewayUpdater(gw, mit->second.legacyTransform, updaters, secrets)); - if (updater) - updater->updateGateway(gw, "allowPublishedGatewayUsage"); - } + gwIt.setown(copy->getElements("Gateway")); + applyGatewayUpdates(*gwIt, mgcIt->second.legacyTransform, updaters, secrets); } else - it.setown(cfgGateways->getElements("Gateway")); - + gwIt.setown(cfgGateways->getElements("Gateway")); + Owned gws = createPTree("gateways", 0); + StringBuffer rowName(cfgGateways->queryProp("@legacyRowName")); + if (rowName.isEmpty()) + rowName.append("row"); + transformGatewaysConfig(gwIt, gws, rowName); + // Temporarily add the closing tag so we have valid // XML to transform the gateways Owned soapTree = createPTreeFromXMLString(reqProcessed.append(""), ipt_ordered); - StringBuffer rowName(cfgGateways->queryProp("@legacyRowName")); - if (rowName.isEmpty()) - rowName.append("row"); - transformGatewaysConfig(it, gws, rowName); xpath.replaceString("{$query}", tgtQueryName); xpath.replaceString("{$method}", mthName); xpath.replaceString("{$service}", srvdef.queryName()); diff --git a/esp/services/esdl_svc_engine/esdl_binding.hpp b/esp/services/esdl_svc_engine/esdl_binding.hpp index 384f74f7711..1c0149d676c 100755 --- a/esp/services/esdl_svc_engine/esdl_binding.hpp +++ b/esp/services/esdl_svc_engine/esdl_binding.hpp @@ -494,23 +494,14 @@ class EsdlServiceImpl : public CInterface, implements IEspService IUpdatableGateway* createInlineGateway(const IPTree& gw, const char* gwName, const char* gwUrl) const; /** - * @brief Obtain an updater instance for use with a specific gateway. - * - * - Null is returned if the gateway does not contain `@name` or `updatables` does not include - * this key. - * - A new link to an existing updater (in `updaters`) is returned if the updatable handler - * (from `updatables`) can find a match. Matching logic is an imlementation detail of the - * updatable handler. - * - A new updater is created, cached in `updaters`, and returned the first time the gateway - * is evaluated. + * @brief Update all iterated nodes, as needed. * - * @param gw - * @param updatables - * @param updaters - * @param secrets - * @return IGatewayUpdater* + * @param gwIt property tree nodes, presumed to be `Gateway` nodes, for possible updates + * @param updatables set of update handlers to be applied to nodes + * @param updaters cache of updaters used in the current transaction + * @param secrets cache of secrets used in the current transaction */ - IGatewayUpdater* getGatewayUpdater(IPTree& gw, const UpdatableGateways& updatables, GatewayUpdaters& updaters, Secrets& secrets) const; + void applyGatewayUpdates(IPTreeIterator& gwIt, const UpdatableGateways& updatables, GatewayUpdaters& updaters, Secrets& secrets) const; /** * @brief Implementation of legacy gateway transformation invoked only during preparation of