X-Git-Url: http://git.meshlink.io/?p=meshlink;a=blobdiff_plain;f=src%2Fmeshlink.c;h=0ea38dbb55c952c5ea69e0ab70181f4cb8f17706;hp=815acdeadd60f40e6e8691a2f5e779a849e5f9e2;hb=ed1f31db1e8840ffd6849b48bcad93e9975a24bb;hpb=2cd74834fff509cdd9ed51232a3a78e7cad04803 diff --git a/src/meshlink.c b/src/meshlink.c index 815acdea..0ea38dbb 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -37,6 +37,7 @@ typedef struct { #include "meshlink_internal.h" #include "netutl.h" #include "node.h" +#include "submesh.h" #include "protocol.h" #include "route.h" #include "sockaddr.h" @@ -1415,6 +1416,37 @@ meshlink_handle_t *meshlink_open_ex(const meshlink_open_params_t *params) { return mesh; } +meshlink_submesh_t *meshlink_submesh_open(meshlink_handle_t *mesh, const char *submesh) { + meshlink_submesh_t *s = NULL; + if(!mesh) { + logger(NULL, MESHLINK_ERROR, "No mesh handle given!\n"); + meshlink_errno = MESHLINK_EINVAL; + return NULL; + } + + if(!submesh || !*submesh) { + logger(NULL, MESHLINK_ERROR, "No submesh name given!\n"); + meshlink_errno = MESHLINK_EINVAL; + return NULL; + } + + s = (meshlink_submesh_t *)lookup_submesh(mesh, submesh); + + if (s) { + logger(NULL, MESHLINK_ERROR, "SubMesh Already exists!\n"); + meshlink_errno = MESHLINK_EEXIST; + return NULL; + } + + s = (meshlink_submesh_t *)new_submesh(); + s->name = xstrdup(submesh); + + submesh_add(mesh, (submesh_t *)s); + + meshlink_errno = MESHLINK_OK; + return s; +} + static void *meshlink_main_loop(void *arg) { meshlink_handle_t *mesh = arg;