Exemplo n.º 1
0
static bool rr_naptr_handler(struct dnsrr *rr, void *arg)
{
	struct sip_request *req = arg;
	enum sip_transp tp;

	if (rr->type != DNS_TYPE_NAPTR)
		return false;

	if (!str_casecmp(rr->rdata.naptr.services, "SIP+D2U"))
		tp = SIP_TRANSP_UDP;
	else if (!str_casecmp(rr->rdata.naptr.services, "SIP+D2T"))
		tp = SIP_TRANSP_TCP;
	else if (!str_casecmp(rr->rdata.naptr.services, "SIPS+D2T"))
		tp = SIP_TRANSP_TLS;
	else
		return false;

	if (!sip_transp_supported(req->sip, tp, AF_UNSPEC))
		return false;

	req->tp = tp;
	req->tp_selected = true;

	return true;
}
Exemplo n.º 2
0
int agent_process_remote_attr(struct agent *ag,
			      const char *name, const char *value)
{
	int err = 0;

	if (!ag || !name)
		return EINVAL;

	if (0 == str_casecmp(name, "ice-ufrag")) {
		ag->rufrag = true;
		err = trice_set_remote_ufrag(ag->icem, value);
	}
	else if (0 == str_casecmp(name, "ice-pwd")) {
		ag->rpwd = true;
		err = trice_set_remote_pwd(ag->icem, value);
	}
	else if (0 == str_casecmp(name, "candidate")) {
		unsigned i;

		err = agent_rcand_decode_add(ag->icem, value);

		for (i=0; i<ag->candc; i++)
			candidate_add_permissions(&ag->candv[i]);
	}
	else if (0 == str_casecmp(name, "end-of-candidates")) {
		re_printf("got end-of-candidates from remote\n");
		ag->remote_eoc = true;
	}
	else {
		re_printf("attribute ignored: %s\n", name);
	}

	if (err) {
		re_printf("remote attr error (%m)\n", err);
		return err;
	}

	if (ag->rufrag && ag->rpwd && ag->cli->param.run_checklist
	    && !list_isempty(trice_rcandl(ag->icem))
	    && !trice_checklist_isrunning(ag->icem)) {

		re_printf("starting ICE checklist with pacing interval"
			  " %u milliseconds..\n",
			  ag->cli->param.pacing_interval);

		err = trice_checklist_start(ag->icem, NULL,
					    ag->cli->param.pacing_interval,
					    true,
					    ice_estab_handler,
					    ice_failed_handler, ag);
		if (err) {
			re_fprintf(stderr, "could not start checklist (%m)\n",
				   err);
		}
	}

	return 0;
}
enum ice_cand_type ice_cand_name2type(const char *name)
{
	if (0 == str_casecmp(name, "host"))  return ICE_CAND_TYPE_HOST;
	if (0 == str_casecmp(name, "srflx")) return ICE_CAND_TYPE_SRFLX;
	if (0 == str_casecmp(name, "prflx")) return ICE_CAND_TYPE_PRFLX;
	if (0 == str_casecmp(name, "relay")) return ICE_CAND_TYPE_RELAY;

	return (enum ice_cand_type)-1;
}
Exemplo n.º 4
0
static const EVP_MD *type2evp(const char *type)
{
	if (0 == str_casecmp(type, "SHA-1"))
		return EVP_sha1();
	else if (0 == str_casecmp(type, "SHA-256"))
		return EVP_sha256();
	else
		return NULL;
}
Exemplo n.º 5
0
int avcodec_resolve_codecid(const char *s)
{
	if (0 == str_casecmp(s, "H263"))
		return AV_CODEC_ID_H263;
	else if (0 == str_casecmp(s, "H264"))
		return AV_CODEC_ID_H264;
	else if (0 == str_casecmp(s, "MP4V-ES"))
		return AV_CODEC_ID_MPEG4;
	else
		return AV_CODEC_ID_NONE;
}
Exemplo n.º 6
0
static enum srtp_suite resolve_suite(const char *suite)
{
	if (0 == str_casecmp(suite, aes_cm_128_hmac_sha1_32))
		return SRTP_AES_CM_128_HMAC_SHA1_32;
	if (0 == str_casecmp(suite, aes_cm_128_hmac_sha1_80))
		return SRTP_AES_CM_128_HMAC_SHA1_80;
	if (0 == str_casecmp(suite, aes_128_gcm))
		return SRTP_AES_128_GCM;

	return -1;
}
Exemplo n.º 7
0
static enum bfcp_transp str2tp(const char *proto)
{
	if (0 == str_casecmp(proto, "udp"))
		return BFCP_UDP;
	else if (0 == str_casecmp(proto, "dtls"))
		return BFCP_DTLS;
	else {
		warning("unsupported BFCP protocol: %s\n", proto);
		return -1;
	}
}
Exemplo n.º 8
0
static int start_srtp(struct menc_st *st, const char *suite)
{
	crypto_policy_t policy;
	err_status_t e;

	if (0 == str_casecmp(suite, aes_cm_128_hmac_sha1_32)) {
		crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy);
	}
	else if (0 == str_casecmp(suite, aes_cm_128_hmac_sha1_80)) {
		crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy);
	}
	else {
		DEBUG_WARNING("unknown SRTP crypto suite (%s)\n", suite);
		return ENOENT;
	}

	/* transmit policy */
	st->policy_tx.rtp = policy;
	st->policy_tx.rtcp = policy;
	st->policy_tx.ssrc.type = ssrc_any_outbound;
	st->policy_tx.key = st->key_tx;
	st->policy_tx.next = NULL;

	/* receive policy */
	st->policy_rx.rtp = policy;
	st->policy_rx.rtcp = policy;
	st->policy_rx.ssrc.type = ssrc_any_inbound;
	st->policy_rx.key = st->key_rx;
	st->policy_rx.next = NULL;

	/* allocate and initialize the SRTP session */
	e = srtp_create(&st->srtp_tx, &st->policy_tx);
	if (e != err_status_ok) {
		DEBUG_WARNING("srtp_create TX failed (%H)\n",
			      errstatus_print, e);
		return EPROTO;
	}

	e = srtp_create(&st->srtp_rx, &st->policy_rx);
	if (err_status_ok != e) {
		DEBUG_WARNING("srtp_create RX failed (%H)\n",
			      errstatus_print, e);
		return EPROTO;
	}

	/* use SRTP for this stream/session */
	st->use_srtp = true;

	return 0;
}
Exemplo n.º 9
0
LogLevel log_str2Level(char* buf) {
	if (str_casecmp(buf, "error") == 0)
		return ERROR;

	if ((str_casecmp(buf, "warn") == 0) || (str_casecmp(buf, "warning") == 0))
		return WARNING;

	if (str_casecmp(buf, "info") == 0)
		return INFO;

	if (str_casecmp(buf, "debug") == 0)
		return DEBUG;

	return DEBUG;
}
Exemplo n.º 10
0
static bool if_getaddr_handler(const char *ifname,
			       const struct sa *sa, void *arg)
{
	struct ifentry *ife = arg;

	/* Match name of interface? */
	if (str_isset(ife->ifname) && 0 != str_casecmp(ife->ifname, ifname))
		return false;

	if (!sa_isset(sa, SA_ADDR))
		return false;

#if 1
	/* skip loopback and link-local IP */
	if (sa_is_loopback(sa) || sa_is_linklocal(sa))
		return false;
#endif

	/* Match address family */
	if (ife->af != sa_af(sa))
		return false;

	/* Match - copy address */
	sa_cpy(ife->ip, sa);
	ife->found = true;

	return ife->found;
}
Exemplo n.º 11
0
static bool remote_user_handler(char *key, void *val, void *arg)
{
	struct flow *flow = val;
	const char *remote_user = arg;

	return 0 == str_casecmp(flow->remoteid, remote_user);
}
Exemplo n.º 12
0
/**
 * Decode SDP media attributes
 *
 * @param icem  ICE Media object
 * @param name  Name of the SDP attribute
 * @param value Value of the SDP attribute (optional)
 *
 * @return 0 if success, otherwise errorcode
 */
int icem_sdp_decode(struct icem *icem, const char *name, const char *value)
{
	if (!icem)
		return EINVAL;

	if (0 == str_casecmp(name, ice_attr_cand))
		return cand_decode(icem, value);
	else if (0 == str_casecmp(name, ice_attr_mismatch))
		icem->mismatch = true;
	else if (0 == str_casecmp(name, ice_attr_ufrag))
		return media_ufrag_decode(icem, value);
	else if (0 == str_casecmp(name, ice_attr_pwd))
		return media_pwd_decode(icem, value);

	return 0;
}
Exemplo n.º 13
0
static void dns_server_match(struct dns_server *srv, struct list *rrl,
			     const char *name, uint16_t type)
{
	struct dnsrr *rr0 = NULL;
	struct le *le;

	le = srv->rrl.head;
	while (le) {

		struct dnsrr *rr = le->data;
		le = le->next;

		if (type == rr->type && 0==str_casecmp(name, rr->name)) {

			if (!rr0)
				rr0 = rr;
			list_append(rrl, &rr->le_priv, rr);
		}
	}

	/* If rotation is enabled, then rotate multiple entries
	   in a deterministic way (no randomness please) */
	if (srv->rotate && rr0) {
		list_unlink(&rr0->le);
		list_append(&srv->rrl, &rr0->le, rr0);
	}
}
Exemplo n.º 14
0
/**
 * Get the DSP samplerate for an audio-codec (exception for G.722)
 */
static inline uint32_t get_srate(const struct aucodec *ac)
{
	if (!ac)
		return 0;

	return !str_casecmp(ac->name, "G722") ? 16000 : ac->srate;
}
Exemplo n.º 15
0
bool sdp_format_cmp(const struct sdp_format *fmt1,
		    const struct sdp_format *fmt2)
{
	if (!fmt1 || !fmt2)
		return false;

	if (fmt1->pt < RTP_DYNPT_START && fmt2->pt < RTP_DYNPT_START) {

		if (!fmt1->id || !fmt2->id)
			return false;

		return strcmp(fmt1->id, fmt2->id) ? false : true;
	}

	if (str_casecmp(fmt1->name, fmt2->name))
		return false;

	if (fmt1->srate != fmt2->srate)
		return false;

	if (fmt1->ch != fmt2->ch)
		return false;

	if (fmt1->cmph && !fmt1->cmph(fmt1->params, fmt2->params, fmt1->data))
		return false;

	if (fmt2->cmph && !fmt2->cmph(fmt2->params, fmt1->params, fmt2->data))
		return false;

	return true;
}
Exemplo n.º 16
0
ADDRESS *mutt_lookup_alias (const char *s)
{
  ALIAS *t = Aliases;

  for (; t; t = t->next)
    if (!str_casecmp (s, t->name))
      return (t->addr);
  return (NULL);                /* no such alias */
}
Exemplo n.º 17
0
int lookup_action (char *keyname)
{
    int i;

    for (i = 0; command_names [i].name; i++){
        if (!str_casecmp (command_names [i].name, keyname))
            return command_names [i].val;
    }
    return 0;
}
Exemplo n.º 18
0
/**
 * Find a Video Codec by name
 *
 * @param name    Name of the Video Codec to find
 * @param variant Codec Variant
 *
 * @return Matching Video Codec if found, otherwise NULL
 */
const struct vidcodec *vidcodec_find(const char *name, const char *variant)
{
	struct le *le;

	for (le=vidcodecl.head; le; le=le->next) {

		struct vidcodec *vc = le->data;

		if (name && 0 != str_casecmp(name, vc->name))
			continue;

		if (variant && 0 != str_casecmp(variant, vc->variant))
			continue;

		return vc;
	}

	return NULL;
}
Exemplo n.º 19
0
/**
 * Decode SDP session attributes
 *
 * @param ice   ICE Session
 * @param name  Name of the SDP attribute
 * @param value Value of the SDP attribute (optional)
 *
 * @return 0 if success, otherwise errorcode
 */
int ice_sdp_decode(struct ice *ice, const char *name, const char *value)
{
	if (!ice)
		return EINVAL;

	if (0 == str_casecmp(name, ice_attr_lite)) {
		if (ICE_MODE_LITE == ice->lmode) {
			DEBUG_WARNING("we are lite, peer is also lite!\n");
			return EPROTO;
		}
		ice->rmode = ICE_MODE_LITE;
		ice->lrole = ROLE_CONTROLLING;
	}
	else if (0 == str_casecmp(name, ice_attr_ufrag))
		return ufrag_decode(ice, value);
	else if (0 == str_casecmp(name, ice_attr_pwd))
		return pwd_decode(ice, value);

	return 0;
}
Exemplo n.º 20
0
/* check_cn()
 *
 * Check if the given commonname matches the full qualified hostname
 * of the target host.
 *
 * Basic wildcard matching is supported (i.e. "*.ccc.de")
 *
 * For a full list of regexes see:
 * http://wp.netscape.com/eng/security/ssl_2.0_certificate.html
**/
int check_cn(char *cn, char *fqdn)
{
  int n;
  if (*cn == '*') {
    cn++;
    n = str_len(fqdn) - str_len(cn);
    if (n >= 0)
      fqdn += n;
  }
  return str_casecmp(fqdn, cn);
}
Exemplo n.º 21
0
static bool interface_handler(const char *ifname, const struct sa *addr,
			      void *arg)
{
	struct agent *ag = arg;
	int err = 0;

	/* Skip loopback and link-local addresses */
	if (ag->cli->param.skip_local) {

		if (sa_is_loopback(addr) || sa_is_linklocal(addr))
			return false;
	}

	if (str_isset(ag->cli->param.ifname) &&
	    str_casecmp(ag->cli->param.ifname, ifname)) {
		return false;
	}

	switch (sa_af(addr)) {

	case AF_INET:
		if (!ag->cli->param.use_ipv4)
			return false;
		break;

	case AF_INET6:
		if (!ag->cli->param.use_ipv6)
			return false;
		break;
	}

	/* NOTE: on some machines an interface is listed twice. */
	if (interface_find(ag, addr)) {
		re_printf("ignoring duplicated interface (%s %j)\n",
			  ifname, addr);
		return false;
	}
	ag->interfacev[ag->interfacec++] = *addr;

	re_printf("interface: %s %j\n", ifname, addr);

	if (ag->cli->param.use_udp)
		err |= add_candidate(ag, addr, IPPROTO_UDP, 0, ifname);
	if (ag->cli->param.use_tcp) {
		err |= add_candidate(ag, addr, IPPROTO_TCP, ICE_TCP_SO,
				     ifname);
		err |= add_candidate(ag, addr, IPPROTO_TCP,
			     ag->client ? ICE_TCP_ACTIVE : ICE_TCP_PASSIVE,
			     ifname);
	}

	return err != 0;
}
Exemplo n.º 22
0
int audio_encoder_set(struct audio *a, const struct aucodec *ac,
		      int pt_tx, const char *params)
{
	struct autx *tx;
	int err = 0;
	bool reset;

	if (!a || !ac)
		return EINVAL;

	tx = &a->tx;

	reset = !aucodec_equal(ac, tx->ac);

	if (ac != tx->ac) {
		(void)re_fprintf(stderr, "Set audio encoder: %s %uHz %dch\n",
				 ac->name, get_srate(ac), ac->ch);

		/* Audio source must be stopped first */
		if (reset) {
			tx->ausrc = mem_deref(tx->ausrc);
		}

		tx->is_g722 = (0 == str_casecmp(ac->name, "G722"));
		tx->enc = mem_deref(tx->enc);
		tx->ac = ac;
	}

	if (ac->encupdh) {
		struct auenc_param prm;

		prm.ptime = tx->ptime;

		err = ac->encupdh(&tx->enc, ac, &prm, params);
		if (err) {
			DEBUG_WARNING("alloc encoder: %m\n", err);
			return err;
		}
	}

	stream_set_srate(a->strm, get_srate(ac), get_srate(ac));
	stream_update_encoder(a->strm, pt_tx);

	if (!tx->ausrc) {
		err |= audio_start(a);
	}

	return err;
}
Exemplo n.º 23
0
/**
 * Find an Audio Source by name
 *
 * @param ausrcl List of Audio Sources
 * @param name   Name of the Audio Source to find
 *
 * @return Matching Audio Source if found, otherwise NULL
 */
const struct ausrc *ausrc_find(const struct list *ausrcl, const char *name)
{
	struct le *le;

	for (le=list_head(ausrcl); le; le=le->next) {

		struct ausrc *as = le->data;

		if (str_isset(name) && 0 != str_casecmp(name, as->name))
			continue;

		return as;
	}

	return NULL;
}
Exemplo n.º 24
0
/**
 * Find a Video Source by name
 *
 * @param name Name of the Video Source to find
 *
 * @return Matching Video Source if found, otherwise NULL
 */
const struct vidsrc *vidsrc_find(const char *name)
{
	struct le *le;

	for (le=vidsrcl.head; le; le=le->next) {

		struct vidsrc *vs = le->data;

		if (str_isset(name) && 0 != str_casecmp(name, vs->name))
			continue;

		return vs;
	}

	return NULL;
}
Exemplo n.º 25
0
static bool sort_handler(struct le *le1, struct le *le2, void *arg)
{
	struct cmd_sort *cs1 = le1->data;
	struct cmd_sort *cs2 = le2->data;
	const struct cmd *cmd1 = cs1->cmd;
	const struct cmd *cmd2 = cs2->cmd;
	bool print_long  = *(bool *)arg;

	if (print_long) {
		return str_casecmp(cs2->cmd->name ? cs2->cmd->name : "",
				   cs1->cmd->name ? cs1->cmd->name : "") >= 0;
	}
	else {
		return tolower(cmd2->key) >= tolower(cmd1->key);
	}
}
Exemplo n.º 26
0
const struct vidisp *vidisp_find(const struct list *vidispl, const char *name)
{
	struct le *le;

	for (le = list_head(vidispl); le; le = le->next) {
		struct vidisp *vd = le->data;

		if (str_isset(name) && 0 != str_casecmp(name, vd->name))
			continue;

		/* Found */
		return vd;
	}

	return NULL;
}
Exemplo n.º 27
0
void module_app_unload(void)
{
	struct le *le = list_tail(mod_list());

	/* unload in reverse order */
	while (le) {
		struct mod *mod = le->data;
		const struct mod_export *me = mod_export(mod);

		le = le->prev;

		if (me && 0 == str_casecmp(me->type, "application")) {
			debug("module: unloading app %s\n", me->name);
			mem_deref(mod);
		}
	}
}
Exemplo n.º 28
0
static bool linklocal_handler(const char *ifname, const struct sa *sa,
			      void *arg)
{
	void **argv = arg;
	int af = *(int *)argv[1];

	if (argv[0] && 0 != str_casecmp(argv[0], ifname))
		return false;

	if (af != AF_UNSPEC && af != sa_af(sa))
		return false;

	if (sa_is_linklocal(sa)) {
		*((struct sa *)argv[2]) = *sa;
		return true;
	}

	return false;
}
Exemplo n.º 29
0
static int module_app_handler(const struct pl *val, void *arg)
{
	struct mod *mod = NULL;
	const struct mod_export *me;

	debug("module: loading app %r\n", val);

	if (load_module(&mod, arg, val)) {
		return 0;
	}

	me = mod_export(mod);
	if (0 != str_casecmp(me->type, "application")) {
		warning("module_app %r should be type application (%s)\n",
			val, me->type);
	}

	return 0;
}
	static void mediaflow_localcand_handler(
					const struct zapi_candidate *candv,
					size_t candc, void *arg)
	{
		TestMedia *tm = static_cast<TestMedia *>(arg);
		ASSERT_TRUE(tm->candc < ARRAY_SIZE(tm->candv));

		for (size_t i=0; i<candc; i++) {
			struct ice_cand_attr *cand = &tm->candv[tm->candc];
			const struct zapi_candidate *zcand = &candv[i];
			int err;

			if (0 == str_casecmp(zcand->sdp,
					     "a=end-of-candidates")) {
				++tm->n_local_eoc;
				continue;
			}

			tm->candc++;

			err = ice_cand_attr_decode(cand, zcand->sdp);
			ASSERT_EQ(0, err);

			ASSERT_STREQ("audio", zcand->mid);
			ASSERT_EQ(0, zcand->mline_index);

			/* verify that SRFLX and RELAY candidates contain
			   the related address */
			switch (cand->type) {

			case ICE_CAND_TYPE_SRFLX:
			case ICE_CAND_TYPE_RELAY:
				ASSERT_TRUE(sa_isset(&cand->rel_addr, SA_ALL));
				break;
			default:
				break;
			}
		}

		if (tm->candc >= tm->candc_expected)
			re_cancel();
	}