ctkLDAPSearchFilter.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 CTKLDAPSEARCHFILTER_H
  16. #define CTKLDAPSEARCHFILTER_H
  17. #include "ctkPluginFrameworkExport.h"
  18. #include "ctkServiceReference.h"
  19. #include "ctkDictionary.h"
  20. #include <QSharedDataPointer>
  21. #include <QDebug>
  22. class ctkLDAPSearchFilterData;
  23. /**
  24. * \ingroup PluginFramework
  25. *
  26. * An <a href="http://www.ietf.org/rfc/rfc1960.txt">RFC 1960</a>-based Filter.
  27. *
  28. * <p>
  29. * A <code>ctkLDAPSearchFilter</code> can be used numerous times to determine if the match
  30. * argument matches the filter string that was used to create the <code>ctkLDAPSearchFilter</code>.
  31. * <p>
  32. * Some examples of LDAP filters are:
  33. *
  34. * \verbatim
  35. * "(cn=Babs Jensen)"
  36. * "(!(cn=Tim Howes))"
  37. * "(&(" + ctkPluginConstants::OBJECTCLASS + "=Person)(|(sn=Jensen)(cn=Babs J*)))"
  38. * "(o=univ*of*mich*)"
  39. * \endverbatim
  40. *
  41. * \see "CTK Wiki for a description of the filter string syntax." TODO!
  42. * \remarks This class is thread safe.
  43. */
  44. class CTK_PLUGINFW_EXPORT ctkLDAPSearchFilter {
  45. public:
  46. /**
  47. * Creates in invalid <code>ctkLDAPSearchFilter</code> object.
  48. * Test the validity by using the boolean conversion operator.
  49. *
  50. * <p>
  51. * Calling methods on an invalid <code>ctkLDAPSearchFilter</code>
  52. * will result in undefined behavior.
  53. */
  54. ctkLDAPSearchFilter();
  55. /**
  56. * Creates a <code>ctkLDAPSearchFilter</code> object. This <code>ctkLDAPSearchFilter</code>
  57. * object may be used to match a <code>ctkServiceReference</code> object or a
  58. * <code>ctkDictionary</code> object.
  59. *
  60. * <p>
  61. * If the filter cannot be parsed, an std::invalid_argument will be
  62. * thrown with a human readable message where the filter became unparsable.
  63. *
  64. * @param filter The filter string.
  65. * @return A <code>ctkLDAPSearchFilter</code> object encapsulating the filter string.
  66. * @throws std::invalid_argument If <code>filter</code> contains an invalid
  67. * filter string that cannot be parsed.
  68. * @see "Framework specification for a description of the filter string syntax." TODO!
  69. */
  70. ctkLDAPSearchFilter(const QString& filter);
  71. ctkLDAPSearchFilter(const ctkLDAPSearchFilter& other);
  72. ~ctkLDAPSearchFilter();
  73. operator bool() const;
  74. /**
  75. * Filter using a service's properties.
  76. * <p>
  77. * This <code>ctkLDAPSearchFilter</code> is executed using the keys and values of the
  78. * referenced service's properties. The keys are looked up in a case
  79. * insensitive manner.
  80. *
  81. * @param reference The reference to the service whose properties are used
  82. * in the match.
  83. * @return <code>true</code> if the service's properties match this
  84. * <code>ctkLDAPSearchFilter</code> <code>false</code> otherwise.
  85. */
  86. bool match(const ctkServiceReference& reference) const;
  87. /**
  88. * Filter using a <code>ctkDictionary</code> with case insensitive key lookup. This
  89. * <code>ctkLDAPSearchFilter</code> is executed using the specified <code>ctkDictionary</code>'s keys
  90. * and values. The keys are looked up in a case insensitive manner.
  91. *
  92. * @param dictionary The <code>ctkDictionary</code> whose key/value pairs are used
  93. * in the match.
  94. * @return <code>true</code> if the <code>ctkDictionary</code>'s values match this
  95. * filter; <code>false</code> otherwise.
  96. */
  97. bool match(const ctkDictionary& dictionary) const;
  98. /**
  99. * Filter using a <code>ctkDictionary</code>. This <code>ctkLDAPSearchFilter</code> is executed using
  100. * the specified <code>ctkDictionary</code>'s keys and values. The keys are looked
  101. * up in a normal manner respecting case.
  102. *
  103. * @param dictionary The <code>ctkDictionary</code> whose key/value pairs are used
  104. * in the match.
  105. * @return <code>true</code> if the <code>ctkDictionary</code>'s values match this
  106. * filter; <code>false</code> otherwise.
  107. */
  108. bool matchCase(const ctkDictionary& dictionary) const;
  109. /**
  110. * Returns this <code>ctkLDAPSearchFilter</code>'s filter string.
  111. * <p>
  112. * The filter string is normalized by removing whitespace which does not
  113. * affect the meaning of the filter.
  114. *
  115. * @return This <code>ctkLDAPSearchFilter</code>'s filter string.
  116. */
  117. QString toString() const;
  118. /**
  119. * Compares this <code>ctkLDAPSearchFilter</code> to another <code>ctkLDAPSearchFilter</code>.
  120. *
  121. * <p>
  122. * This implementation returns the result of calling
  123. * <code>this->toString() == other.toString()</code>.
  124. *
  125. * @param other The object to compare against this <code>ctkLDAPSearchFilter</code>.
  126. * @return Returns the result of calling
  127. * <code>this->toString() == other.toString()</code>.
  128. */
  129. bool operator==(const ctkLDAPSearchFilter& other) const;
  130. ctkLDAPSearchFilter& operator=(const ctkLDAPSearchFilter& filter);
  131. protected:
  132. QSharedDataPointer<ctkLDAPSearchFilterData> d;
  133. };
  134. /**
  135. * \ingroup PluginFramework
  136. */
  137. CTK_PLUGINFW_EXPORT QDebug operator<<(QDebug dbg, const ctkLDAPSearchFilter& filter);
  138. #endif // CTKLDAPSEARCHFILTER_H