return XLAT_ACTION_DONE;
}
-static int xlat_protocol_register(fr_dict_t const *dict)
+static int xlat_protocol_register_by_name(dl_t *dl, char const *name)
{
fr_test_point_pair_decode_t *tp_decode;
fr_test_point_pair_encode_t *tp_encode;
xlat_t *xlat;
- dl_t *dl = fr_dict_dl(dict);
- char *p, buffer[256+32], name[256];
-
- /*
- * No library for this protocol, skip it.
- *
- * Protocol TEST has no libfreeradius-test, so that's OK.
- */
- if (!dl) return 0;
-
- strlcpy(name, fr_dict_root(dict)->name, sizeof(name));
- for (p = name; *p != '\0'; p++) {
- *p = tolower((uint8_t) *p);
- }
+ char buffer[256+32];
/*
* See if there's a decode function for it.
return 0;
}
+static int xlat_protocol_register(fr_dict_t const *dict)
+{
+ dl_t *dl = fr_dict_dl(dict);
+ char *p, name[256];
+
+ /*
+ * No library for this protocol, skip it.
+ *
+ * Protocol TEST has no libfreeradius-test, so that's OK.
+ */
+ if (!dl) return 0;
+
+ strlcpy(name, fr_dict_root(dict)->name, sizeof(name));
+ for (p = name; *p != '\0'; p++) {
+ *p = tolower((uint8_t) *p);
+ }
+
+ return xlat_protocol_register_by_name(dl, name);
+}
+
+static dl_loader_t *cbor_loader = NULL;
+
+static int xlat_protocol_register_cbor(void)
+{
+ dl_t *dl;
+
+ cbor_loader = dl_loader_init(NULL, NULL, false, false);
+ if (!cbor_loader) return 0;
+
+ dl = dl_by_name(cbor_loader, "libfreeradius-cbor", NULL, false);
+ if (!dl) return 0;
+
+ if (xlat_protocol_register_by_name(dl, "cbor") < 0) return -1;
+
+ return 0;
+}
+
+
/** Register xlats for any loaded dictionaries
*/
int xlat_protocols_register(void)
*/
if (xlat_protocol_register(fr_dict_internal()) < 0) return -1;
+ /*
+ * And cbor stuff
+ */
+ if (xlat_protocol_register_cbor() < 0) return -1;
+
return 0;
}
TALLOC_FREE(xlat_ctx);
xlat_func_free();
xlat_eval_free();
+ talloc_free(cbor_loader);
return 0;
}
--- /dev/null
+octets cbor
+string foo
+
+cbor = %cbor.encode(User-Name)
+
+#
+# 9f array of indefinite length
+# a1 map of lenght 1
+# 01 key is integer, value 1 (User-Name)
+# 43 value is string, of length 3
+# 626f62 string 'bob'
+# ff end of indefinite array
+#
+if (cbor != 0x9fa10143626f62ff) {
+ test_fail
+}
+
+#
+# Delete User-Name
+#
+request -= User-Name[*]
+if (User-Name) {
+ test_fail
+}
+
+#
+# Decodes are automatically written to the request list.
+#
+# @todo - change this to be configurable :(
+#
+%cbor.decode(%{cbor})
+
+if (User-Name != "bob") {
+ test_fail
+}
+
+success