Ejemplo n.º 1
0
int TestParsing( ) 
{

  // WELL FORMED Expr
  try
  {
    ctkLDAPExpr ldap( "(cn=Babs Jensen)" );
    ldap = ctkLDAPExpr( "(!(cn=Tim Howes))" );
    ldap = ctkLDAPExpr( "(&(" + ctkPluginConstants::OBJECTCLASS + "=Person)(|(sn=Jensen)(cn=Babs J*)))" );
    ldap = ctkLDAPExpr( "(o=univ*of*mich*)" );
    ldap = ctkLDAPExpr( "(cn=Babs Jensen)" );
  }
  catch ( std::invalid_argument &e )
  {
    std::cerr << e.what() << std::endl;
    return EXIT_FAILURE;
  }


  // MALFORMED Expre
  try
  {
    ctkLDAPExpr ldap( "cn=Babs Jensen)" );
    return EXIT_FAILURE;
  }
  catch ( std::invalid_argument &e )
  {
    // Nothing to do
    int i = 0;
  }

  return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
int TestEvaluate( )
{
  // EVALUATE
  try
  {
    ctkLDAPExpr ldap( "(cn=Babs Jensen)" );
    ctkDictionary dict;
    bool eval = false;

    // Several values
    dict.insert( "cn", "Babs Jensen" );
    dict.insert( "unused", "Jansen" );
    eval = ldap.evaluate( dict, true );
    if ( !eval )
    {
      return EXIT_FAILURE;
    }

    // WILDCARD
    ldap = ctkLDAPExpr( "(cn=Babs *)" );
    dict.clear();
    dict.insert( "cn", "Babs Jensen" );
    eval = ldap.evaluate( dict, true );
    if ( !eval )
    {
      return EXIT_FAILURE;
    }

    // NOT FOUND
    ldap = ctkLDAPExpr( "(cn=Babs *)" );
    dict.clear();
    dict.insert( "unused", "New" );
    eval = ldap.evaluate( dict, true );
    if ( eval )
    {
      return EXIT_FAILURE;
    }

    // QList with integer values
    ldap = ctkLDAPExpr( "  ( |(cn=Babs *)(sn=1) )" );
    dict.clear();
    QList<QVariant> list;
    list.append( "Babs Jensen" );
    list.append( "1" );
    dict.insert( "sn", list );
    eval = ldap.evaluate( dict, true );
    if ( !eval )
    {
      return EXIT_FAILURE;
    }
  }
  catch ( std::invalid_argument &e )
  {
    std::cerr << e.what() << std::endl;
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}
Ejemplo n.º 3
0
QList<ctkServiceReference> ctkServices::get(const QString& clazz, const QString& filter,
                                            ctkPluginPrivate* plugin) const
{
  Q_UNUSED(plugin)

  QMutexLocker lock(&mutex);

  QListIterator<ctkServiceRegistration>* s = 0;
  QList<ctkServiceRegistration> v;
  ctkLDAPExpr ldap;
  if (clazz.isEmpty())
  {
    if (!filter.isEmpty())
    {
      ldap = ctkLDAPExpr(filter);
      QSet<QString> matched = ldap.getMatchedObjectClasses();
      if (!matched.isEmpty())
      {
        v.clear();
        foreach (QString className, matched)
        {
          const QList<ctkServiceRegistration>& cl = classServices[className];
          v += cl;
        }
        if (!v.isEmpty())
        {
          s = new QListIterator<ctkServiceRegistration>(v);
        }
        else
        {
          return QList<ctkServiceReference>();
        }
      }
      else
      {
Ejemplo n.º 4
0
ctkLDAPExpr ctkLDAPExpr::parseExpr( ParseState &ps ) throw (ctkInvalidSyntaxException)
{
  ps.skipWhite();
  if (!ps.prefix("("))
    ps.error(MALFORMED);

  int op;
  ps.skipWhite();
  QChar c = ps.peek();
  if ( c == '&') {
    op = AND;
  }else if ( c == '|' ){
    op = OR; 
  } else if ( c == '!' ) {
    op = NOT;
  } else {
    return parseSimple(ps);
  }
  ps.skip(1); // Ignore the d->m_operator
  QList<ctkLDAPExpr> v;
  do {
    v.append(parseExpr(ps));
    ps.skipWhite();
  } while (ps.peek() == '(');
  int n = v.size();
  if (!ps.prefix(")") || n == 0 || (op == NOT && n > 1))
    ps.error(MALFORMED);

  return ctkLDAPExpr(op, v);
}
Ejemplo n.º 5
0
//----------------------------------------------------------------------------
ctkServiceSlotEntry::ctkServiceSlotEntry(
    QSharedPointer<ctkPlugin> p, QObject* receiver, const char* slot, const QString& filter)
  : d(new ctkServiceSlotEntryData(p, receiver, slot))
{
  if (!filter.isNull())
  {
    d->ldap = ctkLDAPExpr(filter);
  }
}
Ejemplo n.º 6
0
ctkLDAPExpr ctkLDAPExpr::parseSimple( ParseState &ps ) throw (ctkInvalidSyntaxException)
{
  QString attrName = ps.getAttributeName();
  if (attrName.isNull())
    ps.error(MALFORMED);
  int op = 0;
  if (ps.prefix("="))
    op = EQ;
  else if (ps.prefix("<="))
    op = LE;
  else if(ps.prefix(">="))
    op = GE;
  else if(ps.prefix("~="))
    op = APPROX;
  else {
    //      System.out.println("undef op='" + ps.peek() + "'");
    ps.error(OPERATOR); // Does not return
  }
  QString attrValue = ps.getAttributeValue();
  if (!ps.prefix(")"))
    ps.error(MALFORMED);
  return ctkLDAPExpr(op, attrName, attrValue);
}
Ejemplo n.º 7
0
bool ctkLDAPExpr::query( const QString &filter, const ctkDictionary &pd ) throw (ctkInvalidSyntaxException)
{
  return ctkLDAPExpr(filter).evaluate(pd, false);
}