Commit ef634498 authored by Yann Garcia's avatar Yann Garcia
Browse files

Editorial changes; CV2x#4 validation for AtsCAM; Enhance .cfg files

parent 9d95325e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -380,14 +380,14 @@ public:
   * \param[in] p_value The buffer value
   * \return The Base64 encoded buffert
   */
  std::vector<unsigned char> buffer_to_base64(const std::vector<unsigned char> &p_value, const bool p_is_url = false);
  std::vector<uint8_t> buffer_to_base64(const std::vector<uint8_t> &p_value, const bool p_is_url = false);

  /*!
   * \brief Convert the provided Base64 buffer
   * \param[in] p_value The buffer value
   * \return The Base64 encoded buffert
   */
  std::vector<unsigned char> base64_to_buffer(const std::vector<unsigned char> &p_value, const bool p_remove_crlf = true);
  std::vector<uint8_t> base64_to_buffer(const std::vector<uint8_t> &p_value, const bool p_remove_crlf = true);

  static const std::string lut_u;
  static const std::string lut_l;
+11 −11
Original line number Diff line number Diff line
@@ -159,13 +159,13 @@ const std::string converter::base64_enc_map[2] = {
 * @param[in] chr 
 * @return Return the position of chr within base64_encode()
 */
static unsigned char pos_of_char(const unsigned char chr) {
static uint8_t pos_of_char(const uint8_t chr) {
  if ((chr >= 'A' && chr <= 'Z')) {
    return static_cast<unsigned char>(chr - 'A');
    return static_cast<uint8_t>(chr - 'A');
  } else if ((chr >= 'a' && chr <= 'z')) {
    return static_cast<unsigned char>(chr - 'a' + ('Z' - 'A') + 1);
    return static_cast<uint8_t>(chr - 'a' + ('Z' - 'A') + 1);
  } else if ((chr >= '0' && chr <= '9')) {
    return static_cast<unsigned char>(chr - '0' + ('Z' - 'A') + ('z' - 'a') + 2);
    return static_cast<uint8_t>(chr - '0' + ('Z' - 'A') + ('z' - 'a') + 2);
  } else if ((chr == '+' || chr == '-')) {
    return 62; // Be liberal with input and accept both url ('-') and non-url ('+') base 64 characters (
  } else if ((chr == '/' || chr == '_')) {
@@ -197,11 +197,11 @@ std::string converter::replace(const std::string& p_value, const std::string& p_
  return str; 
}

std::vector<unsigned char> converter::buffer_to_base64(const std::vector<unsigned char> &p_value, const bool p_is_url) {
std::vector<uint8_t> converter::buffer_to_base64(const std::vector<uint8_t> &p_value, const bool p_is_url) {
  const std::string& base64_enc_map_ = converter::base64_enc_map[(p_is_url) ? 1 : 0];
  const unsigned char trailing_char = (p_is_url) ? '.' : '=';
  const uint8_t trailing_char = (p_is_url) ? '.' : '=';

  std::vector<unsigned char> out;
  std::vector<uint8_t> out;
  //out.resize((p_value.size() + 2) / 3 * 4);

  unsigned int pos = 0;
@@ -229,19 +229,19 @@ std::vector<unsigned char> converter::buffer_to_base64(const std::vector<unsigne
  return out;
}

std::vector<unsigned char> converter::base64_to_buffer(const std::vector<unsigned char> &p_value, const bool p_remove_crlf) {
std::vector<uint8_t> converter::base64_to_buffer(const std::vector<uint8_t> &p_value, const bool p_remove_crlf) {

  if (p_value.size() == 0) {
    return std::vector<unsigned char>();
    return std::vector<uint8_t>();
  }

  std::vector<unsigned char> value(p_value);
  std::vector<uint8_t> value(p_value);
  if (p_remove_crlf) {
    value.erase(std::remove(value.begin(), value.end(), '\r'), value.end());
    value.erase(std::remove(value.begin(), value.end(), '\n'), value.end());
  }

  std::vector<unsigned char> out;
  std::vector<uint8_t> out;
  //out.resize(value.size() / 4 * 3);

  size_t pos = 0;
+6 −6
Original line number Diff line number Diff line
@@ -57,8 +57,8 @@ namespace LibHelpers__Functions {
  OCTETSTRING fx__enc__base64(const OCTETSTRING& p_to_encode) {
    loggers::get_instance().log_msg(">>> fx__enc__base64: ", p_to_encode);

    const std::vector<unsigned char> to_encode(static_cast<const unsigned char*>(p_to_encode), static_cast<const unsigned char*>(p_to_encode) + p_to_encode.lengthof());
    std::vector<unsigned char> b64 = converter::get_instance().buffer_to_base64(to_encode);
    const std::vector<uint8_t> to_encode(static_cast<const uint8_t*>(p_to_encode), static_cast<const uint8_t*>(p_to_encode) + p_to_encode.lengthof());
    std::vector<uint8_t> b64 = converter::get_instance().buffer_to_base64(to_encode);
    OCTETSTRING os(b64.size(), b64.data());
    loggers::get_instance().log_msg("<<< fx__enc__base64: ", os);
    return os;
@@ -72,18 +72,18 @@ namespace LibHelpers__Functions {
  OCTETSTRING fx__dec__base64(const OCTETSTRING& p_to_decode) {
    loggers::get_instance().log_msg(">>> fx__dec__base64: ", p_to_decode);

    const std::vector<unsigned char> to_decode(static_cast<const unsigned char*>(p_to_decode), static_cast<const unsigned char*>(p_to_decode) + p_to_decode.lengthof());
    std::vector<unsigned char> b64 = converter::get_instance().base64_to_buffer(to_decode);
    const std::vector<uint8_t> to_decode(static_cast<const uint8_t*>(p_to_decode), static_cast<const uint8_t*>(p_to_decode) + p_to_decode.lengthof());
    std::vector<uint8_t> b64 = converter::get_instance().base64_to_buffer(to_decode);
    OCTETSTRING os(b64.size(), b64.data());
    loggers::get_instance().log_msg("<<< fx__dec__base64: ", os);
    return os;
  }

  static unsigned char random_char() {
  static uint8_t random_char() {
    std::random_device rd;
    std::mt19937 gen(rd()); 
    std::uniform_int_distribution<> dis(0, 255);
    return static_cast<unsigned char>(dis(gen));
    return static_cast<uint8_t>(dis(gen));
  }

  static std::string generate_hex(const unsigned int len) {
+4 −4
Original line number Diff line number Diff line
@@ -60,15 +60,15 @@ void ethernet_layer::receive_data(OCTETSTRING& p_data, params& p_params) {
  loggers::get_instance().log_msg(">>> ethernet_layer::receive_data: ", p_data);

  // Extract dest MAC Address
  OCTETSTRING dst = OCTETSTRING(6, static_cast<const unsigned char *>(p_data));
  OCTETSTRING dst = OCTETSTRING(6, static_cast<const uint8_t *>(p_data));
  //loggers::get_instance().log_msg("ethernet_layer::receive_data: dst: ", dst);
  // Extract source MAC Address
  OCTETSTRING src = OCTETSTRING(6, 6 + static_cast<const unsigned char *>(p_data));
  OCTETSTRING src = OCTETSTRING(6, 6 + static_cast<const uint8_t *>(p_data));
  //loggers::get_instance().log_msg("ethernet_layer::receive_data: src: ", src);
  // Extract ethertype
  OCTETSTRING proto = OCTETSTRING(2, 2 + static_cast<const unsigned char *>(p_data));
  OCTETSTRING proto = OCTETSTRING(2, 2 + static_cast<const uint8_t *>(p_data));
  //loggers::get_instance().log_msg("ethernet_layer::receive_data: proto: ", proto);
  OCTETSTRING data = OCTETSTRING(p_data.lengthof() - 14, 14 + static_cast<const unsigned char *>(p_data));
  OCTETSTRING data = OCTETSTRING(p_data.lengthof() - 14, 14 + static_cast<const uint8_t *>(p_data));
  // Update params
  CHARSTRING s = oct2str(dst);
  p_params.insert(std::pair<std::string, std::string>(params::mac_dst, std::string(static_cast<const char *>(s))));
+14 −14
Original line number Diff line number Diff line
@@ -512,7 +512,7 @@ int http_codec::encode_body(const LibHttp__MessageBodyTypes::HttpMessageBody &p_
  if (p_message_body.ischosen(LibHttp__MessageBodyTypes::HttpMessageBody::ALT_binary__body)) {
    const LibHttp__BinaryMessageBodyTypes::BinaryBody &binary_body = p_message_body.binary__body();
    if (binary_body.ischosen(LibHttp__BinaryMessageBodyTypes::BinaryBody::ALT_raw)) {
      p_encoding_buffer = OCTETSTRING(binary_body.raw().lengthof(), (unsigned char *)static_cast<const unsigned char *>(binary_body.raw()));
      p_encoding_buffer = OCTETSTRING(binary_body.raw().lengthof(), (uint8_t *)static_cast<const uint8_t *>(binary_body.raw()));
    } else {
      encode_body_binary(binary_body, p_encoding_buffer, p_content_type);
    }
@@ -526,14 +526,14 @@ int http_codec::encode_body(const LibHttp__MessageBodyTypes::HttpMessageBody &p_
  } else if (p_message_body.ischosen(LibHttp__MessageBodyTypes::HttpMessageBody::ALT_xml__body)) {
    const LibHttp__XmlMessageBodyTypes::XmlBody &xml_body = p_message_body.xml__body();
    if (xml_body.msg().ischosen(LibHttp__XmlMessageBodyTypes::XmlBodyMsg::ALT_raw)) {
      p_encoding_buffer = OCTETSTRING(xml_body.msg().raw().lengthof(), (unsigned char *)static_cast<const char *>(xml_body.msg().raw()));
      p_encoding_buffer = OCTETSTRING(xml_body.msg().raw().lengthof(), (uint8_t *)static_cast<const char *>(xml_body.msg().raw()));
    } else {
      encode_body_xml(xml_body, p_encoding_buffer, p_content_type);
    }
  } else if (p_message_body.ischosen(LibHttp__MessageBodyTypes::HttpMessageBody::ALT_html__body)) {
    p_encoding_buffer = OCTETSTRING(p_message_body.html__body().lengthof(), (unsigned char *)static_cast<const char *>(p_message_body.html__body()));
    p_encoding_buffer = OCTETSTRING(p_message_body.html__body().lengthof(), (uint8_t *)static_cast<const char *>(p_message_body.html__body()));
  } else if (p_message_body.ischosen(LibHttp__MessageBodyTypes::HttpMessageBody::ALT_text__body)) {
    p_encoding_buffer = OCTETSTRING(p_message_body.text__body().lengthof(), (unsigned char *)static_cast<const char *>(p_message_body.text__body()));
    p_encoding_buffer = OCTETSTRING(p_message_body.text__body().lengthof(), (uint8_t *)static_cast<const char *>(p_message_body.text__body()));
  } else {
    loggers::get_instance().warning("http_codec::encode_body: Failed to encode HTTP message body");
    return -1;
@@ -567,7 +567,7 @@ int http_codec::decode_body(TTCN_Buffer &decoding_buffer, LibHttp__MessageBodyTy
  loggers::get_instance().log("http_codec::decode_body: _dc.length=%d - body length=%d", _dc.length, s.lengthof());
  OCTETSTRING body;
  if (_dc.length != 0) {
    const unsigned char *p = static_cast<const unsigned char *>(s);
    const uint8_t *p = static_cast<const uint8_t *>(s);
    if ((unsigned int)s.lengthof() <= _dc.length) {
      body = OCTETSTRING(s.lengthof(), p);
    } else {
@@ -589,7 +589,7 @@ int http_codec::decode_body(TTCN_Buffer &decoding_buffer, LibHttp__MessageBodyTy
    }
  }
  loggers::get_instance().log("http_codec::decode_body: counter=%d", counter);
  body = OCTETSTRING(body.lengthof() - counter, static_cast<const unsigned char*>(body));
  body = OCTETSTRING(body.lengthof() - counter, static_cast<const uint8_t*>(body));
  */
  if (_dc.chunked) {
    int         counter = 0;
@@ -605,9 +605,9 @@ int http_codec::decode_body(TTCN_Buffer &decoding_buffer, LibHttp__MessageBodyTy
      loggers::get_instance().log("http_codec::decode_body: Chunked(0): prev = %d, counter=%d / %d", prev, counter, body.lengthof());
      if (counter < body.lengthof()) {
        int         idx = counter - prev;
        OCTETSTRING trunk(idx, static_cast<const unsigned char *>(body));
        OCTETSTRING trunk(idx, static_cast<const uint8_t *>(body));
        loggers::get_instance().log_msg("http_codec::decode_body: trunk: ", trunk);
        std::string str((const char *)static_cast<const unsigned char *>(trunk), idx);
        std::string str((const char *)static_cast<const uint8_t *>(trunk), idx);
        loggers::get_instance().log("http_codec::decode_body: str: '%s'", str.c_str());
        int len = std::stoi(str, nullptr, 16); // converter::get_instance().string_to_int(str);
        loggers::get_instance().log("http_codec::decode_body: Chunk len: %d", len);
@@ -616,7 +616,7 @@ int http_codec::decode_body(TTCN_Buffer &decoding_buffer, LibHttp__MessageBodyTy
        } // End of 'while' statement
        if (counter < body.lengthof()) {
          loggers::get_instance().log("http_codec::decode_body: Chunked (1): prev = %d, counter=%d / %d", prev, counter, body.lengthof());
          os += OCTETSTRING(len, counter + static_cast<const unsigned char *>(body));
          os += OCTETSTRING(len, counter + static_cast<const uint8_t *>(body));
          loggers::get_instance().log_msg("http_codec::decode_body: os=", os);
          counter += len;
          loggers::get_instance().log("http_codec::decode_body: Chunked: %02x %02x %02x", body[counter].get_octet(), body[counter + 1].get_octet(),
@@ -635,7 +635,7 @@ int http_codec::decode_body(TTCN_Buffer &decoding_buffer, LibHttp__MessageBodyTy
  }
  // Check if HTTP message body contains binary characters
  for (int i = 0; i < body.lengthof(); i++) {
    unsigned char c = body[i].get_octet();
    uint8_t c = body[i].get_octet();
    if (!std::isprint(c) && !std::isspace(c) && !std::ispunct(c)) {
      loggers::get_instance().log("http_codec::decode_body: Byte #%d is not printable: 0x%02x", i, body[i].get_octet());
      _dc.is_binary = 0x01;
@@ -651,7 +651,7 @@ int http_codec::decode_body(TTCN_Buffer &decoding_buffer, LibHttp__MessageBodyTy
  } else {
    // Convert into string
    params p;
    p["decode_str"] = std::string(static_cast<const unsigned char *>(body), body.lengthof() + static_cast<const unsigned char *>(body));
    p["decode_str"] = std::string(static_cast<const uint8_t *>(body), body.lengthof() + static_cast<const uint8_t *>(body));
    loggers::get_instance().log("http_codec::decode_body: decode_str: '%s'", p["decode_str"].c_str());
    // Try to identify xml
    if (p["decode_str"].find("<?xml version=") != std::string::npos) {
@@ -672,7 +672,7 @@ int http_codec::decode_body(TTCN_Buffer &decoding_buffer, LibHttp__MessageBodyTy
    } else {
      loggers::get_instance().log("http_codec::decode_body: Use textBody as default");
      LibHttp__MessageBodyTypes::TextBody text_body;
      message_body.text__body() = CHARSTRING(body.lengthof(), (char *)static_cast<const unsigned char *>(body));
      message_body.text__body() = CHARSTRING(body.lengthof(), (char *)static_cast<const uint8_t *>(body));
    }
  }

@@ -681,7 +681,7 @@ int http_codec::decode_body(TTCN_Buffer &decoding_buffer, LibHttp__MessageBodyTy

int http_codec::get_line(TTCN_Buffer &buffer, CHARSTRING &to, const bool concatenate_header_lines) {
  unsigned int         i     = 0;
  const unsigned char *cc_to = buffer.get_read_data();
  const uint8_t *cc_to = buffer.get_read_data();

  // Sanity checks
  if (buffer.get_read_len() == 0) {
@@ -755,6 +755,6 @@ void http_codec::set_payload_codecs(const std::string& p_codecs) {
}

bool http_codec::decode_body_html(const OCTETSTRING &p_data, CHARSTRING &p_html_body, const std::string& p_content_type, params* p_params) {
  p_html_body = CHARSTRING(p_data.lengthof(), (char*)static_cast<const unsigned char*>(p_data));
  p_html_body = CHARSTRING(p_data.lengthof(), (char*)static_cast<const uint8_t*>(p_data));
  return true;
}
Loading