コード例 #1
0
ファイル: contact.c プロジェクト: GGGO/baresip
/**
 * Check the access parameter of a SIP uri
 *
 * - Matching uri has first presedence
 * - Global <sip:*@*> uri has second presedence
 *
 * @param contacts Contacts container
 * @param uri      SIP uri to check for access
 *
 * @return True if blocked, false if allowed
 */
bool contact_block_access(const struct contacts *contacts, const char *uri)
{
	struct contact *c;

	c = contact_find(contacts, uri);
	if (c && c->access != ACCESS_UNKNOWN)
		return c->access == ACCESS_BLOCK;

	c = contact_find(contacts, "sip:*@*");
	if (c && c->access != ACCESS_UNKNOWN)
		return c->access == ACCESS_BLOCK;

	return false;
}
コード例 #2
0
ファイル: chat.c プロジェクト: Studio-Link-v2/backend
static void message_handler(const struct pl *peer, const struct pl *ctype,
		struct mbuf *body, void *arg)
{
	(void)ctype;
	(void)arg;
	char message[256] = {0};
	char s_peer[50] = {0};
	struct contacts *contacts = baresip_contacts();

	(void)re_snprintf(message, sizeof(message), "%b",
			mbuf_buf(body), mbuf_get_left(body));

	(void)re_snprintf(s_peer, sizeof(s_peer), "%r", peer);

	warning("message from %s: %s\n", s_peer, message);

	struct contact *c = contact_find(contacts, s_peer);

	if (c) {
		const struct sip_addr *addr = contact_addr(c);
		(void)re_snprintf(s_peer, sizeof(s_peer), "%r", &addr->dname);
		(void)webapp_chat_add(s_peer, message, false);
		ws_send_json(WS_CHAT, webapp_messages_get());
	}
}
コード例 #3
0
ファイル: contact.c プロジェクト: Studio-Link/baresip
int test_contact(void)
{
	struct contacts *contacts = NULL;
	struct contact *c;
	const char *addr = "Neil Young <sip:[email protected]>";
	const char *uri = "sip:[email protected]";
	struct pl pl_addr;
	int err;

	err = contact_init(&contacts);
	ASSERT_EQ(0, err);

	/* Verify that we have no contacts */

	ASSERT_EQ(0, list_count(contact_list(contacts)));

	c = contact_find(contacts, "sip:[email protected]");
	ASSERT_TRUE(c == NULL);

	/* Add one contact, list should have one entry and
	   find should return the added contact */

	pl_set_str(&pl_addr, addr);
	err = contact_add(contacts, &c, &pl_addr);
	ASSERT_EQ(0, err);
	ASSERT_TRUE(c != NULL);

	ASSERT_EQ(1, list_count(contact_list(contacts)));

	c = contact_find(contacts, uri);
	ASSERT_TRUE(c != NULL);

	ASSERT_STREQ(addr, contact_str(c));
	ASSERT_STREQ(uri, contact_uri(c));

	/* Delete 1 contact, verify that list is empty */

	mem_deref(c);

	ASSERT_EQ(0, list_count(contact_list(contacts)));

 out:
	mem_deref(contacts);

	return err;
}