reSIProcate/stack  9694
HeaderFieldValue.hxx
Go to the documentation of this file.
00001 #if !defined(RESIP_HEADERFIELDVALUE_HXX)
00002 #define RESIP_HEADERFIELDVALUE_HXX 
00003 
00004 #include "rutil/ParseException.hxx"
00005 #include "rutil/Data.hxx"
00006 #include "resip/stack/ParameterTypes.hxx"
00007 
00008 #include <iosfwd>
00009 
00010 namespace resip
00011 {
00012 
00013 class ParserCategory;
00014 class UnknownParameter;
00015 class ParseBuffer;
00016 
00020 class HeaderFieldValue
00021 {
00022    public:
00023       static const HeaderFieldValue Empty;
00024       
00025       enum CopyPaddingEnum
00026       {
00027          CopyPadding
00028       };
00029 
00030       enum NoOwnershipEnum
00031       {
00032          NoOwnership
00033       };
00034 
00035       HeaderFieldValue()
00036          : mField(0), //this must be initialized to 0 or ParserCategory will parse
00037            mFieldLength(0),
00038            mMine(false)
00039       {}
00040       HeaderFieldValue(const char* field, unsigned int fieldLength);
00041       HeaderFieldValue(const HeaderFieldValue& hfv);
00042       HeaderFieldValue(const HeaderFieldValue& hfv, CopyPaddingEnum);
00043       HeaderFieldValue(const HeaderFieldValue& hfv, NoOwnershipEnum);
00044       HeaderFieldValue& operator=(const HeaderFieldValue&);
00045       HeaderFieldValue& copyWithPadding(const HeaderFieldValue& rhs);
00046 
00047       ~HeaderFieldValue();
00048 
00049       EncodeStream& encode(EncodeStream& str) const;
00050 
00051       inline void init(const char* field, size_t length, bool own)
00052       {
00053          if(mMine)
00054          {
00055             delete [] mField;
00056          }
00057          
00058          mField=field;
00059          mFieldLength=(unsigned int)length;
00060          mMine=own;
00061       }
00062       
00063       inline const char* getBuffer() const {return mField;}
00064       inline unsigned int getLength() const {return mFieldLength;}
00065       inline void clear()
00066       {
00067          if (mMine)
00068          {
00069            delete[] mField;
00070            mMine=false;
00071          }
00072         mField=0;
00073         mFieldLength=0;
00074       }
00075 
00076       // const because Data::Share implies read-only access
00077       void toShareData(Data& data) const
00078       {
00079          data.setBuf(Data::Share, mField, mFieldLength);
00080       }
00081 
00082       // not const because Data::Borrow implies read/write access
00083       void toBorrowData(Data& data)
00084       {
00085          data.setBuf(Data::Borrow, mField, mFieldLength);
00086       }
00087 
00088    private:
00089       
00090       const char* mField;
00091       unsigned int mFieldLength;
00092       bool mMine;
00093 
00094       friend EncodeStream& operator<<(EncodeStream&, HeaderFieldValue&);
00095 };
00096 
00097 EncodeStream& operator<<(EncodeStream& stream, 
00098                          HeaderFieldValue& hList);
00099 
00100 
00101 }
00102 
00103 #endif
00104 
00105 /* ====================================================================
00106  * The Vovida Software License, Version 1.0 
00107  * 
00108  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00109  * 
00110  * Redistribution and use in source and binary forms, with or without
00111  * modification, are permitted provided that the following conditions
00112  * are met:
00113  * 
00114  * 1. Redistributions of source code must retain the above copyright
00115  *    notice, this list of conditions and the following disclaimer.
00116  * 
00117  * 2. Redistributions in binary form must reproduce the above copyright
00118  *    notice, this list of conditions and the following disclaimer in
00119  *    the documentation and/or other materials provided with the
00120  *    distribution.
00121  * 
00122  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00123  *    and "Vovida Open Communication Application Library (VOCAL)" must
00124  *    not be used to endorse or promote products derived from this
00125  *    software without prior written permission. For written
00126  *    permission, please contact vocal@vovida.org.
00127  *
00128  * 4. Products derived from this software may not be called "VOCAL", nor
00129  *    may "VOCAL" appear in their name, without prior written
00130  *    permission of Vovida Networks, Inc.
00131  * 
00132  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00133  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00134  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00135  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00136  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00137  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00138  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00139  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00140  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00141  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00142  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00143  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00144  * DAMAGE.
00145  * 
00146  * ====================================================================
00147  * 
00148  * This software consists of voluntary contributions made by Vovida
00149  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00150  * Inc.  For more information on Vovida Networks, Inc., please see
00151  * <http://www.vovida.org/>.
00152  *
00153  * set shiftwidth=3 expandtab:
00154  */