diff options
author | Sander Vrijders <[email protected]> | 2016-12-02 15:22:52 +0100 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2016-12-02 17:45:24 +0100 |
commit | 85b3822a4cc121dcb3d87937c2a44395d8887ae3 (patch) | |
tree | 941b20c216e21bceb8741704debfe6efc07f2c2f /src/ipcpd/normal/ribmgr.c | |
parent | 552f2eb19f04968c0c5ebc7b16f6aa1cb61b6b29 (diff) | |
download | ouroboros-85b3822a4cc121dcb3d87937c2a44395d8887ae3.tar.gz ouroboros-85b3822a4cc121dcb3d87937c2a44395d8887ae3.zip |
ipcpd: normal: Provide directory for registered names
This adds a directory to the normal IPCP that maps names on IPCP
addresses.
Diffstat (limited to 'src/ipcpd/normal/ribmgr.c')
-rw-r--r-- | src/ipcpd/normal/ribmgr.c | 79 |
1 files changed, 78 insertions, 1 deletions
diff --git a/src/ipcpd/normal/ribmgr.c b/src/ipcpd/normal/ribmgr.c index 3e305ffe..127eb9f2 100644 --- a/src/ipcpd/normal/ribmgr.c +++ b/src/ipcpd/normal/ribmgr.c @@ -45,6 +45,7 @@ #include "cdap_request.h" #include "ro.h" #include "path.h" +#include "dir.h" #include "static_info.pb-c.h" typedef StaticInfoMsg static_info_msg_t; @@ -1269,8 +1270,17 @@ int ribmgr_bootstrap(struct dif_config * conf) return -1; } + if (dir_init()) { + LOG_ERR("Failed to init directory"); + ribmgr_ro_delete(RIBMGR_PREFIX STAT_INFO); + addr_auth_destroy(rib.addr_auth); + ribmgr_ro_delete(RIBMGR_PREFIX); + return -1; + } + if (frct_init()) { LOG_ERR("Failed to initialize FRCT."); + dir_fini(); ribmgr_ro_delete(RIBMGR_PREFIX STAT_INFO); addr_auth_destroy(rib.addr_auth); ribmgr_ro_delete(RIBMGR_PREFIX); @@ -1412,7 +1422,6 @@ int ro_create(const char * name, node = ribmgr_ro_create(name, *attr, data, len); if (node == NULL) { pthread_mutex_unlock(&rib.ro_lock); - LOG_ERR("Failed to create RO."); return -1; } @@ -1563,6 +1572,74 @@ ssize_t ro_read(const char * name, return len; } +ssize_t ro_children(const char * name, + char *** children) +{ + struct rnode * node; + struct rnode * child; + ssize_t len = 0; + int i = 0; + + assert(name); + assert(children); + + pthread_mutex_lock(&rib.ro_lock); + + node = find_rnode_by_name(name); + if (node == NULL) { + pthread_mutex_unlock(&rib.ro_lock); + return -1; + } + + child = node->child; + while (child != NULL) { + len++; + child = child->sibling; + } + child = node->child; + + **children = malloc(len); + if (**children == NULL) { + pthread_mutex_unlock(&rib.ro_lock); + return -1; + } + + for (i = 0; i < len; i++) { + (*children)[i] = strdup(child->name); + if ((*children)[i] == NULL) { + while (i >= 0) { + free((*children)[i]); + i--; + } + free(**children); + pthread_mutex_unlock(&rib.ro_lock); + return -1; + } + child = child->sibling; + } + + pthread_mutex_unlock(&rib.ro_lock); + + return len; +} + +bool ro_exists(const char * name) +{ + struct rnode * node; + bool found; + + assert(name); + + pthread_mutex_lock(&rib.ro_lock); + + node = find_rnode_by_name(name); + found = (node == NULL) ? false : true; + + pthread_mutex_unlock(&rib.ro_lock); + + return found; +} + int ro_subscribe(const char * name, struct ro_sub_ops * ops) { |