reSIProcate/DialogUsageManager  9680
DialogSetId.cxx
Go to the documentation of this file.
00001 #include "DialogSetId.hxx"
00002 #include "resip/stack/SipMessage.hxx"
00003 #include "resip/stack/Helper.hxx"
00004 #include "rutil/Logger.hxx"
00005 
00006 #define RESIPROCATE_SUBSYSTEM Subsystem::DUM
00007 
00008 using namespace resip;
00009 
00010 const DialogSetId DialogSetId::Empty;
00011 
00012 DialogSetId::DialogSetId(const SipMessage& msg) : 
00013    mCallId(msg.header(h_CallID).value())
00014 {
00015    //find local tag, generate one as necessary
00016    if (msg.isExternal())
00017    {
00018       if(msg.isResponse())
00019       {        
00020          if(msg.header(h_From).exists(p_tag))
00021          {
00022             // .bwc. If no tag, leave mTag empty.
00023             mTag = msg.header(h_From).param(p_tag);
00024          }
00025       }
00026       else //external request; generate to tag if not present
00027       {
00028          if (msg.header(h_To).exists(p_tag))
00029          {
00030             mTag = msg.header(h_To).param(p_tag);
00031          }
00032          else
00033          {
00034             //DebugLog ( <<  "********** Generated Local Tag *********** " );            
00035             mTag = Helper::computeTag(Helper::tagSize);
00036          }
00037       }
00038    }
00039    else
00040    {
00041       if(msg.isRequest())
00042       {
00043          assert(msg.header(h_From).exists(p_tag));
00044          mTag = msg.header(h_From).param(p_tag);
00045       }
00046       else
00047       {
00048          assert(msg.header(h_To).exists(p_tag));
00049          mTag = msg.header(h_To).param(p_tag);
00050       }
00051    }
00052 }
00053 
00054 DialogSetId::DialogSetId(const Data& callId, const Data& tag)
00055    : mCallId(callId),
00056      mTag(tag)
00057 {
00058 }
00059 
00060 DialogSetId::DialogSetId() 
00061    : mCallId(),
00062      mTag()
00063 {
00064 }
00065 
00066 bool
00067 DialogSetId::operator==(const DialogSetId& rhs) const
00068 {
00069    return mCallId == rhs.mCallId && mTag == rhs.mTag;
00070 }
00071 
00072 bool
00073 DialogSetId::operator!=(const DialogSetId& rhs) const
00074 {
00075    return mCallId != rhs.mCallId || mTag != rhs.mTag;
00076 }
00077 
00078 bool
00079 DialogSetId::operator<(const DialogSetId& rhs) const
00080 {
00081    if (mCallId < rhs.mCallId)
00082    {
00083       return true;
00084    }
00085    if (mCallId > rhs.mCallId)
00086    {
00087       return false;
00088    }
00089    return mTag < rhs.mTag;
00090 }
00091 
00092 bool 
00093 DialogSetId::operator>(const DialogSetId& rhs) const
00094 {
00095    if (mCallId > rhs.mCallId)
00096    {
00097       return true;
00098    }
00099    if (mCallId < rhs.mCallId)
00100    {
00101       return false;
00102    }
00103    return mTag > rhs.mTag;
00104 }
00105 
00106 size_t DialogSetId::hash() const
00107 {
00108     return mCallId.hash() ^ mTag.hash();
00109 }
00110 
00111 
00112 EncodeStream&
00113 resip::operator<<(EncodeStream& os, const DialogSetId& id)
00114 {
00115     return os << id.mCallId << '-' << id.mTag ;
00116 }
00117 
00118 HashValueImp(resip::DialogSetId, data.hash());
00119 
00120 /* ====================================================================
00121  * The Vovida Software License, Version 1.0 
00122  * 
00123  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00124  * 
00125  * Redistribution and use in source and binary forms, with or without
00126  * modification, are permitted provided that the following conditions
00127  * are met:
00128  * 
00129  * 1. Redistributions of source code must retain the above copyright
00130  *    notice, this list of conditions and the following disclaimer.
00131  * 
00132  * 2. Redistributions in binary form must reproduce the above copyright
00133  *    notice, this list of conditions and the following disclaimer in
00134  *    the documentation and/or other materials provided with the
00135  *    distribution.
00136  * 
00137  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00138  *    and "Vovida Open Communication Application Library (VOCAL)" must
00139  *    not be used to endorse or promote products derived from this
00140  *    software without prior written permission. For written
00141  *    permission, please contact vocal@vovida.org.
00142  *
00143  * 4. Products derived from this software may not be called "VOCAL", nor
00144  *    may "VOCAL" appear in their name, without prior written
00145  *    permission of Vovida Networks, Inc.
00146  * 
00147  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00148  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00149  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00150  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00151  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00152  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00153  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00154  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00155  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00156  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00157  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00158  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00159  * DAMAGE.
00160  * 
00161  * ====================================================================
00162  * 
00163  * This software consists of voluntary contributions made by Vovida
00164  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00165  * Inc.  For more information on Vovida Networks, Inc., please see
00166  * <http://www.vovida.org/>.
00167  *
00168  */