Coverage Report

Created: 2023-09-25 06:23

/src/resiprocate/resip/stack/DialogInfoContents.hxx
Line
Count
Source (jump to first uncovered line)
1
#if !defined(RESIP_DialogInfoContents_HXX)
2
#define RESIP_DialogInfoContents_HXX 
3
4
#include <map>
5
#include <list>
6
7
#include "resip/stack/Contents.hxx"
8
#include "rutil/Data.hxx"
9
#include "rutil/HashMap.hxx"
10
#include "resip/stack/Uri.hxx"
11
#include "rutil/HeapInstanceCounter.hxx"
12
13
namespace resip
14
{
15
16
class XMLCursor;
17
18
/**
19
   SIP body type for holding DialogInfo contents (MIME content-type application/dialog-info+xml).
20
*/
21
class DialogInfoContents : public Contents
22
{
23
public:
24
25
   enum DialogInfoState
26
   {
27
      Full,
28
      Partial,
29
      MaxDialogInfoState
30
   };
31
   // Warning if you modify the above list, make sure you modify DialogInfoStateStrings in the .cxx file to match
32
33
   enum DialogState
34
   {
35
      Trying = 0,
36
      Proceeding,
37
      Early,
38
      Confirmed,
39
      Terminated,
40
      MaxDialogState
41
   };
42
   // Warning if you modify the above list, make sure you modify DialogStateStrings in the .cxx file to match
43
44
   enum DialogStateEvent
45
   {
46
      Cancelled = 0,
47
      Rejected,
48
      Replaced,
49
      LocalBye,
50
      RemoteBye,
51
      Error,
52
      Timeout,
53
      MaxOrUnsetDialogStateEvent
54
   };
55
   // Warning if you modify the above list, make sure you modify DialogStateEventStrings in the .cxx file to match
56
57
   enum Direction
58
   {
59
      Initiator = 0,
60
      Recipient,
61
      MaxOrUnsetDirection
62
   };
63
   // Warning if you modify the above list, make sure you modify DialogStateEventStrings in the .cxx file to match
64
65
   static const DialogInfoContents Empty;
66
67
   RESIP_HeapCount(DialogInfoContents);
68
   DialogInfoContents(const Mime& contentType);
69
   DialogInfoContents();
70
   DialogInfoContents(const HeaderFieldValue& hfv, const Mime& contentType);
71
   virtual ~DialogInfoContents();
72
73
   /** @brief duplicate an DialogInfoContents object
74
       @return pointer to a new DialogInfoContents object
75
       **/
76
   virtual Contents* clone() const;
77
   static const Mime& getStaticType();
78
   virtual EncodeStream& encodeParsed(EncodeStream& str) const;
79
   virtual void parse(ParseBuffer& pb);
80
81
   // Default is 3 spaces "   "
82
0
   void setEncodeIndent(const Data& indent) { mIndent = indent; }
83
84
   // Accesors for data
85
0
   void setEntity(const Uri& entity) { checkParsed(); mEntity = entity; }
86
0
   const Uri& getEntity() const { checkParsed(); return mEntity; }
87
88
0
   void setVersion(uint32_t version) { checkParsed(); mVersion = version; }
89
0
   uint32_t getVersion() const { checkParsed(); return mVersion; }
90
91
0
   void setDialogInfoState(DialogInfoState dialogInfoState) { checkParsed(); mDialogInfoState = dialogInfoState; }
92
0
   DialogInfoState getDialogInfoState() const { checkParsed(); return mDialogInfoState; }
93
94
   // A DialogInfoContents can have multiple Dialog sections in it
95
   class Dialog
96
   {
97
   public:
98
      class DialogIdInfo
99
      {
100
      public:
101
0
         DialogIdInfo() {}
102
         DialogIdInfo(const Data& callId, const Data& localTag, const Data& remoteTag) :
103
0
            mCallId(callId), mLocalTag(localTag), mRemoteTag(remoteTag) {}
104
         Data mCallId;
105
         Data mLocalTag;
106
         Data mRemoteTag;
107
      };
108
109
      Dialog() : mDirection(MaxOrUnsetDirection), mState(Trying), mStateEvent(MaxOrUnsetDialogStateEvent), mStateCode(0), mDuration(0),
110
0
         mHasDuration(false), mAppearance(0), mHasAppearance(false), mExclusive(false), mHasExclusive(false) {}
111
112
      // Accesors for data
113
0
      void setId(const Data& id) { mId = id; }
114
0
      const Data& getId() const { return mId; }
115
116
0
      void setCallId(const Data& callId) { mCallId = callId; }
117
0
      const Data& getCallId() const { return mCallId; }
118
119
0
      void setLocalTag(const Data& localTag) { mLocalTag = localTag; }
120
0
      const Data& getLocalTag() const { return mLocalTag; }
121
122
0
      void setRemoteTag(const Data& remoteTag) { mRemoteTag = remoteTag; }
123
0
      const Data& getRemoteTag() const { return mRemoteTag; }
124
125
0
      void setDirection(const Direction& direction) { mDirection = direction; }
126
0
      const Direction& getDirection() const { return mDirection; }
127
128
0
      void setState(const DialogState& state) { mState = state; }
129
0
      const DialogState& getState() const { return mState; }
130
131
0
      void setStateEvent(const DialogStateEvent& stateEvent) { mStateEvent = stateEvent; }
132
0
      const DialogStateEvent& getStateEvent() const { return mStateEvent; }
133
134
0
      void setStateCode(const int& stateCode) { mStateCode = stateCode; }
135
0
      const int& getStateCode() const { return mStateCode; }
136
137
0
      void setDuration(const uint32_t& duration) { mDuration = duration; mHasDuration = true; }
138
0
      void clearDuration() { mDuration = 0; mHasDuration = false; }
139
0
      bool hasDuration() const { return mHasDuration; }
140
0
      const uint32_t& getDuration() const { return mDuration; }
141
142
      void setReplacesInfo(const Data& callId, const Data& localTag, const Data& remoteTag) 
143
0
         { mReplaces.mCallId = callId; mReplaces.mLocalTag = localTag; mReplaces.mRemoteTag = remoteTag; }
144
0
      const Dialog::DialogIdInfo& getReplaces() const { return mReplaces; }
145
0
      const Data& getReplacesCallId() const { return mReplaces.mCallId; }
146
0
      const Data& getReplacesLocalTag() const { return mReplaces.mLocalTag; }
147
0
      const Data& getReplacesRemoteTag() const { return mReplaces.mRemoteTag; }
148
149
0
      void setReferredBy(const NameAddr& referredBy) { mReferredBy = referredBy; }
150
0
      const NameAddr& getReferredBy() const { return mReferredBy; }
151
152
0
      void addRouteToRouteSet(const NameAddr& route) { mRouteSet.push_back(route); }
153
0
      void setRouteSet(const NameAddrs& routes) { mRouteSet = routes; }
154
0
      void clearRouteSet() { mRouteSet.clear(); }
155
0
      const NameAddrs& getRouteSet() const { return mRouteSet; }
156
157
      // RFC7463 Elements
158
0
      void setAppearance(unsigned int appearanceNum) { mAppearance = appearanceNum; mHasAppearance = true; }
159
0
      void clearAppearance() { mAppearance = 0; mHasAppearance = false; }
160
0
      bool hasAppearance() const { return mHasAppearance; }
161
0
      bool getAppearance() const { return mAppearance; }
162
163
0
      void setExclusive(bool exclusive) { mExclusive = exclusive; mHasExclusive = true; }
164
0
      void clearExclusive() { mExclusive = false; mHasExclusive = false; }
165
0
      bool hasExclusive() const { return mHasExclusive; }
166
0
      bool getExclusive() const { return mExclusive; }
167
168
      void addReplacedDialog(const Data& callId, const Data& localTag, const Data& remoteTag)
169
0
         { mReplacedDialogs.push_back(DialogIdInfo(callId, localTag, remoteTag)); }
170
0
      void addReplacedDialog(const Dialog::DialogIdInfo& dialogIdInfo) { mReplacedDialogs.push_back(dialogIdInfo); }
171
0
      void clearReplacedDialogs() { mReplacedDialogs.clear(); }
172
0
      const std::list<Dialog::DialogIdInfo>& getReplacedDialogs() const { return mReplacedDialogs; }
173
174
      void addJoinedDialog(const Data& callId, const Data& localTag, const Data& remoteTag)
175
0
         { mJoinedDialogs.push_back(DialogIdInfo(callId, localTag, remoteTag)); }
176
0
      void addJoinedDialog(const Dialog::DialogIdInfo& dialogIdInfo) { mJoinedDialogs.push_back(dialogIdInfo); }
177
0
      void clearJoinedDialogs() { mJoinedDialogs.clear(); }
178
0
      const std::list<Dialog::DialogIdInfo>& getJoinedDialogs() const { return mJoinedDialogs; }
179
180
      class Participant
181
      {
182
      public:
183
0
         Participant() : mCSeq(0), mHasCSeq(false) {}
184
185
0
         void setIdentity(const NameAddr& identity) { mIdentity = identity; }
186
0
         const NameAddr& getIdentity() const { return mIdentity; }
187
188
0
         void setTarget(const Uri& target) { mTarget = target; }
189
         void setTarget(const NameAddr& targetWithContactParams);
190
0
         const Uri& getTarget() const { return mTarget; }
191
192
         typedef std::map<Data, Data> TargetParams;
193
0
         void addTargetParam(const Data& name, const Data& value) { mTargetParams[name] = value; }
194
0
         void clearTargetParams() { mTargetParams.clear(); }
195
0
         const TargetParams& getTargetParams() const { return mTargetParams; }
196
         bool getTargetParam(const Data& name, Data& value) const;
197
198
         void setSessionDescription(const Data& sessionDescription, const Data& sessionDescriptionType)
199
0
            {  mSessionDescription = sessionDescription; mSessionDescriptionType = sessionDescriptionType; }
200
0
         const Data& getSessionDescription() const { return mSessionDescription; }
201
0
         const Data& getSessionDescriptionType() const { return mSessionDescriptionType; }
202
203
0
         void setCSeq(const uint32_t& cseq) { mCSeq = cseq; mHasCSeq = true; }
204
0
         void clearCSeq() { mCSeq = 0; mHasCSeq = false; }
205
0
         bool hasCSeq() const { return mHasCSeq; }
206
0
         const uint32_t& getCSeq() const { return mCSeq; }
207
208
      private:
209
         NameAddr mIdentity;
210
         Uri mTarget;
211
         TargetParams mTargetParams;
212
         Data mSessionDescription;
213
         Data mSessionDescriptionType;
214
         uint32_t mCSeq;
215
         bool mHasCSeq;
216
217
         friend class Dialog;
218
         friend class DialogInfoContents;
219
         EncodeStream& encode(EncodeStream& str, const char* baseElementName, const Data& indent) const;
220
         void parse(XMLCursor& xml, const Data& namespacePrefix);
221
         void parseParam(XMLCursor& xml);
222
      };
223
224
0
      Participant& localParticipant() { return mLocalParticipant; }
225
0
      const Participant& localParticipant() const { return mLocalParticipant; }
226
227
0
      Participant& remoteParticipant() { return mRemoteParticipant; }
228
0
      const Participant& remoteParticipant() const { return mRemoteParticipant; }
229
230
      // add element name and value to the extra Dialog child elements map
231
      // These are local/non-standard child elements to the Dialog element
232
0
      void addDialogElement(const Data& childElementName, const Data& elementValue) { mExtraDialogElements.insert( std::pair<Data,Data>(childElementName, elementValue));}
233
234
      // get the instance'th occurance of the named Dialog child element.
235
      // The first instance is index 0.
236
      bool getDialogElement(const Data& childElementName, Data& elementValue, int instance=0) const;
237
238
   private:
239
      Data mId;
240
      Data mCallId;
241
      Data mLocalTag;
242
      Data mRemoteTag;
243
      Direction mDirection;
244
245
      DialogState mState;
246
      DialogStateEvent mStateEvent;
247
      int mStateCode;
248
249
      uint32_t mDuration;
250
      bool mHasDuration;
251
252
      DialogIdInfo mReplaces;
253
254
      NameAddr mReferredBy;
255
256
      NameAddrs mRouteSet;
257
258
      Participant mLocalParticipant;
259
      Participant mRemoteParticipant;
260
261
      // RFC7463 specific elements
262
      unsigned int mAppearance;
263
      bool mHasAppearance;
264
      bool mExclusive;
265
      bool mHasExclusive;
266
      std::list<DialogIdInfo> mReplacedDialogs;
267
      std::list<DialogIdInfo> mJoinedDialogs;
268
269
      std::multimap<Data, Data> mExtraDialogElements;
270
271
      friend class DialogInfoContents;
272
      EncodeStream& encodeParsed(EncodeStream& str, const Data& indent) const;
273
   };
274
275
   typedef std::list<Dialog> DialogList;
276
0
   const DialogList& getDialogs() const { checkParsed(); return mDialogs; }
277
   void addDialog(const Dialog& dialog);
278
   bool removeDialog(const Data& id);
279
0
   void clearDialogs() { checkParsed();  mDialogs.clear(); }
280
281
   static bool init();
282
   static const char* dialogInfoStateToString(const DialogInfoState& dialogInfoState);
283
   static DialogInfoState dialogInfoStateStringToEnum(const Data& dialogInfoStateString);
284
   static const char* dialogStateToString(const DialogState& dialogState);
285
   static DialogState dialogStateStringToEnum(const Data& dialogStateString);
286
   static const char* dialogStateEventToString(const DialogStateEvent& dialogStateEvent);
287
   static DialogStateEvent dialogStateEventStringToEnum(const Data& dialogStateEventString);
288
   static const char* directionToString(const Direction& direction);
289
   static Direction directionStringToEnum(const Data& directionString);
290
   static bool compareTag(const Data& tagName, const Data& compareToTagNoPrefix, const Data& namespacePrefix);
291
292
private:
293
294
   static EncodeStream& encodeNameAddrElement(EncodeStream& str, const char* elementName, const NameAddr& nameAddr);
295
   void parseDialog(XMLCursor& xml);
296
   static bool parseDialogIdInfo(XMLCursor& xml, Dialog::DialogIdInfo& dialogIdInfo);
297
   static bool parseUriValue(XMLCursor& xml, Uri& uri);
298
   static bool parseNameAddrElement(XMLCursor& xml, NameAddr& nameAddr);
299
300
   // Base DialogInfoContents data members
301
   Data mBaseDialogInfoNamespacePrefix;
302
   Data mSharedAppearanceDialogInfoNamespacePrefix;
303
   Data mIndent;
304
   Uri mEntity;
305
   uint32_t mVersion;
306
   DialogInfoState mDialogInfoState;
307
308
   DialogList mDialogs;
309
};
310
311
static bool invokeDialogInfoContentsInit = DialogInfoContents::init();
312
313
}
314
315
#endif
316
317
/* ====================================================================
318
*
319
* Copyright (c) 2016-2021 SIP Spectrum, Inc. www.sipspectrum.com
320
*
321
* Redistribution and use in source and binary forms, with or without
322
* modification, are permitted provided that the following conditions
323
* are met:
324
*
325
* 1. Redistributions of source code must retain the above copyright
326
*    notice, this list of conditions and the following disclaimer.
327
*
328
* 2. Redistributions in binary form must reproduce the above copyright
329
*    notice, this list of conditions and the following disclaimer in
330
*    the documentation and/or other materials provided with the
331
*    distribution.
332
*
333
* 3. Neither the name of the author(s) nor the names of any contributors
334
*    may be used to endorse or promote products derived from this software
335
*    without specific prior written permission.
336
*
337
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND
338
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
339
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
340
* ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
341
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
342
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
343
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
344
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
345
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
346
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
347
* SUCH DAMAGE.
348
*
349
* ====================================================================
350
*
351
*/
352
/*
353
* vi: set shiftwidth=3 expandtab:
354
*/