예제 #1
0
파일: Validate.cpp 프로젝트: BestSilent/eos
	ValueType validateGlobalIndex(const Module& module,Uptr globalIndex,bool mustBeMutable,bool mustBeImmutable,bool mustBeImport,const char* context)
	{
		VALIDATE_INDEX(globalIndex,module.globals.size());
		const GlobalType& globalType = module.globals.getType(globalIndex);
		if(mustBeMutable && !globalType.isMutable) { throw ValidationException("attempting to mutate immutable global"); }
		else if(mustBeImport && globalIndex >= module.globals.imports.size()) { throw ValidationException("global variable initializer expression may only access imported globals"); }
		else if(mustBeImmutable && globalType.isMutable) { throw ValidationException("global variable initializer expression may only access immutable globals"); }
		return globalType.valueType;
	}
예제 #2
0
void AuthRepositoryServer::validateAddUserParams ( authrepo::CommitNode& myHead, const std::string& licenseStaticId, const std::string& login, const std::string &password, const std::string& fullName, const std::string& email, const std::string& phone, bool enabled )
{
	//validate params
	if ( !myHead.getIndex()->getIndex ( m_dbStructure.getByName ( "license" ) )->findStaticId ( licenseStaticId ) )
		throw ValidationException ( "unknown license" );

	if ( myHead.getLoginIndex()->find ( login ) )
		throw ValidationException ( "user exists" );

	if ( login.length() < 6 )
		throw ValidationException ( "login is too short, at least 6 letters required" );

	if ( password.length() < 5 )
		throw ValidationException ( "password is too short, at least 5 letters required" );
}
예제 #3
0
void AuthRepositoryServer::validateTrialParams ( authrepo::CommitNode& myHead, const RegistrationParams& params )
{
	//validate params
	if ( myHead.getLoginIndex()->find ( params.get_login() ) )
		throw ValidationException ( "user exists" );

	if ( params.get_login().length() < 6 )
		throw ValidationException ( "login is too short, at least 6 letters required" );

	if ( params.get_companyName().empty() )
		throw ValidationException ( "Non-empty company name required" );

	if ( params.get_password().length() < 5 )
		throw ValidationException ( "password is too short, at least 5 letters required" );
}
예제 #4
0
 void validateInitializer(const InitializerExpression& expression,ValueType expectedType,const char* context)
 {
     switch(expression.type)
     {
     case InitializerExpression::Type::i32_const:
         validateType(expectedType,ValueType::i32,context);
         break;
     case InitializerExpression::Type::i64_const:
         validateType(expectedType,ValueType::i64,context);
         break;
     case InitializerExpression::Type::f32_const:
         validateType(expectedType,ValueType::f32,context);
         break;
     case InitializerExpression::Type::f64_const:
         validateType(expectedType,ValueType::f64,context);
         break;
     case InitializerExpression::Type::get_global:
     {
         const ValueType globalValueType = validateGlobalIndex(expression.globalIndex,false,true,true,"initializer expression global index");
         validateType(expectedType,globalValueType,context);
         break;
     }
     default:
         throw ValidationException("invalid initializer expression");
     };
 }
예제 #5
0
 void validateBranchDepth(uintp depth) const
 {
     VALIDATE_INDEX(depth,controlStack.size());
     if(depth >= controlStack.size()) {
         throw ValidationException("invalid branch depth");
     }
 }
예제 #6
0
void validateImportKind(ObjectType importType,ObjectKind expectedKind)
{
    if(importType.kind != expectedKind)
    {
        throw ValidationException("incorrect kind");
    }
}
예제 #7
0
 ValueType validateGlobalIndex(uintp globalIndex,bool mustBeMutable,bool mustBeImmutable,bool mustBeImport,const char* context)
 {
     assert(numImportedGlobals != UINTPTR_MAX);
     VALIDATE_INDEX(globalIndex,globals.size());
     const GlobalType& globalType = globals[globalIndex];
     if(mustBeMutable && !globalType.isMutable) {
         throw ValidationException("attempting to mutate immutable global");
     }
     else if(mustBeImport && globalIndex >= numImportedGlobals) {
         throw ValidationException("global variable initializer expression may only access imported globals");
     }
     else if(mustBeImmutable && globalType.isMutable) {
         throw ValidationException("global variable initializer expression may only access immutable globals");
     }
     return globalType.valueType;
 }
예제 #8
0
 void validateStackAccess(size_t num)
 {
     if(controlStack.back().isReachable)
     {
         const uintp stackBase = controlStack.back().outerStackSize;
         if(stack.size() < stackBase + num) {
             throw ValidationException("invalid stack access");
         }
     }
 }
예제 #9
0
파일: Race.cpp 프로젝트: ameily/WarRoom
QDomElement& Race::toXml(QDomDocument& doc, QDomElement& parent) const
    throw(ValidationException)
{
    if(m_game == NULL)
        throw ValidationException("Race", "game", "is null reference");
    
    if(m_id.isEmpty())
        throw ValidationException("Race", "id", "is null");
    
    if(m_name.isEmpty())
        throw ValidationException("Race", "name", "is null");
    
    QDomProcessingInstruction header = doc.createProcessingInstruction("xml", "version=\"1.0\"");   
    doc.appendChild(header);
    
    QDomElement root = doc.createElement("race");
    
    QDomElement ruleSetNode = doc.createElement("rule_set");
    RuleSet::toXml(doc, ruleSetNode);
    
    QDomElement wargearsNode = doc.createElement("wargears");
    WargearList::toXml(doc, wargearsNode);
    
    QDomElement unitsNode = doc.createElement("units");
    UnitList::toXml(doc, unitsNode);
    
    appendElement(doc, root, "id", m_id);
    appendElement(doc, root, "name", m_name);
    
    QDomElement gameNode = doc.createElement("game");
    UnresolvedReference game(m_game->id());
    game.toXml(doc, gameNode);
    root.appendChild(gameNode);
    
    root.appendChild(ruleSetNode);
    root.appendChild(wargearsNode);
    root.appendChild(unitsNode);
    
    doc.appendChild(root);
    
    return parent;
}
예제 #10
0
void validateType(Type expectedType,Type type,const char* context)
{
    if(expectedType != type)
    {
        throw ValidationException(
            std::string("type mismatch: expected ") + asString(expectedType)
            + " but got " + asString(type)
            + " in " + context
        );
    }
}
예제 #11
0
파일: Validate.cpp 프로젝트: BestSilent/eos
	void validateOperandType(ValueType expectedType,ValueType actualType,const char* context)
	{
		// Handle polymorphic values popped off the operand stack after unconditional branches.
		if(expectedType != actualType && expectedType != ValueType::any && actualType != ValueType::any)
		{
			throw ValidationException(
				std::string("type mismatch: expected ") + asString(expectedType)
				+ " but got " + asString(actualType)
				+ " in " + context + " operand"
				);
		}
	}
예제 #12
0
파일: RuleSet.cpp 프로젝트: ameily/WarRoom
QDomElement& RuleSet::toXml(QDomDocument& doc, QDomElement& parent) const
    throw(ValidationException)
{
    if(m_book.isEmpty())
        throw ValidationException("RuleSet", "book", "is null");
    
    if(m_edition.isEmpty())
        throw ValidationException("RuleSet", "edition", "is null");
    
    if(m_version.isEmpty())
        throw ValidationException("RuleSet", "version", "is null");
    
    QDomElement ruleList = doc.createElement("rules");
    RuleList::toXml(doc, ruleList);
    
    appendElement(doc, parent, "book", m_book);
    appendElement(doc, parent, "edition", m_edition);
    appendElement(doc, parent, "version", m_version);
    
    parent.appendChild(ruleList);
    
    return parent;
}
std::vector<const std::type_info*> InsertJ1::getArgTypes(unsigned int inN, GP::Context& ioContext) const {
	std::vector<const std::type_info*> lTypes;
	switch(inN) {
		case 0:
			lTypes.push_back(ArgBond);
			return lTypes;
		case 1:
			lTypes.push_back(ArgBond);
			return lTypes;
		case 2:
			lTypes.push_back(ArgJct1);
			return lTypes;
		default:
			throw ValidationException("InsertJ1 should have no more than 3 arguments");
	}
}
예제 #14
0
파일: Validate.cpp 프로젝트: BestSilent/eos
		ValueType popOperand()
		{
			if(stack.size() > controlStack.back().outerStackSize)
			{
				const ValueType result = stack.back();
				stack.pop_back();
				return result;
			}
			else if(controlStack.back().isReachable)
			{
				throw ValidationException("invalid stack access");
			}
			else
			{
				return ValueType::any;
			}
		}
예제 #15
0
파일: Validate.cpp 프로젝트: BestSilent/eos
		void popControlStack(bool isElse = false)
		{
			VALIDATE_UNLESS("stack was not empty at end of control structure: ",stack.size() > controlStack.back().outerStackSize);

			if(isElse && controlStack.back().type == ControlContext::Type::ifThen)
			{
				controlStack.back().type = ControlContext::Type::ifElse;
				controlStack.back().isReachable = true;
			}
			else
			{
				VALIDATE_UNLESS("else only allowed in if context: ",isElse);
				const ResultType resultType = controlStack.back().resultType;
				if(controlStack.back().type == ControlContext::Type::ifThen && resultType != ResultType::none)
				{
					throw ValidationException("else-less if may not yield a result");
				}
				controlStack.pop_back();
				if(controlStack.size()) { pushOperand(resultType); }
			}
		}
예제 #16
0
void AuthRepositoryServer::updateUser ( 
	authrepo::CommitNode& myHead, 
	const std::string& licenseStaticId, const std::string& login, const std::string &password, 
	const std::string& fullName, const std::string& email, const std::string& phone, 
	bool enabled, const std::string& roleStaticId, const std::vector<std::string>& groupStaticIdList,
	const std::string &userStaticId
)
{
	authrepo::DataNode *user_license = myHead.getIndex()->getIndex ( m_dbStructure.getByName ( "license" ) )->findStaticId ( licenseStaticId );
	if ( !user_license ) throw ValidationException ( "unknown license" );

	authrepo::DataNode *login_user = myHead.getLoginIndex()->find ( login );
	authrepo::DataNode *user = myHead.getIndex()->getIndex ( m_dbStructure.getByName ( "user" ) )->findStaticId ( userStaticId );
	if ( !user ) throw ValidationException ( "unknown user" );

	if (login_user && login_user != user)
		throw ValidationException ( "login exists" );

	authrepo::PDataNode temp = user->getParent()->detachChild(user);
	user_license->attachChild(temp);
	{
		user->setField ( "login", login );
		user->setField ( "welcome_name", fullName );
		user->setField ( "email", email );
		user->setField ( "phone", phone );
		user->setField ( "enabled", enabled ? "true" : "false" );
		if(!roleStaticId.empty()) {
			user->setField ( "srid", roleStaticId );
		}
	}

	//NOTE: merge accessible group list
	const authrepo::DBEntity *p_grouplinkEntity = m_dbStructure.getByName( "grouplink" );
	
	//NOTE: detach all grouplinks from user, collect detached in a map
	std::map<std::string, authrepo::PDataNode> currentGroupLink;
	for(
		authrepo::TChildrenMap::const_iterator itChildren = user->getChildren().begin(); 
		itChildren != user->getChildren().end();
		++itChildren
	) {
		//NOTE: loog only at grouplink items
		if(itChildren->second->getTypeEntity() == p_grouplinkEntity) {
			//NOTE: look for group staticid, skip if not found
			std::map<std::string, std::string>::const_iterator itField = itChildren->second->fields().find("sgid");
			if(itField != itChildren->second->fields().end()) {
				currentGroupLink[itField->second] = itChildren->second;
				user->detachChild(itChildren->second);
			}
		}
	}

	//NOTE: pass througs the actual groups
	for(
		std::vector<std::string>::const_iterator groupIt = groupStaticIdList.begin();
		groupIt != groupStaticIdList.end();
		++groupIt
	) {
		std::map<std::string, authrepo::PDataNode>::iterator it = currentGroupLink.find( *groupIt );
		if(it == currentGroupLink.end()) {
			//NOTE: create new grouplink
			authrepo::DataNode *grouplink = user->createChild ( "grouplink", authrepo::util::generateId ( "" ) );
			grouplink->setField("sgid", *groupIt);
			myHead.checkSharePermission(grouplink);
		} else {
			//NOTE: attach existing grouplink
			user->attachChild(it->second);
		}
	}

}
예제 #17
0
void ListValidator::validate(string listName) throw (ValidationException) {
	if(listName == "") {
		throw ValidationException("Invalid name!");
	}
}
예제 #18
0
void validate(TableElementType type)
{
    if(type != TableElementType::anyfunc) {
        throw ValidationException("invalid table element type (" + std::to_string((uintp)type) + ")");
    }
}
예제 #19
0
 void error(ErrorImm imm) {
     throw ValidationException("error opcode");
 }
예제 #20
0
void AuthRepositoryServer::validateUpdateUserParams ( authrepo::CommitNode& myHead, const std::string& licenseStaticId, const std::string& login, const std::string &password, const std::string& fullName, const std::string& email, const std::string& phone, bool enabled, const std::string &userStaticId)
{
	if ( !password.empty() && password.length() < 5 )
		throw ValidationException ( "password is too short, at least 5 letters required" );
}