From 511b51ffe60c20a9091829c03863197b76027716 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Sun, 24 Aug 2014 21:55:42 -0700 Subject: [PATCH] utils: Refactor check_id out of protocol for global access --- src/info.c | 1 + src/protocol.c | 11 ----------- src/protocol.h | 1 - src/tincctl.c | 12 ------------ src/utils.c | 11 +++++++++++ src/utils.h | 1 + 6 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/info.c b/src/info.c index af085bc..c9b0094 100644 --- a/src/info.c +++ b/src/info.c @@ -24,6 +24,7 @@ #include "subnet.h" #include "tincctl.h" #include "info.h" +#include "utils.h" #include "xalloc.h" void logger(int level, int priority, const char *format, ...) { diff --git a/src/protocol.c b/src/protocol.c index 374c522..1ec169a 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -55,17 +55,6 @@ static char (*request_name[]) = { static splay_tree_t *past_request_tree; -bool check_id(const char *id) { - if(!id || !*id) - return false; - - for(; *id; id++) - if(!isalnum(*id) && *id != '_') - return false; - - return true; -} - /* Generic request routines - takes care of logging and error detection as well */ diff --git a/src/protocol.h b/src/protocol.h index e771c54..1a1fb3f 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -81,7 +81,6 @@ extern ecdsa_t *invitation_key; extern bool send_request(struct connection_t *, const char *, ...) __attribute__ ((__format__(printf, 2, 3))); extern void forward_request(struct connection_t *, const char *); extern bool receive_request(struct connection_t *, const char *); -extern bool check_id(const char *); extern void init_requests(void); extern void exit_requests(void); diff --git a/src/tincctl.c b/src/tincctl.c index 2a2c488..158dfed 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -1675,18 +1675,6 @@ static int cmd_config(int argc, char *argv[]) { return 0; } -bool check_id(const char *name) { - if(!name || !*name) - return false; - - for(int i = 0; i < strlen(name); i++) { - if(!isalnum(name[i]) && name[i] != '_') - return false; - } - - return true; -} - static bool try_bind(int port) { struct addrinfo *ai = NULL; struct addrinfo hint = { diff --git a/src/utils.c b/src/utils.c index 797bc3f..db7a8cd 100644 --- a/src/utils.c +++ b/src/utils.c @@ -181,6 +181,17 @@ unsigned int bitfield_to_int(const void *bitfield, size_t size) { return value; } +bool check_id(const char *id) { + if(!id || !*id) + return false; + + for(; *id; id++) + if(!isalnum(*id) && *id != '_') + return false; + + return true; +} + char *replace_name(const char *name) { char *ret_name; diff --git a/src/utils.h b/src/utils.h index 28afc4e..c3364ce 100644 --- a/src/utils.h +++ b/src/utils.h @@ -50,6 +50,7 @@ extern const char *winerror(int); extern unsigned int bitfield_to_int(const void *bitfield, size_t size); +extern bool check_id(const char *); char *replace_name(const char *name); #endif /* __TINC_UTILS_H__ */ -- 2.25.1