mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
node: use regex to check node name
This commit is contained in:
parent
2f29e30c33
commit
b552fbe47f
2 changed files with 5 additions and 7 deletions
|
@ -51,6 +51,8 @@
|
|||
struct rtnl_cls;
|
||||
#endif /* WITH_NETEM */
|
||||
|
||||
#define REGEX_NODE_NAME "[a-z0-9_-]{3,32}"
|
||||
|
||||
/** The data structure for a node.
|
||||
*
|
||||
* Every entity which exchanges messages is represented by a node.
|
||||
|
|
10
lib/node.cpp
10
lib/node.cpp
|
@ -20,6 +20,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************************/
|
||||
|
||||
#include <regex>
|
||||
#include <cstring>
|
||||
#include <cctype>
|
||||
#include <openssl/md5.h>
|
||||
|
@ -645,14 +646,9 @@ invalid2:
|
|||
|
||||
bool node_is_valid_name(const char *name)
|
||||
{
|
||||
for (const char *p = name; *p; p++) {
|
||||
if (isalnum(*p) || (*p == '_') || (*p == '-'))
|
||||
continue;
|
||||
std::regex re(REGEX_NODE_NAME);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return std::regex_match(name, re);
|
||||
}
|
||||
|
||||
bool node_is_enabled(const struct node *n)
|
||||
|
|
Loading…
Add table
Reference in a new issue