utils: Refactor check_id out of protocol for global access

This commit is contained in:
William A. Kennington III 2014-08-24 21:55:42 -07:00 committed by Guus Sliepen
parent 826ad11e41
commit 511b51ffe6
6 changed files with 13 additions and 24 deletions

View file

@ -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, ...) {

View file

@ -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 */

View file

@ -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);

View file

@ -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 = {

View file

@ -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;

View file

@ -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__ */