Skip to content

Commit

Permalink
2024-12-30: Add support for the '~=' operator in expression parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
wildmeng committed Dec 30, 2024
1 parent 1235ce6 commit 00b8e94
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/core/dm_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,12 @@ int DM_ACCESS_CompareString(char *lhs, expr_op_t op, char *rhs, bool *result)
USP_ERR_SetMessage("%s: Operator '%s' not supported for strings", __FUNCTION__, expr_op_2_str[op]);
err = USP_ERR_INVALID_PATH_SYNTAX;
break;

case kExprOp_Contains:
if (strstr(lhs, rhs) != NULL)
{
*result = true;
}
break;
default:
TERMINATE_BAD_CASE(op);
break;
Expand Down
10 changes: 10 additions & 0 deletions src/core/expr_vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ char *expr_op_2_str[kExprOp_Max] =
"<", // kExprOp_LessThan
">", // kExprOp_GreaterThan
"=", // kExprOp_Equals
"~=", // kExprOp_Contains
};


Expand Down Expand Up @@ -483,6 +484,15 @@ char *SplitOnOperator(char *buf, expr_op_t *p_op)
return &op[2];
}

// Exit if found the "~=" operator
op = strstr(buf, "~=");
if (op != NULL)
{
*p_op = kExprOp_Contains;
*op = '\0';
return &op[2];
}

// Exit if found the "<" operator
op = strchr(buf, '<');
if (op != NULL)
Expand Down
2 changes: 1 addition & 1 deletion src/core/path_resolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,7 @@ int ResolveUniqueKey(char *resolved, char *unresolved, resolver_state_t *state)
char temp[MAX_DM_PATH];
bool is_match;
bool is_ref_match;
expr_op_t valid_ops[] = {kExprOp_Equal, kExprOp_NotEqual, kExprOp_LessThanOrEqual, kExprOp_GreaterThanOrEqual, kExprOp_LessThan, kExprOp_GreaterThan};
expr_op_t valid_ops[] = {kExprOp_Equal, kExprOp_NotEqual, kExprOp_LessThanOrEqual, kExprOp_GreaterThanOrEqual, kExprOp_LessThan, kExprOp_GreaterThan, kExprOp_Contains};
unsigned short permission_bitmask;

// Exit if unable to find the end of the unique key
Expand Down
2 changes: 1 addition & 1 deletion src/include/usp_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ typedef enum
kExprOp_LessThan, // '<'
kExprOp_GreaterThan, // '>'
kExprOp_Equals, // '='

kExprOp_Contains, // '~='
kExprOp_Max
} expr_op_t;

Expand Down

0 comments on commit 00b8e94

Please sign in to comment.