+/* TODO: this could most probably be moved to a similar scheme to create_from_buffer/payload for the
+ * lttng::trace_format_descriptor object */
+static int process_trace_format_descriptor_node(xmlNodePtr trace_format_descriptor_node,
+ struct lttng_trace_format_descriptor **descriptor)
+{
+ int ret;
+ xmlNodePtr node;
+ struct lttng_trace_format_descriptor *local_descriptor = nullptr;
+ struct lttng_trace_format_descriptor *(*constructor)(void) = nullptr;
+
+ for (node = xmlFirstElementChild(trace_format_descriptor_node); node;
+ node = xmlNextElementSibling(node)) {
+ if (!strcmp((const char *) node->name, config_element_session_trace_format_ctf1)) {
+ constructor = lttng_trace_format_ctf_1_descriptor_create;
+ break;
+ } else if (!strcmp((const char *) node->name,
+ config_element_session_trace_format_ctf2)) {
+ constructor = lttng_trace_format_ctf_2_descriptor_create;
+ break;
+ }
+ }
+
+ if (constructor == nullptr) {
+ ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
+ goto end;
+ }
+
+ local_descriptor = constructor();
+
+ if (local_descriptor == nullptr) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ *descriptor = local_descriptor;
+ local_descriptor = nullptr;
+ ret = 0;
+
+end:
+ lttng_trace_format_descriptor_destroy(local_descriptor);
+ return ret;
+}
+