reSIProcate/stack  9694
UnknownParameter.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/UnknownParameter.hxx"
00006 #include "rutil/ParseBuffer.hxx"
00007 #include "resip/stack/Symbols.hxx"
00008 #include "rutil/WinLeakCheck.hxx"
00009 
00010 using namespace resip;
00011 using namespace std;
00012 
00013 UnknownParameter::UnknownParameter(const char* startName, 
00014                                    unsigned int nameSize,
00015                                    ParseBuffer& pb, 
00016                                    const std::bitset<256>& terminators)
00017    : Parameter(ParameterTypes::UNKNOWN),
00018      mName(startName, nameSize),
00019      mValue(),
00020      mIsQuoted(false)
00021 {
00022    pb.skipWhitespace();
00023    if (!pb.eof() && *pb.position() == Symbols::EQUALS[0])
00024    {
00025       pb.skipChar(Symbols::EQUALS[0]);
00026       pb.skipWhitespace();
00027       if (*pb.position() == Symbols::DOUBLE_QUOTE[0])
00028       {
00029          setQuoted(true);
00030          pb.skipChar();
00031          const char* pos = pb.position();
00032          pb.skipToEndQuote();
00033          pb.data(mValue, pos);
00034          pb.skipChar();
00035       }
00036       else
00037       {
00038          const char* pos = pb.position();
00039          pb.skipToOneOf(terminators);
00040          pb.data(mValue, pos);
00041       }
00042       
00043    }
00044    else
00045    {
00046       // must be a terminator -- exists style
00047    }
00048 }
00049 
00050 UnknownParameter::UnknownParameter(const Data& name)
00051    : Parameter(ParameterTypes::UNKNOWN),
00052      mName(name),
00053      mIsQuoted(false)
00054 {
00055 }
00056 
00057 const Data& 
00058 UnknownParameter::getName() const
00059 {
00060    return mName;
00061 }
00062 
00063 
00064 Parameter* 
00065 UnknownParameter::clone() const
00066 {
00067    return new UnknownParameter(*this);
00068 }
00069 
00070 EncodeStream&
00071 UnknownParameter::encode(EncodeStream& stream) const
00072 {
00073    if (mIsQuoted)
00074    {
00075       return stream << getName() << Symbols::EQUALS 
00076                     << Symbols::DOUBLE_QUOTE << mValue << Symbols::DOUBLE_QUOTE;
00077    }
00078    else if (!mValue.empty())
00079    {
00080       return stream << getName() << Symbols::EQUALS << mValue;
00081    }
00082    else
00083    {
00084       return stream << getName();
00085    }
00086 }
00087 
00088 EncodeStream& operator<<(EncodeStream& stream, UnknownParameter& comp)
00089 {
00090    return stream << comp.getName() << "=" << comp.value();
00091 }
00092 
00093 
00094 /* ====================================================================
00095  * The Vovida Software License, Version 1.0 
00096  * 
00097  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00098  * 
00099  * Redistribution and use in source and binary forms, with or without
00100  * modification, are permitted provided that the following conditions
00101  * are met:
00102  * 
00103  * 1. Redistributions of source code must retain the above copyright
00104  *    notice, this list of conditions and the following disclaimer.
00105  * 
00106  * 2. Redistributions in binary form must reproduce the above copyright
00107  *    notice, this list of conditions and the following disclaimer in
00108  *    the documentation and/or other materials provided with the
00109  *    distribution.
00110  * 
00111  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00112  *    and "Vovida Open Communication Application Library (VOCAL)" must
00113  *    not be used to endorse or promote products derived from this
00114  *    software without prior written permission. For written
00115  *    permission, please contact vocal@vovida.org.
00116  *
00117  * 4. Products derived from this software may not be called "VOCAL", nor
00118  *    may "VOCAL" appear in their name, without prior written
00119  *    permission of Vovida Networks, Inc.
00120  * 
00121  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00122  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00123  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00124  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00125  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00126  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00127  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00128  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00129  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00130  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00131  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00132  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00133  * DAMAGE.
00134  * 
00135  * ====================================================================
00136  * 
00137  * This software consists of voluntary contributions made by Vovida
00138  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00139  * Inc.  For more information on Vovida Networks, Inc., please see
00140  * <http://www.vovida.org/>.
00141  *
00142  */