Skip to content

Commit e2c6956

Browse files
author
Pavel Siska
committed
ipfixprobe - introduce process HTTP plugin
1 parent cacb7ad commit e2c6956

File tree

5 files changed

+60
-94
lines changed

5 files changed

+60
-94
lines changed

src/plugins/process/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ add_subdirectory(passiveDns)
2020
add_subdirectory(smtp)
2121
add_subdirectory(quic)
2222
add_subdirectory(tls)
23+
add_subdirectory(http)
2324

2425
if (ENABLE_PROCESS_EXPERIMENTAL)
2526
add_subdirectory(sip)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
project(ipfixprobe-process-http VERSION 1.0.0 DESCRIPTION "ipfixprobe-process-http plugin")
2+
3+
add_library(ipfixprobe-process-http MODULE
4+
src/http.cpp
5+
src/http.hpp
6+
)
7+
8+
set_target_properties(ipfixprobe-process-http PROPERTIES
9+
CXX_VISIBILITY_PRESET hidden
10+
VISIBILITY_INLINES_HIDDEN YES
11+
)
12+
13+
target_include_directories(ipfixprobe-process-http PRIVATE
14+
${CMAKE_SOURCE_DIR}/include/
15+
${CMAKE_SOURCE_DIR}/src/plugins/process/common
16+
)
17+
18+
install(TARGETS ipfixprobe-process-http
19+
LIBRARY DESTINATION "${INSTALL_DIR_LIB}/ipfixprobe/process/"
20+
)

src/plugins/process/http/README.md

Whitespace-only changes.
Lines changed: 29 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,40 @@
11
/**
2-
* \file http.cpp
3-
* \brief Plugin for parsing HTTP traffic
4-
* \author Jiri Havranek <[email protected]>
5-
* \date 2015
6-
* \date 2016
7-
*/
8-
/*
9-
* Copyright (C) 2014-2016 CESNET
10-
*
11-
* LICENSE TERMS
12-
*
13-
* Redistribution and use in source and binary forms, with or without
14-
* modification, are permitted provided that the following conditions
15-
* are met:
16-
* 1. Redistributions of source code must retain the above copyright
17-
* notice, this list of conditions and the following disclaimer.
18-
* 2. Redistributions in binary form must reproduce the above copyright
19-
* notice, this list of conditions and the following disclaimer in
20-
* the documentation and/or other materials provided with the
21-
* distribution.
22-
* 3. Neither the name of the Company nor the names of its contributors
23-
* may be used to endorse or promote products derived from this
24-
* software without specific prior written permission.
25-
*
2+
* @file
3+
* @brief Plugin for parsing HTTP traffic.
4+
* @author Jiri Havranek <[email protected]>
5+
* @author Pavel Siska <[email protected]>
6+
* @date 2025
267
*
8+
* Copyright (c) 2025 CESNET
279
*
10+
* SPDX-License-Identifier: BSD-3-Clause
2811
*/
2912

13+
#include "common.hpp"
14+
#include "http.hpp"
15+
3016
#include <cstdlib>
3117
#include <cstring>
3218
#include <iostream>
3319

20+
#include <ipfixprobe/pluginFactory/pluginManifest.hpp>
21+
#include <ipfixprobe/pluginFactory/pluginRegistrar.hpp>
22+
3423
#ifdef WITH_NEMEA
3524
#include <unirec/unirec.h>
3625
#endif
3726

38-
#include "common.hpp"
39-
#include "http.hpp"
40-
4127
namespace ipxp {
4228

43-
int RecordExtHTTP::REGISTERED_ID = -1;
29+
int RecordExtHTTP::REGISTERED_ID = ProcessPluginIDGenerator::instance().generatePluginID();
4430

45-
__attribute__((constructor)) static void register_this_plugin()
46-
{
47-
static PluginRecord rec = PluginRecord("http", []() { return new HTTPPlugin(); });
48-
register_plugin(&rec);
49-
RecordExtHTTP::REGISTERED_ID = register_extension();
50-
}
31+
static const PluginManifest httpPluginManifest = {
32+
.name = "http",
33+
.description = "http process plugin for parsing http traffic.",
34+
.pluginVersion = "1.0.0",
35+
.apiVersion = "1.0.0",
36+
.usage = nullptr,
37+
};
5138

5239
// #define DEBUG_HTTP
5340

@@ -70,21 +57,25 @@ __attribute__((constructor)) static void register_this_plugin()
7057
#define HTTP_SETCOOKIE_NAME_DELIMITER "="
7158
#define STRING_DELIMITER ";"
7259

73-
HTTPPlugin::HTTPPlugin()
60+
HTTPPlugin::HTTPPlugin(const std::string& params)
7461
: recPrealloc(nullptr)
7562
, flow_flush(false)
7663
, requests(0)
7764
, responses(0)
7865
, total(0)
7966
{
67+
init(params.c_str());
8068
}
8169

8270
HTTPPlugin::~HTTPPlugin()
8371
{
8472
close();
8573
}
8674

87-
void HTTPPlugin::init(const char* params) {}
75+
void HTTPPlugin::init(const char* params)
76+
{
77+
(void) params;
78+
}
8879

8980
void HTTPPlugin::close()
9081
{
@@ -154,34 +145,6 @@ void HTTPPlugin::finish(bool print_stats)
154145
}
155146
}
156147

157-
/**
158-
* \brief Copy string and append \0 character.
159-
* NOTE: function removes any CR chars at the end of string.
160-
* \param [in] dst Destination buffer.
161-
* \param [in] size Size of destination buffer.
162-
* \param [in] begin Ptr to begin of source string.
163-
* \param [in] end Ptr to end of source string.
164-
*/
165-
void copy_str(char* dst, ssize_t size, const char* begin, const char* end)
166-
{
167-
ssize_t len = end - begin;
168-
if (len >= size) {
169-
len = size - 1;
170-
}
171-
172-
memcpy(dst, begin, len);
173-
174-
if (len >= 1 && dst[len - 1] == '\n') {
175-
len--;
176-
}
177-
178-
if (len >= 1 && dst[len - 1] == '\r') {
179-
len--;
180-
}
181-
182-
dst[len] = 0;
183-
}
184-
185148
/**
186149
* \brief Add delimiter and string at the end of destination buffer if is it empty add only string
187150
* and append \0 character. NOTE: function removes any CR chars at the end of string. \param [in]
@@ -650,4 +613,6 @@ void HTTPPlugin::add_ext_http_response(const char* data, int payload_len, Flow&
650613
}
651614
}
652615

616+
static const PluginRegistrar<HTTPPlugin, ProcessPluginFactory> httpRegistrar(httpPluginManifest);
617+
653618
} // namespace ipxp
Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,16 @@
11
/**
2-
* \file http.hpp
3-
* \brief Plugin for parsing HTTP traffic
4-
* \author Jiri Havranek <[email protected]>
5-
* \date 2015
6-
* \date 2016
7-
*/
8-
/*
9-
* Copyright (C) 2014-2016 CESNET
10-
*
11-
* LICENSE TERMS
12-
*
13-
* Redistribution and use in source and binary forms, with or without
14-
* modification, are permitted provided that the following conditions
15-
* are met:
16-
* 1. Redistributions of source code must retain the above copyright
17-
* notice, this list of conditions and the following disclaimer.
18-
* 2. Redistributions in binary form must reproduce the above copyright
19-
* notice, this list of conditions and the following disclaimer in
20-
* the documentation and/or other materials provided with the
21-
* distribution.
22-
* 3. Neither the name of the Company nor the names of its contributors
23-
* may be used to endorse or promote products derived from this
24-
* software without specific prior written permission.
25-
*
2+
* @file
3+
* @brief Plugin for parsing HTTP traffic.
4+
* @author Jiri Havranek <[email protected]>
5+
* @author Pavel Siska <[email protected]>
6+
* @date 2025
267
*
8+
* Copyright (c) 2025 CESNET
279
*
10+
* SPDX-License-Identifier: BSD-3-Clause
2811
*/
2912

30-
#ifndef IPXP_PROCESS_HTTP_HPP
31-
#define IPXP_PROCESS_HTTP_HPP
13+
#pragma once
3214

3315
#include <cstdlib>
3416
#include <cstring>
@@ -42,7 +24,7 @@
4224
#include <ipfixprobe/flowifc.hpp>
4325
#include <ipfixprobe/ipfix-elements.hpp>
4426
#include <ipfixprobe/packet.hpp>
45-
#include <ipfixprobe/process.hpp>
27+
#include <ipfixprobe/processPlugin.hpp>
4628
#include <ipfixprobe/utils.hpp>
4729

4830
namespace ipxp {
@@ -64,7 +46,6 @@ UR_FIELDS(
6446
string HTTP_RESPONSE_SERVER,
6547
string HTTP_RESPONSE_SET_COOKIE_NAMES)
6648

67-
void copy_str(char* dst, ssize_t size, const char* begin, const char* end);
6849
void add_str(char* dst, ssize_t size, const char* begin, const char* end, const char* delimiter);
6950

7051
/**
@@ -210,7 +191,7 @@ struct RecordExtHTTP : public RecordExt {
210191
*/
211192
class HTTPPlugin : public ProcessPlugin {
212193
public:
213-
HTTPPlugin();
194+
HTTPPlugin(const std::string& params);
214195
~HTTPPlugin();
215196
void init(const char* params);
216197
void close();
@@ -241,4 +222,3 @@ class HTTPPlugin : public ProcessPlugin {
241222
};
242223

243224
} // namespace ipxp
244-
#endif /* IPXP_PROCESS_HTTP_HPP */

0 commit comments

Comments
 (0)