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
17 #include <utils/debug.h>
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
;
45 METHOD(plugin_t
, get_name
, char*,
46 private_attr_sql_plugin_t
*this)
51 METHOD(plugin_t
, destroy
, void,
52 private_attr_sql_plugin_t
*this)
54 hydra
->attributes
->remove_provider(hydra
->attributes
, &this->attribute
->provider
);
55 this->attribute
->destroy(this->attribute
);
56 this->db
->destroy(this->db
);
63 plugin_t
*attr_sql_plugin_create()
65 private_attr_sql_plugin_t
*this;
68 uri
= lib
->settings
->get_str(lib
->settings
, "libhydra.plugins.attr-sql.database",
72 DBG1(DBG_CFG
, "attr-sql plugin: database URI not set");
79 .get_name
= _get_name
,
80 .reload
= (void*)return_false
,
84 .db
= lib
->db
->create(lib
->db
, uri
),
89 DBG1(DBG_CFG
, "attr-sql plugin failed to connect to database");
93 this->attribute
= sql_attribute_create(this->db
);
94 hydra
->attributes
->add_provider(hydra
->attributes
, &this->attribute
->provider
);
96 return &this->public.plugin
;