aboutsummaryrefslogtreecommitdiffstats
path: root/src/instance.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/instance.c')
-rw-r--r--src/instance.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/instance.c b/src/instance.c
index ca80a45..8d62e1e 100644
--- a/src/instance.c
+++ b/src/instance.c
@@ -11,6 +11,14 @@
#include <errno.h>
+const char *const l2_instance_errormsg[] = {
+ "Success",
+ "OS error",
+ "JSON error",
+ "Malformed instance file",
+ NULL
+};
+
int l2_instance__load_all_from_object(json_t *obj);
json_t *l2_instance__save_all_to_object(void);
@@ -116,8 +124,8 @@ int l2_instance_del_instance(struct l2_instance *inst)
l2_state.instance_head = inst->next;
}
- free((char *)inst->name); /* okay to cast away const because any instance in the list will be allocated with strdup */
- free((char *)inst->path);
+ free(inst->name); /* okay to cast away const because any instance in the list will be allocated with strdup */
+ free(inst->path);
free(inst);
return INSTANCE_SUCCESS;
@@ -128,11 +136,33 @@ int l2_instance_rename_instance(struct l2_instance *inst, const char *newname)
char *nn = strdup(newname);
if (!nn) return INSTANCE_ERRNO;
- free((char *)inst->name);
+ free(inst->name);
inst->name = nn;
return INSTANCE_SUCCESS;
}
+struct l2_instance *l2_instance_find_by_uuid(const uuid_t *id)
+{
+ for (struct l2_instance *inst = l2_state.instance_head; inst; inst = inst->next) {
+ if (!memcmp(id, &inst->uuid, sizeof(uuid_t))) {
+ return inst;
+ }
+ }
+
+ return NULL;
+}
+
+struct l2_instance *l2_instance_find_by_name(const char *name)
+{
+ for (struct l2_instance *inst = l2_state.instance_head; inst; inst = inst->next) {
+ if (!strcmp(inst->name, name)) {
+ return inst;
+ }
+ }
+
+ return NULL;
+}
+
/* internal utilities */
int l2_instance__load_all_from_object(json_t *obj)