From: Saverio Proto Date: Sat, 7 Jun 2014 10:23:56 +0000 (+0200) Subject: Allow meshlink_open() to be called with a NULL name, in anticipation of meshlink_join... X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=eff41a69e1976fd521b4c524bed86b1bc095b10f;p=meshlink Allow meshlink_open() to be called with a NULL name, in anticipation of meshlink_join(). Do not allow meshlink_start() if no Name is set. --- diff --git a/src/meshlink.c b/src/meshlink.c index 50a5a483..7ea3e440 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -715,6 +715,7 @@ static bool meshlink_setup(meshlink_handle_t *mesh) { meshlink_handle_t *meshlink_open(const char *confbase, const char *name) { // Validate arguments provided by the application + bool usingname = false; if(!confbase || !*confbase) { fprintf(stderr, "No confbase given!\n"); @@ -723,17 +724,19 @@ meshlink_handle_t *meshlink_open(const char *confbase, const char *name) { if(!name || !*name) { fprintf(stderr, "No name given!\n"); - return NULL; + //return NULL; } + else { //check name only if there is a name != NULL - if(!check_id(name)) { - fprintf(stderr, "Invalid name given!\n"); - return NULL; + if(!check_id(name)) { + fprintf(stderr, "Invalid name given!\n"); + return NULL; + } else { usingname = true;} } meshlink_handle_t *mesh = xzalloc(sizeof *mesh); mesh->confbase = xstrdup(confbase); - mesh->name = xstrdup(name); + if (usingname) mesh->name = xstrdup(name); pthread_mutex_init ( &(mesh->outpacketqueue_mutex), NULL); pthread_mutex_init ( &(mesh->nodes_mutex), NULL); mesh->threadstarted = false; @@ -792,6 +795,12 @@ void *meshlink_main_loop(void *arg) { bool meshlink_start(meshlink_handle_t *mesh) { // TODO: open listening sockets first + //Check that a valid name is set + if(!mesh->name ) { + fprintf(stderr, "No name given!\n"); + return false; + } + // Start the main thread if(pthread_create(&mesh->thread, NULL, meshlink_main_loop, mesh) != 0) {