diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/irm.c | 130 | ||||
-rw-r--r-- | src/lib/irmd_messages.proto | 37 |
2 files changed, 146 insertions, 21 deletions
diff --git a/src/lib/irm.c b/src/lib/irm.c index e4b39f2c..08dffb6c 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -543,8 +543,48 @@ int irm_unbind_process(pid_t pid, return ret; } -int irm_reg(pid_t pid, - const char * name) +int irm_create_name(const char * name, + enum pol_balance pol) +{ + irm_msg_t msg = IRM_MSG__INIT; + name_info_msg_t ni_msg = NAME_INFO_MSG__INIT; + irm_msg_t * recv_msg; + int ret; + + if (name == NULL) + return -EINVAL; + + msg.code = IRM_MSG_CODE__IRM_CREATE_NAME; + ni_msg.name = (char *) name; + ni_msg.pol_lb = pol; + msg.n_names = 1; + + msg.names = malloc(sizeof(*msg.names)); + if (msg.names == NULL) { + return -ENOMEM; + } + + msg.names[0] = &ni_msg; + + recv_msg = send_recv_irm_msg(&msg); + + free(msg.names); + + if (recv_msg == NULL) + return -EIRMD; + + if (!recv_msg->has_result) { + irm_msg__free_unpacked(recv_msg, NULL); + return -1; + } + + ret = recv_msg->result; + irm_msg__free_unpacked(recv_msg, NULL); + + return ret; +} + +int irm_destroy_name(const char * name) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -553,7 +593,84 @@ int irm_reg(pid_t pid, if (name == NULL) return -EINVAL; - msg.code = IRM_MSG_CODE__IRM_REG; + msg.code = IRM_MSG_CODE__IRM_DESTROY_NAME; + msg.name = (char *) name; + + recv_msg = send_recv_irm_msg(&msg); + if (recv_msg == NULL) + return -EIRMD; + + if (!recv_msg->has_result) { + irm_msg__free_unpacked(recv_msg, NULL); + return -1; + } + + ret = recv_msg->result; + irm_msg__free_unpacked(recv_msg, NULL); + + return ret; +} + +ssize_t irm_list_names(struct name_info ** names) +{ + irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg; + size_t nr; + size_t i; + + if (names == NULL) + return -EINVAL; + + *names = NULL; + + msg.code = IRM_MSG_CODE__IRM_LIST_NAMES; + + recv_msg = send_recv_irm_msg(&msg); + if (recv_msg == NULL) + return -EIRMD; + + if (recv_msg->names == NULL) { + irm_msg__free_unpacked(recv_msg, NULL); + return 0; + } + + nr = recv_msg->n_names; + if (nr == 0) { + irm_msg__free_unpacked(recv_msg, NULL); + return 0; + } + + *names = malloc(nr * sizeof(**names)); + if (*names == NULL) { + irm_msg__free_unpacked(recv_msg, NULL); + return -ENOMEM; + } + + for (i = 0; i < nr; i++) { + (*names)[i].pol_lb = recv_msg->names[i]->pol_lb; + /* Truncate names > NAME_SIZE */ + if (strlen(recv_msg->names[i]->name) >= NAME_SIZE) + recv_msg->names[i]->name[NAME_SIZE - 1] = 0; + + strcpy((*names)[i].name, recv_msg->names[i]->name); + } + + irm_msg__free_unpacked(recv_msg, NULL); + + return nr; +} + +int irm_reg_name(const char * name, + pid_t pid) +{ + irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg = NULL; + int ret = -1; + + if (name == NULL) + return -EINVAL; + + msg.code = IRM_MSG_CODE__IRM_REG_NAME; msg.has_pid = true; msg.pid = pid; msg.name = (char *) name; @@ -573,9 +690,8 @@ int irm_reg(pid_t pid, return ret; } - -int irm_unreg(pid_t pid, - const char * name) +int irm_unreg_name(const char * name, + pid_t pid) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -584,7 +700,7 @@ int irm_unreg(pid_t pid, if (name == NULL) return -EINVAL; - msg.code = IRM_MSG_CODE__IRM_UNREG; + msg.code = IRM_MSG_CODE__IRM_UNREG_NAME; msg.has_pid = true; msg.pid = pid; msg.name = (char *) name; diff --git a/src/lib/irmd_messages.proto b/src/lib/irmd_messages.proto index c8749699..5b23ee9d 100644 --- a/src/lib/irmd_messages.proto +++ b/src/lib/irmd_messages.proto @@ -39,15 +39,18 @@ enum irm_msg_code { IRM_PROC_ANNOUNCE = 11; IRM_BIND_PROCESS = 12; IRM_UNBIND_PROCESS = 13; - IRM_REG = 14; - IRM_UNREG = 15; - IRM_FLOW_ALLOC = 16; - IRM_FLOW_ACCEPT = 17; - IRM_FLOW_JOIN = 18; - IRM_FLOW_DEALLOC = 19; - IPCP_FLOW_REQ_ARR = 20; - IPCP_FLOW_ALLOC_REPLY = 21; - IRM_REPLY = 22; + IRM_CREATE_NAME = 14; + IRM_DESTROY_NAME = 15; + IRM_LIST_NAMES = 16; + IRM_REG_NAME = 17; + IRM_UNREG_NAME = 18; + IRM_FLOW_ALLOC = 19; + IRM_FLOW_ACCEPT = 20; + IRM_FLOW_JOIN = 21; + IRM_FLOW_DEALLOC = 22; + IPCP_FLOW_REQ_ARR = 23; + IPCP_FLOW_ALLOC_REPLY = 24; + IRM_REPLY = 25; }; message ipcp_info_msg { @@ -57,6 +60,11 @@ message ipcp_info_msg { required string layer = 4; }; +message name_info_msg { + required string name = 1; + required uint32 pol_lb = 2; +}; + message irm_msg { required irm_msg_code code = 1; optional string prog = 2; @@ -73,9 +81,10 @@ message irm_msg { optional ipcp_config_msg conf = 13; optional uint32 opts = 14; repeated ipcp_info_msg ipcps = 15; - optional uint32 timeo_sec = 16; - optional uint32 timeo_nsec = 17; - optional string comp = 18; - optional bytes pk = 19; /* piggyback */ - optional sint32 result = 20; + repeated name_info_msg names = 16; + optional uint32 timeo_sec = 17; + optional uint32 timeo_nsec = 18; + optional string comp = 19; + optional bytes pk = 20; /* piggyback */ + optional sint32 result = 21; }; |