Commit 976f5ffd authored by Yann Garcia's avatar Yann Garcia
Browse files

Bug fixed in Http headers namming

parent 3daa4678
Loading
Loading
Loading
Loading
+32 −19
Original line number Diff line number Diff line
@@ -78,11 +78,12 @@ int http_codec::decode (const OCTETSTRING& data, LibItsHttp__TypesAndValues::Htt
      response.statuscode() = std::stoi(m[3].str().c_str());
      response.statustext() = CHARSTRING(m[4].str().c_str());
      LibItsHttp__TypesAndValues::HeaderLines headers;
      decode_headers(decoding_buffer, headers);
      std::string content_type;
      decode_headers(decoding_buffer, headers, content_type);
      response.header() = headers;
      loggers::get_instance().log_to_hexa("Before decoding Body: ", decoding_buffer);
      LibItsHttp__MessageBodyTypes::HttpMessageBody body;
      if (decode_body(decoding_buffer, body, std::string("application/x-its-request"/*TODO Add Content-Type*/)) == -1) {
      if (decode_body(decoding_buffer, body, content_type) == -1) {
        response.body().set_to_omit();
      } else {
        response.body() = OPTIONAL<LibItsHttp__MessageBodyTypes::HttpMessageBody>(body);
@@ -102,11 +103,12 @@ int http_codec::decode (const OCTETSTRING& data, LibItsHttp__TypesAndValues::Htt
      request.version__major() = std::stoi(m[3].str().c_str());
      request.version__minor() = std::stoi(m[4].str().c_str());
      LibItsHttp__TypesAndValues::HeaderLines headers;
      decode_headers(decoding_buffer, headers);
      std::string content_type;
      decode_headers(decoding_buffer, headers, content_type);
      request.header() = headers;
      OPTIONAL<LibItsHttp__MessageBodyTypes::HttpMessageBody> body;
      body.set_to_omit();
      if (decode_body(decoding_buffer, body, std::string("application/x-its-request"/*TODO Add Content-Type*/)) == -1) {
      if (decode_body(decoding_buffer, body, content_type) == -1) {
        request.body().set_to_omit();
      } else {
        request.body() = body;
@@ -136,13 +138,13 @@ int http_codec::encode_request(const LibItsHttp__TypesAndValues::Request& p_requ
  p_encoding_buffer.put_cs(int2str(p_request.version__minor()));
  p_encoding_buffer.put_cs("\r\n");
  
  // Encode headers excepeted the Content-length
  // Encode headers excepeted the Content-Length
  const LibItsHttp__TypesAndValues::HeaderLines& headers = p_request.header();
  std::string content_type;
  for (int i = 0; i < headers.size_of(); i++) {
    const LibItsHttp__TypesAndValues::HeaderLine& header = headers[i];
    loggers::get_instance().log_msg("http_codec::encode_request: Processing header ", header.header__name());
    if (std::string(static_cast<const char*>(header.header__name())).compare("Content-length") == 0) { // Skip it, processed later
    if (std::string(static_cast<const char*>(header.header__name())).compare("Content-Length") == 0) { // Skip it, processed later
      loggers::get_instance().log("http_codec::encode_request: Skip it");
      continue;
    } else {
@@ -153,8 +155,8 @@ int http_codec::encode_request(const LibItsHttp__TypesAndValues::Request& p_requ
        const LibItsHttp__TypesAndValues::charstring__list& v = dynamic_cast<const OPTIONAL<LibItsHttp__TypesAndValues::charstring__list> &>(o);
        if (v.size_of() > 0) {
          loggers::get_instance().log_msg("http_codec::encode_request: Processing value ", v[0]);
          if (std::string(static_cast<const char*>(header.header__name())).compare("Content-type") == 0) { // Store it for HTTP body payload encoding
            loggers::get_instance().log("http_codec::encode_request: Storing Content-type");
          if (std::string(static_cast<const char*>(header.header__name())).compare("Content-Type") == 0) { // Store it for HTTP body payload encoding
            loggers::get_instance().log("http_codec::encode_request: Storing Content-Type");
            int j = 0;
            while (j < v.size_of()) {
              content_type += v[j++];
@@ -194,10 +196,10 @@ int http_codec::encode_request(const LibItsHttp__TypesAndValues::Request& p_requ
    _ec.is_content_length_present = 0x00;
  }

  // Encode Content-length header
  p_encoding_buffer.put_cs("Content-length: ");
  // Encode Content-Length header
  p_encoding_buffer.put_cs("Content-Length: ");
  if (_ec.length != 0) {
    loggers::get_instance().log("http_codec::encode_request: Content-length: %s", static_cast<const char*>(int2str(_ec.length + 2/*Stand for the last CRLF*/)));
    loggers::get_instance().log("http_codec::encode_request: Content-Length: %s", static_cast<const char*>(int2str(_ec.length + 2/*Stand for the last CRLF*/)));
    p_encoding_buffer.put_cs(static_cast<const char*>(int2str(_ec.length + 2/*Stand for the last CRLF*/)));
    _ec.is_content_length_present = 0x01;
  } else {
@@ -234,7 +236,7 @@ int http_codec::encode_response (const LibItsHttp__TypesAndValues::Response& p_r
  }
  p_encoding_buffer.put_cs("\r\n");
  
  // Encode headers excepeted the Content-length
  // Encode headers excepeted the Content-Length
  const LibItsHttp__TypesAndValues::HeaderLines& headers = p_response.header();
  std::string content_type;
  for (int i = 0; i < headers.size_of(); i++) {
@@ -250,7 +252,7 @@ int http_codec::encode_response (const LibItsHttp__TypesAndValues::Response& p_r
        const LibItsHttp__TypesAndValues::charstring__list& v = dynamic_cast<const OPTIONAL<LibItsHttp__TypesAndValues::charstring__list> &>(o);
        if (v.size_of() > 0) {
          loggers::get_instance().log_msg("http_codec::encode_response: Processing value ", v[0]);
          if (std::string(static_cast<const char*>(header.header__name())).compare("Content-type") == 0) { // Store it for HTTP body payload encoding
          if (std::string(static_cast<const char*>(header.header__name())).compare("Content-Type") == 0) { // Store it for HTTP body payload encoding
            int j = 1;
            while (j < v.size_of()) {
              content_type += v[j++];
@@ -290,7 +292,7 @@ int http_codec::encode_response (const LibItsHttp__TypesAndValues::Response& p_r
    _ec.is_content_length_present = 0x00;
  }

  // Encode Content-length header
  // Encode Content-Length header
  if (_ec.length != 0) {
    p_encoding_buffer.put_cs(int2str(_ec.length + 2/*Stand for the last CRLF*/));
    _ec.is_content_length_present = 0x01;
@@ -298,7 +300,7 @@ int http_codec::encode_response (const LibItsHttp__TypesAndValues::Response& p_r
    p_encoding_buffer.put_cs("0");
    _ec.is_content_length_present = 0x00;
  }
  loggers::get_instance().log("http_codec::encode_response: Content-length: %d - %x", _ec.length, _ec.is_content_length_present);
  loggers::get_instance().log("http_codec::encode_response: Content-Length: %d - %x", _ec.length, _ec.is_content_length_present);
  p_encoding_buffer.put_cs("\r\n");
  
  p_encoding_buffer.put_cs("\r\n");
@@ -310,7 +312,7 @@ int http_codec::encode_response (const LibItsHttp__TypesAndValues::Response& p_r
  return 0;
}

int http_codec::decode_headers(TTCN_Buffer& decoding_buffer, LibItsHttp__TypesAndValues::HeaderLines& headers) {
int http_codec::decode_headers(TTCN_Buffer& decoding_buffer, LibItsHttp__TypesAndValues::HeaderLines& headers, std::string& p_content_type) {
  loggers::get_instance().log(">>> http_codec::decode_headers");
  loggers::get_instance().log_to_hexa("http_codec::decode_headers", decoding_buffer);

@@ -326,6 +328,14 @@ int http_codec::decode_headers(TTCN_Buffer& decoding_buffer, LibItsHttp__TypesAn
            return -1;
          }
          headers[i++] = header;
          if (std::string(static_cast<const char*>(header.header__name())).compare("Content-Type") == 0) {
            if (header.header__value().is_present() != 0) {
              const PreGenRecordOf::PREGEN__RECORD__OF__CHARSTRING& l = static_cast<const PreGenRecordOf::PREGEN__RECORD__OF__CHARSTRING&>(*header.header__value().get_opt_value());
              p_content_type = static_cast<const char*>(l[0]);
            } else {
              p_content_type = "";
            }
          }
        }
        break;
      case 1:
@@ -429,7 +439,7 @@ int http_codec::encode_body(const LibItsHttp__MessageBodyTypes::HttpMessageBody&
    } else {
      std::map<std::string, std::unique_ptr<codec<Record_Type, Record_Type> > >::const_iterator it;
      bool processed = false;
      loggers::get_instance().log("http_codec::encode_body: Content-type:'%s'", p_content_type.c_str());
      loggers::get_instance().log("http_codec::encode_body: Content-Type:'%s'", p_content_type.c_str());
      if (p_content_type.find("held") != std::string::npos) {
        it = _codecs.find("held"); // TODO Use params
        if (it != _codecs.cend()) {
@@ -488,7 +498,7 @@ int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBod
  loggers::get_instance().log_msg("http_codec::decode_body: Convert string to binary: ", s);
#endif
  
  // Align the payload length with the specified Content-lenght value
  // Align the payload length with the specified Content-Lenght value
  loggers::get_instance().log("http_codec::decode_body: _dc.length=%d - body length=%d", _dc.length, s.lengthof());
  OCTETSTRING body;
  if (_dc.length != 0) {
@@ -590,7 +600,10 @@ int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBod
       loggers::get_instance().log("http_codec::decode_body: Find xml message");
       LibItsHttp__XmlMessageBodyTypes::XmlBody xml_body;
       // TODO To be refined adding a string identifier to check which codec to use. E.g. held_code.id() returns "xmlns=\"urn:ietf:params:xml:ns:geopriv:held\">"
       if (p["decode_str"].find("xmlns=\"urn:ietf:params:xml:ns:geopriv:held\"") != std::string::npos) {
       if (
           (p["decode_str"].find("xmlns=\"urn:ietf:params:xml:ns:geopriv:held\"") != std::string::npos) ||
           (p["decode_str"].find("xmlns=\"urn:ietf:params:xml:ns:pidf\"") != std::string::npos)
           ) {
         loggers::get_instance().log("http_codec::decode_body: Find 'urn:ietf:params:xml:ns:geopriv:held'");
         if (_codecs["held"].get() != nullptr) {
           loggers::get_instance().log("http_codec::decode_body: Call 'held_codec'");
+1 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ private:
  int encode_response (const LibItsHttp__TypesAndValues::Response& p_response, TTCN_Buffer& p_encoding_buffer);
  int encode_body(const LibItsHttp__MessageBodyTypes::HttpMessageBody& p_message_body, OCTETSTRING& p_encoding_buffer, const std::string& p_content_type);

  int decode_headers(TTCN_Buffer& decoding_buffer, LibItsHttp__TypesAndValues::HeaderLines& headers);
  int decode_headers(TTCN_Buffer& decoding_buffer, LibItsHttp__TypesAndValues::HeaderLines& headers, std::string& p_content_type);
  int decode_header(CHARSTRING& header_line, LibItsHttp__TypesAndValues::HeaderLine& header);
  int decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBodyTypes::HttpMessageBody& message_body, const std::string& p_content_type);
  int get_line(TTCN_Buffer& buffer, CHARSTRING& to, const bool concatenate_header_lines = false);
+12 −2
Original line number Diff line number Diff line
@@ -591,7 +591,10 @@ int sip_codec_headers::encode_sip_url(const LibSip__SIPTypesAndValues::SipUrl& p
    str += static_cast<const char*>(u.namespaceSpecificString());
    ::osip_uri_parse(uri, str.c_str());
  } else if (components.ischosen(LibSip__SIPTypesAndValues::UriComponents::ALT_other)) {
    loggers::get_instance().error("sip_codec_headers::encode_sip_uri: Unsupported LibSip__SIPTypesAndValues::UriComponents::ALT_other");
    std::string str(static_cast<const char*>(p_sip_uri.scheme()));
    str += ":";
    str += static_cast<const char*>(p_sip_uri.components().other());
    ::osip_uri_parse(uri, str.c_str());
  } // else, noting to do
  
  if (uri != nullptr) {
@@ -1642,7 +1645,14 @@ void sip_codec_headers::decode_uri(LibSip__SIPTypesAndValues::SipUrl& p_sip_url,
    } else {
      char *buffer = nullptr;
      ::osip_uri_to_str_canonical((osip_uri_t*)p_uri, &buffer);
      std::string str(buffer);
      const char* p = static_cast<const char*>(p_sip_url.scheme());
      size_t i = str.find(p);
      if (i == std::string::npos) {
        uri_components.other() = CHARSTRING(buffer);
      } else {
        uri_components.other() = CHARSTRING(str.substr(i + strlen(p) + 1).c_str());
      }
      osip_free(buffer); // Macro
    }
  } else {
+8 −8
Original line number Diff line number Diff line
@@ -2,20 +2,20 @@
# This section shall contain the values of all parameters that are defined in your TTCN-3 modules.

# IUT roles
LibNg112_Pics.PICS_LIS_IUT := false;
LibNg112_Pics.PICS_LIS_IUT := true;
LibNg112_Pics.PICS_ECRF_IUT := false;
LibNg112_Pics.PICS_ESRP_IUT := false;
LibNg112_Pics.PICS_PSAP_IUT := true;
LibNg112_Pics.PICS_PSAP_IUT := false;

LibCommon_Time.PX_TAC := 30.0
LibCommon_Sync.PX_TSYNC_TIME_LIMIT := 30.0;
LibCommon_Sync.PX_TSHUT_DOWN_TIME_LIMIT := 30.0;

#LibItsHttp_Pics.PICS_HEADER_HOST := "lis.gridgears.io" # Used for LIS
LibItsHttp_Pics.PICS_HEADER_HOST := "ecrf.gridgears.io" # Used for ECRF
LibItsHttp_Pics.PICS_HEADER_HOST := "lis.gridgears.io" # Used for LIS
#LibItsHttp_Pics.PICS_HEADER_HOST := "ecrf.gridgears.io" # Used for ECRF

#LibItsHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/held+xml;charset=utf-8"
LibItsHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/lost+xml;charset=utf-8"
LibItsHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/held+xml;charset=utf-8"
#LibItsHttp_Pics.PICS_HEADER_CONTENT_TYPE := "application/lost+xml;charset=utf-8"

#LibNg112_Pics.PICS_HTTP_GET_REQUEST := false
#LibNg112_Pics.PICS_HTTP_POST_REQUEST := false
@@ -78,7 +78,7 @@ CallTaker.SIPP.params := "SIP/UDP(dst_ip=172.24.1.241,dst_port=5060,src_port=506

[EXECUTE]
# In this section you can specify what parts of your test suite you want to execute.
AtsNg112_TestControl.control
#AtsNg112_TestControl.control

#AtsNg112_TestCases.TC_LIS_HTTP_POST_BV_01
#AtsNg112_TestCases.TC_LIS_HTTP_POST_BV_02
@@ -87,7 +87,7 @@ AtsNg112_TestControl.control
#AtsNg112_TestCases.TC_LIS_HTTP_POST_BV_05
#AtsNg112_TestCases.TC_LIS_HTTP_POST_BV_06
#AtsNg112_TestCases.TC_LIS_HTTP_POST_BV_07
#AtsNg112_TestCases.TC_LIS_HTTP_GET_BV_01
AtsNg112_TestCases.TC_LIS_HTTP_GET_BV_01
#AtsNg112_TestCases.TC_LIS_HTTP_GET_BV_02
#AtsNg112_TestCases.TC_ECRF_HTTP_POST_BV_01
#AtsNg112_TestCases.TC_ECRF_HTTP_POST_BV_02
+1 −1
Original line number Diff line number Diff line
@@ -303,7 +303,7 @@ module LibItsHttp_XmlTemplates {
    template Tuple mw_tuple(
                            template (present) universal charstring p_id := ?,
                            template (present) Status p_status := ?,
                            template (present) Tuple.elem_list p_elem_list := {},
                            template (present) Tuple.elem_list p_elem_list := ?,
                            template (present) Tuple.note_list p_note_list := {},
                            template Contact p_contact := *
    ) := {