diff options
author | Dimitri Staessens <dimitri.staessens@ugent.be> | 2018-03-22 11:02:15 +0100 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@ugent.be> | 2018-03-22 12:36:58 +0100 |
commit | 751fb58bcf5fdb31c0627a5153684e96126cffb6 (patch) | |
tree | 5c4e8d8b2b2b323738703644c422a7e6c7095d5e /src/tools/irm/irm_register.c | |
parent | fd5508b8daec47e9f646c086d4cc310583154b97 (diff) | |
download | ouroboros-751fb58bcf5fdb31c0627a5153684e96126cffb6.tar.gz ouroboros-751fb58bcf5fdb31c0627a5153684e96126cffb6.zip |
lib: Simplify reg/unreg API
The reg/unreg API is simplified to registering and unregistering a
single name with a single IPCP. The functionality associated with
registering names was moved from the IRMd to the irm tool. The
function to list IPCPs was simplified to return all IPCPs in the
system with their basic properties needed for management.
The above changes led to some needed changes in the irm tool and the
management functions that were depending on the previous behaviour of
list_ipcps.
Command line functionality to list IPCPs in the system is also added
to the irm tool.
Some older code was refactored.
Signed-off-by: Dimitri Staessens <dimitri.staessens@ugent.be>
Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
Diffstat (limited to 'src/tools/irm/irm_register.c')
-rw-r--r-- | src/tools/irm/irm_register.c | 62 |
1 files changed, 53 insertions, 9 deletions
diff --git a/src/tools/irm/irm_register.c b/src/tools/irm/irm_register.c index 574c2224..59d65a69 100644 --- a/src/tools/irm/irm_register.c +++ b/src/tools/irm/irm_register.c @@ -38,29 +38,42 @@ #include <ouroboros/irm.h> -#include <stdio.h> #include "irm_ops.h" #include "irm_utils.h" +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#define MAX_IPCPS 128 #define MAX_LAYERS 128 static void usage(void) { printf("Usage: irm register\n" " name <name>\n" + " ipcp <ipcp to register with>\n" + " [ipcp <ipcp to register with>]\n" + " [... (maximum %d ipcps)]\n" " layer <layer to register with>\n" " [layer <layer to register with>]\n" " [... (maximum %d layers)]\n" - , MAX_LAYERS); + , MAX_IPCPS, MAX_LAYERS); } -int do_register(int argc, char ** argv) +int do_register(int argc, + char ** argv) { - char * name = NULL; - char * layers[MAX_LAYERS]; - size_t layers_len = 0; + char * name = NULL; + char * layers[MAX_LAYERS]; + size_t layers_len = 0; + char * ipcp[MAX_IPCPS]; + size_t ipcp_len = 0; + struct ipcp_info * ipcps; + size_t len; + size_t i; while (argc > 0) { if (matches(*argv, "name") == 0) { @@ -68,7 +81,13 @@ int do_register(int argc, char ** argv) } else if (matches(*argv, "layer") == 0) { layers[layers_len++] = *(argv + 1); if (layers_len > MAX_LAYERS) { - printf("Too many layers specified\n"); + printf("Too many layers specified.\n"); + return -1; + } + } else if (matches(*argv, "ipcp") == 0) { + ipcp[ipcp_len++] = *(argv + 1); + if (ipcp_len > MAX_IPCPS) { + printf("Too many IPCPs specified.\n"); return -1; } } else { @@ -81,10 +100,35 @@ int do_register(int argc, char ** argv) argv += 2; } - if (layers_len < 1 || name == NULL) { + if ((layers_len < 1 && ipcp_len < 1) || name == NULL) { usage(); return -1; } - return irm_reg(name, layers, layers_len); + len = irm_list_ipcps(&ipcps); + for (i = 0; i < len; ++i) { + size_t j; + for (j = 0; j < layers_len; j++) { + if (wildcard_match(ipcps[i].layer, layers[j]) == 0) { + if (irm_reg(ipcps[i].pid, name)) { + free(ipcps); + return -1; + } + break; + } + } + for (j = 0; j < ipcp_len; j++) { + if (wildcard_match(ipcps[i].name, ipcp[j]) == 0) { + if (irm_reg(ipcps[i].pid, name)) { + free(ipcps); + return -1; + } + break; + } + } + } + + free(ipcps); + + return 0; } |