|
signon
8.40
|
00001 /* 00002 * This file is part of signon 00003 * 00004 * Copyright (C) 2009-2011 Nokia Corporation. 00005 * 00006 * Contact: Aurel Popirtac <ext-aurel.popirtac@nokia.com> 00007 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public License 00011 * version 2.1 as published by the Free Software Foundation. 00012 * 00013 * This library is distributed in the hope that it will be useful, but 00014 * WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00021 * 02110-1301 USA 00022 */ 00023 00024 #include "signonsessioncoretools.h" 00025 00026 #include <QDebug> 00027 #include "signond-common.h" 00028 00029 using namespace SignonDaemonNS; 00030 00031 QVariantMap SignonDaemonNS::mergeVariantMaps(const QVariantMap &map1, 00032 const QVariantMap &map2) 00033 { 00034 if (map1.isEmpty()) return map2; 00035 if (map2.isEmpty()) return map1; 00036 00037 QVariantMap map = map1; 00038 //map2 values will overwrite map1 values for the same keys. 00039 QMapIterator<QString, QVariant> it(map2); 00040 while (it.hasNext()) { 00041 it.next(); 00042 if (map.contains(it.key())) 00043 map.remove(it.key()); 00044 } 00045 return map.unite(map2); 00046 } 00047 00048 /* --------------------- StoreOperation ---------------------- */ 00049 00050 StoreOperation::StoreOperation(const StoreType type): 00051 m_storeType(type) 00052 { 00053 } 00054 00055 StoreOperation::StoreOperation(const StoreOperation &src): 00056 m_storeType(src.m_storeType), 00057 m_info(src.m_info), 00058 m_authMethod(src.m_authMethod), 00059 m_blobData(src.m_blobData) 00060 { 00061 } 00062 00063 StoreOperation::~StoreOperation() 00064 { 00065 } 00066 00067 /* --------------------- RequestData ---------------------- */ 00068 00069 RequestData::RequestData(const QDBusConnection &conn, 00070 const QDBusMessage &msg, 00071 const QVariantMap ¶ms, 00072 const QString &mechanism, 00073 const QString &cancelKey): 00074 m_conn(conn), 00075 m_msg(msg), 00076 m_params(params), 00077 m_mechanism(mechanism), 00078 m_cancelKey(cancelKey) 00079 { 00080 } 00081 00082 RequestData::RequestData(const RequestData &other): 00083 m_conn(other.m_conn), 00084 m_msg(other.m_msg), 00085 m_params(other.m_params), 00086 m_mechanism(other.m_mechanism), 00087 m_cancelKey(other.m_cancelKey) 00088 { 00089 } 00090 00091 RequestData::~RequestData() 00092 { 00093 } 00094 00095 /* --------------------- AuthCoreCache ---------------------- */ 00096 00097 AuthCoreCache *AuthCoreCache::m_instance = 0; 00098 00099 AuthCoreCache::AuthCache::AuthCache() 00100 { 00101 } 00102 00103 AuthCoreCache::AuthCache::~AuthCache() 00104 { 00105 } 00106 00107 bool AuthCoreCache::AuthCache::isEmpty() const 00108 { 00109 return (m_password.isEmpty() && m_blobData.isEmpty()); 00110 } 00111 00112 AuthCoreCache::AuthCoreCache(QObject *parent): 00113 QObject(parent) 00114 { 00115 } 00116 00117 AuthCoreCache::~AuthCoreCache() 00118 { 00119 clear(); 00120 m_instance = 0; 00121 } 00122 00123 AuthCoreCache *AuthCoreCache::instance(QObject *parent) 00124 { 00125 if (m_instance == 0) 00126 m_instance = new AuthCoreCache(parent); 00127 00128 return m_instance; 00129 } 00130 00131 AuthCache *AuthCoreCache::data(const IdentityId id) const 00132 { 00133 return m_cache.value(id, 0); 00134 } 00135 00136 void AuthCoreCache::insert(const CacheId &id, AuthCache *cache) 00137 { 00138 if (cache == 0) return; 00139 00140 AuthCache *data = m_cache.take(id.first); 00141 00142 if ((data != 0) && data->isEmpty()) { 00143 delete data; 00144 data = 0; 00145 } 00146 00147 if (data == 0) { 00148 m_cache.insert(id.first, cache); 00149 m_cachingSessionsMethods[id.first] = AuthMethods() << id.second; 00150 } else { 00151 if (cache->m_username.isEmpty()) 00152 cache->m_username = data->m_username; 00153 if (cache->m_password.isEmpty()) 00154 cache->m_password = data->m_password; 00155 00156 cache->m_blobData = 00157 mergeVariantMaps(data->m_blobData, cache->m_blobData); 00158 00159 delete data; 00160 m_cache.insert(id.first, cache); 00161 00162 AuthMethods cachingSessionsMethods = m_cachingSessionsMethods[id.first]; 00163 if (!cachingSessionsMethods.contains(id.second)) 00164 cachingSessionsMethods.append(id.second); 00165 } 00166 } 00167 00168 void AuthCoreCache::authSessionDestroyed(const CacheId &id) 00169 { 00170 AuthCache *data = m_cache.value(id.first, 0); 00171 if (data != 0) { 00172 AuthMethods authMethods = m_cachingSessionsMethods[id.first]; 00173 authMethods.removeOne(id.second); 00174 if (authMethods.isEmpty()) { 00175 delete m_cache.take(id.first); 00176 (void)m_cachingSessionsMethods.take(id.first); 00177 } 00178 } 00179 } 00180 00181 void AuthCoreCache::clear() 00182 { 00183 QList<IdentityId> keys = m_cache.keys(); 00184 foreach (IdentityId key, keys) 00185 delete m_cache.take(key); 00186 00187 m_cachingSessionsMethods.clear(); 00188 }