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 * --- include/ouroboros/CMakeLists.txt | 2 +- include/ouroboros/da.h | 2 +- include/ouroboros/instance_name.h | 89 ++++++++++++++++++++++++++++++++++++ include/ouroboros/ipcp.h | 10 ++--- include/ouroboros/irm.h | 35 ++++++--------- include/ouroboros/rina_name.h | 94 --------------------------------------- include/ouroboros/sockets.h | 1 - 7 files changed, 110 insertions(+), 123 deletions(-) create mode 100644 include/ouroboros/instance_name.h delete mode 100644 include/ouroboros/rina_name.h (limited to 'include') diff --git a/include/ouroboros/CMakeLists.txt b/include/ouroboros/CMakeLists.txt index cc6b9103..324a85ad 100644 --- a/include/ouroboros/CMakeLists.txt +++ b/include/ouroboros/CMakeLists.txt @@ -9,11 +9,11 @@ set(HEADER_FILES da.h dev.h du_buff.h + instance_name.h ipcp.h irm.h list.h logs.h - rina_name.h shm_du_map.h sockets.h utils.h diff --git a/include/ouroboros/da.h b/include/ouroboros/da.h index f678007d..9ecd4bd8 100644 --- a/include/ouroboros/da.h +++ b/include/ouroboros/da.h @@ -24,7 +24,7 @@ #define OUROBOROS_DA_H #include "common.h" -#include "rina_name.h" +#include "instance_name.h" char * da_resolve_daf(char * daf_name); /* diff --git a/include/ouroboros/instance_name.h b/include/ouroboros/instance_name.h new file mode 100644 index 00000000..b3e528c0 --- /dev/null +++ b/include/ouroboros/instance_name.h @@ -0,0 +1,89 @@ +/* + * RINA naming related utilities + * + * Sander Vrijders + * Francesco Salvestrini + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef INSTANCE_NAME_H +#define INSTANCE_NAME_H + +#include "common.h" + +typedef struct { + char * name; + uint16_t id; +} instance_name_t; + +/* + * Allocates a new name, returning the allocated object. + * In case of an error, a NULL is returned. + */ +instance_name_t * instance_name_create(); + +/* + * Initializes a previously dynamically allocated name (i.e. name_create()) + * or a statically one (e.g. declared into a struct not as a pointer). + * Returns the passed object pointer in case everything is ok, a NULL + * otherwise. + * + * A call to name_destroy() is allowed in case of error, in order to + * release the associated resources. + * + * It is allowed to call name_init() over an already initialized object + */ +instance_name_t * instance_name_init_from(instance_name_t * dst, + const char * name, + uint16_t api_id); + +/* Takes ownership of the passed parameters */ +instance_name_t * instance_name_init_with(instance_name_t * dst, + char * name, + uint16_t id); + +/* + * Finalize a name object, releasing all the embedded resources (without + * releasing the object itself). After name_fini() execution the passed + * object will be in the same states as at the end of name_init(). + */ +void instance_name_fini(instance_name_t * dst); + +/* Releases all the associated resources bound to a name object */ +void instance_name_destroy(instance_name_t * ptr); + +/* Duplicates a name object, returning the pointer to the new object */ +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_cmp(const instance_name_t * a, + const instance_name_t * b); + +bool instance_name_is_valid(const instance_name_t * n); + +/* Returns a name as a (newly allocated) string */ +char * instance_name_to_string(const instance_name_t * n); + +/* Inverse of name_tostring() */ +instance_name_t * string_to_instance_name(const char * s); + +#endif /* INSTANCE_NAME_H */ diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h index cd4a3f51..49b04908 100644 --- a/include/ouroboros/ipcp.h +++ b/include/ouroboros/ipcp.h @@ -26,14 +26,14 @@ #include #include "common.h" -#include "rina_name.h" +#include "instance_name.h" struct ipcp; /* Returns the process id */ -pid_t ipcp_create(rina_name_t name, - char * ipcp_type); -int ipcp_destroy(pid_t pid); +pid_t ipcp_create(instance_name_t * api, + char * ipcp_type); +int ipcp_destroy(pid_t pid); int ipcp_reg(pid_t pid, char ** difs, @@ -50,4 +50,4 @@ int ipcp_enroll(pid_t pid, char ** n_1_difs, ssize_t n_1_difs_size); -#endif +#endif /* OUROBOROS_IPCP_H */ diff --git a/include/ouroboros/irm.h b/include/ouroboros/irm.h index fe72aefe..780bf77b 100644 --- a/include/ouroboros/irm.h +++ b/include/ouroboros/irm.h @@ -24,28 +24,21 @@ #define OUROBOROS_IRM_H #include "common.h" -#include "rina_name.h" +#include "instance_name.h" -int irm_create_ipcp(char * ap_name, - int api_id, - char * ipcp_type); -int irm_destroy_ipcp(char * ap_name, - int api_id); +int irm_create_ipcp(instance_name_t * api, + char * ipcp_type); +int irm_destroy_ipcp(instance_name_t * api); -int irm_bootstrap_ipcp(char * ap_name, - int api_id, +int irm_bootstrap_ipcp(instance_name_t * api, struct dif_config * conf); -int irm_enroll_ipcp(char * ap_name, - int api_id, - char * dif_name); +int irm_enroll_ipcp(instance_name_t * api, + char * dif_name); -int irm_reg_ipcp(char * ap_name, - int api_id, - char ** difs, - size_t difs_size); -int irm_unreg_ipcp(char * ap_name, - int api_id, - char ** difs, - size_t difs_size); - -#endif +int irm_reg_ipcp(instance_name_t * api, + char ** difs, + size_t difs_size); +int irm_unreg_ipcp(const instance_name_t * api, + char ** difs, + size_t difs_size); +#endif /* OUROBOROS_IRM_H */ diff --git a/include/ouroboros/rina_name.h b/include/ouroboros/rina_name.h deleted file mode 100644 index f8af00c2..00000000 --- a/include/ouroboros/rina_name.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * RINA naming related utilities - * - * Sander Vrijders - * Francesco Salvestrini - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef RINA_NAME_H -#define RINA_NAME_H - -#include "common.h" - -typedef struct { - char * ap_name; - unsigned int api_id; -} rina_name_t; - -/* - * Allocates a new name, returning the allocated object. - * In case of an error, a NULL is returned. - */ -rina_name_t * name_create(); - -/* - * Initializes a previously dynamically allocated name (i.e. name_create()) - * or a statically one (e.g. declared into a struct not as a pointer). - * Returns the passed object pointer in case everything is ok, a NULL - * otherwise. - * - * A call to name_destroy() is allowed in case of error, in order to - * release the associated resources. - * - * It is allowed to call name_init() over an already initialized object - */ -rina_name_t * name_init_from(rina_name_t * dst, - const char * ap_name, - unsigned int api_id); - -/* Takes ownership of the passed parameters */ -rina_name_t * name_init_with(rina_name_t * dst, - char * ap_name, - unsigned int api_id); - -/* - * Finalize a name object, releasing all the embedded resources (without - * releasing the object itself). After name_fini() execution the passed - * object will be in the same states as at the end of name_init(). - */ -void name_fini(rina_name_t * dst); - -/* Releases all the associated resources bound to a name object */ -void name_destroy(rina_name_t * ptr); - -/* Duplicates a name object, returning the pointer to the new object */ -rina_name_t * name_dup(const rina_name_t * src); - -/* - * Copies the source object contents into the destination object, both must - * be previously allocated - */ -int name_cpy(const rina_name_t * src, rina_name_t * dst); - -bool name_is_equal(const rina_name_t * a, const rina_name_t * b); -bool name_is_ok(const rina_name_t * n); - -#define NAME_CMP_APN 0x01 -#define NAME_CMP_API 0x02 -#define NAME_CMP_ALL (NAME_CMP_APN | NAME_CMP_API) - -bool name_cmp(uint8_t flags, - const rina_name_t * a, - const rina_name_t * b); - -/* Returns a name as a (newly allocated) string */ -char * name_to_string(const rina_name_t * n); - -/* Inverse of name_tostring() */ -rina_name_t * string_to_name(const char * s); - -#endif diff --git a/include/ouroboros/sockets.h b/include/ouroboros/sockets.h index bb8e6d84..4c736de2 100644 --- a/include/ouroboros/sockets.h +++ b/include/ouroboros/sockets.h @@ -24,7 +24,6 @@ #define OUROBOROS_SOCKETS_H #include -#include #include -- 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 'include') 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