Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
3f847f9d
Commit
3f847f9d
authored
Aug 25, 2011
by
Jelte Jansen
Browse files
Merge branch 'trac1174'
parents
087c6def
1921e129
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/lib/datasrc/database.cc
View file @
3f847f9d
...
...
@@ -49,7 +49,7 @@ DatabaseClient::DatabaseClient(boost::shared_ptr<DatabaseAccessor>
DataSourceClient
::
FindResult
DatabaseClient
::
findZone
(
const
Name
&
name
)
const
{
std
::
pair
<
bool
,
int
>
zone
(
database_
->
getZone
(
name
));
std
::
pair
<
bool
,
int
>
zone
(
database_
->
getZone
(
name
.
toText
()
));
// Try exact first
if
(
zone
.
first
)
{
return
(
FindResult
(
result
::
SUCCESS
,
...
...
@@ -60,7 +60,7 @@ DatabaseClient::findZone(const Name& name) const {
// Start from 1, as 0 is covered above
for
(
size_t
i
(
1
);
i
<
name
.
getLabelCount
();
++
i
)
{
isc
::
dns
::
Name
superdomain
(
name
.
split
(
i
));
zone
=
database_
->
getZone
(
superdomain
);
zone
=
database_
->
getZone
(
superdomain
.
toText
()
);
if
(
zone
.
first
)
{
return
(
FindResult
(
result
::
PARTIALMATCH
,
ZoneFinderPtr
(
new
Finder
(
database_
,
...
...
@@ -488,7 +488,7 @@ private:
ZoneIteratorPtr
DatabaseClient
::
getIterator
(
const
isc
::
dns
::
Name
&
name
)
const
{
// Get the zone
std
::
pair
<
bool
,
int
>
zone
(
database_
->
getZone
(
name
));
std
::
pair
<
bool
,
int
>
zone
(
database_
->
getZone
(
name
.
toText
()
));
if
(
!
zone
.
first
)
{
// No such zone, can't continue
isc_throw
(
DataSourceError
,
"Zone "
+
name
.
toText
()
+
...
...
src/lib/datasrc/database.h
View file @
3f847f9d
...
...
@@ -88,7 +88,8 @@ public:
* It is not specified if and what implementation of this method may throw,
* so code should expect anything.
*
* \param name The name of the zone's apex to be looked up.
* \param name The (fully qualified) domain name of the zone's apex to be
* looked up.
* \return The first part of the result indicates if a matching zone
* was found. In case it was, the second part is internal zone ID.
* This one will be passed to methods finding data in the zone.
...
...
@@ -96,7 +97,7 @@ public:
* be returned - the ID is only passed back to the database as
* an opaque handle.
*/
virtual
std
::
pair
<
bool
,
int
>
getZone
(
const
isc
::
dns
::
Name
&
name
)
const
=
0
;
virtual
std
::
pair
<
bool
,
int
>
getZone
(
const
std
::
string
&
name
)
const
=
0
;
/**
* \brief This holds the internal context of ZoneIterator for databases
...
...
src/lib/datasrc/sqlite3_accessor.cc
View file @
3f847f9d
...
...
@@ -280,14 +280,14 @@ SQLite3Database::close(void) {
}
std
::
pair
<
bool
,
int
>
SQLite3Database
::
getZone
(
const
isc
::
dns
::
Name
&
name
)
const
{
SQLite3Database
::
getZone
(
const
std
::
string
&
name
)
const
{
int
rc
;
// Take the statement (simple SELECT id FROM zones WHERE...)
// and prepare it (bind the parameters to it)
sqlite3_reset
(
dbparameters_
->
q_zone_
);
rc
=
sqlite3_bind_text
(
dbparameters_
->
q_zone_
,
1
,
name
.
toText
().
c_str
(),
-
1
,
SQLITE_
TRANSIENT
);
rc
=
sqlite3_bind_text
(
dbparameters_
->
q_zone_
,
1
,
name
.
c_str
(),
-
1
,
SQLITE_
STATIC
);
if
(
rc
!=
SQLITE_OK
)
{
isc_throw
(
SQLite3Error
,
"Could not bind "
<<
name
<<
" to SQL statement (zone)"
);
...
...
src/lib/datasrc/sqlite3_accessor.h
View file @
3f847f9d
...
...
@@ -87,11 +87,11 @@ public:
*
* \exception SQLite3Error if something about the database is broken.
*
* \param name The name of zone to look up
* \param name The
(fully qualified) domain
name of zone to look up
* \return The pair contains if the lookup was successful in the first
* element and the zone id in the second if it was.
*/
virtual
std
::
pair
<
bool
,
int
>
getZone
(
const
isc
::
dns
::
Name
&
name
)
const
;
virtual
std
::
pair
<
bool
,
int
>
getZone
(
const
std
::
string
&
name
)
const
;
/** \brief Look up all resource records for a name
*
...
...
src/lib/datasrc/tests/database_unittest.cc
View file @
3f847f9d
...
...
@@ -44,14 +44,14 @@ public:
NopAccessor
()
:
database_name_
(
"mock_database"
)
{
}
virtual
std
::
pair
<
bool
,
int
>
getZone
(
const
Name
&
name
)
const
{
if
(
name
==
Name
(
"example.org"
)
)
{
virtual
std
::
pair
<
bool
,
int
>
getZone
(
const
std
::
string
&
name
)
const
{
if
(
name
==
"example.org
.
"
)
{
return
(
std
::
pair
<
bool
,
int
>
(
true
,
42
));
}
else
if
(
name
==
Name
(
"null.example.org"
)
)
{
}
else
if
(
name
==
"null.example.org
.
"
)
{
return
(
std
::
pair
<
bool
,
int
>
(
true
,
13
));
}
else
if
(
name
==
Name
(
"empty.example.org"
)
)
{
}
else
if
(
name
==
"empty.example.org
.
"
)
{
return
(
std
::
pair
<
bool
,
int
>
(
true
,
0
));
}
else
if
(
name
==
Name
(
"bad.example.org"
)
)
{
}
else
if
(
name
==
"bad.example.org
.
"
)
{
return
(
std
::
pair
<
bool
,
int
>
(
true
,
-
1
));
}
else
{
return
(
std
::
pair
<
bool
,
int
>
(
false
,
0
));
...
...
src/lib/datasrc/tests/sqlite3_accessor_unittest.cc
View file @
3f847f9d
...
...
@@ -83,25 +83,25 @@ public:
// This zone exists in the data, so it should be found
TEST_F
(
SQLite3Access
,
getZone
)
{
std
::
pair
<
bool
,
int
>
result
(
db
->
getZone
(
Name
(
"example.com"
)
));
std
::
pair
<
bool
,
int
>
result
(
db
->
getZone
(
"example.com
.
"
));
EXPECT_TRUE
(
result
.
first
);
EXPECT_EQ
(
1
,
result
.
second
);
}
// But it should find only the zone, nothing below it
TEST_F
(
SQLite3Access
,
subZone
)
{
EXPECT_FALSE
(
db
->
getZone
(
Name
(
"sub.example.com"
)
).
first
);
EXPECT_FALSE
(
db
->
getZone
(
"sub.example.com
.
"
).
first
);
}
// This zone is not there at all
TEST_F
(
SQLite3Access
,
noZone
)
{
EXPECT_FALSE
(
db
->
getZone
(
Name
(
"example.org"
)
).
first
);
EXPECT_FALSE
(
db
->
getZone
(
"example.org
.
"
).
first
);
}
// This zone is there, but in different class
TEST_F
(
SQLite3Access
,
noClass
)
{
initAccessor
(
SQLITE_DBFILE_EXAMPLE
,
RRClass
::
CH
());
EXPECT_FALSE
(
db
->
getZone
(
Name
(
"example.com"
)
).
first
);
EXPECT_FALSE
(
db
->
getZone
(
"example.com
.
"
).
first
);
}
// This tests the iterator context
...
...
@@ -109,7 +109,7 @@ TEST_F(SQLite3Access, iterator) {
// Our test zone is conveniently small, but not empty
initAccessor
(
SQLITE_DBFILE_EXAMPLE_ORG
,
RRClass
::
IN
());
const
std
::
pair
<
bool
,
int
>
zone_info
(
db
->
getZone
(
Name
(
"example.org"
)
));
const
std
::
pair
<
bool
,
int
>
zone_info
(
db
->
getZone
(
"example.org
.
"
));
ASSERT_TRUE
(
zone_info
.
first
);
// Get the iterator context
...
...
@@ -223,7 +223,7 @@ checkRecordRow(const std::string columns[],
}
TEST_F
(
SQLite3Access
,
getRecords
)
{
const
std
::
pair
<
bool
,
int
>
zone_info
(
db
->
getZone
(
Name
(
"example.com"
)
));
const
std
::
pair
<
bool
,
int
>
zone_info
(
db
->
getZone
(
"example.com
.
"
));
ASSERT_TRUE
(
zone_info
.
first
);
const
int
zone_id
=
zone_info
.
second
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment