reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
GenericPidfContents.hxx
Go to the documentation of this file.
1#if !defined(RESIP_GENERICPIDFCONTENTS_HXX)
2#define RESIP_GENERICPIDFCONTENTS_HXX
3
4#include <map>
5#include <list>
6
8#include "rutil/Data.hxx"
9#include "rutil/HashMap.hxx"
11#include "resip/stack/Uri.hxx"
14
15namespace resip
16{
17
18class XMLCursor;
19
26{
27public:
28
30
32 GenericPidfContents(const Mime& contentType);
34 GenericPidfContents(const HeaderFieldValue& hfv, const Mime& contentType);
36 virtual ~GenericPidfContents();
38
42 virtual Contents* clone() const;
43 static const Mime& getStaticType();
44 virtual EncodeStream& encodeParsed(EncodeStream& str) const;
45 virtual void parse(ParseBuffer& pb);
46
47 void setEntity(const Uri& entity);
48 const Uri& getEntity() const;
49
50 void addNamespace(const Data& uri, const Data& prefix);
51 // first is Uri, second is prefix (which includes a trailing ":"). In document
52 // order; keyed hash as the Uris come from the network (see XMLCursor::AttributeMap
53 // and KeyedDataHash).
55 const NamespaceMap& getNamespaces() const { checkParsed(); return mNamespaces; }
56 // Note: you set the RootPidfNamesapces prefix by adding the generic Pidf
57 // namespace urn:ietf:params:xml:ns:pidf via addNamespace
58 const Data& getRootPidfNamespacePrefix() const { checkParsed(); return mRootPidfNamespacePrefix; }
59
60 class Node;
61 typedef std::list<Node*> NodeList;
62 class Node
63 {
64 public:
67 // Same type as XMLCursor::AttributeMap, which explains the keyed hash
72
73 void copy(const Node& rhs, HashMap<Data, Data, KeyedDataHash>* namespacePrefixCorrections);
74
76 EncodeStream& encode(EncodeStream& str, Data indent) const;
77 };
78 const NodeList& getRootNodes() const { checkParsed(); return mRootNodes; }
79 void setRootNodes(const NodeList& nodeList);
80
81 // Helpers for users of this class
82 static const Data& getSubNodeValue(Node* node, const Data& tag);
84 static Data generateTimestampData(time_t datetime);
85
86 // You should be adding the namespace first manually if you want a custom prefix
87 void setSimplePresenceTupleNode(const Data& id,
88 bool online,
89 const Data& timestamp = Data::Empty,
90 const Data& note = Data::Empty,
91 const Data& contact = Data::Empty,
92 const Data& contactPriority = Data::Empty);
93
94 // Use these methods to get simple presence info from a document that only contains one Tuple.
95 // If multiple tuples are in this document, then these API's will only return data from the first
96 // Tuple in the document. If you require access to the simple presence of all tuples, then use the
97 // getSimplePresenceList API below.
99 const bool getSimplePresenceOnline();
104
116 typedef std::list<SimplePresenceInfo*> SimplePresenceInfoList; // Use pointers to avoid copying when adding
117 const SimplePresenceInfoList& getSimplePresenceList() { checkParsed(); extractSimplePresenceInfo(); return mSimplePresenceInfoList; }
118
119 static bool init();
120
121 // combine pidfs
122 bool merge(const GenericPidfContents& other);
123
124private:
125
126 NamespaceMap mNamespaces;
127 Data mRootPidfNamespacePrefix; // includes trailing ":"
128 Uri mEntity;
129
130 // Simple Presence Info
131 SimplePresenceInfoList mSimplePresenceInfoList;
132 bool mSimplePresenceExtracted;
133
134 NodeList mRootNodes;
135 void parseChildren(XMLCursor& xml, NodeList& nodeList);
136 void cleanupNodeMemory(NodeList& nodeList);
137 void reset();
138 bool mergeNoCheckParse(const GenericPidfContents& other);
139 void extractSimplePresenceInfo();
140 void clearSimplePresenceInfo();
141};
142
143EncodeStream& operator<<(EncodeStream& strm, const GenericPidfContents::SimplePresenceInfo& tuple);
144
146
147}
148
149#endif
150
151/* ====================================================================
152*
153* Copyright (c) 2015-2026 SIP Spectrum, Inc. All rights reserved.
154*
155* Redistribution and use in source and binary forms, with or without
156* modification, are permitted provided that the following conditions
157* are met:
158*
159* 1. Redistributions of source code must retain the above copyright
160* notice, this list of conditions and the following disclaimer.
161*
162* 2. Redistributions in binary form must reproduce the above copyright
163* notice, this list of conditions and the following disclaimer in
164* the documentation and/or other materials provided with the
165* distribution.
166*
167* 3. Neither the name of the author(s) nor the names of any contributors
168* may be used to endorse or promote products derived from this software
169* without specific prior written permission.
170*
171* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND
172* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
173* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
174* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
175* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
176* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
177* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
178* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
179* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
180* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
181* SUCH DAMAGE.
182*
183* ====================================================================
184*
185*/
186/*
187* vi: set shiftwidth=3 expandtab:
188*/
Wraps your platform's implementation of hash_map, hash_multimap, and hash_set.
Base class for all SIP body types.
Definition Contents.hxx:51
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
static const Data Empty
Constant that represents a zero-length data.
Definition Data.hxx:882
EncodeStream & encode(EncodeStream &str, Data indent) const
EncodeStream & encodeAttributes(EncodeStream &str) const
void copy(const Node &rhs, HashMap< Data, Data, KeyedDataHash > *namespacePrefixCorrections)
LinkedHashMap< Data, Data, KeyedDataHash > AttributeMap
SIP body type for holding PIDF contents (MIME content-type application/pidf+xml).
void setRootNodes(const NodeList &nodeList)
virtual GenericPidfContents & operator=(const GenericPidfContents &rhs)
static const Mime & getStaticType()
std::list< SimplePresenceInfo * > SimplePresenceInfoList
const Data & getSimplePresenceContactPriority()
RESIP_HeapCount(GenericPidfContents)
void setSimplePresenceTupleNode(const Data &id, bool online, const Data &timestamp=Data::Empty, const Data &note=Data::Empty, const Data &contact=Data::Empty, const Data &contactPriority=Data::Empty)
const NodeList & getRootNodes() const
virtual Contents * clone() const
duplicate an GenericPidfContents object
virtual void parse(ParseBuffer &pb)
static const GenericPidfContents Empty
virtual EncodeStream & encodeParsed(EncodeStream &str) const
const SimplePresenceInfoList & getSimplePresenceList()
static Data generateTimestampData(time_t datetime)
LinkedHashMap< Data, Data, KeyedDataHash > NamespaceMap
const NamespaceMap & getNamespaces() const
void addNamespace(const Data &uri, const Data &prefix)
static const Data & getSubNodeValue(Node *node, const Data &tag)
void setEntity(const Uri &entity)
const Data & getRootPidfNamespacePrefix() const
bool merge(const GenericPidfContents &other)
void checkParsed() const
A hash map that iterates in insertion order, so a container filled while parsing (eg.
Represents the "media-type" element in the RFC 3261 grammar.
Definition Mime.hxx:20
Provides string-parsing functionality with protection from buffer overflow.
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
Definition Uri.hxx:22
dcm! – add UnusedChecking(_enum) below;
EncodeStream & operator<<(EncodeStream &strm, const BaseException &e)
static bool invokeGenericPidfContentsInit
#define EncodeStream