Example #1
0
   UInt8 *serialize()
   {
 	    UInt32 size = getSerializedSize();
       UInt8 * result = new UInt8[size];
       int pos = 0;
       iviLink::stringToBuffer(mName, result);
       pos += iviLink::stringInBufSize(mName);
       iviLink::stringToBuffer(mAddress, result + pos);
       pos += iviLink::stringInBufSize(mAddress);
       *(reinterpret_cast<UInt32*>(result+pos))=ByteOrder::hton32(mConnection);
       pos += sizeof(UInt32);
       iviLink::stringToBuffer(mUid.value(), result + pos);
       pos += iviLink::stringInBufSize(mUid.value());
       *(reinterpret_cast<UInt64*>(result+pos))=ByteOrder::hton64(static_cast<UInt64>(mLastSeenTime));
       pos += sizeof(UInt64);
       *(reinterpret_cast<UInt32*>(result+pos))=ByteOrder::hton32(mOS);
       pos += sizeof(UInt32);
       return result;
   }
Example #2
0
 UInt32 getSerializedSize()
 {
     UInt32 size = iviLink::stringInBufSize(mName)
                 + iviLink::stringInBufSize(mAddress)
                 + sizeof(UInt32)
                 + iviLink::stringInBufSize(mUid.value())
                 + sizeof(UInt64)
                 + sizeof(UInt32);
     return size;
 }
Example #3
0
iviLink::BaseUid CTrustList::getOurUid() const
{
	LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__);
	BaseUid uid;
	BaseError err = mpStorage->getOurUid(uid);
	if (!err.isNoError())
	{
		LOG4CPLUS_WARN(msLogger, static_cast<std::string>(err));
		uid = generateNewUid();
		LOG4CPLUS_INFO(msLogger, "Our newly-generated uid is: " + uid.value());
		err = mpStorage->setOurUid(uid);
		if (!err.isNoError())
			LOG4CPLUS_ERROR(msLogger, static_cast<std::string>(err));
	}
	else
	{
		LOG4CPLUS_INFO(msLogger, "Our stored uid is: " + uid.value());		
	}

	return uid;
}
Example #4
0
    void deserialize(UInt8* data)
    {
   	    int pos = 0;
        mName = iviLink::bufferToString(data);
        pos = iviLink::stringInBufSize(mName);

        mAddress = iviLink::bufferToString(data + pos);
        pos += iviLink::stringInBufSize(mAddress);

        mConnection = static_cast<ConnectionType>(ByteOrder::ntoh32(*(reinterpret_cast<UInt32*>(data + pos))));
        pos += sizeof(UInt32);

        mUid = iviLink::bufferToString(data + pos);
        pos += iviLink::stringInBufSize(mUid.value());

        mLastSeenTime = static_cast<time_t>(ByteOrder::ntoh64(*(reinterpret_cast<UInt64*>(data + pos))));
        pos += sizeof(UInt64);

        mOS = static_cast<DeviceOs>(ByteOrder::ntoh32(*(reinterpret_cast<UInt32*>(data + pos))));
    }
Example #5
0
CTrustListError CFileStorage::setOurUid(BaseUid const& uid)
{
   LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__);
   // if (!isReady())
   //    return CTrustListError(CTrustListError::ERROR_STORAGE, gsModuleName, "file is not ready");

   Json::Value root;
   if (!reopen(ios::in) || !read(file, root))
   {
      //return CTrustListError(CTrustListError::ERROR_STORAGE, gsModuleName, "unable to parse file");
      LOG4CPLUS_WARN(msLogger, "unable to parse file");
   }

   root[gsOurTag] = uid.value();
   
   if (!reopen(ios::in | ios::out | ios::trunc))
      return CTrustListError(CTrustListError::ERROR_STORAGE, gsModuleName, "unable to reopen file");
   
   if (!write(file, root))
      return CTrustListError(CTrustListError::ERROR_STORAGE, gsModuleName, "unable to write file");

   return CTrustListError::NoTLError(gsModuleName);;
}