free(list);
}
-list_node_t *list_alloc_node(void) {
+static list_node_t *list_alloc_node(void) {
return xzalloc(sizeof(list_node_t));
}
-void list_free_node(list_t *list, list_node_t *node) {
+static void list_free_node(list_t *list, list_node_t *node) {
if(node->data && list->delete) {
list->delete(node->data);
}
return node;
}
-list_node_t *list_insert_after(list_t *list, list_node_t *after, void *data) {
- list_node_t *node = list_alloc_node();
-
- node->data = data;
- node->next = after->next;
- node->prev = after;
- after->next = node;
-
- if(node->next) {
- node->next->prev = node;
- } else {
- list->tail = node;
- }
+static void list_unlink_node(list_t *list, list_node_t *node) {
+ assert(list->count);
+ assert(node->prev || list->head == node);
+ assert(node->next || list->tail == node);
- list->count++;
-
- return node;
-}
-
-list_node_t *list_insert_before(list_t *list, list_node_t *before, void *data) {
- list_node_t *node;
-
- node = list_alloc_node();
-
- node->data = data;
- node->next = before;
- node->prev = before->prev;
- before->prev = node;
-
- if(node->prev) {
- node->prev->next = node;
- } else {
- list->head = node;
- }
-
- list->count++;
-
- return node;
-}
-
-void list_unlink_node(list_t *list, list_node_t *node) {
if(node->prev) {
node->prev->next = node->next;
} else {
}
void list_delete(list_t *list, const void *data) {
- for(list_node_t *node = list->head, *next; next = node ? node->next : NULL, node; node = next)
+ for(list_node_t *node = list->head, *next; next = node ? node->next : NULL, node; node = next) {
if(node->data == data) {
list_delete_node(list, node);
}
+ }
}
/* Head/tail lookup */
}
void list_foreach(list_t *list, list_action_t action) {
- for(list_node_t *node = list->head, *next; next = node ? node->next : NULL, node; node = next)
+ for(list_node_t *node = list->head, *next; next = node ? node->next : NULL, node; node = next) {
if(node->data) {
action(node->data);
}
+ }
}
extern list_t *list_alloc(list_action_t) __attribute__((__malloc__));
extern void list_free(list_t *);
-extern list_node_t *list_alloc_node(void);
-extern void list_free_node(list_t *, list_node_t *);
/* Insertion and deletion */
extern list_node_t *list_insert_head(list_t *, void *);
extern list_node_t *list_insert_tail(list_t *, void *);
-extern list_node_t *list_insert_after(list_t *, list_node_t *, void *);
-extern list_node_t *list_insert_before(list_t *, list_node_t *, void *);
extern void list_delete(list_t *, const void *);
-extern void list_unlink_node(list_t *, list_node_t *);
extern void list_delete_node(list_t *, list_node_t *);
extern void list_delete_head(list_t *);
return true;
}
-bool send_ans_key(meshlink_handle_t *mesh, node_t *to) {
- (void)mesh;
- (void)to;
- abort();
-}
-
bool ans_key_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
assert(request);
assert(*request);
return tree;
}
-void splay_free_tree(splay_tree_t *tree) {
- free(tree);
-}
-
splay_node_t *splay_alloc_node(void) {
return xzalloc(sizeof(splay_node_t));
}
/* Insertion and deletion */
-void splay_insert_top(splay_tree_t *tree, splay_node_t *node) {
+static void splay_insert_top(splay_tree_t *tree, splay_node_t *node) {
node->prev = node->next = node->left = node->right = node->parent = NULL;
tree->head = tree->tail = tree->root = node;
tree->count++;
}
-void splay_insert_before(splay_tree_t *tree, splay_node_t *before, splay_node_t *node) {
+static void splay_insert_after(splay_tree_t *tree, splay_node_t *after, splay_node_t *node);
+
+static void splay_insert_before(splay_tree_t *tree, splay_node_t *before, splay_node_t *node) {
if(!before) {
if(tree->tail) {
splay_insert_after(tree, tree->tail, node);
tree->count++;
}
-void splay_insert_after(splay_tree_t *tree, splay_node_t *after, splay_node_t *node) {
+static void splay_insert_after(splay_tree_t *tree, splay_node_t *after, splay_node_t *node) {
if(!after) {
if(tree->head) {
splay_insert_before(tree, tree->head, node);
/* (De)constructors */
extern splay_tree_t *splay_alloc_tree(splay_compare_t, splay_action_t) __attribute__((__malloc__));
-extern void splay_free_tree(splay_tree_t *);
+extern void splay_delete_tree(splay_tree_t *);
extern splay_node_t *splay_alloc_node(void) __attribute__((__malloc__));
extern void splay_free_node(splay_tree_t *tree, splay_node_t *);
extern splay_node_t *splay_insert(splay_tree_t *, void *);
extern splay_node_t *splay_insert_node(splay_tree_t *, splay_node_t *);
-extern void splay_insert_top(splay_tree_t *, splay_node_t *);
-extern void splay_insert_before(splay_tree_t *, splay_node_t *, splay_node_t *);
-extern void splay_insert_after(splay_tree_t *, splay_node_t *, splay_node_t *);
-
extern splay_node_t *splay_unlink(splay_tree_t *, void *);
extern void splay_unlink_node(splay_tree_t *tree, splay_node_t *);
extern void splay_delete(splay_tree_t *, void *);
extern void splay_delete_node(splay_tree_t *, splay_node_t *);
-/* Fast tree cleanup */
-
-extern void splay_delete_tree(splay_tree_t *);
-
/* Searching */
extern void *splay_search(splay_tree_t *, const void *);
#include "xalloc.h"
#include "protocol.h"
+static submesh_t *new_submesh(void) {
+ return xzalloc(sizeof(submesh_t));
+}
+
+static void free_submesh(submesh_t *s) {
+ free(s->name);
+ free(s);
+}
+
void init_submeshes(meshlink_handle_t *mesh) {
assert(!mesh->submeshes);
mesh->submeshes = list_alloc((list_action_t)free_submesh);
mesh->submeshes = NULL;
}
-submesh_t *new_submesh(void) {
- submesh_t *s = xzalloc(sizeof(*s));
-
- s->name = NULL;
- s->priv = NULL;
-
- return s;
-}
-
-void free_submesh(submesh_t *s) {
- if(s->name) {
- free(s->name);
- }
-
- free(s);
-}
-
-static submesh_t *submesh_new(meshlink_handle_t *mesh, const char *submesh) {
- submesh_t *s = NULL;
+static submesh_t *submesh_add(meshlink_handle_t *mesh, const char *submesh) {
assert(submesh);
- s = new_submesh();
+ submesh_t *s = new_submesh();
s->name = xstrdup(submesh);
-
- submesh_add(mesh, (submesh_t *)s);
+ list_insert_tail(mesh->submeshes, (void *)s);
return s;
}
submesh_t *create_submesh(meshlink_handle_t *mesh, const char *submesh) {
assert(submesh);
- submesh_t *s = NULL;
if(0 == strcmp(submesh, CORE_MESH)) {
logger(NULL, MESHLINK_ERROR, "Cannot create submesh handle for core mesh!\n");
return NULL;
}
- s = lookup_submesh(mesh, submesh);
-
- if(s) {
+ if(lookup_submesh(mesh, submesh)) {
logger(NULL, MESHLINK_ERROR, "SubMesh Already exists!\n");
meshlink_errno = MESHLINK_EEXIST;
return NULL;
}
- s = submesh_new(mesh, submesh);
-
- meshlink_errno = MESHLINK_OK;
- return s;
+ return submesh_add(mesh, submesh);
}
submesh_t *lookup_or_create_submesh(meshlink_handle_t *mesh, const char *submesh) {
assert(submesh);
- submesh_t *s = NULL;
if(0 == strcmp(submesh, CORE_MESH)) {
logger(NULL, MESHLINK_ERROR, "Cannot create submesh handle for core mesh!\n");
return NULL;
}
- s = lookup_submesh(mesh, submesh);
+ submesh_t *s = lookup_submesh(mesh, submesh);
if(s) {
meshlink_errno = MESHLINK_OK;
return s;
}
- s = submesh_new(mesh, submesh);
-
- meshlink_errno = MESHLINK_OK;
- return s;
-}
-
-void submesh_add(meshlink_handle_t *mesh, submesh_t *s) {
- s->mesh = mesh;
- list_insert_tail(mesh->submeshes, (void *)s);
-}
-
-void submesh_del(meshlink_handle_t *mesh, submesh_t *s) {
- list_delete(mesh->submeshes, (void *)s);
+ return submesh_add(mesh, submesh);
}
submesh_t *lookup_submesh(struct meshlink_handle *mesh, const char *submesh_name) {
extern void init_submeshes(struct meshlink_handle *mesh);
extern void exit_submeshes(struct meshlink_handle *mesh);
-extern submesh_t *new_submesh(void) __attribute__((__malloc__));
-extern void free_submesh(submesh_t *);
extern submesh_t *create_submesh(struct meshlink_handle *mesh, const char *);
-extern void submesh_add(struct meshlink_handle *mesh, submesh_t *);
-extern void submesh_del(struct meshlink_handle *mesh, submesh_t *);
extern submesh_t *lookup_submesh(struct meshlink_handle *mesh, const char *);
extern submesh_t *lookup_or_create_submesh(struct meshlink_handle *mesh, const char *);
extern bool submesh_allows_node(const submesh_t *submesh, const struct node_t *node);