Skip to content

Commit

Permalink
OA prop validation
Browse files Browse the repository at this point in the history
  • Loading branch information
externl committed Oct 2, 2024
1 parent 96d855c commit e82f588
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 106 deletions.
64 changes: 9 additions & 55 deletions cpp/src/Ice/ObjectAdapterI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "ObjectAdapterFactory.h"
#include "ObserverMiddleware.h"
#include "PropertyNames.h"
#include "PropertyUtil.h"
#include "ReferenceFactory.h"
#include "RouterInfo.h"
#include "ServantManager.h"
Expand Down Expand Up @@ -1399,48 +1400,6 @@ ObjectAdapterI::updateLocatorRegistry(const IceInternal::LocatorInfoPtr& locator
bool
Ice::ObjectAdapterI::filterProperties(StringSeq& unknownProps)
{
static const string suffixes[] = {
"AdapterId",
"Connection.CloseTimeout",
"Connection.ConnectTimeout",
"Connection.EnableIdleCheck",
"Connection.IdleTimeout",
"Connection.InactivityTimeout",
"Connection.MaxDispatches",
"Endpoints",
"Locator",
"Locator.EncodingVersion",
"Locator.EndpointSelection",
"Locator.ConnectionCached",
"Locator.PreferSecure",
"Locator.CollocationOptimized",
"Locator.Router",
"MaxConnections",
"MessageSizeMax",
"PublishedEndpoints",
"ReplicaGroupId",
"Router",
"Router.EncodingVersion",
"Router.EndpointSelection",
"Router.ConnectionCached",
"Router.PreferSecure",
"Router.CollocationOptimized",
"Router.Locator",
"Router.Locator.EndpointSelection",
"Router.Locator.ConnectionCached",
"Router.Locator.PreferSecure",
"Router.Locator.CollocationOptimized",
"Router.Locator.LocatorCacheTimeout",
"Router.Locator.InvocationTimeout",
"Router.LocatorCacheTimeout",
"Router.InvocationTimeout",
"ProxyOptions",
"ThreadPool.Serialize",
"ThreadPool.Size",
"ThreadPool.SizeMax",
"ThreadPool.SizeWarn",
"ThreadPool.ThreadIdleTime"};

//
// Do not create unknown properties list if Ice prefix, ie Ice, Glacier2, etc
//
Expand All @@ -1458,23 +1417,18 @@ Ice::ObjectAdapterI::filterProperties(StringSeq& unknownProps)

bool noProps = true;
PropertyDict props = _instance->initializationData().properties->getPropertiesForPrefix(prefix);
for (PropertyDict::const_iterator p = props.begin(); p != props.end(); ++p)
for (const auto& prop : props)
{
bool valid = false;
for (unsigned int i = 0; i < sizeof(suffixes) / sizeof(*suffixes); ++i)
// Strip prefix from property name
string name = prop.first.substr(prefix.size());
auto property = findInPropertyArray(&IceInternal::PropertyNames::ObjectAdapterClassProps, name);
if (property)
{
string prop = prefix + suffixes[i];
if (p->first == prop)
{
noProps = false;
valid = true;
break;
}
noProps = false;
}

if (!valid && addUnknown)
else if (addUnknown)
{
unknownProps.push_back(p->first);
unknownProps.push_back(prop.first);
}
}

Expand Down
53 changes: 2 additions & 51 deletions cpp/src/Ice/Properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Ice/LoggerUtil.h"
#include "Ice/StringUtil.h"
#include "PropertyNames.h"
#include "PropertyUtil.h"

#include <cassert>
#include <fstream>
Expand All @@ -20,56 +21,6 @@ using namespace IceInternal;

namespace
{
/// Searches a property array for a property with the given key.
/// @param propertyArray The property array to search.
/// @param key The key to search for.
/// @return The property if found, nullopt otherwise.
optional<Property> searchPropertyArray(const PropertyArray* propertyArray, string_view key)
{
for (int i = 0; i < propertyArray->length; ++i)
{
auto prop = propertyArray->properties[i];

// If the key is an exact match, return the property if it's not a property class. If it is, return nullopt.
// If the key is a regex match, return the property. A property cannot have a property class and use regex.
if (key == prop.pattern)
{
if (prop.propertyClass != nullptr && prop.prefixOnly)
{
return nullopt;
}
return prop;
}
else if (prop.usesRegex && IceInternal::match(string{key}, prop.pattern))
{
return prop;
}

// If the property has a property class, check if the key is a prefix of the property.
if (prop.propertyClass)
{
auto pattern = string{prop.pattern};
// Check if the key is a prefix of the property.
// The key must be:
// - shorter than the property pattern
// - the property pattern must start with the key
// - the pattern character after the key must be a dot
if (key.length() > pattern.length() && key.find(pattern) == 0 && key[pattern.length()] == '.')
{
// Plus one to skip the dot.
string_view substring = key.substr(pattern.length() + 1);
// Check if the suffix is a valid property. If so, return it. If it's not, continue searching
// the current property array.
if (auto subProp = searchPropertyArray(prop.propertyClass, substring))
{
return subProp;
}
}
}
}

return nullopt;
}

/// Find a property in the Ice property set.
/// @param key The property name.
Expand Down Expand Up @@ -126,7 +77,7 @@ namespace
return nullopt;
}

if (auto prop = searchPropertyArray(propertyArray, key))
if (auto prop = IceInternal::findInPropertyArray(propertyArray, key))
{
return prop;
}
Expand Down
54 changes: 54 additions & 0 deletions cpp/src/Ice/PropertyUtil.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) ZeroC, Inc.

#include "PropertyUtil.h"
#include "Ice/StringUtil.h"

using namespace std;

optional<IceInternal::Property>
IceInternal::findInPropertyArray(const PropertyArray* propertyArray, string_view key)
{
for (int i = 0; i < propertyArray->length; ++i)
{
auto prop = propertyArray->properties[i];

// If the key is an exact match, return the property if it's not a property class. If it is, return nullopt.
// If the key is a regex match, return the property. A property cannot have a property class and use regex.
if (key == prop.pattern)
{
if (prop.propertyClass != nullptr && prop.prefixOnly)
{
return nullopt;
}
return prop;
}
else if (prop.usesRegex && IceInternal::match(string{key}, prop.pattern))
{
return prop;
}

// If the property has a property class, check if the key is a prefix of the property.
if (prop.propertyClass)
{
auto pattern = string{prop.pattern};
// Check if the key is a prefix of the property.
// The key must be:
// - shorter than the property pattern
// - the property pattern must start with the key
// - the pattern character after the key must be a dot
if (key.length() > pattern.length() && key.find(pattern) == 0 && key[pattern.length()] == '.')
{
// Plus one to skip the dot.
string_view substring = key.substr(pattern.length() + 1);
// Check if the suffix is a valid property. If so, return it. If it's not, continue searching
// the current property array.
if (auto subProp = findInPropertyArray(prop.propertyClass, substring))
{
return subProp;
}
}
}
}

return nullopt;
}
17 changes: 17 additions & 0 deletions cpp/src/Ice/PropertyUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) ZeroC, Inc.

#ifndef ICE_PROPERTY_UTIL_H
#define ICE_PROPERTY_UTIL_H

#include "PropertyNames.h"

namespace IceInternal
{
/// Searches a property array for a property with the given key.
/// @param propertyArray The property array to search.
/// @param key The key to search for.
/// @return The property if found, nullopt otherwise.
std::optional<Property> findInPropertyArray(const PropertyArray* propertyArray, std::string_view key);
}

#endif

0 comments on commit e82f588

Please sign in to comment.