From: William A. Kennington III Date: Mon, 25 Aug 2014 04:55:42 +0000 (-0700) Subject: utils: Refactor check_id out of protocol for global access X-Git-Tag: release-1.1pre11~51 X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=511b51ffe60c20a9091829c03863197b76027716;p=tinc utils: Refactor check_id out of protocol for global access --- diff --git a/src/info.c b/src/info.c index af085bc3..c9b00946 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 374c5229..1ec169a0 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 e771c545..1a1fb3f8 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 2a2c488e..158dfed8 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 797bc3f5..db7a8cd6 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 28afc4ef..c3364ced 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__ */