mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-11 10:35:22 -04:00
Merge branch 'master' into jsonapi
This commit is contained in:
commit
047ae7f723
260 changed files with 1737 additions and 1178 deletions
|
@ -26,8 +26,10 @@
|
|||
#include "retroshare/rstypes.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "util/rsnet.h"
|
||||
#include "util/rstime.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdint>
|
||||
|
||||
/* UInt8 get/set */
|
||||
|
||||
|
@ -287,15 +289,19 @@ bool setRawString(void *data, uint32_t size, uint32_t *offset, const std::string
|
|||
return true;
|
||||
}
|
||||
|
||||
bool getRawTimeT(const void *data,uint32_t size,uint32_t *offset,time_t& t)
|
||||
bool getRawTimeT(const void *data,uint32_t size,uint32_t *offset,rstime_t& t)
|
||||
{
|
||||
uint64_t T ;
|
||||
bool res = getRawUInt64(data,size,offset,&T) ;
|
||||
t = T ;
|
||||
uint64_t T;
|
||||
bool res = getRawUInt64(data,size,offset,&T);
|
||||
t = T;
|
||||
|
||||
return res ;
|
||||
if(t < 0) // [[unlikely]]
|
||||
std::cerr << __PRETTY_FUNCTION__ << " got a negative time: " << t
|
||||
<< " this seems fishy, report to the developers!" << std::endl;
|
||||
|
||||
return res;
|
||||
}
|
||||
bool setRawTimeT(void *data, uint32_t size, uint32_t *offset, const time_t& t)
|
||||
bool setRawTimeT(void *data, uint32_t size, uint32_t *offset, const rstime_t& t)
|
||||
{
|
||||
return setRawUInt64(data,size,offset,t) ;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,9 @@
|
|||
#include <string>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <retroshare/rsids.h>
|
||||
|
||||
#include "retroshare/rsids.h"
|
||||
#include "util/rstime.h"
|
||||
|
||||
/*******************************************************************
|
||||
* This is at the lowlevel packing routines. They are usually
|
||||
|
@ -63,8 +65,8 @@ uint32_t getRawStringSize(const std::string &outStr);
|
|||
bool getRawString(const void *data, uint32_t size, uint32_t *offset, std::string &outStr);
|
||||
bool setRawString(void *data, uint32_t size, uint32_t *offset, const std::string &inStr);
|
||||
|
||||
bool getRawTimeT(const void *data, uint32_t size, uint32_t *offset, time_t& outStr);
|
||||
bool setRawTimeT(void *data, uint32_t size, uint32_t *offset, const time_t& inStr);
|
||||
bool getRawTimeT(const void *data, uint32_t size, uint32_t *offset, rstime_t& outTime);
|
||||
bool setRawTimeT(void *data, uint32_t size, uint32_t *offset, const rstime_t& inTime);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#include <time.h>
|
||||
#include "util/rstime.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rsmailtransportitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
|
|
@ -75,7 +75,7 @@ class Counter
|
|||
static int total_rsitem_mallocs = 0 ;
|
||||
static int total_rsitem_frees = 0 ;
|
||||
static int total_rsitem_freed = 0 ;
|
||||
static time_t last_time = 0 ;
|
||||
static rstime_t last_time = 0 ;
|
||||
|
||||
void *RsItem::operator new(size_t s)
|
||||
{
|
||||
|
@ -85,7 +85,7 @@ void *RsItem::operator new(size_t s)
|
|||
|
||||
++size_hits[ s ].v() ;
|
||||
|
||||
time_t now = time(NULL);
|
||||
rstime_t now = time(NULL);
|
||||
++nb_rsitem_creations ;
|
||||
total_rsitem_mallocs += s ;
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
//
|
||||
// private:
|
||||
// uint32_t count ; // example of an int type. All int sizes are supported
|
||||
// std::map<uint32_t,time_t> update_times ; // example of a std::map. All std containers are supported.
|
||||
// std::map<uint32_t,rstime_t> update_times ; // example of a std::map. All std containers are supported.
|
||||
// RsTlvSecurityKey key ; // example of a TlvItem class.
|
||||
// BIGNUM *dh_key; // example of a class that needs its own serializer (see below)
|
||||
// };
|
||||
|
|
|
@ -27,9 +27,9 @@
|
|||
#include "serialiser/rsserializable.h"
|
||||
#include "util/radix64.h"
|
||||
#include "util/rsprint.h"
|
||||
#include "util/rstime.h"
|
||||
|
||||
#include <iomanip>
|
||||
#include <time.h>
|
||||
#include <string>
|
||||
#include <typeinfo> // for typeid
|
||||
|
||||
|
@ -93,7 +93,7 @@ template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint3
|
|||
{
|
||||
return setRawUInt64(data,size,&offset,member);
|
||||
}
|
||||
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const time_t& member)
|
||||
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const rstime_t& member)
|
||||
{
|
||||
return setRawTimeT(data,size,&offset,member);
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t siz
|
|||
{
|
||||
return getRawUInt64(data,size,&offset,&member);
|
||||
}
|
||||
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, time_t& member)
|
||||
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, rstime_t& member)
|
||||
{
|
||||
return getRawTimeT(data,size,&offset,member);
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ template<> uint32_t RsTypeSerializer::serial_size(const uint64_t& /* member*/)
|
|||
{
|
||||
return 8;
|
||||
}
|
||||
template<> uint32_t RsTypeSerializer::serial_size(const time_t& /* member*/)
|
||||
template<> uint32_t RsTypeSerializer::serial_size(const rstime_t& /* member*/)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
@ -187,9 +187,9 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const uint64_
|
|||
{
|
||||
std::cerr << " [uint64_t ] " << n << ": " << std::to_string(V) << std::endl;
|
||||
}
|
||||
template<> void RsTypeSerializer::print_data(const std::string& n, const time_t& V)
|
||||
template<> void RsTypeSerializer::print_data(const std::string& n, const rstime_t& V)
|
||||
{
|
||||
std::cerr << " [time_t ] " << n << ": " << V << " (" << time(NULL)-V << " secs ago)" << std::endl;
|
||||
std::cerr << " [rstime_t ] " << n << ": " << V << " (" << time(NULL)-V << " secs ago)" << std::endl;
|
||||
}
|
||||
|
||||
#define SIMPLE_TO_JSON_DEF(T) \
|
||||
|
@ -210,23 +210,7 @@ template<> bool RsTypeSerializer::to_JSON( const std::string& memberName, \
|
|||
|
||||
SIMPLE_TO_JSON_DEF(bool)
|
||||
SIMPLE_TO_JSON_DEF(int32_t)
|
||||
|
||||
template<> bool RsTypeSerializer::to_JSON( const std::string& memberName,
|
||||
const time_t& member, RsJson& jDoc )
|
||||
{
|
||||
rapidjson::Document::AllocatorType& allocator = jDoc.GetAllocator();
|
||||
|
||||
rapidjson::Value key;
|
||||
key.SetString(memberName.c_str(), memberName.length(), allocator);
|
||||
|
||||
// without this compilation may break depending on how time_t is defined
|
||||
int64_t tValue = member;
|
||||
rapidjson::Value value(tValue);
|
||||
|
||||
jDoc.AddMember(key, value, allocator);
|
||||
|
||||
return true;
|
||||
}
|
||||
SIMPLE_TO_JSON_DEF(rstime_t)
|
||||
|
||||
SIMPLE_TO_JSON_DEF(uint8_t)
|
||||
SIMPLE_TO_JSON_DEF(uint16_t)
|
||||
|
@ -254,12 +238,12 @@ bool RsTypeSerializer::from_JSON( const std::string& memberName,
|
|||
}
|
||||
|
||||
template<> /*static*/
|
||||
bool RsTypeSerializer::from_JSON( const std::string& memberName, time_t& member,
|
||||
bool RsTypeSerializer::from_JSON( const std::string& memberName, rstime_t& member,
|
||||
RsJson& jDoc )
|
||||
{
|
||||
SAFE_GET_JSON_V();
|
||||
ret = ret && v.IsInt();
|
||||
if(ret) member = v.GetInt();
|
||||
ret = ret && v.IsInt64();
|
||||
if(ret) member = v.GetInt64();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -290,11 +290,11 @@ struct RsTypeSerializer
|
|||
// Use same allocator to avoid deep copy
|
||||
RsGenericSerializer::SerializeContext kCtx(
|
||||
nullptr, 0, ctx.mFlags, &allocator );
|
||||
serial_process<T>(j, kCtx, const_cast<T&>(kv.first), "key");
|
||||
serial_process(j, kCtx, const_cast<T&>(kv.first), "key");
|
||||
|
||||
RsGenericSerializer::SerializeContext vCtx(
|
||||
nullptr, 0, ctx.mFlags, &allocator );
|
||||
serial_process<U>(j, vCtx, const_cast<U&>(kv.second), "value");
|
||||
serial_process(j, vCtx, const_cast<U&>(kv.second), "value");
|
||||
|
||||
if(kCtx.mOk && vCtx.mOk)
|
||||
{
|
||||
|
@ -394,8 +394,8 @@ struct RsTypeSerializer
|
|||
RsGenericSerializer::SerializeContext lCtx(
|
||||
nullptr, 0, ctx.mFlags, &allocator );
|
||||
|
||||
serial_process(j, ctx, p.first, "first");
|
||||
serial_process(j, ctx, p.second, "second");
|
||||
serial_process(j, lCtx, p.first, "first");
|
||||
serial_process(j, lCtx, p.second, "second");
|
||||
|
||||
rapidjson::Value key;
|
||||
key.SetString(memberName.c_str(), memberName.length(), allocator);
|
||||
|
@ -434,8 +434,8 @@ struct RsTypeSerializer
|
|||
RsGenericSerializer::SerializeContext lCtx(nullptr, 0, ctx.mFlags);
|
||||
lCtx.mJson.SetObject() = v; // Beware of move semantic!!
|
||||
|
||||
serial_process(j, ctx, p.first, "first");
|
||||
serial_process(j, ctx, p.second, "second");
|
||||
serial_process(j, lCtx, p.first, "first");
|
||||
serial_process(j, lCtx, p.second, "second");
|
||||
ctx.mOk &= lCtx.mOk;
|
||||
|
||||
break;
|
||||
|
@ -532,7 +532,7 @@ struct RsTypeSerializer
|
|||
for(uint32_t i=0; i<n; ++i)
|
||||
{
|
||||
T tmp;
|
||||
serial_process<T>(j,ctx,tmp,memberName);
|
||||
serial_process(j,ctx,tmp,memberName);
|
||||
v.insert(tmp);
|
||||
}
|
||||
break;
|
||||
|
@ -590,7 +590,7 @@ struct RsTypeSerializer
|
|||
for(uint32_t i=0;i<n;++i)
|
||||
{
|
||||
T tmp;
|
||||
serial_process<T>(j,ctx,tmp,memberName);
|
||||
serial_process(j,ctx,tmp,memberName);
|
||||
v.push_back(tmp);
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue