Migrated mysql plugin to INIT/METHOD macros
authorAndreas Steffen <andreas.steffen@strongswan.org>
Sat, 4 Dec 2010 09:38:35 +0000 (10:38 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Sat, 4 Dec 2010 09:38:35 +0000 (10:38 +0100)
src/libstrongswan/plugins/mysql/mysql_database.c
src/libstrongswan/plugins/mysql/mysql_plugin.c

index 8005b91..5fbfa0f 100644 (file)
@@ -474,10 +474,8 @@ static bool mysql_enumerator_enumerate(mysql_enumerator_t *this, ...)
        return TRUE;
 }
 
-/**
- * Implementation of database_t.query.
- */
-static enumerator_t* query(private_mysql_database_t *this, char *sql, ...)
+METHOD(database_t, query, enumerator_t*,
+       private_mysql_database_t *this, char *sql, ...)
 {
        MYSQL_STMT *stmt;
        va_list args;
@@ -563,10 +561,8 @@ static enumerator_t* query(private_mysql_database_t *this, char *sql, ...)
        return (enumerator_t*)enumerator;
 }
 
-/**
- * Implementation of database_t.execute.
- */
-static int execute(private_mysql_database_t *this, int *rowid, char *sql, ...)
+METHOD(database_t, execute, int,
+       private_mysql_database_t *this, int *rowid, char *sql, ...)
 {
        MYSQL_STMT *stmt;
        va_list args;
@@ -594,18 +590,14 @@ static int execute(private_mysql_database_t *this, int *rowid, char *sql, ...)
        return affected;
 }
 
-/**
- * Implementation of database_t.get_driver
- */
-static db_driver_t get_driver(private_mysql_database_t *this)
+METHOD(database_t, get_driver,db_driver_t,
+       private_mysql_database_t *this)
 {
        return DB_MYSQL;
 }
 
-/**
- * Implementation of database_t.destroy
- */
-static void destroy(private_mysql_database_t *this)
+METHOD(database_t, destroy, void,
+       private_mysql_database_t *this)
 {
        this->pool->destroy_function(this->pool, (void*)conn_destroy);
        this->mutex->destroy(this->mutex);
@@ -677,12 +669,16 @@ mysql_database_t *mysql_database_create(char *uri)
                return NULL;
        }
 
-       this = malloc_thing(private_mysql_database_t);
-
-       this->public.db.query = (enumerator_t* (*)(database_t *this, char *sql, ...))query;
-       this->public.db.execute = (int (*)(database_t *this, int *rowid, char *sql, ...))execute;
-       this->public.db.get_driver = (db_driver_t(*)(database_t*))get_driver;
-       this->public.db.destroy = (void(*)(database_t*))destroy;
+       INIT(this,
+               .public = {
+                       .db = {
+                               .query = _query,
+                               .execute = _execute,
+                               .get_driver = _get_driver,
+                               .destroy = _destroy,
+                       },
+               },
+       );
 
        if (!parse_uri(this, uri))
        {
index a13aa80..65d8681 100644 (file)
@@ -32,10 +32,8 @@ struct private_mysql_plugin_t {
        mysql_plugin_t public;
 };
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_mysql_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       private_mysql_plugin_t *this)
 {
        lib->db->remove_database(lib->db,
                                                         (database_constructor_t)mysql_database_create);
@@ -56,8 +54,13 @@ plugin_t *mysql_plugin_create()
                return NULL;
        }
 
-       this = malloc_thing(private_mysql_plugin_t);
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+       );
 
        lib->db->add_database(lib->db,
                                                  (database_constructor_t)mysql_database_create);