reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
InMemoryRegistrationDatabase.cxx
Go to the documentation of this file.
1#include <ctime>
2
4#include "rutil/Timer.hxx"
5#include "rutil/Logger.hxx"
7
8using namespace resip;
9
10#define RESIPROCATE_SUBSYSTEM Subsystem::DUM
11
13 mCheckExpiry(checkExpiry)
14{
15}
16
18{
19 for( database_map_t::const_iterator it = mDatabase.begin();
20 it != mDatabase.end(); it++)
21 {
22 delete it->second;
23 }
24 mDatabase.clear();
25}
26
27void
29 const ContactList& contacts)
30{
32 mDatabase[aor] = new ContactList(contacts);
33}
34
35void
37{
38 database_map_t::iterator i;
39
41 i = mDatabase.find(aor);
42 //DebugLog (<< "Removing registration bindings " << aor);
43 if (i != mDatabase.end())
44 {
45 if (i->second)
46 {
47 DebugLog (<< "Removed " << i->second->size() << " entries");
48 delete i->second;
49 // Setting this to 0 causes it to be removed when we unlock the AOR.
50 i->second = 0;
51 }
52 }
53}
54
55void
57{
58 container.clear();
60 for( database_map_t::const_iterator it = mDatabase.begin();
61 it != mDatabase.end(); it++)
62 {
63 container.push_back(it->first);
64 }
65}
66
67bool
69{
71 database_map_t::iterator i = findNotExpired(aor);
72 if (i == mDatabase.end() || i->second == 0)
73 {
74 return false;
75 }
76 return true;
77}
78
79void
81{
83
84 {
86 // This forces insertion if the record does not yet exist.
87 mDatabase[aor];
88 }
89
90 while (mLockedRecords.find(aor) != mLockedRecords.end())
91 {
92 mRecordUnlocked.wait(g2);
93 }
94
95 mLockedRecords.insert(aor);
96}
97
98void
100{
102
103 {
105 // If the pointer is null, we remove the record from the map.
106 database_map_t::iterator i = mDatabase.find(aor);
107
108 // The record must have been inserted when we locked it in the first place
109 resip_assert (i != mDatabase.end());
110
111 if (i->second == 0)
112 {
113 mDatabase.erase(i);
114 }
115 }
116
117 mLockedRecords.erase(aor);
118 mRecordUnlocked.notify_all();
119}
120
123 const ContactInstanceRecord& rec)
124{
125 ContactList *contactList = 0;
126
127 {
129
130 database_map_t::iterator i;
131 i = mDatabase.find(aor);
132 if (i == mDatabase.end() || i->second == 0)
133 {
134 contactList = new ContactList();
135 mDatabase[aor] = contactList;
136 }
137 else
138 {
139 contactList = i->second;
140 }
141
142 }
143
144 resip_assert(contactList);
145
146 ContactList::iterator j;
147
148 // See if the contact is already present. We use URI matching rules here.
149 for (j = contactList->begin(); j != contactList->end(); j++)
150 {
151 if (*j == rec)
152 {
153 *j=rec;
154 return CONTACT_UPDATED;
155 }
156 }
157
158 // This is a new contact, so we add it to the list.
159 contactList->push_back(rec);
160 return CONTACT_CREATED;
161}
162
163void
165 const ContactInstanceRecord& rec)
166{
167 ContactList *contactList = 0;
168
169 {
171
172 database_map_t::iterator i;
173 i = mDatabase.find(aor);
174 if (i == mDatabase.end() || i->second == 0)
175 {
176 return;
177 }
178 contactList = i->second;
179 }
180
181 ContactList::iterator j;
182
183 // See if the contact is present. We use URI matching rules here.
184 for (j = contactList->begin(); j != contactList->end(); j++)
185 {
186 if (*j == rec)
187 {
188 contactList->erase(j);
189 if (contactList->empty())
190 {
191 removeAor(aor);
192 }
193 return;
194 }
195 }
196}
197
198void
200{
202 database_map_t::iterator i = findNotExpired(aor);
203 if (i == mDatabase.end() || i->second == 0)
204 {
205 container.clear();
206 return;
207 }
208 container = *(i->second);
209}
210
212{
213protected:
215public:
217 {
218 now = Timer::getTimeSecs();
219 }
220 bool operator () (const ContactInstanceRecord& rec)
221 {
222 return expired(rec);
223 }
225 {
226 if(rec.mRegExpires <= now)
227 {
228 DebugLog(<< "ContactInstanceRecord expired: " << rec.mContact);
229 return true;
230 }
231 return false;
232 }
233};
234
236{
237 RemoveIfExpired rei;
238 return rei.expired(rec);
239}
240
241InMemoryRegistrationDatabase::database_map_t::iterator
243{
244 database_map_t::iterator i;
245 i = mDatabase.find(aor);
246 if (i == mDatabase.end() || i->second == 0)
247 {
248 return i;
249 }
250 if(mCheckExpiry)
251 {
252 ContactList *contacts = i->second;
253#ifdef __SUNPRO_CC
254 contacts->remove_if(expired);
255#else
256 contacts->remove_if(RemoveIfExpired());
257#endif
258 }
259 return i;
260}
261
262/* ====================================================================
263 * The Vovida Software License, Version 1.0
264 *
265 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
266 *
267 * Redistribution and use in source and binary forms, with or without
268 * modification, are permitted provided that the following conditions
269 * are met:
270 *
271 * 1. Redistributions of source code must retain the above copyright
272 * notice, this list of conditions and the following disclaimer.
273 *
274 * 2. Redistributions in binary form must reproduce the above copyright
275 * notice, this list of conditions and the following disclaimer in
276 * the documentation and/or other materials provided with the
277 * distribution.
278 *
279 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
280 * and "Vovida Open Communication Application Library (VOCAL)" must
281 * not be used to endorse or promote products derived from this
282 * software without prior written permission. For written
283 * permission, please contact vocal@vovida.org.
284 *
285 * 4. Products derived from this software may not be called "VOCAL", nor
286 * may "VOCAL" appear in their name, without prior written
287 * permission of Vovida Networks, Inc.
288 *
289 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
290 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
291 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
292 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
293 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
294 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
295 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
296 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
297 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
298 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
299 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
300 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
301 * DAMAGE.
302 *
303 * ====================================================================
304 *
305 * This software consists of voluntary contributions made by Vovida
306 * Networks, Inc. and many individuals on behalf of Vovida Networks,
307 * Inc. For more information on Vovida Networks, Inc., please see
308 * <http://www.vovida.org/>.
309 *
310 */
bool expired(const ContactInstanceRecord &rec)
#define DebugLog(args_)
Definition Logger.hxx:128
#define resip_assert(x)
This file needs to work for both C and C++ code.
bool expired(const ContactInstanceRecord &rec)
A single contact record, bound to an Aor during registration.
virtual void addAor(const Uri &aor, const ContactList &contacts)
virtual void getAors(UriList &container)
return all the AOR in the DB
virtual void getContacts(const Uri &aor, ContactList &container)
database_map_t::iterator findNotExpired(const Uri &aor)
Find aor in mDatabase Before returning the iterator pointing to aor, delete all expired contacts.
virtual update_status_t updateContact(const resip::Uri &aor, const ContactInstanceRecord &rec)
virtual void removeContact(const Uri &aor, const ContactInstanceRecord &rec)
static uint64_t getTimeSecs()
Returns the current clock time in seconds.
Definition Timer.hxx:78
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
Definition Uri.hxx:22
dcm! – add UnusedChecking(_enum) below;
std::unique_lock< Mutex > Lock
A convenience class to lock a Lockable (such as a Mutex) on object creation, and unlock on destructio...
Definition Lock.hxx:28
unsigned long long uint64_t
Definition Stun.hxx:39
std::list< ContactInstanceRecord > ContactList