]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_cdsa_utilities/lib/db++.cpp
2 * Copyright (c) 2003-2004,2006,2011,2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 // dbm++ - generic C++ layer interface to [n]dbm
29 #include <security_utilities/debugging.h>
33 namespace UnixPlusPlus
{
35 UnixDb::UnixDb() : mDb(NULL
)
39 UnixDb::UnixDb(const char *path
, int flags
, int mode
, DBTYPE type
) : mDb(NULL
)
41 open(path
, flags
, mode
);
44 UnixDb::UnixDb(const std::string
&path
, int flags
, int mode
, DBTYPE type
) : mDb(NULL
)
46 open(path
, flags
, mode
);
54 void UnixDb::open(const char *path
, int flags
, int mode
, DBTYPE type
)
56 if (DB
* newDb
= ::dbopen(path
, flags
, mode
, type
, NULL
)) {
60 secnotice("unixdb", "open(%s,0x%x,0x%x,type=%d)=%p", path
, flags
, mode
, type
, mDb
);
65 void UnixDb::open(const std::string
&path
, int flags
, int mode
, DBTYPE type
)
67 open(path
.c_str(), flags
, mode
);
73 secnotice("unixdb", "close(%p)", mDb
);
80 bool UnixDb::get(const CssmData
&key
, CssmData
&value
, int flags
) const
84 int rc
= mDb
->get(mDb
, &dKey
, &val
, flags
);
85 secnotice("unixdb", "get(%p,[:%ld],flags=0x%x)=%d[:%ld]",
86 mDb
, key
.length(), flags
, rc
, value
.length());
95 bool UnixDb::get(const CssmData
&key
, CssmOwnedData
&value
, int flags
) const
98 if (get(key
, val
, flags
)) {
105 bool UnixDb::put(const CssmData
&key
, const CssmData
&value
, int flags
)
109 int rc
= mDb
->put(mDb
, &dKey
, &dValue
, flags
);
110 secnotice("unixdb", "put(%p,[:%ld],[:%ld],flags=0x%x)=%d",
111 mDb
, key
.length(), value
.length(), flags
, rc
);
116 void UnixDb::erase(const CssmData
&key
, int flags
)
119 secnotice("unixdb", "delete(%p,[:%ld],flags=0x%x)", mDb
, key
.length(), flags
);
120 checkError(mDb
->del(mDb
, &dKey
, flags
));
123 bool UnixDb::next(CssmData
&key
, CssmData
&value
, int flags
/* = R_NEXT */) const
126 int rc
= mDb
->seq(mDb
, &dKey
, &dValue
, flags
);
137 void UnixDb::flush(int flags
)
139 checkError(mDb
->sync(mDb
, flags
));
143 } // end namespace UnixPlusPlus
144 } // end namespace Security