Code Monkey home page Code Monkey logo

Comments (3)

weiqiushi avatar weiqiushi commented on June 2, 2024

The filter is part of the old processing logic of the protocol stack, and is used to distribute requests to different handlers.
Currently recommended use req_path to distribute between different handlers, and the filter field should be left empty.

from cyfs.

lurenpluto avatar lurenpluto commented on June 2, 2024

This filter is a built-in expression of cyfs-stack, the design and development was completed relatively early, some historical reasons for not updating to github, the following is the documentation of the filter expression:

Legal characters supported by filter expression variables

The legal character set is as follows

  • English letters
  • numbers
  • hyphen (-)
  • underscore (_)
  • dot (.)
  • dollar sign($)
  • asterisk(*)
  • forward slash (/) and backslash (\)

If the variable contains characters other than the above legal ones, you need to enclose it in quotes, either single or double quotes

req_path == '/put/**'
req_path == "/'put'/**"

Integer constants are available in binary, octal, decimal and hexadecimal.

  1. decimal by default
  2. binary Beginning with 0b or 0B
  3. octal starting with 0o or 0O
  4. hexadecimal starting with 0x or 0X

Boolean constants support the following two forms.

  1. true, false
  2. 1, 0

Special expressions

The following special expressions are currently supported.

  • "*" The result is fixed to true and is used in filters to indicate that the filter must match.

The data types supported by filter expressions

The following five types are supported.

1. None

means empty, corresponding to rust is Option=None, using the reserved word $none
For example

object.owner == $none

2. string

String type, the most commonly used type, represents a string value or a type that can be converted to a string, such as object_id, dec_id, etc.
String and glob types need to be enclosed in single or double quotes if they contain reserved characters, otherwise they will fail to be parsed

3. glob

This is mainly used for fuzzy matching of paths, using the standard glob pattern under linux, please refer to the related documentation for details
Currently req_path and inner_path are glob types

"req_path == '/**/*.js'"

4. bool

supports logical operations, the result of all intermediate expressions, is also of type bool
bool variables can be true/false, 0/1

5. integers

Signed and unsigned.

  • signed: I8, I16, I32, I64
  • unsigned: U8, U16, U32, U64

Types of operations supported by filter expressions

The types of operations supported by filter expressions are briefly divided into several categories.

  1. match comparison == and ! =
  2. size comparisons <=, <, >=, >
  3. logical operations && ||
  4. bitwise operations &, ^, |
  5. logical non-operations (NOT) !

The operations supported by each data type are shown in the table below.

datatatype matching comparison size comparison logical operations bitwise operations logical non
None YES
string YES
glob YES
bool YES YES YES YES
I8 YES YES YES
I16 YES YES YES YES
I32 YES YES YES YES
I64 YES YES YES YES
U8 YES YES YES YES
U16 YES YES YES YES
U32 YES YES YES YES
U64 YES YES YES YES

Operator priority

The priorities are sorted from highest to lowest as follows.

Operator Priority
NOT 17
LT/LT/GT/GE 12
NE/EQ 11
BAND 10
BXOR 9
BOR 8
AND 7
OR 6

Expressions support parentheses, use them as much as possible if you don't know the operator precedence.

(a ! = 0 && ((b!=1) || c < 10))

Some sample expressions.

"a & 0x10"
"! (c && ! !c)"
"(a >= 11 || (b==10)) && d <= 10"
"(a ! = 0 && (a!=1) && a == c && (b ! = b1 || (!c) || d == 1))"
"(x ! = $none)"
"req_path == '/**/*.js'"
"(*)"
"*"

from cyfs.

lurenpluto avatar lurenpluto commented on June 2, 2024

If I want to use stack.router_handlers().add_handler() to register an event, how do I set the filter? There is currently no document found about filter rules

The dynamic acl handler supports two types of filters, string and blob, and the corresponding usage methods can be found in the above document.

For the introduction and usage of glob, please refer to https://docs.rs/globset/latest/globset/#syntax

from cyfs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.