2 * Copyright (c) 2000-2004,2011-2012,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
22 #include <security_cdsa_client/dlquery.h>
26 namespace CssmClient
{
30 // Constructing Relations
32 Comparison::Comparison(const Comparison
&r
)
33 : mName(r
.mName
), mOperator(r
.mOperator
), mFormat(r
.mFormat
),
34 mValue(Allocator::standard())
36 mValue
.copy(r
.mValue
);
39 Comparison
&Comparison::operator = (const Comparison
&r
)
42 mOperator
= r
.mOperator
;
44 mValue
.copy(r
.mValue
);
49 Comparison::Comparison(const Attribute
&attr
, CSSM_DB_OPERATOR op
, const char *s
)
50 : mName(attr
.name()), mOperator(op
), mFormat(CSSM_DB_ATTRIBUTE_FORMAT_STRING
),
51 mValue(Allocator::standard(), StringData(s
))
54 Comparison::Comparison(const Attribute
&attr
, CSSM_DB_OPERATOR op
, const std::string
&s
)
55 : mName(attr
.name()), mOperator(op
), mFormat(CSSM_DB_ATTRIBUTE_FORMAT_STRING
),
56 mValue(Allocator::standard(), StringData(s
))
59 Comparison::Comparison(const Attribute
&attr
, CSSM_DB_OPERATOR op
, uint32 value
)
60 : mName(attr
.name()), mOperator(op
), mFormat(CSSM_DB_ATTRIBUTE_FORMAT_UINT32
),
61 mValue(Allocator::standard(), CssmData::wrap(value
))
64 Comparison::Comparison(const Attribute
&attr
, CSSM_DB_OPERATOR op
, bool value
)
65 : mName(attr
.name()), mOperator(op
), mFormat(CSSM_DB_ATTRIBUTE_FORMAT_UINT32
),
66 mValue(Allocator::standard(), CssmData::wrap(uint32(value
? 1 : 0)))
69 Comparison::Comparison(const Attribute
&attr
, CSSM_DB_OPERATOR op
, const CssmData
&data
)
70 : mName(attr
.name()), mOperator(op
), mFormat(CSSM_DB_ATTRIBUTE_FORMAT_BLOB
),
71 mValue(Allocator::standard(), data
)
74 Comparison::Comparison(const Attribute
&attr
, CSSM_DB_OPERATOR op
, const CSSM_GUID
&guid
)
75 : mName(attr
.name()), mOperator(op
), mFormat(CSSM_DB_ATTRIBUTE_FORMAT_STRING
),
76 mValue(Allocator::standard(), StringData(Guid::overlay(guid
).toString()))
81 Comparison::Comparison(const Attribute
&attr
)
82 : mName(attr
.name()), mOperator(CSSM_DB_NOT_EQUAL
), mFormat(CSSM_DB_ATTRIBUTE_FORMAT_UINT32
),
83 mValue(Allocator::standard(), CssmData::wrap(uint32(CSSM_FALSE
)))
87 Comparison
operator ! (const Attribute
&attr
)
89 return Comparison(attr
, CSSM_DB_EQUAL
, uint32(CSSM_FALSE
));
96 Query
&Query::operator = (const Query
&q
)
98 mRelations
= q
.mRelations
;
105 // Form the CssmQuery from a Query object.
106 // We cache this in mQuery, which we have made sure isn't copied along.
108 const CssmQuery
&Query::cssmQuery() const
111 // record type remains at ANY
112 mQuery
.conjunctive(CSSM_DB_AND
);
113 for (vector
<Comparison
>::const_iterator it
= mRelations
.begin(); it
!= mRelations
.end(); it
++) {
114 CssmSelectionPredicate pred
;
115 pred
.dbOperator(it
->mOperator
);
116 pred
.attribute().info() = CssmDbAttributeInfo(it
->mName
.c_str(), it
->mFormat
);
117 pred
.attribute().set(it
->mValue
.get());
118 mPredicates
.push_back(pred
);
120 mQuery
.set((uint32
)mPredicates
.size(), &mPredicates
[0]);
127 } // end namespace CssmClient
128 } // end namespace Security