void add_application(application app)
{
  std::map<unsigned int, application>::iterator it
    = apps.insert(std::make_pair(app.application_id, application())).first;
  swap(app, it->second);

  if(!it->second.transport_protocol_descriptor.empty()
     && !it->second.ginga_location_descriptor.empty())
  {
    typedef std::vector<char>::const_iterator iterator;
    typedef gts::descriptors::transport_protocol_descriptor<iterator>
      transport_protocol_descriptor;
    typedef transport_protocol_descriptor::protocol_id_iterator
      protocol_id_iterator;
    typedef transport_protocol_descriptor::transport_protocol_label_iterator
      transport_protocol_label_iterator;
    typedef transport_protocol_descriptor::selector_byte_iterator
      selector_byte_iterator;

    transport_protocol_descriptor transport_protocol
      (it->second.transport_protocol_descriptor.begin()
       , it->second.transport_protocol_descriptor.end());
    if(* ++transport_protocol.begin() == gts::constants::etsi::protocol_ids::object_carousel)
    {
      selector_byte_iterator selector_byte_it = gts::iterators::next<3>(transport_protocol.begin());
      typedef transport_protocol_descriptor::object_carousel_transport object_carousel_transport;
      object_carousel_transport transport(*selector_byte_it);
      typedef object_carousel_transport::component_tag_iterator component_tag_iterator;
      component_tag_iterator component_it = gts::iterators::next<4>(transport.begin());
      
      std::cout << "=== Should filter component " << *component_it << std::endl;
      boost::optional<unsigned int> pid = sections::pid_from_component_tag(*component_it);
      if(pid)
      {
        dsmcc::start(it->second.dsmcc, *pid
                     , boost::bind(&application_download_finish
                                   , it->second.application_id));
      }
      else
        std::cout << "Couldn't find ES for component tag" << std::endl;
    }
    else
    {
      std::cout << "protocol id is " << * ++transport_protocol.begin() << std::endl;
    }
  }
  else
  {
    std::cout << "transport_protocol is empty" << std::endl;
  }
}
Esempio n. 2
0
static void call_ng_process_flags(struct sdp_ng_flags *out, bencode_item_t *input) {
	bencode_item_t *list, *it;
	int diridx;
	str s;

	ZERO(*out);

	if ((list = bencode_dictionary_get_expect(input, "flags", BENCODE_LIST))) {
		for (it = list->child; it; it = it->sibling) {
			str_hyphenate(it);
			if (!bencode_strcmp(it, "trust-address"))
				out->trust_address = 1;
			else if (!bencode_strcmp(it, "asymmetric"))
				out->asymmetric = 1;
			else if (!bencode_strcmp(it, "strict-source"))
				out->strict_source = 1;
			else if (!bencode_strcmp(it, "media-handover"))
				out->media_handover = 1;
			else
				ilog(LOG_WARN, "Unknown flag encountered: '"BENCODE_FORMAT"'",
						BENCODE_FMT(it));
		}
	}

	if ((list = bencode_dictionary_get_expect(input, "replace", BENCODE_LIST))) {
		for (it = list->child; it; it = it->sibling) {
			str_hyphenate(it);
			if (!bencode_strcmp(it, "origin"))
				out->replace_origin = 1;
			else if (!bencode_strcmp(it, "session-connection"))
				out->replace_sess_conn = 1;
			else
				ilog(LOG_WARN, "Unknown 'replace' flag encountered: '"BENCODE_FORMAT"'",
						BENCODE_FMT(it));
		}
	}

	diridx = 0;
	if ((list = bencode_dictionary_get_expect(input, "direction", BENCODE_LIST))) {
		for (it = list->child; it && diridx < 2; it = it->sibling)
			bencode_get_str(it, &out->direction[diridx++]);
	}

	list = bencode_dictionary_get_expect(input, "received from", BENCODE_LIST);
	if (!list)
		list = bencode_dictionary_get_expect(input, "received-from", BENCODE_LIST);
	if (list && (it = list->child)) {
		bencode_get_str(it, &out->received_from_family);
		bencode_get_str(it->sibling, &out->received_from_address);
	}

	if (bencode_dictionary_get_str(input, "ICE", &s)) {
		if (!str_cmp(&s, "remove"))
			out->ice_remove = 1;
		else if (!str_cmp(&s, "force"))
			out->ice_force = 1;
		else if (!str_cmp(&s, "force_relay") || !str_cmp(&s, "force-relay"))
			out->ice_force_relay = 1;
		else
			ilog(LOG_WARN, "Unknown 'ICE' flag encountered: '"STR_FORMAT"'",
					STR_FMT(&s));
	}

	if ((list = bencode_dictionary_get_expect(input, "rtcp-mux", BENCODE_LIST))) {
		for (it = list->child; it; it = it->sibling) {
			if (!bencode_strcmp(it, "offer"))
				out->rtcp_mux_offer = 1;
			else if (!bencode_strcmp(it, "demux"))
				out->rtcp_mux_demux = 1;
			else if (!bencode_strcmp(it, "accept"))
				out->rtcp_mux_accept = 1;
			else if (!bencode_strcmp(it, "reject"))
				out->rtcp_mux_reject = 1;
			else
				ilog(LOG_WARN, "Unknown 'rtcp-mux' flag encountered: '"BENCODE_FORMAT"'",
						BENCODE_FMT(it));
		}
	}

	bencode_get_alt(input, "transport-protocol", "transport protocol", &out->transport_protocol_str);
	out->transport_protocol = transport_protocol(&out->transport_protocol_str);
	bencode_get_alt(input, "media-address", "media address", &out->media_address);
	if (bencode_get_alt(input, "address-family", "address family", &out->address_family_str))
		out->address_family = address_family(&out->address_family_str);
	out->tos = bencode_dictionary_get_integer(input, "TOS", 256);
}
Esempio n. 3
0
/* XXX split this function up */
int sdp_streams(const GQueue *sessions, GQueue *streams, struct sdp_ng_flags *flags) {
	struct sdp_session *session;
	struct sdp_media *media;
	struct stream_params *sp;
	GList *l, *k;
	const char *errstr;
	int num;
	struct sdp_attribute *attr;

	num = 0;
	for (l = sessions->head; l; l = l->next) {
		session = l->data;

		for (k = session->media_streams.head; k; k = k->next) {
			media = k->data;

			sp = g_slice_alloc0(sizeof(*sp));
			sp->index = ++num;

			errstr = "No address info found for stream";
			if (fill_endpoint(&sp->rtp_endpoint, media, flags, NULL, media->port_num))
				goto error;

			sp->consecutive_ports = media->port_count;
			sp->protocol = transport_protocol(&media->transport);
			sp->type = media->media_type;
			memcpy(sp->direction, flags->direction, sizeof(sp->direction));
			sp->desired_family = flags->address_family;
			bf_set_clear(&sp->sp_flags, SP_FLAG_ASYMMETRIC, flags->asymmetric);
			bf_set_clear(&sp->sp_flags, SP_FLAG_STRICT_SOURCE, flags->strict_source);
			bf_set_clear(&sp->sp_flags, SP_FLAG_MEDIA_HANDOVER, flags->media_handover);

			errstr = "Invalid RTP payload types";
			if (__rtp_payload_types(sp, media))
				goto error;

			/* a=crypto */
			attr = attr_get_by_id(&media->attributes, ATTR_CRYPTO);
			if (attr) {
				sp->crypto.crypto_suite = attr->u.crypto.crypto_suite;
				sp->crypto.mki_len = attr->u.crypto.mki_len;
				if (sp->crypto.mki_len) {
					sp->crypto.mki = malloc(sp->crypto.mki_len);
					memcpy(sp->crypto.mki, attr->u.crypto.mki, sp->crypto.mki_len);
				}
				sp->sdes_tag = attr->u.crypto.tag;
				assert(sizeof(sp->crypto.master_key) >= attr->u.crypto.master_key.len);
				assert(sizeof(sp->crypto.master_salt) >= attr->u.crypto.salt.len);
				memcpy(sp->crypto.master_key, attr->u.crypto.master_key.s,
						attr->u.crypto.master_key.len);
				memcpy(sp->crypto.master_salt, attr->u.crypto.salt.s,
						attr->u.crypto.salt.len);
				sp->crypto.session_params.unencrypted_srtp = attr->u.crypto.unencrypted_srtp;
				sp->crypto.session_params.unencrypted_srtcp = attr->u.crypto.unencrypted_srtcp;
				sp->crypto.session_params.unauthenticated_srtp = attr->u.crypto.unauthenticated_srtp;
			}

			/* a=sendrecv/sendonly/recvonly/inactive */
			SP_SET(sp, SEND);
			SP_SET(sp, RECV);
			if (attr_get_by_id_m_s(media, ATTR_RECVONLY))
				SP_CLEAR(sp, SEND);
			else if (attr_get_by_id_m_s(media, ATTR_SENDONLY))
				SP_CLEAR(sp, RECV);
			else if (attr_get_by_id_m_s(media, ATTR_INACTIVE))
			{
				SP_CLEAR(sp, RECV);
				SP_CLEAR(sp, SEND);
			}

			/* a=setup */
			attr = attr_get_by_id_m_s(media, ATTR_SETUP);
			if (attr) {
				if (attr->u.setup.value == SETUP_ACTPASS
						|| attr->u.setup.value == SETUP_ACTIVE)
					SP_SET(sp, SETUP_ACTIVE);
				if (attr->u.setup.value == SETUP_ACTPASS
						|| attr->u.setup.value == SETUP_PASSIVE)
					SP_SET(sp, SETUP_PASSIVE);
			}

			/* a=fingerprint */
			attr = attr_get_by_id_m_s(media, ATTR_FINGERPRINT);
			if (attr && attr->u.fingerprint.hash_func) {
				sp->fingerprint.hash_func = attr->u.fingerprint.hash_func;
				memcpy(sp->fingerprint.digest, attr->u.fingerprint.fingerprint,
						sp->fingerprint.hash_func->num_bytes);
			}

			__sdp_ice(sp, media);

			/* determine RTCP endpoint */

			if (attr_get_by_id(&media->attributes, ATTR_RTCP_MUX)) {
				SP_SET(sp, RTCP_MUX);
				goto next;
			}

			if (media->port_count != 1)
				goto next;

			attr = attr_get_by_id(&media->attributes, ATTR_RTCP);
			if (!attr) {
				SP_SET(sp, IMPLICIT_RTCP);
				goto next;
			}
			if (attr->u.rtcp.port_num == sp->rtp_endpoint.port
					&& !is_trickle_ice_address(&sp->rtp_endpoint))
			{
				SP_SET(sp, RTCP_MUX);
				goto next;
			}
			errstr = "Invalid RTCP attribute";
			if (fill_endpoint(&sp->rtcp_endpoint, media, flags, &attr->u.rtcp.address,
						attr->u.rtcp.port_num))
				goto error;

next:
			g_queue_push_tail(streams, sp);
		}
	}

	return 0;

error:
	ilog(LOG_WARNING, "Failed to extract streams from SDP: %s", errstr);
	if (sp)
		g_slice_free1(sizeof(*sp), sp);
	return -1;
}
Esempio n. 4
0
static void call_ng_process_flags(struct sdp_ng_flags *out, bencode_item_t *input) {
	bencode_item_t *list, *it;
	int diridx;
	str s;

	ZERO(*out);

	if ((list = bencode_dictionary_get_expect(input, "flags", BENCODE_LIST))) {
		for (it = list->child; it; it = it->sibling) {
			if (!bencode_strcmp(it, "trust address"))
				out->trust_address = 1;
			else if (!bencode_strcmp(it, "asymmetric"))
				out->asymmetric = 1;
			else if (!bencode_strcmp(it, "trust-address"))
				out->trust_address = 1;
			else if (!bencode_strcmp(it, "strict source"))
				out->strict_source = 1;
			else if (!bencode_strcmp(it, "media handover"))
				out->media_handover = 1;
		}
	}

	if ((list = bencode_dictionary_get_expect(input, "replace", BENCODE_LIST))) {
		for (it = list->child; it; it = it->sibling) {
			if (!bencode_strcmp(it, "origin"))
				out->replace_origin = 1;
			else if (!bencode_strcmp(it, "session connection"))
				out->replace_sess_conn = 1;
			else if (!bencode_strcmp(it, "session-connection"))
				out->replace_sess_conn = 1;
		}
	}

	diridx = 0;
	if ((list = bencode_dictionary_get_expect(input, "direction", BENCODE_LIST))) {
		for (it = list->child; it && diridx < 2; it = it->sibling) {
			if (!bencode_strcmp(it, "internal"))
				out->directions[diridx++] = DIR_INTERNAL;
			else if (!bencode_strcmp(it, "external"))
				out->directions[diridx++] = DIR_EXTERNAL;
		}
	}

	list = bencode_dictionary_get_expect(input, "received from", BENCODE_LIST);
	if (!list)
		list = bencode_dictionary_get_expect(input, "received-from", BENCODE_LIST);
	if (list && (it = list->child)) {
		bencode_get_str(it, &out->received_from_family);
		bencode_get_str(it->sibling, &out->received_from_address);
	}

	if (bencode_dictionary_get_str(input, "ICE", &s)) {
		if (!str_cmp(&s, "remove"))
			out->ice_remove = 1;
		else if (!str_cmp(&s, "force"))
			out->ice_force = 1;
		else if (!str_cmp(&s, "force_relay"))
			out->ice_force_relay = 1;
	}

	if ((list = bencode_dictionary_get_expect(input, "rtcp-mux", BENCODE_LIST))) {
		for (it = list->child; it; it = it->sibling) {
			if (!bencode_strcmp(it, "offer"))
				out->rtcp_mux_offer = 1;
			else if (!bencode_strcmp(it, "demux"))
				out->rtcp_mux_demux = 1;
			else if (!bencode_strcmp(it, "accept"))
				out->rtcp_mux_accept = 1;
			else if (!bencode_strcmp(it, "reject"))
				out->rtcp_mux_reject = 1;
		}
	}

	bencode_dictionary_get_str(input, "transport protocol", &out->transport_protocol_str);
	if (!out->transport_protocol_str.s)
		bencode_dictionary_get_str(input, "transport-protocol", &out->transport_protocol_str);
	out->transport_protocol = transport_protocol(&out->transport_protocol_str);
	bencode_dictionary_get_str(input, "media address", &out->media_address);
	if (bencode_dictionary_get_str(input, "address family", &out->address_family_str))
		out->address_family = address_family(&out->address_family_str);
}
Esempio n. 5
0
static void call_ng_process_flags(struct sdp_ng_flags *out, bencode_item_t *input) {
	bencode_item_t *list, *it;
	int diridx;
	str s;

	ZERO(*out);

	out->trust_address = trust_address_def;
	out->dtls_passive = dtls_passive_def;

	if ((list = bencode_dictionary_get_expect(input, "flags", BENCODE_LIST))) {
		for (it = list->child; it; it = it->sibling) {
			if (it->type !=  BENCODE_STRING)
				continue;

			str_hyphenate(it);

			if (!bencode_strcmp(it, "trust-address"))
				out->trust_address = 1;
			else if (!bencode_strcmp(it, "SIP-source-address"))
				out->trust_address = 0;
			else if (!bencode_strcmp(it, "asymmetric"))
				out->asymmetric = 1;
			else if (!bencode_strcmp(it, "strict-source"))
				out->strict_source = 1;
			else if (!bencode_strcmp(it, "media-handover"))
				out->media_handover = 1;
			else if (!bencode_strcmp(it, "reset"))
				out->reset = 1;
			else if (it->iov[1].iov_len >= 5 && !memcmp(it->iov[1].iov_base, "SDES-", 5))
				ng_sdes_option(out, it, 5);
			else
				ilog(LOG_WARN, "Unknown flag encountered: '"BENCODE_FORMAT"'",
						BENCODE_FMT(it));
		}
	}

	if ((list = bencode_dictionary_get_expect(input, "replace", BENCODE_LIST))) {
		for (it = list->child; it; it = it->sibling) {
			str_hyphenate(it);
			if (!bencode_strcmp(it, "origin"))
				out->replace_origin = 1;
			else if (!bencode_strcmp(it, "session-connection"))
				out->replace_sess_conn = 1;
			else
				ilog(LOG_WARN, "Unknown 'replace' flag encountered: '"BENCODE_FORMAT"'",
						BENCODE_FMT(it));
		}
	}

	diridx = 0;
	if ((list = bencode_dictionary_get_expect(input, "direction", BENCODE_LIST))) {
		for (it = list->child; it && diridx < 2; it = it->sibling)
			bencode_get_str(it, &out->direction[diridx++]);
	}

	list = bencode_dictionary_get_expect(input, "received from", BENCODE_LIST);
	if (!list)
		list = bencode_dictionary_get_expect(input, "received-from", BENCODE_LIST);
	if (list && (it = list->child)) {
		bencode_get_str(it, &out->received_from_family);
		bencode_get_str(it->sibling, &out->received_from_address);
	}

	if (bencode_dictionary_get_str(input, "ICE", &s)) {
		if (!str_cmp(&s, "remove"))
			out->ice_remove = 1;
		else if (!str_cmp(&s, "force"))
			out->ice_force = 1;
		else if (!str_cmp(&s, "force_relay") || !str_cmp(&s, "force-relay")
				|| !str_cmp(&s, "force relay"))
			out->ice_force_relay = 1;
		else
			ilog(LOG_WARN, "Unknown 'ICE' flag encountered: '"STR_FORMAT"'",
					STR_FMT(&s));
	}

	if (bencode_dictionary_get_str(input, "DTLS", &s)) {
		if (!str_cmp(&s, "passive"))
			out->dtls_passive = 1;
		else if (!str_cmp(&s, "no") || !str_cmp(&s, "off") || !str_cmp(&s, "disabled")
				|| !str_cmp(&s, "disable"))
			out->dtls_off = 1;
		else
			ilog(LOG_WARN, "Unknown 'DTLS' flag encountered: '"STR_FORMAT"'",
					STR_FMT(&s));
	}

	if ((list = bencode_dictionary_get_expect(input, "rtcp-mux", BENCODE_LIST))) {
		for (it = list->child; it; it = it->sibling) {
			if (!bencode_strcmp(it, "offer"))
				out->rtcp_mux_offer = 1;
			else if (!bencode_strcmp(it, "demux"))
				out->rtcp_mux_demux = 1;
			else if (!bencode_strcmp(it, "accept"))
				out->rtcp_mux_accept = 1;
			else if (!bencode_strcmp(it, "reject"))
				out->rtcp_mux_reject = 1;
			else
				ilog(LOG_WARN, "Unknown 'rtcp-mux' flag encountered: '"BENCODE_FORMAT"'",
						BENCODE_FMT(it));
		}
	}

	/* XXX abstractize the other list walking functions using callbacks */
	/* XXX module still needs to support this list */
	if ((list = bencode_dictionary_get_expect(input, "SDES", BENCODE_LIST))) {
		for (it = list->child; it; it = it->sibling)
			ng_sdes_option(out, it, 0);
	}

	bencode_get_alt(input, "transport-protocol", "transport protocol", &out->transport_protocol_str);
	out->transport_protocol = transport_protocol(&out->transport_protocol_str);
	bencode_get_alt(input, "media-address", "media address", &out->media_address);
	if (bencode_get_alt(input, "address-family", "address family", &out->address_family_str))
		out->address_family = address_family(&out->address_family_str);
	out->tos = bencode_dictionary_get_integer(input, "TOS", 256);
}