ctkLDAPSearchFilter.h 5.5 KB

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