Create/destroy TR_APC structures.
authorJennifer Richards <jennifer@painless-security.com>
Wed, 10 Aug 2016 18:35:59 +0000 (14:35 -0400)
committerJennifer Richards <jennifer@painless-security.com>
Wed, 10 Aug 2016 18:35:59 +0000 (14:35 -0400)
common/tr_apc.c [new file with mode: 0644]

diff --git a/common/tr_apc.c b/common/tr_apc.c
new file mode 100644 (file)
index 0000000..9728022
--- /dev/null
@@ -0,0 +1,40 @@
+#include <talloc.h>
+
+#include <trust_router/tr_name.h>
+#include <tr_apc.h>
+
+static int tr_apc_destructor(void *obj)
+{
+  TR_APC *apc=talloc_get_type_abort(obj, TR_APC);
+  if (apc->id!=NULL)
+    tr_free_name(apc->id);
+  return 0;
+}
+
+TR_APC *tr_apc_new(TALLOC_CTX *mem_ctx)
+{
+  TR_APC *apc=talloc(mem_ctx, TR_APC);
+  if (apc!=NULL) {
+    apc->id=NULL;
+    apc->next=NULL;
+    talloc_set_destructor((void *)apc, tr_apc_destructor);
+  }
+  return apc;
+}
+
+void tr_apc_free(TR_APC *apc)
+{
+  talloc_free(apc);
+}
+
+void tr_apc_set_id(TR_APC *apc, TR_NAME *id)
+{
+  if (apc->id)
+    tr_free_name(apc->id);
+  apc->id=id;
+}
+
+TR_NAME *tr_apc_get_id(TR_APC *apc)
+{
+  return apc->id;
+}