jrtplib  3.6.0
rtcpsdesinfo.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2006 Jori Liesenborgs
5 
6  Contact: jori.liesenborgs@gmail.com
7 
8  This library was developed at the "Expertisecentrum Digitale 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 "rtpmemoryobject.h"
46 #include <string.h>
47 #include <list>
48 
50 class RTCPSDESInfo : public RTPMemoryObject
51 {
52 public:
54  RTCPSDESInfo(RTPMemoryManager *mgr = 0) : RTPMemoryObject(mgr) { for (int i = 0 ; i < RTCP_SDES_NUMITEMS_NONPRIVATE ; i++) nonprivateitems[i].SetMemoryManager(mgr); }
55  virtual ~RTCPSDESInfo() { Clear(); }
56 
58  void Clear();
59 
61  int SetCNAME(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_CNAME-1,s,l); }
62 
64  int SetName(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_NAME-1,s,l); }
65 
67  int SetEMail(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_EMAIL-1,s,l); }
68 
70  int SetPhone(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_PHONE-1,s,l); }
71 
73  int SetLocation(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_LOCATION-1,s,l); }
74 
76  int SetTool(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_TOOL-1,s,l); }
77 
79  int SetNote(const uint8_t *s,size_t l) { return SetNonPrivateItem(RTCP_SDES_ID_NOTE-1,s,l); }
80 
81 #ifdef RTP_SUPPORT_SDESPRIV
82 
86  int SetPrivateValue(const uint8_t *prefix,size_t prefixlen,const uint8_t *value,size_t valuelen);
87 
89  int DeletePrivatePrefix(const uint8_t *s,size_t len);
90 #endif // RTP_SUPPORT_SDESPRIV
91 
93  uint8_t *GetCNAME(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_CNAME-1,len); }
94 
96  uint8_t *GetName(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_NAME-1,len); }
97 
99  uint8_t *GetEMail(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_EMAIL-1,len); }
100 
102  uint8_t *GetPhone(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_PHONE-1,len); }
103 
105  uint8_t *GetLocation(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_LOCATION-1,len); }
106 
108  uint8_t *GetTool(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_TOOL-1,len); }
109 
111  uint8_t *GetNote(size_t *len) const { return GetNonPrivateItem(RTCP_SDES_ID_NOTE-1,len); }
112 #ifdef RTP_SUPPORT_SDESPRIV
113 
114  void GotoFirstPrivateValue();
115 
123  bool GetNextPrivateValue(uint8_t **prefix,size_t *prefixlen,uint8_t **value,size_t *valuelen);
124 
132  bool GetPrivateValue(const uint8_t *prefix,size_t prefixlen,uint8_t **value,size_t *valuelen) const;
133 #endif // RTP_SUPPORT_SDESPRIV
134 private:
135  int SetNonPrivateItem(int itemno,const uint8_t *s,size_t l) { if (l > RTCP_SDES_MAXITEMLENGTH) return ERR_RTP_SDES_LENGTHTOOBIG; return nonprivateitems[itemno].SetInfo(s,l); }
136  uint8_t *GetNonPrivateItem(int itemno,size_t *len) const { return nonprivateitems[itemno].GetInfo(len); }
137 
138  class SDESItem : public RTPMemoryObject
139  {
140  public:
141  SDESItem(RTPMemoryManager *mgr = 0) : RTPMemoryObject(mgr)
142  {
143  str = 0;
144  length = 0;
145  }
146  void SetMemoryManager(RTPMemoryManager *mgr)
147  {
148  RTPMemoryObject::SetMemoryManager(mgr);
149  }
150  ~SDESItem()
151  {
152  if (str)
153  RTPDeleteByteArray(str,GetMemoryManager());
154  }
155  uint8_t *GetInfo(size_t *len) const { *len = length; return str; }
156  int SetInfo(const uint8_t *s,size_t len) { return SetString(&str,&length,s,len); }
157  protected:
158  int SetString(uint8_t **dest,size_t *destlen,const uint8_t *s,size_t len)
159  {
160  if (len <= 0)
161  {
162  if (*dest)
163  RTPDeleteByteArray((*dest),GetMemoryManager());
164  *dest = 0;
165  *destlen = 0;
166  }
167  else
168  {
169  len = (len>RTCP_SDES_MAXITEMLENGTH)?RTCP_SDES_MAXITEMLENGTH:len;
170  uint8_t *str2 = RTPNew(GetMemoryManager(),RTPMEM_TYPE_BUFFER_SDESITEM) uint8_t[len];
171  if (str2 == 0)
172  return ERR_RTP_OUTOFMEM;
173  memcpy(str2,s,len);
174  *destlen = len;
175  if (*dest)
176  RTPDeleteByteArray((*dest),GetMemoryManager());
177  *dest = str2;
178  }
179  return 0;
180  }
181  private:
182  uint8_t *str;
183  size_t length;
184  };
185 
186  SDESItem nonprivateitems[RTCP_SDES_NUMITEMS_NONPRIVATE];
187 
188 #ifdef RTP_SUPPORT_SDESPRIV
189  class SDESPrivateItem : public SDESItem
190  {
191  public:
192  SDESPrivateItem(RTPMemoryManager *mgr) : SDESItem(mgr)
193  {
194  prefixlen = 0;
195  prefix = 0;
196  }
197  ~SDESPrivateItem()
198  {
199  if (prefix)
200  RTPDeleteByteArray(prefix,GetMemoryManager());
201  }
202  uint8_t *GetPrefix(size_t *len) const { *len = prefixlen; return prefix; }
203  int SetPrefix(const uint8_t *s,size_t len) { return SetString(&prefix,&prefixlen,s,len); }
204  private:
205  uint8_t *prefix;
206  size_t prefixlen;
207  };
208 
209  std::list<SDESPrivateItem *> privitems;
210  std::list<SDESPrivateItem *>::const_iterator curitem;
211 #endif // RTP_SUPPORT_SDESPRIV
212 };
213 
214 #endif // RTCPSDESINFO_H
215 
uint8_t * GetLocation(size_t *len) const
Returns the SDES location item and stores its length in len.
Definition: rtcpsdesinfo.h:105
int SetNote(const uint8_t *s, size_t l)
Sets the SDES note item to s with length l.
Definition: rtcpsdesinfo.h:79
RTCPSDESInfo(RTPMemoryManager *mgr=0)
Constructs an instance, optionally installing a memory manager.
Definition: rtcpsdesinfo.h:54
int SetLocation(const uint8_t *s, size_t l)
Sets the SDES location item to s with length l.
Definition: rtcpsdesinfo.h:73
#define RTPMEM_TYPE_BUFFER_SDESITEM
Buffer to store an SDES item.
Definition: rtpmemorymanager.h:75
The class RTCPSDESInfo is a container for RTCP SDES information.
Definition: rtcpsdesinfo.h:50
uint8_t * GetName(size_t *len) const
Returns the SDES name item and stores its length in len.
Definition: rtcpsdesinfo.h:96
A memory manager.
Definition: rtpmemorymanager.h:144
bool GetNextPrivateValue(uint8_t **prefix, size_t *prefixlen, uint8_t **value, size_t *valuelen)
Returns SDES priv item information.
uint8_t * GetEMail(size_t *len) const
Returns the SDES e-mail item and stores its length in len.
Definition: rtcpsdesinfo.h:99
int SetEMail(const uint8_t *s, size_t l)
Sets the SDES e-mail item to s with length l.
Definition: rtcpsdesinfo.h:67
bool GetPrivateValue(const uint8_t *prefix, size_t prefixlen, uint8_t **value, size_t *valuelen) const
Returns SDES priv item information.
int SetCNAME(const uint8_t *s, size_t l)
Sets the SDES CNAME item to s with length l.
Definition: rtcpsdesinfo.h:61
int DeletePrivatePrefix(const uint8_t *s, size_t len)
Deletes the entry for the prefix specified by s with length len.
int SetPrivateValue(const uint8_t *prefix, size_t prefixlen, const uint8_t *value, size_t valuelen)
Sets the entry for the prefix string specified by prefix with length prefixlen to contain the value s...
uint8_t * GetTool(size_t *len) const
Returns the SDES tool item and stores its length in len.
Definition: rtcpsdesinfo.h:108
uint8_t * GetPhone(size_t *len) const
Returns the SDES phone item and stores its length in len.
Definition: rtcpsdesinfo.h:102
int SetTool(const uint8_t *s, size_t l)
Sets the SDES tool item to s with length l.
Definition: rtcpsdesinfo.h:76
int SetName(const uint8_t *s, size_t l)
Sets the SDES name item to s with length l.
Definition: rtcpsdesinfo.h:64
void GotoFirstPrivateValue()
Starts the iteration over the stored SDES private item prefixes and their associated values...
void Clear()
Clears all SDES information.
int SetPhone(const uint8_t *s, size_t l)
Sets the SDES phone item to s with length l.
Definition: rtcpsdesinfo.h:70
uint8_t * GetNote(size_t *len) const
Returns the SDES note item and stores its length in len.
Definition: rtcpsdesinfo.h:111
uint8_t * GetCNAME(size_t *len) const
Returns the SDES CNAME item and stores its length in len.
Definition: rtcpsdesinfo.h:93