tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SipccSdpParser.cpp (3042B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "sdp/SipccSdpParser.h"
      8 
      9 #include <utility>
     10 
     11 #include "sdp/SipccSdp.h"
     12 extern "C" {
     13 #include "sipcc_sdp.h"
     14 }
     15 
     16 namespace mozilla {
     17 
     18 extern "C" {
     19 
     20 void sipcc_sdp_parser_results_handler(void* context, uint32_t line,
     21                                      const char* message) {
     22  auto* results = static_cast<UniquePtr<InternalResults>*>(context);
     23  std::string err(message);
     24  (*results)->AddParseError(line, err);
     25 }
     26 
     27 }  // extern "C"
     28 
     29 const std::string& SipccSdpParser::ParserName() {
     30  static const std::string SIPCC_NAME = "SIPCC";
     31  return SIPCC_NAME;
     32 }
     33 
     34 UniquePtr<SdpParser::Results> SipccSdpParser::Parse(const std::string& aText) {
     35  UniquePtr<InternalResults> results(new InternalResults(Name()));
     36  sdp_conf_options_t* sipcc_config = sdp_init_config();
     37  if (!sipcc_config) {
     38    return UniquePtr<SdpParser::Results>();
     39  }
     40 
     41  sdp_nettype_supported(sipcc_config, SDP_NT_INTERNET, true);
     42  sdp_addrtype_supported(sipcc_config, SDP_AT_IP4, true);
     43  sdp_addrtype_supported(sipcc_config, SDP_AT_IP6, true);
     44  sdp_transport_supported(sipcc_config, SDP_TRANSPORT_RTPAVP, true);
     45  sdp_transport_supported(sipcc_config, SDP_TRANSPORT_RTPAVPF, true);
     46  sdp_transport_supported(sipcc_config, SDP_TRANSPORT_RTPSAVP, true);
     47  sdp_transport_supported(sipcc_config, SDP_TRANSPORT_RTPSAVPF, true);
     48  sdp_transport_supported(sipcc_config, SDP_TRANSPORT_UDPTLSRTPSAVP, true);
     49  sdp_transport_supported(sipcc_config, SDP_TRANSPORT_UDPTLSRTPSAVPF, true);
     50  sdp_transport_supported(sipcc_config, SDP_TRANSPORT_TCPDTLSRTPSAVP, true);
     51  sdp_transport_supported(sipcc_config, SDP_TRANSPORT_TCPDTLSRTPSAVPF, true);
     52  sdp_transport_supported(sipcc_config, SDP_TRANSPORT_DTLSSCTP, true);
     53  sdp_transport_supported(sipcc_config, SDP_TRANSPORT_UDPDTLSSCTP, true);
     54  sdp_transport_supported(sipcc_config, SDP_TRANSPORT_TCPDTLSSCTP, true);
     55  sdp_require_session_name(sipcc_config, false);
     56 
     57  sdp_config_set_error_handler(sipcc_config, &sipcc_sdp_parser_results_handler,
     58                               &results);
     59 
     60  // Takes ownership of |sipcc_config| iff it succeeds
     61  sdp_t* sdp = sdp_init_description(sipcc_config);
     62  if (!sdp) {
     63    sdp_free_config(sipcc_config);
     64    return results;
     65  }
     66 
     67  const char* rawString = aText.c_str();
     68  sdp_result_e sdpres = sdp_parse(sdp, rawString, aText.length());
     69  if (sdpres != SDP_SUCCESS) {
     70    sdp_free_description(sdp);
     71    return results;
     72  }
     73 
     74  UniquePtr<SipccSdp> sipccSdp(new SipccSdp);
     75 
     76  bool success = sipccSdp->Load(sdp, *results);
     77  sdp_free_description(sdp);
     78  if (success) {
     79    results->SetSdp(UniquePtr<mozilla::Sdp>(std::move(sipccSdp)));
     80  }
     81 
     82  return results;
     83 }
     84 
     85 bool SipccSdpParser::IsNamed(const std::string& aName) {
     86  return aName == ParserName();
     87 }
     88 
     89 }  // namespace mozilla