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 " http.hpp"
14+
15+ #include " common.hpp"
16+
3017#include < cstdlib>
3118#include < cstring>
3219#include < iostream>
3320
21+ #include < ipfixprobe/pluginFactory/pluginManifest.hpp>
22+ #include < ipfixprobe/pluginFactory/pluginRegistrar.hpp>
23+
3424#ifdef WITH_NEMEA
3525#include < unirec/unirec.h>
3626#endif
3727
38- #include " common.hpp"
39- #include " http.hpp"
40-
4128namespace ipxp {
4229
43- int RecordExtHTTP::REGISTERED_ID = - 1 ;
30+ int RecordExtHTTP::REGISTERED_ID = ProcessPluginIDGenerator::instance().generatePluginID() ;
4431
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- }
32+ static const PluginManifest httpPluginManifest = {
33+ .name = " http" ,
34+ .description = " http process plugin for parsing http traffic." ,
35+ .pluginVersion = " 1.0.0" ,
36+ .apiVersion = " 1.0.0" ,
37+ .usage = nullptr ,
38+ };
5139
5240// #define DEBUG_HTTP
5341
@@ -70,21 +58,25 @@ __attribute__((constructor)) static void register_this_plugin()
7058#define HTTP_SETCOOKIE_NAME_DELIMITER " ="
7159#define STRING_DELIMITER " ;"
7260
73- HTTPPlugin::HTTPPlugin ()
61+ HTTPPlugin::HTTPPlugin (const std::string& params )
7462 : recPrealloc(nullptr )
7563 , flow_flush(false )
7664 , requests(0 )
7765 , responses(0 )
7866 , total(0 )
7967{
68+ init (params.c_str ());
8069}
8170
8271HTTPPlugin::~HTTPPlugin ()
8372{
8473 close ();
8574}
8675
87- void HTTPPlugin::init (const char * params) {}
76+ void HTTPPlugin::init (const char * params)
77+ {
78+ (void ) params;
79+ }
8880
8981void HTTPPlugin::close ()
9082{
@@ -154,34 +146,6 @@ void HTTPPlugin::finish(bool print_stats)
154146 }
155147}
156148
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-
185149/* *
186150 * \brief Add delimiter and string at the end of destination buffer if is it empty add only string
187151 * and append \0 character. NOTE: function removes any CR chars at the end of string. \param [in]
@@ -650,4 +614,6 @@ void HTTPPlugin::add_ext_http_response(const char* data, int payload_len, Flow&
650614 }
651615}
652616
617+ static const PluginRegistrar<HTTPPlugin, ProcessPluginFactory> httpRegistrar (httpPluginManifest);
618+
653619} // namespace ipxp
0 commit comments