Coverage Report

Created: 2025-01-28 07:34

/src/fluent-bit/plugins/processor_sql/sql_config.c
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*  Fluent Bit
4
 *  ==========
5
 *  Copyright (C) 2015-2024 The Fluent Bit Authors
6
 *
7
 *  Licensed under the Apache License, Version 2.0 (the "License");
8
 *  you may not use this file except in compliance with the License.
9
 *  You may obtain a copy of the License at
10
 *
11
 *      http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 *  Unless required by applicable law or agreed to in writing, software
14
 *  distributed under the License is distributed on an "AS IS" BASIS,
15
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 *  See the License for the specific language governing permissions and
17
 *  limitations under the License.
18
 */
19
20
#include <fluent-bit/flb_processor_plugin.h>
21
#include <fluent-bit/flb_mem.h>
22
23
#include "sql.h"
24
#include "parser/sql_parser.h"
25
26
struct sql_ctx *sql_config_create(struct flb_processor_instance *ins,
27
                                  struct flb_config *config)
28
0
{
29
0
    int ret;
30
0
    struct sql_ctx *ctx;
31
32
0
    ctx = flb_calloc(1, sizeof(struct sql_ctx));
33
0
    if (!ctx) {
34
0
        flb_errno();
35
0
        return NULL;
36
0
    }
37
0
    ctx->ins = ins;
38
39
    /* Initialize the config map */
40
0
    ret = flb_processor_instance_config_map_set(ins, ctx);
41
0
    if (ret == -1) {
42
0
        flb_free(ctx);
43
0
        return NULL;
44
0
    }
45
46
0
    if (!ctx->query_str) {
47
0
        flb_plg_error(ctx->ins, "no SQL query provided");
48
0
        flb_free(ctx);
49
0
        return NULL;
50
0
    }
51
52
    /* create query context */
53
0
    ctx->query = sql_parser_query_create(ctx->query_str);
54
0
    if (!ctx->query) {
55
0
        flb_plg_error(ctx->ins, "failed to parse SQL query: %s", ctx->query_str);
56
0
        flb_free(ctx);
57
0
        return NULL;
58
0
    }
59
60
0
    return ctx;
61
0
}
62
63
void sql_config_destroy(struct sql_ctx *ctx)
64
0
{
65
0
    if (ctx->query) {
66
0
        sql_parser_query_destroy(ctx->query);
67
0
    }
68
69
0
    flb_free(ctx);
70
0
}
71