]>
git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/db++.cpp
33b9f772f275d1dc2667880a1f5f7040a09f6ede
2 * Copyright (c) 2003 Apple Computer, 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 // dbm++ - generic C++ layer interface to [n]dbm
23 #include <Security/debugging.h>
27 namespace UnixPlusPlus
{
29 UnixDb::UnixDb() : mDb(NULL
)
33 UnixDb::UnixDb(const char *path
, int flags
, int mode
, DBTYPE type
) : mDb(NULL
)
35 open(path
, flags
, mode
);
38 UnixDb::UnixDb(const std::string
&path
, int flags
, int mode
, DBTYPE type
) : mDb(NULL
)
40 open(path
, flags
, mode
);
48 void UnixDb::open(const char *path
, int flags
, int mode
, DBTYPE type
)
50 if (DB
* newDb
= ::dbopen(path
, flags
, mode
, type
, NULL
)) {
54 secdebug("unixdb", "open(%s,0x%x,0x%x,type=%d)=%p", path
, flags
, mode
, type
, mDb
);
59 void UnixDb::open(const std::string
&path
, int flags
, int mode
, DBTYPE type
)
61 open(path
.c_str(), flags
, mode
);
67 secdebug("unixdb", "close(%p)", mDb
);
74 bool UnixDb::get(const CssmData
&key
, CssmData
&value
, int flags
) const
78 int rc
= mDb
->get(mDb
, &dKey
, &val
, flags
);
79 secdebug("unixdb", "get(%p,[:%ld],flags=0x%x)=%d[:%ld]",
80 mDb
, key
.length(), flags
, rc
, value
.length());
89 bool UnixDb::get(const CssmData
&key
, CssmOwnedData
&value
, int flags
) const
92 if (get(key
, val
, flags
)) {
99 bool UnixDb::put(const CssmData
&key
, const CssmData
&value
, int flags
)
103 int rc
= mDb
->put(mDb
, &dKey
, &dValue
, flags
);
104 secdebug("unixdb", "put(%p,[:%ld],[:%ld],flags=0x%x)=%d",
105 mDb
, key
.length(), value
.length(), flags
, rc
);
110 void UnixDb::erase(const CssmData
&key
, int flags
)
113 secdebug("unixdb", "delete(%p,[:%ld],flags=0x%x)", mDb
, key
.length(), flags
);
114 checkError(mDb
->del(mDb
, &dKey
, flags
));
117 bool UnixDb::next(CssmData
&key
, CssmData
&value
, int flags
/* = R_NEXT */) const
120 int rc
= mDb
->seq(mDb
, &dKey
, &dValue
, flags
);
131 void UnixDb::flush(int flags
)
133 checkError(mDb
->sync(mDb
, flags
));
137 } // end namespace UnixPlusPlus
138 } // end namespace Security