ctkLDAPExpr_p.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKLDAPEXPR_P_H
  16. #define CTKLDAPEXPR_P_H
  17. #include "ctkPluginConstants.h"
  18. #include "ctkServiceProperties_p.h"
  19. #include <QString>
  20. #include <QHash>
  21. #include <QSharedDataPointer>
  22. #include <QVector>
  23. #include <QStringList>
  24. class ctkLDAPExprData;
  25. /**
  26. \ingroup PluginFramework
  27. \brief LDAP Expression
  28. \date 19 May 2010
  29. \author Xavi Planes
  30. \ingroup ctkPluginFramework
  31. */
  32. class ctkLDAPExpr {
  33. public:
  34. const static int AND; // = 0;
  35. const static int OR; // = 1;
  36. const static int NOT; // = 2;
  37. const static int EQ; // = 4;
  38. const static int LE; // = 8;
  39. const static int GE; // = 16;
  40. const static int APPROX; // = 32;
  41. const static int COMPLEX; // = AND | OR | NOT;
  42. const static int SIMPLE; // = EQ | LE | GE | APPROX;
  43. typedef char Byte;
  44. typedef QVector<QStringList> LocalCache;
  45. /**
  46. * Creates an invalid ctkLDAPExpr object. Use with care.
  47. *
  48. * @see isNull()
  49. */
  50. ctkLDAPExpr();
  51. //!
  52. ctkLDAPExpr(const QString &filter);
  53. //!
  54. ctkLDAPExpr(const ctkLDAPExpr& other);
  55. ctkLDAPExpr& operator=(const ctkLDAPExpr& other);
  56. ~ctkLDAPExpr();
  57. /**
  58. * Get object class set matched by this LDAP expression. This will not work
  59. * with wildcards and NOT expressions. If a set can not be determined return <code>fasle</code>.
  60. *
  61. * \param objClasses The set of matched classes will be added to objClasses.
  62. * \return If the set cannot be determined, <code>false</code> is returned,
  63. * <code>true</code> otherwise.
  64. */
  65. bool getMatchedObjectClasses(QSet<QString>& objClasses) const;
  66. /**
  67. * Checks if this LDAP expression is "simple". The definition of
  68. * a simple filter is:
  69. * <ul>
  70. * <li><code>(<it>name</it>=<it>value</it>)</code> is simple if
  71. * <it>name</it> is a member of the provided <code>keywords</code>,
  72. * and <it>value</it> does not contain a wildcard character;</li>
  73. * <li><code>(| EXPR+ )</code> is simple if all <code>EXPR</code>
  74. * expressions are simple;</li>
  75. * <li>No other expressions are simple.</li>
  76. * </ul>
  77. * If the filter is found to be simple, the <code>cache</code> is
  78. * filled with mappings from the provided keywords to lists
  79. * of attribute values. The keyword-value-pairs are the ones that
  80. * satisfy this expression, for the given keywords.
  81. *
  82. * @param keywords The keywords to look for.
  83. * @param cache An array (indexed by the keyword indexes) of lists to
  84. * fill in with values saturating this expression.
  85. * @return <code>true</code> if this expression is simple,
  86. * <code>false</code> otherwise.
  87. */
  88. bool isSimple(
  89. const QStringList& keywords,
  90. LocalCache& cache,
  91. bool matchCase) const;
  92. /**
  93. * Returns <code>true</code> if this instance is invalid, i.e. it was
  94. * constructed using ctkLDAPExpr().
  95. *
  96. * @return <code>true</code> if the expression is invalid,
  97. * <code>false</code> otherwise.
  98. */
  99. bool isNull() const;
  100. //!
  101. static bool query(const QString &filter, const ctkDictionary &pd);
  102. //! Evaluate this LDAP filter.
  103. bool evaluate(const ctkServiceProperties &p, bool matchCase) const;
  104. //!
  105. const QString toString() const;
  106. private:
  107. class ParseState;
  108. //!
  109. ctkLDAPExpr(int op, const QList<ctkLDAPExpr> &args);
  110. //!
  111. ctkLDAPExpr(int op, const QString &attrName, const QString &attrValue);
  112. //!
  113. static ctkLDAPExpr parseExpr(ParseState &ps);
  114. //!
  115. static ctkLDAPExpr parseSimple(ParseState &ps);
  116. //!
  117. bool compare(const QVariant &obj, int op, const QString &s) const;
  118. //!
  119. static bool compareString(const QString &s1, int op, const QString &s2);
  120. //!
  121. static QString fixupString(const QString &s);
  122. //!
  123. static bool patSubstr(const QString &s, const QString &pat);
  124. //!
  125. static bool patSubstr(const QString &s, int si, const QString &pat, int pi);
  126. const static QChar WILDCARD; // = 65535;
  127. const static QString WILDCARD_QString;// = QString( WILDCARD );
  128. const static QString NULLQ;// = "Null query";
  129. const static QString GARBAGE;// = "Trailing garbage";
  130. const static QString EOS;// = "Unexpected end of query";
  131. const static QString MALFORMED;// = "Malformed query";
  132. const static QString OPERATOR;// = "Undefined m_operator";
  133. //! Shared pointer
  134. QSharedDataPointer<ctkLDAPExprData> d;
  135. };
  136. #endif // CTKLDAPEXPR_P_H