예제 #1
0
bool filterMatches(uint8_t *filter, Client *server) {
	char variable[256];
	char value[256];
	char *result;
	char *p = (char *)filter;
	if(filter == NULL) return true;
	if(findNextVariable((char **)&p,(char *)&variable,sizeof(variable))) {
		EOperatorType oper = findNextOperator((char **)&p);
		findNextValue((char **)&p,(char *)&value,sizeof(value));
		if(oper == EOperatorType_Equals) {
			//getValue(variable,result,sizeof(result));
			//printf("value: %s\n",value);
			if(strcmp(variable,"groupid") != 0) return true; //temp fix for games which use other filters
			result = server->findServerValue(variable);
			if(result == NULL) return false;
			if(strcmp(value,result) != 0) {
				return false;
			}
		}
			
	}
	return true;	
}
예제 #2
0
파일: v3Formula.cpp 프로젝트: SillyDuck/V3
// Formula Expression Lexing Functions
const bool
V3Formula::lexFormula(V3OperatorMap::const_iterator& it, string& exp, uint32_t& lhs) {
   //cout << "lexFormula: exp = " << exp << endl;
   const uint32_t minPriority = (_opTable.end() == it) ? 0 : it->second.first;
   uint32_t pos, rhs = V3NtkUD; string formula;
   V3OperatorMap::const_iterator is;
   // Find the next operator and lhs if input not given
   if (_opTable.end() == it) {
      it = findNextOperator(exp, pos);
      if (_opTable.end() == it) return lexOperand(exp, lhs); ++pos;
      if (!lexOperand(exp.substr(0, pos - it->first.size()), lhs)) return false;
      exp = (exp.size() > pos) ? exp.substr(pos) : "";
   }
   // Try Associate lhs with rhs by the operator it->first
   while (_opTable.end() != it && minPriority <= it->second.first) {
      //cout << "While loop with op = " << it->first << ", lhs = " << lhs << ", rhs = " << rhs << ", exp = " << exp << endl;
      if ("(" == it->first) {  // Parenthesis
         if (V3NtkUD != lhs) { Msg(MSG_ERR) << "Unexpected Operand on LHS of \"(\" Found !!" << endl; return false; }
         // Find the corresponding ")"
         pos = findCorresOperator(exp, '(', ')');
         if (exp.size() == pos) { Msg(MSG_ERR) << "Missing Corresponding \")\" !!" << endl; return false; }
         // Compute the formula in the parenthesis
         formula = exp.substr(0, pos); exp = exp.substr(++pos); is = _opTable.end();
         //cout << "In () = " << formula << ", after = " << exp << endl;
         if (!lexFormula(is, formula, lhs)) return false;
         if (V3NtkUD == lhs) { Msg(MSG_ERR) << "Missing Formula Inside Parentheses !!" << endl; return false; }
         // Find the next operator
         it = findNextOperator(exp, pos); ++pos;
         // Check if () followed by a concatenation
         formula = (_opTable.end() == it) ? exp : exp.substr(0, pos - it->first.size());
         exp = (exp.size() > pos) ? exp.substr(pos) : "";
         if (formula.size() && '[' == formula[0]) {
            pos = findCorresOperator(formula.substr(1), '[', ']'); uint32_t msb, lsb;
            if (formula.size() == (1 + pos)) { Msg(MSG_ERR) << "Missing Corresponding \"]\" !!" << endl; return false; }
            if (!lexOperand(formula.substr(2 + pos), rhs)) return false;
            if (V3NtkUD != rhs) { Msg(MSG_ERR) << "Unexpected Operand on RHS of \"]\" Found !!" << endl; return false; }
            if (!findSliceOperand(formula.substr(1, pos), msb, lsb)) {
               Msg(MSG_ERR) << "Unexpected Operand \"" << formula.substr(0, 2 + pos) << "\" !!" << endl; return false; }
            _formula.push_back(make_pair(BV_SLICE, V3InputVec()));
            _formula.back().second.push_back(V3NetType(lhs));
            _formula.back().second.push_back(V3NetType(V3BvNtk::hashV3BusId(msb, lsb)));
            lhs = _formula.size() - 1;
         }
         else {
            if (!lexOperand(formula, rhs)) return false;
            if (V3NtkUD != rhs) { Msg(MSG_ERR) << "Unexpected Operand on RHS of \")\" Found !!" << endl; return false; }
         }
      }
      else if ("{" == it->first) {  // Concatenation
         if (V3NtkUD != lhs) { Msg(MSG_ERR) << "Unexpected Operand on LHS of \"{\" Found !!" << endl; return false; }
         // Find the corresponding "}"
         pos = findCorresOperator(exp, '{', '}');
         if (exp.size() == pos) { Msg(MSG_ERR) << "Missing Corresponding \"}\" !!" << endl; return false; }
         // Compute the formula in the parenthesis
         formula = exp.substr(0, pos); exp = exp.substr(++pos);
         if (!lexConcatenateOperand(formula, lhs)) return false; assert (V3NtkUD != lhs);
         // Find the next operator
         it = findNextOperator(exp, pos); ++pos;
         // Check if () followed by a concatenation
         formula = (_opTable.end() == it) ? exp : exp.substr(0, pos - it->first.size());
         exp = (exp.size() > pos) ? exp.substr(pos) : "";
         if (formula.size() && '[' == formula[0]) {
            pos = findCorresOperator(formula.substr(1), '[', ']'); uint32_t msb, lsb;
            if (formula.size() == (1 + pos)) { Msg(MSG_ERR) << "Missing Corresponding \"]\" !!" << endl; return false; }
            if (!lexOperand(formula.substr(2 + pos), rhs)) return false;
            if (V3NtkUD != rhs) { Msg(MSG_ERR) << "Unexpected Operand on RHS of \"]\" Found !!" << endl; return false; }
            if (!findSliceOperand(formula.substr(1, pos), msb, lsb)) {
               Msg(MSG_ERR) << "Unexpected Operand \"" << formula.substr(0, 2 + pos) << "\" !!" << endl; return false; }
            _formula.push_back(make_pair(BV_SLICE, V3InputVec()));
            _formula.back().second.push_back(V3NetType(lhs));
            _formula.back().second.push_back(V3NetType(V3BvNtk::hashV3BusId(msb, lsb)));
            lhs = _formula.size() - 1;
         }
         else {
            if (!lexOperand(formula, rhs)) return false;
            if (V3NtkUD != rhs) { Msg(MSG_ERR) << "Unexpected Operand on RHS of \"}\" Found !!" << endl; return false; }
         }
      }
      else {  // Operators
         if ("!" == it->first || "~" == it->first) {  // Unary Operators
            if (V3NtkUD != lhs) {
               Msg(MSG_ERR) << "Unexpected Operand on LHS of \"" << it->first << "\" Found !!" << endl; return false; }
            if (exp.size() && isspace(exp[0])) {
               Msg(MSG_ERR) << "Unexpected Space after Operator \"" << it->first << "\" Found !!" << endl; return false; }
            // Find the next operator and rhs
            is = findNextOperator(exp, pos); ++pos;
            if (_opTable.end() == is) { if (!lexOperand(exp, rhs)) return false; }
            else if (!lexOperand(exp.substr(0, pos - is->first.size()), rhs)) return false;
            exp = (exp.size() > pos) ? exp.substr(pos) : "";
            // Check Operator Precedence
            if (it->second.first <= is->second.first) {
               if (!lexFormula(is, exp, rhs)) return false;
               if (V3NtkUD == rhs) {
                  Msg(MSG_ERR) << "Missing Operand on RHS of \"" << it->first << "\" !!" << endl;
                  return false;
               }
            }
            // Associate with RHS
            if (V3NtkUD == rhs) {
               Msg(MSG_ERR) << "Missing Operand on RHS of \"" << it->first << "\" !!" << endl; return false; }
            _formula.push_back(make_pair(BV_INV, V3InputVec()));
            _formula.back().second.push_back(rhs);
            if ("!" == it->first) {
               _formula.push_back(make_pair(BV_RED_AND, V3InputVec()));
               _formula.back().second.push_back(_formula.size() - 2);
            }
            lhs = _formula.size() - 1; it = is;
         }
         else if (("&" == it->first || "|" == it->first || "^" == it->first) && (V3NtkUD == lhs)) {  // Reduced Operators
            if (V3NtkUD != lhs) {
               Msg(MSG_ERR) << "Unexpected Operand on LHS of \"" << it->first << "\" Found !!" << endl; return false; }
            if (exp.size() && isspace(exp[0])) {
               Msg(MSG_ERR) << "Unexpected Space after Operator \"" << it->first << "\" Found !!" << endl; return false; }
            // Find the next operator and rhs
            is = findNextOperator(exp, pos); ++pos;
            if (_opTable.end() == is) { if (!lexOperand(exp, rhs)) return false; }
            else if (!lexOperand(exp.substr(0, pos - is->first.size()), rhs)) return false;
            exp = (exp.size() > pos) ? exp.substr(pos) : "";
            // Check Operator Precedence
            while (_opTable.end() != is && 13 < is->second.first) {  // 13 is the priority of REDUCED Gates
               if (!lexFormula(is, exp, rhs)) return false;
               if (V3NtkUD == rhs) break;
            }
            // Associate with RHS
            if (V3NtkUD == rhs) {
               Msg(MSG_ERR) << "Missing Operand on RHS of \"" << it->first << "\" !!" << endl; return false; }
            const V3GateType type = "&" == it->first ? BV_RED_AND : "|" == it->first ? BV_RED_OR : BV_RED_XOR;
            _formula.push_back(make_pair(type, V3InputVec()));
            _formula.back().second.push_back(rhs);
            lhs = _formula.size() - 1; it = is;
         }
         else if ("?" == it->first) {  // Multiplexers
            if (V3NtkUD == lhs) { Msg(MSG_ERR) << "Missing Operand on LHS of \"?\" !!" << endl; return false; }
            // Find the corresponding ":"
            pos = findCorresOperator(exp, '?', ':');
            if (exp.size() == pos) { Msg(MSG_ERR) << "Missing Corresponding \":\" !!" << endl; return false; }
            // Compute the formula between ? and :
            formula = exp.substr(0, pos); exp = exp.substr(++pos); is = _opTable.end();
            if (!lexFormula(is, formula, rhs)) return false;
            if (V3NtkUD == rhs) { Msg(MSG_ERR) << "Missing Formula Between \"?\" and \":\" !!" << endl; return false; }
            // Compute the formula after :
            uint32_t falseId = V3NtkUD; is = _opTable.end();
            if (!lexFormula(is, exp, falseId)) return false;
            if (V3NtkUD == falseId) { Msg(MSG_ERR) << "Missing Formula After \":\" !!" << endl; return false; }
            _formula.push_back(make_pair(it->second.second, V3InputVec()));
            _formula.back().second.push_back(falseId);
            _formula.back().second.push_back(rhs);
            _formula.back().second.push_back(lhs);
            lhs = _formula.size() - 1; it = is;
         }
         else {  // Binary Operators
            if (V3NtkUD == lhs) {
               Msg(MSG_ERR) << "Missing Operand on LHS of \"" << it->first << "\" !!" << endl; return false; }
            // Find the next operator and rhs
            is = findNextOperator(exp, pos); ++pos;
            if (_opTable.end() == is) { if (!lexOperand(exp, rhs)) return false; }
            else if (!lexOperand(exp.substr(0, pos - is->first.size()), rhs)) return false;
            exp = (exp.size() > pos) ? exp.substr(pos) : "";
            // Check Operator Precedence
            while (_opTable.end() != is && ((it->second.first < is->second.first) ||
                   (V3NtkUD == rhs && ("&" == is->first || "|" == is->first || "^" == is->first)))) {
               if (!lexFormula(is, exp, rhs)) return false;
               if (V3NtkUD == rhs) break;
            }
            if (V3NtkUD == rhs) {
               Msg(MSG_ERR) << "Missing Operand on RHS of \"" << it->first << "\" !!" << endl; return false; }
            _formula.push_back(make_pair(it->second.second, V3InputVec()));
            _formula.back().second.push_back(lhs);
            _formula.back().second.push_back(rhs);
            lhs = _formula.size() - 1; it = is;
         }
      }
   }
   return true;
}