-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
in_http: add HTTP input plugin (#18)
Signed-off-by: Eduardo Silva <[email protected]>
- Loading branch information
Showing
14 changed files
with
844 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,8 @@ | ||
set(src | ||
in_http.c) | ||
|
||
FLB_PLUGIN(in_http "${src}" "") | ||
target_link_libraries(flb-plugin-in_http | ||
monkey-core-static | ||
${CMAKE_DL_LIBS}) | ||
|
||
# Configuration files | ||
# =================== | ||
# Default values for conf/in_http.conf | ||
|
||
set(MK_CONF_LISTEN "8080") | ||
set(MK_CONF_WORKERS "1") | ||
set(MK_CONF_TIMEOUT "15") | ||
set(MK_CONF_INDEXFILE "index.html index.htm index.php") | ||
set(MK_CONF_HIDEVERSION "Off") | ||
set(MK_CONF_RESUME "On") | ||
set(MK_CONF_KA "On") | ||
set(MK_CONF_KA_TIMEOUT "5") | ||
set(MK_CONF_KA_MAXREQ "1000") | ||
set(MK_CONF_REQ_SIZE "32") | ||
set(MK_CONF_SYMLINK "Off") | ||
set(MK_CONF_TRANSPORT "liana") | ||
set(MK_CONF_DEFAULT_MIME "text/plain") | ||
set(MK_CONF_FDT "On") | ||
set(MK_CONF_OVERCAPACITY "Resist") | ||
|
||
# Virtual Host | ||
# ============ | ||
set(MK_VH_SERVERNAME "127.0.0.1") | ||
set(MK_PATH_WWW "${PROJECT_SOURCE_DIR}/lib/monkey/htdocs") | ||
set(IN_HTTP_CONF_PATH "${PROJECT_BINARY_DIR}/conf/") | ||
|
||
configure_file( | ||
"in_http_info.h.in" | ||
"${PROJECT_SOURCE_DIR}/plugins/in_http/in_http_info.h" | ||
http.c | ||
http_conn.c | ||
http_prot.c | ||
http_config.c | ||
) | ||
|
||
configure_file( | ||
"conf/in_http.conf.in" | ||
"${PROJECT_BINARY_DIR}/conf/in_http.conf" | ||
) | ||
|
||
configure_file( | ||
"conf/sites/default.in" | ||
"${PROJECT_BINARY_DIR}/conf/sites/default" | ||
) | ||
|
||
configure_file( | ||
"conf/mimetypes.conf.in" | ||
"${PROJECT_BINARY_DIR}/conf/mimetypes.conf" | ||
) | ||
FLB_PLUGIN(in_http "${src}" "") |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
|
||
/* Fluent Bit | ||
* ========== | ||
* Copyright (C) 2019-2020 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 <fluent-bit/flb_input_plugin.h> | ||
#include <fluent-bit/flb_network.h> | ||
#include <fluent-bit/flb_config.h> | ||
|
||
#include "http.h" | ||
#include "http_conn.h" | ||
#include "http_config.h" | ||
|
||
/* | ||
* For a server event, the collection event means a new client have arrived, we | ||
* accept the connection and create a new TCP instance which will wait for | ||
* JSON map messages. | ||
*/ | ||
static int in_http_collect(struct flb_input_instance *ins, | ||
struct flb_config *config, void *in_context) | ||
{ | ||
int fd; | ||
struct flb_http *ctx = in_context; | ||
struct http_conn *conn; | ||
|
||
/* Accept the new connection */ | ||
fd = flb_net_accept(ctx->server_fd); | ||
if (fd == -1) { | ||
flb_plg_error(ctx->ins, "could not accept new connection"); | ||
return -1; | ||
} | ||
|
||
flb_plg_trace(ctx->ins, "new TCP connection arrived FD=%i", fd); | ||
conn = http_conn_add(fd, ctx); | ||
if (!conn) { | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
|
||
static int in_http_init(struct flb_input_instance *ins, | ||
struct flb_config *config, void *data) | ||
{ | ||
int ret; | ||
struct flb_http *ctx; | ||
|
||
/* Create context and basic conf */ | ||
ctx = http_config_create(ins); | ||
if (!ctx) { | ||
return -1; | ||
} | ||
|
||
/* Set the context */ | ||
flb_input_set_context(ins, ctx); | ||
|
||
ctx->evl = config->evl; | ||
|
||
/* Create HTTP listener */ | ||
ctx->server_fd = flb_net_server(ctx->tcp_port, ctx->listen); | ||
if (ctx->server_fd > 0) { | ||
flb_plg_info(ctx->ins, "listening on %s:%s", ctx->listen, ctx->tcp_port); | ||
} | ||
else { | ||
flb_plg_error(ctx->ins, "could not bind address %s:%s. Aborting", | ||
ctx->listen, ctx->tcp_port); | ||
http_config_destroy(ctx); | ||
return -1; | ||
} | ||
|
||
/* Set the socket non-blocking */ | ||
flb_net_socket_nonblocking(ctx->server_fd); | ||
|
||
/* Collect upon data available on the standard input */ | ||
ret = flb_input_set_collector_socket(ins, | ||
in_http_collect, | ||
ctx->server_fd, | ||
config); | ||
if (ret == -1) { | ||
flb_plg_error(ctx->ins, "Could not set collector for IN_TCP input plugin"); | ||
http_config_destroy(ctx); | ||
return -1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static int in_http_exit(void *data, struct flb_config *config) | ||
{ | ||
struct flb_http *ctx = data; | ||
(void) config; | ||
|
||
if (!ctx) { | ||
return 0; | ||
} | ||
|
||
http_config_destroy(ctx); | ||
return 0; | ||
} | ||
|
||
/* Configuration properties map */ | ||
static struct flb_config_map config_map[] = { | ||
{ | ||
FLB_CONFIG_MAP_SIZE, "buffer_max_size", HTTP_BUFFER_MAX_SIZE, | ||
0, FLB_TRUE, offsetof(struct flb_http, buffer_max_size), | ||
"" | ||
}, | ||
|
||
{ | ||
FLB_CONFIG_MAP_SIZE, "buffer_chunk_size", HTTP_BUFFER_CHUNK_SIZE, | ||
0, FLB_TRUE, offsetof(struct flb_http, buffer_chunk_size), | ||
"" | ||
}, | ||
|
||
/* EOF */ | ||
{0} | ||
}; | ||
|
||
/* Plugin reference */ | ||
struct flb_input_plugin in_http_plugin = { | ||
.name = "http", | ||
.description = "HTTP", | ||
.cb_init = in_http_init, | ||
.cb_pre_run = NULL, | ||
.cb_collect = in_http_collect, | ||
.cb_flush_buf = NULL, | ||
.cb_pause = NULL, | ||
.cb_resume = NULL, | ||
.cb_exit = in_http_exit, | ||
.config_map = config_map, | ||
.flags = FLB_INPUT_NET, | ||
}; |
Oops, something went wrong.