summaryrefslogtreecommitdiff
path: root/src/lib/irm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/irm.c')
-rw-r--r--src/lib/irm.c232
1 files changed, 151 insertions, 81 deletions
diff --git a/src/lib/irm.c b/src/lib/irm.c
index 9fd13d52..7c187be1 100644
--- a/src/lib/irm.c
+++ b/src/lib/irm.c
@@ -26,141 +26,211 @@
#include <ouroboros/common.h>
#include <ouroboros/logs.h>
#include <ouroboros/sockets.h>
+#include <ouroboros/instance_name.h>
+
#include <stdlib.h>
-int irm_create_ipcp(rina_name_t name,
- char * ipcp_type)
+int irm_create_ipcp(instance_name_t * api,
+ char * ipcp_type)
{
- struct irm_msg msg;
-
- if (ipcp_type == NULL)
- return -1;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
- return -1;
- }
+ if (api == NULL || ipcp_type == NULL || api->name == NULL)
+ return -EINVAL;
- msg.code = IRM_CREATE_IPCP;
- msg.name = &name;
+ msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP;
+ msg.ap_name = api->name;
+ msg.has_api_id = true;
+ msg.api_id = api->id;
msg.ipcp_type = ipcp_type;
- if (send_irmd_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
-int irm_destroy_ipcp(rina_name_t name)
+int irm_destroy_ipcp(instance_name_t * api)
{
- struct irm_msg msg;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
- return -1;
- }
+ if (api == NULL || api->name == NULL)
+ return -EINVAL;
- msg.code = IRM_DESTROY_IPCP;
- msg.name = &name;
+ msg.code = IRM_MSG_CODE__IRM_DESTROY_IPCP;
+ msg.ap_name = api->name;
+ msg.has_api_id = true;
+ msg.api_id = api->id;
+
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
- if (send_irmd_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
-int irm_bootstrap_ipcp(rina_name_t name,
- struct dif_config conf)
+int irm_bootstrap_ipcp(instance_name_t * api,
+ struct dif_config * conf)
{
- struct irm_msg msg;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
- return -1;
- }
+ if (api == NULL || api->name == NULL || conf == NULL)
+ return -EINVAL;
+
+ msg.code = IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP;
+ msg.ap_name = api->name;
+ msg.has_api_id = true;
+ msg.api_id = api->id;
- msg.code = IRM_BOOTSTRAP_IPCP;
- msg.name = &name;
- msg.conf = &conf;
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
- if (send_irmd_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
-int irm_enroll_ipcp(rina_name_t name,
- char * dif_name)
+int irm_enroll_ipcp(instance_name_t * api,
+ char * dif_name)
{
- struct irm_msg msg;
-
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
+
+ if (api == NULL || api->name == NULL || dif_name == NULL)
+ return -EINVAL;
+
+ msg.code = IRM_MSG_CODE__IRM_ENROLL_IPCP;
+ msg.ap_name = api->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;
- msg.code = IRM_ENROLL_IPCP;
- msg.name = &name;
- msg.dif_name = dif_name;
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL) {
+ free(msg.dif_name);
+ return -1;
+ }
- if (send_irmd_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ free(msg.dif_name);
+ return ret;
}
-int irm_reg_ipcp(rina_name_t name,
- char ** difs,
- size_t difs_size)
+int irm_reg_ipcp(instance_name_t * api,
+ char ** difs,
+ size_t difs_size)
{
- struct irm_msg msg;
-
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
- return -1;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
+
+ if (api->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 = api->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)) {
- LOG_ERR("Failed to send message to daemon");
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
-int irm_unreg_ipcp(rina_name_t name,
- char ** difs,
- size_t difs_size)
+int irm_unreg_ipcp(const instance_name_t * api,
+ char ** difs,
+ size_t difs_size)
{
- struct irm_msg msg;
-
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
- return -1;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
+
+ if (api == NULL ||
+ api->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 = api->name;
+ msg.has_api_id = true;
+ msg.api_id = api->id;
+ msg.dif_name = difs;
+ msg.n_dif_name = difs_size;
+
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
- if (send_irmd_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}