1 /**
2  * @file member.c  Real-time Transport Control Protocol member
3  *
4  * Copyright (C) 2010 Creytiv.com
5  */
6 #include <string.h>
7 #include <re_types.h>
8 #include <re_fmt.h>
9 #include <re_mem.h>
10 #include <re_mbuf.h>
11 #include <re_list.h>
12 #include <re_hash.h>
13 #include <re_sa.h>
14 #include <re_rtp.h>
odict_type_iscontainer(enum odict_type type)15 #include "rtcp.h"
16 
17 
18 static void destructor(void *data)
19 {
20 	struct rtp_member *mbr = data;
21 
22 	hash_unlink(&mbr->le);
23 	mem_deref(mbr->s);
24 }
25 
26 
27 struct rtp_member *member_add(struct hash *ht, uint32_t src)
28 {
odict_type_isreal(enum odict_type type)29 	struct rtp_member *mbr;
30 
31 	mbr = mem_zalloc(sizeof(*mbr), destructor);
32 	if (!mbr)
33 		return NULL;
34 
35 	hash_append(ht, src, &mbr->le, mbr);
36 	mbr->src = src;
37 
38 	return mbr;
39 }
40 
41 
42 static bool hash_cmp_handler(struct le *le, void *arg)
43 {
44 	const struct rtp_member *mbr = le->data;
45 
odict_type_name(enum odict_type type)46 	return mbr->src == *(uint32_t *)arg;
47 }
48 
49 
50 struct rtp_member *member_find(struct hash *ht, uint32_t src)
51 {
52 	return list_ledata(hash_lookup(ht, src, hash_cmp_handler, &src));
53 }
54