2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 #include "attr_sql_plugin.h"
20 #include "sql_attribute.h"
22 typedef struct private_attr_sql_plugin_t private_attr_sql_plugin_t
;
25 * private data of attr_sql plugin
27 struct private_attr_sql_plugin_t
{
30 * implements plugin interface
32 attr_sql_plugin_t
public;
35 * database connection instance
40 * configuration attributes
42 sql_attribute_t
*attribute
;
47 * Implementation of plugin_t.destroy
49 static void destroy(private_attr_sql_plugin_t
*this)
51 hydra
->attributes
->remove_provider(hydra
->attributes
, &this->attribute
->provider
);
52 this->attribute
->destroy(this->attribute
);
53 this->db
->destroy(this->db
);
60 plugin_t
*attr_sql_plugin_create()
63 private_attr_sql_plugin_t
*this;
65 uri
= lib
->settings
->get_str(lib
->settings
, "libhydra.plugins.attr-sql.database", NULL
);
68 DBG1(DBG_CFG
, "attr-sql plugin: database URI not set");
72 this = malloc_thing(private_attr_sql_plugin_t
);
74 this->public.plugin
.destroy
= (void(*)(plugin_t
*))destroy
;
76 this->db
= lib
->db
->create(lib
->db
, uri
);
79 DBG1(DBG_CFG
, "attr-sql plugin failed to connect to database");
83 this->attribute
= sql_attribute_create(this->db
);
84 hydra
->attributes
->add_provider(hydra
->attributes
, &this->attribute
->provider
);
86 return &this->public.plugin
;