Git Product home page Git Product logo

Comments (5)

shmuelzon avatar shmuelzon commented on July 28, 2024

Sadly, the ESP32 toolchain doesn't include regex implementation nor fnmatch().
I don't want to bring in a regex library just for this as it would probably be overkill.
Perhaps we can simply use wildcard character, e.g. ? and create out own MAC compare function. This wildcard would only handle a single character, not octet, to make things simpler and then you could configure:

"whitelist": [ "aa:bb:cc:??:??:??" ]

Does that sound reasonable to you?

from esp32-ble2mqtt.

robertcsakany avatar robertcsakany commented on July 28, 2024

Yes. That was my "regex like" function, the * or ?? does not matter me. Better the use of Wildcard as name. I fix the issue topic.

from esp32-ble2mqtt.

robertcsakany avatar robertcsakany commented on July 28, 2024

It may an easy implementation that replace the characters on the source mac addresses to ? on positions where the configurations contains them and only strcmp is required. Does it makes sense?

from esp32-ble2mqtt.

robertcsakany avatar robertcsakany commented on July 28, 2024

There is a proposal for wildcard support:

// The main function that checks if two given strings 
// match. The first string may contain wildcard characters 
int match(char *first, char *second) 
{ 
    // If we reach at the end of both strings, we are done 
    if (*first == '\0' && *second == '\0') 
        return 1; 
  
    // Make sure that the characters after '*' are present 
    // in second string. This function assumes that the first 
    // string will not contain two consecutive '*' 
    if (*first == '*' && *(first+1) != '\0' && *second == '\0') 
        return 0; 
  
    // If the first string contains '?', or current characters 
    // of both strings match 
    if (*first == '?' || *first == *second) 
        return match(first+1, second+1); 
  
    // If there is *, then there are two possibilities 
    // a) We consider current character of second string 
    // b) We ignore current character of second string. 
    if (*first == '*') 
        return match(first+1, second) || match(first, second+1); 
    return 0; 
}

from esp32-ble2mqtt.

shmuelzon avatar shmuelzon commented on July 28, 2024

I saw that implementation when I was looking before. It seemed cumbersome and I'm not sure if it will handle multiple wildcards as expected. That's why I opted for a single-character wildcard. much more simple to implement.
The only reason I suggested the ? is because it usually denotes a single character where * is for zero-or-more characters.

from esp32-ble2mqtt.

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.