reSIProcate/stack  9694
DataParameter.cxx
Go to the documentation of this file.
00001 #if defined(HAVE_CONFIG_H)
00002 #include "config.h"
00003 #endif
00004 
00005 #include <cassert>
00006 #include "resip/stack/DataParameter.hxx"
00007 #include "resip/stack/Symbols.hxx"
00008 #include "rutil/ParseBuffer.hxx"
00009 #include "rutil/ParseException.hxx"
00010 #include "rutil/Logger.hxx"
00011 #include "rutil/WinLeakCheck.hxx"
00012 
00013 using namespace resip;
00014 using namespace std;
00015 
00016 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
00017 
00018 DataParameter::DataParameter(ParameterTypes::Type type,
00019                              ParseBuffer& pb,
00020                              const std::bitset<256>& terminators)
00021    : Parameter(type), 
00022      mValue(),
00023      mQuoted(false)
00024 {
00025    pb.skipWhitespace();
00026    pb.skipChar(Symbols::EQUALS[0]);
00027    pb.skipWhitespace();
00028    if(terminators[(unsigned char)(*pb.position())]) // handle cases such as ;tag=
00029    {
00030       throw ParseException("Empty value in string-type parameter.",
00031                               "DataParameter",
00032                               __FILE__,__LINE__);
00033    }
00034 
00035    if (*pb.position() == Symbols::DOUBLE_QUOTE[0])
00036    {
00037       setQuoted(true);
00038       pb.skipChar();
00039       const char* pos = pb.position();
00040       pb.skipToEndQuote();
00041       pb.data(mValue, pos);
00042       pb.skipChar();
00043    }
00044    else
00045    {
00046       const char* pos = pb.position();
00047       pb.skipToOneOf(terminators);
00048       pb.data(mValue, pos);
00049    }
00050 
00051    if(!mQuoted && mValue.empty())
00052    {
00053       // .bwc. We can't let this happen, because we throw if we try to encode
00054       // when we have an empty value. If that behavior stops, this can be 
00055       // removed.
00056      /* throw ParseException("DataParameter c'tor parsed empty param!", 
00057                            "DataParameter",
00058                            __FILE__,
00059                            __LINE__); */
00060    }
00061 }
00062 
00063 DataParameter::DataParameter(ParameterTypes::Type type)
00064    : Parameter(type),
00065      mValue(),
00066      mQuoted(false)
00067 {
00068 }
00069 
00070 Parameter* 
00071 DataParameter::clone() const
00072 {
00073    return new DataParameter(*this);
00074 }
00075 
00076 EncodeStream& 
00077 DataParameter::encode(EncodeStream& stream) const
00078 {
00079    if (mQuoted)
00080    {
00081       return stream << getName() << Symbols::EQUALS 
00082                     << Symbols::DOUBLE_QUOTE << mValue << Symbols::DOUBLE_QUOTE;
00083    }
00084    else
00085    {
00086       // this will assert if you've accessed a parameter that doesn't exist and
00087       // then the stack has created an empty parameter with no value. Try
00088       // calling exists(p_foo) before calling param(p_foo)
00089       if (mValue.empty())
00090       {
00091          ErrLog(<< "Accessing defaulted DataParameter: '" << getName() << "'");
00092       }
00093       assert(!mValue.empty()); // !jf!  probably should throw here
00094       return stream << getName() << Symbols::EQUALS << mValue;
00095    }
00096 }
00097 
00098 /* ====================================================================
00099  * The Vovida Software License, Version 1.0 
00100  * 
00101  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00102  * 
00103  * Redistribution and use in source and binary forms, with or without
00104  * modification, are permitted provided that the following conditions
00105  * are met:
00106  * 
00107  * 1. Redistributions of source code must retain the above copyright
00108  *    notice, this list of conditions and the following disclaimer.
00109  * 
00110  * 2. Redistributions in binary form must reproduce the above copyright
00111  *    notice, this list of conditions and the following disclaimer in
00112  *    the documentation and/or other materials provided with the
00113  *    distribution.
00114  * 
00115  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00116  *    and "Vovida Open Communication Application Library (VOCAL)" must
00117  *    not be used to endorse or promote products derived from this
00118  *    software without prior written permission. For written
00119  *    permission, please contact vocal@vovida.org.
00120  *
00121  * 4. Products derived from this software may not be called "VOCAL", nor
00122  *    may "VOCAL" appear in their name, without prior written
00123  *    permission of Vovida Networks, Inc.
00124  * 
00125  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00126  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00127  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00128  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00129  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00130  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00131  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00132  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00133  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00134  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00135  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00136  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00137  * DAMAGE.
00138  * 
00139  * ====================================================================
00140  * 
00141  * This software consists of voluntary contributions made by Vovida
00142  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00143  * Inc.  For more information on Vovida Networks, Inc., please see
00144  * <http://www.vovida.org/>.
00145  *
00146  */