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.h
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 
37 #ifndef RTCPSDESINFO_H
38 
39 #define RTCPSDESINFO_H
40 
41 #include "rtpconfig.h"
42 #include "rtperrors.h"
43 #include "rtpdefines.h"
44 #include "rtptypes.h"
45 #include <string.h>
46 #include <list>
47 
48 #include "export.h"
49 
50 namespace qrtplib
51 {
52 
55 {
56 public:
59  {
60  }
61  virtual ~RTCPSDESInfo()
62  {
63  Clear();
64  }
65 
67  void Clear();
68 
70  int SetCNAME(const uint8_t *s, std::size_t l)
71  {
72  return SetNonPrivateItem(RTCP_SDES_ID_CNAME - 1, s, l);
73  }
74 
76  int SetName(const uint8_t *s, std::size_t l)
77  {
78  return SetNonPrivateItem(RTCP_SDES_ID_NAME - 1, s, l);
79  }
80 
82  int SetEMail(const uint8_t *s, std::size_t l)
83  {
84  return SetNonPrivateItem(RTCP_SDES_ID_EMAIL - 1, s, l);
85  }
86 
88  int SetPhone(const uint8_t *s, std::size_t l)
89  {
90  return SetNonPrivateItem(RTCP_SDES_ID_PHONE - 1, s, l);
91  }
92 
94  int SetLocation(const uint8_t *s, std::size_t l)
95  {
96  return SetNonPrivateItem(RTCP_SDES_ID_LOCATION - 1, s, l);
97  }
98 
100  int SetTool(const uint8_t *s, std::size_t l)
101  {
102  return SetNonPrivateItem(RTCP_SDES_ID_TOOL - 1, s, l);
103  }
104 
106  int SetNote(const uint8_t *s, std::size_t l)
107  {
108  return SetNonPrivateItem(RTCP_SDES_ID_NOTE - 1, s, l);
109  }
110 
111 #ifdef RTP_SUPPORT_SDESPRIV
112 
116  int SetPrivateValue(const uint8_t *prefix, std::size_t prefixlen, const uint8_t *value, std::size_t valuelen);
117 
119  int DeletePrivatePrefix(const uint8_t *s, std::size_t len);
120 #endif // RTP_SUPPORT_SDESPRIV
121 
123  uint8_t *GetCNAME(std::size_t *len) const
124  {
125  return GetNonPrivateItem(RTCP_SDES_ID_CNAME - 1, len);
126  }
127 
129  uint8_t *GetName(std::size_t *len) const
130  {
131  return GetNonPrivateItem(RTCP_SDES_ID_NAME - 1, len);
132  }
133 
135  uint8_t *GetEMail(std::size_t *len) const
136  {
137  return GetNonPrivateItem(RTCP_SDES_ID_EMAIL - 1, len);
138  }
139 
141  uint8_t *GetPhone(std::size_t *len) const
142  {
143  return GetNonPrivateItem(RTCP_SDES_ID_PHONE - 1, len);
144  }
145 
147  uint8_t *GetLocation(std::size_t *len) const
148  {
149  return GetNonPrivateItem(RTCP_SDES_ID_LOCATION - 1, len);
150  }
151 
153  uint8_t *GetTool(std::size_t *len) const
154  {
155  return GetNonPrivateItem(RTCP_SDES_ID_TOOL - 1, len);
156  }
157 
159  uint8_t *GetNote(std::size_t *len) const
160  {
161  return GetNonPrivateItem(RTCP_SDES_ID_NOTE - 1, len);
162  }
163 #ifdef RTP_SUPPORT_SDESPRIV
164 
165  void GotoFirstPrivateValue();
166 
174  bool GetNextPrivateValue(uint8_t **prefix, std::size_t *prefixlen, uint8_t **value, std::size_t *valuelen);
175 
183  bool GetPrivateValue(const uint8_t *prefix, std::size_t prefixlen, uint8_t **value, std::size_t *valuelen) const;
184 #endif // RTP_SUPPORT_SDESPRIV
185 private:
186  int SetNonPrivateItem(int itemno, const uint8_t *s, std::size_t l)
187  {
188  if (l > RTCP_SDES_MAXITEMLENGTH)
190  return nonprivateitems[itemno].SetInfo(s, l);
191  }
192  uint8_t *GetNonPrivateItem(int itemno, std::size_t *len) const
193  {
194  return nonprivateitems[itemno].GetInfo(len);
195  }
196 
197  class SDESItem
198  {
199  public:
201  {
202  str = 0;
203  length = 0;
204  }
206  {
207  if (str)
208  delete[] str;
209  }
210  uint8_t *GetInfo(std::size_t *len) const
211  {
212  *len = length;
213  return str;
214  }
215  int SetInfo(const uint8_t *s, std::size_t len)
216  {
217  return SetString(&str, &length, s, len);
218  }
219  protected:
220  int SetString(uint8_t **dest, std::size_t *destlen, const uint8_t *s, std::size_t len)
221  {
222  if (len <= 0)
223  {
224  if (*dest)
225  delete[] (*dest);
226  *dest = 0;
227  *destlen = 0;
228  }
229  else
230  {
231  len = (len > RTCP_SDES_MAXITEMLENGTH) ? RTCP_SDES_MAXITEMLENGTH : len;
232  uint8_t *str2 = new uint8_t[len];
233  memcpy(str2, s, len);
234  *destlen = len;
235  if (*dest)
236  delete[] (*dest);
237  *dest = str2;
238  }
239  return 0;
240  }
241  private:
243  std::size_t length;
244  };
245 
247 
248 #ifdef RTP_SUPPORT_SDESPRIV
249  class SDESPrivateItem: public SDESItem
250  {
251  public:
253  {
254  prefixlen = 0;
255  prefix = 0;
256  }
258  {
259  if (prefix)
260  delete[] prefix;
261  }
262  uint8_t *GetPrefix(std::size_t *len) const
263  {
264  *len = prefixlen;
265  return prefix;
266  }
267  int SetPrefix(const uint8_t *s, std::size_t len)
268  {
269  return SetString(&prefix, &prefixlen, s, len);
270  }
271  private:
273  std::size_t prefixlen;
274  };
275 
276  std::list<SDESPrivateItem *> privitems;
277  std::list<SDESPrivateItem *>::const_iterator curitem;
278 #endif // RTP_SUPPORT_SDESPRIV
279 };
280 
281 } // end namespace
282 
283 #endif // RTCPSDESINFO_H
284 
#define RTCP_SDES_ID_EMAIL
Definition: rtpdefines.h:58
#define RTCP_SDES_ID_LOCATION
Definition: rtpdefines.h:60
uint8_t * GetTool(std::size_t *len) const
Definition: rtcpsdesinfo.h:153
uint8_t * GetNonPrivateItem(int itemno, std::size_t *len) const
Definition: rtcpsdesinfo.h:192
#define RTCP_SDES_NUMITEMS_NONPRIVATE
Definition: rtpdefines.h:64
uint8_t * GetCNAME(std::size_t *len) const
Definition: rtcpsdesinfo.h:123
uint8_t * GetNote(std::size_t *len) const
Definition: rtcpsdesinfo.h:159
int SetPhone(const uint8_t *s, std::size_t l)
Definition: rtcpsdesinfo.h:88
std::list< SDESPrivateItem * >::const_iterator curitem
Definition: rtcpsdesinfo.h:277
#define RTCP_SDES_ID_NOTE
Definition: rtpdefines.h:62
int SetNonPrivateItem(int itemno, const uint8_t *s, std::size_t l)
Definition: rtcpsdesinfo.h:186
#define QRTPLIB_API
Definition: export.h:112
uint8_t * GetLocation(std::size_t *len) const
Definition: rtcpsdesinfo.h:147
#define RTCP_SDES_MAXITEMLENGTH
Definition: rtpdefines.h:65
int SetEMail(const uint8_t *s, std::size_t l)
Definition: rtcpsdesinfo.h:82
int SetCNAME(const uint8_t *s, std::size_t l)
Definition: rtcpsdesinfo.h:70
unsigned char uint8_t
Definition: rtptypes_win.h:42
int SetInfo(const uint8_t *s, std::size_t len)
Definition: rtcpsdesinfo.h:215
uint8_t * GetName(std::size_t *len) const
Definition: rtcpsdesinfo.h:129
uint8_t * GetEMail(std::size_t *len) const
Definition: rtcpsdesinfo.h:135
#define RTCP_SDES_ID_TOOL
Definition: rtpdefines.h:61
int SetTool(const uint8_t *s, std::size_t l)
Definition: rtcpsdesinfo.h:100
std::list< SDESPrivateItem * > privitems
Definition: rtcpsdesinfo.h:276
int SetLocation(const uint8_t *s, std::size_t l)
Definition: rtcpsdesinfo.h:94
#define RTCP_SDES_ID_CNAME
Definition: rtpdefines.h:56
uint8_t * GetPhone(std::size_t *len) const
Definition: rtcpsdesinfo.h:141
int SetPrefix(const uint8_t *s, std::size_t len)
Definition: rtcpsdesinfo.h:267
int SetName(const uint8_t *s, std::size_t l)
Definition: rtcpsdesinfo.h:76
int SetString(uint8_t **dest, std::size_t *destlen, const uint8_t *s, std::size_t len)
Definition: rtcpsdesinfo.h:220
#define RTCP_SDES_ID_NAME
Definition: rtpdefines.h:57
#define ERR_RTP_SDES_LENGTHTOOBIG
Definition: rtperrors.h:107
#define RTCP_SDES_ID_PHONE
Definition: rtpdefines.h:59
uint8_t * GetInfo(std::size_t *len) const
Definition: rtcpsdesinfo.h:210
int SetNote(const uint8_t *s, std::size_t l)
Definition: rtcpsdesinfo.h:106
uint8_t * GetPrefix(std::size_t *len) const
Definition: rtcpsdesinfo.h:262