From 2ed8914deed73a558c6fbac7f107f47dc22f22d2 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Tue, 29 Mar 2016 23:32:04 +0200 Subject: lib: renamed rina_name_t to instance_name_t all functions taking a char * ap_name and uint id now take either a instance_name_t or instance_name_t * --- src/lib/irm.c | 84 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 38 deletions(-) (limited to 'src/lib/irm.c') diff --git a/src/lib/irm.c b/src/lib/irm.c index 92d8b3a5..af899d0a 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -26,22 +26,25 @@ #include #include #include +#include #include -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) + return -EINVAL; + + if (ipcp_type == NULL || api == 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 +55,21 @@ 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) + return -EINVAL; + + if (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 +79,21 @@ 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) + return -EINVAL; + + if (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 +103,21 @@ 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) + return -EINVAL; + + if (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 +137,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 +151,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 +165,16 @@ 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) + return -EINVAL; + + if (api->name == NULL || difs == NULL || difs_size == 0 || difs[0] == NULL) { @@ -174,9 +182,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; -- cgit v1.2.3 From 9aa7cd1d8d137bdb11f963af3e29ba4f421ab6b3 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Wed, 30 Mar 2016 13:17:34 +0200 Subject: lib: fixes for instance_name fixes wrong check, checks now use lazy evaluation changed the order of instance_name_cpy to (dst, src) --- include/ouroboros/instance_name.h | 4 ++-- src/lib/instance_name.c | 26 ++++++++++---------------- src/lib/irm.c | 27 ++++++--------------------- 3 files changed, 18 insertions(+), 39 deletions(-) (limited to 'src/lib/irm.c') diff --git a/include/ouroboros/instance_name.h b/include/ouroboros/instance_name.h index b3e528c0..351b222f 100644 --- a/include/ouroboros/instance_name.h +++ b/include/ouroboros/instance_name.h @@ -72,8 +72,8 @@ instance_name_t * instance_name_dup(const instance_name_t * src); * Copies the source object contents into the destination object, both must * be previously allocated */ -int instance_name_cpy(const instance_name_t * src, - instance_name_t * dst); +int instance_name_cpy(instance_name_t * dst, + const instance_name_t * src); int instance_name_cmp(const instance_name_t * a, const instance_name_t * b); diff --git a/src/lib/instance_name.c b/src/lib/instance_name.c index 1e61f790..0f666211 100644 --- a/src/lib/instance_name.c +++ b/src/lib/instance_name.c @@ -86,7 +86,7 @@ instance_name_t * instance_name_init_from(instance_name_t * dst, } instance_name_t * instance_name_init_with(instance_name_t * dst, - char * name, + char * name, uint16_t id) { if (dst == NULL) @@ -103,13 +103,11 @@ instance_name_t * instance_name_init_with(instance_name_t * dst, void instance_name_fini(instance_name_t * n) { - if (n == NULL) + if (n == NULL || n->name == NULL) return; - if (n->name != NULL) { - free(n->name); - n->name = NULL; - } + free(n->name); + n->name = NULL; } void instance_name_destroy(instance_name_t * ptr) @@ -122,17 +120,15 @@ void instance_name_destroy(instance_name_t * ptr) free(ptr); } -int instance_name_cpy(const instance_name_t * src, - instance_name_t * dst) +int instance_name_cpy(instance_name_t * dst, + const instance_name_t * src) { instance_name_t * res; if (src == NULL || dst == NULL) return -1; - res = instance_name_init_from(dst, - src->name, - src->id); + res = instance_name_init_from(dst, src->name, src->id); if (res == NULL) return -1; @@ -150,7 +146,7 @@ instance_name_t * instance_name_dup(const instance_name_t * src) if (tmp == NULL) return NULL; - if (instance_name_cpy(src, tmp)) { + if (instance_name_cpy(tmp, src)) { instance_name_destroy(tmp); return NULL; } @@ -160,9 +156,7 @@ instance_name_t * instance_name_dup(const instance_name_t * src) bool instance_name_is_valid(const instance_name_t * n) { - return (n != NULL && - n->name != NULL && - strlen(n->name)); + return (n != NULL && n->name != NULL && strlen(n->name)); } int instance_name_cmp(const instance_name_t * a, @@ -205,7 +199,7 @@ char * instance_name_to_string(const instance_name_t * n) if (n == NULL) return NULL; - size = 0; + size = 0; size += (n->name != NULL ? strlen(n->name) : none_len); diff --git a/src/lib/irm.c b/src/lib/irm.c index af899d0a..644e1113 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -35,10 +35,7 @@ int irm_create_ipcp(instance_name_t * api, { irm_msg_t msg = IRM_MSG__INIT; - if (api == NULL) - return -EINVAL; - - if (ipcp_type == NULL || api == NULL) + if (api == NULL || ipcp_type == NULL || api->name == NULL) return -EINVAL; msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP; @@ -59,12 +56,8 @@ int irm_destroy_ipcp(instance_name_t * api) { irm_msg_t msg = IRM_MSG__INIT; - if (api == NULL) - return -EINVAL; - - if (api->name == NULL) { + if (api == NULL || api->name == NULL) return -EINVAL; - } msg.code = IRM_MSG_CODE__IRM_DESTROY_IPCP; msg.ap_name = api->name; @@ -84,10 +77,7 @@ int irm_bootstrap_ipcp(instance_name_t * api, { irm_msg_t msg = IRM_MSG__INIT; - if (api == NULL) - return -EINVAL; - - if (api->name == NULL || conf == NULL) + if (api == NULL || api->name == NULL || conf == NULL) return -EINVAL; msg.code = IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP; @@ -108,10 +98,7 @@ int irm_enroll_ipcp(instance_name_t * api, { irm_msg_t msg = IRM_MSG__INIT; - if (api == NULL) - return -EINVAL; - - if (api->name == NULL || dif_name == NULL) + if (api == NULL || api->name == NULL || dif_name == NULL) return -EINVAL; msg.code = IRM_MSG_CODE__IRM_ENROLL_IPCP; @@ -171,10 +158,8 @@ int irm_unreg_ipcp(const instance_name_t * api, { irm_msg_t msg = IRM_MSG__INIT; - if (api == NULL) - return -EINVAL; - - if (api->name == NULL || + if (api == NULL || + api->name == NULL || difs == NULL || difs_size == 0 || difs[0] == NULL) { -- cgit v1.2.3