Example #1
0
    /*!
        \fn bool QDBusUtil::isValidBusName(const QString &busName)
        Returns true if \a busName is a valid bus name.

        A valid bus name is either a valid unique connection name or follows the rules:
        \list
          \o is not empty
          \o does not exceed 255 characters in length
          \o be composed of dot-separated string components that contain only ASCII letters, digits,
             hyphens or underscores ("_"), but don't start with a digit
          \o contains at least two such elements
        \endlist

        \sa isValidUniqueConnectionName()
    */
    bool isValidBusName(const QString &busName)
    {
        if (busName.isEmpty() || busName.length() > DBUS_MAXIMUM_NAME_LENGTH)
            return false;

        if (busName.startsWith(QLatin1Char(':')))
            return isValidUniqueConnectionName(busName);

        QStringList parts = busName.split(QLatin1Char('.'));
        if (parts.count() < 1)
            return false;

        for (int i = 0; i < parts.count(); ++i) {
            const QString &part = parts.at(i);
            if (part.isEmpty())
                return false;

            const QChar *c = part.unicode();
            if (isValidNumber(c[0]))
                return false;
            for (int j = 0; j < part.length(); ++j)
                if (!isValidCharacter(c[j]))
                    return false;
        }

        return true;
    }
Example #2
0
    /*!
        \fn bool QDBusUtil::isValidUniqueConnectionName(const QStringRef &connName)
        Returns \c true if \a connName is a valid unique connection name.

        Unique connection names start with a colon (":") and are followed by a list of dot-separated
        components composed of ASCII letters, digits, the hyphen or the underscore ("_") character.
    */
    bool isValidUniqueConnectionName(const QStringRef &connName)
    {
        if (connName.isEmpty() || connName.length() > DBUS_MAXIMUM_NAME_LENGTH ||
            !connName.startsWith(QLatin1Char(':')))
            return false;

        const auto parts = connName.mid(1).split(QLatin1Char('.'));
        if (parts.count() < 1)
            return false;

        for (const QStringRef &part : parts) {
            if (part.isEmpty())
                 return false;

            const QChar* c = part.unicode();
            for (int j = 0; j < part.length(); ++j)
                if (!isValidCharacter(c[j]))
                    return false;
        }

        return true;
    }
Example #3
0
int checkCloseParen(char* parsedFile, char c, int initSize)
{
  int parsePointer = initSize-1;
  int semicolonFound = 0;
  while(parsePointer > 0)
  {
    if( parsedFile[parsePointer] == c || isspace(parsedFile[parsePointer]))
    {
      //do nothing
    }
    else if( parsedFile[parsePointer] == '|' || parsedFile[parsePointer] == '&'|| 
             parsedFile[parsePointer] == '(')
    {
      return 0;
    }
    else if( isValidCharacter(parsedFile[parsePointer]) )
    {
      return 1;
    }
    parsePointer--;
  }
  return 0;
}
Example #4
0
int checkSpecialToken(char* parsedFile, char c, int initSize)
{
  if(c != '&' && c != '|' && c != ';' && c != '(' && c != ')')
  {
    error(1, 0, "Improper call to checkSpecialToken");
    return 0;
  }

  if(c == '(')
  {
    return checkOpenParen(parsedFile, c, initSize);
  }

  if(c == ')')
  {
    return checkCloseParen(parsedFile, c, initSize);
  }

  int tempCounter = 0;
  int parsePointer = initSize-1;
  int spaceFound = 0;
  int closeParenFound = 0;

  //printf("DEBUG: checkSpecialToken: initSize=%i\n", initSize);
  while(parsePointer >= 0)
  {
    //printf("DEBUG: checkSpecialToken: checking %c\n", parsedFile[parsePointer]);
    if( parsedFile[parsePointer] == c)
    {
      if(c == '|' || c == '&')
      {
        tempCounter++;
        if(spaceFound || closeParenFound)
        {
          return 0;
        }
        else if(tempCounter > 1)
        {
          return 0;
        }
      }
      else if(c == ';')
      {
        if(closeParenFound)
        {
          return 1;
        }
        else
        {
          return 0;
        }
      }
    }
    else if( parsedFile[parsePointer] == '|' || parsedFile[parsePointer] == '&' || 
             parsedFile[parsePointer] == ';' || parsedFile[parsePointer] == '(' ||
             parsedFile[parsePointer] == '\n')
    {
      return 0;
    }
    else if( isspace(parsedFile[parsePointer]) )
    {
      spaceFound = 1;
    }
    else if( parsedFile[parsePointer] == ')' )
    {
      closeParenFound = 1;
    }
    else if( isValidCharacter(parsedFile[parsePointer]) )
    {
      return 1;
    }
    parsePointer--;
  }


  
  //printf("DEBUG: checkSpecialToken: error 1\n");
  return 0;
}
Example #5
0
/*
 * Checks if next char value is valid in respect to current set of values
 * if next char is valid, it returns 1
 * if next char is invalid, it returns 0
 */
int isProperGrammar(char* parsedFile, int initSize, int* parenCount, char nextInput)
{
  if(!isValidCharacter(nextInput))
    {
      //printf("DEBUG: grammer error 1\n");
      return 0;
    }
  // if its the first character, 
  // then it must be a non-special character
  if(initSize == 0)
  {
    if(nextInput != '&' && nextInput != '|' && nextInput != ';' && nextInput != '<' && nextInput != '>' )
    {
      if(nextInput == '(')
      {
        (*parenCount)++;
      }
      else if(nextInput == ')')
      {
        (*parenCount)--;
        if( (*parenCount) < 0 )
        {
	  //printf("DEBUG: grammer error 2\n");

          return 0;
        }
      }
      return 1;
    }
    else{
      //printf("DEBUG: grammer error 3\n");
      return 0;
    }
  }
  // If & or | follows a different special character
  // or there are three of these back to back without
  // intermediate valid characters
  // Then return false

  if(nextInput == '&' || nextInput == '|' || nextInput == ';' ||
     nextInput == '(' || nextInput == ')' )
  {
    if(!checkSpecialToken(parsedFile, nextInput, initSize))
    {
      //printf("DEBUG: parsedFile at failure = %s\n", parsedFile);
      //printf("DEBUG: last char = %c\n", nextInput);
      //printf("DEBUG: grammer error 4\n");
      return 0;
    }
  }
  else if(nextInput == '<' || nextInput == '>')
  {
    if(!checkRedirectToken(parsedFile, nextInput, initSize))
    {
      //printf("DEBUG: grammer error 5\n");
      return 0;
    }
  }
  else
  {
      int parsePointer = initSize-1;
      if(parsedFile[parsePointer] == '&')
      {
        parsePointer--;
        if(parsePointer < 0 || parsedFile[parsePointer] != '&')
	  {
	    //printf("DEBUG: 6\n");
	    return 0;
	  }
      }
  }

  if(nextInput == '(')
  {
    (*parenCount)++;
  }
  else if(nextInput == ')')
  {
    (*parenCount)--;
    if( (*parenCount) < 0 )
    {
      //printf("DEBUG: 7\n");
      return 0;
    }
  }

  return 1;
}