reSIProcate/DialogUsageManager  9694
UserProfile.cxx
Go to the documentation of this file.
00001 
00002 #include "resip/dum/Profile.hxx"
00003 #include "resip/dum/UserProfile.hxx"
00004 #include "rutil/Logger.hxx"
00005 #include "rutil/Inserter.hxx"
00006 #include "resip/stack/SipMessage.hxx"
00007 #include "rutil/MD5Stream.hxx"
00008 
00009 using namespace resip;
00010 #define RESIPROCATE_SUBSYSTEM Subsystem::DUM
00011 
00012 const resip::NameAddr UserProfile::mAnonymous("\"Anonymous\" <sip:anonymous@anonymous.invalid>", true /* preCacheAor */);
00013 
00014 UserProfile::UserProfile() : Profile(), 
00015    mGruuEnabled(false),
00016    mRegId(0),
00017    mClientOutboundEnabled(false)
00018 {
00019     //InfoLog (<< "************ UserProfile created (no base)!: " << *this);
00020 }
00021 
00022 UserProfile::UserProfile(SharedPtr<Profile> baseProfile) : Profile(baseProfile), 
00023    mGruuEnabled(false),
00024    mRegId(0),
00025    mClientOutboundEnabled(false)
00026 {
00027     //InfoLog (<< "************ UserProfile created (with base)!: " << *this);
00028 }
00029 
00030 UserProfile::~UserProfile()
00031 {
00032     //InfoLog (<< "************ UserProfile destroyed!: " << *this);
00033 }
00034 
00035 SharedPtr<UserProfile> 
00036 UserProfile::getAnonymousUserProfile() const
00037 {
00038    SharedPtr<UserProfile> anon(this->clone());
00039    anon->setDefaultFrom(mAnonymous);
00040    return anon;
00041 }
00042 
00043 UserProfile* 
00044 UserProfile::clone() const
00045 {
00046    return new UserProfile(*this);
00047 }
00048 
00049 bool
00050 UserProfile::isAnonymous() const
00051 {
00052    return (mDefaultFrom.uri().getAor() == mAnonymous.uri().getAor());
00053 }
00054 
00055 void
00056 UserProfile::setDefaultFrom(const NameAddr& from)
00057 {
00058    mDefaultFrom = from;
00059 }
00060 
00061 NameAddr& 
00062 UserProfile::getDefaultFrom()
00063 {
00064    return mDefaultFrom;
00065 }
00066 
00067 void
00068 UserProfile::setServiceRoute(const NameAddrs& sRoute)
00069 {
00070    mServiceRoute = sRoute;
00071 }
00072 
00073 NameAddrs& 
00074 UserProfile::getServiceRoute()
00075 {
00076    return mServiceRoute;
00077 }
00078 
00079 bool
00080 UserProfile::hasInstanceId()
00081 {
00082    return !mInstanceId.empty();
00083 }
00084 
00085 void
00086 UserProfile::setInstanceId(const Data& id)
00087 {
00088    mInstanceId = id;
00089 }
00090 
00091 const Data&
00092 UserProfile::getInstanceId() const
00093 {
00094    return mInstanceId;
00095 }
00096 
00097 void 
00098 UserProfile::addGruu(const Data& aor, const NameAddr& contact)
00099 {
00100 }
00101 
00102 bool 
00103 UserProfile::hasGruu(const Data& aor) const
00104 {
00105    return false;
00106 }
00107 
00108 bool 
00109 UserProfile::hasGruu(const Data& aor, const Data& instance) const
00110 {
00111    return false;
00112 }
00113 
00114 NameAddr&
00115 UserProfile:: getGruu(const Data& aor)
00116 {
00117    assert(0);
00118    static NameAddr gruu;
00119    return gruu;
00120 }
00121 
00122 NameAddr&
00123 UserProfile:: getGruu(const Data& aor, const NameAddr& contact)
00124 {
00125    assert(0);
00126    static NameAddr gruu;
00127    return gruu;
00128 }
00129 
00130 void 
00131 UserProfile::clearDigestCredentials()
00132 {
00133    mDigestCredentials.clear();
00134 }
00135 
00136 void 
00137 UserProfile::setDigestCredential( const Data& realm, const Data& user, const Data& password, bool isPasswordA1Hash)
00138 {
00139    DigestCredential cred(realm, user, password, isPasswordA1Hash);
00140 
00141    DebugLog (<< "Adding credential: " << cred);
00142    mDigestCredentials.erase(cred);
00143    mDigestCredentials.insert(cred);
00144 }
00145      
00146 static const UserProfile::DigestCredential emptyDigestCredential;
00147 const UserProfile::DigestCredential&
00148 UserProfile::getDigestCredential( const Data& realm  )
00149 {
00150    if(mDigestCredentials.empty())
00151    {
00152       // !jf! why not just throw here? 
00153       return emptyDigestCredential;
00154    }
00155 
00156    DigestCredentials::const_iterator it = mDigestCredentials.find(DigestCredential(realm));
00157    if (it == mDigestCredentials.end())
00158    {
00159       DebugLog(<< "Didn't find credential for realm: " << realm << " " << *mDigestCredentials.begin());
00160       return *mDigestCredentials.begin();
00161    }
00162    else      
00163    {
00164       DebugLog(<< "Found credential for realm: " << *it << realm);      
00165       return *it;
00166    }
00167 }
00168 
00169 UserProfile::DigestCredential::DigestCredential(const Data& r, const Data& u, const Data& pwd, bool pwdA1Hash) :
00170    realm(r),
00171    user(u),
00172    password(pwd),
00173    isPasswordA1Hash(pwdA1Hash)
00174 {  
00175 }
00176 
00177 UserProfile::DigestCredential::DigestCredential() : 
00178    realm(Data::Empty),
00179    user(Data::Empty),
00180    password(Data::Empty),
00181    isPasswordA1Hash(false)
00182 {
00183 }  
00184 
00185 UserProfile::DigestCredential::DigestCredential(const Data& pRealm) : 
00186    realm(pRealm),
00187    user(Data::Empty),
00188    password(Data::Empty),
00189    isPasswordA1Hash(false)
00190 {
00191 }  
00192 
00193 bool
00194 UserProfile::DigestCredential::operator<(const DigestCredential& rhs) const
00195 {
00196    return realm < rhs.realm;
00197 }
00198 
00199 EncodeStream&
00200 resip::operator<<(EncodeStream& strm, const UserProfile& profile)
00201 {
00202    strm << "UserProfile: " << profile.mDefaultFrom << Inserter(profile.mDigestCredentials);
00203    return strm;
00204 }
00205 
00206 EncodeStream&
00207 resip::operator<<(EncodeStream& strm, const UserProfile::DigestCredential& cred)
00208 {
00209    strm << "realm=" << cred.realm << " user=" << cred.user ;
00210    return strm;
00211 }
00212 
00213 
00214 /* ====================================================================
00215  * The Vovida Software License, Version 1.0 
00216  * 
00217  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00218  * 
00219  * Redistribution and use in source and binary forms, with or without
00220  * modification, are permitted provided that the following conditions
00221  * are met:
00222  * 
00223  * 1. Redistributions of source code must retain the above copyright
00224  *    notice, this list of conditions and the following disclaimer.
00225  * 
00226  * 2. Redistributions in binary form must reproduce the above copyright
00227  *    notice, this list of conditions and the following disclaimer in
00228  *    the documentation and/or other materials provided with the
00229  *    distribution.
00230  * 
00231  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00232  *    and "Vovida Open Communication Application Library (VOCAL)" must
00233  *    not be used to endorse or promote products derived from this
00234  *    software without prior written permission. For written
00235  *    permission, please contact vocal@vovida.org.
00236  *
00237  * 4. Products derived from this software may not be called "VOCAL", nor
00238  *    may "VOCAL" appear in their name, without prior written
00239  *    permission of Vovida Networks, Inc.
00240  * 
00241  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00242  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00243  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00244  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00245  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00246  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00247  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00248  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00249  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00250  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00251  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00252  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00253  * DAMAGE.
00254  * 
00255  * ====================================================================
00256  * 
00257  * This software consists of voluntary contributions made by Vovida
00258  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00259  * Inc.  For more information on Vovida Networks, Inc., please see
00260  * <http://www.vovida.org/>.
00261  *
00262  */