12#if defined(HAVE_CONFIG_H)
33Data::PreallocateType::PreallocateType(
int)
41 false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
42 false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
43 false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
44 true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
false,
false,
false,
false,
false,
false,
45 false,
true,
true,
true,
true,
true,
true,
false,
false,
false,
false,
false,
false,
false,
false,
false,
46 false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
47 false,
true,
true,
true,
true,
true,
true,
false,
false,
false,
false,
false,
false,
false,
false,
false,
48 false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
49 false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
50 false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
51 false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
52 false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
53 false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
54 false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
55 false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false
59static const char hexmap[] =
"0123456789abcdef";
62 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
63 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
64 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
65 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
66 -1, -1, -1, -1, -1, -1, -1, -1,
68 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
73 10, 11, 12, 13, 14, 15,
75 -1, -1, -1, -1, -1, -1, -1, -1, -1,
76 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
77 -1, -1, -1, -1, -1, -1, -1,
79 10, 11, 12, 13, 14, 15
222 : mBuf(capacity > LocalAlloc
223 ? new char[capacity + 1]
226 mCapacity(capacity > LocalAlloc
229 mShareEnum(capacity > LocalAlloc ?
Take :
Borrow)
235#ifdef DEPRECATED_PREALLOC
238 : mBuf(capacity > LocalAlloc
239 ? new char[capacity + 1]
242 mCapacity(capacity > LocalAlloc
245 mShareEnum(capacity > LocalAlloc ? Take : Borrow)
254 initFromString(str, length);
259 initFromString((
const char*)str, length);
265Data::Data(
const char* str, size_type length,
bool)
266 : mBuf(const_cast<char*>(str)),
275Data::initFromString(
const char* str, size_type len)
282 size_t bytes = len + 1;
286 throw std::bad_alloc();
288 if(bytes > LocalAlloc)
290 mBuf =
new char[bytes];
297 mCapacity = LocalAlloc;
302 memcpy(mBuf, str, len);
308 : mBuf(const_cast<char*>(buffer)),
317 : mBuf(const_cast<char*>(buffer)),
326 : mBuf(const_cast<char*>(buffer)),
335 : mBuf(staticData.mBuf),
336 mSize(staticData.mSize),
357#if RESIP_HAVE_STRING_VIEW
369 initFromString(
data.mBuf,
data.mSize);
373 : mBuf(mPreBuffer),mSize(0),mCapacity(LocalAlloc),mShareEnum(Borrow)
375 *
this = std::move(data);
429 mBuf[c--] =
'0' + v%10;
439#ifndef RESIP_FIXED_POINT
450 mShareEnum(
DoubleMaxSize + precision > LocalAlloc ? Take : Borrow)
456 bool neg = (value < 0.0);
474 int dec = (int)floor(v+0.5);
483 d.mBuf[precision] = 0;
486 bool significant =
false;
489 if (dec % 10 || significant)
493 d.mBuf[p] =
'0' + (dec % 10);
507 memcpy(mBuf+1, m.mBuf, m.
size());
508 mBuf[1+m.
size()] =
'.';
509 memcpy(mBuf+1+m.
size()+1, d.mBuf, d.
size()+1);
514 if (mCapacity < m.
size() + d.
size() + 1)
516 resize(m.
size() + d.
size() + 1,
false);
518 memcpy(mBuf, m.mBuf, m.
size());
519 mBuf[m.
size()] =
'.';
520 memcpy(mBuf+m.
size()+1, d.mBuf, d.
size()+1);
559 unsigned int digit = v%10;
560 unsigned char d = (char)digit;
598 unsigned char d = (char)digit;
613 mShareEnum(
CharMaxSize > LocalAlloc ? Take : Borrow)
620 : mBuf(value ? const_cast<char*>(
"true") : const_cast<char*>(
"false")),
621 mSize(value ? 4 : 5),
622 mCapacity(value ? 4 : 5),
630 if (mShareEnum ==
Take)
634 mBuf =
const_cast<char*
>(buffer);
635 mCapacity = mSize = length;
643 if ( &other ==
this )
649 if ( other.mBuf == other.mPreBuffer )
652 memcpy( mPreBuffer, other.mPreBuffer, other.mSize+1);
658 other.mBuf = other.mPreBuffer;
661 mCapacity = other.mCapacity;
662 mShareEnum = other.mShareEnum;
667 other.mCapacity = LocalAlloc;
669 other.mPreBuffer[0] = 0;
683 if (other.mBuf == other.mPreBuffer)
686 memcpy(mPreBuffer, other.mPreBuffer, other.mSize + 1);
694 mCapacity = other.mCapacity;
695 mShareEnum = other.mShareEnum;
703 if (mShareEnum ==
Data::Share || mCapacity < length+1)
706 resize(length,
false);
714 memmove(mBuf, buf, mSize);
725 if (mShareEnum ==
Data::Share || mCapacity < length)
728 resize(length,
false);
731 else if ( mCapacity != length )
745 if (lhs.mSize != rhs.mSize)
749 return memcmp(lhs.mBuf, rhs.mBuf, lhs.mSize) == 0;
756 if (strncmp(lhs.mBuf, rhs, lhs.mSize) != 0)
760 return strlen(rhs) == lhs.mSize;
766 return lhs.size() == rhs.size() && std::memcmp(lhs.data(), rhs.c_str(), rhs.size()) == 0;
769#if RESIP_HAVE_STRING_VIEW
773 return lhs.size() == rhs.size() && std::memcmp(lhs.data(), rhs.data(), rhs.size()) == 0;
780 int res = memcmp(lhs.mBuf, rhs.mBuf,
resipMin(lhs.mSize, rhs.mSize));
792 return (lhs.mSize < rhs.mSize);
801 int res = memcmp(lhs.mBuf, rhs,
resipMin(lhs.mSize, l));
813 return (lhs.mSize < l);
822 int res = memcmp(lhs, rhs.mBuf,
resipMin(l, rhs.mSize));
834 return (l < rhs.mSize);
844 return lhs.mSize < l;
846 return memcmp(lhs.mBuf, rhs.c_str(), lhs.mSize) < 0;
853 if (lhsSize != rhs.mSize)
855 return lhsSize < rhs.mSize;
857 return memcmp(lhs.c_str(), rhs.mBuf, lhsSize) < 0;
860#if RESIP_HAVE_STRING_VIEW
865 if (lhs.mSize != rhsSize)
867 return lhs.mSize < rhsSize;
869 return memcmp(lhs.mBuf, rhs.data(), lhs.mSize) < 0;
876 if (lhsSize != rhs.mSize)
878 return lhsSize < rhs.mSize;
880 return memcmp(lhs.data(), rhs.mBuf, lhsSize) < 0;
894 if (mShareEnum ==
Share)
896 resize(
data.mSize,
false);
900 if (
data.mSize > mCapacity)
902 resize(
data.mSize,
false);
910 memmove(mBuf,
data.mBuf, mSize);
924 return takeBuf(data);
954 tmp.mSize = mSize +
data.mSize;
955 tmp.mCapacity = tmp.mSize;
956 memcpy(tmp.mBuf, mBuf, mSize);
957 memcpy(tmp.mBuf + mSize,
data.mBuf,
data.mSize);
958 tmp.mBuf[tmp.mSize] = 0;
966 if (mCapacity < rhs.mSize)
968 resize(rhs.mSize,
true);
970 if (mSize < rhs.mSize)
972 memset(mBuf+mSize, 0, mCapacity - mSize);
977 char*
end = c2 + rhs.mSize;
1014 if (mShareEnum ==
Share)
1028 memmove(mBuf, str, mSize+1);
1040 tmp.mSize = mSize + l;
1041 tmp.mCapacity = tmp.mSize;
1042 memcpy(tmp.mBuf, mBuf, mSize);
1043 memcpy(tmp.mBuf + mSize, str, l+1);
1051 if (len > mCapacity)
1061 if (mCapacity <= mSize + len)
1064 resize(((mSize + len +16)*3)/2,
true);
1068 if (mShareEnum ==
Share)
1070 resize(mSize + len,
true);
1075 memmove(mBuf + mSize, str, len);
1087 tmp.mSize = mSize + 1;
1088 tmp.mCapacity = tmp.mSize;
1089 memcpy(tmp.mBuf, mBuf, mSize);
1090 tmp.mBuf[mSize] = c;
1091 tmp.mBuf[mSize+1] = 0;
1099 if (mShareEnum ==
Data::Share || mSize == mCapacity)
1101 const_cast<Data*
>(
this)->resize(mSize+1,
true);
1114#if RESIP_HAVE_STRING_VIEW
1116Data::toStringView()
const
1118 return std::string_view(
c_str(),
size());
1125 if (mShareEnum ==
Share)
1127 const_cast<Data*
>(
this)->resize(mSize,
true);
1133Data::resize(size_type newCapacity,
1138 char *oldBuf = mBuf;
1139 bool needToDelete=(mShareEnum==
Take);
1141 size_t newBytes = newCapacity + 1;
1142 if(newBytes <= newCapacity)
1145 throw std::range_error(
"newCapacity too big");
1148 if(newCapacity > LocalAlloc)
1150 mBuf =
new char[newBytes];
1161 memcpy(mBuf, oldBuf, mSize);
1170 mCapacity = newCapacity;
1178 MD5Update(&context,
reinterpret_cast < unsigned const char*
> (mBuf), (
unsigned int)mSize);
1180 unsigned char digestBuf[16];
1203 const char* p =
data();
1206 unsigned char c = *p++;
1227 int hi = (c & 0xF0)>>4;
1228 int low = (c & 0x0F);
1247 const char* p =
data();
1250 unsigned char c = *p++;
1269 strchr(
" \";/?:@&=+%$,\t-_.!~*'()", c))
1273 int hi = (c & 0xF0)>>4;
1274 int low = (c & 0x0F);
1293 const char* p =
data();
1296 unsigned char c = *p++;
1301 const char* high = strchr(
hexmap, tolower(
static_cast< unsigned char >(*p++)));
1302 const char* low = strchr(
hexmap, tolower(
static_cast< unsigned char >(*p++)));
1305 if (high == 0 && low == 0)
1312 int highInt = int(high -
hexmap);
1313 int lowInt = int(low -
hexmap);
1314 ret += char(highInt<<4 | lowInt);
1354 for (
const char* p =
data(); p !=
data()+
size(); ++p, ++i)
1356 unsigned char c = *p;
1388 for (
int i = 0; i < 256; ++i)
1423 for (
const char* p =
data(); p !=
data() +
size(); ++p)
1425 unsigned char c = *p;
1445 s <<
'%' << (
hexmap[(c & 0xF0)>>4]) << (
hexmap[(c & 0x0F)]);
1477 for (
const char* p =
data(); p !=
data() +
size(); ++p)
1479 unsigned char c = *p;
1510 for (
const char* p =
data(); p !=
data()+
size(); ++p, ++i)
1512 unsigned char c = *p;
1517 *(p+1) ==
'a' && *(p+2) ==
'm' && *(p+3) ==
'p' && *(p+4) ==
';')
1523 else if(i+3 <
size() &&
1524 *(p+1) ==
'l' && *(p+2) ==
't' && *(p+3) ==
';')
1530 else if(i+3 <
size() &&
1531 *(p+1) ==
'g' && *(p+2) ==
't' && *(p+3) ==
';')
1537 else if(i+5 <
size() &&
1538 *(p+1) ==
'a' && *(p+2) ==
'p' && *(p+3) ==
'o' && *(p+4) ==
's' && *(p+5) ==
';')
1544 else if(i+5 <
size() &&
1545 *(p+1) ==
'q' && *(p+2) ==
'u' && *(p+3) ==
'o' && *(p+4) ==
't' && *(p+5) ==
';')
1581 const char* p = mBuf;
1585 unsigned char temp = *p++;
1587 int hi = (temp & 0xf0)>>4;
1588 int low = (temp & 0xf);
1594 ret.mSize = 2*mSize;
1601 bool oddSize = mSize & 1;
1602 size_type resultSize = (mSize + (mSize & 1)) / 2;
1605 const unsigned char* p = (
unsigned char*)mBuf;
1618 for ( ; i < mSize; i+=2)
1620 const unsigned char high = *p++;
1621 const unsigned char low = *p++;
1622 if(!isHex(high) || !isHex(low))
1630 ret.mSize = resultSize;
1641 *p = tolower(
static_cast< unsigned char >(*p));
1654 *p = toupper(
static_cast< unsigned char >(*p));
1688 const char*
const end = mBuf + mSize;
1691 for (; p !=
end; ++p)
1693 if (!isspace(
static_cast< unsigned char >(*p)))
1711 for(; p !=
end; ++p)
1713 if (!isdigit(
static_cast< unsigned char >(*p)))
1726 unsigned long val = 0;
1728 const char*
const end = mBuf + mSize;
1730 for (; p !=
end; ++p)
1732 if (!isspace(
static_cast< unsigned char >(*p)))
1745 for(; p !=
end; ++p)
1747 if (!isdigit(
static_cast< unsigned char >(*p)))
1762 const char*
const end = mBuf + mSize;
1764 for (; p !=
end; ++p)
1766 if (!isspace(
static_cast< unsigned char >(*p)))
1779 for(; p !=
end; ++p)
1781 if (!isdigit(
static_cast< unsigned char >(*p)))
1796 const char*
const end = mBuf + mSize;
1798 for (; p !=
end; ++p)
1800 if (!isspace(
static_cast< unsigned char >(*p)))
1813 for(; p !=
end; ++p)
1815 if (!isdigit(
static_cast< unsigned char >(*p)))
1825#ifndef RESIP_FIXED_POINT
1831 const char*
const end = p + mSize;
1834 for (; p !=
end; ++p)
1836 if (!isspace(
static_cast< unsigned char >(*p)))
1854 for(; p !=
end; ++p)
1860 if (!isdigit(
static_cast< unsigned char >(*p)))
1873 for(; p !=
end; ++p)
1875 if (!isdigit(
static_cast< unsigned char >(*p)))
1883 return s*(val + d/div);
1890 if (pre.size() > size())
1895 return memcmp(data(), pre.
data(), pre.size()) == 0;
1901 if (pre.size() > size())
1906 return strncasecmp(data(), pre.
data(), pre.size()) == 0;
1912 if (post.size() > size())
1917 return memcmp(data() + (size()-post.size()), post.
data(), post.size()) == 0;
1923 if (post.size() > size())
1928 return strncasecmp(data() + (size() - post.size()), post.
data(), post.size()) == 0;
1937 return Data(mBuf+first, mSize-first);
1942 return Data(mBuf+first, count);
1965 const Data& replaceWith,
1972 const int incr = int(replaceWith.
size() - match.
size());
1975 offset =
find(match, offset+replaceWith.
size()))
1977 if (mSize + incr >= mCapacity)
1979 resize((mCapacity + incr) * 3 / 2,
true);
1987 memmove(mBuf + offset + replaceWith.
size(), mBuf + offset + match.
size(), mSize - offset - match.
size());
1988 memcpy(mBuf + offset, replaceWith.
data(), replaceWith.
size());
1997#ifndef RESIP_USE_STL_STREAMS
2001 return strm.write(d.mBuf, d.mSize);
2008 44, 9, 46, 184, 21, 30, 92, 231, 79, 7, 166, 237, 173, 72, 91, 123,
2009 212, 183, 16, 99, 85, 45, 190, 130, 118, 107, 169, 119, 100, 179, 251, 177,
2010 23, 125, 12, 101, 121, 246, 61, 38, 156, 114, 159, 57, 181, 145, 198, 182,
2011 58, 215, 174, 225, 82, 178, 150, 161, 63, 103, 32, 203, 68, 151, 139, 55,
2012 143, 2, 36, 110, 209, 154, 204, 89, 62, 17, 187, 226, 31, 105, 195, 208,
2013 49, 56, 238, 172, 37, 3, 234, 206, 134, 233, 19, 148, 64, 4, 10, 224,
2014 144, 88, 93, 191, 20, 131, 138, 199, 243, 244, 39, 50, 214, 87, 6, 84,
2015 185, 112, 171, 75, 192, 193, 239, 69, 106, 43, 194, 1, 78, 67, 116, 200,
2016 83, 70, 213, 25, 59, 137, 52, 13, 153, 42, 232, 0, 133, 210, 76, 33,
2017 255, 236, 124, 104, 65, 201, 53, 155, 140, 254, 54, 196, 120, 146, 216, 29,
2018 28, 86, 245, 90, 98, 26, 81, 115, 180, 66, 102, 136, 167, 51, 109, 132,
2019 77, 175, 14, 202, 222, 48, 223, 188, 40, 242, 157, 5, 128, 229, 71, 127,
2020 164, 207, 247, 8, 80, 149, 94, 160, 47, 117, 135, 176, 129, 142, 189, 97,
2021 11, 250, 221, 218, 96, 220, 35, 197, 152, 126, 219, 74, 170, 252, 163, 41,
2022 95, 27, 34, 22, 205, 230, 241, 186, 168, 228, 253, 249, 113, 108, 111, 211,
2023 235, 217, 165, 122, 15, 141, 158, 147, 240, 24, 162, 18, 60, 73, 227, 248
2035 unsigned char bytes[4];
2043 const unsigned char*
end = c +
size;
2044 for ( ; c !=
end; ++c)
2053 return ntohl((u_long)st);
2064 unsigned char bytes[4];
2072 const unsigned char*
end = c +
size;
2073 for ( ; c !=
end; ++c)
2075 unsigned char cc = tolower(*c);
2083 return ntohl((u_long)st);
2102 static const SipHashKey key = []()
2106 uint64_t seed[4] = { (
uint64_t)std::chrono::high_resolution_clock::now().time_since_epoch().count(),
2111 std::random_device rd;
2114 s ^= ((
uint64_t)rd() << 32) ^ rd();
2117 catch (
const std::exception&)
2120 SipHashKey k = { seed[0] ^ seed[2], seed[1] ^ seed[3] };
2129 return (x << b) | (x >> (64 - b));
2135 v0 += v1; v1 = rotl64(v1, 13); v1 ^= v0; v0 = rotl64(v0, 32);
2136 v2 += v3; v3 = rotl64(v3, 16); v3 ^= v2;
2137 v0 += v3; v3 = rotl64(v3, 21); v3 ^= v0;
2138 v2 += v1; v1 = rotl64(v1, 17); v1 ^= v2; v2 = rotl64(v2, 32);
2141template <
bool NoCase>
2143sipByte(
unsigned char c)
2146 if (NoCase && (
unsigned char)(c -
'A') < 26)
2153template <
bool NoCase>
2155sipHash13(
const unsigned char* c,
size_t size)
2157 const SipHashKey& key = sipHashKey();
2158 uint64_t v0 = 0x736f6d6570736575ULL ^ key.k0;
2159 uint64_t v1 = 0x646f72616e646f6dULL ^ key.k1;
2160 uint64_t v2 = 0x6c7967656e657261ULL ^ key.k0;
2161 uint64_t v3 = 0x7465646279746573ULL ^ key.k1;
2163 const unsigned char* end = c + (size & ~(size_t)7);
2164 for ( ; c != end; c += 8)
2167 for (
int i = 7; i >= 0; --i)
2169 m = (m << 8) | sipByte<NoCase>(c[i]);
2172 sipRound(v0, v1, v2, v3);
2177 for (
int i = (
int)(size & 7) - 1; i >= 0; --i)
2179 b |= sipByte<NoCase>(c[i]) << (8 * i);
2182 sipRound(v0, v1, v2, v3);
2186 sipRound(v0, v1, v2, v3);
2187 sipRound(v0, v1, v2, v3);
2188 sipRound(v0, v1, v2, v3);
2190 return (
size_t)(v0 ^ v1 ^ v2 ^ v3);
2198 return sipHash13<false>(c,
size);
2204 return sipHash13<true>(c,
size);
2207#if defined(RESIP_BIG_ENDIAN) || (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
2209#if !defined (get16bits)
2210#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[0])) << 8)\
2211 +(uint32_t)(((const uint8_t *)(d))[1]) )
2214#if !defined (get32bits)
2215#define get32bits(d) ((get16bits(d) << 16) + get16bits(d+2))
2221#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \
2222 || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
2223#define get16bits(d) (*((const uint16_t *) (d)))
2226#if !defined (get16bits)
2227#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\
2228 +(uint32_t)(((const uint8_t *)(d))[0]) )
2232#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \
2233 || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
2234#define get32bits(d) (*((const uint32_t *) (d)))
2237#if !defined (get32bits)
2238#define get32bits(d) ((get16bits(d+2) << 16) + get16bits(d))
2258 if (len <= 0 ||
data == NULL)
return 0;
2270 for (;len > 0; len--)
2345 for (
unsigned int i = 0; i < 8*
sizeof(size_t); ++i)
2384#define compUnalignedRemainder(d1, d2, size) \
2388 if( (*d1 ^ *d2) & 0xDF) \
2396 if((get16bits(d1) ^ get16bits(d2)) & 0xDFDF) \
2404 if( (*d1 ^ *d2) & 0xDF) \
2419 const char* d1(mBuf);
2420 const char* d2(rhs.mBuf);
2429 int unalignedPrefix(4-((ptrdiff_t)d1 & 3));
2435 size_t wordLen=(mSize-unalignedPrefix)>>2;
2436 int rem=(mSize-unalignedPrefix)&3;
2438 if((ptrdiff_t)(d2)%4==0)
2442 for (;wordLen > 0; wordLen--)
2446 if( (*wd1 ^ *wd2) & 0xDFDFDFDF)
2453 d2=(
const char*)wd2;
2457 for (;wordLen > 0; wordLen--)
2462 if( (*wd1 ^ test) & 0xDFDFDFDF)
2470 d1=(
const char*)wd1;
2479 std::bitset<256> result;
2481 for (
unsigned int i=0; i!=chars.mSize;++i)
2483 result.set(*(
unsigned char*)(chars.mBuf+i));
2490 const std::bitset<256>& shouldEscape)
const
2492 static char hex[] =
"0123456789ABCDEF";
2499 const unsigned char* anchor = (
unsigned char*)mBuf;
2500 const unsigned char* p = (
unsigned char*)mBuf;
2501 const unsigned char* e = (
unsigned char*)mBuf + mSize;
2514 else if (shouldEscape[*p])
2518 str.write((
char*)anchor, p-anchor);
2520 int hi = (*p & 0xF0)>>4;
2521 int low = (*p & 0x0F);
2523 str <<
'%' <<
hex[hi] <<
hex[low];
2533 str.write((
char*)anchor, p-anchor);
2542 is.open(filename.
c_str(), ios::binary );
2543 if ( !is.is_open() )
2545 throw DataException(
"Could not read file " + filename, __FILE__,__LINE__);
2553#if !defined(__MSL_CPP__) || (__MSL_CPP_ >= 0x00012000)
2554 is.seekg (0, ios::end);
2555 length = (int)is.tellg();
2556 is.seekg (0, ios::beg);
2560 FILE * tmpFile = fopen(filename.
c_str(),
"r+b");
2562 fseek(tmpFile, 0, SEEK_END);
2563 length = ftell(tmpFile);
2564 fseek(tmpFile, 0, SEEK_SET);
2576 char* buffer =
new char [length+1];
2579 is.read (buffer,length);
2592 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
2593 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
2594 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
2595 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
2596 -1,-1,-1,62,-1,62,-2,63,52,53,
2597 54,55,56,57,58,59,60,61,-1,-1,
2598 -1,-2,-1,-1,-1,0, 1, 2, 3, 4,
2599 5, 6, 7, 8, 9, 10,11,12,13,14,
2600 15,16,17,18,19,20,21,22,23,24,
2601 25,-1,-1,-1,-1,63,-1,26,27,28,
2602 29,30,31,32,33,34,35,36,37,38,
2603 39,40,41,42,43,44,45,46,47,48,
2604 49,50,51,-1,-1,-1,-1,-1
2619 for(
unsigned int i=0; i<
size(); i++ )
2621 unsigned int x = mBuf[i] & 0x7F;
2634 c3 = char( val & 0xFF ); val = val >> 8;
2635 c2 = char( val & 0xFF ); val = val >> 8;
2636 c1 = char( val & 0xFF ); val = val >> 8;
2648 if (wc==2) val = val<<12;
2649 if (wc==3) val = val<<6;
2651 c3 = char( val & 0xFF ); val = val >> 8;
2652 c2 = char( val & 0xFF ); val = val >> 8;
2653 c1 = char( val & 0xFF ); val = val >> 8;
2655 unsigned int xNext = mBuf[i] & 0x7F;
2678 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
2680 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.";
2686 int srcLength = (int)this->
size();
2687 unsigned int dstLimitLength = 4 * (srcLength / 3 + (srcLength%3==0 ? 0 : 1));
2688 unsigned char * dstData =
new unsigned char[dstLimitLength + 1];
2689 unsigned int dstIndex = 0;
2691 const char * p =
static_cast<const char *
>( this->
data() );
2693 for(
int index=0;index<srcLength;index+=3)
2695 unsigned char codeBits = (p[index] & 0xfc)>>2;
2698 dstData[dstIndex++] = codeChar[codeBits];
2702 codeBits = ((p[index]&0x3)<<4);
2703 if (index+1 < srcLength)
2705 codeBits |= ((p[index+1]&0xf0)>>4);
2708 dstData[dstIndex++] = codeChar[codeBits];
2711 if (index+1 >= srcLength)
2713 dstData[dstIndex++] = codeChar[64];
2715 dstData[dstIndex++] = codeChar[64];
2721 codeBits = ((p[index+1]&0xf)<<2);
2722 if (index+2 < srcLength)
2724 codeBits |= ((p[index+2]&0xc0)>>6);
2727 dstData[dstIndex++] = codeChar[codeBits];
2730 if (index+2 >= srcLength)
2732 dstData[dstIndex++] = codeChar[64];
2738 codeBits = ((p[index+2]&0x3f));
2740 dstData[dstIndex++] = codeChar[codeBits];
2745 dstData[dstIndex] = 0;
static unsigned char codeCharUnsafe[]
static const int Int32MaxSize
static const unsigned char randomPermutation[256]
static signed char base64Lookup[128]
int hexpair2int(char high, char low)
bool urlNonEncodedCharsInitFn()
static const int UInt64MaxSize
bool urlNonEncodedChars[256]
static unsigned char codeCharSafe[]
#define compUnalignedRemainder(d1, d2, size)
static const int CharMaxSize
static const int DoubleMaxSize
static const char hexmap[]
static const signed char inversehexmap[]
#define HashValueImp(type, ret)
static Data digest("digest")
#define resip_assert(x)
This file needs to work for both C and C++ code.
static Data decode(const Data &)
static const bool isCharHex[256]
An iostream that operates on an existing Data.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
EncodeStream & escapeToStream(EncodeStream &str, Predicate shouldEscape) const
Performs escaping of this Data according to the indicated Predicate.
Data xmlCharDataDecode() const
Performs in-place XML Character Data un-escaping of a Data.
Data & uppercase()
Converts this Data to uppercase.
Data base64decode() const
Performs RFC 3548 Base 64 decoding of the contents of this data.
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 mad...
static const Data Empty
Constant that represents a zero-length data.
const char * c_str() const
Returns a null-terminated string representing.
ShareEnum
The various memory management behaviors.
@ Share
The Data instance will use the buffer in a read-only mode.
@ Borrow
The Data instance is borrowing the memory from the passed in buffer.
@ Take
The Data instance takes complete ownership of the buffer.
Data base64encode(bool useUrlSafe=false) const
Performs RFC 3548 Base 64 encoding of the contents of this data.
static size_t rawKeyedCaseInsensitiveHash(const unsigned char *c, size_t size)
As rawKeyedHash, after normalizing ASCII alphabetic characters to lowercase; consistent with isEqualN...
char & at(size_type p)
Returns the character at the specified position.
Data & operator^=(const Data &rhs)
Performs an in-place exclusive-or of this buffer buffer with the specified buffer.
int replace(const Data &match, const Data &target, int max=INT_MAX)
Replaces up to max occurrences of the bytes match with target.
bool postfixNoCase(const Data &post) const noexcept
const char * end() const noexcept
Returns a pointer to the end of the buffer used by the Data.
static Data fromFile(const Data &filename)
Data charUnencoded() const
Performs RFC 3261 un-escaping of SIP URIs.
unsigned long convertUnsignedLong() const
bool sizeEqualCaseInsensitiveTokenCompare(const Data &rhs) const
char * getBuf(size_type length)
Set size to be exactly {length}, extending buffer if needed.
Data xmlCharDataEncode() const
Performs in-place XML Character Data escaping of a Data.
Data & operator=(const Data &data)
size_t keyedCaseInsensitiveHash() const
Creates a keyed hash based on the contents of this Data, after normalizing ASCII alphabetic character...
uint64_t convertUInt64() const
Takes the contents of the Data and converts them to an unsigned 64-bit integer.
static const PreallocateType Preallocate
used only to disambiguate constructors
std::string toString() const
Convert to a C++ string.
bool prefix(const Data &pre) const noexcept
Returns true if this Data starts with the bytes indicated by the passed-in Data.
Data & append(const char *str, size_type len)
Appends the specified number of bytes to the end of this Data.
Data & duplicate(const Data &other)
Functional equivalent of: *this = Data(buf, length) and Data& copy(const char *buf,...
size_t caseInsensitivehash() const
Creates a 32-bit hash based on the contents of this Data, after normalizing any alphabetic characters...
Data substr(size_type first, size_type count=Data::npos) const
Copies a portion of this Data into a new Data.
Data & takeBuf(Data &other) noexcept
Take the data from {other}.
bool empty() const noexcept
Checks whether the Data is empty.
Data charEncoded() const
Performs RFC 3261 escaping of SIP URIs.
Data & lowercase()
Converts this Data to lowercase.
Data urlDecoded() const
Performs in-place HTTP URL un-escaping of a Data.
size_type size() const noexcept
Returns the number of bytes in this Data.
EncodeStream & urlEncode(EncodeStream &s) const
Escapes a Data to a stream according to HTTP URL encoding rules.
static bool init(DataLocalSize< RESIP_DATA_LOCAL_SIZE > arg)
Initializes Data class.
EncodeStream & urlDecode(EncodeStream &s) const
Un-escapes a Data to a stream according to HTTP URL encoding rules.
size_type find(const Data &match, size_type start=0) const
Finds a specified sequence of bytes in this Data.
static const size_type npos
Represents an impossible position; returned to indicate failure to find.
static size_t rawKeyedHash(const unsigned char *c, size_t size)
Creates a hash based on the contents of the indicated buffer, using SipHash-1-3 with a key chosen ran...
Data operator+(const Data &rhs) const
Concatenates two Data objects.
Data urlEncoded() const
Performs in-place HTTP URL escaping of a Data.
Data & schemeLowercase()
Converts this Data to lowercase, assuming this Data only consists of scheme characters.
Data trunc(size_type trunc) const
Shortens the size of this Data.
Data fromHex() const
Returns the binary form of the hexadecimal string in this Data.
size_t caseInsensitiveTokenHash() const
A faster version of caseInsensitiveHash that has the same collision properties if this Data is made u...
size_type truncate(size_type len)
Shortens the size of this 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,...
static size_t rawHash(const unsigned char *c, size_t size)
Creates a 32-bit hash based on the contents of the indicated buffer.
Data & copy(const char *buf, size_type length)
Functional equivalent of: *this = Data(buf, length) but avoids the intermediate allocation and free.
Data hex() const
Returns a hexadecimal representation of the contents of this Data.
size_t hash() const
Creates a 32-bit hash based on the contents of this Data.
double convertDouble() const
Takes the contents of the Data and converts them to a double precision floating point value.
int convertInt() const
Takes the contents of the Data and converts them to an integer.
Data escaped() const
Returns a representation of the contents of the data with any non-printable characters escaped.
bool postfix(const Data &post) const noexcept
Returns true if this Data ends with the bytes indicated by the passed-in Data.
Data & clear()
Clears the contents of this Data.
static std::bitset< 256 > toBitset(const resip::Data &chars)
Creates a bitset reflecting the contents of this data (as a set) ie.
size_t keyedHash() const
Creates a keyed hash based on the contents of this Data.
Data md5(EncodingType type=HEX) const
Computes the MD5 hash of the current data.
size_t convertSize() const
Takes the contents of the Data and converts them to a size_t.
const char * data() const noexcept
Returns a pointer to the contents of this Data.
bool prefixNoCase(const Data &pre) const noexcept
void reserve(size_type capacity)
Guarantees that the underlying buffer used by the Data is at least the number of bytes specified.
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...
Data & truncate2(size_type len)
Shortens the size of this Data so length is at most of {len}.
Provides string-parsing functionality with protection from buffer overflow.
CurrentPosition skipToChars(const char *cs)
CurrentPosition position() const
dcm! – add UnusedChecking(_enum) below;
const _Tp & resipMin(const _Tp &__a, const _Tp &__b)
void MD5Final(unsigned char digest[16], struct MD5Context *context)
void MD5Init(struct MD5Context *context)
unsigned long long uint64_t
bool operator<(const Data &lhs, const Data &rhs)
const _Tp & resipMax(const _Tp &__a, const _Tp &__b)
void MD5Update(struct MD5Context *context, md5byte const *buf, unsigned len)
EncodeStream & operator<<(EncodeStream &strm, const BaseException &e)
bool operator==(const char *lhs, const Data &rhs)
_W64 unsigned int uintptr_t
unsigned __int64 uint64_t