コード例 #1
0
void
DirEntity::PackDataObjects(BaseMessage& theMsgR, const DataObjectTypeSet& theSetR,
                           unsigned long theFlags)
{
	WTRACE("DirEntity::PackDataObjects");
	WDBG_LL("DirEntity::PackDataObject Packing data objects, size=" << theSetR.size());
	theMsgR.AppendShort(theSetR.size());

	bool packType = ((theFlags & WONMsg::GF_ADDDOTYPE) != 0);
	bool packData = ((theFlags & WONMsg::GF_ADDDODATA) != 0);
	DataObjectTypeSet::const_iterator anItr(theSetR.begin());
	for (; anItr != theSetR.end(); anItr++)
	{
		if (packType)
		{
			unsigned char aTypeLen = anItr->GetDataType().size();
			theMsgR.AppendByte(aTypeLen);
			theMsgR.AppendBytes(aTypeLen, anItr->GetDataType().data());
		}

		if (packData)
		{
			unsigned short aDataLen = anItr->GetData().size();
			theMsgR.AppendShort(aDataLen);
			theMsgR.AppendBytes(aDataLen, anItr->GetData().data());
		}
	}
}
コード例 #2
0
unsigned long
DirEntity::ComputeSize(unsigned long theGetFlags, const DataObjectTypeSet& theSetR) const
{
	unsigned long aSize = 0;

	// Add type if needed
	if (theGetFlags & WONMsg::GF_ADDTYPE)
		aSize += sizeof(mType);

	// Entity specific fields
	switch (mType)
	{
	case DirEntity::ET_DIRECTORY:
		// Add dir path if needed
		if (theGetFlags & WONMsg::GF_DIRADDPATH)
			aSize += TRawMsg::ComputeWStringPackSize(mPath);
		// Add dir name if needed
		if (theGetFlags & WONMsg::GF_DIRADDNAME)
			aSize += TRawMsg::ComputeWStringPackSize(mName);
		// Add dir visibility if needed
		if (theGetFlags & WONMsg::GF_DIRADDVISIBLE)
			aSize += sizeof(mVisible);
		break;
	case DirEntity::ET_SERVICE:
		// Add serv path if needed
		if (theGetFlags & WONMsg::GF_SERVADDPATH)
			aSize += TRawMsg::ComputeWStringPackSize(mPath);
		// Add serv name if needed
		if (theGetFlags & WONMsg::GF_SERVADDNAME)
			aSize += TRawMsg::ComputeWStringPackSize(mName);
		// Add serv netaddress if needed
		if (theGetFlags & WONMsg::GF_SERVADDNETADDR)
			aSize += sizeof(unsigned char) + mNetAddress.size();
		break;
	}

	// Add displayName if needed
	if (theGetFlags & WONMsg::GF_ADDDISPLAYNAME)
		aSize += TRawMsg::ComputeWStringPackSize(mDisplayName);

	// Add lifespan if needed
	if (theGetFlags & WONMsg::GF_ADDLIFESPAN)
		aSize += sizeof(mLifespan);

	// Add create date if needed
	if (theGetFlags & WONMsg::GF_ADDCREATED)
		aSize += sizeof(mCreated);

	// Add touched date if needed
	if (theGetFlags & WONMsg::GF_ADDTOUCHED)
		aSize += sizeof(mTouched);

	// Add CRC if needed
	if (theGetFlags & WONMsg::GF_ADDCRC)
		aSize += sizeof(mCRC);

	// Add UserIds if needed
	if (theGetFlags & WONMsg::GF_ADDUIDS)
		aSize += sizeof(mCreateId) + sizeof(mTouchId);

	// Data Objects
	bool packAllObjs = ((theGetFlags & WONMsg::GF_ADDDATAOBJECTS) != 0);
	if ((packAllObjs) || (! theSetR.empty()))
	{
		aSize += sizeof(unsigned short);  // data object count
		bool packType = ((theGetFlags & WONMsg::GF_ADDDOTYPE) != 0);
		bool packData = ((theGetFlags & WONMsg::GF_ADDDODATA) != 0);
		DataObjectTypeSet::const_iterator anItr(mDataObjects.begin());
		for (; anItr != mDataObjects.end(); ++anItr)
		{
			if ((packAllObjs) || (theSetR.find(*anItr) != theSetR.end()))
			{
				if (packType)
					aSize += sizeof(unsigned char)  + anItr->GetDataType().size();
				if (packData)
					aSize += sizeof(unsigned short) + anItr->GetData().size();
			}
		}
	}

	// Add ACLs if needed
	if (theGetFlags & WONMsg::GF_ADDACLS)
	{
		aSize += sizeof(unsigned short);  // ACL count
		DirACLList::const_iterator anItr(mACLs.begin());
		for (; anItr != mACLs.end(); ++anItr)
			aSize += sizeof(unsigned char) + sizeof(unsigned short) + (anItr->mACL.size() * sizeof(Permission));
	}

	return aSize;
}
コード例 #3
0
void
DirEntity::Pack(BaseMessage& theMsgR, unsigned long theGetFlags,
                const DataObjectTypeSet& theSetR) const
{
	WTRACE("DirEntity::Pack");
	WDBG_LL("DirEntity::Pack Packing entity, type=" << mType);

	// Add type if needed
	if (theGetFlags & WONMsg::GF_ADDTYPE)
		theMsgR.AppendByte(mType);

	// Entity specific fields
	switch (mType)
	{
	case DirEntity::ET_DIRECTORY:
		// Add dir path if needed
		if (theGetFlags & WONMsg::GF_DIRADDPATH)
			theMsgR.Append_PW_STRING(mPath);
		// Add dir name if needed
		if (theGetFlags & WONMsg::GF_DIRADDNAME)
			theMsgR.Append_PW_STRING(mName);
		// Add dir visibility if needed
		if (theGetFlags & WONMsg::GF_DIRADDVISIBLE)
			theMsgR.AppendByte(mVisible);
		break;
	case DirEntity::ET_SERVICE:
		// Add serv path if needed
		if (theGetFlags & WONMsg::GF_SERVADDPATH)
			theMsgR.Append_PW_STRING(mPath);
		// Add serv name if needed
		if (theGetFlags & WONMsg::GF_SERVADDNAME)
			theMsgR.Append_PW_STRING(mName);
		// Add serv netaddress if needed
		if (theGetFlags & WONMsg::GF_SERVADDNETADDR)
		{
			theMsgR.AppendByte(mNetAddress.size());
			theMsgR.AppendBytes(mNetAddress.size(), mNetAddress.data());
		}
		break;
	}

	// Add displayName if needed
	if (theGetFlags & WONMsg::GF_ADDDISPLAYNAME)
		theMsgR.Append_PW_STRING(mDisplayName);

	// Add lifespan if needed
	if (theGetFlags & WONMsg::GF_ADDLIFESPAN)
		theMsgR.AppendLong(mLifespan);

	// Add create date if needed
	if (theGetFlags & WONMsg::GF_ADDCREATED)
		theMsgR.AppendLong(mCreated);

	// Add touched date if needed
	if (theGetFlags & WONMsg::GF_ADDTOUCHED)
		theMsgR.AppendLong(mTouched);

	// Add CRC if needed
	if (theGetFlags & WONMsg::GF_ADDCRC)
		theMsgR.AppendLong(mCRC);

	// Add UserIds if needed
	if (theGetFlags & WONMsg::GF_ADDUIDS)
	{
		theMsgR.AppendLong(mCreateId);
		theMsgR.AppendLong(mTouchId);
	}

	// Add all data objects if needed
	if (theGetFlags & WONMsg::GF_ADDDATAOBJECTS)
		PackDataObjects(theMsgR, mDataObjects, theGetFlags);

	// Otherwise, add requested data objects (if any)
	else if (theSetR.size() > 0)
	{
		DataObjectTypeSet aPackSet;
		DataObjectTypeSet::const_iterator anItr(theSetR.begin());
		for (; anItr != theSetR.end(); anItr++)
		{
			DataObjectTypeSet::const_iterator aSrch(mDataObjects.find(*anItr));
			if (aSrch != mDataObjects.end())
				aPackSet.insert(*aSrch);
		}
		PackDataObjects(theMsgR, aPackSet, theGetFlags);
	}

	// Add ACLs if needed (deferred)
	if (theGetFlags & WONMsg::GF_ADDACLS)
		PackACLs(theMsgR);
}