SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
rtcpsdesinfo.cpp
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2017 Jori Liesenborgs
5 
6  Contact: jori.liesenborgs@gmail.com
7 
8  This library was developed at the Expertise Centre for Digital Media
9  (http://www.edm.uhasselt.be), a research center of the Hasselt University
10  (http://www.uhasselt.be). The library is based upon work done for
11  my thesis at the School for Knowledge Technology (Belgium/The Netherlands).
12 
13  Permission is hereby granted, free of charge, to any person obtaining a
14  copy of this software and associated documentation files (the "Software"),
15  to deal in the Software without restriction, including without limitation
16  the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  and/or sell copies of the Software, and to permit persons to whom the
18  Software is furnished to do so, subject to the following conditions:
19 
20  The above copyright notice and this permission notice shall be included
21  in all copies or substantial portions of the Software.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29  IN THE SOFTWARE.
30 
31  */
32 
33 #include "rtcpsdesinfo.h"
34 
35 namespace qrtplib
36 {
37 
39 {
40 #ifdef RTP_SUPPORT_SDESPRIV
41  std::list<SDESPrivateItem *>::const_iterator it;
42 
43  for (it = privitems.begin(); it != privitems.end(); ++it)
44  delete *it;
45  privitems.clear();
46 #endif // RTP_SUPPORT_SDESPRIV
47 }
48 
49 #ifdef RTP_SUPPORT_SDESPRIV
50 int RTCPSDESInfo::SetPrivateValue(const uint8_t *prefix, std::size_t prefixlen, const uint8_t *value, std::size_t valuelen)
51 {
52  std::list<SDESPrivateItem *>::const_iterator it;
53  bool found;
54 
55  found = false;
56  it = privitems.begin();
57  while (!found && it != privitems.end())
58  {
59  uint8_t *p;
60  std::size_t l;
61 
62  p = (*it)->GetPrefix(&l);
63  if (l == prefixlen)
64  {
65  if (l <= 0)
66  found = true;
67  else if (memcmp(prefix, p, l) == 0)
68  found = true;
69  else
70  ++it;
71  }
72  else
73  ++it;
74  }
75 
76  SDESPrivateItem *item;
77 
78  if (found) // replace the value for this entry
79  item = *it;
80  else // no entry for this prefix found... add it
81  {
82  if (privitems.size() >= RTP_MAXPRIVITEMS) // too many items present, just ignore it
84 
85  int status;
86 
87  item = new SDESPrivateItem();
88 
89  if ((status = item->SetPrefix(prefix, prefixlen)) < 0)
90  {
91  delete item;
92  return status;
93  }
94  privitems.push_front(item);
95  }
96  return item->SetInfo(value, valuelen);
97 }
98 
99 int RTCPSDESInfo::DeletePrivatePrefix(const uint8_t *prefix, std::size_t prefixlen)
100 {
101  std::list<SDESPrivateItem *>::iterator it;
102  bool found;
103 
104  found = false;
105  it = privitems.begin();
106  while (!found && it != privitems.end())
107  {
108  uint8_t *p;
109  std::size_t l;
110 
111  p = (*it)->GetPrefix(&l);
112  if (l == prefixlen)
113  {
114  if (l <= 0)
115  found = true;
116  else if (memcmp(prefix, p, l) == 0)
117  found = true;
118  else
119  ++it;
120  }
121  else
122  ++it;
123  }
124  if (!found)
126 
127  delete *it;
128  privitems.erase(it);
129  return 0;
130 }
131 
133 {
134  curitem = privitems.begin();
135 }
136 
137 bool RTCPSDESInfo::GetNextPrivateValue(uint8_t **prefix, std::size_t *prefixlen, uint8_t **value, std::size_t *valuelen)
138 {
139  if (curitem == privitems.end())
140  return false;
141  *prefix = (*curitem)->GetPrefix(prefixlen);
142  *value = (*curitem)->GetInfo(valuelen);
143  ++curitem;
144  return true;
145 }
146 
147 bool RTCPSDESInfo::GetPrivateValue(const uint8_t *prefix, std::size_t prefixlen, uint8_t **value, std::size_t *valuelen) const
148 {
149  std::list<SDESPrivateItem *>::const_iterator it;
150  bool found;
151 
152  found = false;
153  it = privitems.begin();
154  while (!found && it != privitems.end())
155  {
156  uint8_t *p;
157  std::size_t l;
158 
159  p = (*it)->GetPrefix(&l);
160  if (l == prefixlen)
161  {
162  if (l <= 0)
163  found = true;
164  else if (memcmp(prefix, p, l) == 0)
165  found = true;
166  else
167  ++it;
168  }
169  else
170  ++it;
171  }
172  if (found)
173  *value = (*it)->GetInfo(valuelen);
174  return found;
175 }
176 #endif // RTP_SUPPORT_SDESPRIV
177 
178 } // end namespace
179 
std::list< SDESPrivateItem * >::const_iterator curitem
Definition: rtcpsdesinfo.h:277
#define ERR_RTP_SDES_MAXPRIVITEMS
Definition: rtperrors.h:108
int SetPrivateValue(const uint8_t *prefix, std::size_t prefixlen, const uint8_t *value, std::size_t valuelen)
bool GetPrivateValue(const uint8_t *prefix, std::size_t prefixlen, uint8_t **value, std::size_t *valuelen) const
#define RTP_MAXPRIVITEMS
Definition: rtpdefines.h:42
unsigned char uint8_t
Definition: rtptypes_win.h:42
int DeletePrivatePrefix(const uint8_t *s, std::size_t len)
int SetInfo(const uint8_t *s, std::size_t len)
Definition: rtcpsdesinfo.h:215
std::list< SDESPrivateItem * > privitems
Definition: rtcpsdesinfo.h:276
int SetPrefix(const uint8_t *s, std::size_t len)
Definition: rtcpsdesinfo.h:267
#define ERR_RTP_SDES_PREFIXNOTFOUND
Definition: rtperrors.h:109
bool GetNextPrivateValue(uint8_t **prefix, std::size_t *prefixlen, uint8_t **value, std::size_t *valuelen)