reSIProcate/stack  9694
ExpiresCategory.cxx
Go to the documentation of this file.
00001 #if defined(HAVE_CONFIG_H)
00002 #include "config.h"
00003 #endif
00004 
00005 #include "resip/stack/ExpiresCategory.hxx"
00006 #include "rutil/Logger.hxx"
00007 #include "rutil/ParseBuffer.hxx"
00008 //#include "rutil/WinLeakCheck.hxx"  // not compatible with placement new used below
00009 
00010 using namespace resip;
00011 using namespace std;
00012 
00013 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
00014 
00015 //====================
00016 // Expires:
00017 //====================
00018 ExpiresCategory:: ExpiresCategory()
00019    : ParserCategory(), 
00020      mValue(0) 
00021 {}
00022 
00023 ExpiresCategory::ExpiresCategory(const HeaderFieldValue& hfv, 
00024                                  Headers::Type type,
00025                                  PoolBase* pool)
00026    : ParserCategory(hfv, type, pool), mValue(0)
00027 {}
00028 
00029 ExpiresCategory::ExpiresCategory(const ExpiresCategory& rhs,
00030                                  PoolBase* pool)
00031    : ParserCategory(rhs, pool),
00032      mValue(rhs.mValue)
00033 {}
00034 
00035 ExpiresCategory&
00036 ExpiresCategory::operator=(const ExpiresCategory& rhs)
00037 {
00038    if (this != &rhs)
00039    {
00040       ParserCategory::operator=(rhs);
00041       mValue = rhs.mValue;
00042    }
00043    return *this;
00044 }
00045 
00046 ParserCategory* ExpiresCategory::clone() const
00047 {
00048    return new ExpiresCategory(*this);
00049 }
00050 
00051 ParserCategory* ExpiresCategory::clone(void* location) const
00052 {
00053    return new (location) ExpiresCategory(*this);
00054 }
00055 
00056 ParserCategory* 
00057 ExpiresCategory::clone(PoolBase* pool) const
00058 {
00059    return new (pool) ExpiresCategory(*this, pool);
00060 }
00061 
00062 UInt32& 
00063 ExpiresCategory::value() 
00064 {
00065    checkParsed(); 
00066    return mValue;
00067 }
00068 
00069 UInt32
00070 ExpiresCategory::value() const 
00071 {
00072    checkParsed(); 
00073    return mValue;
00074 }
00075 
00076 void
00077 ExpiresCategory::parse(ParseBuffer& pb)
00078 {
00079    pb.skipWhitespace();
00080    const char *p = pb.position();
00081    if (!pb.eof() && isdigit(*p))
00082    {
00083      mValue = pb.uInt32();
00084    }
00085    else
00086    {
00087       mValue = 3600;
00088    }
00089    pb.skipToChar(Symbols::SEMI_COLON[0]);
00090    parseParameters(pb);
00091 }
00092 
00093 EncodeStream& 
00094 ExpiresCategory::encodeParsed(EncodeStream& str) const
00095 {
00096    str << mValue;
00097    encodeParameters(str);
00098    return str;
00099 }
00100 
00101 ParameterTypes::Factory ExpiresCategory::ParameterFactories[ParameterTypes::MAX_PARAMETER]={0};
00102 
00103 Parameter* 
00104 ExpiresCategory::createParam(ParameterTypes::Type type, ParseBuffer& pb, const std::bitset<256>& terminators, PoolBase* pool)
00105 {
00106    if(type > ParameterTypes::UNKNOWN && type < ParameterTypes::MAX_PARAMETER && ParameterFactories[type])
00107    {
00108       return ParameterFactories[type](type, pb, terminators, pool);
00109    }
00110    return 0;
00111 }
00112 
00113 bool 
00114 ExpiresCategory::exists(const Param<ExpiresCategory>& paramType) const
00115 {
00116     checkParsed();
00117     bool ret = getParameterByEnum(paramType.getTypeNum()) != NULL;
00118     return ret;
00119 }
00120 
00121 void 
00122 ExpiresCategory::remove(const Param<ExpiresCategory>& paramType)
00123 {
00124     checkParsed();
00125     removeParameterByEnum(paramType.getTypeNum());
00126 }
00127 
00128 #define defineParam(_enum, _name, _type, _RFC_ref_ignored)                                                      \
00129 _enum##_Param::DType&                                                                                           \
00130 ExpiresCategory::param(const _enum##_Param& paramType)                                                           \
00131 {                                                                                                               \
00132    checkParsed();                                                                                               \
00133    _enum##_Param::Type* p =                                                                                     \
00134       static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum()));                            \
00135    if (!p)                                                                                                      \
00136    {                                                                                                            \
00137       p = new _enum##_Param::Type(paramType.getTypeNum());                                                      \
00138       mParameters.push_back(p);                                                                                 \
00139    }                                                                                                            \
00140    return p->value();                                                                                           \
00141 }                                                                                                               \
00142                                                                                                                 \
00143 const _enum##_Param::DType&                                                                                     \
00144 ExpiresCategory::param(const _enum##_Param& paramType) const                                                     \
00145 {                                                                                                               \
00146    checkParsed();                                                                                               \
00147    _enum##_Param::Type* p =                                                                                     \
00148       static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum()));                            \
00149    if (!p)                                                                                                      \
00150    {                                                                                                            \
00151       InfoLog(<< "Missing parameter " _name " " << ParameterTypes::ParameterNames[paramType.getTypeNum()]);     \
00152       DebugLog(<< *this);                                                                                       \
00153       throw Exception("Missing parameter " _name, __FILE__, __LINE__);                                          \
00154    }                                                                                                            \
00155    return p->value();                                                                                           \
00156 }
00157 
00158 defineParam(refresher, "refresher", DataParameter, "RFC 4028");
00159 
00160 #undef defineParam
00161 
00162 /* ====================================================================
00163  * The Vovida Software License, Version 1.0 
00164  * 
00165  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00166  * 
00167  * Redistribution and use in source and binary forms, with or without
00168  * modification, are permitted provided that the following conditions
00169  * are met:
00170  * 
00171  * 1. Redistributions of source code must retain the above copyright
00172  *    notice, this list of conditions and the following disclaimer.
00173  * 
00174  * 2. Redistributions in binary form must reproduce the above copyright
00175  *    notice, this list of conditions and the following disclaimer in
00176  *    the documentation and/or other materials provided with the
00177  *    distribution.
00178  * 
00179  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00180  *    and "Vovida Open Communication Application Library (VOCAL)" must
00181  *    not be used to endorse or promote products derived from this
00182  *    software without prior written permission. For written
00183  *    permission, please contact vocal@vovida.org.
00184  *
00185  * 4. Products derived from this software may not be called "VOCAL", nor
00186  *    may "VOCAL" appear in their name, without prior written
00187  *    permission of Vovida Networks, Inc.
00188  * 
00189  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00190  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00191  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00192  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00193  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00194  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00195  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00196  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00197  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00198  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00199  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00200  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00201  * DAMAGE.
00202  * 
00203  * ====================================================================
00204  * 
00205  * This software consists of voluntary contributions made by Vovida
00206  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00207  * Inc.  For more information on Vovida Networks, Inc., please see
00208  * <http://www.vovida.org/>.
00209  *
00210  */