diff options
author | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-03-30 13:32:27 +0200 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-03-30 13:32:27 +0200 |
commit | a3f002d6f2d102588f988c99eb16c64a68706dd2 (patch) | |
tree | 2ca4abbddec6866be75fa51c4ed7368fadf020a1 /src/lib | |
parent | 1d4442e472d20f261986089ea468daa93631d1f4 (diff) | |
parent | 9aa7cd1d8d137bdb11f963af3e29ba4f421ab6b3 (diff) | |
download | ouroboros-a3f002d6f2d102588f988c99eb16c64a68706dd2.tar.gz ouroboros-a3f002d6f2d102588f988c99eb16c64a68706dd2.zip |
Merged in dstaesse/ouroboros/be-rina-name (pull request #46)
lib: renamed rina_name_t to instance_name_t
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/lib/instance_name.c (renamed from src/lib/rina_name.c) | 155 | ||||
-rw-r--r-- | src/lib/ipcp.c | 10 | ||||
-rw-r--r-- | src/lib/irm.c | 71 |
4 files changed, 112 insertions, 126 deletions
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index c986112e..f18b4d3b 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -26,10 +26,10 @@ set(SOURCE_FILES da.c dev.c du_buff.c + instance_name.c ipcp.c irm.c list.c - rina_name.c shm_du_map.c sockets.c utils.c diff --git a/src/lib/rina_name.c b/src/lib/instance_name.c index 2dcfbb08..0f666211 100644 --- a/src/lib/rina_name.c +++ b/src/lib/instance_name.c @@ -19,11 +19,11 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define OUROBOROS_PREFIX "name-utils" +#define OUROBOROS_PREFIX "instance-name" #include <ouroboros/logs.h> #include <ouroboros/common.h> -#include <ouroboros/rina_name.h> +#include <ouroboros/instance_name.h> #include <ouroboros/utils.h> #include <string.h> @@ -31,6 +31,8 @@ #include <malloc.h> #include <stdlib.h> +#define instance_name_is_equal(a, b) (instance_name_cmp(a, b) == 0) + static char * strdup(const char * src) { int len = 0; @@ -50,153 +52,144 @@ static char * strdup(const char * src) return dst; } -rina_name_t * name_create() +instance_name_t * instance_name_create() { - rina_name_t * tmp; + instance_name_t * tmp; - tmp = malloc(sizeof(rina_name_t)); + tmp = malloc(sizeof *tmp); - tmp->ap_name = NULL; - tmp->api_id = 0; + tmp->name = NULL; + tmp->id = 0; return tmp; } -rina_name_t * name_init_from(rina_name_t * dst, - const char * ap_name, - unsigned int api_id) +instance_name_t * instance_name_init_from(instance_name_t * dst, + const char * name, + uint16_t id) { if (dst == NULL) return NULL; /* Clean up the destination, leftovers might be there ... */ - name_fini(dst); + instance_name_fini(dst); - dst->ap_name = strdup(ap_name); - dst->api_id = api_id; + dst->name = strdup(name); + dst->id = id; - if (dst->ap_name == NULL) { - name_fini(dst); + if (dst->name == NULL) { + instance_name_fini(dst); return NULL; } return dst; } -rina_name_t * name_init_with(rina_name_t * dst, - char * ap_name, - unsigned int api_id) +instance_name_t * instance_name_init_with(instance_name_t * dst, + char * name, + uint16_t id) { if (dst == NULL) return NULL; /* Clean up the destination, leftovers might be there ... */ - name_fini(dst); + instance_name_fini(dst); - dst->ap_name = ap_name; - dst->api_id = api_id; + dst->name = name; + dst->id = id; return dst; } -void name_fini(rina_name_t * n) +void instance_name_fini(instance_name_t * n) { - if (n == NULL) + if (n == NULL || n->name == NULL) return; - if (n->ap_name != NULL) { - free(n->ap_name); - n->ap_name = NULL; - } + free(n->name); + n->name = NULL; } -void name_destroy(rina_name_t * ptr) +void instance_name_destroy(instance_name_t * ptr) { if (ptr == NULL) return; - name_fini(ptr); + instance_name_fini(ptr); free(ptr); } -int name_cpy(const rina_name_t * src, - rina_name_t * dst) +int instance_name_cpy(instance_name_t * dst, + const instance_name_t * src) { - rina_name_t * res; + instance_name_t * res; if (src == NULL || dst == NULL) return -1; - res = name_init_from(dst, - src->ap_name, - src->api_id); + res = instance_name_init_from(dst, src->name, src->id); if (res == NULL) return -1; return 0; } -rina_name_t * name_dup(const rina_name_t * src) +instance_name_t * instance_name_dup(const instance_name_t * src) { - rina_name_t * tmp; + instance_name_t * tmp; if (src == NULL) return NULL; - tmp = name_create(); + tmp = instance_name_create(); if (tmp == NULL) return NULL; - if (name_cpy(src, tmp)) { - name_destroy(tmp); + if (instance_name_cpy(tmp, src)) { + instance_name_destroy(tmp); return NULL; } return tmp; } -#define NAME_CMP_FIELD(X, Y, FIELD) \ - ((X->FIELD != NULL && Y->FIELD != NULL) ? \ - strcmp(X->FIELD, Y->FIELD) : \ - ((X->FIELD == NULL && Y->FIELD == NULL) ? 0 : -1)) - -bool name_is_ok(const rina_name_t * n) -{ return (n != NULL && - n->ap_name != NULL && - strlen(n->ap_name)); } +bool instance_name_is_valid(const instance_name_t * n) +{ + return (n != NULL && n->name != NULL && strlen(n->name)); +} -bool name_cmp(uint8_t flags, - const rina_name_t * a, - const rina_name_t * b) +int instance_name_cmp(const instance_name_t * a, + const instance_name_t * b) { - if (a == b) - return true; - if (a == NULL || b == NULL) - return false; + int ret = 0; + + if (a == NULL || b == NULL) { + LOG_DBGF("Won't compare NULL."); + return -2; + } - if (!(flags & NAME_CMP_ALL)) - LOG_DBG("No flags, name comparison will be meaningless ..."); + if (a == b) + return 0; - if (flags & NAME_CMP_APN) - if (NAME_CMP_FIELD(a, b, ap_name)) - return false; + ret = strcmp(a->name, b->name); - if (flags & NAME_CMP_API) - if (a->api_id != b->api_id) - return false; + if (!ret) { + if (a->id == b-> id) + return 0; + else + return a->id < b->id ? -1 : 1; + } - return true; + return ret; } -bool name_is_equal(const rina_name_t * a, - const rina_name_t * b) -{ return name_cmp(NAME_CMP_ALL, a, b); } + #define DELIMITER "/" -char * name_to_string(const rina_name_t * n) +char * instance_name_to_string(const instance_name_t * n) { char * tmp; size_t size; @@ -206,14 +199,14 @@ char * name_to_string(const rina_name_t * n) if (n == NULL) return NULL; - size = 0; + size = 0; - size += (n->ap_name != NULL ? - strlen(n->ap_name) : none_len); + size += (n->name != NULL ? + strlen(n->name) : none_len); size += strlen(DELIMITER); - size += (n->api_id == 0 ? - 1 : n_digits(n->api_id)); + size += (n->id == 0 ? + 1 : n_digits(n->id)); size += strlen(DELIMITER); tmp = malloc(size); @@ -221,8 +214,8 @@ char * name_to_string(const rina_name_t * n) return NULL; if (sprintf(tmp, "%s%s%d", - (n->ap_name != NULL ? n->ap_name : none), - DELIMITER, n->api_id) + (n->name != NULL ? n->name : none), + DELIMITER, n->id) != size - 1) { free(tmp); return NULL; @@ -231,9 +224,9 @@ char * name_to_string(const rina_name_t * n) return tmp; } -rina_name_t * string_to_name(const char * s) +instance_name_t * string_to_instance_name(const char * s) { - rina_name_t * name; + instance_name_t * name; char * tmp1 = NULL; char * tmp_ap = NULL; @@ -254,15 +247,15 @@ rina_name_t * string_to_name(const char * s) if (tmp_s_api != NULL) tmp_api = (unsigned int) strtol(tmp_s_api, &tmp2, 10); - name = name_create(); + name = instance_name_create(); if (name == NULL) { if (tmp1 != NULL) free(tmp1); return NULL; } - if (!name_init_from(name, tmp_ap, tmp_api)) { - name_destroy(name); + if (!instance_name_init_from(name, tmp_ap, tmp_api)) { + instance_name_destroy(name); if (tmp1 != NULL) free(tmp1); return NULL; diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c index 445160f0..60d5879e 100644 --- a/src/lib/ipcp.c +++ b/src/lib/ipcp.c @@ -85,8 +85,8 @@ static int send_ipcp_msg(pid_t pid, return 0; } -pid_t ipcp_create(rina_name_t name, - char * ipcp_type) +pid_t ipcp_create(instance_name_t * api, + char * ipcp_type) { pid_t pid = 0; char * api_id = NULL; @@ -107,12 +107,12 @@ pid_t ipcp_create(rina_name_t name, return pid; } - api_id = malloc(n_digits(name.api_id) + 1); + api_id = malloc(n_digits(api->id) + 1); if (!api_id) { LOG_ERR("Failed to malloc"); exit(EXIT_FAILURE); } - sprintf(api_id, "%d", name.api_id); + sprintf(api_id, "%d", api->id); len += strlen(INSTALL_DIR); len += strlen(ipcp_dir); @@ -129,7 +129,7 @@ pid_t ipcp_create(rina_name_t name, strcat(full_name, ipcp_dir); char * argv[] = {full_name, - name.ap_name, api_id, + api->name, api_id, ipcp_type, 0}; char * envp[] = {0}; diff --git a/src/lib/irm.c b/src/lib/irm.c index 92d8b3a5..644e1113 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -26,22 +26,22 @@ #include <ouroboros/common.h> #include <ouroboros/logs.h> #include <ouroboros/sockets.h> +#include <ouroboros/instance_name.h> #include <stdlib.h> -int irm_create_ipcp(char * ap_name, - int api_id, - char * ipcp_type) +int irm_create_ipcp(instance_name_t * api, + char * ipcp_type) { irm_msg_t msg = IRM_MSG__INIT; - if (ipcp_type == NULL || ap_name == NULL) + if (api == NULL || ipcp_type == NULL || api->name == NULL) return -EINVAL; msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP; - msg.ap_name = ap_name; + msg.ap_name = api->name; msg.has_api_id = true; - msg.api_id = api_id; + msg.api_id = api->id; msg.ipcp_type = ipcp_type; if (send_irm_msg(&msg)) { @@ -52,19 +52,17 @@ int irm_create_ipcp(char * ap_name, return 0; } -int irm_destroy_ipcp(char * ap_name, - int api_id) +int irm_destroy_ipcp(instance_name_t * api) { irm_msg_t msg = IRM_MSG__INIT; - if (ap_name == NULL) { + if (api == NULL || api->name == NULL) return -EINVAL; - } msg.code = IRM_MSG_CODE__IRM_DESTROY_IPCP; - msg.ap_name = ap_name; + msg.ap_name = api->name; msg.has_api_id = true; - msg.api_id = api_id; + msg.api_id = api->id; if (send_irm_msg(&msg)) { LOG_ERR("Failed to send message to daemon"); @@ -74,20 +72,18 @@ int irm_destroy_ipcp(char * ap_name, return 0; } -int irm_bootstrap_ipcp(char * ap_name, - int api_id, +int irm_bootstrap_ipcp(instance_name_t * api, struct dif_config * conf) { irm_msg_t msg = IRM_MSG__INIT; - if (ap_name == NULL || conf == NULL) { + if (api == NULL || api->name == NULL || conf == NULL) return -EINVAL; - } msg.code = IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP; - msg.ap_name = ap_name; + msg.ap_name = api->name; msg.has_api_id = true; - msg.api_id = api_id; + msg.api_id = api->id; if (send_irm_msg(&msg)) { LOG_ERR("Failed to send message to daemon"); @@ -97,20 +93,18 @@ int irm_bootstrap_ipcp(char * ap_name, return 0; } -int irm_enroll_ipcp(char * ap_name, - int api_id, - char * dif_name) +int irm_enroll_ipcp(instance_name_t * api, + char * dif_name) { irm_msg_t msg = IRM_MSG__INIT; - if (ap_name == NULL || dif_name == NULL) { + if (api == NULL || api->name == NULL || dif_name == NULL) return -EINVAL; - } msg.code = IRM_MSG_CODE__IRM_ENROLL_IPCP; - msg.ap_name = ap_name; + msg.ap_name = api->name; msg.has_api_id = true; - msg.api_id = api_id; + msg.api_id = api->id; msg.n_dif_name = 1; msg.dif_name = malloc(sizeof(*(msg.dif_name))); if (msg.dif_name == NULL) { @@ -130,14 +124,13 @@ int irm_enroll_ipcp(char * ap_name, return 0; } -int irm_reg_ipcp(char * ap_name, - int api_id, - char ** difs, - size_t difs_size) +int irm_reg_ipcp(instance_name_t * api, + char ** difs, + size_t difs_size) { irm_msg_t msg = IRM_MSG__INIT; - if (ap_name == NULL || + if (api->name == NULL || difs == NULL || difs_size == 0 || difs[0] == NULL) { @@ -145,9 +138,9 @@ int irm_reg_ipcp(char * ap_name, } msg.code = IRM_MSG_CODE__IRM_REG_IPCP; - msg.ap_name = ap_name; + msg.ap_name = api->name; msg.has_api_id = true; - msg.api_id = api_id; + msg.api_id = api->id; msg.dif_name = difs; msg.n_dif_name = difs_size; @@ -159,14 +152,14 @@ int irm_reg_ipcp(char * ap_name, return 0; } -int irm_unreg_ipcp(char * ap_name, - int api_id, - char ** difs, - size_t difs_size) +int irm_unreg_ipcp(const instance_name_t * api, + char ** difs, + size_t difs_size) { irm_msg_t msg = IRM_MSG__INIT; - if (ap_name == NULL || + if (api == NULL || + api->name == NULL || difs == NULL || difs_size == 0 || difs[0] == NULL) { @@ -174,9 +167,9 @@ int irm_unreg_ipcp(char * ap_name, } msg.code = IRM_MSG_CODE__IRM_UNREG_IPCP; - msg.ap_name = ap_name; + msg.ap_name = api->name; msg.has_api_id = true; - msg.api_id = api_id; + msg.api_id = api->id; msg.dif_name = difs; msg.n_dif_name = difs_size; |