|
reSIProcate/repro
9694
|
00001 00002 #include "rutil/Logger.hxx" 00003 #include "rutil/ParseBuffer.hxx" 00004 #include "rutil/Lock.hxx" 00005 #include "resip/stack/Uri.hxx" 00006 00007 #include "repro/ConfigStore.hxx" 00008 00009 00010 using namespace resip; 00011 using namespace repro; 00012 using namespace std; 00013 00014 00015 #define RESIPROCATE_SUBSYSTEM Subsystem::REPRO 00016 00017 00018 ConfigStore::ConfigStore(AbstractDb& db): 00019 mDb(db) 00020 { 00021 AbstractDb::ConfigRecordList input = mDb.getAllConfigs(); 00022 for (AbstractDb::ConfigRecordList::const_iterator it = input.begin(); 00023 it != input.end(); it++) 00024 { 00025 mCachedConfigData[it->mDomain] = *it; 00026 } 00027 } 00028 00029 00030 ConfigStore::~ConfigStore() 00031 { 00032 } 00033 00034 00035 bool 00036 ConfigStore::addDomain(const resip::Data& domain, 00037 const int tlsPort ) 00038 { 00039 InfoLog( << "Add domain " << domain << " to config." ); 00040 00041 AbstractDb::ConfigRecord rec; 00042 rec.mDomain = domain; 00043 rec.mTlsPort = tlsPort; 00044 00045 if(!mDb.addConfig(buildKey(domain), rec)) 00046 { 00047 return false; 00048 } 00049 00050 { 00051 Lock lock(mMutex, VOCAL_WRITELOCK); 00052 mCachedConfigData[domain] = rec; 00053 } 00054 return true; 00055 } 00056 00057 00058 const ConfigStore::ConfigData& 00059 ConfigStore::getConfigs() const 00060 { 00061 // LOCKING NOTE: From an API perspective this method dangerous, but we know that the WebAdmin Thread is currently 00062 // the only thread requiring a WRITE lock and is the only thread calling this function, so 00063 // locking is not required 00064 return mCachedConfigData; 00065 } 00066 00067 00068 int 00069 ConfigStore::getTlsPort(const resip::Data& domain) 00070 { 00071 Lock lock(mMutex, VOCAL_READLOCK); 00072 ConfigData::const_iterator it = mCachedConfigData.find(domain); 00073 if(it != mCachedConfigData.end()) 00074 { 00075 return it->second.mTlsPort; 00076 } 00077 00078 return 0; 00079 } 00080 00081 00082 void 00083 ConfigStore::eraseDomain(const resip::Data& domain) 00084 { 00085 mDb.eraseConfig( buildKey(domain) ); 00086 { 00087 Lock lock(mMutex, VOCAL_WRITELOCK); 00088 mCachedConfigData.erase(domain); 00089 } 00090 } 00091 00092 00093 AbstractDb::Key 00094 ConfigStore::buildKey(const resip::Data& domain ) const 00095 { 00096 return domain; 00097 } 00098 00099 00100 /* ==================================================================== 00101 * The Vovida Software License, Version 1.0 00102 * 00103 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00104 * 00105 * Redistribution and use in source and binary forms, with or without 00106 * modification, are permitted provided that the following conditions 00107 * are met: 00108 * 00109 * 1. Redistributions of source code must retain the above copyright 00110 * notice, this list of conditions and the following disclaimer. 00111 * 00112 * 2. Redistributions in binary form must reproduce the above copyright 00113 * notice, this list of conditions and the following disclaimer in 00114 * the documentation and/or other materials provided with the 00115 * distribution. 00116 * 00117 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00118 * and "Vovida Open Communication Application Library (VOCAL)" must 00119 * not be used to endorse or promote products derived from this 00120 * software without prior written permission. For written 00121 * permission, please contact vocal@vovida.org. 00122 * 00123 * 4. Products derived from this software may not be called "VOCAL", nor 00124 * may "VOCAL" appear in their name, without prior written 00125 * permission of Vovida Networks, Inc. 00126 * 00127 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00128 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00129 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00130 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00131 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00132 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00133 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00134 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00135 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00136 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00137 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00138 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00139 * DAMAGE. 00140 * 00141 * ==================================================================== 00142 */
1.7.5.1