reSIProcate/stack  9694
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes
resip::BranchParameter Class Reference

Represents the "via-branch" parameter of the RFC 3261 grammar. More...

#include <BranchParameter.hxx>

Inheritance diagram for resip::BranchParameter:
Inheritance graph
[legend]
Collaboration diagram for resip::BranchParameter:
Collaboration graph
[legend]

List of all members.

Public Types

typedef BranchParameter Type

Public Member Functions

 BranchParameter (ParameterTypes::Type, ParseBuffer &pb, const std::bitset< 256 > &terminators)
 BranchParameter (ParameterTypes::Type)
 ~BranchParameter ()
bool hasMagicCookie () const
const DatagetTransactionId () const
void incrementTransportSequence ()
void reset (const Data &transactionId=Data::Empty)
DataclientData ()
const DataclientData () const
void setSigcompCompartment (const Data &)
Data getSigcompCompartment () const
virtual Parameterclone () const
virtual EncodeStreamencode (EncodeStream &stream) const
 BranchParameter (const BranchParameter &other)
BranchParameteroperator= (const BranchParameter &other)
bool operator== (const BranchParameter &other)
Typevalue ()

Static Public Member Functions

static Parameterdecode (ParameterTypes::Type type, ParseBuffer &pb, const std::bitset< 256 > &terminators, PoolBase *pool)

Private Attributes

bool mHasMagicCookie
bool mIsMyBranch
Data mTransactionId
unsigned int mTransportSeq
Data mClientData
const DatamInteropMagicCookie
Data mSigcompCompartment

Detailed Description

Represents the "via-branch" parameter of the RFC 3261 grammar.

Definition at line 26 of file BranchParameter.hxx.


Member Typedef Documentation

Definition at line 29 of file BranchParameter.hxx.


Constructor & Destructor Documentation

BranchParameter::BranchParameter ( ParameterTypes::Type  type,
ParseBuffer pb,
const std::bitset< 256 > &  terminators 
)

Definition at line 21 of file BranchParameter.cxx.

References resip::Data::base64decode(), resip::ParseBuffer::data(), resip::Data::empty(), resip::ParseBuffer::end(), resip::Symbols::EQUALS, resip::Random::getRandomHex(), resip::Symbols::MagicCookie, mClientData, mHasMagicCookie, mInteropMagicCookie, mIsMyBranch, mSigcompCompartment, mTransactionId, mTransportSeq, resip::ParseBuffer::position(), resip::Symbols::resipCookie, resip::ParseBuffer::skipChar(), resip::ParseBuffer::skipN(), resip::ParseBuffer::skipToChar(), resip::ParseBuffer::skipToOneOf(), resip::ParseBuffer::skipWhitespace(), strncasecmp(), resip::Data::toBitset(), and resip::ParseBuffer::uInt32().

Referenced by clone(), and decode().

   : Parameter(type), 
     mHasMagicCookie(false),
     mIsMyBranch(false),
     mTransactionId(),
     mTransportSeq(1),
     mClientData(),
     mInteropMagicCookie(0),
     mSigcompCompartment()
{
   try
   {
      pb.skipWhitespace();
      pb.skipChar(Symbols::EQUALS[0]);
      pb.skipWhitespace();
      if(memcmp(pb.position(), Symbols::MagicCookie, 7) == 0)
      {
         mHasMagicCookie=true;
         pb.skipN(7);
      }
      // !bwc! This no-case comparison is expensive; only do it if the case-
      // sensitive comparison fails.
      else if(strncasecmp(pb.position(), Symbols::MagicCookie, 7) == 0)
      {
         mHasMagicCookie=true;
         mInteropMagicCookie = new Data(pb.position(), 7);
         pb.skipN(7);
      }
      
      const char* start = pb.position();
      static std::bitset<256> delimiter=Data::toBitset("\r\n\t ;=?>");

      if (mHasMagicCookie &&
          (pb.end() - start > 8) &&
          // look for prefix cookie (maybe make this bigger?)
          memcmp(start, Symbols::resipCookie, 8) == 0)
      {
         // ?bwc? Wrap this stuff in try/catch, just in case of false positives?
         const char* curr=start;
         mIsMyBranch = true;
         pb.skipN(8);

         mTransportSeq=pb.uInt32();

         curr=pb.skipChar('-');
         pb.skipToChar('-');
         Data encoded;
         pb.data(encoded, curr);
         if(!encoded.empty())
         {
            // !bwc! Expensive! Also, Base64 isn't case-insensitive.
            mClientData = encoded.base64decode();
         }

         curr=pb.skipChar('-');
         pb.skipToChar('-');
         pb.data(encoded,curr);
         if(!encoded.empty())
         {
            // !bwc! Expensive! Also, Base64 isn't case-insensitive.
            mSigcompCompartment = encoded.base64decode();
         }

         start=pb.skipChar('-');
      }
      pb.skipToOneOf(delimiter);
      pb.data(mTransactionId, start);
   }
   catch(resip::ParseException& e)
   {
      mTransactionId=Random::getRandomHex(8);
      throw e;
   }
}

Here is the call graph for this function:

BranchParameter::BranchParameter ( ParameterTypes::Type  type) [explicit]
BranchParameter::~BranchParameter ( )

Definition at line 128 of file BranchParameter.cxx.

References mInteropMagicCookie.

{
   delete mInteropMagicCookie;
}
BranchParameter::BranchParameter ( const BranchParameter other)

Member Function Documentation

Data & BranchParameter::clientData ( )

Definition at line 193 of file BranchParameter.cxx.

References mClientData.

{
    return mClientData;
}
const Data & BranchParameter::clientData ( ) const

Definition at line 199 of file BranchParameter.cxx.

References mClientData.

{
    return mClientData;
}
Parameter * BranchParameter::clone ( ) const [virtual]

Implements resip::Parameter.

Definition at line 252 of file BranchParameter.cxx.

References BranchParameter().

{
   return new BranchParameter(*this);
}

Here is the call graph for this function:

static Parameter* resip::BranchParameter::decode ( ParameterTypes::Type  type,
ParseBuffer pb,
const std::bitset< 256 > &  terminators,
PoolBase pool 
) [inline, static]

Definition at line 57 of file BranchParameter.hxx.

References BranchParameter().

      {
         return new (pool) BranchParameter(type, pb, terminators);
      }

Here is the call graph for this function:

EncodeStream & BranchParameter::encode ( EncodeStream stream) const [virtual]

Implements resip::Parameter.

Definition at line 258 of file BranchParameter.cxx.

References resip::Data::base64encode(), resip::Symbols::DASH, resip::Data::empty(), resip::Symbols::EQUALS, resip::Parameter::getName(), resip::Symbols::MagicCookie, mClientData, mHasMagicCookie, mInteropMagicCookie, mIsMyBranch, mSigcompCompartment, mTransactionId, mTransportSeq, and resip::Symbols::resipCookie.

Referenced by main().

{
   stream << getName() << Symbols::EQUALS;
   if (mHasMagicCookie)
   {
      if (mInteropMagicCookie)
      {
         stream << *mInteropMagicCookie;         
      }
      else
      {
         stream << Symbols::MagicCookie;
      }
   }
   if (mIsMyBranch)
   {
      stream << Symbols::resipCookie;
      stream << mTransportSeq;
      stream << Symbols::DASH;
      if(!mClientData.empty()) // base64encode() makes copies
      {
         // !bwc! We should be using hex encoding; branch params are supposed to
         // be case-insensitive.
         stream << mClientData.base64encode(true/*safe URL*/);
      }
      stream << Symbols::DASH;
      if(!mSigcompCompartment.empty()) // base64encode() makes copies
      {
         // !bwc! We should be using hex encoding; branch params are supposed to
         // be case-insensitive.
         stream << mSigcompCompartment.base64encode(true);
      }
      stream << Symbols::DASH;
   }
   stream << mTransactionId;
      
   return stream;
}

Here is the call graph for this function:

Data BranchParameter::getSigcompCompartment ( ) const

Definition at line 225 of file BranchParameter.cxx.

References mSigcompCompartment.

{
  return mSigcompCompartment;
}
const Data & BranchParameter::getTransactionId ( ) const

Definition at line 180 of file BranchParameter.cxx.

References mTransactionId.

Referenced by main().

{
   return mTransactionId;
}
bool BranchParameter::hasMagicCookie ( ) const

Definition at line 174 of file BranchParameter.cxx.

References mHasMagicCookie.

Referenced by main().

{
   return mHasMagicCookie;
}
void BranchParameter::incrementTransportSequence ( )

Definition at line 186 of file BranchParameter.cxx.

References mIsMyBranch, and mTransportSeq.

{
   assert(mIsMyBranch);
   mTransportSeq++;
}
BranchParameter & BranchParameter::operator= ( const BranchParameter other)
bool BranchParameter::operator== ( const BranchParameter other)
void BranchParameter::reset ( const Data transactionId = Data::Empty)

Definition at line 231 of file BranchParameter.cxx.

References resip::Data::Empty, resip::Data::empty(), resip::Random::getRandomHex(), mHasMagicCookie, mInteropMagicCookie, mIsMyBranch, mSigcompCompartment, mTransactionId, and mTransportSeq.

Referenced by main().

{
   mHasMagicCookie = true;
   mIsMyBranch = true;
   delete mInteropMagicCookie;
   mInteropMagicCookie = 0;   

   mSigcompCompartment = Data::Empty;

   mTransportSeq = 1;
   if (!transactionId.empty())
   {
      mTransactionId = transactionId;
   }
   else
   {
      mTransactionId = Random::getRandomHex(8);
   }
}

Here is the call graph for this function:

void BranchParameter::setSigcompCompartment ( const Data id)
Todo:
The encoding here could be more efficient.

Definition at line 208 of file BranchParameter.cxx.

References resip::Data::Empty, and mSigcompCompartment.

{
  if (id.size() == 0)
  {
    mSigcompCompartment = Data::Empty;
  }

  // These will often (but not always) be UUID URNs in angle brackets;
  // e.g.: <urn:uuid:fa33c72d-121f-47e8-42e2-1eb6e24aba64>

  // Ideally, we would detect this, strip out everything that isn't
  // hex, and convert the hex to raw data.

  mSigcompCompartment = id;
}
Type& resip::BranchParameter::value ( ) [inline]

Definition at line 72 of file BranchParameter.hxx.

{return *this;}

Member Data Documentation

Definition at line 79 of file BranchParameter.hxx.

Referenced by BranchParameter(), clientData(), encode(), operator=(), and operator==().

Definition at line 81 of file BranchParameter.hxx.

Referenced by BranchParameter(), encode(), operator=(), reset(), and ~BranchParameter().

unsigned int resip::BranchParameter::mTransportSeq [private]

The documentation for this class was generated from the following files: