reSIProcate/rutil  9694
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes | Friends
resip::ParseBuffer Class Reference

Provides string-parsing functionality with protection from buffer overflow. More...

#include <ParseBuffer.hxx>

Collaboration diagram for resip::ParseBuffer:
Collaboration graph
[legend]

List of all members.

Classes

class  CurrentPosition
 Provides some access to the current position of a ParseBuffer, which guards against invalid accesses. Just a wrapper around a ParseBuffer&, so is very cheap to initialize/copy. More...
class  Pointer
 Similar to CurrentPosition, but does not move depending on the state of the ParseBuffer. Initializing one of these is more expensive. More...

Public Member Functions

 ParseBuffer (const char *buff, size_t len, const Data &errorContext=Data::Empty)
 ParseBuffer (const Data &data, const Data &errorContext=Data::Empty)
 ParseBuffer (const ParseBuffer &other)
const DatagetContext () const
ParseBufferoperator= (const ParseBuffer &other)
void reset (const char *pos)
bool eof () const
bool bof () const
bool valid () const
Pointer start () const
CurrentPosition position () const
Pointer end () const
CurrentPosition skipChar ()
CurrentPosition skipChar (char c)
CurrentPosition skipChars (const char *cs)
CurrentPosition skipChars (const Data &cs)
CurrentPosition skipNonWhitespace ()
CurrentPosition skipWhitespace ()
CurrentPosition skipLWS ()
CurrentPosition skipToTermCRLF ()
CurrentPosition skipToChar (char c)
CurrentPosition skipToChars (const char *cs)
CurrentPosition skipToChars (const Data &cs)
CurrentPosition skipToOneOf (const char *cs)
CurrentPosition skipToOneOf (const char *cs1, const char *cs2)
CurrentPosition skipToOneOf (const Data &cs)
CurrentPosition skipToOneOf (const Data &cs1, const Data &cs2)
CurrentPosition skipChars (const std::bitset< 256 > &cs)
CurrentPosition skipToOneOf (const std::bitset< 256 > &cs)
const char * skipToEndQuote (char quote= '"')
CurrentPosition skipN (int count)
CurrentPosition skipToEnd ()
const char * skipBackChar ()
const char * skipBackWhitespace ()
const char * skipBackN (int count)
const char * skipBackChar (char c)
const char * skipBackToChar (char c)
const char * skipBackToOneOf (const char *cs)
void assertEof () const
void assertNotEof () const
void fail (const char *file, unsigned int line, const Data &errmsg=Data::Empty) const
void data (Data &data, const char *start) const
 make the passed in data share memory with the buffer (uses Data::Share)
Data data (const char *start) const
void dataUnescaped (Data &data, const char *start) const
int integer ()
UInt8 uInt8 ()
UInt32 uInt32 ()
 dcm! -- merge these, ask about length checks
UInt64 uInt64 ()
RESIP_DEPRECATED UInt64 unsignedLongLong ()
RESIP_DEPRECATED unsigned long unsignedInteger ()
float floatVal ()
int qVal ()

Static Public Member Functions

static bool oneOf (char c, const char *cs)
static bool oneOf (char c, const Data &cs)

Static Public Attributes

static const char * Whitespace = " \t\r\n"
static const char * ParamTerm = ";?"

Private Attributes

const char * mBuff
const char * mPosition
const char * mEnd
const DatamErrorContext

Friends

class ParseBuffer::CurrentPosition

Detailed Description

Provides string-parsing functionality with protection from buffer overflow.

Throws ParseException when parse failures occur.

Definition at line 17 of file ParseBuffer.hxx.


Constructor & Destructor Documentation

ParseBuffer::ParseBuffer ( const char *  buff,
size_t  len,
const Data errorContext = Data::Empty 
)

Definition at line 17 of file ParseBuffer.cxx.

   : mBuff(buff),
     mPosition(buff),
     mEnd(buff+len),
     mErrorContext(errorContext)
{}
ParseBuffer::ParseBuffer ( const Data data,
const Data errorContext = Data::Empty 
) [explicit]

Definition at line 25 of file ParseBuffer.cxx.

   : mBuff(data.data()),
     mPosition(mBuff),
     mEnd(mBuff + data.size()),
     mErrorContext(errorContext)
{}
ParseBuffer::ParseBuffer ( const ParseBuffer other)

Definition at line 33 of file ParseBuffer.cxx.

   : mBuff(rhs.mBuff),
     mPosition(rhs.mPosition),
     mEnd(rhs.mEnd),
     mErrorContext(rhs.mErrorContext)
{}

Member Function Documentation

void resip::ParseBuffer::assertEof ( ) const [inline]

Definition at line 214 of file ParseBuffer.hxx.

References eof(), and fail().

Referenced by main().

      {
         if (!eof())
         {
            fail(__FILE__, __LINE__,"expected eof");
         }
      }

Here is the call graph for this function:

void resip::ParseBuffer::assertNotEof ( ) const [inline]

Definition at line 222 of file ParseBuffer.hxx.

References eof(), and fail().

Referenced by resip::XMLCursor::Node::extractTag(), integer(), resip::XMLCursor::Node::Node(), resip::ParseBuffer::CurrentPosition::operator*(), and skipNonWhitespace().

      {
         if (eof())
         {
            fail(__FILE__, __LINE__,"unexpected eof");
         }
      }

Here is the call graph for this function:

bool resip::ParseBuffer::bof ( ) const [inline]

Definition at line 108 of file ParseBuffer.hxx.

References mBuff, and mPosition.

Referenced by main(), skipBackChar(), skipBackN(), skipBackToChar(), skipBackToOneOf(), skipBackWhitespace(), and valid().

{ return mPosition <= mBuff;}
void ParseBuffer::data ( Data data,
const char *  start 
) const

make the passed in data share memory with the buffer (uses Data::Share)

Definition at line 513 of file ParseBuffer.cxx.

References fail(), resip::Data::mBuf, mBuff, resip::Data::mCapacity, mPosition, resip::Data::mShareEnum, resip::Data::mSize, resip::Data::Share, start(), and resip::Data::Take.

Referenced by data(), dataUnescaped(), resip::XMLCursor::Node::extractTag(), resip::XMLCursor::getAttributes(), resip::ConfigParse::getConfigValue(), resip::XMLCursor::getValue(), main(), resip::ConfigParse::parseCommandLine(), resip::ConfigParse::parseConfigFile(), resip::DnsNaptrRecord::RegExp::RegExp(), and resip::XMLCursor::XMLCursor().

{
   if (!(mBuff <= start && start <= mPosition))
   {
      fail(__FILE__, __LINE__,"Bad anchor position");
   }

   if (data.mShareEnum == Data::Take)
   {
      delete[] data.mBuf;
   }
   data.mSize = (unsigned int)(mPosition - start);
   data.mBuf = const_cast<char*>(start);
   data.mCapacity = data.mSize;
   data.mShareEnum = Data::Share;
}

Here is the call graph for this function:

Data ParseBuffer::data ( const char *  start) const

Definition at line 631 of file ParseBuffer.cxx.

References data(), fail(), mBuff, and mPosition.

{
   if (!(mBuff <= start && start <= mPosition))
   {
      
      fail(__FILE__, __LINE__,"Bad anchor position");
   }

   Data data(start, mPosition - start);
   return data;
}

Here is the call graph for this function:

void ParseBuffer::dataUnescaped ( Data data,
const char *  start 
) const

Definition at line 552 of file ParseBuffer.cxx.

References data(), fail(), hexToByte, resip::Data::mBuf, mBuff, resip::Data::mCapacity, mPosition, resip::Data::mSize, resip::Data::resize(), and start().

Referenced by main().

{
   if (!(mBuff <= start && start <= mPosition))
   {
      fail(__FILE__, __LINE__, "Bad anchor position");
   }

   {
      const char* current = start;   
      while (current < mPosition)
      {
         if (*current == '%')
         {
            // needs to be unencoded
            goto copy;
         }
         current++;
      }
      // can use an overlay
      data(dataToUse, start);
      return;
   }

  copy:
   if ((size_t)(mPosition-start) > dataToUse.mCapacity)
   {
      dataToUse.resize(mPosition-start, false);
   }

   char* target = dataToUse.mBuf;
   const char* current = start;   
   while (current < mPosition)
   {
      if (*current == '%')
      {
         current++;
         if (mPosition - current < 2)
         {
            fail(__FILE__, __LINE__,"Illegal escaping");
         }
         const char high = hexToByte[(unsigned char)*current];
         const char low = hexToByte[(unsigned char)*(current + 1)];
         if (high!='k' && low!='k')
         {
            unsigned char escaped = 0;            
            escaped = high << 4 | low;
            // !bwc! I think this check is bogus, especially the ':' (58) check
            // You could maybe argue that the point of %-escaping is to allow
            // the use of UTF-8 data (including ASCII that is not allowed in an 
            // on-the-wire representation of whatever it is we're unescaping),
            // and not unprintable characters (the unprintable codes are not 
            // used by UTF-8). 
            if (escaped > 31 && escaped != 127 && escaped != 58)
            {
               *target++ = escaped;
               current+= 2;
            }
            else
            {
               *target++ = '%';
               *target++ = *current++;
               *target++ = *current++;
            }
         }
         else
         {
            fail(__FILE__, __LINE__,"Illegal escaping, not hex");
         }
      }
      else
      {
         *target++ = *current++;
      }
   }
   *target = 0;
   dataToUse.mSize = target - dataToUse.mBuf;   
}

Here is the call graph for this function:

Pointer resip::ParseBuffer::end ( ) const [inline]
bool resip::ParseBuffer::eof ( ) const [inline]
void ParseBuffer::fail ( const char *  file,
unsigned int  line,
const Data errmsg = Data::Empty 
) const

Definition at line 947 of file ParseBuffer.cxx.

References DebugLog, resip::Data::Empty, escapeAndAnnotate(), mBuff, mEnd, mErrorContext, and mPosition.

Referenced by assertEof(), assertNotEof(), data(), dataUnescaped(), floatVal(), resip::XMLCursor::getAttributes(), integer(), qVal(), skipBackChar(), skipBackN(), skipChar(), skipChars(), skipN(), skipToChars(), skipToEndQuote(), uInt32(), uInt64(), uInt8(), and resip::XMLCursor::XMLCursor().

{
    Data errmsg;
    {
       DataStream ds(errmsg);
       ds << file << ":" << line
          << ", Parse failed ";

       if (detail != Data::Empty) ds << detail << ' ' ;

       ds << "in context: " << mErrorContext
          << std::endl
          << escapeAndAnnotate(mBuff, mEnd - mBuff, mPosition);
          
       ds.flush();
   }
   DebugLog(<<errmsg);
   throw ParseException(errmsg, mErrorContext, file, line);
}

Here is the call graph for this function:

float ParseBuffer::floatVal ( )

Definition at line 803 of file ParseBuffer.cxx.

References fail(), integer(), mPosition, and skipChar().

Referenced by main().

{
   const char* s = mPosition;
   try
   {
      float mant = 0.0;
      int num = integer();

      if (*mPosition == '.')
      {
         skipChar();
         const char* pos = mPosition;
         mant = float(integer());
         int s = int(mPosition - pos);
         while (s--)
         {
            mant /= 10.0;
         }
      }
      return num + mant;
   }
   catch (ParseException&)
   {
      Data msg("Expected a floating point value, got: ");
      msg += Data(s, mPosition - s);
      fail(__FILE__, __LINE__,msg);
      return 0.0;
   }
}

Here is the call graph for this function:

const Data& resip::ParseBuffer::getContext ( ) const [inline]

Definition at line 93 of file ParseBuffer.hxx.

References mErrorContext.

{return mErrorContext;}
int ParseBuffer::integer ( )

Definition at line 644 of file ParseBuffer.cxx.

References assertNotEof(), eof(), fail(), mEnd, and mPosition.

Referenced by floatVal(), main(), and qVal().

{
   if (this->eof())
   {
      fail(__FILE__, __LINE__,"Expected a digit, got eof ");
   }

   int signum = 1;
   if (*mPosition == '-')
   {
      signum = -1;
      ++mPosition;
      assertNotEof();
   }
   else if (*mPosition == '+')
   {
      ++mPosition;
      assertNotEof();
   }

   if (!isdigit(*mPosition))
   {
       Data msg("Expected a digit, got: ");
       msg += Data(mPosition, (mEnd - mPosition));
      fail(__FILE__, __LINE__,msg);
   }
   
   int num = 0;
   int last=0;
   while (!eof() && isdigit(*mPosition))
   {
      last=num;
      num = num*10 + (*mPosition-'0');
      if(last > num)
      {
         fail(__FILE__, __LINE__,"Overflow detected.");
      }
      ++mPosition;
   }
   
   return signum*num;
}

Here is the call graph for this function:

bool ParseBuffer::oneOf ( char  c,
const char *  cs 
) [static]

Definition at line 298 of file ParseBuffer.cxx.

Referenced by skipBackToOneOf(), and skipToOneOf().

{
   while (*cs)
   {
      if (c == *(cs++))
      {
         return true;
      }
   }
   return false;
}
bool ParseBuffer::oneOf ( char  c,
const Data cs 
) [static]

Definition at line 311 of file ParseBuffer.cxx.

References resip::Data::size().

{
   for (Data::size_type i = 0; i < cs.size(); i++)
   {
      if (c == cs[i])
      {
         return true;
      }
   }
   return false;
}

Here is the call graph for this function:

ParseBuffer & ParseBuffer::operator= ( const ParseBuffer other)

Definition at line 41 of file ParseBuffer.cxx.

References mBuff, mEnd, and mPosition.

{
   mBuff = rhs.mBuff;
   mPosition = rhs.mPosition;
   mEnd = rhs.mEnd;

   return *this;
}
CurrentPosition resip::ParseBuffer::position ( ) const [inline]
int ParseBuffer::qVal ( )

Definition at line 835 of file ParseBuffer.cxx.

References eof(), fail(), integer(), mPosition, and skipChar().

{
   // parse a qvalue into an integer between 0 and 1000  (ex: 1.0 -> 1000,  0.8 -> 800, 0.05 -> 50)
   const char* s = mPosition;
   try
   {
      int num = integer();
      if (num == 1)
      {
         num = 1000;
      }
      else if (num != 0)
      {
         // error: qvalue must start with 1 or 0
         return 0;
      }
      
      if (*mPosition == '.')
      {
         skipChar();
         
         int i = 100;
         while(!eof() && isdigit(*mPosition) && i)
         {
            num += (*mPosition-'0') * i;
            i /= 10;
            skipChar();
         }
      }
      return num;
   }
   catch (ParseException&)
   {
      Data msg("Expected a floating point value, got: ");
      msg += Data(s, mPosition - s);
      fail(__FILE__, __LINE__,msg);
      return 0;
   }
}

Here is the call graph for this function:

void resip::ParseBuffer::reset ( const char *  pos) [inline]

Definition at line 97 of file ParseBuffer.hxx.

References mBuff, mEnd, and mPosition.

Referenced by resip::XMLCursor::getAttributes(), main(), resip::XMLCursor::parseNextRootChild(), resip::XMLCursor::skipProlog(), and resip::XMLCursor::XMLCursor().

      {
         assert( mBuff <= mEnd);
         assert( (pos >= mBuff) && (pos <= mEnd) );
         mPosition = pos;
      }
const char * ParseBuffer::skipBackChar ( )

Definition at line 425 of file ParseBuffer.cxx.

References bof(), fail(), and mPosition.

Referenced by main().

{
   if (bof())
   {
      fail(__FILE__, __LINE__,"backed over beginning of buffer");
   }
   mPosition--;
   return mPosition;
}

Here is the call graph for this function:

const char * ParseBuffer::skipBackChar ( char  c)

Definition at line 465 of file ParseBuffer.cxx.

References bof(), fail(), and mPosition.

{
   if (bof())
   {
      fail(__FILE__, __LINE__,"backed over beginning of buffer");
   }
   if (*(--mPosition) != c)
   {
       Data msg( "Expected '");
       msg += c;
       msg += "'";
      fail(__FILE__, __LINE__,msg);
   }
   return mPosition;
}

Here is the call graph for this function:

const char* resip::ParseBuffer::skipBackN ( int  count) [inline]

Definition at line 200 of file ParseBuffer.hxx.

References bof(), fail(), and mPosition.

      {
         mPosition -= count;
         if (bof())
         { 
           fail(__FILE__, __LINE__,"backed over beginning of buffer");
         }
         return mPosition;
      }

Here is the call graph for this function:

const char * ParseBuffer::skipBackToChar ( char  c)

Definition at line 487 of file ParseBuffer.cxx.

References bof(), mBuff, and mPosition.

Referenced by resip::Log::initialize(), and main().

{
   while (!bof())
   {
      if (*(--mPosition) == c)
      {
         return ++mPosition;
      }
   }
   return mBuff;
}

Here is the call graph for this function:

const char * ParseBuffer::skipBackToOneOf ( const char *  cs)

Definition at line 500 of file ParseBuffer.cxx.

References bof(), mBuff, mPosition, and oneOf().

{
   while (!bof())
   {
      if (oneOf(*(--mPosition),cs))
      {
         return ++mPosition;
      }
   }
   return mBuff;
}

Here is the call graph for this function:

const char * ParseBuffer::skipBackWhitespace ( )

Definition at line 436 of file ParseBuffer.cxx.

References bof(), mBuff, and mPosition.

{
   while (!bof())
   {
      switch (*(--mPosition))
      {
         case ' ' :
         case '\t' : 
         case '\r' : 
         case '\n' : 
         {
            break;
         }
         default : 
            return ++mPosition;
      }
   }
   return mBuff;
}

Here is the call graph for this function:

CurrentPosition resip::ParseBuffer::skipChar ( ) [inline]
ParseBuffer::CurrentPosition ParseBuffer::skipChar ( char  c)

Definition at line 51 of file ParseBuffer.cxx.

References eof(), fail(), and mPosition.

{
   if (eof())
   {
      fail(__FILE__, __LINE__,"skipped over eof");
   }
   if (*mPosition != c)
   {
      Data msg("expected '");
      msg += c;
      msg += "'";
      fail(__FILE__, __LINE__,msg);
   }
   ++mPosition;
   return CurrentPosition(*this);
}

Here is the call graph for this function:

ParseBuffer::CurrentPosition ParseBuffer::skipChars ( const char *  cs)

Definition at line 69 of file ParseBuffer.cxx.

References eof(), fail(), and mPosition.

Referenced by main(), resip::ConfigParse::parseCommandLine(), and resip::XMLCursor::Node::skipComments().

{
   const char* match = cs;
   while (*match != 0)
   {
      if (eof() || (*match != *mPosition))
      {
          Data msg("Expected \"");
          msg += cs;
          msg +=  "\"";
         fail(__FILE__, __LINE__,msg);
      }
      match++;
      mPosition++;
   }
   return CurrentPosition(*this);
}

Here is the call graph for this function:

ParseBuffer::CurrentPosition ParseBuffer::skipChars ( const Data cs)

Definition at line 88 of file ParseBuffer.cxx.

References resip::Data::data(), eof(), fail(), mPosition, and resip::Data::size().

{
   const char* match = cs.data();
   for(Data::size_type i = 0; i < cs.size(); i++)
   {
      if (eof() || (*match != *mPosition))
      {
          Data msg( "Expected \"");
          msg += cs;
          msg += "\"";
         fail(__FILE__, __LINE__,msg);
      }
      match++;
      mPosition++;
   }
   return CurrentPosition(*this);
}

Here is the call graph for this function:

CurrentPosition resip::ParseBuffer::skipChars ( const std::bitset< 256 > &  cs) [inline]

Definition at line 148 of file ParseBuffer.hxx.

References mEnd, and mPosition.

      {
         while (mPosition < mEnd)
         {
            if (cs.test((unsigned char)(*mPosition)))
            {
               mPosition++;
            }
            else
            {
               return CurrentPosition(*this);
            }
         }
         return CurrentPosition(*this);
      }
ParseBuffer::CurrentPosition ParseBuffer::skipLWS ( )

Definition at line 153 of file ParseBuffer.cxx.

References mEnd, and mPosition.

Referenced by main().

{
   enum State {WS, CR, LF};
   State state = WS;
   while (mPosition < mEnd)
   {
      char c = *mPosition++;
      if (c == '\\')
      {
         // treat escaped CR and LF as space
         c = *mPosition++;
         if (c == '\r' || c == '\n')
         {
            c = ' ';
         }
      }
      switch (*mPosition++)
      {
         case ' ' :
         case '\t' : 
         {
            state = WS;
            break;
         }
         case '\r' : 
         {
            state = CR;
            break;
         }
         case '\n' : 
         {
            if (state == CR)
            {
               state = LF;
            }
            else
            {
               state = WS;
            }
            break;
         }
         default : 
         {
            // terminating CRLF not skipped
            if (state == LF)
            {
               mPosition -= 3;
            }
            else
            {
               mPosition--;
            }
            return CurrentPosition(*this);
         }
      }
   }
   return CurrentPosition(*this);
}
CurrentPosition resip::ParseBuffer::skipN ( int  count) [inline]

Definition at line 181 of file ParseBuffer.hxx.

References fail(), mEnd, and mPosition.

Referenced by main(), and resip::XMLCursor::skipProlog().

      {
         mPosition += count;
         if (mPosition > mEnd)
         {
            fail(__FILE__, __LINE__, "skipped eof");
         }
         return CurrentPosition(*this);
      }

Here is the call graph for this function:

ParseBuffer::CurrentPosition ParseBuffer::skipNonWhitespace ( )

Definition at line 107 of file ParseBuffer.cxx.

References assertNotEof(), mEnd, and mPosition.

Referenced by main().

{
   assertNotEof();
   while (mPosition < mEnd)
   {
      switch (*mPosition)
      {
         case ' ' :
         case '\t' : 
         case '\r' : 
         case '\n' : 
            return CurrentPosition(*this);
         default : 
            mPosition++;
      }
   }
   return CurrentPosition(*this);
}

Here is the call graph for this function:

CurrentPosition resip::ParseBuffer::skipToChar ( char  c) [inline]
ParseBuffer::CurrentPosition ParseBuffer::skipToChars ( const char *  cs)

Definition at line 235 of file ParseBuffer.cxx.

References mEnd, and mPosition.

Referenced by resip::Data::find(), main(), resip::XMLCursor::Node::skipComments(), resip::XMLCursor::skipProlog(), skipToTermCRLF(), and resip::XMLCursor::XMLCursor().

{
   assert(cs);
   unsigned int l = (unsigned int)strlen(cs);

   const char* rpos;
   const char* cpos;
   while (mPosition < mEnd)
   {
      rpos = mPosition;
      cpos = cs;
      for (unsigned int i = 0; i < l; i++)
      {
         if (*cpos++ != *rpos++)
         {
            mPosition++;
            goto skip;
         }
      }
      return CurrentPosition(*this);
     skip: ;
   }
   return CurrentPosition(*this);
}
ParseBuffer::CurrentPosition ParseBuffer::skipToChars ( const Data cs)

Definition at line 261 of file ParseBuffer.cxx.

References fail(), resip::Data::mBuf, mEnd, mPosition, and resip::Data::mSize.

{
   const char* begSub = sub.mBuf;
   const char* endSub = sub.mBuf + sub.mSize;
   if(begSub == endSub)
   {
      fail(__FILE__, __LINE__, "ParseBuffer::skipToChars() called with an "
                                 "empty string. Don't do this!");
   }

   while (true)
   {
next:
     const char* searchPos = mPosition;
     const char* subPos = sub.mBuf;

     while (subPos != endSub) 
     {
         if (searchPos == mEnd)
         {
            // nope
            mPosition = mEnd;
            return CurrentPosition(*this);
         }
         if (*subPos++ != *searchPos++)
         {
            // nope, but try the next position
            ++mPosition;
            goto next;
         }
     }
     // found a match
     return CurrentPosition(*this);
   }
}

Here is the call graph for this function:

CurrentPosition resip::ParseBuffer::skipToEnd ( ) [inline]
const char * ParseBuffer::skipToEndQuote ( char  quote = '"')

Definition at line 396 of file ParseBuffer.cxx.

References fail(), mEnd, and mPosition.

Referenced by main().

{
   while (mPosition < mEnd)
   {
      // !dlb! mark character encoding
      if (*mPosition == '\\')
      {
         mPosition += 2;
      }
      else if (*mPosition == quote)
      {
         return mPosition;
      }
      else
      {
         mPosition++;
      }
   }

   {
      Data msg("Missing '");
      msg += quote;
      msg += "'";
      fail(__FILE__,__LINE__,msg);
   }
   return 0;
}

Here is the call graph for this function:

ParseBuffer::CurrentPosition ParseBuffer::skipToOneOf ( const char *  cs)

Definition at line 324 of file ParseBuffer.cxx.

References mEnd, mPosition, and oneOf().

Referenced by resip::XMLCursor::Node::extractTag(), resip::XMLCursor::getAttributes(), resip::ConfigParse::getConfigValue(), main(), resip::ConfigParse::parseCommandLine(), and resip::ConfigParse::parseConfigFile().

{
   while (mPosition < mEnd)
   {
      if (oneOf(*mPosition, cs))
      {
         return CurrentPosition(*this);
      }
      else
      {
         mPosition++;
      }
   }
   return CurrentPosition(*this);
}

Here is the call graph for this function:

ParseBuffer::CurrentPosition ParseBuffer::skipToOneOf ( const char *  cs1,
const char *  cs2 
)

Definition at line 341 of file ParseBuffer.cxx.

References mEnd, mPosition, and oneOf().

{
   while (mPosition < mEnd)
   {
      if (oneOf(*mPosition, cs1) ||
          oneOf(*mPosition, cs2))
      {
         return CurrentPosition(*this);
      }
      else
      {
         mPosition++;
      }
   }
   return CurrentPosition(*this);
}

Here is the call graph for this function:

ParseBuffer::CurrentPosition ParseBuffer::skipToOneOf ( const Data cs)

Definition at line 360 of file ParseBuffer.cxx.

References mEnd, mPosition, and oneOf().

{
   while (mPosition < mEnd)
   {
      if (oneOf(*mPosition, cs))
      {
         return CurrentPosition(*this);
      }
      else
      {
         mPosition++;
      }
   }
   return CurrentPosition(*this);
}

Here is the call graph for this function:

ParseBuffer::CurrentPosition ParseBuffer::skipToOneOf ( const Data cs1,
const Data cs2 
)

Definition at line 377 of file ParseBuffer.cxx.

References mEnd, mPosition, and oneOf().

{
   while (mPosition < mEnd)
   {
      if (oneOf(*mPosition, cs1) ||
          oneOf(*mPosition, cs2))
      {
         return CurrentPosition(*this);
      }
      else
      {
         mPosition++;
      }
   }
   return CurrentPosition(*this);
}

Here is the call graph for this function:

CurrentPosition resip::ParseBuffer::skipToOneOf ( const std::bitset< 256 > &  cs) [inline]

Definition at line 164 of file ParseBuffer.hxx.

References mEnd, and mPosition.

      {
         while (mPosition < mEnd)
         {
            if (cs.test((unsigned char)(*mPosition)))
            {
               return CurrentPosition(*this);
            }
            else
            {
               mPosition++;
            }
         }
         return CurrentPosition(*this);
      }
ParseBuffer::CurrentPosition ParseBuffer::skipToTermCRLF ( )

Definition at line 214 of file ParseBuffer.cxx.

References CRLF, mBuff, mEnd, mPosition, and skipToChars().

Referenced by main().

{
   while (mPosition < mEnd)
   {
      skipToChars(CRLF);
      mPosition += 2;
      if ((*mPosition != ' ' &&
           *mPosition != '\t' &&
           // check for \CRLF -- not terminating
           //           \\CRLF -- terminating
           ((mPosition-3 < mBuff || *(mPosition-3) != '\\') ||
            (mPosition-4 > mBuff && *(mPosition-4) == '\\'))))
      {
         mPosition -= 2;
         return CurrentPosition(*this);
      }
   }
   return CurrentPosition(*this);
}

Here is the call graph for this function:

ParseBuffer::CurrentPosition ParseBuffer::skipWhitespace ( )

Definition at line 127 of file ParseBuffer.cxx.

References mEnd, and mPosition.

Referenced by resip::XMLCursor::getAttributes(), resip::ConfigParse::getConfigValue(), main(), resip::ConfigParse::parseConfigFile(), resip::XMLCursor::parseNextRootChild(), resip::XMLCursor::Node::skipComments(), resip::XMLCursor::skipProlog(), and resip::XMLCursor::XMLCursor().

{
   while (mPosition < mEnd)
   {
      switch (*mPosition)
      {
         case ' ' :
         case '\t' : 
         case '\r' : 
         case '\n' : 
         {
            mPosition++;
            break;
         }
         default : 
            return CurrentPosition(*this);
      }
   }
   return CurrentPosition(*this);
}
Pointer resip::ParseBuffer::start ( ) const [inline]

Definition at line 110 of file ParseBuffer.hxx.

References eof(), and mBuff.

Referenced by data(), dataUnescaped(), resip::Data::find(), resip::XMLCursor::getAttributes(), resip::XMLCursor::getValue(), resip::operator<<(), resip::XMLCursor::parseNextRootChild(), and resip::XMLCursor::XMLCursor().

{ return Pointer(*this, mBuff, eof()); }

Here is the call graph for this function:

UInt32 ParseBuffer::uInt32 ( )

dcm! -- merge these, ask about length checks

Definition at line 714 of file ParseBuffer.cxx.

References eof(), fail(), and mPosition.

Referenced by unsignedInteger().

{
   const char* begin=mPosition;
   UInt32 num = 0;
   while (!eof() && isdigit(*mPosition))
   {
      num = num*10 + (*mPosition-'0');
      ++mPosition;
   }

   switch(mPosition-begin)
   {
      case 0:
         fail(__FILE__, __LINE__,"Expected a digit");
      case 1:
      case 2:
      case 3:
      case 4:
      case 5:
      case 6:
      case 7:
      case 8:
      case 9:
         break;
      case 10:
         if(*begin<'4')
         {
            break;
         }
         else if(*begin=='4' && num >= 4000000000UL)
         {
            break;
         }
      default:
         fail(__FILE__, __LINE__,"Overflow detected");
   }

   return num;
}

Here is the call graph for this function:

UInt64 ParseBuffer::uInt64 ( )

Definition at line 755 of file ParseBuffer.cxx.

References eof(), fail(), and mPosition.

Referenced by main(), and unsignedLongLong().

{
   const char* begin=mPosition;
   UInt64 num = 0;
   while (!eof() && isdigit(*mPosition))
   {
      num = num*10 + (*mPosition-'0');
      ++mPosition;
   }

   switch(mPosition-begin)
   {
      case 0:
         fail(__FILE__, __LINE__,"Expected a digit");
      case 1:
      case 2:
      case 3:
      case 4:
      case 5:
      case 6:
      case 7:
      case 8:
      case 9:
      case 10:
      case 11:
      case 12:
      case 13:
      case 14:
      case 15:
      case 16:
      case 17:
      case 18:
      case 19:
         break;
      case 20:
         if(*begin=='1' && num >= 10000000000000000000ULL)
         {
            break;
         }
      default:
         fail(__FILE__, __LINE__,"Overflow detected");
   }

   return num;
}

Here is the call graph for this function:

UInt8 ParseBuffer::uInt8 ( )

Definition at line 688 of file ParseBuffer.cxx.

References eof(), fail(), and mPosition.

{
   const char* begin=mPosition;
   UInt8 num = 0;
   UInt8 last = 0;
   while (!eof() && isdigit(*mPosition))
   {
      last = num;
      num = num*10 + (*mPosition-'0');
      if(last>num)
      {
         fail(__FILE__, __LINE__,"Overflow detected.");
      }
      ++mPosition;
   }
   
   if(mPosition==begin)
   {
      fail(__FILE__, __LINE__,"Expected a digit");
   }
   return num;
}

Here is the call graph for this function:

RESIP_DEPRECATED unsigned long resip::ParseBuffer::unsignedInteger ( ) [inline]

Definition at line 248 of file ParseBuffer.hxx.

References uInt32().

{return uInt32();}

Here is the call graph for this function:

RESIP_DEPRECATED UInt64 resip::ParseBuffer::unsignedLongLong ( ) [inline]

Definition at line 247 of file ParseBuffer.hxx.

References uInt64().

{return uInt64();} 

Here is the call graph for this function:

bool resip::ParseBuffer::valid ( ) const [inline]

Definition at line 109 of file ParseBuffer.hxx.

References bof(), and eof().

{return (!eof()) && (!bof());}

Here is the call graph for this function:


Friends And Related Function Documentation

friend class ParseBuffer::CurrentPosition [friend]

Definition at line 260 of file ParseBuffer.hxx.


Member Data Documentation

const char* resip::ParseBuffer::mBuff [private]
const char* resip::ParseBuffer::mEnd [private]

Definition at line 264 of file ParseBuffer.hxx.

Referenced by fail(), and getContext().

const char* resip::ParseBuffer::mPosition [private]
const char * ParseBuffer::ParamTerm = ";?" [static]

Definition at line 258 of file ParseBuffer.hxx.

const char * ParseBuffer::Whitespace = " \t\r\n" [static]

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