Move to kernel style SPDX license identifiers
[babeltrace.git] / src / plugins / ctf / common / metadata / decoder.c
index 17b2aa4bd211be1474d4d7da288207f7cc7fc2a7..342cba2fd82f7a1543d91adba5a8dca94c6a1296 100644 (file)
@@ -1,15 +1,7 @@
 /*
- * Copyright 2016-2017 - Philippe Proulx <pproulx@efficios.com>
+ * SPDX-License-Identifier: MIT
  *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
+ * Copyright 2016-2017 Philippe Proulx <pproulx@efficios.com>
  */
 
 #define BT_COMP_LOG_SELF_COMP (mdec->config.self_comp)
 #include "decoder.h"
 #include "scanner.h"
 #include "logging.h"
+#include "parser-wrap.h"
 
 #define TSDL_MAGIC     0x75d11d57
 
-extern
-int yydebug;
-
 struct ctf_metadata_decoder {
        struct ctf_scanner *scanner;
        GString *text;
@@ -271,9 +261,11 @@ enum ctf_metadata_decoder_status ctf_metadata_decoder_append_content(
                }
        }
 
+#if YYDEBUG
        if (BT_LOG_ON_TRACE) {
                yydebug = 1;
        }
+#endif
 
        /* Save the file's position: we'll seek back to append the plain text */
        BT_ASSERT(fp);
@@ -341,7 +333,9 @@ enum ctf_metadata_decoder_status ctf_metadata_decoder_append_content(
        }
 
 end:
+#if YYDEBUG
        yydebug = 0;
+#endif
 
        if (fp && close_fp) {
                if (fclose(fp)) {
@@ -359,8 +353,8 @@ BT_HIDDEN
 bt_trace_class *ctf_metadata_decoder_get_ir_trace_class(
                struct ctf_metadata_decoder *mdec)
 {
-       BT_ASSERT(mdec);
-       BT_ASSERT(mdec->config.create_trace_class);
+       BT_ASSERT_DBG(mdec);
+       BT_ASSERT_DBG(mdec->config.create_trace_class);
        return ctf_visitor_generate_ir_get_ir_trace_class(mdec->visitor);
 }
 
@@ -368,23 +362,23 @@ BT_HIDDEN
 struct ctf_trace_class *ctf_metadata_decoder_borrow_ctf_trace_class(
                struct ctf_metadata_decoder *mdec)
 {
-       BT_ASSERT(mdec);
-       BT_ASSERT(mdec->config.create_trace_class);
+       BT_ASSERT_DBG(mdec);
+       BT_ASSERT_DBG(mdec->config.create_trace_class);
        return ctf_visitor_generate_ir_borrow_ctf_trace_class(mdec->visitor);
 }
 
 BT_HIDDEN
 const char *ctf_metadata_decoder_get_text(struct ctf_metadata_decoder *mdec)
 {
-       BT_ASSERT(mdec);
-       BT_ASSERT(mdec->config.keep_plain_text);
+       BT_ASSERT_DBG(mdec);
+       BT_ASSERT_DBG(mdec->config.keep_plain_text);
        return mdec->text->str;
 }
 
 BT_HIDDEN
 int ctf_metadata_decoder_get_byte_order(struct ctf_metadata_decoder *mdec)
 {
-       BT_ASSERT(mdec);
+       BT_ASSERT_DBG(mdec);
        return mdec->bo;
 }
 
@@ -394,7 +388,7 @@ int ctf_metadata_decoder_get_uuid(struct ctf_metadata_decoder *mdec,
 {
        int ret = 0;
 
-       BT_ASSERT(mdec);
+       BT_ASSERT_DBG(mdec);
 
        if (!mdec->is_uuid_set) {
                ret = -1;
@@ -406,3 +400,80 @@ int ctf_metadata_decoder_get_uuid(struct ctf_metadata_decoder *mdec,
 end:
        return ret;
 }
+
+static
+enum ctf_metadata_decoder_status find_uuid_in_trace_decl(
+               struct ctf_metadata_decoder *mdec, struct ctf_node *trace_node,
+               bt_uuid_t uuid)
+{
+       enum ctf_metadata_decoder_status status =
+               CTF_METADATA_DECODER_STATUS_OK;
+       struct ctf_node *entry_node;
+       struct bt_list_head *decl_list = &trace_node->u.trace.declaration_list;
+       char *left = NULL;
+
+       bt_list_for_each_entry(entry_node, decl_list, siblings) {
+               if (entry_node->type == NODE_CTF_EXPRESSION) {
+                       int ret;
+
+                       left = ctf_ast_concatenate_unary_strings(
+                               &entry_node->u.ctf_expression.left);
+                       if (!left) {
+                               BT_COMP_LOGE("Cannot concatenate unary strings.");
+                               status = CTF_METADATA_DECODER_STATUS_ERROR;
+                               goto end;
+                       }
+
+                       if (strcmp(left, "uuid") == 0) {
+                               ret = ctf_ast_get_unary_uuid(
+                                       &entry_node->u.ctf_expression.right,
+                                       uuid, mdec->config.log_level,
+                                       mdec->config.self_comp);
+                               if (ret) {
+                                       BT_COMP_LOGE("Invalid trace's `uuid` attribute.");
+                                       status = CTF_METADATA_DECODER_STATUS_ERROR;
+                                       goto end;
+                               }
+
+                               goto end;
+                       }
+
+                       g_free(left);
+                       left = NULL;
+               }
+       }
+
+       status = CTF_METADATA_DECODER_STATUS_NONE;
+
+end:
+       g_free(left);
+       return status;
+}
+
+BT_HIDDEN
+enum ctf_metadata_decoder_status ctf_metadata_decoder_get_trace_class_uuid(
+               struct ctf_metadata_decoder *mdec, bt_uuid_t uuid)
+{
+       enum ctf_metadata_decoder_status status =
+               CTF_METADATA_DECODER_STATUS_INCOMPLETE;
+       struct ctf_node *root_node = &mdec->scanner->ast->root;
+       struct ctf_node *trace_node;
+
+       if (!root_node) {
+               status = CTF_METADATA_DECODER_STATUS_INCOMPLETE;
+               goto end;
+       }
+
+       trace_node =
+               bt_list_entry(root_node->u.root.trace.next,
+                       struct ctf_node, siblings);
+       if (!trace_node) {
+               status = CTF_METADATA_DECODER_STATUS_INCOMPLETE;
+               goto end;
+       }
+
+       status = find_uuid_in_trace_decl(mdec, trace_node, uuid);
+
+end:
+       return status;
+}
This page took 0.02506 seconds and 4 git commands to generate.