/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Fluent Bit * ========== * Copyright (C) 2019 The Fluent Bit Authors * Copyright (C) 2015-2018 Treasure Data Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include "tcp.h" #include "tcp_conf.h" struct flb_out_tcp *flb_tcp_conf_create(struct flb_output_instance *ins, struct flb_config *config) { int ret; int io_flags = 0; const char *tmp; struct flb_upstream *upstream; struct flb_out_tcp *ctx = NULL; /* Allocate plugin context */ ctx = flb_calloc(1, sizeof(struct flb_out_tcp)); if (!ctx) { flb_errno(); return NULL; } /* Set default network configuration if not set */ flb_output_net_default("127.0.0.1", 5170, ins); /* Check if SSL/TLS is enabled */ #ifdef FLB_HAVE_TLS if (ins->use_tls == FLB_TRUE) { io_flags = FLB_IO_TLS; } else { io_flags = FLB_IO_TCP; } #else io_flags = FLB_IO_TCP; #endif if (ins->host.ipv6 == FLB_TRUE) { io_flags |= FLB_IO_IPV6; } /* Upstream context */ upstream = flb_upstream_create(config, ins->host.name, ins->host.port, io_flags, (void *) &ins->tls); if (!upstream) { flb_error("[out_tcp] could not create upstream context"); flb_free(ctx); return NULL; } /* Output format */ ctx->out_format = FLB_PACK_JSON_FORMAT_NONE; tmp = flb_output_get_property("format", ins); if (tmp) { ret = flb_pack_to_json_format_type(tmp); if (ret == -1) { flb_error("[out_tcp] unrecognized 'format' option '%s'. " "Using 'msgpack'", tmp); } else { ctx->out_format = ret; } } /* Date format for JSON output */ ctx->json_date_format = FLB_PACK_JSON_DATE_DOUBLE; tmp = flb_output_get_property("json_date_format", ins); if (tmp) { ret = flb_pack_to_json_date_type(tmp); if (ret == -1) { flb_error("[out_tcp] unrecognized 'json_date_format' option '%s'. " "Using 'double'", tmp); } else { ctx->json_date_format = ret; } } /* Date key for JSON output */ tmp = flb_output_get_property("json_date_key", ins); if (tmp) { ctx->json_date_key = flb_sds_create(tmp); } else { ctx->json_date_key = flb_sds_create("date"); } ctx->u = upstream; ctx->host = ins->host.name; ctx->port = ins->host.port; return ctx; } void flb_tcp_conf_destroy(struct flb_out_tcp *ctx) { if (!ctx) { return; } if (ctx->u) { flb_upstream_destroy(ctx->u); } if (ctx->json_date_key) { flb_sds_destroy(ctx->json_date_key); } flb_free(ctx); ctx = NULL; }