reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
StaticRegStore.cxx
Go to the documentation of this file.
1
2#include "rutil/Logger.hxx"
4#include "rutil/Lock.hxx"
5
7
8using namespace resip;
9using namespace repro;
10using namespace std;
11
12
13#define RESIPROCATE_SUBSYSTEM Subsystem::REPRO
14
16 mDb(db)
17{
19 while (!key.empty())
20 {
22
23 try
24 {
25 Uri aor(rec.mAor);
26 NameAddr contact(rec.mContact);
27 NameAddrs paths;
28 Data path;
29 ParseBuffer pb(rec.mPath);
30 const char* anchor = pb.position();
31 while(!pb.eof())
32 {
34 pb.data(path, anchor);
35 paths.push_back(NameAddr(path));
36 if(!pb.eof()) pb.skipChar(); // skip over comma
37 anchor = pb.position();
38 }
39
40 mStaticRegList[make_pair(aor, contact.uri())] = StaticRegRecord(aor, contact, paths);
41 }
42 catch(resip::ParseBuffer::Exception& e)
43 {
44 // This should never happen, since the format should be verified before writing to DB
45 ErrLog(<<"Failed to load a static registration due to parse error: " << e);
46 }
47
48 key = mDb.nextStaticRegKey();
49 }
50}
51
52
56
57
58bool
60 const resip::NameAddr& contact,
61 const resip::NameAddrs& path)
62{
63 Data aorData(Data::from(aor));
64 Data contactData(Data::from(contact));
65
66 // Add new Db Record
67 Key addKey = buildKey(aorData, contactData);
69 rec.mAor = aorData;
70 rec.mContact = contactData;
71 NameAddrs::const_iterator it = path.begin();
72 for(; it != path.end(); it++)
73 {
74 if(it != path.begin())
75 {
76 rec.mPath += ",";
77 }
78 rec.mPath += Data::from(*it);
79 }
80
81 InfoLog( << "Add StaticReg: key=" << addKey);
82
83 if(!mDb.addStaticReg(addKey, rec))
84 {
85 return false;
86 }
87
88 Key removeKey;
89 {
90 WriteLock lock(mMutex);
91 std::pair<Uri, Uri> mapKey = make_pair(aor, contact.uri());
92 StaticRegRecordMap::iterator it = mStaticRegList.find(mapKey);
93 if(it != mStaticRegList.end())
94 {
95 // Exists already (Uri equalitiy for both aor and Uri portion of contact)- updatedb by removing
96 removeKey = buildKey(Data::from(it->second.mAor), Data::from(it->second.mContact));
97
98 // Update Map
99 it->second.mAor = aor;
100 it->second.mContact = contact;
101 it->second.mPath = path;
102 }
103 else
104 {
105 mStaticRegList[mapKey] = StaticRegRecord(aor, contact, path);
106 }
107 }
108
109 // Do DB Work outside of local lock
110 if(!removeKey.empty())
111 {
112 // Erase old DB record
113 mDb.eraseStaticReg(removeKey);
114 }
115
116 return true;
117}
118
119
120void
122 const resip::NameAddr& contact)
123{
124 Key removeKey;
125 {
126 WriteLock lock(mMutex);
127 StaticRegRecordMap::iterator it = mStaticRegList.find(make_pair(aor, contact.uri()));
128 if(it != mStaticRegList.end())
129 {
130 // Exists (Uri equalitiy for both aor and Uri portion of contact)
131 removeKey = buildKey(Data::from(it->second.mAor), Data::from(it->second.mContact));
132
133 // Erase from local storage
134 mStaticRegList.erase(it);
135 }
136 }
137
138 if(!removeKey.empty())
139 {
140 // Erase DB record
141 mDb.eraseStaticReg(removeKey);
142 }
143}
144
145
147StaticRegStore::buildKey(const resip::Data& aor,
148 const resip::Data& contact) const
149{
150 Data pKey = aor+":"+contact;
151 return pKey;
152}
153
154
155/* ====================================================================
156 * The Vovida Software License, Version 1.0
157 *
158 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
159 *
160 * Redistribution and use in source and binary forms, with or without
161 * modification, are permitted provided that the following conditions
162 * are met:
163 *
164 * 1. Redistributions of source code must retain the above copyright
165 * notice, this list of conditions and the following disclaimer.
166 *
167 * 2. Redistributions in binary form must reproduce the above copyright
168 * notice, this list of conditions and the following disclaimer in
169 * the documentation and/or other materials provided with the
170 * distribution.
171 *
172 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
173 * and "Vovida Open Communication Application Library (VOCAL)" must
174 * not be used to endorse or promote products derived from this
175 * software without prior written permission. For written
176 * permission, please contact vocal@vovida.org.
177 *
178 * 4. Products derived from this software may not be called "VOCAL", nor
179 * may "VOCAL" appear in their name, without prior written
180 * permission of Vovida Networks, Inc.
181 *
182 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
183 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
184 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
185 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
186 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
187 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
188 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
189 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
190 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
191 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
192 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
193 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
194 * DAMAGE.
195 *
196 * ====================================================================
197 */
#define InfoLog(args_)
Definition Logger.hxx:131
#define ErrLog(args_)
Definition Logger.hxx:137
virtual Key nextStaticRegKey()
virtual void eraseStaticReg(const Key &key)
virtual Key firstStaticRegKey()
virtual bool addStaticReg(const Key &key, const StaticRegRecord &rec)
virtual StaticRegRecord getStaticReg(const Key &key) const
bool addStaticReg(const resip::Uri &aor, const resip::NameAddr &contact, const resip::NameAddrs &path)
StaticRegStore(AbstractDb &db)
void eraseStaticReg(const resip::Uri &aor, const resip::NameAddr &contact)
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
bool empty() const noexcept
Checks whether the Data is empty.
Definition Data.hxx:591
static Data from(const T &x)
Converts from arbitrary other type to Data.
Definition Data.hxx:398
Represents the "name-addr" and the "addr-spec" elements in the RFC 3261 grammar.
Definition NameAddr.hxx:19
Provides string-parsing functionality with protection from buffer overflow.
CurrentPosition skipToChar(char c)
CurrentPosition position() const
CurrentPosition skipChar()
void data(Data &data, const char *start) const
make the passed in data share memory with the buffer (uses Data::Share)
iterator end()
Returns an iterator pointing to the last header field value.
iterator begin()
Returns an iterator pointing to the first header field value.
void push_back(const T &t)
Inserts a header field value at the back of this container.
static const char * COMMA
Definition Symbols.hxx:35
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
Definition Uri.hxx:22
This Class is used to implement a primitive form of RPC using loose XML formatting.
dcm! – add UnusedChecking(_enum) below;