Author: mysqlpp
Date: Mon Dec  3 10:31:46 2007
New Revision: 1956

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1956&view=rev
Log:
- Created SslOption, holding a set of strings suitable for passing to
  DBDriver::enable_ssl()
- Removed Connection::enable_ssl() -- no longer necessary
- DBDriver::enable_ssl() now returns bool like all the other set_option()
  implementation methods, keeping SslOption::set() internals as similar
  as possible to that of the other set() methods.

Modified:
    trunk/Wishlist
    trunk/lib/connection.cpp
    trunk/lib/connection.h
    trunk/lib/dbdriver.cpp
    trunk/lib/dbdriver.h
    trunk/lib/options.cpp
    trunk/lib/options.h

Modified: trunk/Wishlist
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=1956&r1=1955&r2=1956&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Mon Dec  3 10:31:46 2007
@@ -31,12 +31,6 @@
       - If we can get reference semantics everywhere, we can add
         operator->() to subscript_iterator.  It can't work with
         value semantics.
-
-    o Refactor option mechanism:
-    
-      - Add new Option subclass SSLOption, and reimplement
-        Connection::enable_ssl() in terms of it.  The success of this
-        will prove the value of an extensible option type system.
 
     o If Bakefile 0.2.3 (guessing) comes out before we release, change
       all the msvs2005prj references in mysql++.bkl, Bakefiles.bkgen

Modified: trunk/lib/connection.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/connection.cpp?rev=1956&r1=1955&r2=1956&view=diff
==============================================================================
--- trunk/lib/connection.cpp (original)
+++ trunk/lib/connection.cpp Mon Dec  3 10:31:46 2007
@@ -148,14 +148,6 @@
        Query q(this, throw_exceptions());
        q << "DROP DATABASE " << db;
        return q.exec();
-}
-
-
-void
-Connection::enable_ssl(const char* key, const char* cert,
-               const char* ca, const char* capath, const char* cipher) const
-{
-       error_message_ = driver_->enable_ssl(key, cert, ca, capath, cipher);
 }
 
 

Modified: trunk/lib/connection.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/connection.h?rev=1956&r1=1955&r2=1956&view=diff
==============================================================================
--- trunk/lib/connection.h (original)
+++ trunk/lib/connection.h Mon Dec  3 10:31:46 2007
@@ -165,20 +165,6 @@
        /// \return true if database was dropped successfully
        bool drop_db(const std::string& db);
 
-       /// \brief Enable SSL-encrypted connection.
-       ///
-       /// \param key the pathname to the key file
-       /// \param cert the pathname to the certificate file
-       /// \param ca the pathname to the certificate authority file
-       /// \param capath directory that contains trusted SSL CA
-       ///        certificates in pem format.
-    /// \param cipher list of allowable ciphers to use
-       ///
-       /// Must be called before connection is established.
-       void enable_ssl(const char* key = 0,
-                       const char* cert = 0, const char* ca = 0,
-                       const char* capath = 0, const char* cipher = 0) const;
-
        /// \brief Return last error number associated with this
        /// connection
        int errnum();

Modified: trunk/lib/dbdriver.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/dbdriver.cpp?rev=1956&r1=1955&r2=1956&view=diff
==============================================================================
--- trunk/lib/dbdriver.cpp (original)
+++ trunk/lib/dbdriver.cpp Mon Dec  3 10:31:46 2007
@@ -129,15 +129,14 @@
 }
 
 
-const char*
+bool
 DBDriver::enable_ssl(const char* key, const char* cert,
                const char* ca, const char* capath, const char* cipher)
 {
 #if defined(HAVE_MYSQL_SSL_SET)
-       mysql_ssl_set(&mysql_, key, cert, ca, capath, cipher);
-       return "";
+       return mysql_ssl_set(&mysql_, key, cert, ca, capath, cipher) == 0;
 #else
-       return "SSL not enabled in MySQL++";
+       return false;
 #endif
 }
 

Modified: trunk/lib/dbdriver.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/dbdriver.h?rev=1956&r1=1955&r2=1956&view=diff
==============================================================================
--- trunk/lib/dbdriver.h (original)
+++ trunk/lib/dbdriver.h Mon Dec  3 10:31:46 2007
@@ -145,12 +145,13 @@
        ///        certificates in pem format.
     /// \param cipher list of allowable ciphers to use
        ///
-       /// \return Error message if it fails, or a blank string otherwise
+       /// \return False if call fails or the C API library wasn't compiled
+       /// with SSL support enabled.
        ///
        /// Must be called before connection is established.
        ///
        /// Wraps \c mysql_ssl_set() in MySQL C API.
-       const char* enable_ssl(const char* key = 0, const char* cert = 0,
+       bool enable_ssl(const char* key = 0, const char* cert = 0,
                        const char* ca = 0, const char* capath = 0,
                        const char* cipher = 0);
 

Modified: trunk/lib/options.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/options.cpp?rev=1956&r1=1955&r2=1956&view=diff
==============================================================================
--- trunk/lib/options.cpp (original)
+++ trunk/lib/options.cpp Mon Dec  3 10:31:46 2007
@@ -302,6 +302,20 @@
 
 
 Option::Error
+SslOption::set(DBDriver* dbd)
+{
+#if defined(HAVE_MYSQL_SSL_SET)
+       return dbd->connected() ? Option::err_connected :
+                       dbd->enable_ssl(key_.c_str(), cert_.c_str(), 
ca_.c_str(),
+                               capath_.c_str(), cipher_.c_str()) ?
+                               Option::err_NONE : Option::err_bad_arg;
+#else
+       return Option::err_api_limit;
+#endif
+}
+
+
+Option::Error
 UseEmbeddedConnectionOption::set(DBDriver* dbd)
 {
 #if MYSQL_VERSION_ID >= 40101

Modified: trunk/lib/options.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/options.h?rev=1956&r1=1955&r2=1956&view=diff
==============================================================================
--- trunk/lib/options.h (original)
+++ trunk/lib/options.h Mon Dec  3 10:31:46 2007
@@ -71,8 +71,8 @@
 };
 
 
-/// \brief Define abstract interface for all *Options that take an
-/// argument.
+/// \brief Define abstract interface for all *Options that take a
+/// lone scalar as an argument.
 template <typename T>
 class DataOption : public Option
 {
@@ -409,6 +409,39 @@
 };
 
 
+/// \brief Specialized option for handling SSL parameters.
+class SslOption : public Option
+{
+public:
+       /// \brief Create a set of SSL connection option parameters
+       ///
+       /// \param key the pathname to the key file
+       /// \param cert the pathname to the certificate file
+       /// \param ca the pathname to the certificate authority file
+       /// \param capath directory that contains trusted SSL CA
+       ///        certificates in pem format.
+    /// \param cipher list of allowable ciphers to use
+       ///
+       /// This option replaces \c Connection::enable_ssl() from MySQL++
+       /// version 2.  Now you can set this connection option just like any
+       /// other.
+       SslOption(const char* key = 0, const char* cert = 0,
+                       const char* ca = 0, const char* capath = 0,
+                       const char* cipher = 0)
+       {
+               if (key)        key_.assign(key);
+               if (cert)       cert_.assign(key);
+               if (ca)         ca_.assign(key);
+               if (capath)     capath_.assign(key);
+               if (cipher)     cipher_.assign(key);
+       }
+
+private:
+       std::string key_, cert_, ca_, capath_, cipher_;
+       Error set(DBDriver* dbd);
+};
+
+
 /// \brief Connect to embedded  server in preference to remote server
 class UseEmbeddedConnectionOption : public Option
 {


_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits

Reply via email to