summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2011-11-16 15:29:43 -0500
committerEliot Horowitz <eliot@10gen.com>2011-11-16 15:40:58 -0500
commit2ea225cd7f2aa6fa2f0b93aae375f199a67f9e3f (patch)
treeac4cc2f05c085c6572a7b7450472962cd9690bc1 /db
parent51aa7535dbaa360efef413f9c3f489a4b49f573e (diff)
downloadmongo-2ea225cd7f2aa6fa2f0b93aae375f199a67f9e3f.tar.gz
move validDBName from Database to NamespaceString
Diffstat (limited to 'db')
-rw-r--r--db/database.cpp7
-rw-r--r--db/database.h5
-rw-r--r--db/namespace_common.h22
3 files changed, 26 insertions, 8 deletions
diff --git a/db/database.cpp b/db/database.cpp
index 7b47cd4e516..5b617bba141 100644
--- a/db/database.cpp
+++ b/db/database.cpp
@@ -284,13 +284,6 @@ namespace mongo {
return true;
}
- bool Database::validDBName( const string& ns ) {
- if ( ns.size() == 0 || ns.size() > 64 )
- return false;
- size_t good = strcspn( ns.c_str() , "/\\. \"" );
- return good == ns.size();
- }
-
void Database::flushFiles( bool sync ) const {
dbMutex.assertAtLeastReadLocked();
for ( unsigned i=0; i<files.size(); i++ ) {
diff --git a/db/database.h b/db/database.h
index 3522f52d935..26005c99e2b 100644
--- a/db/database.h
+++ b/db/database.h
@@ -103,7 +103,10 @@ namespace mongo {
return ns[name.size()] == '.';
}
- static bool validDBName( const string& ns );
+ // TODO: remove this method entirely
+ static bool validDBName( const string& ns ) {
+ return NamespaceString::validDBName( ns );
+ }
/**
* @throws DatabaseDifferCaseCode if the name is a duplicate based on
diff --git a/db/namespace_common.h b/db/namespace_common.h
index 59d06af63aa..b237a0b9280 100644
--- a/db/namespace_common.h
+++ b/db/namespace_common.h
@@ -60,6 +60,28 @@ namespace mongo {
static bool special(const char *ns) {
return !normal(ns) || strstr(ns, ".system.");
}
+
+ /**
+ * samples:
+ * good:
+ * foo
+ * bar
+ * foo-bar
+ * bad:
+ * foo bar
+ * foo.bar
+ * foo"bar
+ *
+ * @param db - a possible database name
+ * @return if db is an allowed database name
+ */
+ static bool validDBName( const string& db ) {
+ if ( db.size() == 0 || db.size() > 64 )
+ return false;
+ size_t good = strcspn( db.c_str() , "/\\. \"" );
+ return good == db.size();
+ }
+
private:
void init(const char *ns) {
const char *p = strchr(ns, '.');