reSIProcate/repro  9694
UserStore.cxx
Go to the documentation of this file.
00001 
00002 
00003 #include <cassert>
00004 
00005 #include "rutil/Data.hxx"
00006 #include "rutil/MD5Stream.hxx"
00007 #include "rutil/DataStream.hxx"
00008 #include "resip/stack/Symbols.hxx"
00009 #include "rutil/Logger.hxx"
00010 #include "resip/stack/TransactionUser.hxx"
00011 #include "resip/dum/UserAuthInfo.hxx"
00012 
00013 #include "repro/UserStore.hxx"
00014 #include "repro/AbstractDb.hxx"
00015 #include "rutil/WinLeakCheck.hxx"
00016 
00017 
00018 using namespace resip;
00019 using namespace repro;
00020 using namespace std;
00021 
00022 #define RESIPROCATE_SUBSYSTEM Subsystem::REPRO
00023 
00024 UserStore::UserStore(AbstractDb& db ):
00025    mDb(db)
00026 { 
00027 }
00028 
00029 UserStore::~UserStore()
00030 { 
00031 }
00032 
00033 
00034 AbstractDb::UserRecord
00035 UserStore::getUserInfo( const Key& key ) const
00036 {
00037    return mDb.getUser(key);
00038 }
00039 
00040 
00041 Data 
00042 UserStore::getUserAuthInfo(  const resip::Data& user, 
00043                              const resip::Data& realm ) const
00044 {
00045    Key key =  buildKey(user, realm);
00046    return mDb.getUserAuthInfo( key );
00047 }
00048 
00049 
00050 bool 
00051 UserStore::addUser( const Data& username,
00052                     const Data& domain,
00053                     const Data& realm,
00054                     const Data& password, 
00055                     bool  applyA1HashToPassword,
00056                     const Data& fullName, 
00057                     const Data& emailAddress )
00058 {
00059    AbstractDb::UserRecord rec;
00060    rec.user = username;
00061    rec.domain = domain;
00062    rec.realm = realm;
00063    if(applyA1HashToPassword)
00064    {
00065       MD5Stream a1;
00066       a1 << username
00067          << Symbols::COLON
00068          << realm
00069          << Symbols::COLON
00070          << password;
00071       a1.flush();
00072       rec.passwordHash = a1.getHex();
00073    }
00074    else
00075    {
00076       rec.passwordHash = password;
00077    }
00078    rec.name = fullName;
00079    rec.email = emailAddress;
00080    rec.forwardAddress = Data::Empty;
00081 
00082    return mDb.addUser( buildKey(username,domain), rec);
00083 }
00084 
00085 
00086 void 
00087 UserStore::eraseUser( const Key& key )
00088 { 
00089    mDb.eraseUser( key );
00090 }
00091 
00092 bool
00093 UserStore::updateUser( const Key& originalKey, 
00094                        const resip::Data& user, 
00095                        const resip::Data& domain, 
00096                        const resip::Data& realm, 
00097                        const resip::Data& password, 
00098                        bool  applyA1HashToPassword,
00099                        const resip::Data& fullName,
00100                        const resip::Data& emailAddress )
00101 {
00102    Key newkey = buildKey(user, domain);
00103    
00104    bool ret = addUser(user, domain, realm, password, applyA1HashToPassword, fullName, emailAddress);
00105    if ( newkey != originalKey )
00106    {
00107       eraseUser(originalKey);
00108    }
00109    return ret;
00110 }
00111 
00112 
00113 UserStore::Key
00114 UserStore::getFirstKey()
00115 {
00116    return mDb.firstUserKey();
00117 }
00118 
00119 
00120 UserStore::Key
00121 UserStore::getNextKey()
00122 {
00123    return mDb.nextUserKey();
00124 }
00125 
00126 
00127 UserStore::Key
00128 UserStore::buildKey( const resip::Data& user, 
00129                      const resip::Data& realm) const
00130 {
00131    Data ret = user + Data("@") + realm;
00132    return ret;
00133 }
00134 
00135 
00136 
00137 
00138 /* ====================================================================
00139  * The Vovida Software License, Version 1.0 
00140  * 
00141  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00142  * 
00143  * Redistribution and use in source and binary forms, with or without
00144  * modification, are permitted provided that the following conditions
00145  * are met:
00146  * 
00147  * 1. Redistributions of source code must retain the above copyright
00148  *    notice, this list of conditions and the following disclaimer.
00149  * 
00150  * 2. Redistributions in binary form must reproduce the above copyright
00151  *    notice, this list of conditions and the following disclaimer in
00152  *    the documentation and/or other materials provided with the
00153  *    distribution.
00154  * 
00155  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00156  *    and "Vovida Open Communication Application Library (VOCAL)" must
00157  *    not be used to endorse or promote products derived from this
00158  *    software without prior written permission. For written
00159  *    permission, please contact vocal@vovida.org.
00160  *
00161  * 4. Products derived from this software may not be called "VOCAL", nor
00162  *    may "VOCAL" appear in their name, without prior written
00163  *    permission of Vovida Networks, Inc.
00164  * 
00165  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00166  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00167  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00168  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00169  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00170  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00171  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00172  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00173  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00174  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00175  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00176  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00177  * DAMAGE.
00178  * 
00179  * ====================================================================
00180  * 
00181  * This software consists of voluntary contributions made by Vovida
00182  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00183  * Inc.  For more information on Vovida Networks, Inc., please see
00184  * <http://www.vovida.org/>.
00185  *
00186  */