/src/resiprocate/resip/stack/GenericPidfContents.hxx
Line | Count | Source |
1 | | #if !defined(RESIP_GENERICPIDFCONTENTS_HXX) |
2 | | #define RESIP_GENERICPIDFCONTENTS_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 | | #include "resip/stack/QValue.hxx" |
13 | | |
14 | | namespace resip |
15 | | { |
16 | | |
17 | | class XMLCursor; |
18 | | |
19 | | /** |
20 | | SIP body type for holding PIDF contents (MIME content-type application/pidf+xml). |
21 | | This version is used to be able to extract and manipulate all Pidf contents and |
22 | | contained extensions (ie: rpid, data-model, cipid, etc.) in a generic manner. |
23 | | */ |
24 | | class GenericPidfContents : public Contents |
25 | | { |
26 | | public: |
27 | | |
28 | | static const GenericPidfContents Empty; |
29 | | |
30 | | RESIP_HeapCount(GenericPidfContents); |
31 | | GenericPidfContents(const Mime& contentType); |
32 | | GenericPidfContents(); |
33 | | GenericPidfContents(const HeaderFieldValue& hfv, const Mime& contentType); |
34 | | GenericPidfContents(const GenericPidfContents& rhs); |
35 | | virtual ~GenericPidfContents(); |
36 | | virtual GenericPidfContents& operator=(const GenericPidfContents& rhs); |
37 | | |
38 | | /** @brief duplicate an GenericPidfContents object |
39 | | @return pointer to a new GenericPidfContents object |
40 | | **/ |
41 | | virtual Contents* clone() const; |
42 | | static const Mime& getStaticType(); |
43 | | virtual EncodeStream& encodeParsed(EncodeStream& str) const; |
44 | | virtual void parse(ParseBuffer& pb); |
45 | | |
46 | | void setEntity(const Uri& entity); |
47 | | const Uri& getEntity() const; |
48 | | |
49 | | void addNamespace(const Data& uri, const Data& prefix); |
50 | | typedef HashMap<Data, Data> NamespaceMap; // first is Uri, second is prefix (which includes a trailing ":") |
51 | 0 | const NamespaceMap& getNamespaces() const { checkParsed(); return mNamespaces; } |
52 | | // Note: you set the RootPidfNamesapces prefix by adding the generic Pidf |
53 | | // namespace urn:ietf:params:xml:ns:pidf via addNamespace |
54 | 0 | const Data& getRootPidfNamespacePrefix() const { checkParsed(); return mRootPidfNamespacePrefix; } |
55 | | |
56 | | class Node; |
57 | | typedef std::list<Node*> NodeList; |
58 | | class Node |
59 | | { |
60 | | public: |
61 | | Data mNamespacePrefix; |
62 | | Data mTag; |
63 | | typedef HashMap<Data, Data> AttributeMap; |
64 | | AttributeMap mAttributes; |
65 | | Data mValue; |
66 | | NodeList mChildren; |
67 | | |
68 | | void copy(const Node& rhs, HashMap<Data, Data>* namespacePrefixCorrections); |
69 | | |
70 | | EncodeStream& encodeAttributes(EncodeStream& str) const; |
71 | | EncodeStream& encode(EncodeStream& str, Data indent) const; |
72 | | }; |
73 | 0 | const NodeList& getRootNodes() const { checkParsed(); return mRootNodes; } |
74 | | void setRootNodes(const NodeList& nodeList); |
75 | | |
76 | | // Helpers for users of this class |
77 | | static const Data& getSubNodeValue(Node* node, const Data& tag); |
78 | | static Data generateNowTimestampData(); |
79 | | static Data generateTimestampData(time_t datetime); |
80 | | |
81 | | // You should be adding the namespace first manually if you want a custom prefix |
82 | | void setSimplePresenceTupleNode(const Data& id, |
83 | | bool online, |
84 | | const Data& timestamp = Data::Empty, |
85 | | const Data& note = Data::Empty, |
86 | | const Data& contact = Data::Empty, |
87 | | const Data& contactPriority = Data::Empty); |
88 | | |
89 | | // Use these methods to get simple presence info from a document that only contains one Tuple. |
90 | | // If multiple tuples are in this document, then these API's will only return data from the first |
91 | | // Tuple in the document. If you require access to the simple presence of all tuples, then use the |
92 | | // getSimplePresenceList API below. |
93 | | const Data& getSimplePresenceTupleId(); |
94 | | const bool getSimplePresenceOnline(); |
95 | | const Data& getSimplePresenceTimestamp(); |
96 | | const Data& getSimplePresenceNote(); |
97 | | const Data& getSimplePresenceContact(); |
98 | | const Data& getSimplePresenceContactPriority(); |
99 | | |
100 | | class SimplePresenceInfo |
101 | | { |
102 | | public: |
103 | 0 | SimplePresenceInfo() : mOnline(false) {} |
104 | | Data mTupleId; |
105 | | bool mOnline; |
106 | | Data mTimestamp; |
107 | | Data mNote; |
108 | | Data mContact; |
109 | | Data mContactPriority; |
110 | | }; |
111 | | typedef std::list<SimplePresenceInfo*> SimplePresenceInfoList; // Use pointers to avoid copying when adding |
112 | 0 | const SimplePresenceInfoList& getSimplePresenceList() { checkParsed(); extractSimplePresenceInfo(); return mSimplePresenceInfoList; } |
113 | | |
114 | | static bool init(); |
115 | | |
116 | | // combine pidfs |
117 | | bool merge(const GenericPidfContents& other); |
118 | | |
119 | | private: |
120 | | |
121 | | NamespaceMap mNamespaces; |
122 | | Data mRootPidfNamespacePrefix; // includes trailing ":" |
123 | | Uri mEntity; |
124 | | |
125 | | // Simple Presence Info |
126 | | SimplePresenceInfoList mSimplePresenceInfoList; |
127 | | bool mSimplePresenceExtracted; |
128 | | |
129 | | NodeList mRootNodes; |
130 | | void parseChildren(XMLCursor& xml, NodeList& nodeList); |
131 | | void cleanupNodeMemory(NodeList& nodeList); |
132 | | void reset(); |
133 | | bool mergeNoCheckParse(const GenericPidfContents& other); |
134 | | void extractSimplePresenceInfo(); |
135 | | void clearSimplePresenceInfo(); |
136 | | }; |
137 | | |
138 | | EncodeStream& operator<<(EncodeStream& strm, const GenericPidfContents::SimplePresenceInfo& tuple); |
139 | | |
140 | | static bool invokeGenericPidfContentsInit = GenericPidfContents::init(); |
141 | | |
142 | | } |
143 | | |
144 | | #endif |
145 | | |
146 | | /* ==================================================================== |
147 | | * |
148 | | * Copyright (c) 2015-2025 SIP Spectrum, Inc. All rights reserved. |
149 | | * |
150 | | * Redistribution and use in source and binary forms, with or without |
151 | | * modification, are permitted provided that the following conditions |
152 | | * are met: |
153 | | * |
154 | | * 1. Redistributions of source code must retain the above copyright |
155 | | * notice, this list of conditions and the following disclaimer. |
156 | | * |
157 | | * 2. Redistributions in binary form must reproduce the above copyright |
158 | | * notice, this list of conditions and the following disclaimer in |
159 | | * the documentation and/or other materials provided with the |
160 | | * distribution. |
161 | | * |
162 | | * 3. Neither the name of the author(s) nor the names of any contributors |
163 | | * may be used to endorse or promote products derived from this software |
164 | | * without specific prior written permission. |
165 | | * |
166 | | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND |
167 | | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
168 | | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
169 | | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE |
170 | | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
171 | | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
172 | | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
173 | | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
174 | | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
175 | | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
176 | | * SUCH DAMAGE. |
177 | | * |
178 | | * ==================================================================== |
179 | | * |
180 | | */ |
181 | | /* |
182 | | * vi: set shiftwidth=3 expandtab: |
183 | | */ |