Пример #1
0
MojErr MojDbQuotaEngine::quotaForKind(const MojDbKind* kind, MojRefCountedPtr<Quota>& quotaOut)
{
	// prefer to use super's quota
	const MojDbKind::KindVec& supers = kind->supers();
	for (MojDbKind::KindVec::ConstIterator i = supers.begin(); i != supers.end(); ++i) {
		// don't want to inherit admin quota, so don't check root kind
		if ((*i)->id() != MojDbKindEngine::RootKindId) {
			MojErr err = quotaForKind(*i, quotaOut);
			MojErrCheck(err);
			if (quotaOut.get())
				return MojErrNone;
		}
	}
	// check for quota that matches owner of this kindS
	const MojString& owner = kind->owner();
	QuotaMap::ConstIterator iter = m_quotas.find(owner);
	if (iter == m_quotas.end()) {
		for (iter = m_quotas.begin(); iter != m_quotas.end(); ++iter) {
			if (matchWildcard(iter.key(), owner, owner.length()))
				break;
		}
	}
	if (iter != m_quotas.end()) {
		quotaOut = *iter;
	}
	return MojErrNone;
}
Пример #2
0
MojErr MojDbQuotaEngine::stats(MojObject& objOut, MojDbReq& req)
{
	// check for admin permission
	if (!req.admin()) {
		MojErrThrow(MojErrDbPermissionDenied);
	}
	for (QuotaMap::ConstIterator i = m_quotas.begin(); i != m_quotas.end(); ++i) {
		MojObject quota;
		MojErr err = quota.put(MojDbServiceDefs::SizeKey, i.value()->size());
		MojErrCheck(err);
		err = quota.put(MojDbServiceDefs::UsedKey, i.value()->usage());
		MojErrCheck(err);
		err = objOut.put(i.key(), quota);
		MojErrCheck(err);
	}
	return MojErrNone;
}