Sync llcommon with Alchemy a bit.

llmath::llround->ll_round
LL_ICC->LL_INTELC
Add llpredicate
Add LL_CPP11 macro
Remove llhash
Update llinitparam, llsd and all relatives of it.
This commit is contained in:
Inusaito Sayori
2015-03-20 22:04:04 -04:00
parent 16a2b28c1b
commit 72080e79e9
135 changed files with 1940 additions and 1282 deletions

View File

@@ -30,9 +30,9 @@
#include "llsdserialize.h"
#include "llpointer.h"
#include "llstreamtools.h" // for fullread
#include "llbase64.h"
#include <iostream>
#include "apr_base64.h"
#ifdef LL_STANDALONE
# include <zlib.h>
@@ -43,6 +43,7 @@
#if !LL_WINDOWS
#include <netinet/in.h> // htonl & ntohl
#endif
#include "apr_general.h" // for strncasecmp
#include "lldate.h"
#include "llsd.h"
@@ -648,7 +649,7 @@ S32 LLSDNotationParser::doParse(std::istream& istr, LLSD& data) const
default:
parse_count = PARSE_FAILURE;
llinfos << "Unrecognized character while parsing: int(" << (int)c
<< ")" << llendl;
<< ")" << LL_ENDL;
break;
}
if(PARSE_FAILURE == parse_count)
@@ -807,12 +808,12 @@ bool LLSDNotationParser::parseBinary(std::istream& istr, LLSD& data) const
get(istr, *(coded_stream.rdbuf()), '\"');
c = get(istr);
std::string encoded(coded_stream.str());
S32 len = apr_base64_decode_len(encoded.c_str());
size_t len = LLBase64::requiredDecryptionSpace(encoded);
std::vector<U8> value;
if(len)
{
value.resize(len);
len = apr_base64_decode_binary(&value[0], encoded.c_str());
len = LLBase64::decode(encoded, &value[0], len);
value.resize(len);
}
data = value;
@@ -873,7 +874,7 @@ S32 LLSDBinaryParser::doParse(std::istream& istr, LLSD& data) const
{
/**
* Undefined: '!'<br>
* Boolean: 't' for true 'f' for false<br>
* Boolean: '1' for true '0' for false<br>
* Integer: 'i' + 4 bytes network byte order<br>
* Real: 'r' + 8 bytes IEEE double<br>
* UUID: 'u' + 16 byte unsigned integer<br>
@@ -999,7 +1000,7 @@ S32 LLSDBinaryParser::doParse(std::istream& istr, LLSD& data) const
if(istr.fail())
{
llinfos << "STREAM FAILURE reading binary (notation-style) string."
<< llendl;
<< LL_ENDL;
parse_count = PARSE_FAILURE;
}
break;
@@ -1088,7 +1089,7 @@ S32 LLSDBinaryParser::doParse(std::istream& istr, LLSD& data) const
default:
parse_count = PARSE_FAILURE;
llinfos << "Unrecognized character while parsing: int(" << (int)c
<< ")" << llendl;
<< ")" << LL_ENDL;
break;
}
if(PARSE_FAILURE == parse_count)
@@ -1260,13 +1261,38 @@ std::string LLSDNotationFormatter::escapeString(const std::string& in)
// virtual
S32 LLSDNotationFormatter::format(const LLSD& data, std::ostream& ostr, U32 options) const
{
S32 rv = format_impl(data, ostr, options, 0);
return rv;
}
S32 LLSDNotationFormatter::format_impl(const LLSD& data, std::ostream& ostr, U32 options, U32 level) const
{
S32 format_count = 1;
std::string pre;
std::string post;
if (options & LLSDFormatter::OPTIONS_PRETTY)
{
for (U32 i = 0; i < level; i++)
{
pre += " ";
}
post = "\n";
}
switch(data.type())
{
case LLSD::TypeMap:
{
if (0 != level) ostr << post << pre;
ostr << "{";
std::string inner_pre;
if (options & LLSDFormatter::OPTIONS_PRETTY)
{
inner_pre = pre + " ";
}
bool need_comma = false;
LLSD::map_const_iterator iter = data.beginMap();
LLSD::map_const_iterator end = data.endMap();
@@ -1274,18 +1300,18 @@ S32 LLSDNotationFormatter::format(const LLSD& data, std::ostream& ostr, U32 opti
{
if(need_comma) ostr << ",";
need_comma = true;
ostr << '\'';
ostr << post << inner_pre << '\'';
serialize_string((*iter).first, ostr);
ostr << "':";
format_count += format((*iter).second, ostr);
format_count += format_impl((*iter).second, ostr, options, level + 2);
}
ostr << "}";
ostr << post << pre << "}";
break;
}
case LLSD::TypeArray:
{
ostr << "[";
ostr << post << pre << "[";
bool need_comma = false;
LLSD::array_const_iterator iter = data.beginArray();
LLSD::array_const_iterator end = data.endArray();
@@ -1293,7 +1319,7 @@ S32 LLSDNotationFormatter::format(const LLSD& data, std::ostream& ostr, U32 opti
{
if(need_comma) ostr << ",";
need_comma = true;
format_count += format(*iter, ostr);
format_count += format_impl(*iter, ostr, options, level + 1);
}
ostr << "]";
break;
@@ -1343,7 +1369,7 @@ S32 LLSDNotationFormatter::format(const LLSD& data, std::ostream& ostr, U32 opti
case LLSD::TypeString:
ostr << '\'';
serialize_string(data.asString(), ostr);
serialize_string(data.asStringRef(), ostr);
ostr << '\'';
break;
@@ -1360,9 +1386,26 @@ S32 LLSDNotationFormatter::format(const LLSD& data, std::ostream& ostr, U32 opti
case LLSD::TypeBinary:
{
// *FIX: memory inefficient.
std::vector<U8> buffer = data.asBinary();
const std::vector<U8>& buffer = data.asBinary();
ostr << "b(" << buffer.size() << ")\"";
if(buffer.size()) ostr.write((const char*)&buffer[0], buffer.size());
if(buffer.size())
{
if (options & LLSDFormatter::OPTIONS_PRETTY_BINARY)
{
std::ios_base::fmtflags old_flags = ostr.flags();
ostr.setf( std::ios::hex, std::ios::basefield );
ostr << "0x";
for (size_t i = 0; i < buffer.size(); i++)
{
ostr << (int) buffer[i];
}
ostr.flags(old_flags);
}
else
{
ostr.write((const char*)&buffer[0], buffer.size());
}
}
ostr << "\"";
break;
}
@@ -1460,7 +1503,7 @@ S32 LLSDBinaryFormatter::format(const LLSD& data, std::ostream& ostr, U32 option
case LLSD::TypeString:
ostr.put('s');
formatString(data.asString(), ostr);
formatString(data.asStringRef(), ostr);
break;
case LLSD::TypeDate:
@@ -1478,9 +1521,8 @@ S32 LLSDBinaryFormatter::format(const LLSD& data, std::ostream& ostr, U32 option
case LLSD::TypeBinary:
{
// *FIX: memory inefficient.
ostr.put('b');
std::vector<U8> buffer = data.asBinary();
const std::vector<U8>& buffer = data.asBinary();
U32 size_nbo = htonl(buffer.size());
ostr.write((const char*)(&size_nbo), sizeof(U32));
if(buffer.size()) ostr.write((const char*)&buffer[0], buffer.size());
@@ -2080,6 +2122,7 @@ std::string zip_llsd(LLSD& data)
return result;
}
// <alchemy>
//decompress a block of LLSD from provided istream
// not very efficient -- creats a copy of decompressed LLSD block in memory
// and deserializes from that copy using LLSDSerialize
@@ -2109,13 +2152,6 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size)
strm.avail_out = CHUNK;
strm.next_out = out;
ret = inflate(&strm, Z_NO_FLUSH);
if (ret == Z_STREAM_ERROR)
{
inflateEnd(&strm);
free(result);
delete [] in;
return false;
}
switch (ret)
{
@@ -2123,6 +2159,7 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size)
ret = Z_DATA_ERROR;
case Z_DATA_ERROR:
case Z_MEM_ERROR:
case Z_STREAM_ERROR:
inflateEnd(&strm);
free(result);
delete [] in;
@@ -2172,6 +2209,7 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size)
free(result);
return true;
}
//This unzip function will only work with a gzip header and trailer - while the contents
//of the actual compressed data is the same for either format (gzip vs zlib ), the headers
//and trailers are different for the formats.
@@ -2201,27 +2239,19 @@ U8* unzip_llsdNavMesh( bool& valid, unsigned int& outsize, std::istream& is, S32
strm.avail_out = CHUNK;
strm.next_out = out;
ret = inflate(&strm, Z_NO_FLUSH);
if (ret == Z_STREAM_ERROR)
{
inflateEnd(&strm);
free(result);
delete [] in;
valid = false;
}
switch (ret)
{
case Z_NEED_DICT:
ret = Z_DATA_ERROR;
case Z_DATA_ERROR:
case Z_MEM_ERROR:
case Z_STREAM_ERROR:
inflateEnd(&strm);
free(result);
delete [] in;
valid = false;
break;
return NULL;
}
U32 have = CHUNK-strm.avail_out;
result = (U8*) realloc(result, cur_size + have);
@@ -2248,5 +2278,5 @@ U8* unzip_llsdNavMesh( bool& valid, unsigned int& outsize, std::istream& is, S32
return result;
}
// </alchemy>