|
reSIProcate/rutil
9694
|
An alternative to std::string, encapsulates an arbitrary buffer of bytes. More...
#include <Data.hxx>

Classes | |
| class | PreallocateType |
Public Types | |
| enum | DoubleDigitPrecision { ZeroDigitPrecision = 0, OneDigitPrecision, TwoDigitPrecision, ThreeDigitPrecision, FourDigitPrecision, FiveDigitPrecision, SixDigitPrecision, SevenDigitPrecision, EightDigitPrecision, NineDigitPrecision, TenDigitPrecision, MaxDigitPrecision } |
| enum | ShareEnum { Borrow = 0, Share = 1, Take = 2 } |
| The various memory management behaviors. More... | |
| enum | EncodingType { BINARY, BASE64, HEX } |
| typedef UInt32 | size_type |
Public Member Functions | |
| RESIP_HeapCount (Data) | |
| Data () | |
| Data (size_type capacity, const PreallocateType &) | |
| Creates a data with a specified initial capacity. | |
| Data (const char *str) | |
| Creates a data with a copy of the contents of the null-terminated string. | |
| Data (const char *buffer, size_type length) | |
| Creates a data with the contents of the buffer. | |
| Data (const unsigned char *buffer, size_type length) | |
| Creates a data with the contents of the buffer. | |
| Data (const Data &data) | |
| Data (const std::string &str) | |
| Creates a data with the contents of the string. | |
| Data (int value) | |
| Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value. | |
| Data (unsigned long value) | |
| Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value. | |
| Data (unsigned int value) | |
| Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value. | |
| Data (UInt64 value) | |
| Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value. | |
| Data (double value, Data::DoubleDigitPrecision precision=FourDigitPrecision) | |
| Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value. | |
| Data (bool value) | |
| Creates a buffer containing "true" or "false", depending on the value of "value". | |
| Data (char c) | |
| Creates a buffer containing a single character. | |
| Data (ShareEnum, const char *buffer, size_type length) | |
| Creates a Data from the passed-in buffer. | |
| Data (ShareEnum, const char *buffer) | |
| Takes a null-terminated string and creates a buffer. | |
| Data (ShareEnum, const Data &staticData) | |
| Lazily creates a Data from the passed-in Data. | |
| ~Data () | |
| Data & | setBuf (ShareEnum se, const char *buf, size_type length) |
| Set the Data to hold {buf} using share type {se}, which may be any of Share (read-only, no-free), Borrow (read-write, no-free) or Take (read-write, yes-free). | |
| Data & | setBuf (ShareEnum se, const char *str) |
| Convience function to call setBuf() with a NULL-terminated string. | |
| Data & | takeBuf (Data &other) |
| Take the data from {other}. | |
| Data & | copy (const char *buf, size_type length) |
| Functional equivalent of: *this = Data(buf, length) but avoid the intermediate allocation and free. | |
| char * | getBuf (size_type length) |
| Set size to be exactly {length}, extending buffer if needed. | |
| Data & | operator= (const Data &data) |
| Data & | operator= (const char *str) |
| Assigns a null-terminated string to the buffer. | |
| Data | operator+ (const Data &rhs) const |
| Concatenates two Data objects. | |
| Data | operator+ (const char *str) const |
| Concatenates a null-terminated string after the Data object. | |
| Data | operator+ (char c) const |
| Concatenates a single byte after Data object. | |
| Data & | operator+= (const Data &rhs) |
| Appends a data object to this one. | |
| Data & | operator+= (const char *str) |
| Appends a null-terminated string to the end of the Data object. | |
| Data & | operator+= (char c) |
| Appends a single byte to the Data object. | |
| Data & | operator^= (const Data &rhs) |
| Performs an in-place exclusive-or of this buffer buffer with the specified buffer. | |
| char & | operator[] (size_type p) |
| Returns the character at the specified position. | |
| char | operator[] (size_type p) const |
| Returns the character at the specified position. | |
| char & | at (size_type p) |
| Returns the character at the specified position. | |
| void | reserve (size_type capacity) |
| Guarantees that the underlying buffer used by the Data is at least the number of bytes specified. | |
| Data & | append (const char *str, size_type len) |
| Appends the specified number of bytes to the end of this Data. | |
| size_type | truncate (size_type len) |
| Shortens the size of this Data. | |
| Data & | truncate2 (size_type len) |
| Shortens the size of this Data so length is at most of {len}. | |
| bool | empty () const |
| Checks whether the Data is empty. | |
| size_type | size () const |
| Returns the number of bytes in this Data. | |
| const char * | data () const |
| Returns a pointer to the contents of this Data. | |
| const char * | c_str () const |
| Returns a null-terminated string representing. | |
| const char * | begin () const |
| Returns a pointer to the beginning of the buffer used by the Data. | |
| const char * | end () const |
| Returns a pointer to the end of the buffer used by the Data. | |
| Data | md5 (EncodingType type=HEX) const |
| Computes the MD5 hash of the current data. | |
| Data & | lowercase () |
| Converts this Data to lowercase. | |
| Data & | uppercase () |
| Converts this Data to uppercase. | |
| Data & | schemeLowercase () |
| Converts this Data to lowercase, assuming this Data only consists of scheme characters. | |
| Data | hex () const |
| Returns a hexadecimal representation of the contents of this Data. | |
| Data | escaped () const |
| Returns a representation of the contents of the data with any non-printable characters escaped. | |
| Data | charEncoded () const |
| Performs RFC 3261 escaping of SIP URIs. | |
| Data | charUnencoded () const |
| Performs RFC 3261 un-escaping of SIP URIs. | |
| Data | urlEncoded () const |
| Performs in-place HTTP URL escaping of a Data. | |
| Data | urlDecoded () const |
| Performs in-place HTTP URL un-escaping of a Data. | |
| EncodeStream & | urlEncode (EncodeStream &s) const |
| Escapes a Data to a stream according to HTTP URL encoding rules. | |
| EncodeStream & | urlDecode (EncodeStream &s) const |
| Un-escapes a Data to a stream according to HTTP URL encoding rules. | |
| Data | xmlCharDataEncode () const |
| Performs in-place XML Character Data escaping of a Data. | |
| Data | xmlCharDataDecode () const |
| Performs in-place XML Character Data un-escaping of a Data. | |
| EncodeStream & | xmlCharDataEncode (EncodeStream &s) const |
| Escapes a Data to a stream according to XML Character Data encoding rules. | |
| EncodeStream & | xmlCharDataDecode (EncodeStream &s) const |
| Un-escapes a Data to a stream according to XML Character Data encoding rules. | |
| Data | trunc (size_type trunc) const |
| Shortens the size of this Data. | |
| Data & | clear () |
| Clears the contents of this Data. | |
| int | convertInt () const |
| Takes the contents of the Data and converts them to an integer. | |
| unsigned long | convertUnsignedLong () const |
| size_t | convertSize () const |
| Takes the contents of the Data and converts them to a size_t. | |
| double | convertDouble () const |
| Takes the contents of the Data and converts them to a double precision floating point value. | |
| UInt64 | convertUInt64 () const |
| Takes the contents of the Data and converts them to an unsigned 64-bit integer. | |
| bool | prefix (const Data &pre) const |
| Returns true if this Data starts with the bytes indicated by the passed-in Data. | |
| bool | postfix (const Data &post) const |
| Returns true if this Data ends with the bytes indicated by the passed-in Data. | |
| Data | substr (size_type first, size_type count=Data::npos) const |
| Copies a portion of this Data into a new Data. | |
| size_type | find (const Data &match, size_type start=0) const |
| Finds a specified sequence of bytes in this Data. | |
| int | replace (const Data &match, const Data &target, int max=INT_MAX) |
| Replaces up to max occurrences of the bytes match with target. | |
| Data | base64decode () const |
| Performs RFC 3548 Base 64 decoding of the contents of this data. | |
| Data | base64encode (bool useUrlSafe=false) const |
| Performs RFC 3548 Base 64 encoding of the contents of this data. | |
| size_t | hash () const |
| Creates a 32-bit hash based on the contents of this Data. | |
| size_t | caseInsensitivehash () const |
| Creates a 32-bit hash based on the contents of this Data, after normalizing any alphabetic characters to lowercase. | |
| size_t | caseInsensitiveTokenHash () const |
| A faster version of caseInsensitiveHash that has the same collision properties if this Data is made up of RFC 3261 token characters. | |
| bool | caseInsensitiveTokenCompare (const Data &rhs) const |
| bool | sizeEqualCaseInsensitiveTokenCompare (const Data &rhs) const |
| template<class Predicate > | |
| EncodeStream & | escapeToStream (EncodeStream &str, Predicate shouldEscape) const |
| Performs escaping of this Data according to the indicated Predicate. | |
| std::ostream & | escapeToStream (std::ostream &str, const std::bitset< 256 > &shouldEscape) const |
| Performs escaping of this Data according to a bitset. | |
Static Public Member Functions | |
| template<class T > | |
| static Data | from (const T &x) |
| Converts from arbitrary other type to Data. | |
| static bool | init (DataLocalSize< RESIP_DATA_LOCAL_SIZE > arg) |
| Initializes Data class. | |
| static size_t | rawHash (const unsigned char *c, size_t size) |
| Creates a 32-bit hash based on the contents of the indicated buffer. | |
| static size_t | rawCaseInsensitiveHash (const unsigned char *c, size_t size) |
| Creates a 32-bit hash based on the contents of the indicated buffer, after normalizing any alphabetic characters to lowercase. | |
| static size_t | rawCaseInsensitiveTokenHash (const unsigned char *c, size_t size) |
| A faster version of rawCaseInsensitiveHash that has the same collision properties if this Data is made up of RFC 3261 token characters. | |
| static std::bitset< 256 > | toBitset (const resip::Data &chars) |
| Creates a bitset reflecting the contents of this data (as a set) ie. | |
Static Public Attributes | |
| static const PreallocateType | Preallocate |
| used only to disambiguate constructors | |
| static const Data | Empty |
| Constant that represents a zero-length data. | |
| static const size_type | npos = UINT_MAX |
| Represents an impossible position; returned to indicate failure to find. | |
Private Types | |
| enum | { LocalAlloc = RESIP_DATA_LOCAL_SIZE } |
| Trade off between in-object and heap allocation Larger LocalAlloc makes for larger objects that have Data members but bulk allocation/deallocation of Data members. More... | |
Private Member Functions | |
| Data (const char *buffer, size_type length, bool) | |
| void | own () const |
| Copies the contents of this data to a new buffer if the Data does not own the current buffer. | |
| void | resize (size_type newSize, bool copy) |
Static Private Member Functions | |
| static bool | isHex (unsigned char c) |
Private Attributes | |
| char * | mBuf |
| size_type | mSize |
| size_type | mCapacity |
| char | mPreBuffer [LocalAlloc] |
| size_type | mShareEnum |
Friends | |
| class | ParseBuffer |
| class | DataBuffer |
| class | DataStream |
| class | oDataStream |
| class | ::TestData |
| class | MD5Buffer |
| bool | operator== (const Data &lhs, const Data &rhs) |
| bool | operator== (const Data &lhs, const char *rhs) |
| bool | operator< (const Data &lhs, const Data &rhs) |
| bool | operator< (const Data &lhs, const char *rhs) |
| bool | operator< (const char *lhs, const Data &rhs) |
| std::ostream & | operator<< (std::ostream &strm, const Data &d) |
| EncodeStream & | operator<< (EncodeStream &strm, const Data &d) |
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
It has a variety of memory management styles that can be established at contruction time and changed later via setBuf().
Three modes of allocation are currently available:
Additionally, Data has a small locally-allocated buffer (member buffer) that it will use to hold small amounts of data. By default, this buffer can contain 16 bytes, meaning that Data will not use the heap unless it needs more than 16 bytes of space. The tradeoff here, of course, is that instances of Data will be larger than instances of std::string. Generally speaking, if you expect to need more than 16 bytes of room, and you cannot make good use of the flexible memory management offered by Data, you may want to use a std::string instead.
| typedef UInt32 resip::Data::size_type |
anonymous enum [private] |
The various memory management behaviors.
| Borrow |
The Data instance is borrowing the memory from the passed in buffer. It will modify its contents as necessary, but will not deallocate it. |
| Share |
The Data instance will use the buffer in a read-only mode. If any attempt is made to modify the contents of the Data, it will copy the buffer and modify it. |
| Take |
The Data instance takes complete ownership of the buffer. The buffer must have been allocate using "new char[]" so that it can be freed with "delete char[]". |
| resip::Data::Data | ( | ) | [inline] |
Definition at line 93 of file Data.hxx.
Referenced by base64encode(), substr(), and trunc().
: mBuf(mPreBuffer), mSize(0), mCapacity(LocalAlloc), mShareEnum(Borrow) { mBuf[mSize] = 0; }
| Data::Data | ( | size_type | capacity, |
| const PreallocateType & | |||
| ) |
Creates a data with a specified initial capacity.
| capacity | The initial capacity of the buffer |
| foo | This parameter is ignored; it is merely used to disambuguate this constructor from the constructor that takes a single int. Always pass Data::Preallocate. |
Definition at line 193 of file Data.cxx.
: mBuf(capacity > LocalAlloc ? new char[capacity + 1] : mPreBuffer), mSize(0), mCapacity(capacity > LocalAlloc ? capacity : LocalAlloc), mShareEnum(capacity > LocalAlloc ? Take : Borrow) { assert( capacity >= 0 ); mBuf[mSize] = 0; }
| Data::Data | ( | const char * | str | ) |
Creates a data with a copy of the contents of the null-terminated string.
Definition at line 304 of file Data.cxx.
References LocalAlloc, mBuf, mPreBuffer, and mSize.
: mSize(str ? strlen(str) : 0), mCapacity(mSize > LocalAlloc ? mSize : LocalAlloc), mShareEnum(mSize > LocalAlloc ? Take : Borrow) { if(mSize > LocalAlloc) { mBuf = new char[mSize+1]; } else { mBuf = mPreBuffer; } if (str) { memcpy(mBuf, str, mSize+1); } else { mBuf[mSize] = 0; } }
| Data::Data | ( | const char * | buffer, |
| size_type | length | ||
| ) |
Creates a data with the contents of the buffer.
| length | Number of bytes in the buffer |
Definition at line 225 of file Data.cxx.
: mBuf(length > LocalAlloc ? new char[length + 1] : mPreBuffer), mSize(length), mCapacity(mSize > LocalAlloc ? mSize : LocalAlloc), mShareEnum(mSize > LocalAlloc ? Take : Borrow) { if (mSize > 0) { assert(str); memcpy(mBuf, str, mSize); } mBuf[mSize]=0; }
| Data::Data | ( | const unsigned char * | buffer, |
| size_type | length | ||
| ) |
Creates a data with the contents of the buffer.
| length | Number of bytes in the buffer |
Definition at line 243 of file Data.cxx.
: mBuf(length > LocalAlloc ? new char[length + 1] : mPreBuffer), mSize(length), mCapacity(mSize > LocalAlloc ? mSize : LocalAlloc), mShareEnum(mSize > LocalAlloc ? Take : Borrow) { if (mSize > 0) { assert(str); memcpy(mBuf, str, mSize); } mBuf[mSize]=0; }
| Data::Data | ( | const Data & | data | ) |
Definition at line 343 of file Data.cxx.
: mBuf(data.mSize > LocalAlloc ? new char[data.mSize + 1] : mPreBuffer), mSize(data.mSize), mCapacity(mSize > LocalAlloc ? mSize : LocalAlloc), mShareEnum(mSize > LocalAlloc ? Take : Borrow) { if (mSize) { memcpy(mBuf, data.mBuf, mSize); } mBuf[mSize] = 0; }
| resip::Data::Data | ( | const std::string & | str | ) | [explicit] |
Creates a data with the contents of the string.
| Data::Data | ( | int | value | ) | [explicit] |
Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value.
(E.g. "Data(75)" will create a Data with length=2, and contents of 0x37 0x35).
Definition at line 371 of file Data.cxx.
: mBuf(IntMaxSize > LocalAlloc ? new char[IntMaxSize + 1] : mPreBuffer), mSize(0), mCapacity(IntMaxSize > LocalAlloc ? IntMaxSize : LocalAlloc), mShareEnum(IntMaxSize > LocalAlloc ? Take : Borrow) { if (val == 0) { mBuf[0] = '0'; mBuf[1] = 0; mSize = 1; return; } bool neg = false; int value = val; if (value < 0) { value = -value; neg = true; } int c = 0; int v = value; while (v /= 10) { ++c; } if (neg) { ++c; } mSize = c+1; mBuf[c+1] = 0; v = value; while (v) { mBuf[c--] = '0' + v%10; v /= 10; } if (neg) { mBuf[0] = '-'; } }
| Data::Data | ( | unsigned long | value | ) | [explicit] |
Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value.
(E.g. "Data(75)" will create a Data with length=2, and contents of 0x37 0x35).
Definition at line 427 of file Data.cxx.
: mBuf(MaxLongSize > LocalAlloc ? new char[MaxLongSize + 1] : mPreBuffer), mSize(0), mCapacity(MaxLongSize > LocalAlloc ? MaxLongSize : LocalAlloc), mShareEnum(MaxLongSize > LocalAlloc ? Take : Borrow) { if (value == 0) { mBuf[0] = '0'; mBuf[1] = 0; mSize = 1; return; } int c = 0; unsigned long v = value; while (v /= 10) { ++c; } mSize = c+1; mBuf[c+1] = 0; v = value; while (v) { unsigned int digit = v%10; unsigned char d = (char)digit; mBuf[c--] = '0' + d; v /= 10; } }
| Data::Data | ( | unsigned int | value | ) | [explicit] |
Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value.
(E.g. "Data(75)" will create a Data with length=2, and contents of 0x37 0x35).
Definition at line 554 of file Data.cxx.
: mBuf(IntMaxSize > LocalAlloc ? new char[IntMaxSize + 1] : mPreBuffer), mSize(0), mCapacity(IntMaxSize > LocalAlloc ? IntMaxSize : LocalAlloc), mShareEnum(IntMaxSize > LocalAlloc ? Take : Borrow) { if (value == 0) { mBuf[0] = '0'; mBuf[1] = 0; mSize = 1; return; } int c = 0; unsigned long v = value; while (v /= 10) { ++c; } mSize = c+1; mBuf[c+1] = 0; v = value; while (v) { unsigned int digit = v%10; unsigned char d = (char)digit; mBuf[c--] = '0' + d; v /= 10; } }
| Data::Data | ( | UInt64 | value | ) | [explicit] |
Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value.
(E.g. "Data(75)" will create a Data with length=2, and contents of 0x37 0x35).
Definition at line 595 of file Data.cxx.
: mBuf(UInt64MaxSize > LocalAlloc ? new char[UInt64MaxSize + 1] : mPreBuffer), mSize(0), mCapacity(UInt64MaxSize > LocalAlloc ? UInt64MaxSize : LocalAlloc), mShareEnum(UInt64MaxSize > LocalAlloc ? Take : Borrow) { if (value == 0) { mBuf[0] = '0'; mBuf[1] = 0; mSize = 1; return; } int c = 0; UInt64 v = value; while (v /= 10) { ++c; } mSize = c+1; mBuf[c+1] = 0; v = value; while (v) { UInt64 digit = v%10; unsigned char d = (char)digit; mBuf[c--] = '0' + d; v /= 10; } }
| Data::Data | ( | double | value, |
| Data::DoubleDigitPrecision | precision = FourDigitPrecision |
||
| ) | [explicit] |
Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value.
(E.g. "Data(75.4,2)" will create a Data with length=4, and contents of 0x37 0x35 0x2E 0x34).
| precision | Number of digits after the decimal point. Trailing zeros will be removed. |
Definition at line 467 of file Data.cxx.
References MaxDigitPrecision, mBuf, mCapacity, mSize, Preallocate, resize(), and size().
: mBuf(DoubleMaxSize + precision > LocalAlloc ? new char[DoubleMaxSize + precision + 1] : mPreBuffer), mSize(0), mCapacity(DoubleMaxSize + precision > LocalAlloc ? DoubleMaxSize + precision : LocalAlloc), mShareEnum(DoubleMaxSize + precision > LocalAlloc ? Take : Borrow) { assert(precision >= 0); assert(precision < MaxDigitPrecision); double v = value; bool neg = (value < 0.0); if (neg) { v = -v; } Data m((unsigned long)v); // remainder v = v - floor(v); int p = precision; while (p--) { v *= 10; } int dec = (int)floor(v+0.5); Data d(precision, Data::Preallocate); if (dec == 0) { d = "0"; } else { d.mBuf[precision] = 0; p = precision; // neglect trailing zeros bool significant = false; while (p--) { if (dec % 10 || significant) { significant = true; ++d.mSize; d.mBuf[p] = '0' + (dec % 10); } else { d.mBuf[p] = 0; } dec /= 10; } } if (neg) { mBuf[0] = '-'; memcpy(mBuf+1, m.mBuf, m.size()); mBuf[1+m.size()] = '.'; memcpy(mBuf+1+m.size()+1, d.mBuf, d.size()+1); mSize = m.size() + d.size() + 2; } else { if (mCapacity < m.size() + d.size() + 1) { resize(m.size() + d.size() + 1, false); } memcpy(mBuf, m.mBuf, m.size()); mBuf[m.size()] = '.'; memcpy(mBuf+m.size()+1, d.mBuf, d.size()+1); mSize = m.size() + d.size() + 1; } assert(mBuf[mSize] == 0); }

| Data::Data | ( | bool | value | ) | [explicit] |
| Data::Data | ( | char | c | ) | [explicit] |
Creates a buffer containing a single character.
Is this silly? Maybe. Perhaps it can be removed.
Definition at line 634 of file Data.cxx.
References mBuf.
: mBuf(CharMaxSize > LocalAlloc ? new char[CharMaxSize + 1] : mPreBuffer), mSize(1), mCapacity(CharMaxSize > LocalAlloc ? CharMaxSize : LocalAlloc), mShareEnum(CharMaxSize > LocalAlloc ? Take : Borrow) { mBuf[0] = c; mBuf[1] = 0; }
| Data::Data | ( | ShareEnum | se, |
| const char * | buffer | ||
| ) |
Takes a null-terminated string and creates a buffer.
Definition at line 282 of file Data.cxx.
: mBuf(const_cast<char*>(buffer)), mSize(strlen(buffer)), mCapacity(mSize), mShareEnum(se) { assert(buffer); }
Lazily creates a Data from the passed-in Data.
Definition at line 291 of file Data.cxx.
References Share.
| resip::Data::~Data | ( | ) | [inline] |
Definition at line 308 of file Data.hxx.
References mBuf, mShareEnum, and Take.
{
if (mShareEnum == Take)
{
delete[] mBuf;
}
}
| Data::Data | ( | const char * | buffer, |
| size_type | length, | ||
| bool | |||
| ) | [private] |
Appends the specified number of bytes to the end of this Data.
Definition at line 1021 of file Data.cxx.
References mBuf, mCapacity, mShareEnum, mSize, resize(), and Share.
Referenced by resip::DnsUtil::inet_ntop(), TestData::main(), and operator+=().
{
assert(str);
if (mCapacity <= mSize + len) // append null terminates, thus the equality
{
// .dlb. pad for future growth?
resize(((mSize + len +16)*3)/2, true);
}
else
{
if (mShareEnum == Share)
{
resize(mSize + len, true);
}
}
// could conceivably overlap
memmove(mBuf + mSize, str, len);
mSize += len;
mBuf[mSize] = 0;
return *this;
}

| char & Data::at | ( | size_type | p | ) |
Returns the character at the specified position.
Definition at line 951 of file Data.cxx.
References mBuf, mCapacity, mSize, own(), and resize().
Referenced by resip::ConfigParse::parseCommandLine(), and resip::Log::timestamp().
{
if (p >= mCapacity)
{
resize(p+1, true);
}
else
{
own();
if (p > mSize)
{
mSize = p + 1;
mBuf[mSize] = 0;
}
}
return mBuf[p];
}

| Data Data::base64decode | ( | ) | const |
Performs RFC 3548 Base 64 decoding of the contents of this data.
Definition at line 2294 of file Data.cxx.
References base64Lookup, resip::Base64Coder::decode(), mBuf, reserve(), and size().
Referenced by resip::Base64Coder::decode(), and TestData::main().
{
// see RFC 3548
// this will decode normal and URL safe alphabet
#if 0
return Base64Coder::decode( *this );
#else
int wc=0;
int val=0;
Data bin;
bin.reserve( size()*3/4 );
for( unsigned int i=0; i<size(); i++ )
{
unsigned int x = mBuf[i] & 0x7F;
char c1,c2,c3;
int v = base64Lookup[x];
if ( v >= 0 )
{
val = val << 6;
val |= v;
wc++;
if ( wc == 4 )
{
c3 = char( val & 0xFF ); val = val >> 8;
c2 = char( val & 0xFF ); val = val >> 8;
c1 = char( val & 0xFF ); val = val >> 8;
bin += c1;
bin += c2;
bin += c3;
wc=0;
val=0;
}
}
if ( base64Lookup[x] == -2 )
{
if (wc==2) val = val<<12;
if (wc==3) val = val<<6;
c3 = char( val & 0xFF ); val = val >> 8;
c2 = char( val & 0xFF ); val = val >> 8;
c1 = char( val & 0xFF ); val = val >> 8;
unsigned int xNext = mBuf[i] & 0x7F;
if ( (i+1<size() ) && ( base64Lookup[xNext] == -2 ))
{
bin += c1;
i++;
}
else
{
bin += c1;
bin += c2;
}
break;
}
}
return bin;
#endif
}

| Data Data::base64encode | ( | bool | useUrlSafe = false | ) | const |
Performs RFC 3548 Base 64 encoding of the contents of this data.
Definition at line 2369 of file Data.cxx.
References codeCharSafe, codeCharUnsafe, Data(), data(), size(), and Take.
Referenced by resip::Base64Coder::encode(), TestData::main(), and md5().
{
unsigned char* codeChar = useSafeSet ? codeCharSafe : codeCharUnsafe;
int srcLength = (int)this->size();
unsigned int dstLimitLength = srcLength*4/3 + 1 + 2; // +2 for the == chars
unsigned char * dstData = new unsigned char[dstLimitLength];
unsigned int dstIndex = 0;
const char * p = static_cast<const char *>( this->data() );
for(int index=0;index<srcLength;index+=3)
{
unsigned char codeBits = (p[index] & 0xfc)>>2;
assert(codeBits < 64);
dstData[dstIndex++] = codeChar[codeBits]; // c0 output
assert(dstIndex <= dstLimitLength);
// do second codeBits
codeBits = ((p[index]&0x3)<<4);
if (index+1 < srcLength)
{
codeBits |= ((p[index+1]&0xf0)>>4);
}
assert(codeBits < 64);
dstData[dstIndex++] = codeChar[codeBits]; // c1 output
assert(dstIndex <= dstLimitLength);
if (index+1 >= srcLength)
{
dstData[dstIndex++] = codeChar[64];
assert(dstIndex <= dstLimitLength);
dstData[dstIndex++] = codeChar[64];
assert(dstIndex <= dstLimitLength);
break; // encoded d0 only
}
// do third codeBits
codeBits = ((p[index+1]&0xf)<<2);
if (index+2 < srcLength)
{
codeBits |= ((p[index+2]&0xc0)>>6);
}
assert(codeBits < 64);
dstData[dstIndex++] = codeChar[codeBits]; // c2 output
assert(dstIndex <= dstLimitLength);
if (index+2 >= srcLength)
{
dstData[dstIndex++] = codeChar[64];
assert(dstIndex <= dstLimitLength);
break; // encoded d0 d1 only
}
// do fourth codeBits
codeBits = ((p[index+2]&0x3f));
assert(codeBits < 64);
dstData[dstIndex++] = codeChar[codeBits]; // c3 output
assert(dstIndex <= dstLimitLength);
// outputed all d0,d1, and d2
}
return Data(Data::Take, reinterpret_cast<char*>(dstData),
dstIndex);
}

| const char* resip::Data::begin | ( | ) | const [inline] |
| const char * Data::c_str | ( | ) | const |
Returns a null-terminated string representing.
Definition at line 1060 of file Data.cxx.
References mBuf, mCapacity, mShareEnum, mSize, resize(), and Share.
Referenced by resip::ServerProcess::daemonize(), resip::getTransportNameFromType(), resip::getTransportNameFromTypeLower(), resip::DnsStub::Query::go(), resip::DnsUtil::inet_pton(), resip::Log::ThreadData::Instance(), resip::FileSystem::Directory::iterator::iterator(), resip::DnsUtil::lookupARecords(), resip::DnsStub::lookupRecords(), main(), TestData::main(), resip::Log::OutputToWin32DebugWindow(), and resip::ConfigParse::parseConfigFile().
{
if (mShareEnum == Data::Share || mSize == mCapacity)
{
const_cast<Data*>(this)->resize(mSize+1,true);
}
// mostly is zero terminated, but not by DataStream
mBuf[mSize] = 0;
return mBuf;
}

| size_t Data::caseInsensitivehash | ( | ) | const |
Creates a 32-bit hash based on the contents of this Data, after normalizing any alphabetic characters to lowercase.
Definition at line 2110 of file Data.cxx.
References data(), rawCaseInsensitiveHash(), and size().
Referenced by TestData::main().
{
return rawCaseInsensitiveHash((const unsigned char*)(this->data()), this->size());
}

| bool resip::Data::caseInsensitiveTokenCompare | ( | const Data & | rhs | ) | const [inline] |
Definition at line 891 of file Data.hxx.
References mSize, and sizeEqualCaseInsensitiveTokenCompare().
Referenced by resip::isTokenEqualNoCase(), and TestData::main().
{
if(mSize==rhs.mSize)
{
return sizeEqualCaseInsensitiveTokenCompare(rhs);
}
return false;
}

| size_t Data::caseInsensitiveTokenHash | ( | ) | const |
A faster version of caseInsensitiveHash that has the same collision properties if this Data is made up of RFC 3261 token characters.
Definition at line 2116 of file Data.cxx.
References data(), rawCaseInsensitiveTokenHash(), and size().
Referenced by TestData::main().
{
return rawCaseInsensitiveTokenHash((const unsigned char*)(this->data()), this->size());
}

| Data Data::charEncoded | ( | ) | const |
Performs RFC 3261 escaping of SIP URIs.
Definition at line 1185 of file Data.cxx.
References data(), hexmap, Preallocate, and size().
Referenced by TestData::main().
{
Data ret((int)((size()*11)/10), Data::Preallocate);
const char* p = data();
for (size_type i=0; i < size(); ++i)
{
unsigned char c = *p++;
if ( c == 0x0d )
{
if ( i+1 < size() )
{
if ( *p == 0x0a )
{
// found a CRLF sequence
ret += c;
c = *p++; i++;
ret += c;
continue;
}
}
}
if ( !isprint(c) ||
// rfc 3261 reserved + mark + space + tab
strchr(" \";/?:@&=+%$,\t-_.!~*'()", c))
{
ret +='%';
int hi = (c & 0xF0)>>4;
int low = (c & 0x0F);
ret += hexmap[hi];
ret += hexmap[low];
}
else
{
ret += c;
}
}
return ret;
}

| Data Data::charUnencoded | ( | ) | const |
Performs RFC 3261 un-escaping of SIP URIs.
Definition at line 1231 of file Data.cxx.
References data(), hexmap, Preallocate, and size().
Referenced by TestData::main().
{
Data ret(size(), Data::Preallocate);
const char* p = data();
for (size_type i = 0; i < size(); ++i)
{
unsigned char c = *p++;
if (c == '%')
{
if ( i+2 < size())
{
const char* high = strchr(hexmap, tolower(*p++));
const char* low = strchr(hexmap, tolower(*p++));
// !rwm! changed from high==0 || low==0
if (high == 0 && low == 0)
{
assert(0);
// ugh
return ret;
}
int highInt = int(high - hexmap);
int lowInt = int(low - hexmap);
ret += char(highInt<<4 | lowInt);
i += 2;
}
else
{
break;
}
}
else
{
ret += c;
}
}
return ret;
}

| Data& resip::Data::clear | ( | ) | [inline] |
Clears the contents of this Data.
This call does not modify the capacity of the Data. It does not write terminating NULL, and thus is safe to use with external buffers.
Definition at line 735 of file Data.hxx.
References truncate2().
Referenced by resip::XMLCursor::getAttributes(), resip::XMLCursor::getValue(), resip::DnsUtil::inet_ntop(), main(), TestData::main(), and resip::Log::timestamp().
{ return truncate2(0); };

| double Data::convertDouble | ( | ) | const |
Takes the contents of the Data and converts them to a double precision floating point value.
Will strip leading whitespace. This method stops upon encountering the first non-decimal digit (with exceptions made for decimal points and leading negative signs).
Definition at line 1733 of file Data.cxx.
References end(), mBuf, and mSize.
Referenced by TestData::main().
{
long val = 0;
char* p = mBuf;
const char* const end = p + mSize;
int s = 1;
for (; p != end; ++p)
{
if (!isspace(*p))
{
goto sign_char;
}
}
return val;
sign_char:
if (*p == '-')
{
s = -1;
++p;
}
else if (*p == '+')
{
++p;
}
for(; p != end; ++p)
{
if (*p == '.')
{
goto decimals;
}
if (!isdigit(*p))
{
return s*val;
}
val *= 10;
val += (*p) - '0';
}
return s*val;
decimals:
++p;
long d = 0;
double div = 1.0;
for(; p != end; ++p)
{
if (!isdigit(*p))
{
break;
}
d *= 10;
d += *p - '0';
div *= 10;
}
return s*(val + d/div);
}

| int Data::convertInt | ( | ) | const |
Takes the contents of the Data and converts them to an integer.
Will strip leading whitespace. This method stops upon encountering the first non-decimal digit (with exceptions made for leading negative signs).
Definition at line 1590 of file Data.cxx.
References end(), mBuf, and mSize.
Referenced by TestData::main().
{
int val = 0;
char* p = mBuf;
const char* const end = mBuf + mSize;
int s = 1;
for (; p != end; ++p)
{
if (!isspace(*p))
{
goto sign_char;
}
}
return val;
sign_char:
if (*p == '-')
{
s = -1;
++p;
}
else if (*p == '+')
{
++p;
}
for(; p != end; ++p)
{
if (!isdigit(*p))
{
break;
}
val *= 10;
val += (*p) - '0';
}
return s*val;
}

| size_t Data::convertSize | ( | ) | const |
Takes the contents of the Data and converts them to a size_t.
Will strip leading whitespace. This method stops upon encountering the first non-decimal digit.
Definition at line 1698 of file Data.cxx.
References end(), mBuf, and mSize.
Referenced by TestData::main().
{
size_t val = 0;
char* p = mBuf;
const char* const end = mBuf + mSize;
for (; p != end; ++p)
{
if (!isspace(*p))
{
goto sign_char;
}
}
return val;
sign_char:
if (*p == '+')
{
++p;
}
for(; p != end; ++p)
{
if (!isdigit(*p))
{
break;
}
val *= 10;
val += (*p) - '0';
}
return val;
}

| UInt64 Data::convertUInt64 | ( | ) | const |
Takes the contents of the Data and converts them to an unsigned 64-bit integer.
Will strip leading whitespace. This method stops upon encountering the first non-decimal digit.
Definition at line 1664 of file Data.cxx.
References end(), mBuf, and mSize.
Referenced by TestData::main().
{
UInt64 val = 0;
char* p = mBuf;
const char* const end = mBuf + mSize;
for (; p != end; ++p)
{
if (!isspace(*p))
{
goto sign_char;
}
}
return val;
sign_char:
if (*p == '+')
{
++p;
}
for(; p != end; ++p)
{
if (!isdigit(*p))
{
break;
}
val *= 10;
val += (*p) - '0';
}
return val;
}

| unsigned long Data::convertUnsignedLong | ( | ) | const |
Definition at line 1630 of file Data.cxx.
References end(), mBuf, and mSize.
Referenced by TestData::main().
{
unsigned long val = 0;
char* p = mBuf;
const char* const end = mBuf + mSize;
for (; p != end; ++p)
{
if (!isspace(*p))
{
goto sign_char;
}
}
return val;
sign_char:
if (*p == '+')
{
++p;
}
for(; p != end; ++p)
{
if (!isdigit(*p))
{
break;
}
val *= 10;
val += (*p) - '0';
}
return val;
}

Functional equivalent of: *this = Data(buf, length) but avoid the intermediate allocation and free.
Also, will never decrease capacity. Safe to call even if {buf} is part of {this}.
Definition at line 704 of file Data.cxx.
References mBuf, mCapacity, mShareEnum, mSize, resize(), and Share.
Referenced by operator=().
{
if (mShareEnum == Data::Share || mCapacity < length+1)
{
// will alloc length+1, so the term NULL below is safe
resize(length, false);
}
// {buf} might be part of ourselves already, in which case {length}
// is smaller than our capacity, so resize above won't happen, so
// just memmove (not memcpy) and everything good
mSize = length;
if (mSize>0)
{
memmove(mBuf, buf, mSize);
}
// DONT do term NULL until after copy, because may be shifting contents
// down and don't want to put NULL in middle of it
mBuf[mSize] = 0;
return *this;
}

| const char* resip::Data::data | ( | ) | const [inline] |
Returns a pointer to the contents of this Data.
This is the preferred mechanism for accessing the bytes inside the Data.
Definition at line 560 of file Data.hxx.
References mBuf.
Referenced by base64encode(), caseInsensitivehash(), caseInsensitiveTokenHash(), charEncoded(), charUnencoded(), encodeTurnData(), escaped(), resip::Random::getCryptoRandom(), hash(), resip::isEqualNoCase(), resip::DnsUtil::isIpV4Address(), resip::DnsUtil::isIpV6Address(), resip::isLessThanNoCase(), main(), TestData::main(), operator+=(), resip::XMLCursor::parseNextRootChild(), postfix(), prefix(), rawCaseInsensitiveTokenHash(), replace(), showData(), resip::ParseBuffer::skipChars(), resip::XMLCursor::Node::skipToEndTag(), resip::Log::timestamp(), trunc(), urlDecode(), urlEncode(), resip::BaseException::what(), xmlCharDataDecode(), xmlCharDataEncode(), and resip::XMLCursor::XMLCursor().
{
return mBuf;
}
| bool resip::Data::empty | ( | ) | const [inline] |
Checks whether the Data is empty.
Definition at line 543 of file Data.hxx.
References mSize.
Referenced by escapeToStream(), resip::ConfigParse::getConfigData(), resip::DnsUtil::isIpV6Address(), resip::FileSystem::Directory::iterator::iterator(), main(), TestData::main(), replace(), and resip::GeneralCongestionManager::updateFifoTolerances().
{ return mSize == 0; }
| const char* resip::Data::end | ( | ) | const [inline] |
Returns a pointer to the end of the buffer used by the Data.
Definition at line 590 of file Data.hxx.
Referenced by convertDouble(), convertInt(), convertSize(), convertUInt64(), convertUnsignedLong(), operator^=(), rawCaseInsensitiveHash(), and rawHash().
| Data Data::escaped | ( | ) | const |
Returns a representation of the contents of the data with any non-printable characters escaped.
Definition at line 1141 of file Data.cxx.
References data(), hexmap, Preallocate, and size().
{
Data ret((int)((size()*11)/10), Data::Preallocate);
const char* p = data();
for (size_type i=0; i < size(); ++i)
{
unsigned char c = *p++;
if ( c == 0x0d )
{
if ( i+1 < size() )
{
if ( *p == 0x0a )
{
// found a CRLF sequence
ret += c;
c = *p++; i++;
ret += c;
continue;
}
}
}
if ( !isprint(c) )
{
ret +='%';
int hi = (c & 0xF0)>>4;
int low = (c & 0x0F);
ret += hexmap[hi];
ret += hexmap[low];
}
else
{
ret += c;
}
}
return ret;
}

| EncodeStream & resip::Data::escapeToStream | ( | EncodeStream & | str, |
| Predicate | shouldEscape | ||
| ) | const |
Performs escaping of this Data according to the indicated Predicate.
| str | A stream to which the escaped representation should be added. |
| shouldEscape | A functor which takes a single character as a parameter, and returns true if the character should be escaped, false if it should not. |
Definition at line 1031 of file Data.hxx.
References empty(), hex(), isHex(), mBuf, and mSize.
{
static char hex[] = "0123456789ABCDEF";
if (empty())
{
return str;
}
const unsigned char* p = (unsigned char*)mBuf;
const unsigned char* e = (unsigned char*)mBuf + mSize;
while (p < e)
{
// ?abr? Why is this special cased? Removing this code
// does not change the behavior of this method.
if (*p == '%'
&& e - p > 2
&& isHex(*(p+1))
&& isHex(*(p+2)))
{
str.write((char*)p, 3);
p+=3;
}
else if (shouldEscape[*p])
{
int hi = (*p & 0xF0)>>4;
int low = (*p & 0x0F);
str << '%' << hex[hi] << hex[low];
p++;
}
else
{
str.put(*p++);
}
}
return str;
}

| std::ostream & Data::escapeToStream | ( | std::ostream & | str, |
| const std::bitset< 256 > & | shouldEscape | ||
| ) | const |
Performs escaping of this Data according to a bitset.
| str | A stream to which the escaped representation should be added. |
| shouldEscape | A bitset representing which chars should be escaped. |
Definition at line 2226 of file Data.cxx.
References empty(), hex(), isHex(), mBuf, and mSize.
{
static char hex[] = "0123456789ABCDEF";
if (empty())
{
return str;
}
const unsigned char* anchor = (unsigned char*)mBuf;
const unsigned char* p = (unsigned char*)mBuf;
const unsigned char* e = (unsigned char*)mBuf + mSize;
while (p < e)
{
// ?abr? Why is this special cased? Removing this code
// does not change the behavior of this method.
if (*p == '%'
&& e - p > 2
&& isHex(*(p+1))
&& isHex(*(p+2)))
{
p+=3;
}
else if (shouldEscape[*p])
{
if(p > anchor)
{
str.write((char*)anchor, p-anchor);
}
int hi = (*p & 0xF0)>>4;
int low = (*p & 0x0F);
str << '%' << hex[hi] << hex[low];
anchor=++p;
}
else
{
++p;
}
}
if(p > anchor)
{
str.write((char*)anchor, p-anchor);
}
return str;
}

| Data::size_type Data::find | ( | const Data & | match, |
| size_type | start = 0 |
||
| ) | const |
Finds a specified sequence of bytes in this Data.
| match | The bytes to be found |
| start | Offset into this Data to start the search |
Definition at line 1831 of file Data.cxx.
References resip::ParseBuffer::eof(), mBuf, mSize, npos, resip::ParseBuffer::position(), resip::ParseBuffer::skipToChars(), and resip::ParseBuffer::start().
Referenced by resip::ConfigParse::getConfigValue(), resip::DnsUtil::getLocalDomainName(), TestData::main(), and replace().
{
if (start < mSize)
{
ParseBuffer pb(mBuf + start, mSize - start);
pb.skipToChars(match);
if (!pb.eof())
{
return pb.position() - pb.start() + start;
}
}
return Data::npos;
}

| static Data resip::Data::from | ( | const T & | x | ) | [inline, static] |
Converts from arbitrary other type to Data.
Requires the other type to have an operator<<.
Definition at line 382 of file Data.hxx.
{
Data d;
{
DataStream s(d);
s << x;
}
return d;
}
| char * Data::getBuf | ( | size_type | length | ) |
Set size to be exactly {length}, extending buffer if needed.
Also, reallocate buffer if needed so that it is writable. Buffer contents is NOT initialized, and existing contents may or may not be preserved.
Definition at line 726 of file Data.cxx.
References mBuf, mCapacity, mShareEnum, mSize, resize(), and Share.
{
if (mShareEnum == Data::Share || mCapacity < length)
{
// will alloc length+1, so the term NULL below is safe
resize(length, false);
mBuf[length] = 0;
}
else if ( mCapacity != length )
{
mBuf[length] = 0;
}
// even if we don't NULL-term it, it may have NULL term from before.
// But if external buffer (taken or borrow'd) then don't know if it
// has a NULL or not.
mSize = length;
return mBuf;
}

| size_t Data::hash | ( | ) | const |
Creates a 32-bit hash based on the contents of this Data.
Definition at line 2104 of file Data.cxx.
References data(), rawHash(), and size().
Referenced by resip::Random::getSimpleSeed(), TestData::main(), and rawCaseInsensitiveTokenHash().

| Data Data::hex | ( | ) | const |
Returns a hexadecimal representation of the contents of this Data.
Definition at line 1519 of file Data.cxx.
References hexmap, mBuf, mSize, and Preallocate.
Referenced by escapeToStream(), resip::MD5Buffer::getHex(), resip::DigestBuffer::getHex(), resip::Random::getVersion4UuidUrn(), TestData::main(), main(), and md5().
| bool Data::init | ( | DataLocalSize< RESIP_DATA_LOCAL_SIZE > | arg | ) | [static] |
| bool resip::Data::isHex | ( | unsigned char | c | ) | [inline, static, private] |
Definition at line 995 of file Data.hxx.
References resip::DataHelper::isCharHex.
Referenced by escapeToStream().
{
return DataHelper::isCharHex[c];
}
| Data & Data::lowercase | ( | ) |
Converts this Data to lowercase.
Definition at line 1541 of file Data.cxx.
References mBuf, mSize, and own().
Referenced by resip::ConfigParse::getConfigValue(), resip::ConfigParse::insertConfigValue(), and TestData::main().
{
own();
char* p = mBuf;
for (size_type i=0; i < mSize; ++i)
{
*p = tolower(*p);
++p;
}
return *this;
}

| Data Data::md5 | ( | EncodingType | type = HEX | ) | const |
Computes the MD5 hash of the current data.
| type | The encoding of the return (default is HEX) |
Definition at line 1116 of file Data.cxx.
References BASE64, base64encode(), BINARY, HEX, hex(), mBuf, resip::MD5Final(), resip::MD5Init(), resip::MD5Update(), and mSize.
Referenced by main(), and TestData::main().
{
MD5Context context;
MD5Init(&context);
MD5Update(&context, reinterpret_cast < unsigned const char* > (mBuf), (unsigned int)mSize);
unsigned char digestBuf[16];
MD5Final(digestBuf, &context);
Data digest(digestBuf,16);
switch(type)
{
case BINARY:
return digest;
case BASE64:
return digest.base64encode(true);
case HEX:
default:
return digest.hex();
}
assert(0);
return digest.hex();
}

| Data Data::operator+ | ( | const char * | str | ) | const |
| Data Data::operator+ | ( | char | c | ) | const |
| Data& resip::Data::operator+= | ( | const char * | str | ) | [inline] |
| Data& resip::Data::operator+= | ( | char | c | ) | [inline] |
| Data& resip::Data::operator= | ( | const char * | str | ) | [inline] |
Assigns a null-terminated string to the buffer.
Definition at line 418 of file Data.hxx.
References copy().

| char& resip::Data::operator[] | ( | size_type | p | ) | [inline] |
| char resip::Data::operator[] | ( | size_type | p | ) | const [inline] |
Performs an in-place exclusive-or of this buffer buffer with the specified buffer.
If the specifed buffer is longer than this buffer, then this buffer will first be expanded and zero-padded.
Definition at line 927 of file Data.cxx.
References end(), mBuf, mCapacity, mSize, resip::resipMax(), and resize().
{
if (mCapacity < rhs.mSize)
{
resize(rhs.mSize, true);
}
if (mSize < rhs.mSize)
{
memset(mBuf+mSize, 0, mCapacity - mSize);
}
char* c1 = mBuf;
char* c2 = rhs.mBuf;
char* end = c2 + rhs.mSize;
while (c2 != end)
{
*c1++ ^= *c2++;
}
mSize = resipMax(mSize, rhs.mSize);
return *this;
}

| void Data::own | ( | ) | const [private] |
Copies the contents of this data to a new buffer if the Data does not own the current buffer.
Definition at line 1072 of file Data.cxx.
References mShareEnum, mSize, resize(), and Share.
Referenced by at(), lowercase(), operator[](), replace(), schemeLowercase(), and uppercase().
{
if (mShareEnum == Share)
{
const_cast<Data*>(this)->resize(mSize, true);
}
}

| bool Data::postfix | ( | const Data & | post | ) | const |
Returns true if this Data ends with the bytes indicated by the passed-in Data.
For example, if this Data is "abc", then postfix(Data("bc")) would be true; however, postfix(Data("ab")) would be false.
Definition at line 1805 of file Data.cxx.
References data(), and size().
Referenced by TestData::main().
{
if (post.size() > size())
{
return false;
}
return memcmp(data() + (size()-post.size()), post.data(), post.size()) == 0;
}

| bool Data::prefix | ( | const Data & | pre | ) | const |
Returns true if this Data starts with the bytes indicated by the passed-in Data.
For example, if this Data is "abc", then prefix(Data("ab")) would be true; however, prefix(Data("abcd")) would be false.
Definition at line 1794 of file Data.cxx.
References data(), and size().
Referenced by TestData::main(), and resip::Log::toLevel().

| size_t Data::rawCaseInsensitiveHash | ( | const unsigned char * | c, |
| size_t | size | ||
| ) | [static] |
Creates a 32-bit hash based on the contents of the indicated buffer, after normalizing any alphabetic characters to lowercase.
| c | Pointer to the buffer to hash |
| size | Number of bytes to be hashed |
Definition at line 1942 of file Data.cxx.
References end(), randomPermutation, and size().
Referenced by caseInsensitivehash().
{
union
{
size_t st;
unsigned char bytes[4];
};
st = 0; // suppresses warnings about unused st
bytes[0] = randomPermutation[0];
bytes[1] = randomPermutation[1];
bytes[2] = randomPermutation[2];
bytes[3] = randomPermutation[3];
const unsigned char* end = c + size;
for ( ; c != end; ++c)
{
unsigned char cc = tolower(*c);
bytes[0] = randomPermutation[cc ^ bytes[0]];
bytes[1] = randomPermutation[cc ^ bytes[1]];
bytes[2] = randomPermutation[cc ^ bytes[2]];
bytes[3] = randomPermutation[cc ^ bytes[3]];
}
// convert from network to host byte order
return ntohl((u_long)st);
}

| size_t Data::rawCaseInsensitiveTokenHash | ( | const unsigned char * | c, |
| size_t | size | ||
| ) | [static] |
A faster version of rawCaseInsensitiveHash that has the same collision properties if this Data is made up of RFC 3261 token characters.
| c | Pointer to the buffer to hash |
| size | Number of bytes to be hashed |
Definition at line 2000 of file Data.cxx.
References data(), get16bits, get32bits, and hash().
Referenced by caseInsensitiveTokenHash().
{
// .bwc. Hsieh hash, with some bitmasking to get the case-insensitive
// property (this is what all the "0x2020 |" business is about.)
UInt32 hash = len, tmp;
int rem;
if (len <= 0 || data == NULL) return 0;
rem = len & 3;
len >>= 2;
union
{
UInt32 masked;
UInt16 ui16[2];
};
/* Main loop */
for (;len > 0; len--)
{
// mask out bit 6 for case-insensitivity
masked = (0x20202020 | get32bits(data));
hash += ui16[0];
tmp = ((UInt32)ui16[1] << 11) ^ hash;
hash = (hash << 16) ^ tmp;
data += 2*sizeof (UInt16);
hash += hash >> 11;
}
/* Handle end cases */
switch (rem)
{
case 3: hash += (0x2020 | get16bits (data));
hash ^= hash << 16;
hash ^= (0x20 | data[sizeof (UInt16)]) << 18;
hash += hash >> 11;
break;
case 2: hash += (0x2020 | get16bits (data));
hash ^= hash << 11;
hash += hash >> 17;
break;
case 1: hash += (0x20 | *data);
hash ^= hash << 10;
hash += hash >> 1;
}
/* Force "avalanching" of final 127 bits */
hash ^= hash << 3;
hash += hash >> 5;
hash ^= hash << 4;
hash += hash >> 17;
hash ^= hash << 25;
hash += hash >> 6;
return hash;
// union
// {
// size_t st;
// unsigned char bytes[4];
// };
// st = 0; // suppresses warnings about unused st
// bytes[0] = randomPermutation[0];
// bytes[1] = randomPermutation[1];
// bytes[2] = randomPermutation[2];
// bytes[3] = randomPermutation[3];
//
// const unsigned char* end = c + size;
// for ( ; c != end; ++c)
// {
// union
// {
// UInt32 temp;
// UInt8 cccc[4];
// };
// // .bwc. Mask out bit 6, use a multiplication op to write the
// // resulting byte to each of the 4 bytes in temp, and xor the whole
// // thing with bytes/st.
// temp = ( (*c | ' ') * 16843009UL) ^ st;
// bytes[0] = randomPermutation[cccc[0]];
// bytes[1] = randomPermutation[cccc[1]];
// bytes[2] = randomPermutation[cccc[2]];
// bytes[3] = randomPermutation[cccc[3]];
// }
//
// // convert from network to host byte order
// return ntohl((u_long)st);
}

| size_t Data::rawHash | ( | const unsigned char * | c, |
| size_t | size | ||
| ) | [static] |
Creates a 32-bit hash based on the contents of the indicated buffer.
| c | Pointer to the buffer to hash |
| size | Number of bytes to be hashed |
Definition at line 1911 of file Data.cxx.
References end(), randomPermutation, and size().
Referenced by hash().
{
// 4 byte Pearson's hash
// essentially random hashing
union
{
size_t st;
unsigned char bytes[4];
};
st = 0; // suppresses warnings about unused st
bytes[0] = randomPermutation[0];
bytes[1] = randomPermutation[1];
bytes[2] = randomPermutation[2];
bytes[3] = randomPermutation[3];
const unsigned char* end = c + size;
for ( ; c != end; ++c)
{
bytes[0] = randomPermutation[*c ^ bytes[0]];
bytes[1] = randomPermutation[*c ^ bytes[1]];
bytes[2] = randomPermutation[*c ^ bytes[2]];
bytes[3] = randomPermutation[*c ^ bytes[3]];
}
// convert from network to host byte order
return ntohl((u_long)st);
}

Replaces up to max occurrences of the bytes match with target.
Returns the number of matches.
Definition at line 1848 of file Data.cxx.
References data(), empty(), find(), mBuf, mCapacity, mSize, npos, own(), resize(), and size().
Referenced by TestData::main().
{
assert(!match.empty());
int count = 0;
const int incr = int(replaceWith.size() - match.size());
for (size_type offset = find(match, 0);
count < max && offset != Data::npos;
offset = find(match, offset+replaceWith.size()))
{
if (mSize + incr >= mCapacity)
{
resize((mCapacity + incr) * 3 / 2, true);
}
else
{
own();
}
// move the memory forward (or backward)
memmove(mBuf + offset + replaceWith.size(), mBuf + offset + match.size(), mSize - offset - match.size());
memcpy(mBuf + offset, replaceWith.data(), replaceWith.size());
mSize += incr;
++count;
}
return count;
}

| void Data::reserve | ( | size_type | capacity | ) |
Guarantees that the underlying buffer used by the Data is at least the number of bytes specified.
May cause reallocation of the buffer.
Definition at line 1012 of file Data.cxx.
References mCapacity, and resize().
Referenced by base64decode(), and resip::XMLCursor::XMLCursor().

| resip::Data::RESIP_HeapCount | ( | Data | ) |
| void Data::resize | ( | size_type | newSize, |
| bool | copy | ||
| ) | [private] |
Definition at line 1082 of file Data.cxx.
References Borrow, LocalAlloc, mBuf, mCapacity, mPreBuffer, mShareEnum, mSize, Share, and Take.
Referenced by append(), at(), c_str(), copy(), Data(), resip::ParseBuffer::dataUnescaped(), getBuf(), operator^=(), own(), replace(), and reserve().
{
assert(newCapacity >= mCapacity || mShareEnum == Data::Share);
char *oldBuf = mBuf;
bool needToDelete=(mShareEnum==Take);
if(newCapacity > LocalAlloc)
{
mBuf = new char[newCapacity+1];
mShareEnum = Take;
}
else
{
mBuf = mPreBuffer;
mShareEnum = Borrow;
}
if (copy)
{
memcpy(mBuf, oldBuf, mSize);
mBuf[mSize] = 0;
}
if (needToDelete)
{
delete[] oldBuf;
}
mCapacity = newCapacity;
}
| Data & Data::schemeLowercase | ( | ) |
Converts this Data to lowercase, assuming this Data only consists of scheme characters.
Definition at line 1567 of file Data.cxx.
References mBuf, mSize, and own().

Set the Data to hold {buf} using share type {se}, which may be any of Share (read-only, no-free), Borrow (read-write, no-free) or Take (read-write, yes-free).
Both the capacity and current length are set to {length}; you can call truncate2() afterwords to shorten. The provided buffer (and its current contents) will be used going forward; any currently owned buffer will be released. NOTE: The {buf} param is declared const to support Share type; for Borrow and Take the buffer may be written (e.g., treated non-const).
Definition at line 656 of file Data.cxx.
References mBuf, mCapacity, mShareEnum, mSize, and Take.
Referenced by setBuf().
{
assert(buffer);
if (mShareEnum == Take)
{
delete[] mBuf;
}
mBuf = const_cast<char*>(buffer);
mCapacity = mSize = length;
mShareEnum = se;
return *this;
}
| size_type resip::Data::size | ( | ) | const [inline] |
Returns the number of bytes in this Data.
Definition at line 551 of file Data.hxx.
References mSize.
Referenced by base64decode(), base64encode(), caseInsensitivehash(), caseInsensitiveTokenHash(), charEncoded(), charUnencoded(), resip::ServerProcess::daemonize(), Data(), resip::DataBuffer::DataBuffer(), encodeTurnData(), escaped(), resip::Log::Guard::Guard(), hash(), resip::isEqualNoCase(), resip::DnsUtil::isIpV4Address(), resip::DnsUtil::isIpV6Address(), resip::isLessThanNoCase(), TestData::main(), main(), resip::ParseBuffer::oneOf(), operator+=(), resip::XMLCursor::parseNextRootChild(), postfix(), prefix(), rawCaseInsensitiveHash(), rawHash(), resip::DnsNaptrRecord::RegExp::RegExp(), replace(), showData(), resip::ParseBuffer::skipChars(), resip::XMLCursor::Node::skipToEndTag(), trunc(), urlDecode(), urlEncode(), xmlCharDataDecode(), xmlCharDataEncode(), and resip::XMLCursor::XMLCursor().
{ return mSize; }
| bool Data::sizeEqualCaseInsensitiveTokenCompare | ( | const Data & | rhs | ) | const |
Definition at line 2153 of file Data.cxx.
References compUnalignedRemainder, get32bits, mBuf, and mSize.
Referenced by caseInsensitiveTokenCompare().
{
assert(mSize==rhs.mSize);
const char* d1(mBuf);
const char* d2(rhs.mBuf);
if(mSize < 4)
{
// No point in trying 32-bit ops.
compUnalignedRemainder(d1, d2, mSize);
return true;
}
int unalignedPrefix((ptrdiff_t)d1 & 3);
compUnalignedRemainder(d1, d2, unalignedPrefix);
// We are now on a 32-bit boundary with d1.
UInt32* wd1((UInt32*)(d1));
size_t wordLen=(mSize-unalignedPrefix)>>2;
int rem=(mSize-unalignedPrefix)&3;
if((ptrdiff_t)(d2)%4==0)
{
// d2 is aligned too. Happy day!
UInt32* wd2((UInt32*)(d2));
for (;wordLen > 0; wordLen--)
{
// bitwise xor is zero iff equal, but we only really care about bits
// other than bit 6, so we mask out bit 6 after the xor.
if( (*wd1 ^ *wd2) & 0xDFDFDFDF)
{
return false;
}
wd1++;
wd2++;
}
d2=(const char*)wd2;
}
else
{
for (;wordLen > 0; wordLen--)
{
// bitwise xor is zero iff equal, but we only really care about bits
// other than bit 6, so we mask out bit 6 after the xor.
UInt32 test=get32bits(d2);
if( (*wd1 ^ test) & 0xDFDFDFDF)
{
return false;
}
wd1++;
d2+=4;
}
}
d1=(const char*)wd1;
compUnalignedRemainder(d1, d2, rem);
return true;
}
| Data Data::substr | ( | size_type | first, |
| size_type | count = Data::npos |
||
| ) | const |
Copies a portion of this Data into a new Data.
| first | Index of the first byte to copy |
| count | Number of bytes to copy |
Definition at line 1816 of file Data.cxx.
References Data(), mBuf, mSize, and npos.
Referenced by resip::DnsUtil::getLocalDomainName(), TestData::main(), and resip::Log::toLevel().
{
assert(first <= mSize);
if ( count == Data::npos)
{
return Data(mBuf+first, mSize-first);
}
else
{
assert(first + count <= mSize);
return Data(mBuf+first, count);
}
}

Take the data from {other}.
Any current buffer is released. {this} will have the same storage mode as {other} and steal its buffer. All storage modes of {other} (Share,Borrow,Take) are legal. When done, {other} will be empty (it will ref its internal buffer).
Definition at line 670 of file Data.cxx.
References Borrow, LocalAlloc, mBuf, mCapacity, mPreBuffer, mShareEnum, mSize, and Take.
{
if ( &other == this )
return *this;
if (mShareEnum == Data::Take)
delete[] mBuf;
if ( other.mBuf == other.mPreBuffer )
{
// plus one picks up the terminating safety NULL
memcpy( mPreBuffer, other.mPreBuffer, other.mSize+1);
mBuf = mPreBuffer;
}
else
{
mBuf = other.mBuf;
other.mBuf = other.mPreBuffer;
}
mSize = other.mSize;
mCapacity = other.mCapacity;
mShareEnum = other.mShareEnum;
// reset {other} to same state as the default Data() constructor
// note that other.mBuf is set above
other.mSize = 0;
other.mCapacity = LocalAlloc;
other.mShareEnum = Data::Borrow;
other.mPreBuffer[0] = 0;
return *this;
}
| std::bitset< 256 > Data::toBitset | ( | const resip::Data & | chars | ) | [static] |
Creates a bitset reflecting the contents of this data (as a set) ie.
"15eo" would have the bits 49, 53, 101, and 111 set to true, and all others set to false
Definition at line 2214 of file Data.cxx.
Referenced by resip::ConfigParse::parseCommandLine().
| Data::size_type Data::truncate | ( | size_type | len | ) |
Shortens the size of this Data.
Does not impact the size of the allocated buffer. This owns() the buffer (undoes Share) so as to write terminating NULL. See truncate2() as alternative.
Definition at line 891 of file Data.cxx.
References mSize.
Shortens the size of this Data so length is at most of {len}.
(If already shorter, doesn't increase length). Does not affect buffer allocation, and doesn't impact writing terminating NULL. Thus is safe to use with Share'd or external Take'n buffers.
Definition at line 903 of file Data.cxx.
References mSize.
Referenced by clear().
| Data & Data::uppercase | ( | ) |
Converts this Data to uppercase.
Definition at line 1554 of file Data.cxx.
References mBuf, mSize, and own().
Referenced by TestData::main().
{
own();
char* p = mBuf;
for (size_type i=0; i < mSize; ++i)
{
*p = toupper(*p);
++p;
}
return *this;
}

| EncodeStream & Data::urlDecode | ( | EncodeStream & | s | ) | const |
Un-escapes a Data to a stream according to HTTP URL encoding rules.
Definition at line 1293 of file Data.cxx.
References data(), hexpair2int(), and size().
Referenced by urlDecoded().
{
unsigned int i = 0;
for (const char* p = data(); p != data()+size(); ++p, ++i)
{
unsigned char c = *p;
if (c == '%')
{
if (i+2 < size())
{
s << (char) hexpair2int( *(p+1), *(p+2));
p += 2;
}
else
{
break;
}
}
else if (c == '+')
{
s << ' ';
}
else
{
s << c;
}
}
return s;
}

| Data Data::urlDecoded | ( | ) | const |
Performs in-place HTTP URL un-escaping of a Data.
Definition at line 1283 of file Data.cxx.
References urlDecode().
Referenced by TestData::main().
{
Data buffer;
DataStream strm(buffer);
urlDecode(strm);
strm.flush();
return buffer;
}

| EncodeStream & Data::urlEncode | ( | EncodeStream & | s | ) | const |
Escapes a Data to a stream according to HTTP URL encoding rules.
Definition at line 1363 of file Data.cxx.
References data(), hexmap, size(), and urlNonEncodedChars.
Referenced by TestData::main(), and urlEncoded().
{
for (const char* p = data(); p != data() + size(); ++p)
{
unsigned char c = *p;
// pchar, slash, questionmark
// pchar = unreserved, sub-delims, colon, at-sign
// unreserved = alphanum, hyphen, underscore, period, tilde
// subdelims = bang (!), dollar, ampersand (oops!), plus, single-quote, lparen, rparen, asterisk, comma, semicolon, equal
//if (isalpha(c) || isdigit(c) || strchr("-_.~!$+'()*,;=:@/?", c)) //
// strchr is inefficient and wrong
if (urlNonEncodedChars[c])
{
s << c;
}
else
{
if (c == 0x20)
{
s << '+';
}
else
{
s << '%' << (hexmap[(c & 0xF0)>>4]) << (hexmap[(c & 0x0F)]);
}
}
}
return s;
}

| Data Data::urlEncoded | ( | ) | const |
Performs in-place HTTP URL escaping of a Data.
Definition at line 1273 of file Data.cxx.
References urlEncode().
Referenced by TestData::main().
{
Data buffer;
DataStream strm(buffer);
urlEncode(strm);
strm.flush();
return buffer;
}

| Data Data::xmlCharDataDecode | ( | ) | const |
Performs in-place XML Character Data un-escaping of a Data.
Definition at line 1406 of file Data.cxx.
{
Data buffer;
DataStream strm(buffer);
xmlCharDataDecode(strm);
strm.flush();
return buffer;
}
| EncodeStream & Data::xmlCharDataDecode | ( | EncodeStream & | s | ) | const |
Un-escapes a Data to a stream according to XML Character Data encoding rules.
Definition at line 1449 of file Data.cxx.
References data(), and size().
{
unsigned int i = 0;
for (const char* p = data(); p != data()+size(); ++p, ++i)
{
unsigned char c = *p;
if (c == '&')
{
// look for amp;
if(i+4 < size() &&
*(p+1) == 'a' && *(p+2) == 'm' && *(p+3) == 'p' && *(p+4) == ';')
{
s << '&';
p += 4;
}
// look for lt;
else if(i+3 < size() &&
*(p+1) == 'l' && *(p+2) == 't' && *(p+3) == ';')
{
s << '<';
p += 3;
}
// look for gt;
else if(i+3 < size() &&
*(p+1) == 'g' && *(p+2) == 't' && *(p+3) == ';')
{
s << '>';
p += 3;
}
// look for apos;
else if(i+5 < size() &&
*(p+1) == 'a' && *(p+2) == 'p' && *(p+3) == 'o' && *(p+4) == 's' && *(p+5) == ';')
{
s << '\'';
p += 5;
}
// look for quot;
else if(i+5 < size() &&
*(p+1) == 'q' && *(p+2) == 'u' && *(p+3) == 'o' && *(p+4) == 't' && *(p+5) == ';')
{
s << '\"';
p += 5;
}
else // if no conversion found - just leave characters in data
{
s << c;
}
}
else
{
s << c;
}
}
return s;
}

| Data Data::xmlCharDataEncode | ( | ) | const |
Performs in-place XML Character Data escaping of a Data.
Definition at line 1396 of file Data.cxx.
{
Data buffer;
DataStream strm(buffer);
xmlCharDataEncode(strm);
strm.flush();
return buffer;
}
| EncodeStream & Data::xmlCharDataEncode | ( | EncodeStream & | s | ) | const |
Escapes a Data to a stream according to XML Character Data encoding rules.
Definition at line 1417 of file Data.cxx.
References data(), and size().
{
for (const char* p = data(); p != data() + size(); ++p)
{
unsigned char c = *p;
switch(c)
{
case '&':
s << "&";
break;
case '<':
s << "<";
break;
case '>':
s << ">";
break;
case '\'':
s << "'";
break;
case '\"':
s << """;
break;
default:
s << c;
}
}
return s;
}

friend class DataBuffer [friend] |
friend class DataStream [friend] |
friend class oDataStream [friend] |
| bool operator< | ( | const Data & | lhs, |
| const char * | rhs | ||
| ) | [friend] |
| bool operator< | ( | const char * | lhs, |
| const Data & | rhs | ||
| ) | [friend] |
| std::ostream& operator<< | ( | std::ostream & | strm, |
| const Data & | d | ||
| ) | [friend] |
| EncodeStream& operator<< | ( | EncodeStream & | strm, |
| const Data & | d | ||
| ) | [friend] |
| bool operator== | ( | const Data & | lhs, |
| const char * | rhs | ||
| ) | [friend] |
friend class ParseBuffer [friend] |
const Data Data::Empty [static] |
Constant that represents a zero-length data.
Definition at line 815 of file Data.hxx.
Referenced by resip::DnsUtil::canonicalizeIpV6Address(), Foo::checkConstAccessors(), resip::ParseBuffer::fail(), Foo::Foo(), resip::KeyValueStore::getDataValue(), resip::DnsUtil::getInterfaces(), TestData::main(), and main().
char* resip::Data::mBuf [private] |
Definition at line 962 of file Data.hxx.
Referenced by append(), at(), base64decode(), begin(), c_str(), convertDouble(), convertInt(), convertSize(), convertUInt64(), convertUnsignedLong(), copy(), Data(), resip::ParseBuffer::data(), data(), resip::DataBuffer::DataBuffer(), resip::ParseBuffer::dataUnescaped(), end(), escapeToStream(), find(), getBuf(), hex(), lowercase(), md5(), operator+(), resip::operator<<(), operator=(), operator[](), operator^=(), replace(), resize(), schemeLowercase(), setBuf(), sizeEqualCaseInsensitiveTokenCompare(), resip::ParseBuffer::skipToChars(), substr(), takeBuf(), toBitset(), uppercase(), and ~Data().
size_type resip::Data::mCapacity [private] |
Definition at line 964 of file Data.hxx.
Referenced by append(), at(), c_str(), copy(), resip::ParseBuffer::data(), Data(), resip::DataBuffer::DataBuffer(), resip::ParseBuffer::dataUnescaped(), getBuf(), TestData::main(), operator+(), operator^=(), replace(), reserve(), resize(), setBuf(), and takeBuf().
char resip::Data::mPreBuffer[LocalAlloc] [private] |
size_type resip::Data::mShareEnum [private] |
Definition at line 971 of file Data.hxx.
Referenced by append(), c_str(), copy(), resip::ParseBuffer::data(), resip::DataStream::DataStream(), getBuf(), TestData::main(), resip::oDataStream::oDataStream(), own(), resize(), setBuf(), takeBuf(), and ~Data().
size_type resip::Data::mSize [private] |
Definition at line 963 of file Data.hxx.
Referenced by append(), at(), c_str(), caseInsensitiveTokenCompare(), convertDouble(), convertInt(), convertSize(), convertUInt64(), convertUnsignedLong(), copy(), Data(), resip::ParseBuffer::data(), resip::DataBuffer::DataBuffer(), resip::ParseBuffer::dataUnescaped(), empty(), end(), escapeToStream(), find(), getBuf(), hex(), lowercase(), md5(), operator+(), resip::operator<<(), operator=(), operator[](), operator^=(), own(), replace(), resize(), schemeLowercase(), setBuf(), size(), sizeEqualCaseInsensitiveTokenCompare(), resip::ParseBuffer::skipToChars(), substr(), takeBuf(), toBitset(), truncate(), truncate2(), and uppercase().
const Data::size_type Data::npos = UINT_MAX [static] |
Represents an impossible position; returned to indicate failure to find.
Definition at line 820 of file Data.hxx.
Referenced by find(), resip::DnsUtil::getLocalDomainName(), TestData::main(), replace(), and substr().
const Data::PreallocateType Data::Preallocate [static] |
used only to disambiguate constructors
Definition at line 113 of file Data.hxx.
Referenced by charEncoded(), charUnencoded(), Data(), escapeAndAnnotate(), escaped(), hex(), main(), TestData::main(), operator+(), and spaces().
1.7.5.1