summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_parser.h
diff options
context:
space:
mode:
authorTess Avitabile <tess.avitabile@mongodb.com>2017-08-21 15:31:06 -0400
committerTess Avitabile <tess.avitabile@mongodb.com>2017-08-25 14:16:10 -0400
commitb19f95495d1df437722e6a0c85ea5ca6f91cdd8b (patch)
treebbc5dd0a3b5868240cd6c5c97c48408e3170046f /src/mongo/db/matcher/expression_parser.h
parent529d5de71344fda500802fa4a8671c5745ad62fa (diff)
downloadmongo-b19f95495d1df437722e6a0c85ea5ca6f91cdd8b.tar.gz
SERVER-29840 Add allowed features bitmask to MatchExpressionParser::parse
Diffstat (limited to 'src/mongo/db/matcher/expression_parser.h')
-rw-r--r--src/mongo/db/matcher/expression_parser.h49
1 files changed, 41 insertions, 8 deletions
diff --git a/src/mongo/db/matcher/expression_parser.h b/src/mongo/db/matcher/expression_parser.h
index 621a35e4451..75ed1a60dd7 100644
--- a/src/mongo/db/matcher/expression_parser.h
+++ b/src/mongo/db/matcher/expression_parser.h
@@ -37,6 +37,7 @@
#include "mongo/db/matcher/expression_tree.h"
#include "mongo/db/matcher/expression_type.h"
#include "mongo/db/matcher/extensions_callback.h"
+#include "mongo/db/matcher/extensions_callback_noop.h"
#include "mongo/db/pipeline/expression_context.h"
#include "mongo/stdx/functional.h"
@@ -84,6 +85,20 @@ enum class PathAcceptingKeyword {
class MatchExpressionParser {
public:
/**
+ * Features allowed in match expression parsing.
+ */
+ enum AllowedFeatures {
+ kText = 1,
+ kGeoNear = 1 << 1,
+ kJavascript = 1 << 2,
+ kExpr = 1 << 3,
+ };
+ using AllowedFeatureSet = unsigned long long;
+ static constexpr AllowedFeatureSet kBanAllSpecialFeatures = 0;
+ static constexpr AllowedFeatureSet kAllowAllSpecialFeatures =
+ std::numeric_limits<unsigned long long>::max();
+
+ /**
* Constant double representation of 2^63.
*/
static const double kLongLongMaxPlusOneAsDouble;
@@ -104,12 +119,18 @@ public:
*/
static StatusWithMatchExpression parse(
const BSONObj& obj,
- const ExtensionsCallback& extensionsCallback,
const CollatorInterface* collator,
- const boost::intrusive_ptr<ExpressionContext>& expCtx = nullptr) {
+ const boost::intrusive_ptr<ExpressionContext>& expCtx = nullptr,
+ const ExtensionsCallback& extensionsCallback = ExtensionsCallbackNoop(),
+ AllowedFeatureSet allowedFeatures = kBanAllSpecialFeatures) {
+ // A non-null ExpressionContext is required for parsing $expr.
+ if (!expCtx) {
+ invariant((allowedFeatures & AllowedFeatures::kExpr) == 0u);
+ }
+
const bool topLevelCall = true;
return MatchExpressionParser(&extensionsCallback)
- ._parse(obj, collator, expCtx, topLevelCall);
+ ._parse(obj, collator, expCtx, allowedFeatures, topLevelCall);
}
/**
@@ -171,6 +192,7 @@ private:
StatusWithMatchExpression _parse(const BSONObj& obj,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel);
/**
@@ -183,6 +205,7 @@ private:
AndMatchExpression* root,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel);
/**
@@ -196,6 +219,7 @@ private:
const BSONElement& e,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel);
StatusWithMatchExpression _parseComparison(
@@ -203,7 +227,8 @@ private:
ComparisonMatchExpression* cmp,
const BSONElement& e,
const CollatorInterface* collator,
- const boost::intrusive_ptr<ExpressionContext>& expCtx);
+ const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures);
StatusWithMatchExpression _parseMOD(const char* name,
const BSONElement& e,
@@ -231,7 +256,8 @@ private:
StatusWithMatchExpression _parseGeo(const char* name,
PathAcceptingKeyword type,
- const BSONObj& section);
+ const BSONObj& section,
+ AllowedFeatureSet allowedFeatures);
// arrays
@@ -239,12 +265,14 @@ private:
const BSONElement& e,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel);
StatusWithMatchExpression _parseAll(const char* name,
const BSONElement& e,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel);
// tree
@@ -253,12 +281,14 @@ private:
ListOfMatchExpression* out,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel);
StatusWithMatchExpression _parseNot(const char* name,
const BSONElement& e,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel);
/**
@@ -284,7 +314,8 @@ private:
StringData name,
const BSONElement& elem,
const CollatorInterface* collator,
- const boost::intrusive_ptr<ExpressionContext>& expCtx);
+ const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures);
/**
* Parses the given BSONElement into a single integer argument and creates a MatchExpression
@@ -310,8 +341,10 @@ private:
bool _isAggExpression(BSONElement elem, const boost::intrusive_ptr<ExpressionContext>& expCtx);
- boost::intrusive_ptr<Expression> _parseAggExpression(
- BSONElement elem, const boost::intrusive_ptr<ExpressionContext>& expCtx);
+ StatusWith<boost::intrusive_ptr<Expression>> _parseAggExpression(
+ BSONElement elem,
+ const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures);
StatusWithMatchExpression _parseInternalSchemaAllowedProperties(
const BSONElement& elem, const CollatorInterface* collator);