Example #1
0
bool InetPacket::isValid(shared_ptr<Packet> packet, Protocol datalink_protocol) {
	bool valid = true;
	try {
		assert_ex(datalink_protocol == Protocol::Ethernet, ValidationError("")); 
		assert_ex(packet->raw_data_end() >= packet->raw_data_begin() + 14, ValidationError(""));
	} catch (ValidationError& e) {
		valid = false;
	}
	return valid;
}
Example #2
0
bool TCPPacket::isValid(shared_ptr<IPPacket> packet) {
	bool valid = true;
	try {
		assert_ex(packet->getIPProtocol() == Protocol::TCP, ValidationError(""));
		assert_ex(packet->raw_data_end() >= packet->ip_data_begin() + 20, ValidationError(""));
	} catch (ValidationError& e) {
		valid = false;
	}
	return valid;
}
Example #3
0
void COXMaskedEdit::OnKillfocus() 
{
	// TODO: Add your control notification handler code here

	// send OXMEN_VALIDATE notification to parent to validate typed information
	// if the notification was handled, the return value have to be one of these:
	//
	//		-1	-	if typed info is invalid
	//		0	-	typed info is valid but virtual OnValidate function will be 
	//				called to verify typed info
	//		1	-	typed info is valid and OnValidate function won't be called

	CWnd* pParentWnd=GetParent();
	ASSERT(pParentWnd);

	MENMHDR MENMHdr;
	memset(&MENMHdr,0,sizeof(MENMHdr));
	MENMHdr.hdr.hwndFrom=GetSafeHwnd();
	MENMHdr.hdr.idFrom=GetDlgCtrlID();
	MENMHdr.hdr.code=OXMEN_VALIDATE;
	MENMHdr.bValid=TRUE;
	MENMHdr.bDefaultValidation=TRUE;
	MENMHdr.nPosition=0;
	
	pParentWnd->SendMessage(WM_NOTIFY,MENMHdr.hdr.idFrom,(LPARAM)&MENMHdr);

	if(!MENMHdr.bValid || !(MENMHdr.bDefaultValidation ? OnValidate() : TRUE))
	{
		SetFocus();
		ValidationError();
		// set insertion point at the first input location
		UpdateInsertionPointForward(MENMHdr.nPosition);
	}
}
Example #4
0
ptr_lib::shared_ptr<CertificateV2>
ValidationState::verifyCertificateChain
  (const ptr_lib::shared_ptr<CertificateV2>& trustedCertificate)
{
  ptr_lib::shared_ptr<CertificateV2> validatedCertificate = trustedCertificate;
  for (size_t i = 0; i < certificateChain_.size(); ++i) {
    ptr_lib::shared_ptr<CertificateV2> certificateToValidate =
      certificateChain_[i];

    if (!VerificationHelpers::verifyDataSignature
        (*certificateToValidate, *validatedCertificate)) {
      fail(ValidationError(ValidationError::INVALID_SIGNATURE,
           "Invalid signature of certificate `" +
           certificateToValidate->getName().toUri() + "`"));
      certificateChain_.erase
        (certificateChain_.begin() + i, certificateChain_.end());
      return ptr_lib::shared_ptr<CertificateV2>();
    }
    else {
      _LOG_TRACE("OK signature for certificate `" << certificateToValidate->getName() << "`");
      validatedCertificate = certificateToValidate;
    }
  }

  return validatedCertificate;
}
Example #5
0
void ValidationBuilder::addOutputArc(const std::string& transition,
									 const std::string& place,
									 int weight){
	_outputArcs.push_back(Arc(transition, place));
	if(weight < 0){
		string msg = "Weight is " + int2string(weight)
					 + " is less than zero";
		_errors.push_back(ValidationError(transition, place, msg));
	}
}
Example #6
0
void ValidationBuilder::addVariable(const std::string& name,
									int initialValue,
									int range){
	_varNames.push_back(name);
	if(initialValue > range){	//TODO: Figure out if this is > or >=
		string msg = "Initial value " + int2string(initialValue)
					 + " is larger than range " + int2string(range);
		_errors.push_back(ValidationError(name, msg));
	}
}
Example #7
0
void ValidationBuilder::addPlace(const std::string& name,
								 int tokens,
								 double,
								 double){
	_placeNames.push_back(name);
	if(tokens < 0){
		string msg = "Initial marking " + int2string(tokens)
					 + " is less than zero";
		_errors.push_back(ValidationError(name, msg));
	}
}
Example #8
0
void
DataValidationState::verifyOriginalPacket
  (const CertificateV2& trustedCertificate)
{
  if (VerificationHelpers::verifyDataSignature(data_, trustedCertificate)) {
    _LOG_TRACE("OK signature for data `" << data_.getName() << "`");
    try {
      successCallback_(data_);
    } catch (const std::exception& ex) {
      _LOG_ERROR("DataValidationState::fail: Error in successCallback: " << ex.what());
    } catch (...) {
      _LOG_ERROR("DataValidationState::fail: Error in successCallback.");
    }
    setOutcome(true);
  }
  else
    fail(ValidationError(ValidationError::INVALID_SIGNATURE,
      "Invalid signature of data `" + data_.getName().toUri() + "`"));
}
Example #9
0
void
InterestValidationState::verifyOriginalPacket
  (const CertificateV2& trustedCertificate)
{
  if (VerificationHelpers::verifyInterestSignature(interest_, trustedCertificate)) {
    _LOG_TRACE("OK signature for interest `" << interest_.getName() << "`");
    for (size_t i = 0; i < successCallbacks_.size(); ++i) {
      try {
        successCallbacks_[i](interest_);
      } catch (const std::exception& ex) {
        _LOG_ERROR("InterestValidationState::fail: Error in successCallback: " << ex.what());
      } catch (...) {
        _LOG_ERROR("InterestValidationState::fail: Error in successCallback.");
      }
    }
    setOutcome(true);
  }
  else
    fail(ValidationError(ValidationError::INVALID_SIGNATURE,
      "Invalid signature of interest `" + interest_.getName().toUri() + "`"));
}
Example #10
0
void COXMaskedEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	// If there is no mask, then exit quickly performing the default operation. 
	if(m_listData.GetCount()==0 || GetStyle()&ES_READONLY)
	{
		CEdit::OnChar(nChar, nRepCnt, nFlags);
		return;
	}
	
	int nSelectionStart=0;
	int nSelectionEnd  =0;
	GetSel(nSelectionStart, nSelectionEnd);
	
	// If character value is above 32, then it is ANSI or Extended. 
	// Below 32 are control and navigation characters. 
	if(nChar >= 32)
	{
		if(nSelectionStart==nSelectionEnd)
		{
			if(IsInputData(nSelectionStart))
			{
				int nActualInsertionPoint=nSelectionStart;
				if(m_bInsertMode)
					nActualInsertionPoint=InsertAt(nSelectionStart, (TCHAR)nChar);
				else
					nActualInsertionPoint=SetAt   (nSelectionStart, (TCHAR)nChar);
				
				// InsertAt will return -1 if the character cannot be inserted here. 
				if(nActualInsertionPoint >= 0)
					nSelectionStart=nActualInsertionPoint + 1;
				else
					ValidationError();
				
				Update(nSelectionStart);
			}
			else
			{
				// Beep if trying to type over a literal. 
				ValidationError();
				UpdateInsertionPointForward(nSelectionStart);
			}
		}
		else
		{
			// First delete the remaining selection. 
			// The function will return a valid count if 
			// some input characters were deleted. We use 
			// this value to determine if it makes sense to insert. 
			if(DeleteRange(nSelectionStart, nSelectionEnd))
			{
				// InsertAt will place the character at the next available position, 
				// then return that positition
				int nActualInsertionPoint=nSelectionStart;
				nActualInsertionPoint=InsertAt(nSelectionStart, (TCHAR)nChar);
				
				// InsertAt will return -1 if the character cannot be inserted here. 
				if(nActualInsertionPoint >= 0)
					nSelectionStart=nActualInsertionPoint + 1;
				else
					ValidationError();
				
				Update(nSelectionStart);
			}
			else  // Must be on a literal, so beep and move to a valid location. 
			{
				ValidationError();
				UpdateInsertionPointForward(nSelectionStart);
			}
		}
	}
	else
	{
		if(nChar==VK_BACK)
		{
			// Backspace performs two functions, if there is a selection,
			// then the backspace is the same as deleting the selection.
			// If there is no selection, then the backspace deletes the
			// first non-literal character to the left.
			if(nSelectionStart==nSelectionEnd)
			{
				if (nSelectionStart >= 1)
				{
					while (nSelectionStart>=0)
					{
						nSelectionStart--; // Do the equivalent of a backspace.

						if (DeleteRange(nSelectionStart, nSelectionEnd))
						{
							Update(nSelectionStart);
							break;
						}

						nSelectionEnd--;
					}
				}
			}
			else if(DeleteRange(nSelectionStart, nSelectionEnd))
			{
				Update(nSelectionStart);
			}
			else	// Must be on a literal, so continue moving to left
					// and re-attempting the delete until we either delete
					// a character or run out of characters.
			{
				if (nSelectionStart >= 1)
				{
					while (nSelectionStart>=0)
					{
						nSelectionStart--; // Do the equivalent of a backspace.

						if (DeleteRange(nSelectionStart, nSelectionEnd))
						{
							Update(nSelectionStart);
							break;
						}
						
						nSelectionEnd--;
					}
				}
			}
		}
		else
			// let edit control to do its job 
			CEdit::OnChar(nChar, nRepCnt, nFlags);
	}
}
Example #11
0
bool ValidationBuilder::validate(){
	//Check for duplicate identifiers
	set<string> reportedDuplicates;	//Use a set to avoid reporting them more than once
	//Check variable names
	for(size_t i = 0; i < _varNames.size(); i++){
		const string& id = _varNames[i];
		int count = countMatchingIds(id);
		assert(count >= 1);
		if(count > 1 && reportedDuplicates.count(id) == 0){
			reportedDuplicates.insert(id);
			_errors.push_back(ValidationError(id,
											  "The identifiers must be unique, \""
											  + id + "\" is shared by "
											  + int2string(count) + " entities"));
		}
	}
	//Check bool variable names
	for(size_t i = 0; i < _boolVarNames.size(); i++){
		const string& id = _boolVarNames[i];
		int count = countMatchingIds(id);
		assert(count >= 1);
		if(count > 1 && reportedDuplicates.count(id) == 0){
			reportedDuplicates.insert(id);
			_errors.push_back(ValidationError(id,
											  "The identifiers must be unique, \""
											  + id + "\" is shared by "
											  + int2string(count) + " entities"));
		}
	}
	//Check place names
	for(size_t i = 0; i < _placeNames.size(); i++){
		const string& id = _placeNames[i];
		int count = countMatchingIds(id);
		assert(count >= 1);
		if(count > 1 && reportedDuplicates.count(id) == 0){
			reportedDuplicates.insert(id);
			_errors.push_back(ValidationError(id,
											  "The identifiers must be unique, \""
											  + id + "\" is shared by "
											  + int2string(count) + " entities"));
		}
	}
	//Check transition names
	for(size_t i = 0; i < _transitionNames.size(); i++){
		const string& id = _transitionNames[i];
		int count = countMatchingIds(id);
		assert(count >= 1);
		if(count > 1 && reportedDuplicates.count(id) == 0){
			reportedDuplicates.insert(id);
			_errors.push_back(ValidationError(id,
											  "The identifiers must be unique, \""
											  + id + "\" is shared by "
											  + int2string(count) + " entities"));
		}
	}

	//Check all input arcs
	for(size_t i = 0; i < _inputArcs.size(); i++){
		const Arc& arc = _inputArcs[i];
		bool foundPlace = false;
		bool foundTransition = false;
		//Look for place
		for(size_t j = 0; j < _placeNames.size(); j++){
			foundPlace |= _placeNames[j] == arc.start;
			if(foundPlace) break;
		}
		//Look for transition
		for(size_t j = 0; j < _transitionNames.size(); j++){
			foundTransition |= _transitionNames[j] == arc.end;
			if(foundTransition) break;
		}
		//Report error
		if(!foundPlace || !foundTransition){
			string msg;
			if(!foundPlace && !foundTransition)
				msg = "Neigther end-points found";
			else if(!foundPlace)
				msg = "Start-place \"" + arc.start + "\" not found";
			else
				msg = "End-transition \"" + arc.end + "\" not found";
			_errors.push_back(ValidationError(arc.start,
											  arc.end,
											  msg));
		}
	}
	//Check all output arcs
	for(size_t i = 0; i < _outputArcs.size(); i++){
		const Arc& arc = _outputArcs[i];
		bool foundPlace = false;
		bool foundTransition = false;
		//Look for transition
		for(size_t j = 0; j < _transitionNames.size(); j++){
			foundTransition |= _transitionNames[j] == arc.start;
			if(foundTransition) break;
		}
		//Look for place
		for(size_t j = 0; j < _placeNames.size(); j++){
			foundPlace |= _placeNames[j] == arc.end;
			if(foundPlace) break;
		}
		//Report error
		if(!foundPlace || !foundTransition){
			string msg;
			if(!foundPlace && !foundTransition)
				msg = "Neither end-points found";
			else if(!foundPlace)
				msg = "End-place \"" + arc.end + "\" not found";
			else
				msg = "Start-transition \"" + arc.start + "\" not found";
			_errors.push_back(ValidationError(arc.start,
											  arc.end,
											  msg));
		}
	}

	//Attempt to parse all non-empty conditions
	for(size_t i = 0; i < _conditions.size(); i++){
		if(_conditions[i].empty()) continue;
		//PQL::Condition* cond = PQL::ParseQuery(_conditions[i]);
		PQL::Condition* cond = PQL::ParseCondition(_conditions[i]);
		if(cond){
			PQL::AnalysisContext context(_placeNames, _varNames, _boolVarNames);
			cond->analyze(context);
			for(size_t j = 0; j < context.errors().size(); j++){
				_errors.push_back(ValidationError(_transitionNames[i],
												  context.errors()[j],
												  true));
			}
			delete cond;
			cond = NULL;
		}else
			_errors.push_back(ValidationError(_transitionNames[i],
											  "Unable to parse non-empty condition"));
	}
	//Attempt to parse all non-empty assignments
	for(size_t i = 0; i < _assignments.size(); i++){
		if(_assignments[i].empty()) continue;
		//PQL::AssignmentExpression* a = PQL::ParseAssignment(_assignments[i]);
		PQL::AssignmentExpression* a = PQL::ParseConditionAssignment(_assignments[i]);
		if(a){
			PQL::AnalysisContext context(_placeNames, _varNames, _boolVarNames);
			a->analyze(context);
			for(size_t j = 0; j < context.errors().size(); j++){
				_errors.push_back(ValidationError(_transitionNames[i],
												  context.errors()[j],
												  false));
			}
			delete a;
			a = NULL;
		}else
			_errors.push_back(ValidationError(_transitionNames[i],
											  "Unable to parse non-empty assignment"));
	}

	return _errors.empty();
}