bool ParseQuery(const char* query)
	{
		const char SELECT[] = "SELECT";
		const char FROM[] = "FROM";
		const char WHERE[] = "WHERE";
		const char* p;
		const char* start;
		int len;
		
		if (strncmp(query, SELECT, sizeof(SELECT) - 1))
			return false;
		
		p = query + sizeof(SELECT) - 1;
		p = SkipWhitespace(p);
		if (!p)
			return false;
		
		p = ParseQueryKeys(p);
		
		if (strncmp(p, FROM, sizeof(FROM) - 1))
			return false;
		p = p + sizeof(FROM) - 1;
		p = SkipWhitespace(p);
		start = p;
		p = SkipKey(start, &len);
		if (!len)
			return false;
		
		keyhint.Printf("%.*s", len, start);

		if (!strncmp(p, WHERE, sizeof(WHERE) - 1))
		{
			p = p + sizeof(WHERE) - 1;
			p = SkipWhitespace(p);
			p = ParseConditions(p);
		}
		
		return true;
	}
Beispiel #2
0
bool csDriverDBReader::ParseRules (iDocumentNode* node)
{
  csRef<iDocumentNodeIterator> it (node->GetNodes ());
  while (it->HasNext())
  {
    csRef<iDocumentNode> child = it->Next();
    if (child->GetType() != CS_NODE_ELEMENT) continue;
    csStringID token = tokens.Request (child->GetValue ());

    switch (token)
    {
      case XMLTOKEN_RULE:
	{
	  const char* rulePhase = child->GetAttributeValue ("phase");
	  if (rulePhase == 0) rulePhase = "";
	  if (strcmp (db->rulePhase, rulePhase) != 0)
	    continue;

	  csRef<iDocumentNode> conditions = child->GetNode ("conditions");
	  csRef<iDocumentNode> applicable = child->GetNode ("applicable");
	  csRef<iDocumentNode> notapplicable = child->GetNode ("notapplicable");

	  bool condTrue = true;
	  bool applied = false;
	  if (conditions.IsValid())
	  {
	    if (!ParseConditions (conditions, condTrue))
	      return false;
	  }
	  if (condTrue)
	  {
	    if (applicable.IsValid ())
	    {
	      if (!Apply (applicable)) return false;
	      applied = true;
	    }
	  }
	  else
	  {
	    if (notapplicable.IsValid ())
	    {
	      if (!Apply (notapplicable)) return false;
	      applied = true;
	    }
	  }
	  if (applied)
	  {
	    const char* descr = child->GetAttributeValue ("description");
	    if (descr != 0)
	    {
	      db->Report (CS_REPORTER_SEVERITY_NOTIFY,
		"Applied: %s", descr);
	    }
	  }
	}
	break;
      default:
	db->ReportBadToken (child);
	return false;
    }
  }
  return true;
}
Beispiel #3
0
bool csDriverDBReader::ParseConditions (iDocumentNode* node, 
					bool& result, 
					bool negate)
{
  FulfillConditions fulfill = All;
  const char* fulfillAttr = node->GetAttributeValue ("fulfill");
  if (fulfillAttr != 0)
  {
    if (strcmp (fulfillAttr, "one") == 0)
      fulfill = One;
    else if (strcmp (fulfillAttr, "all") == 0)
      fulfill = All;
    else
    {
      db->Report (
	CS_REPORTER_SEVERITY_WARNING,
	node,
	"Invalid %s attribute %s",
	CS::Quote::Single ("fulfill"),
	CS::Quote::Single (fulfillAttr));
      return false;
    }
  }

  csRef<iDocumentNodeIterator> it (node->GetNodes ());
  while (it->HasNext())
  {
    csRef<iDocumentNode> child = it->Next();
    if (child->GetType() != CS_NODE_ELEMENT) continue;
    csStringID token = tokens.Request (child->GetValue ());

    bool lastResult = false;

    switch (token)
    {
      case XMLTOKEN_CONDITIONS:
	if (!ParseConditions (child, lastResult))
	  return false;
	break;
      case XMLTOKEN_NEGATE:
	if (!ParseConditions (child, lastResult, true))
	  return false;
	break;
      case XMLTOKEN_REGEXP:
	if (!ParseRegexp (child, lastResult))
	  return false;
	break;
      case XMLTOKEN_COMPAREVER:
	if (!ParseCompareVer (child, lastResult))
	  return false;
	break;
      default:
	db->ReportBadToken (child);
	return false;
    }

    switch (fulfill)
    {
      case One:
	if (lastResult ^ negate)
	{
	  result = true;
	  return true;
	}
	break;
      case All:
	if (!(lastResult ^ negate))
	{
	  result = false;
	  return true;
	}
	break;
    }
  }
  result = (fulfill == All);
  return true;
}