]> git.meshlink.io Git - meshlink/blob - src/submesh.c
Modified meshlink_invite to generate invites for submesh
[meshlink] / src / submesh.c
1 /*
2     node.c -- node tree management
3     Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>,
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "system.h"
21
22 #include "hash.h"
23 #include "logger.h"
24 #include "meshlink_internal.h"
25 #include "net.h"
26 #include "netutl.h"
27 #include "submesh.h"
28 #include "splay_tree.h"
29 #include "utils.h"
30 #include "xalloc.h"
31
32 void init_submeshes(meshlink_handle_t *mesh) {
33         mesh->submeshes = list_alloc((list_action_t)free_submesh);
34 }
35
36 void exit_submeshes(meshlink_handle_t *mesh) {
37         list_delete_list(mesh->submeshes);
38         mesh->submeshes = NULL;
39 }
40
41 submesh_t *new_submesh(void) {
42         submesh_t *s = xzalloc(sizeof(*s));
43
44         s->name = NULL;
45         s->priv = NULL;
46
47         return s;
48 }
49
50 void free_submesh(submesh_t *s) {
51         if(s->name) {
52                 free(s->name);
53         }
54
55         free(s);
56 }
57
58 void submesh_add(meshlink_handle_t *mesh, submesh_t *s) {
59         s->mesh = mesh;
60         list_insert_tail(mesh->submeshes, (void *)s);
61 }
62
63 void submesh_del(meshlink_handle_t *mesh, submesh_t *s) {
64         list_delete(mesh->submeshes, (void *)s);
65 }
66
67 submesh_t *lookup_submesh(struct meshlink_handle *mesh, const char *submesh_name) {
68         submesh_t *submesh = NULL;
69
70         if(!mesh->submeshes) {
71                 return NULL;
72         }
73
74         for list_each(submesh_t, s, mesh->submeshes) {
75                 if(!strcmp(submesh_name, s->name)) {
76                         submesh = s;
77                         break;
78                 }
79         }
80
81         return submesh;
82 }