...@@ -15,11 +15,17 @@ ...@@ -15,11 +15,17 @@
namespace LibItsPki__Functions { namespace LibItsPki__Functions {
INTEGER fx__get__root__ca__certificate(const CHARSTRING& p__iut_certificate, const BOOLEAN& p__explicit_type, OCTETSTRING& p__certificate) { INTEGER fx__get__root__ca__certificate(const CHARSTRING &p__iut_certificate, const BOOLEAN &p__explicit_type, OCTETSTRING &p__certificate) {
loggers::get_instance().log_msg(">>> fx__get__root__ca__certificate: ", p__iut_certificate); loggers::get_instance().log_msg(">>> fx__get__root__ca__certificate: ", p__iut_certificate);
CHARSTRING c("800300810038811b45545349205465737420524341204320636572746966696361746500000000001e19cf808466a8c001028002026e810201018002027081030201380102a080010f80012482080301fffc03ff0003800125820a0401ffffff04ff00000080018982060201e002ff1f80018a82060201c002ff3f80018b820e0601000000fff806ff000000000780018c820a0401ffffe004ff00001f8002027d8204010101ff00018d0001600001610001620001630001640001650001660102c0208001018002026f82060201fe02ff01c0808083ee2cb68fe4618d3aff28e38b8ebdd1875221ee686c36434cc5c3d7829402d4df80805204e6e5a7fd85f9f2044a5e57646a89d0ab73e1413dda9615456fa1ea1ddf9d483451a36b7116bbc4f8fe9b4bb54478d4195c95b083ab80d77098a86f17e088"); // CERT_IUT_A_RCA CHARSTRING c("800300810038811b45545349205465737420524341204320636572746966696361746500000000001e19cf808466a8c001028002026e810201018002027081030201380102a08"
//CHARSTRING c("800300810079811b45545349205465737420524341204320636572746966696361746500000000001e19cf808466a88101011a0645a1042d654819f89082043b1a67c001028002026e810201018002027081030201380101a080010980012482080301fffc03ff0003800125820a0401ffffff04ff00000080018982060201e002ff1f80018a82060201c002ff3f80018b820e0601000000fff806ff000000000780018c820a0401ffffe004ff00001f8002027d8204010101ff00018d8002026f82060201fe02ff010102c0008082cab9d2e83ba971bcc5c7295ffcc4b98ca415745cf03c230d6b79a7afafeadfa38080828b5146c0160df69389e5b26e4a8a25e1ff0141c577cc24eb1626184995513f3f808068c5ab4b07fa9eef841e1d6471a310eb35333520273a6ca1cca4126b32a128d5ef56aed4439046ca0263e28c5bdd459a382837c3c97af9fd150640c44910fdbc"); // CERT_IUT_C_RCA "0010f80012482080301fffc03ff0003800125820a0401ffffff04ff00000080018982060201e002ff1f80018a82060201c002ff3f80018b820e0601000000fff806ff00000000"
"0780018c820a0401ffffe004ff00001f8002027d8204010101ff00018d0001600001610001620001630001640001650001660102c0208001018002026f82060201fe02ff01c08"
"08083ee2cb68fe4618d3aff28e38b8ebdd1875221ee686c36434cc5c3d7829402d4df80805204e6e5a7fd85f9f2044a5e57646a89d0ab73e1413dda9615456fa1ea1ddf9d4834"
"51a36b7116bbc4f8fe9b4bb54478d4195c95b083ab80d77098a86f17e088"); // CERT_IUT_A_RCA
// CHARSTRING
// c("800300810079811b45545349205465737420524341204320636572746966696361746500000000001e19cf808466a88101011a0645a1042d654819f89082043b1a67c001028002026e810201018002027081030201380101a080010980012482080301fffc03ff0003800125820a0401ffffff04ff00000080018982060201e002ff1f80018a82060201c002ff3f80018b820e0601000000fff806ff000000000780018c820a0401ffffe004ff00001f8002027d8204010101ff00018d8002026f82060201fe02ff010102c0008082cab9d2e83ba971bcc5c7295ffcc4b98ca415745cf03c230d6b79a7afafeadfa38080828b5146c0160df69389e5b26e4a8a25e1ff0141c577cc24eb1626184995513f3f808068c5ab4b07fa9eef841e1d6471a310eb35333520273a6ca1cca4126b32a128d5ef56aed4439046ca0263e28c5bdd459a382837c3c97af9fd150640c44910fdbc");
// // CERT_IUT_C_RCA
p__certificate = str2oct(c); p__certificate = str2oct(c);
return 0; return 0;
} }
......
This diff is collapsed.
sources := LibItsCommon_externals.cc \ sources := LibItsCommon_externals.cc \
LibItsGeoNetworking_externals.cc \ LibItsGeoNetworking_externals.cc \
LibItsIpv6OverGeoNetworking_externals.cc \
LibItsSecurity_externals.cc \ LibItsSecurity_externals.cc \
LibItsPki_externals.cc LibItsIpv6OverGeoNetworking_externals.cc
ifeq (AtsPki, $(ATS))
sources += LibItsPki_externals.cc
endif
ifeq (AtsRSUsSimulator, $(ATS)) ifeq (AtsRSUsSimulator, $(ATS))
sources += LibItsPki_externals.cc
sources += AtsRSUsSimulator_externals.cc sources += AtsRSUsSimulator_externals.cc
endif endif
# LibItsDcc_externals.cc \ # LibItsDcc_externals.cc \
...@@ -21,13 +21,17 @@ class base_time { ...@@ -21,13 +21,17 @@ class base_time {
unsigned long long leap_delay; unsigned long long leap_delay;
static base_time* _instance; static base_time *_instance;
private: private:
base_time(): leap_delay{0} { }; //! Can not be created manually base_time() : leap_delay{0} {}; //! Can not be created manually
public: public:
static inline base_time& get_instance(); static inline base_time &get_instance();
virtual ~base_time() { if (_instance != nullptr) delete _instance; }; virtual ~base_time() {
if (_instance != nullptr)
delete _instance;
};
public: public:
inline const unsigned long long get_current_time_ms() const; inline const unsigned long long get_current_time_ms() const;
...@@ -40,34 +44,30 @@ public: ...@@ -40,34 +44,30 @@ public:
}; // End of class base_time }; // End of class base_time
// static functions // static functions
base_time& base_time::get_instance() { base_time &base_time::get_instance() { return (_instance != nullptr) ? *_instance : *(_instance = new base_time()); }
return (_instance != nullptr) ? *_instance : *(_instance = new base_time());
}
const unsigned long long base_time::get_current_time_ms() const { const unsigned long long base_time::get_current_time_ms() const {
return (leap_delay / 1000) + std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); return (leap_delay / 1000) + std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
} }
const unsigned long long base_time::get_its_base_time_ms() const { const unsigned long long base_time::get_its_base_time_ms() const { return base_time::its_base_time_ms; }
return base_time::its_base_time_ms;
}
const unsigned long long base_time::get_its_current_time_ms() const { const unsigned long long base_time::get_its_current_time_ms() const {
return (leap_delay / 1000) + std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - base_time::its_base_time_ms; return (leap_delay / 1000) + std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() -
base_time::its_base_time_ms;
} }
const unsigned long long base_time::get_its_current_time_us() const { const unsigned long long base_time::get_its_current_time_us() const {
return leap_delay + std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - base_time::its_base_time_ms * 1000; return leap_delay + std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count() -
base_time::its_base_time_ms * 1000;
} }
const unsigned long long base_time::get_its_current_time_mod_ms() const { const unsigned long long base_time::get_its_current_time_mod_ms() const {
return ((leap_delay / 1000) + std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - base_time::its_base_time_ms) % 65536; return ((leap_delay / 1000) + std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() -
base_time::its_base_time_ms) %
65536;
} }
void base_time::set_leap_delay_us(const unsigned long long p_leap_delay) { void base_time::set_leap_delay_us(const unsigned long long p_leap_delay) { leap_delay = p_leap_delay; }
leap_delay = p_leap_delay;
}
inline const unsigned long long base_time::get_leap_delay_us() const { inline const unsigned long long base_time::get_leap_delay_us() const { return leap_delay; }
return leap_delay;
}
...@@ -21,10 +21,9 @@ class BITSTRING; //! Declare TITAN class ...@@ -21,10 +21,9 @@ class BITSTRING; //! Declare TITAN class
* \brief This class provides the interface for all ITS codecs, include UT and AC codecs * \brief This class provides the interface for all ITS codecs, include UT and AC codecs
* \abstract * \abstract
*/ */
template<typename TPDUEnc, typename TPDUDec> template <typename TPDUEnc, typename TPDUDec> class codec {
class codec {
protected: protected:
params* _params; //! Reference to params stack params *_params; //! Reference to params stack
// \todo Use smart pointer std::unique_ptr<params> // \todo Use smart pointer std::unique_ptr<params>
public: //! \publicsection public: //! \publicsection
...@@ -33,14 +32,14 @@ public: //! \publicsection ...@@ -33,14 +32,14 @@ public: //! \publicsection
* \brief Default constructor * \brief Default constructor
* \todo Remove logs * \todo Remove logs
*/ */
explicit codec() : _params(nullptr) { }; explicit codec() : _params(nullptr){};
/*! /*!
* \fn ~codec(); * \fn ~codec();
* \brief Default destructor * \brief Default destructor
* \virtual * \virtual
* \todo Remove logs * \todo Remove logs
*/ */
virtual ~codec() { }; virtual ~codec(){};
/*! /*!
* \fn int encode(const TPDUEnc& msg, OCTETSTRING& data); * \fn int encode(const TPDUEnc& msg, OCTETSTRING& data);
* \brief Encode typed message into an octet string * \brief Encode typed message into an octet string
...@@ -49,7 +48,7 @@ public: //! \publicsection ...@@ -49,7 +48,7 @@ public: //! \publicsection
* \return 0 on success, -1 otherwise * \return 0 on success, -1 otherwise
* \pure * \pure
*/ */
virtual int encode(const TPDUEnc& p_message, OCTETSTRING& p_data) = 0; virtual int encode(const TPDUEnc &p_message, OCTETSTRING &p_data) = 0;
/*! /*!
* \fn int decode(const OCTETSTRING& p_, TPDUDec& p_message, params* p_params = NULL); * \fn int decode(const OCTETSTRING& p_, TPDUDec& p_message, params* p_params = NULL);
* \brief Encode typed message into an octet string format * \brief Encode typed message into an octet string format
...@@ -58,6 +57,5 @@ public: //! \publicsection ...@@ -58,6 +57,5 @@ public: //! \publicsection
* \return 0 on success, -1 otherwise * \return 0 on success, -1 otherwise
* \pure * \pure
*/ */
virtual int decode(const OCTETSTRING& p_, TPDUDec& p_message, params* p_params = NULL) = 0; virtual int decode(const OCTETSTRING &p_, TPDUDec &p_message, params *p_params = NULL) = 0;
}; // End of class codec }; // End of class codec
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
*/ */
#pragma once #pragma once
#include <string> #include <algorithm>
#include <map> #include <map>
#include <string>
#include <vector> #include <vector>
#include <algorithm>
#include "codec.hh" #include "codec.hh"
...@@ -30,7 +30,7 @@ public: //! \publicsection ...@@ -30,7 +30,7 @@ public: //! \publicsection
* \fn codec(); * \fn codec();
* \brief Default constructor * \brief Default constructor
*/ */
codec_factory() { }; codec_factory(){};
/*! /*!
* \fn codec* create_codec(const std::string & type, const std::string & param); * \fn codec* create_codec(const std::string & type, const std::string & param);
* \brief Create the codecs stack based on the provided codecs stack description (cf. remark) * \brief Create the codecs stack based on the provided codecs stack description (cf. remark)
...@@ -41,6 +41,5 @@ public: //! \publicsection ...@@ -41,6 +41,5 @@ public: //! \publicsection
* HTTP(codecs=xml:held_codec;html:html_codec,json:json_codec)/TCP(debug=1,server=httpbin.org,port=80,use_ssl=0) * HTTP(codecs=xml:held_codec;html:html_codec,json:json_codec)/TCP(debug=1,server=httpbin.org,port=80,use_ssl=0)
* \pure * \pure
*/ */
virtual codec<Record_Type, Record_Type>* create_codec() = 0; virtual codec<Record_Type, Record_Type> *create_codec() = 0;
}; // End of class codec_factory }; // End of class codec_factory
...@@ -20,22 +20,22 @@ class Record_Type; //! TITAN forward declaration ...@@ -20,22 +20,22 @@ class Record_Type; //! TITAN forward declaration
*/ */
class codec_stack_builder { class codec_stack_builder {
private: //! \privatesection private: //! \privatesection
static codec_stack_builder* _instance; //! Smart pointer to the unique instance of the logger framework static codec_stack_builder * _instance; //! Smart pointer to the unique instance of the logger framework
std::map<std::string, codec_factory*> _codecs; //! The list of the registered \see t_codec factories std::map<std::string, codec_factory *> _codecs; //! The list of the registered \see t_codec factories
/*! /*!
* \brief Default constructor * \brief Default constructor
* Create a new instance of the codec_stack_builder class * Create a new instance of the codec_stack_builder class
* \private * \private
*/ */
codec_stack_builder() { }; // can not be created manually codec_stack_builder(){}; // can not be created manually
public: //! \publicsection public: //! \publicsection
/*! /*!
* \fn codec_stack_builder* get_instance(); * \fn codec_stack_builder* get_instance();
* \brief Accessor for the unique instance of the logger framework * \brief Accessor for the unique instance of the logger framework
* \static * \static
*/ */
static codec_stack_builder* get_instance() { return _instance ? _instance : _instance = new codec_stack_builder(); }; static codec_stack_builder *get_instance() { return _instance ? _instance : _instance = new codec_stack_builder(); };
/*! /*!
* \fn void register_codec_factory(const std::string & p_type, codec_factory<TPDUEnc, TPDUDec>* p_codec_factory); * \fn void register_codec_factory(const std::string & p_type, codec_factory<TPDUEnc, TPDUDec>* p_codec_factory);
...@@ -44,7 +44,9 @@ public: //! \publicsection ...@@ -44,7 +44,9 @@ public: //! \publicsection
* \param[in] p_codec_factory A reference to the \see codec_factory * \param[in] p_codec_factory A reference to the \see codec_factory
* \static * \static
*/ */
static void register_codec_factory(const std::string & p_type, codec_factory* p_codec_factory) { codec_stack_builder::get_instance()->_register_codec_factory(p_type, p_codec_factory); }; static void register_codec_factory(const std::string &p_type, codec_factory *p_codec_factory) {
codec_stack_builder::get_instance()->_register_codec_factory(p_type, p_codec_factory);
};
private: //! \privatesection private: //! \privatesection
/*! /*!
...@@ -53,7 +55,7 @@ private: //! \privatesection ...@@ -53,7 +55,7 @@ private: //! \privatesection
* \param[in] p_type The codec identifier (e.g. GN for the GeoNetworking codec...) * \param[in] p_type The codec identifier (e.g. GN for the GeoNetworking codec...)
* \param[in] p_codec_factory A reference to the \see codec_factory * \param[in] p_codec_factory A reference to the \see codec_factory
*/ */
void _register_codec_factory(const std::string & p_type, codec_factory* p_codec_factory) { _codecs[p_type] = p_codec_factory; }; void _register_codec_factory(const std::string &p_type, codec_factory *p_codec_factory) { _codecs[p_type] = p_codec_factory; };
public: //! \publicsection public: //! \publicsection
/*! /*!
...@@ -62,8 +64,8 @@ public: //! \publicsection ...@@ -62,8 +64,8 @@ public: //! \publicsection
* \param[in] p_codec_name The codec indentifier * \param[in] p_codec_name The codec indentifier
* \return The pointer to the codec object on success, nullptr otherwise * \return The pointer to the codec object on success, nullptr otherwise
*/ */
inline codec<Record_Type, Record_Type>* get_codec(const char* p_codec_name) { // NOTE A virtual method cannot not be a template ==> polymorphism required here inline codec<Record_Type, Record_Type> *get_codec(const char *p_codec_name) { // NOTE A virtual method cannot not be a template ==> polymorphism required here
typename std::map<std::string, codec_factory*>::const_iterator it = _codecs.find(p_codec_name); typename std::map<std::string, codec_factory *>::const_iterator it = _codecs.find(p_codec_name);
if (it != _codecs.cend()) { if (it != _codecs.cend()) {
return it->second->create_codec(); return it->second->create_codec();
} }
...@@ -71,4 +73,3 @@ public: //! \publicsection ...@@ -71,4 +73,3 @@ public: //! \publicsection
return nullptr; return nullptr;
} }
}; // End of class codec_stack_builder }; // End of class codec_stack_builder
...@@ -10,17 +10,17 @@ ...@@ -10,17 +10,17 @@
*/ */
#pragma once #pragma once
#include <iostream>
#include <iomanip> #include <iomanip>
#include <iostream>
#include <sstream> #include <sstream>
#include <algorithm>
#include <string> #include <string>
#include <vector> #include <vector>
#include <algorithm>
#include <cstdint>
#include <cctype> #include <cctype>
#include <climits> // LONG_MAX, LLONG_MAX #include <climits> // LONG_MAX, LLONG_MAX
#include <cstdint>
#include <ctime> // time_t, struct tm, difftime, time, mktime #include <ctime> // time_t, struct tm, difftime, time, mktime
/*! /*!
...@@ -33,12 +33,12 @@ class converter { ...@@ -33,12 +33,12 @@ class converter {
/*! /*!
* \brief Unique static object reference of this class * \brief Unique static object reference of this class
*/ */
static converter * instance; static converter *instance;
/*! /*!
* \brief Default private ctor * \brief Default private ctor
*/ */
converter() {}; converter(){};
/*! /*!
* \brief Default private dtor * \brief Default private dtor
*/ */
...@@ -53,8 +53,9 @@ public: /*! \publicsection */ ...@@ -53,8 +53,9 @@ public: /*! \publicsection */
/*! /*!
* \brief Public accessor to the single object reference * \brief Public accessor to the single object reference
*/ */
inline static converter & get_instance() { inline static converter &get_instance() {
if (instance == NULL) instance = new converter(); if (instance == NULL)
instance = new converter();
return *instance; return *instance;
}; };
...@@ -63,10 +64,7 @@ public: ...@@ -63,10 +64,7 @@ public:
* \enum endian_t * \enum endian_t
* \brief Endianess style * \brief Endianess style
*/ */
typedef enum { typedef enum { big_endian, little_endian } endian_t;
big_endian,
little_endian
} endian_t;
public: public:
/*! /*!
...@@ -75,9 +73,7 @@ public: ...@@ -75,9 +73,7 @@ public:
* \return The binary value * \return The binary value
* \inline * \inline
*/ */
inline uint8_t bcd_to_bin(const uint8_t p_value) { inline uint8_t bcd_to_bin(const uint8_t p_value) { return ((p_value / 16 * 10) + (p_value % 16)); };
return ((p_value / 16 * 10) + (p_value % 16));
};
/*! /*!
* \brief Convert a binary value into a Binary Coded Decimal value * \brief Convert a binary value into a Binary Coded Decimal value
...@@ -85,9 +81,7 @@ public: ...@@ -85,9 +81,7 @@ public:
* \return The BCD value * \return The BCD value
* \inline * \inline
*/ */
inline uint8_t bin_to_bcd(const uint8_t p_value) { inline uint8_t bin_to_bcd(const uint8_t p_value) { return ((p_value / 10 * 16) + (p_value % 10)); };
return ((p_value / 10 * 16) + (p_value % 10));
};
/*! /*!
* \brief Swap two bytes length value (e.g. 0xCAFE becomes 0xFECA) * \brief Swap two bytes length value (e.g. 0xCAFE becomes 0xFECA)
...@@ -96,37 +90,33 @@ public: ...@@ -96,37 +90,33 @@ public:
* \inline * \inline
*/ */
uint16_t swap(const uint16_t p_value); uint16_t swap(const uint16_t p_value);
inline int16_t swap(const int16_t p_value) { inline int16_t swap(const int16_t p_value) { return static_cast<short>(swap(static_cast<uint16_t>(p_value))); };
return static_cast<short>(swap(static_cast<uint16_t>(p_value)));
};
/*! /*!
* \brief Swap four bytes length value (used for littel endian / big endian) * \brief Swap four bytes length value (used for littel endian / big endian)
* \param[in] p_value The value to swap * \param[in] p_value The value to swap
* \return The swapped value * \return The swapped value
*/ */
uint32_t swap(const uint32_t p_value); uint32_t swap(const uint32_t p_value);
inline int32_t swap(const int32_t p_value) { inline int32_t swap(const int32_t p_value) { return static_cast<int>(swap(static_cast<uint32_t>(p_value))); };
return static_cast<int>(swap(static_cast<uint32_t>(p_value)));
};
/*! /*!
* \brief Convert a string into an hexadecimal string * \brief Convert a string into an hexadecimal string
* \param[in] p_value The string value * \param[in] p_value The string value
* \return The hexadecimal value * \return The hexadecimal value
*/ */
std::string string_to_hexa(const std::string & p_value, const bool p_uppercase = false); std::string string_to_hexa(const std::string &p_value, const bool p_uppercase = false);
/*! /*!
* \brief Convert a bytes array int32_t an hexadecimal string * \brief Convert a bytes array int32_t an hexadecimal string
* \param[in] p_value The bytes array value * \param[in] p_value The bytes array value
* \return The hexadecimal value * \return The hexadecimal value
*/ */
std::string bytes_to_hexa(const std::vector<uint8_t> & p_value, const bool p_uppercase = false); std::string bytes_to_hexa(const std::vector<uint8_t> &p_value, const bool p_uppercase = false);
/*! /*!
* \brief Convert an hexadecimal string into a bytes array * \brief Convert an hexadecimal string into a bytes array
* \param[in] p_value The hexadecimal value * \param[in] p_value The hexadecimal value
* \return The bytes array value * \return The bytes array value
*/ */
std::vector<uint8_t> hexa_to_bytes(const std::string & p_value); std::vector<uint8_t> hexa_to_bytes(const std::string &p_value);
/*! /*!
* \brief Convert a time in time_t format into a string formated according to RFC 822, 1036, 1123, 2822 * \brief Convert a time in time_t format into a string formated according to RFC 822, 1036, 1123, 2822
...@@ -137,7 +127,8 @@ public: ...@@ -137,7 +127,8 @@ public:
* std::string result = time_to_string(1489755780); * std::string result = time_to_string(1489755780);
* result.compare("Fri, 17 Mar 2017 13:03:00 +0000") == 0 // When time zone is set to UTC * result.compare("Fri, 17 Mar 2017 13:03:00 +0000") == 0 // When time zone is set to UTC
* @endcode * @endcode
* \remark Use commands 1) timedatectl to change your machine timezone (e.g. sudo timedatectl set-timezone UTC to change machine timezone to UTC, 2) timedatectl list-timezones to get the list of the timezones) * \remark Use commands 1) timedatectl to change your machine timezone (e.g. sudo timedatectl set-timezone UTC to change machine timezone to UTC, 2)
* timedatectl list-timezones to get the list of the timezones)
*/ */
std::string time_to_string(const time_t p_time); std::string time_to_string(const time_t p_time);
/*! /*!
...@@ -146,7 +137,7 @@ public: ...@@ -146,7 +137,7 @@ public:
* \return The time string formated * \return The time string formated
* \see http://www.unixtimestamp.com/ * \see http://www.unixtimestamp.com/
*/ */
std::string time_to_string(const struct tm & p_time); std::string time_to_string(const struct tm &p_time);
/*! /*!
* \brief Convert a 16-bits integer (int16_t) into a bytes array * \brief Convert a 16-bits integer (int16_t) into a bytes array
...@@ -169,7 +160,7 @@ public: ...@@ -169,7 +160,7 @@ public:
* \param[in] p_endianess Endianess style. Default: big_endian * \param[in] p_endianess Endianess style. Default: big_endian
* \return The 16-bits integer on success, SHRT_MAX on error (wrong bytes array size) * \return The 16-bits integer on success, SHRT_MAX on error (wrong bytes array size)
*/ */
inline int16_t bytes_to_short(const std::vector<uint8_t> & p_value, const endian_t p_endianess = big_endian) const { inline int16_t bytes_to_short(const std::vector<uint8_t> &p_value, const endian_t p_endianess = big_endian) const {
// Sanity check // Sanity check
if (p_value.size() > sizeof(short)) { if (p_value.size() > sizeof(short)) {
return SHRT_MAX; return SHRT_MAX;
...@@ -209,7 +200,7 @@ public: ...@@ -209,7 +200,7 @@ public:
* \param[in] p_endianess Endianess style. Default: big_endian * \param[in] p_endianess Endianess style. Default: big_endian
* \return The 32-bits integer on success, LONG_MAX on error (wrong bytes array size) * \return The 32-bits integer on success, LONG_MAX on error (wrong bytes array size)
*/ */
inline int32_t bytes_to_int(const std::vector<uint8_t> & p_value, const endian_t p_endianess = big_endian) const { inline int32_t bytes_to_int(const std::vector<uint8_t> &p_value, const endian_t p_endianess = big_endian) const {
// Sanity check // Sanity check
if (p_value.size() > sizeof(int)) { if (p_value.size() > sizeof(int)) {
return INT_MAX; return INT_MAX;
...@@ -250,7 +241,7 @@ public: ...@@ -250,7 +241,7 @@ public:
* \param[in] p_endianess Endianess style. Default: big_endian * \param[in] p_endianess Endianess style. Default: big_endian
* \return The 64-bits integer on success, LLONG_MAX on error (wrong bytes array size) * \return The 64-bits integer on success, LLONG_MAX on error (wrong bytes array size)
*/ */
inline int64_t bytes_to_long(const std::vector<uint8_t> & p_value, const endian_t p_endianess = big_endian) const { inline int64_t bytes_to_long(const std::vector<uint8_t> &p_value, const endian_t p_endianess = big_endian) const {
// Sanity check // Sanity check
if (p_value.size() > sizeof(int64_t)) { if (p_value.size() > sizeof(int64_t)) {
return LLONG_MAX; return LLONG_MAX;
...@@ -270,11 +261,8 @@ public: ...@@ -270,11 +261,8 @@ public:
*/ */
inline std::vector<uint8_t> float_to_bytes(const float p_value) const { inline std::vector<uint8_t> float_to_bytes(const float p_value) const {
uint8_t bytes[sizeof(p_value)]; uint8_t bytes[sizeof(p_value)];
std::copy( std::copy(static_cast<const uint8_t *>(static_cast<const void *>(&p_value)),
static_cast<const uint8_t *>(static_cast<const void *>(&p_value)), static_cast<const uint8_t *>(static_cast<const void *>(&p_value)) + sizeof(p_value), bytes);
static_cast<const uint8_t *>(static_cast<const void *>(&p_value)) + sizeof(p_value),
bytes
);
std::vector<uint8_t> result(bytes, bytes + sizeof(bytes) / sizeof(uint8_t)); std::vector<uint8_t> result(bytes, bytes + sizeof(bytes) / sizeof(uint8_t));
return result; return result;
}; // End of float_to_long }; // End of float_to_long
...@@ -284,16 +272,14 @@ public: ...@@ -284,16 +272,14 @@ public:
* \param[in] p_value The bytes array * \param[in] p_value The bytes array
* \return The float value * \return The float value
*/ */
inline float bytes_to_float(const std::vector<uint8_t> & p_value) const { inline float bytes_to_float(const std::vector<uint8_t> &p_value) const { return *((float *)(&p_value[0])); }; // End of bytes_to_float
return *((float *)(&p_value[0]));
}; // End of bytes_to_float
/*! /*!
* \brief Convert a string into a bytes array * \brief Convert a string into a bytes array
* \param[in] p_value The string value * \param[in] p_value The string value
* \return The bytes array value * \return The bytes array value
*/ */
inline std::vector<uint8_t> string_to_bytes(const std::string & p_value) const { inline std::vector<uint8_t> string_to_bytes(const std::string &p_value) const {
return std::vector<uint8_t>(p_value.begin(), p_value.end()); return std::vector<uint8_t>(p_value.begin(), p_value.end());
}; // End of string_to_bytes }; // End of string_to_bytes
...@@ -302,7 +288,7 @@ public: ...@@ -302,7 +288,7 @@ public:
* \param[in] p_value The bytes array value * \param[in] p_value The bytes array value
* \return The string value * \return The string value
*/ */
inline std::string bytes_to_string(const std::vector<uint8_t> & p_value) const { inline std::string bytes_to_string(const std::vector<uint8_t> &p_value) const {
return std::string(p_value.begin(), p_value.end()); return std::string(p_value.begin(), p_value.end());
}; // End of bytes_to_string }; // End of bytes_to_string
...@@ -312,9 +298,9 @@ public: ...@@ -312,9 +298,9 @@ public:
* \param[in] p_value The string value * \param[in] p_value The string value
* \return The integer value * \return The integer value
*/ */
inline int32_t string_to_int(const std::string & p_value) const { inline int32_t string_to_int(const std::string &p_value) const {
return std::stoi(p_value); return std::stoi(p_value);
//return atoi(p_value.c_str()); // return atoi(p_value.c_str());
}; // End of string_to_int }; // End of string_to_int
/*! /*!
...@@ -322,7 +308,7 @@ public: ...@@ -322,7 +308,7 @@ public:
* \param[in] p_value The integer value * \param[in] p_value The integer value
* \return The string value * \return The string value
*/ */
inline std::string int_to_string(const int32_t & p_value) const { inline std::string int_to_string(const int32_t &p_value) const {
std::ostringstream ss; std::ostringstream ss;
ss << p_value; ss << p_value;
return ss.str(); return ss.str();
...@@ -332,27 +318,22 @@ public: ...@@ -332,27 +318,22 @@ public:
* \brief Convert a string in to lower case * \brief Convert a string in to lower case
* \param[in/out] p_value The string value to convert * \param[in/out] p_value The string value to convert
*/ */
inline void to_lower(std::string& p_value) { inline void to_lower(std::string &p_value) { std::transform(p_value.begin(), p_value.end(), p_value.begin(), ::tolower); }
std::transform(p_value.begin(), p_value.end(), p_value.begin(), ::tolower);
}
/*! /*!
* \brief Convert a string in to upper case * \brief Convert a string in to upper case
* \param[in/out] p_value The string value to convert * \param[in/out] p_value The string value to convert
*/ */
inline void to_upper(std::string& p_value) { inline void to_upper(std::string &p_value) { std::transform(p_value.begin(), p_value.end(), p_value.begin(), ::toupper); }
std::transform(p_value.begin(), p_value.end(), p_value.begin(), ::toupper);
}
public: public:
/*! /*!
* \brief Returns a copy of the string, with leading and trailing special characters omitted * \brief Returns a copy of the string, with leading and trailing special characters omitted
* \param[in] p_value The string value * \param[in] p_value The string value
* \param[in] p_trim_chars The special characters to be omitted. Default: ' ' and TAB * \param[in] p_trim_chars The special characters to be omitted. Default: ' ' and TAB
* \return The new string value * \return The new string value
*/ */
std::string trim(const std::string& p_value, const std::string& p_trim_chars = " \t"); std::string trim(const std::string &p_value, const std::string &p_trim_chars = " \t");
/*! /*!
* \brief Convert the provided string into a list of arguments * \brief Convert the provided string into a list of arguments
...@@ -368,7 +349,7 @@ public: ...@@ -368,7 +349,7 @@ public:
* } * }
* \endcode * \endcode
*/ */
std::vector<std::string> split(const std::string & p_value, const std::string& p_separator); std::vector<std::string> split(const std::string &p_value, const std::string &p_separator);
/*! /*!
* \brief Convert the provided string into a list of arguments * \brief Convert the provided string into a list of arguments
...@@ -383,21 +364,21 @@ public: ...@@ -383,21 +364,21 @@ public:
* } * }
* \endcode * \endcode
*/ */
std::vector<std::string> split_arguments_line(const std::string & p_value); std::vector<std::string> split_arguments_line(const std::string &p_value);
/*! /*!
* \brief Convert the provided buffer into a Base64 * \brief Convert the provided buffer into a Base64
* \param[in] p_value The buffer value * \param[in] p_value The buffer value
* \return The Base64 encoded buffert * \return The Base64 encoded buffert
*/ */
std::vector<unsigned char> buffer_to_base64(const std::vector<unsigned char> & p_value); std::vector<unsigned char> buffer_to_base64(const std::vector<unsigned char> &p_value);
/*! /*!
* \brief Convert the provided Base64 buffer * \brief Convert the provided Base64 buffer
* \param[in] p_value The buffer value * \param[in] p_value The buffer value
* \return The Base64 encoded buffert * \return The Base64 encoded buffert
*/ */
std::vector<unsigned char> base64_to_buffer(const std::vector<unsigned char> & p_value); std::vector<unsigned char> base64_to_buffer(const std::vector<unsigned char> &p_value);
static const std::string lut_u; static const std::string lut_u;
static const std::string lut_l; static const std::string lut_l;
......
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
*/ */
#pragma once #pragma once
#include <string> #include <algorithm>
#include <map> #include <map>
#include <string>
#include <vector> #include <vector>
#include <algorithm>
#include "params.hh" #include "params.hh"
...@@ -27,8 +27,8 @@ class INTEGER; //! Forward declaration of TITAN class ...@@ -27,8 +27,8 @@ class INTEGER; //! Forward declaration of TITAN class
* \brief This class provides basic description of an ITS protocol layer * \brief This class provides basic description of an ITS protocol layer
*/ */
class layer { class layer {
std::vector<layer*> upperLayers; //! List of the upper protocol layers std::vector<layer *> upperLayers; //! List of the upper protocol layers
std::vector<layer*> lowerLayers; //! List of the lower protocol layers std::vector<layer *> lowerLayers; //! List of the lower protocol layers
protected: protected:
std::string type; //! Type description, it indicates the protocol type (e.g. CAM, DENM, GN, ETH, PCAP...) std::string type; //! Type description, it indicates the protocol type (e.g. CAM, DENM, GN, ETH, PCAP...)
...@@ -38,7 +38,7 @@ public: //! \publicsection ...@@ -38,7 +38,7 @@ public: //! \publicsection
* \brief Default constructor * \brief Default constructor
* Create a new instance of the layer class * Create a new instance of the layer class
*/ */
explicit layer() : upperLayers(), lowerLayers(), type(std::string("")) { }; explicit layer() : upperLayers(), lowerLayers(), type(std::string("")){};
/*! /*!
* \brief Specialized constructor * \brief Specialized constructor
...@@ -47,7 +47,7 @@ public: //! \publicsection ...@@ -47,7 +47,7 @@ public: //! \publicsection
* \remark This constructor is called by the layer factory * \remark This constructor is called by the layer factory
* \see layer_factory * \see layer_factory
*/ */
explicit layer(const std::string& p_type) : upperLayers(), lowerLayers(), type(std::string(p_type.begin(), p_type.end())) { }; explicit layer(const std::string &p_type) : upperLayers(), lowerLayers(), type(std::string(p_type.begin(), p_type.end())){};
/*! /*!
* \brief Default destructor * \brief Default destructor
...@@ -55,7 +55,7 @@ public: //! \publicsection ...@@ -55,7 +55,7 @@ public: //! \publicsection
*/ */
virtual ~layer() { virtual ~layer() {
// Double linked list, only remove layers in lowerLayers from the lowest one // Double linked list, only remove layers in lowerLayers from the lowest one
std::for_each(lowerLayers.rbegin(), lowerLayers.rend(), [](layer* it) { delete it; } ); std::for_each(lowerLayers.rbegin(), lowerLayers.rend(), [](layer *it) { delete it; });
lowerLayers.clear(); lowerLayers.clear();
upperLayers.clear(); upperLayers.clear();
}; };
...@@ -65,7 +65,7 @@ public: //! \publicsection ...@@ -65,7 +65,7 @@ public: //! \publicsection
* \brief Delete this layer * \brief Delete this layer
* \todo To be implemented * \todo To be implemented
*/ */
void delete_layer() { }; void delete_layer(){};
public: //! \publicsection public: //! \publicsection
/*! /*!
...@@ -74,7 +74,7 @@ public: //! \publicsection ...@@ -74,7 +74,7 @@ public: //! \publicsection
* \brief Add a new layer in the list of the upper layer * \brief Add a new layer in the list of the upper layer
* \param[in] p_layer The layer protocol to be removed * \param[in] p_layer The layer protocol to be removed
*/ */
inline void add_upper_layer(layer* p_layer) { inline void add_upper_layer(layer *p_layer) {
if (p_layer != NULL) { if (p_layer != NULL) {
upperLayers.push_back(p_layer); upperLayers.push_back(p_layer);
p_layer->lowerLayers.push_back(this); p_layer->lowerLayers.push_back(this);
...@@ -87,7 +87,7 @@ public: //! \publicsection ...@@ -87,7 +87,7 @@ public: //! \publicsection
* \param[in] p_layer The layer protocol to be removed * \param[in] p_layer The layer protocol to be removed
* \todo To be implemented * \todo To be implemented
*/ */
void remove_upper_layer(layer* p_layer) { }; void remove_upper_layer(layer *p_layer){};
/*! /*!
* \virtual * \virtual
...@@ -98,7 +98,7 @@ public: //! \publicsection ...@@ -98,7 +98,7 @@ public: //! \publicsection
* \todo Remove the logs * \todo Remove the logs
* \virtual * \virtual
*/ */
virtual void send_data(OCTETSTRING& p_data, params& p_params) { }; virtual void send_data(OCTETSTRING &p_data, params &p_params){};
/*! /*!
* \virtual * \virtual
...@@ -109,7 +109,7 @@ public: //! \publicsection ...@@ -109,7 +109,7 @@ public: //! \publicsection
* \todo Remove the logs * \todo Remove the logs
* \virtual * \virtual
*/ */
virtual void receive_data(OCTETSTRING& p_data, params& p_params) { } virtual void receive_data(OCTETSTRING &p_data, params &p_params) {}
/*! /*!
* \inline * \inline
...@@ -117,28 +117,27 @@ public: //! \publicsection ...@@ -117,28 +117,27 @@ public: //! \publicsection
* \brief Remove the specified upper layer protocol from the list of the upper layer * \brief Remove the specified upper layer protocol from the list of the upper layer
* \param[in] The layer protocol to be removed * \param[in] The layer protocol to be removed
*/ */
inline const std::string& to_string() const { return type; }; inline const std::string &to_string() const { return type; };
protected: //! \protectedsection protected: //! \protectedsection
inline void to_all_layers(std::vector<layer*>&layers, OCTETSTRING& data, params& params) { inline void to_all_layers(std::vector<layer *> &layers, OCTETSTRING &data, params &params) {
for (std::vector<layer*>::const_iterator it = layers.cbegin(); it != layers.cend(); ++it) { for (std::vector<layer *>::const_iterator it = layers.cbegin(); it != layers.cend(); ++it) {
layer* p = *it; layer *p = *it;
p->receive_data(data, params); // FIXME BUG I p->receive_data(data, params); // FIXME BUG I
} // End of 'for' statement } // End of 'for' statement
}; };
inline void receive_to_all_layers(OCTETSTRING& data, params& params) { inline void receive_to_all_layers(OCTETSTRING &data, params &params) {
for (std::vector<layer*>::const_iterator it = upperLayers.cbegin(); it != upperLayers.cend(); ++it) { for (std::vector<layer *>::const_iterator it = upperLayers.cbegin(); it != upperLayers.cend(); ++it) {
layer* p = *it; layer *p = *it;
p->receive_data(data, params); p->receive_data(data, params);
} // End of 'for' statement } // End of 'for' statement
}; };
inline void send_to_all_layers(OCTETSTRING& data, params& params) { inline void send_to_all_layers(OCTETSTRING &data, params &params) {
for (std::vector<layer*>::const_iterator it = lowerLayers.cbegin(); it != lowerLayers.cend(); ++it) { for (std::vector<layer *>::const_iterator it = lowerLayers.cbegin(); it != lowerLayers.cend(); ++it) {
layer* p = *it; layer *p = *it;
p->send_data(data, params); p->send_data(data, params);
} // End of 'for' statement } // End of 'for' statement
}; };
}; // End of class layer }; // End of class layer
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
*/ */
#pragma once #pragma once
#include <string> #include <algorithm>
#include <map> #include <map>
#include <string>
#include <vector> #include <vector>
#include <algorithm>
#include "layer.hh" #include "layer.hh"
...@@ -28,7 +28,7 @@ public: //! \publicsection ...@@ -28,7 +28,7 @@ public: //! \publicsection
* \fn codec(); * \fn codec();
* \brief Default constructor * \brief Default constructor
*/ */
layer_factory() {}; layer_factory(){};
/*! /*!
* \fn layer* create_layer(const std::string & type, const std::string & param); * \fn layer* create_layer(const std::string & type, const std::string & param);
* \brief Create the layers stack based on the provided layers stack description (cf. remark) * \brief Create the layers stack based on the provided layers stack description (cf. remark)
...@@ -101,14 +101,21 @@ public: //! \publicsection ...@@ -101,14 +101,21 @@ public: //! \publicsection
* save_mode : 1 to save sent packet, 0 otherwise * save_mode : 1 to save sent packet, 0 otherwise
* Here are some examples: * Here are some examples:
* GeoNetworking multiple component case: * GeoNetworking multiple component case:
* NodeB.geoNetworkingPort.params := "GN(ll_address=04e548000001,latitude=43551050,longitude=10298730,beaconing=0,expiry=1000,its_aid=141)/COMMSIGNIA(mac_src=04e548000001,mac_bc=FFFFFFFFFFFF,eth_type=8947,target_host=10.200.1.101,target_port=7942,source_port=7943,its_aid=141,interface_id=2,tx_power=-32)/UDP(dst_ip=192.168.56.1,dst_port=12346,src_ip=192.168.156.4,src_port=12345)/ETH(mac_src=04e548000001,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=04e548000001,file=/home/vagrant/TriesAndDelete/etsi_its/testdata/TC_AUTO_IOT_DENM_RWW_BV_01_short.pcap,filter=and (udp port 30000 or udp port 7943))" * NodeB.geoNetworkingPort.params :=
NodeC.geoNetworkingPort.params := "GN(ll_address=70b3d5791b48,latitude=43551050,longitude=10298730,beaconing=0,expiry=1000,its_aid=141)/COMMSIGNIA(mac_src=70b3d5791b48,mac_bc=FFFFFFFFFFFF,eth_type=8947,target_host=10.200.1.101,target_port=7942,source_port=7943,its_aid=141,interface_id=2,tx_power=-32)/UDP(dst_ip=192.168.56.1,dst_port=12346,src_ip=192.168.156.4,src_port=12345)/ETH(mac_src=70b3d5791b48,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=70b3d5791b48,file=/home/vagrant/TriesAndDelete/etsi_its/testdata/TC_AUTO_IOT_DENM_RWW_BV_01_short.pcap,filter=and (udp port 30000 or udp port 7943))" "GN(ll_address=04e548000001,latitude=43551050,longitude=10298730,beaconing=0,expiry=1000,its_aid=141)/COMMSIGNIA(mac_src=04e548000001,mac_bc=FFFFFFFFFFFF,eth_type=8947,target_host=10.200.1.101,target_port=7942,source_port=7943,its_aid=141,interface_id=2,tx_power=-32)/UDP(dst_ip=192.168.56.1,dst_port=12346,src_ip=192.168.156.4,src_port=12345)/ETH(mac_src=04e548000001,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=04e548000001,file=/home/vagrant/TriesAndDelete/etsi_its/testdata/TC_AUTO_IOT_DENM_RWW_BV_01_short.pcap,filter=and
* NodeB.geoNetworkingPort.params := "GN(ll_address=04e548000001,latitude=43551050,longitude=10298730,beaconing=0,expiry=1000,its_aid=141)/ETH(mac_src=04e548000001,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=04e548000001,file=/home/vagrant/TriesAndDelete/etsi_its/testdata/TC_AUTO_IOT_DENM_RWW_BV_01.pcap,filter=and ether src 04e548000001)" (udp port 30000 or udp port 7943))" NodeC.geoNetworkingPort.params :=
#NodeC.geoNetworkingPort.params := "GN(ll_address=70b3d5791b48,latitude=43551050,longitude=10298730,beaconing=0,expiry=1000,its_aid=141)/ETH(mac_src=70b3d5791b48,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=70b3d5791b48,file=/home/vagrant/TriesAndDelete/etsi_its/testdata/TC_AUTO_IOT_DENM_RWW_BV_01.pcap,filter=and ether src 70b3d5791b48)" "GN(ll_address=70b3d5791b48,latitude=43551050,longitude=10298730,beaconing=0,expiry=1000,its_aid=141)/COMMSIGNIA(mac_src=70b3d5791b48,mac_bc=FFFFFFFFFFFF,eth_type=8947,target_host=10.200.1.101,target_port=7942,source_port=7943,its_aid=141,interface_id=2,tx_power=-32)/UDP(dst_ip=192.168.56.1,dst_port=12346,src_ip=192.168.156.4,src_port=12345)/ETH(mac_src=70b3d5791b48,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=70b3d5791b48,file=/home/vagrant/TriesAndDelete/etsi_its/testdata/TC_AUTO_IOT_DENM_RWW_BV_01_short.pcap,filter=and
(udp port 30000 or udp port 7943))"
* NodeB.geoNetworkingPort.params :=
"GN(ll_address=04e548000001,latitude=43551050,longitude=10298730,beaconing=0,expiry=1000,its_aid=141)/ETH(mac_src=04e548000001,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=04e548000001,file=/home/vagrant/TriesAndDelete/etsi_its/testdata/TC_AUTO_IOT_DENM_RWW_BV_01.pcap,filter=and
ether src 04e548000001)" #NodeC.geoNetworkingPort.params :=
"GN(ll_address=70b3d5791b48,latitude=43551050,longitude=10298730,beaconing=0,expiry=1000,its_aid=141)/ETH(mac_src=70b3d5791b48,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=70b3d5791b48,file=/home/vagrant/TriesAndDelete/etsi_its/testdata/TC_AUTO_IOT_DENM_RWW_BV_01.pcap,filter=and
ether src 70b3d5791b48)"
* UpperTester port based on UDP * UpperTester port based on UDP
* system.utPort.params := "UT_GN/UDP(dst_ip=192.168.1.1,dst_port=12346,src_ip=192.168.156.4,src_port=12345)/ETH(mac_src=026f8338c1e5,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=0800275c4959,nic=enp0s8,filter=and udp port 12346)" * system.utPort.params :=
"UT_GN/UDP(dst_ip=192.168.1.1,dst_port=12346,src_ip=192.168.156.4,src_port=12345)/ETH(mac_src=026f8338c1e5,mac_dst=0A0027000011,eth_type=0800)/PCAP(mac_src=0800275c4959,nic=enp0s8,filter=and
udp port 12346)"
* \pure * \pure
*/ */
virtual layer* create_layer(const std::string & p_type, const std::string & p_params) = 0; virtual layer *create_layer(const std::string &p_type, const std::string &p_params) = 0;
}; // End of class layer_factory }; // End of class layer_factory
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
*/ */
class layer_stack_builder { class layer_stack_builder {
private: //! \privatesection private: //! \privatesection
typedef std::map<std::string, layer_factory*> LayerFactoryMap; typedef std::map<std::string, layer_factory *> LayerFactoryMap;
static layer_stack_builder * _instance; //! Smart pointer to the unique instance of the logger framework static layer_stack_builder * _instance; //! Smart pointer to the unique instance of the logger framework
std::map<std::string, layer_factory*> _layer_factories; //! The list of the registered \see t_layer factories std::map<std::string, layer_factory *> _layer_factories; //! The list of the registered \see t_layer factories
/*! /*!
* \brief Default constructor * \brief Default constructor
...@@ -35,7 +35,7 @@ public: //! \publicsection ...@@ -35,7 +35,7 @@ public: //! \publicsection
* \brief Accessor for the unique instance of the logger framework * \brief Accessor for the unique instance of the logger framework
* \static * \static
*/ */
static layer_stack_builder* get_instance(); static layer_stack_builder *get_instance();
/*! /*!
* \fn void register_layer_factory(const std::string & p_type, layer_factory* p_layer_factory); * \fn void register_layer_factory(const std::string & p_type, layer_factory* p_layer_factory);
...@@ -44,7 +44,7 @@ public: //! \publicsection ...@@ -44,7 +44,7 @@ public: //! \publicsection
* \param[in] p_layer_factory A reference to the \see layer_factory * \param[in] p_layer_factory A reference to the \see layer_factory
* \static * \static
*/ */
static void register_layer_factory(const std::string & p_type, layer_factory* p_layer_factory); static void register_layer_factory(const std::string &p_type, layer_factory *p_layer_factory);
private: //! \privatesection private: //! \privatesection
/*! /*!
...@@ -53,7 +53,7 @@ private: //! \privatesection ...@@ -53,7 +53,7 @@ private: //! \privatesection
* \param[in] p_type The layer identifier (e.g. GN for the GeoNetworking layer...) * \param[in] p_type The layer identifier (e.g. GN for the GeoNetworking layer...)
* \param[in] p_layer_factory A reference to the \see layer_factory * \param[in] p_layer_factory A reference to the \see layer_factory
*/ */
void _register_layer_factory(const std::string & p_type, layer_factory* p_layer_factory); void _register_layer_factory(const std::string &p_type, layer_factory *p_layer_factory);
public: //! \publicsection public: //! \publicsection
/*! /*!
...@@ -62,6 +62,5 @@ public: //! \publicsection ...@@ -62,6 +62,5 @@ public: //! \publicsection
* \param[in] p_layer_stack_description A textual description of the layer to create * \param[in] p_layer_stack_description A textual description of the layer to create
* \return The created layer object on success, nullptr otherwise * \return The created layer object on success, nullptr otherwise
*/ */
layer* create_layer_stack(const char* p_layer_stack_description); layer *create_layer_stack(const char *p_layer_stack_description);
}; // End of class layer_stack_builder }; // End of class layer_stack_builder
...@@ -7,38 +7,36 @@ class CHARSTRING; ...@@ -7,38 +7,36 @@ class CHARSTRING;
class BITSTRING; class BITSTRING;
struct asn_TYPE_descriptor_s; struct asn_TYPE_descriptor_s;
class asn1_recode_oer class asn1_recode_oer {
{
protected: protected:
int xer2oer (const asn_TYPE_descriptor_s & td, TTCN_Buffer & buf); int xer2oer(const asn_TYPE_descriptor_s &td, TTCN_Buffer &buf);
int oer2xer (const asn_TYPE_descriptor_s & td, TTCN_Buffer & buf); int oer2xer(const asn_TYPE_descriptor_s &td, TTCN_Buffer &buf);
int recode (const asn_TYPE_descriptor_s & td, int from, int to, TTCN_Buffer & buf); int recode(const asn_TYPE_descriptor_s &td, int from, int to, TTCN_Buffer &buf);
}; };
template<typename TPDU> class oer_codec : public asn1_recode_oer template <typename TPDU> class oer_codec : public asn1_recode_oer {
{
public: public:
virtual int encode(const TPDU& msg, BITSTRING& bits) = 0; virtual int encode(const TPDU &msg, BITSTRING &bits) = 0;
virtual int decode(const BITSTRING& bits, TPDU& msg) = 0; virtual int decode(const BITSTRING &bits, TPDU &msg) = 0;
protected: protected:
inline int _decode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const BITSTRING& p_data, TPDU& msg) { inline int _decode(const TTCN_Typedescriptor_t &ttcn, const asn_TYPE_descriptor_s &td, const BITSTRING &p_data, TPDU &msg) {
TTCN_Buffer buf(bit2oct(p_data)); TTCN_Buffer buf(bit2oct(p_data));
TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING); TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING);
int rc = oer2xer (td, buf); int rc = oer2xer(td, buf);
if (rc > 0) { if (rc > 0) {
msg.decode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ACCEPT_ALL); msg.decode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ACCEPT_ALL);
rc = buf.get_len(); rc = buf.get_len();
} }
return rc; return rc;
} }
inline int _encode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const TPDU& msg, BITSTRING& p_data) { inline int _encode(const TTCN_Typedescriptor_t &ttcn, const asn_TYPE_descriptor_s &td, const TPDU &msg, BITSTRING &p_data) {
int rc = -1; int rc = -1;
TTCN_Buffer buf; TTCN_Buffer buf;
TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING); TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING);
msg.encode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ENCODE_DER); msg.encode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ENCODE_DER);
if (buf.get_len() > 0) { if (buf.get_len() > 0) {
rc = xer2oer (td, buf); rc = xer2oer(td, buf);
if (rc > 0) { if (rc > 0) {
p_data = oct2bit(OCTETSTRING(buf.get_len(), buf.get_data())); p_data = oct2bit(OCTETSTRING(buf.get_len(), buf.get_data()));
} }
......
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
*/ */
#pragma once #pragma once
#include <vector>
#include <string>
#include <map> #include <map>
#include <string>
#include <vector>
/*! /*!
* \class params * \class params
* \brief This class provides basic functionalities for an ITS dictionary * \brief This class provides basic functionalities for an ITS dictionary
* \implements std::map * \implements std::map
...@@ -22,91 +22,93 @@ ...@@ -22,91 +22,93 @@
class params : public std::map<std::string, std::string> { class params : public std::map<std::string, std::string> {
public: //! \publicsection public: //! \publicsection
// TODO Use static constexpr (see commsignia_layer.hh) // TODO Use static constexpr (see commsignia_layer.hh)
static const std::string& debug; //! Set to 1 to enable the debug mode static const std::string &debug; //! Set to 1 to enable the debug mode
static const std::string& loopback; static const std::string &loopback;
static const std::string& mac_src; //! Source MAC address parameter name static const std::string &mac_src; //! Source MAC address parameter name
static const std::string& mac_dst; //! Destination MAC address parameter name static const std::string &mac_dst; //! Destination MAC address parameter name
static const std::string& mac_bc; //! Broadcast MAC address parameter name static const std::string &mac_bc; //! Broadcast MAC address parameter name
static const std::string& eth_type; //! Ethernet type parameter name static const std::string &eth_type; //! Ethernet type parameter name
static const std::string& beaconing; //! Beaconing mode parameter name static const std::string &beaconing; //! Beaconing mode parameter name
static const std::string& timestamp; //! Packet reception timestamp static const std::string &timestamp; //! Packet reception timestamp
static const std::string& station_type; static const std::string &station_type;
static const std::string& country; static const std::string &country;
static const std::string& type_of_address; static const std::string &type_of_address;
static const std::string& ssp; //! SSP parameter name static const std::string &ssp; //! SSP parameter name
static const std::string& its_aid; //! ITS-AID parameter name static const std::string &its_aid; //! ITS-AID parameter name
static const std::string& gn_payload; //! GeoNetworking Payload parameter name static const std::string &gn_payload; //! GeoNetworking Payload parameter name
static const std::string& gn_next_header; //! GeoNetworking NextHeader parameter name static const std::string &gn_next_header; //! GeoNetworking NextHeader parameter name
static const std::string& gn_header_type; //! GeoNetworking HeaderType parameter name static const std::string &gn_header_type; //! GeoNetworking HeaderType parameter name
static const std::string& gn_header_sub_type; //! GeoNetworking HeaderSubType parameter name static const std::string &gn_header_sub_type; //! GeoNetworking HeaderSubType parameter name
static const std::string& gn_lifetime; //! GeoNetworking Lifetime parameter name static const std::string &gn_lifetime; //! GeoNetworking Lifetime parameter name
static const std::string& gn_traffic_class; //! GeoNetworking Traffic class parameter name static const std::string &gn_traffic_class; //! GeoNetworking Traffic class parameter name
static const std::string& btp_type; //! BTP Type parameter name static const std::string &btp_type; //! BTP Type parameter name
static const std::string& btp_payload; //! BTP Payload parameter name static const std::string &btp_payload; //! BTP Payload parameter name
static const std::string& btp_destination_port; //! BTP DestinationPort parameter name static const std::string &btp_destination_port; //! BTP DestinationPort parameter name
static const std::string& btp_info; //! BTP Info parameter name static const std::string &btp_info; //! BTP Info parameter name
static const std::string& nic; //! Network Interface Card parameter name static const std::string &nic; //! Network Interface Card parameter name
static const std::string& ll_address; //! Test system GeoNetworking LL-Address parameter name static const std::string &ll_address; //! Test system GeoNetworking LL-Address parameter name
static const std::string& latitude; //! Test system Latitude parameter name static const std::string &latitude; //! Test system Latitude parameter name
static const std::string& longitude; //! Test system Longitude parameter name static const std::string &longitude; //! Test system Longitude parameter name
static const std::string& expiry; //! Test system GeoNetworking Lifetime parameter name (in ms) static const std::string &expiry; //! Test system GeoNetworking Lifetime parameter name (in ms)
static const std::string& station_id; //! To indicate to the peer ITS_Container::stationID static const std::string &station_id; //! To indicate to the peer ITS_Container::stationID
static const std::string& device_mode; //! To indicate to the lower layer to act as a standalone device static const std::string &device_mode; //! To indicate to the lower layer to act as a standalone device
static const std::string& secured_mode; //! To indicate to the lower layer to apply signature on message exchanges as defined in IEEE 1609.2 & ETSI TS 102 965 static const std::string &secured_mode; //! To indicate to the lower layer to apply signature on message exchanges as defined in IEEE 1609.2 & ETSI TS 102 965
static const std::string& encrypted_mode; //! To indicate to the lower layer to apply encryption on message exchanges as defined in IEEE 1609.2 & ETSI TS 102 965 static const std::string
static const std::string& enable_security_checks;//! To indicates if security check failures shall be treated as error or warning &encrypted_mode; //! To indicate to the lower layer to apply encryption on message exchanges as defined in IEEE 1609.2 & ETSI TS 102 965
static const std::string& sec_db_path; //! Path to the folder containing certificates static const std::string &enable_security_checks; //! To indicates if security check failures shall be treated as error or warning
static const std::string& certificate; //! The certificate identifier the Test System shall use. E.g. CERT_TS_A static const std::string &sec_db_path; //! Path to the folder containing certificates
static const std::string& peer_certificate; //! The peer certificate identifier the Test System shall use for encryption. E.g. CERT_TS_A static const std::string &certificate; //! The certificate identifier the Test System shall use. E.g. CERT_TS_A
static const std::string& hash; //! The digest algorithm the Test System shall use, authorised values are SHA-256 or SHA-384. Default: SHA-256 static const std::string &peer_certificate; //! The peer certificate identifier the Test System shall use for encryption. E.g. CERT_TS_A
static const std::string& signature; //! The signature algorithm the Test System shall use, authorised values are NISTP-256, BP-256 and BP-384. Default: NISTP-256 static const std::string &hash; //! The digest algorithm the Test System shall use, authorised values are SHA-256 or SHA-384. Default: SHA-256
static const std::string& cypher; //! The encryption algorithm the Test System shall use, authorised values are NISTP-256 and BP-256. Default: NISTP-256 static const std::string
static const std::string& distanceA; //! Test system GeoNetworking DistanceA parameter name &signature; //! The signature algorithm the Test System shall use, authorised values are NISTP-256, BP-256 and BP-384. Default: NISTP-256
static const std::string& distanceB; //! Test system GeoNetworking DistanceB parameter name static const std::string &cypher; //! The encryption algorithm the Test System shall use, authorised values are NISTP-256 and BP-256. Default: NISTP-256
static const std::string& angle; //! Test system GeoNetworking Angle parameter name static const std::string &distanceA; //! Test system GeoNetworking DistanceA parameter name
static const std::string &distanceB; //! Test system GeoNetworking DistanceB parameter name
static const std::string& payload_type; //! Tyoe of payload, value is the ITS Conatainer message identifier or omitted in case of unknown payload static const std::string &angle; //! Test system GeoNetworking Angle parameter name
static const std::string& next_header; //! Upper layer settings static const std::string &payload_type; //! Tyoe of payload, value is the ITS Conatainer message identifier or omitted in case of unknown payload
static const std::string& header_type; //! Upper layer settings
static const std::string& header_sub_type; //! Upper layer settings static const std::string &next_header; //! Upper layer settings
static const std::string &header_type; //! Upper layer settings
static const std::string& interface_id; //! Commsignia antenna selector static const std::string &header_sub_type; //! Upper layer settings
static const std::string& server; //! HTTP server address (e.g. www.etsi.org) static const std::string &interface_id; //! Commsignia antenna selector
static const std::string& port; //! HTTP server port. Default: 80
static const std::string& use_ssl; //! Set to 1 to use SSL to communicate with the HTTP server. Default: false static const std::string &server; //! HTTP server address (e.g. www.etsi.org)
static const std::string& server_mode; //! Does the test sytem acting as a server. Default: 0 static const std::string &port; //! HTTP server port. Default: 80
static const std::string& local_port; //! Local listener port. Default: 80 static const std::string &use_ssl; //! Set to 1 to use SSL to communicate with the HTTP server. Default: false
static const std::string &server_mode; //! Does the test sytem acting as a server. Default: 0
static const std::string& method; //! HTTP method type. Default: POST static const std::string &local_port; //! Local listener port. Default: 80
static const std::string& uri; //! HTTP URI value. Default: /
static const std::string& host; //! HTTP Host value. Default: 127.0.0.1 static const std::string &method; //! HTTP method type. Default: POST
static const std::string& content_type; //! HTTP Content-type value. Default: application/text static const std::string &uri; //! HTTP URI value. Default: /
static const std::string &host; //! HTTP Host value. Default: 127.0.0.1
static const std::string& codecs; //! List of codecs to use for HTTP application layers static const std::string &content_type; //! HTTP Content-type value. Default: application/text
static const std::string &codecs; //! List of codecs to use for HTTP application layers
/*! /*!
* \brief Default constructor * \brief Default constructor
* Create a new instance of the params class * Create a new instance of the params class
*/ */
params() : std::map<std::string, std::string>() {}; params() : std::map<std::string, std::string>(){};
/*! /*!
* \brief Copy constructor * \brief Copy constructor
* Clone an existing instance of a params object * Clone an existing instance of a params object
* \param[in] p_params An existing instance of a params object * \param[in] p_params An existing instance of a params object
*/ */
explicit params(const params& p_params) : std::map<std::string, std::string>(p_params.begin(), p_params.end()) { }; explicit params(const params &p_params) : std::map<std::string, std::string>(p_params.begin(), p_params.end()){};
/*! /*!
* \brief Default destructor * \brief Default destructor
*/ */
virtual ~params() { }; virtual ~params(){};
/*! /*!
* \fn void log() const; * \fn void log() const;
...@@ -130,6 +132,5 @@ public: //! \publicsection ...@@ -130,6 +132,5 @@ public: //! \publicsection
* \brief Create a new instance of a params object by converting a list of ITS parameters in string format (t1=v1,T2=(v0,v1v2)...) * \brief Create a new instance of a params object by converting a list of ITS parameters in string format (t1=v1,T2=(v0,v1v2)...)
* \return a new instance of a params object * \return a new instance of a params object
*/ */
static void convert(params& p_param, const std::string p_parameters); static void convert(params &p_param, const std::string p_parameters);
}; // End of class params }; // End of class params
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
*/ */
#pragma once #pragma once
#include "params.hh"
#include "asn1_recode_per.hh" #include "asn1_recode_per.hh"
#include "params.hh"
class BITSTRING; //! Forward declaration of TITAN class class BITSTRING; //! Forward declaration of TITAN class
class TTCN_Typedescriptor_t; //! Forward declaration of TITAN class class TTCN_Typedescriptor_t; //! Forward declaration of TITAN class
...@@ -23,9 +23,7 @@ struct asn_TYPE_descriptor_s; //! Declare asn1c class ...@@ -23,9 +23,7 @@ struct asn_TYPE_descriptor_s; //! Declare asn1c class
* \brief This class provides the interface for all ASN.1 PER codecs. * \brief This class provides the interface for all ASN.1 PER codecs.
* \remark This class uses asn1c external tool * \remark This class uses asn1c external tool
*/ */
template<typename TPDU> template <typename TPDU> class per_codec : public asn1_recode_per {
class per_codec : public asn1_recode_per
{
public: //! \publicsection public: //! \publicsection
/*! /*!
* \fn int encode(const TPDU& p_message, BITSTRING& p_bitstring); * \fn int encode(const TPDU& p_message, BITSTRING& p_bitstring);
...@@ -34,7 +32,7 @@ public: //! \publicsection ...@@ -34,7 +32,7 @@ public: //! \publicsection
* \param[out] p_bitstring The encoded PDU message in bit string format * \param[out] p_bitstring The encoded PDU message in bit string format
* \pure * \pure
*/ */
virtual int encode(const TPDU& p_message, BITSTRING& p_bitstring) = 0; virtual int encode(const TPDU &p_message, BITSTRING &p_bitstring) = 0;
/*! /*!
* \fn int decode(const BITSTRING& p_bitstring, TPDU& p_message); * \fn int decode(const BITSTRING& p_bitstring, TPDU& p_message);
* \brief Decode ASN.1 PER message into TITAN message * \brief Decode ASN.1 PER message into TITAN message
...@@ -42,12 +40,11 @@ public: //! \publicsection ...@@ -42,12 +40,11 @@ public: //! \publicsection
* \param[out] p_message The PDU message * \param[out] p_message The PDU message
* \pure * \pure
*/ */
virtual int decode(const BITSTRING& p_bitstring, TPDU& p_message) = 0; virtual int decode(const BITSTRING &p_bitstring, TPDU &p_message) = 0;
protected: //! \protectedsection protected: //! \protectedsection
int _decode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const BITSTRING& p_data, TPDU& msg); int _decode(const TTCN_Typedescriptor_t &ttcn, const asn_TYPE_descriptor_s &td, const BITSTRING &p_data, TPDU &msg);
int _encode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const TPDU& msg, BITSTRING& p_data); int _encode(const TTCN_Typedescriptor_t &ttcn, const asn_TYPE_descriptor_s &td, const TPDU &msg, BITSTRING &p_data);
}; // End of class per_codec }; // End of class per_codec
#include "per_codec.t.hh" #include "per_codec.t.hh"
#include <TTCN3.hh> #include <TTCN3.hh>
template<class TPDU> template <class TPDU> int per_codec<TPDU>::_decode(const TTCN_Typedescriptor_t &ttcn, const asn_TYPE_descriptor_s &td, const BITSTRING &p_data, TPDU &msg) {
int per_codec<TPDU>::_decode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const BITSTRING& p_data, TPDU& msg) {
TTCN_Buffer buf(bit2oct(p_data)); TTCN_Buffer buf(bit2oct(p_data));
TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING); TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING);
int rc = per2ber (td, buf); int rc = per2ber(td, buf);
if (rc > 0) { if (rc > 0) {
msg.decode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ACCEPT_ALL); msg.decode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ACCEPT_ALL);
rc = buf.get_len(); rc = buf.get_len();
...@@ -12,14 +11,13 @@ int per_codec<TPDU>::_decode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_ ...@@ -12,14 +11,13 @@ int per_codec<TPDU>::_decode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_
return rc; return rc;
} }
template<class TPDU> template <class TPDU> int per_codec<TPDU>::_encode(const TTCN_Typedescriptor_t &ttcn, const asn_TYPE_descriptor_s &td, const TPDU &msg, BITSTRING &p_data) {
int per_codec<TPDU>::_encode (const TTCN_Typedescriptor_t& ttcn, const asn_TYPE_descriptor_s & td, const TPDU& msg, BITSTRING& p_data) {
int rc = -1; int rc = -1;
TTCN_Buffer buf; TTCN_Buffer buf;
TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING); TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING);
msg.encode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ENCODE_DER); msg.encode(ttcn, buf, TTCN_EncDec::CT_BER, BER_ENCODE_DER);
if (buf.get_len() > 0) { if (buf.get_len() > 0) {
rc = ber2per (td, buf); rc = ber2per(td, buf);
if (rc > 0) { if (rc > 0) {
p_data = oct2bit(OCTETSTRING(buf.get_len(), buf.get_data())); p_data = oct2bit(OCTETSTRING(buf.get_len(), buf.get_data()));
} }
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
*/ */
#pragma once #pragma once
#include <string>
#include <map> #include <map>
#include <string>
/** /**
* \class registration * \class registration
...@@ -19,43 +19,37 @@ ...@@ -19,43 +19,37 @@
* The registered items are accessible from any object (singleton pattern) * The registered items are accessible from any object (singleton pattern)
* \remark There is one limitation: each item is uniquely defined in the process * \remark There is one limitation: each item is uniquely defined in the process
*/ */
template <typename TItem> template <typename TItem> class registration { // TODO Refine the naming, derive from std::map<std::string, TItem*>
class registration { // TODO Refine the naming, derive from std::map<std::string, TItem*> std::map<std::string, TItem *> _items;
std::map<std::string, TItem*> _items;
static registration<TItem> *_instance;
static registration<TItem>* _instance;
private: private:
registration(): _items() { }; // can not be created manually registration() : _items(){}; // can not be created manually
public: public:
static registration<TItem>& get_instance(); static registration<TItem> &get_instance();
virtual ~registration() { if (_instance != nullptr) delete _instance; }; virtual ~registration() {
if (_instance != nullptr)
delete _instance;
};
public: public:
void add_item(const std::string& type, TItem* f); void add_item(const std::string &type, TItem *f);
TItem * get_item(const std::string& type); TItem *get_item(const std::string &type);
}; // End of class registration }; // End of class registration
template <typename TItem> template <typename TItem> registration<TItem> *registration<TItem>::_instance = nullptr;
registration<TItem>* registration<TItem>::_instance = nullptr;
// static functions // static functions
template <typename TItem> template <typename TItem> registration<TItem> &registration<TItem>::get_instance() {
registration<TItem>& registration<TItem>::get_instance()
{
return (_instance != nullptr) ? *_instance : *(_instance = new registration()); return (_instance != nullptr) ? *_instance : *(_instance = new registration());
} }
template <typename TItem> template <typename TItem> void registration<TItem>::add_item(const std::string &type, TItem *f) { _items[type] = f; }
void registration<TItem>::add_item(const std::string & type, TItem * f)
{
_items[type] = f;
}
template <typename TItem> template <typename TItem> TItem *registration<TItem>::get_item(const std::string &type) {
TItem* registration<TItem>::get_item(const std::string & type) typename std::map<std::string, TItem *>::const_iterator it = _items.find(type);
{
typename std::map<std::string, TItem*>::const_iterator it =_items.find(type);
if (it == _items.cend()) { if (it == _items.cend()) {
return nullptr; return nullptr;
} }
......
...@@ -10,4 +10,4 @@ ...@@ -10,4 +10,4 @@
*/ */
#include "base_time.hh" #include "base_time.hh"
base_time* base_time::_instance = nullptr; base_time *base_time::_instance = nullptr;
#include "codec_stack_builder.hh" #include "codec_stack_builder.hh"
codec_stack_builder* codec_stack_builder::_instance = NULL; codec_stack_builder *codec_stack_builder::_instance = NULL;
#include "converter.hh" #include "converter.hh"
#include <stdexcept> #include <stdexcept>
converter * converter::instance = NULL; converter *converter::instance = NULL;
uint16_t converter::swap(const uint16_t p_value) { uint16_t converter::swap(const uint16_t p_value) {
uint8_t *ptr = (uint8_t *)&p_value; uint8_t *ptr = (uint8_t *)&p_value;
...@@ -14,16 +14,10 @@ uint32_t converter::swap(const uint32_t p_value) { ...@@ -14,16 +14,10 @@ uint32_t converter::swap(const uint32_t p_value) {
const std::string converter::lut_u = "0123456789ABCDEF"; const std::string converter::lut_u = "0123456789ABCDEF";
const std::string converter::lut_l = "0123456789abcdef"; const std::string converter::lut_l = "0123456789abcdef";
std::string converter::string_to_hexa(const std::string & p_value, const bool p_uppercase) { std::string converter::string_to_hexa(const std::string &p_value, const bool p_uppercase) {
std::string input(p_value); std::string input(p_value);
std::for_each( std::for_each(input.begin(), input.end(), [](char &c) { c = std::toupper(c); });
input.begin(),
input.end(),
[](char & c) {
c = std::toupper(c);
}
);
std::string output; std::string output;
uint32_t length = p_value.length(); uint32_t length = p_value.length();
...@@ -45,20 +39,20 @@ std::string converter::string_to_hexa(const std::string & p_value, const bool p_ ...@@ -45,20 +39,20 @@ std::string converter::string_to_hexa(const std::string & p_value, const bool p_
return output; return output;
} }
std::string converter::bytes_to_hexa(const std::vector<uint8_t> & p_value, const bool p_uppercase) { std::string converter::bytes_to_hexa(const std::vector<uint8_t> &p_value, const bool p_uppercase) {
std::string ret; std::string ret;
ret.assign(p_value.size()*2, ' '); ret.assign(p_value.size() * 2, ' ');
if (p_uppercase) { // TODO Use pointer to reduce code size if (p_uppercase) { // TODO Use pointer to reduce code size
for(size_t i=0; i<p_value.size(); i++){ for (size_t i = 0; i < p_value.size(); i++) {
uint8_t c = p_value[i]; uint8_t c = p_value[i];
ret[i*2] = lut_u[c>>4]; ret[i * 2] = lut_u[c >> 4];
ret[i*2+1] = lut_u[c&0xF]; ret[i * 2 + 1] = lut_u[c & 0xF];
} }
} else { } else {
for(size_t i=0; i<p_value.size(); i++){ for (size_t i = 0; i < p_value.size(); i++) {
uint8_t c = p_value[i]; uint8_t c = p_value[i];
ret[i*2] = lut_l[c>>4]; ret[i * 2] = lut_l[c >> 4];
ret[i*2+1] = lut_l[c&0xF]; ret[i * 2 + 1] = lut_l[c & 0xF];
} }
} }
return ret; return ret;
...@@ -66,48 +60,47 @@ std::string converter::bytes_to_hexa(const std::vector<uint8_t> & p_value, const ...@@ -66,48 +60,47 @@ std::string converter::bytes_to_hexa(const std::vector<uint8_t> & p_value, const
inline uint8_t char2byte(const char p_ch) { inline uint8_t char2byte(const char p_ch) {
size_t s = converter::lut_l.find(p_ch); size_t s = converter::lut_l.find(p_ch);
if(s == std::string::npos) { if (s == std::string::npos) {
if ((s = converter::lut_u.find(p_ch)) == std::string::npos) { if ((s = converter::lut_u.find(p_ch)) == std::string::npos) {
throw (std::length_error("")); throw(std::length_error(""));
} }
} }
return s; return s;
} }
std::vector<uint8_t> converter::hexa_to_bytes(const std::string & p_value) { std::vector<uint8_t> converter::hexa_to_bytes(const std::string &p_value) {
// Sanity check // Sanity check
std::vector<uint8_t> output; std::vector<uint8_t> output;
size_t i=0, idx = 0, outlen=(p_value.length()+1) / 2; size_t i = 0, idx = 0, outlen = (p_value.length() + 1) / 2;
output.assign(outlen, 0x00); output.assign(outlen, 0x00);
try{ try {
if (p_value.length() & 1) if (p_value.length() & 1)
output[idx++] = char2byte(p_value[i++]); output[idx++] = char2byte(p_value[i++]);
for(;idx<outlen;idx++){ for (; idx < outlen; idx++) {
uint8_t b0 = char2byte(p_value[i++]); uint8_t b0 = char2byte(p_value[i++]);
uint8_t b1 = char2byte(p_value[i++]); uint8_t b1 = char2byte(p_value[i++]);
output[idx] = (b0<<4)|b1; output[idx] = (b0 << 4) | b1;
}
} }
catch (const std::length_error& le) { } catch (const std::length_error &le) {
output.clear(); output.clear();
} }
return output; return output;
} }
std::string converter::time_to_string(const time_t p_time) { std::string converter::time_to_string(const time_t p_time) {
struct tm * t = std::localtime(&p_time); struct tm *t = std::localtime(&p_time);
return time_to_string(*t); return time_to_string(*t);
} }
std::string converter::time_to_string(const struct tm & p_time) { std::string converter::time_to_string(const struct tm &p_time) {
char buffer[64] = { 0 }; char buffer[64] = {0};
// Format: RFC 822, 1036, 1123, 2822 // Format: RFC 822, 1036, 1123, 2822
std::strftime(buffer, 64, "%a, %d %b %Y %H:%M:%S %z", &p_time); std::strftime(buffer, 64, "%a, %d %b %Y %H:%M:%S %z", &p_time);
return std::string(buffer); return std::string(buffer);
} }
std::string converter::trim(const std::string& str, const std::string& whitespace) { std::string converter::trim(const std::string &str, const std::string &whitespace) {
size_t strBegin = str.find_first_not_of(whitespace); size_t strBegin = str.find_first_not_of(whitespace);
if (strBegin == std::string::npos) if (strBegin == std::string::npos)
return ""; // no content return ""; // no content
...@@ -118,7 +111,7 @@ std::string converter::trim(const std::string& str, const std::string& whitespac ...@@ -118,7 +111,7 @@ std::string converter::trim(const std::string& str, const std::string& whitespac
return str.substr(strBegin, strRange); return str.substr(strBegin, strRange);
} }
std::vector<std::string> converter::split(const std::string & p_value, const std::string& p_separator) { std::vector<std::string> converter::split(const std::string &p_value, const std::string &p_separator) {
std::vector<std::string> output; std::vector<std::string> output;
std::size_t current, previous = 0; std::size_t current, previous = 0;
current = p_value.find(p_separator); current = p_value.find(p_separator);
...@@ -132,7 +125,7 @@ std::vector<std::string> converter::split(const std::string & p_value, const std ...@@ -132,7 +125,7 @@ std::vector<std::string> converter::split(const std::string & p_value, const std
return output; return output;
} }
std::vector<std::string> converter::split_arguments_line(const std::string & p_value) { std::vector<std::string> converter::split_arguments_line(const std::string &p_value) {
std::vector<std::string> output; std::vector<std::string> output;
std::string line = trim(p_value); std::string line = trim(p_value);
if (!line.empty() && (line[0] == '-')) { // Valid command line if (!line.empty() && (line[0] == '-')) { // Valid command line
...@@ -156,7 +149,7 @@ std::vector<std::string> converter::split_arguments_line(const std::string & p_v ...@@ -156,7 +149,7 @@ std::vector<std::string> converter::split_arguments_line(const std::string & p_v
const std::string converter::base64_enc_map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; const std::string converter::base64_enc_map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
std::vector<unsigned char> converter::buffer_to_base64(const std::vector<unsigned char> & p_value) { std::vector<unsigned char> converter::buffer_to_base64(const std::vector<unsigned char> &p_value) {
std::vector<unsigned char> out; std::vector<unsigned char> out;
int val = 0, valb = -6; int val = 0, valb = -6;
......
#include <stdexcept>
#include <regex> #include <regex>
#include <stdexcept>
#include "layer_stack_builder.hh" #include "layer_stack_builder.hh"
#include "loggers.hh" #include "loggers.hh"
layer_stack_builder* layer_stack_builder::_instance = NULL; layer_stack_builder *layer_stack_builder::_instance = NULL;
// static functions // static functions
layer_stack_builder * layer_stack_builder::get_instance() layer_stack_builder *layer_stack_builder::get_instance() { return _instance ? _instance : _instance = new layer_stack_builder(); }
{
return _instance ? _instance : _instance = new layer_stack_builder();
}
void layer_stack_builder::register_layer_factory(const std::string & p_type, layer_factory* p_layer_factory) void layer_stack_builder::register_layer_factory(const std::string &p_type, layer_factory *p_layer_factory) {
{
layer_stack_builder::get_instance()->_register_layer_factory(p_type, p_layer_factory); layer_stack_builder::get_instance()->_register_layer_factory(p_type, p_layer_factory);
} }
// member functions // member functions
layer_stack_builder::layer_stack_builder() layer_stack_builder::layer_stack_builder() {}
{
}
void layer_stack_builder::_register_layer_factory(const std::string & p_type, layer_factory* p_layer_factory) void layer_stack_builder::_register_layer_factory(const std::string &p_type, layer_factory *p_layer_factory) { _layer_factories[p_type] = p_layer_factory; }
{
_layer_factories[p_type] = p_layer_factory;
}
layer* layer_stack_builder::create_layer_stack(const char* p_layer_stack_description) layer *layer_stack_builder::create_layer_stack(const char *p_layer_stack_description) {
{
loggers::get_instance().log(">>> layer_stack_builder::create_layer_stack: %s", p_layer_stack_description); loggers::get_instance().log(">>> layer_stack_builder::create_layer_stack: %s", p_layer_stack_description);
layer* entry = NULL; // Initial layer (the first declared) layer *entry = NULL; // Initial layer (the first declared)
layer* up = NULL; // Upper layer layer *up = NULL; // Upper layer
// Parse the layer description // Parse the layer description
try { try {
std::regex rgx ("(\\w+)(\\((.*?)\\))?(\\/|$)"); std::regex rgx("(\\w+)(\\((.*?)\\))?(\\/|$)");
std::string str = p_layer_stack_description; std::string str = p_layer_stack_description;
std::sregex_iterator begin(str.cbegin(), str.cend(), rgx); std::sregex_iterator begin(str.cbegin(), str.cend(), rgx);
std::sregex_iterator end = std::sregex_iterator(); std::sregex_iterator end = std::sregex_iterator();
for (std::sregex_iterator it = begin; it != end; ++it) { for (std::sregex_iterator it = begin; it != end; ++it) {
std::smatch m = *it; std::smatch m = *it;
loggers::get_instance().log("layer_stack_builder::create_layer_stack: %d - %s - %s - %s - %s", m.size(), m[0].str().c_str(), m[1].str().c_str(), m[2].str().c_str(), m[3].str().c_str()); loggers::get_instance().log("layer_stack_builder::create_layer_stack: %d - %s - %s - %s - %s", m.size(), m[0].str().c_str(), m[1].str().c_str(),
m[2].str().c_str(), m[3].str().c_str());
LayerFactoryMap::iterator i = _layer_factories.find(m[1].str()); LayerFactoryMap::iterator i = _layer_factories.find(m[1].str());
if (i == _layer_factories.end()) { if (i == _layer_factories.end()) {
loggers::get_instance().error("layer_stack_builder::create_layer_stack: %s: Unknown layer type", m[1].str().c_str()); loggers::get_instance().error("layer_stack_builder::create_layer_stack: %s: Unknown layer type", m[1].str().c_str());
} }
loggers::get_instance().log("layer_stack_builder::create_layer_stack: Create layer %s, %s", m[1].str().c_str(), m[3].str().c_str()); loggers::get_instance().log("layer_stack_builder::create_layer_stack: Create layer %s, %s", m[1].str().c_str(), m[3].str().c_str());
layer* l = i->second->create_layer(m[1].str(), m[3].str()); layer *l = i->second->create_layer(m[1].str(), m[3].str());
if (NULL == l) { if (NULL == l) {
loggers::get_instance().error("layer_stack_builder::create_layer_stack: %s: Layer creation error", m[1].str().c_str()); loggers::get_instance().error("layer_stack_builder::create_layer_stack: %s: Layer creation error", m[1].str().c_str());
} }
...@@ -60,9 +51,8 @@ layer* layer_stack_builder::create_layer_stack(const char* p_layer_stack_descrip ...@@ -60,9 +51,8 @@ layer* layer_stack_builder::create_layer_stack(const char* p_layer_stack_descrip
} }
up = l; // Build the linked list of layers up = l; // Build the linked list of layers
} // End of 'for' statement } // End of 'for' statement
} } catch (const std::logic_error &e) {
catch(const std::logic_error& e){ if (up) { // FIXME To be reviewed
if(up){ // FIXME To be reviewed
up->delete_layer(); up->delete_layer();
up = NULL; up = NULL;
} }
......