2 * Copyright (c) 2004,2011,2014 Apple Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // dlquery - search query sublanguage for DL and MDS queries
23 #ifndef _H_CDSA_CLIENT_DLQUERY
24 #define _H_CDSA_CLIENT_DLQUERY
26 #include <security_cdsa_utilities/cssmdb.h>
32 namespace CssmClient
{
36 // A DL record attribute
40 Attribute(const std::string
&name
) : mName(name
) { }
41 Attribute(const char *name
) : mName(name
) { }
43 const std::string
&name() const { return mName
; }
51 // A comparison (attribute ~rel~ constant-value)
56 Comparison(const Attribute
&attr
, CSSM_DB_OPERATOR op
, const char *s
);
57 Comparison(const Attribute
&attr
, CSSM_DB_OPERATOR op
, const std::string
&s
);
58 Comparison(const Attribute
&attr
, CSSM_DB_OPERATOR op
, uint32 v
);
59 Comparison(const Attribute
&attr
, CSSM_DB_OPERATOR op
, bool v
);
60 Comparison(const Attribute
&attr
, CSSM_DB_OPERATOR op
, const CSSM_GUID
&guid
);
61 Comparison(const Attribute
&attr
, CSSM_DB_OPERATOR op
, const CssmData
&data
);
63 Comparison(const Attribute
&attr
);
64 friend Comparison
operator ! (const Attribute
&attr
);
66 Comparison(const Comparison
&r
);
67 Comparison
&operator = (const Comparison
&r
);
71 CSSM_DB_OPERATOR mOperator
;
72 CSSM_DB_ATTRIBUTE_FORMAT mFormat
;
76 template <class Value
>
77 Comparison
operator == (const Attribute
&attr
, const Value
&value
)
78 { return Comparison(attr
, CSSM_DB_EQUAL
, value
); }
80 template <class Value
>
81 Comparison
operator != (const Attribute
&attr
, const Value
&value
)
82 { return Comparison(attr
, CSSM_DB_NOT_EQUAL
, value
); }
84 template <class Value
>
85 Comparison
operator < (const Attribute
&attr
, const Value
&value
)
86 { return Comparison(attr
, CSSM_DB_LESS_THAN
, value
); }
88 template <class Value
>
89 Comparison
operator > (const Attribute
&attr
, const Value
&value
)
90 { return Comparison(attr
, CSSM_DB_GREATER_THAN
, value
); }
92 template <class Value
>
93 Comparison
operator % (const Attribute
&attr
, const Value
&value
)
94 { return Comparison(attr
, CSSM_DB_CONTAINS
, value
); }
102 Query() : mQueryValid(false) { }
103 Query(const Comparison r
) : mQueryValid(false) { mRelations
.push_back(r
); }
104 Query(const Attribute
&attr
) : mQueryValid(false) { mRelations
.push_back(attr
); }
106 Query(const Query
&q
) : mRelations(q
.mRelations
), mQueryValid(false) { }
108 Query
&operator = (const Query
&q
);
110 Query
&add(const Comparison
&r
)
111 { mRelations
.push_back(r
); return *this; }
113 const CssmQuery
&cssmQuery() const;
116 std::vector
<Comparison
> mRelations
;
118 // cached CssmQuery equivalent of this object
119 mutable bool mQueryValid
; // mQuery has been constructed
120 mutable vector
<CssmSelectionPredicate
> mPredicates
; // holds lifetimes for mQuery
121 mutable CssmQuery mQuery
;
124 inline Query
operator && (Query c
, const Comparison
&r
)
128 } // end namespace CssmClient
129 } // end namespace Security
131 #endif // _H_CDSA_CLIENT_DLQUERY