Coverage Report

Created: 2023-03-26 07:01

/src/fluent-bit/plugins/in_http/http_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-2022 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_input_plugin.h>
21
22
#include "http.h"
23
#include "http_conn.h"
24
25
struct flb_http *http_config_create(struct flb_input_instance *ins)
26
0
{
27
0
    int ret;
28
0
    char port[8];
29
0
    struct flb_http *ctx;
30
31
0
    ctx = flb_calloc(1, sizeof(struct flb_http));
32
0
    if (!ctx) {
33
0
        flb_errno();
34
0
        return NULL;
35
0
    }
36
0
    ctx->ins = ins;
37
0
    mk_list_init(&ctx->connections);
38
39
    /* Load the config map */
40
0
    ret = flb_input_config_map_set(ins, (void *) ctx);
41
0
    if (ret == -1) {
42
0
        flb_free(ctx);
43
0
        return NULL;
44
0
    }
45
46
    /* Listen interface (if not set, defaults to 0.0.0.0:9880) */
47
0
    flb_input_net_default_listener("0.0.0.0", 9880, ins);
48
49
0
    ctx->listen = flb_strdup(ins->host.listen);
50
0
    snprintf(port, sizeof(port) - 1, "%d", ins->host.port);
51
0
    ctx->tcp_port = flb_strdup(port);
52
53
    /* HTTP Server specifics */
54
0
    ctx->server = flb_calloc(1, sizeof(struct mk_server));
55
0
    ctx->server->keep_alive = MK_TRUE;
56
57
    /* monkey detects server->workers == 0 as the server not being initialized at the
58
     * moment so we want to make sure that it stays that way!
59
     */
60
61
0
    return ctx;
62
0
}
63
64
int http_config_destroy(struct flb_http *ctx)
65
0
{
66
    /* release all connections */
67
0
    http_conn_release_all(ctx);
68
69
0
    if (ctx->collector_id != -1) {
70
0
        flb_input_collector_delete(ctx->collector_id, ctx->ins);
71
72
0
        ctx->collector_id = -1;
73
0
    }
74
75
0
    if (ctx->downstream != NULL) {
76
0
        flb_downstream_destroy(ctx->downstream);
77
0
    }
78
79
0
    if (ctx->server) {
80
0
        flb_free(ctx->server);
81
0
    }
82
0
    flb_free(ctx->listen);
83
0
    flb_free(ctx->tcp_port);
84
0
    flb_free(ctx);
85
0
    return 0;
86
0
}