From a14d696bdbc72754e8019fa9579d5a338cc85a05 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Mon, 28 Mar 2016 14:43:16 +0200 Subject: lib: Update irm.h API Removes rina_name_t from that API. Passing ap_name and api_id as params instead. The IRM tool has been updated accordingly. Some errors in the build related to protobuf-c have also been resolved. --- src/lib/.gitignore | 1 + src/lib/CMakeLists.txt | 11 ++-- src/lib/irm.c | 141 ++++++++++++++++++++++++++++--------------------- src/lib/sockets.c | 7 +++ 4 files changed, 98 insertions(+), 62 deletions(-) create mode 100644 src/lib/.gitignore (limited to 'src/lib') diff --git a/src/lib/.gitignore b/src/lib/.gitignore new file mode 100644 index 00000000..8704469b --- /dev/null +++ b/src/lib/.gitignore @@ -0,0 +1 @@ +*.pb-c.[ch] \ No newline at end of file diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index e05dce8b..0427e236 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -34,10 +34,13 @@ set(SOURCE_FILES shm_du_map.c sockets.c utils.c -) + ) -add_library(ouroboros SHARED ${SOURCE_FILES} ${PROTO_SRCS} ${PROTO_HDRS}) -target_link_libraries(ouroboros rt pthread ${PROTOBUF_LIBRARIES}) +install(FILES ${PROTO_HDRS} + DESTINATION include/ouroboros) + +add_library(ouroboros SHARED ${SOURCE_FILES} ${PROTO_SRCS}) +target_link_libraries(ouroboros rt pthread ${PROTOBUF_C_LIBRARY}) include(MacroAddCompileFlags) if (CMAKE_BUILD_TYPE MATCHES Debug) @@ -46,4 +49,6 @@ endif (CMAKE_BUILD_TYPE MATCHES Debug) install(TARGETS ouroboros LIBRARY DESTINATION lib) +target_include_directories(ouroboros PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) + add_subdirectory(tests) diff --git a/src/lib/irm.c b/src/lib/irm.c index 9fd13d52..92d8b3a5 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -26,26 +26,25 @@ #include #include #include + #include -int irm_create_ipcp(rina_name_t name, +int irm_create_ipcp(char * ap_name, + int api_id, char * ipcp_type) { - struct irm_msg msg; + irm_msg_t msg = IRM_MSG__INIT; - if (ipcp_type == NULL) - return -1; + if (ipcp_type == NULL || ap_name == NULL) + return -EINVAL; - if (!name_is_ok(&name)) { - LOG_ERR("Bad name"); - return -1; - } - - msg.code = IRM_CREATE_IPCP; - msg.name = &name; + msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP; + msg.ap_name = ap_name; + msg.has_api_id = true; + msg.api_id = api_id; msg.ipcp_type = ipcp_type; - if (send_irmd_msg(&msg)) { + if (send_irm_msg(&msg)) { LOG_ERR("Failed to send message to daemon"); return -1; } @@ -53,19 +52,21 @@ int irm_create_ipcp(rina_name_t name, return 0; } -int irm_destroy_ipcp(rina_name_t name) +int irm_destroy_ipcp(char * ap_name, + int api_id) { - struct irm_msg msg; + irm_msg_t msg = IRM_MSG__INIT; - if (!name_is_ok(&name)) { - LOG_ERR("Bad name"); - return -1; + if (ap_name == NULL) { + return -EINVAL; } - msg.code = IRM_DESTROY_IPCP; - msg.name = &name; + msg.code = IRM_MSG_CODE__IRM_DESTROY_IPCP; + msg.ap_name = ap_name; + msg.has_api_id = true; + msg.api_id = api_id; - if (send_irmd_msg(&msg)) { + if (send_irm_msg(&msg)) { LOG_ERR("Failed to send message to daemon"); return -1; } @@ -73,21 +74,22 @@ int irm_destroy_ipcp(rina_name_t name) return 0; } -int irm_bootstrap_ipcp(rina_name_t name, - struct dif_config conf) +int irm_bootstrap_ipcp(char * ap_name, + int api_id, + struct dif_config * conf) { - struct irm_msg msg; + irm_msg_t msg = IRM_MSG__INIT; - if (!name_is_ok(&name)) { - LOG_ERR("Bad name"); - return -1; + if (ap_name == NULL || conf == NULL) { + return -EINVAL; } - msg.code = IRM_BOOTSTRAP_IPCP; - msg.name = &name; - msg.conf = &conf; + msg.code = IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP; + msg.ap_name = ap_name; + msg.has_api_id = true; + msg.api_id = api_id; - if (send_irmd_msg(&msg)) { + if (send_irm_msg(&msg)) { LOG_ERR("Failed to send message to daemon"); return -1; } @@ -95,45 +97,61 @@ int irm_bootstrap_ipcp(rina_name_t name, return 0; } -int irm_enroll_ipcp(rina_name_t name, +int irm_enroll_ipcp(char * ap_name, + int api_id, char * dif_name) { - struct irm_msg msg; + irm_msg_t msg = IRM_MSG__INIT; - if (!name_is_ok(&name)) { - LOG_ERR("Bad name"); - return -1; + if (ap_name == NULL || dif_name == NULL) { + return -EINVAL; } - msg.code = IRM_ENROLL_IPCP; - msg.name = &name; - msg.dif_name = dif_name; + msg.code = IRM_MSG_CODE__IRM_ENROLL_IPCP; + msg.ap_name = ap_name; + msg.has_api_id = true; + msg.api_id = api_id; + msg.n_dif_name = 1; + msg.dif_name = malloc(sizeof(*(msg.dif_name))); + if (msg.dif_name == NULL) { + LOG_ERR("Failed to malloc"); + return -1; + } + msg.dif_name[0] = dif_name; - if (send_irmd_msg(&msg)) { + if (send_irm_msg(&msg)) { LOG_ERR("Failed to send message to daemon"); + free(msg.dif_name); return -1; } + free(msg.dif_name); + return 0; } -int irm_reg_ipcp(rina_name_t name, +int irm_reg_ipcp(char * ap_name, + int api_id, char ** difs, size_t difs_size) { - struct irm_msg msg; + irm_msg_t msg = IRM_MSG__INIT; - if (!name_is_ok(&name)) { - LOG_ERR("Bad name"); - return -1; + if (ap_name == NULL || + difs == NULL || + difs_size == 0 || + difs[0] == NULL) { + return -EINVAL; } - msg.code = IRM_REG_IPCP; - msg.name = &name; - msg.difs = difs; - msg.difs_size = difs_size; + msg.code = IRM_MSG_CODE__IRM_REG_IPCP; + msg.ap_name = ap_name; + msg.has_api_id = true; + msg.api_id = api_id; + msg.dif_name = difs; + msg.n_dif_name = difs_size; - if (send_irmd_msg(&msg)) { + if (send_irm_msg(&msg)) { LOG_ERR("Failed to send message to daemon"); return -1; } @@ -141,23 +159,28 @@ int irm_reg_ipcp(rina_name_t name, return 0; } -int irm_unreg_ipcp(rina_name_t name, +int irm_unreg_ipcp(char * ap_name, + int api_id, char ** difs, size_t difs_size) { - struct irm_msg msg; + irm_msg_t msg = IRM_MSG__INIT; - if (!name_is_ok(&name)) { - LOG_ERR("Bad name"); - return -1; + if (ap_name == NULL || + difs == NULL || + difs_size == 0 || + difs[0] == NULL) { + return -EINVAL; } - msg.code = IRM_UNREG_IPCP; - msg.name = &name; - msg.difs = difs; - msg.difs_size = difs_size; + msg.code = IRM_MSG_CODE__IRM_UNREG_IPCP; + msg.ap_name = ap_name; + msg.has_api_id = true; + msg.api_id = api_id; + msg.dif_name = difs; + msg.n_dif_name = difs_size; - if (send_irmd_msg(&msg)) { + if (send_irm_msg(&msg)) { LOG_ERR("Failed to send message to daemon"); return -1; } diff --git a/src/lib/sockets.c b/src/lib/sockets.c index b157b628..b98f6bbc 100644 --- a/src/lib/sockets.c +++ b/src/lib/sockets.c @@ -166,6 +166,13 @@ struct irm_msg * send_recv_irmd_msg(struct irm_msg * msg) return recv_msg; } + +int send_irm_msg(irm_msg_t * msg) +{ + + return -1; +} + char * ipcp_sock_path(pid_t pid) { char * full_name = NULL; -- cgit v1.2.3