Commit 82f182b5 authored by Yann Garcia's avatar Yann Garcia
Browse files

Add SIP MIME support

parent c90b262d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
#include "urn_ietf_params_xml_ns_geopriv_held.hh"
#include "urn_ietf_params_xml_ns_pidf_geopriv10.hh"

// TODO Unify held_codec for bothHttp & Sip: instead of LibItsHttp__XmlMessageBodyTypes::XmlBody, use a generic XmlBody common to LibItsHttp & LibSip
int held_codec::encode (const LibItsHttp__XmlMessageBodyTypes::XmlBody& msg, OCTETSTRING& data)
{
  loggers::get_instance().log_msg(">>> held_codec::encode: ", (const Base_Type&)msg);
@@ -45,7 +46,7 @@ int held_codec::encode (const LibItsHttp__XmlMessageBodyTypes::XmlBody& msg, OCT
    } // End of 'while' statement
    data = OCTETSTRING(s.length(), (const unsigned char*)s.c_str());
  }
  loggers::get_instance().log_msg("held_codec::decode: After encoding: ", data);
  loggers::get_instance().log_msg("held_codec::encode: After encoding: ", data);
  
  loggers::get_instance().log("<<< held_codec::encode");
  return 0;
+6 −1
Original line number Diff line number Diff line
@@ -2363,10 +2363,15 @@ void sip_codec_headers::decode_via_header(const osip_message_t* p_sip_message, L
  do {
    loggers::get_instance().log("sip_codec_headers::decode_via_header: Processing item #%d", i);
    LibSip__SIPTypesAndValues::ViaBody v;
    v.sentProtocol() = LibSip__SIPTypesAndValues::SentProtocol(
    /*Buggy v.sentProtocol() = LibSip__SIPTypesAndValues::SentProtocol(
                                                               CHARSTRING(::via_get_protocol(sip_via)),
                                                               CHARSTRING(::via_get_version(sip_via)),
                                                               CHARSTRING(::via_get_comment(sip_via))
                                                               );*/
    v.sentProtocol() = LibSip__SIPTypesAndValues::SentProtocol(
                                                               CHARSTRING("SIP"),
                                                               CHARSTRING(::via_get_version(sip_via)),
                                                               CHARSTRING(::via_get_protocol(sip_via))
                                                               );
    OPTIONAL<LibSip__SIPTypesAndValues::HostPort> host_port;
    decode_host_port(::via_get_host(sip_via), ::via_get_port(sip_via), host_port);
+175 −50
Original line number Diff line number Diff line
@@ -6,6 +6,11 @@

#include "converter.hh"

#include "held_codec.hh"
#include "lost_codec.hh"

#include "urn_ietf_params_xml_ns_pidf.hh"

int sip_codec_message_body::encode (const LibSip__MessageBodyTypes::MessageBody& msg, OCTETSTRING& data)
{
  loggers::get_instance().log_msg(">>> sip_codec_message_body::encode: ", msg);
@@ -48,7 +53,7 @@ int sip_codec_message_body::decode (const OCTETSTRING& data, LibSip__MessageBody

int sip_codec_message_body::encode_message_body(const LibSip__MessageBodyTypes::MessageBody& p_message_body, osip_message_t* p_sip_message)
{ // TODO Rename into encode_message
  loggers::get_instance().log(">>> sip_codec_message_body::encode_message_body");
  loggers::get_instance().log_msg(">>> sip_codec_message_body::encode_message_body: ", p_message_body);

  osip_content_length* content_length = ::osip_message_get_content_length(p_sip_message);
  loggers::get_instance().log("sip_codec_message_body::encode_message_body: content_length= %s", content_length->value);
@@ -66,6 +71,54 @@ int sip_codec_message_body::encode_message_body(const LibSip__MessageBodyTypes::
      osip_free(buff);
      sdp_message_free(sdp_body);
    }
  } else if (p_message_body.ischosen(LibSip__MessageBodyTypes::MessageBody::ALT_mimeMessageBody)) {
    const LibSip__MessageBodyTypes::MIME__Message& mime = p_message_body.mimeMessageBody();
    const LibSip__MessageBodyTypes::MimeEncapsulatedList& l = mime.mimeEncapsulatedList();
    int pos = 0;
    while (pos < l.lengthof()) {
      const LibSip__MessageBodyTypes::MIME__Encapsulated__Part& p = l[pos];
      loggers::get_instance().log_msg("sip_codec_message_body::encode_message_body: p: ", p);
      const LibSip__MessageBodyTypes::MIME__Encapsulated__Parts& ps = p.mime__encapsulated__part();
      if (ps.ischosen(LibSip__MessageBodyTypes::MIME__Encapsulated__Parts::ALT_sdpMessageBody)) {
        const LibSip__SDPTypes::SDP__Message& sdp = ps.sdpMessageBody();
        sdp_message_t* sdp_body = nullptr;
        if (encode_sdp(sdp, &sdp_body) == -1) {
          loggers::get_instance().warning("sip_codec_message_body::encode_message_body: Failed to encode SDP message");
          return -1;
        }
        char* buff = nullptr;
        ::sdp_message_to_str(sdp_body, &buff);
        if (buff != nullptr) {
          loggers::get_instance().log("sip_codec_message_body::encode_message_body: sdp encoded value: %s", buff);
          if (::osip_message_set_body(p_sip_message, buff, strlen(buff)) != 0) {
            loggers::get_instance().warning("sip_codec_message_body::encode_message_body: Failed to encode SDP message");
          }
          osip_free(buff);
          sdp_message_free(sdp_body);
        }
      } else if (ps.ischosen(LibSip__MessageBodyTypes::MIME__Encapsulated__Parts::ALT_xmlBody)) {
        const LibSip__XMLTypes::XmlBody& xml = ps.xmlBody();
        osip_body_t* body;
        if (encode_xml(xml, &body) == -1) {
          loggers::get_instance().warning("sip_codec_message_body::encode_message_body: Failed to encode XML message");
          return -1;
        }
        loggers::get_instance().log("sip_codec_message_body::encode_message_body: xml encoded value: %s", body->body);
        if (::osip_message_set_body(p_sip_message, body->body, body->length) != 0) {
          loggers::get_instance().warning("sip_codec_message_body::encode_message_body: Failed to encode SDP message");
        }
        osip_body_free(body);
      } else if (ps.ischosen(LibSip__MessageBodyTypes::MIME__Encapsulated__Parts::ALT_msdBody)) {
        loggers::get_instance().warning("sip_codec_message_body::encode_message_body: Unsupported decoding of ALT_msdBody");
      } else {
        loggers::get_instance().warning("sip_codec_message_body::encode_message_body: Unsupported decoding of encapulated parts");
      }
      pos += 1;
    } // End of 'while' statement
    
  } else {
    loggers::get_instance().warning("sip_codec_message_body::encode_message_body: Unsupported variant");
    return -1;
  }
  
  return 0;
@@ -121,8 +174,8 @@ int sip_codec_message_body::encode_sdp(const LibSip__SDPTypes::SDP__Message& p_s
  loggers::get_instance().log_msg("sip_codec_message_body::encode_sdp: emails: ", p_sdp_message.emails());
  if (p_sdp_message.emails().is_present()) {
    const LibSip__SDPTypes::SDP__email__list& l = static_cast<const LibSip__SDPTypes::SDP__email__list&>(*p_sdp_message.emails().get_opt_value());
    for (int i = 0; i < l.lengthof(); i++) {
      const LibSip__SDPTypes::SDP__contact& e = l[i];
    for (int j = 0; j < l.lengthof(); j++) {
      const LibSip__SDPTypes::SDP__contact& e = l[j];
      std::string str;
      if (e.disp__name().is_present()) {
        str = static_cast<const char*>(static_cast<const CHARSTRING&>(*e.disp__name().get_opt_value()));
@@ -145,13 +198,29 @@ int sip_codec_message_body::encode_sdp(const LibSip__SDPTypes::SDP__Message& p_s
    for ( ; i < l.lengthof(); i++) {
      const LibSip__SDPTypes::SDP__media__desc m = l[i];
      loggers::get_instance().log_msg("sip_codec_message_body::encode_sdp: media: ", m);
      // Mandatory fields
      // Media field
      if (m.media__field().ports().num__of__ports().is_present()) {
        int p = static_cast<const INTEGER&>(*m.media__field().ports().num__of__ports().get_opt_value());
        ::sdp_message_m_media_add(*p_sdp_body, (char*)::strdup(static_cast<const char*>(m.media__field().media())), (char*)::strdup(std::to_string(m.media__field().ports().port__number()).c_str()), (char*)::strdup(std::to_string(p).c_str()), (char*)::strdup(static_cast<const char*>(m.media__field().transport())));
      } else {
        ::sdp_message_m_media_add(*p_sdp_body, (char*)::strdup(static_cast<const char*>(m.media__field().media())), (char*)::strdup(std::to_string(m.media__field().ports().port__number()).c_str()), NULL, (char*)::strdup(static_cast<const char*>(m.media__field().transport())));
      }
      // Format list
      const LibSip__SDPTypes::SDP__fmt__list& fmts = m.media__field().fmts();
      std::string str;
      for (int j = 0; j < fmts.lengthof() - 1; j++) {
        str += static_cast<const char*>(fmts[j]);
        str += " ";
      } // End of 'for' statement
      str += static_cast<const char*>(fmts[fmts.lengthof() - 1]);
      // information
      if (m.information().is_present()) {
        str += " ";
        str += static_cast<const char*>(static_cast<const CHARSTRING&>(*m.information().get_opt_value()));
      }
      if (str.length() != 0) {
        ::sdp_message_m_payload_add(*p_sdp_body, i, (char*)::strdup(str.c_str()));
      }
      // Attribute list, a
      loggers::get_instance().log_msg("sip_codec_message_body::encode_sdp: attributes: ", m.attributes());
      if (m.attributes().is_present()) {
@@ -160,21 +229,20 @@ int sip_codec_message_body::encode_sdp(const LibSip__SDPTypes::SDP__Message& p_s
          const LibSip__SDPTypes::SDP__attribute a = al[k];
          loggers::get_instance().log_msg("sip_codec_message_body::encode_sdp: attribute: ", a);
          if (a.ischosen(LibSip__SDPTypes::SDP__attribute::ALT_rtpmap)) {
            std::string strp("rtpmap:");
            strp += static_cast<const char*>(a.rtpmap().payload__type());
            std::string str(static_cast<const char*>(a.rtpmap().codec().encoding()));
            std::string str(static_cast<const char*>(a.rtpmap().payload__type()));
            str += " ";
            str += static_cast<const char*>(a.rtpmap().codec().encoding());
            str += " ";
            str += a.rtpmap().codec().clockrate();
            if (a.rtpmap().codec().parameters().is_present()) {
              str += "/";
              str += static_cast<const char*>(static_cast<const CHARSTRING&>(*a.rtpmap().codec().parameters().get_opt_value()));
            }
            loggers::get_instance().log("sip_codec_message_body::encode_sdp: attribute: media #%d: encode %s - %s", i, strp.c_str(), str.c_str());
            ::sdp_message_a_attribute_add(*p_sdp_body, i, (char*)::strdup(strp.c_str()), (char*)::strdup(str.c_str()));
            loggers::get_instance().log("sip_codec_message_body::encode_sdp: attribute: media #%d: encode rtpmap:%s", i, str.c_str());
            ::sdp_message_a_attribute_add(*p_sdp_body, i, (char*)::strdup("rtpmap"), (char*)::strdup(str.c_str()));
          } else if (a.ischosen(LibSip__SDPTypes::SDP__attribute::ALT_fmtp)) {
            std::string strp("fmtp:");
            strp += static_cast<const char*>(a.fmtp().format());
            std::string str;
            std::string str(static_cast<const char*>(a.fmtp().format()));
            str += " ";
            if (a.fmtp().params().ischosen(LibSip__SDPTypes::SDP__attribute__fmtp__format__specific__params::ALT_paramList)) {
              const LibSip__Common::SemicolonParam__List& sl = a.fmtp().params().paramList();
              for (int k = 0; k < sl.lengthof(); k++) {
@@ -192,19 +260,17 @@ int sip_codec_message_body::encode_sdp(const LibSip__SDPTypes::SDP__Message& p_s
                str += ";";
              } // End of 'for' statement
            } else {
              str.assign(static_cast<const char*>(a.fmtp().params().unstructured()));
              str += static_cast<const char*>(a.fmtp().params().unstructured());
            }
            ::sdp_message_a_attribute_add(*p_sdp_body, i, (char*)::strdup(strp.c_str()), (char*)::strdup(str.c_str()));
            ::sdp_message_a_attribute_add(*p_sdp_body, i, (char*)::strdup("fmtp"), (char*)::strdup(str.c_str()));
          } else if (a.ischosen(LibSip__SDPTypes::SDP__attribute::ALT_curr)) {
            std::string strp("curr:");
            std::string str(static_cast<const char*>(a.curr().preconditionType()));
            str += " ";
            str += static_cast<const char*>(a.curr().statusType());
            str += " ";
            str += static_cast<const char*>(a.curr().direction());
            ::sdp_message_a_attribute_add(*p_sdp_body, i, (char*)::strdup(strp.c_str()), (char*)::strdup(str.c_str()));
            ::sdp_message_a_attribute_add(*p_sdp_body, i, (char*)::strdup("curr"), (char*)::strdup(str.c_str()));
          } else if (a.ischosen(LibSip__SDPTypes::SDP__attribute::ALT_des)) {
            std::string strp("des:");
            std::string str(static_cast<const char*>(a.des().preconditionType()));
            str += " ";
            str += static_cast<const char*>(a.des().strength());
@@ -212,13 +278,11 @@ int sip_codec_message_body::encode_sdp(const LibSip__SDPTypes::SDP__Message& p_s
            str += static_cast<const char*>(a.des().statusType());
            str += " ";
            str += static_cast<const char*>(a.des().direction());
            ::sdp_message_a_attribute_add(*p_sdp_body, i, (char*)::strdup(strp.c_str()), (char*)::strdup(str.c_str()));
            ::sdp_message_a_attribute_add(*p_sdp_body, i, (char*)::strdup("des"), (char*)::strdup(str.c_str()));
          } else if (a.ischosen(LibSip__SDPTypes::SDP__attribute::ALT_maxptime)) {
            ::sdp_message_a_attribute_add(*p_sdp_body, i, (char*)::strdup("maxptime"), (char*)::strdup(static_cast<const char*>(a.maxptime().attr__value())));
          } else if (a.ischosen(LibSip__SDPTypes::SDP__attribute::ALT_sendrecv)) {
            ::sdp_message_a_attribute_add(*p_sdp_body, i, (char*)::strdup("sendrecv"), nullptr);
          } else if (a.ischosen(LibSip__SDPTypes::SDP__attribute::ALT_maxptime)) {
            std::string str("maxptime:");
            str += static_cast<const char*>(a.maxptime().attr__value());
            ::sdp_message_a_attribute_add(*p_sdp_body, i, (char*)::strdup(str.c_str()), NULL);
          } else {
            loggers::get_instance().warning("sip_codec_message_body::encode_sdp: attribute not processed");
          }
@@ -236,7 +300,8 @@ int sip_codec_message_body::encode_sdp(const LibSip__SDPTypes::SDP__Message& p_s
      const LibSip__SDPTypes::SDP__attribute a = l[i];
      loggers::get_instance().log_msg("sip_codec_message_body::encode_sdp: attribute: ", a);
      if (a.ischosen(LibSip__SDPTypes::SDP__attribute::ALT_rtpmap)) {
        std::string str("rtpmap:");
        std::string str(static_cast<const char*>(a.rtpmap().payload__type()));
        str += " ";
        str += static_cast<const char*>(a.rtpmap().codec().encoding());
        str += " ";
        str += a.rtpmap().codec().clockrate();
@@ -244,11 +309,11 @@ int sip_codec_message_body::encode_sdp(const LibSip__SDPTypes::SDP__Message& p_s
          str += "/";
          str += static_cast<const char*>(static_cast<const CHARSTRING&>(*a.rtpmap().codec().parameters().get_opt_value()));
        }
        ::sdp_message_a_attribute_add(*p_sdp_body, 0, (char*)::strdup(static_cast<const char*>(a.rtpmap().payload__type())), (char*)::strdup(str.c_str()));
        loggers::get_instance().log("sip_codec_message_body::encode_sdp: attribute: media #%d: encode rtpmap:%s", i, str.c_str());
        ::sdp_message_a_attribute_add(*p_sdp_body, 0, (char*)::strdup("rtpmap"), (char*)::strdup(str.c_str()));
      } else if (a.ischosen(LibSip__SDPTypes::SDP__attribute::ALT_fmtp)) {
        std::string strp("fmtp:");
        strp += static_cast<const char*>(a.fmtp().format());
        std::string str;
        std::string str(static_cast<const char*>(a.fmtp().format()));
        str += " ";
        if (a.fmtp().params().ischosen(LibSip__SDPTypes::SDP__attribute__fmtp__format__specific__params::ALT_paramList)) {
          const LibSip__Common::SemicolonParam__List& sl = a.fmtp().params().paramList();
          for (int k = 0; k < sl.lengthof(); k++) {
@@ -266,19 +331,17 @@ int sip_codec_message_body::encode_sdp(const LibSip__SDPTypes::SDP__Message& p_s
            str += ";";
          } // End of 'for' statement
        } else {
          str.assign(static_cast<const char*>(a.fmtp().params().unstructured()));
          str += static_cast<const char*>(a.fmtp().params().unstructured());
        }
        ::sdp_message_a_attribute_add(*p_sdp_body, 0, (char*)::strdup(strp.c_str()), (char*)::strdup(str.c_str()));
        ::sdp_message_a_attribute_add(*p_sdp_body, 0, (char*)::strdup("fmtp"), (char*)::strdup(str.c_str()));
      } else if (a.ischosen(LibSip__SDPTypes::SDP__attribute::ALT_curr)) {
        std::string strp("curr:");
        std::string str(static_cast<const char*>(a.curr().preconditionType()));
        str += " ";
        str += static_cast<const char*>(a.curr().statusType());
        str += " ";
        str += static_cast<const char*>(a.curr().direction());
        ::sdp_message_a_attribute_add(*p_sdp_body, 0, (char*)::strdup(strp.c_str()), (char*)::strdup(str.c_str()));
        ::sdp_message_a_attribute_add(*p_sdp_body, 0, (char*)::strdup("curr"), (char*)::strdup(str.c_str()));
      } else if (a.ischosen(LibSip__SDPTypes::SDP__attribute::ALT_des)) {
        std::string strp("des:");
        std::string str(static_cast<const char*>(a.des().preconditionType()));
        str += " ";
        str += static_cast<const char*>(a.des().strength());
@@ -286,13 +349,11 @@ int sip_codec_message_body::encode_sdp(const LibSip__SDPTypes::SDP__Message& p_s
        str += static_cast<const char*>(a.des().statusType());
        str += " ";
        str += static_cast<const char*>(a.des().direction());
        ::sdp_message_a_attribute_add(*p_sdp_body, 0, (char*)::strdup(strp.c_str()), (char*)::strdup(str.c_str()));
        ::sdp_message_a_attribute_add(*p_sdp_body, 0, (char*)::strdup("des"), (char*)::strdup(str.c_str()));
      } else if (a.ischosen(LibSip__SDPTypes::SDP__attribute::ALT_maxptime)) {
        ::sdp_message_a_attribute_add(*p_sdp_body, 0, (char*)::strdup("maxptime"), (char*)::strdup(static_cast<const char*>(a.maxptime().attr__value())));
      } else if (a.ischosen(LibSip__SDPTypes::SDP__attribute::ALT_sendrecv)) {
        ::sdp_message_a_attribute_add(*p_sdp_body, 0, (char*)::strdup("sendrecv"), nullptr);
      } else if (a.ischosen(LibSip__SDPTypes::SDP__attribute::ALT_maxptime)) {
        std::string str("maxptime:");
        str += static_cast<const char*>(a.maxptime().attr__value());
        ::sdp_message_a_attribute_add(*p_sdp_body, 0, (char*)::strdup(str.c_str()), NULL);
      } else {
        loggers::get_instance().warning("sip_codec_message_body::encode_sdp: attribute not processed");
      }
@@ -347,11 +408,11 @@ void sip_codec_message_body::decode_message_body(const osip_message_t* p_sip_mes
    loggers::get_instance().log("sip_codec_message_body::decode_message_body: Body headers size: %d", osip_list_size(body->headers));
  }
  if (body->content_type != nullptr) {
    loggers::get_instance().log("sip_codec_message_body::decode_message_body: Body content-type: '%s'/'%s'", body->content_type->type, body->content_type->subtype);
    loggers::get_instance().log("sip_codec_message_body::decode_message_body: Body content-type: '%s'/'%s'/%p", body->content_type->type, body->content_type->subtype, body->content_type->gen_params.node);
  }
  LibSip__MessageBodyTypes::MessageBody msg_body;
  if (content_type != nullptr) {
    loggers::get_instance().log("sip_codec_message_body::decode_message_body: content-type.type: '%s'/'%s'", content_type->type, content_type->subtype);
    loggers::get_instance().log("sip_codec_message_body::decode_message_body: content-type.type: '%s'/'%s'/%p", content_type->type, content_type->subtype, content_type->gen_params.node);
    if (std::string(content_type->type).compare("multipart") == 0) {
      const osip_list_t* p = &(p_sip_message->bodies);
      size_t size = osip_list_size(p);
@@ -361,10 +422,16 @@ void sip_codec_message_body::decode_message_body(const osip_message_t* p_sip_mes
        msg_body.textplain() = CHARSTRING(body->body);
      } else {
        LibSip__MessageBodyTypes::MIME__Message mime;
        if (content_type->gen_params.node != nullptr) {
          mime.boundary() = CHARSTRING("boundary1"/*(const char*)content_type->gen_params.node->element*/); // TODO How to get the boundary name?
        } else {
          mime.boundary() = CHARSTRING("boundary1");
        }
        loggers::get_instance().log_msg("sip_codec_message_body::decode_message_body: Boundary: ", mime.boundary());
        LibSip__MessageBodyTypes::MimeEncapsulatedList& l = mime.mimeEncapsulatedList();
        size_t pos = 0;
        while (pos < size) {
          const osip_header_t* header = (const osip_header_t*)osip_list_get(p, pos++);
          const osip_header_t* header = (const osip_header_t*)osip_list_get(p, pos);
          loggers::get_instance().log("sip_codec_message_body::decode_message_body: body content=%s", header->hname);
          if ((*header->hname == 'v') && (*(header->hname + 1) == '=') && (*(header->hname + 2) == '0')) { // SDP
            loggers::get_instance().log("sip_codec_message_body::decode_message_body: Decode SDP");
@@ -383,7 +450,6 @@ void sip_codec_message_body::decode_message_body(const osip_message_t* p_sip_mes
            } else {
              parts.msdBody() = char2oct(CHARSTRING(header->hname));
            }
            ::osip_body_free(body);
            l[pos] = p;
          } else if ((*header->hname == '<') && (*(header->hname + 1) == '?') && (*(header->hname + 2) == 'x')) { // <?xml
              loggers::get_instance().log("sip_codec_message_body::decode_message_body: Decode XML");
@@ -402,12 +468,12 @@ void sip_codec_message_body::decode_message_body(const osip_message_t* p_sip_mes
              } else {
                parts.msdBody() = char2oct(CHARSTRING(header->hname));
              }
              ::osip_body_free(body);
              l[pos] = p;
          } else {
            // TODO
            loggers::get_instance().error("sip_codec_message_body::decode_message_body: Not implemented yet");
          }
          pos += 1;
        } // End of 'while' statement
        msg_body.mimeMessageBody() = mime;
      }
@@ -440,7 +506,9 @@ int sip_codec_message_body::decode_sdp(const osip_body_t* p_body, LibSip__SDPTyp

  sdp_message_t* sdp = nullptr;
  ::sdp_message_init(&sdp);
  if (::sdp_message_parse(sdp, p_body->body) == 0) {
  std::string s(p_body->body);
  s += "\r\n\r\n";
  if (::sdp_message_parse(sdp, s.c_str()/*p_body->body*/) == 0) {
    // Mandatroy fields
    // Version, v
    char *hvalue = ::sdp_message_v_version_get(sdp);
@@ -660,11 +728,36 @@ int sip_codec_message_body::decode_sdp(const osip_body_t* p_body, LibSip__SDPTyp
    } else {
      p_sdp_header.bandwidth().set_to_omit();
    }
    // Connection, c
    char* net__type;
    if ((net__type = ::sdp_message_c_nettype_get(sdp, 0, 0)) != nullptr) {
      loggers::get_instance().log("sip_codec_message_body::decode_sdp: Connections#%d: '%s'", 0, a);
      LibSip__SDPTypes::SDP__connection c;
      c.net__type() = CHARSTRING(net__type);
      c.addr__type() = CHARSTRING(::sdp_message_c_addrtype_get(sdp, 0, 0));
      LibSip__SDPTypes::SDP__conn__addr a;
      a.addr() = CHARSTRING(::sdp_message_c_addr_get(sdp, 0, 0));
      if (::sdp_message_c_addr_multicast_ttl_get(sdp, 0, 0) != nullptr) {
        a.ttl() = OPTIONAL<INTEGER>(::stoi(::sdp_message_c_addr_multicast_ttl_get(sdp, 0, 0)));
      } else {
          a.ttl().set_to_omit();
      }
      if (::sdp_message_c_addr_multicast_int_get(sdp, 0, 0) != nullptr) {
        a.num__of__addr() = OPTIONAL<INTEGER>(::stoi(::sdp_message_c_addr_multicast_int_get(sdp, 0, 0)));
      } else {
        a.num__of__addr().set_to_omit();
      }
      c.conn__addr() = a;
      loggers::get_instance().log_msg("sip_codec_message_body::decode_sdp_sdp: connection: ", c);
      p_sdp_header.connection() = OPTIONAL<LibSip__SDPTypes::SDP__connection>(c);
    } else {
      p_sdp_header.connection().set_to_omit();
    }
    i = 0;
    
    // TODO
    p_sdp_header.uri().set_to_omit();
    p_sdp_header.phone__numbers().set_to_omit();
    p_sdp_header.connection().set_to_omit();
    p_sdp_header.timezone__adjustments().set_to_omit();
    p_sdp_header.key().set_to_omit();
    
@@ -677,19 +770,51 @@ int sip_codec_message_body::decode_sdp(const osip_body_t* p_body, LibSip__SDPTyp
  return 0;
}

int sip_codec_message_body::encode_xml(const LibSip__XMLTypes::XmlBody& p_message_body, sdp_message_t** p_xml_header) {
int sip_codec_message_body::encode_xml(const LibSip__XMLTypes::XmlBody& p_message_body, osip_body_t** p_body) {
  loggers::get_instance().log_msg(">>> sip_codec_message_body::encode_xml: ", p_message_body);
  
  ::osip_body_init(p_body);

  loggers::get_instance().log("<<< sip_codec_message_body::encode_xml");
  TTCN_EncDec::clear_error();
  TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_DEFAULT);
  TTCN_Buffer encoding_buffer;
  
  CHARSTRING h("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n");
  encoding_buffer.put_s(h.lengthof(), (const unsigned char*)static_cast<const char*>(h));
  if (p_message_body.ischosen(LibSip__XMLTypes::XmlBody::ALT_presence)) { // Held codec
    const urn__ietf__params__xml__ns__pidf::Presence& presence = p_message_body.presence();
    loggers::get_instance().log_msg("sip_codec_message_body::encode_xml: Process Presence", (const Base_Type&)presence);
    presence.encode(urn__ietf__params__xml__ns__pidf::Presence_descr_, encoding_buffer, TTCN_EncDec::CT_XER, XER_EXTENDED);
  } else {
    loggers::get_instance().warning("sip_codec_message_body::encode_xml: Unsupported variant");
    return -1;
  }
  OCTETSTRING data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data());
  (*p_body)->body = ::strdup(static_cast<const char*>(oct2char(data)));
  (*p_body)->length = strlen((*p_body)->body);

  loggers::get_instance().log("<<< sip_codec_message_body::encode_xml: %s", (*p_body)->body);
  return 0;
}

int sip_codec_message_body::decode_xml(const osip_body_t* p_body, LibSip__XMLTypes::XmlBody& p_xml_header) {
  loggers::get_instance().log(">>> sip_codec_message_body::decode_xml: %s", p_body->body);
  
  // TODO Unify held_codec for bothHttp & Sip: instead of LibItsHttp__XmlMessageBodyTypes::XmlBody, use a generic XmlBody common to LibItsHttp & LibSip
  TTCN_EncDec::clear_error();
  TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_DEFAULT);
  OCTETSTRING data(p_body->length, (const unsigned char*)p_body->body);
  TTCN_Buffer decoding_buffer(data);
  loggers::get_instance().log_to_hexa("<<< sip_codec_message_body::decode_xml: decoding_buffer: ", decoding_buffer);
  
  if (strstr(p_body->body, "<presence") != nullptr) { // Held codec
    urn__ietf__params__xml__ns__pidf::Presence presence;
    presence.decode(urn__ietf__params__xml__ns__pidf::Presence_descr_, decoding_buffer, TTCN_EncDec::CT_XER, XER_EXTENDED);
    p_xml_header.presence() = presence;
  } else {
    loggers::get_instance().warning("sip_codec_message_body::decode_xml: Unsupported XML message, to be implemented");
  }
  
  loggers::get_instance().log_msg("<<< sip_codec_message_body::decode_xml: xml: ", p_xml_header);
  return 0;
}
+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+2 −2

File changed.

Preview size limit exceeded, changes collapsed.

Loading