2012-10-16 16:39:32 +01:00
|
|
|
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
// PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
2012-10-17 18:37:22 +01:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <string>
|
2012-10-16 16:39:32 +01:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <dhcp/mysql_lease_mgr.h>
|
|
|
|
|
2012-10-17 18:37:22 +01:00
|
|
|
using namespace std;
|
|
|
|
|
2012-10-16 16:39:32 +01:00
|
|
|
namespace isc {
|
|
|
|
namespace dhcp {
|
|
|
|
|
2012-10-17 18:37:22 +01:00
|
|
|
void
|
|
|
|
MySqlLeaseMgr::openDatabase() {
|
|
|
|
|
|
|
|
// Set up the values of the parameters
|
|
|
|
const char* host = NULL;
|
|
|
|
string shost;
|
|
|
|
try {
|
|
|
|
shost = getParameter("host");
|
|
|
|
host = shost.c_str();
|
|
|
|
} catch (...) {
|
|
|
|
// No host. Fine, we'll use NULL
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* user = NULL;
|
|
|
|
string suser;
|
|
|
|
try {
|
|
|
|
suser = getParameter("user");
|
|
|
|
user = suser.c_str();
|
|
|
|
} catch (...) {
|
|
|
|
// No user. Fine, we'll use NULL
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* password = NULL;
|
|
|
|
string spassword;
|
|
|
|
try {
|
|
|
|
spassword = getParameter("password");
|
|
|
|
password = spassword.c_str();
|
|
|
|
} catch (...) {
|
|
|
|
// No password. Fine, we'll use NULL
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* name = NULL;
|
|
|
|
string sname;
|
|
|
|
try {
|
|
|
|
sname = getParameter("name");
|
|
|
|
name = sname.c_str();
|
|
|
|
} catch (...) {
|
|
|
|
// No database name. Fine, we'll use NULL
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open the database. Use defaults for non-specified options.
|
|
|
|
MYSQL* status = mysql_real_connect(mysql_, host, user, password, name,
|
|
|
|
0, NULL, 0);
|
|
|
|
if (status != mysql_) {
|
|
|
|
isc_throw(DbOpenError, mysql_error(mysql_));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-16 16:39:32 +01:00
|
|
|
MySqlLeaseMgr::MySqlLeaseMgr(const LeaseMgr::ParameterMap& parameters)
|
2012-10-17 18:37:22 +01:00
|
|
|
: LeaseMgr(parameters), mysql_(NULL), major_(0), minor_(0) {
|
|
|
|
|
|
|
|
// Allocate context for MySQL - it is destroyed in the destructor.
|
|
|
|
mysql_ = mysql_init(NULL);
|
|
|
|
std::cerr << "cerr: mysql_ is " << long(mysql_) << std::endl;
|
|
|
|
std::cout << "cout: mysql_ is " << long(mysql_) << std::endl;
|
|
|
|
|
|
|
|
// Open the database
|
|
|
|
openDatabase();
|
|
|
|
|
2012-10-16 16:39:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MySqlLeaseMgr::~MySqlLeaseMgr() {
|
2012-10-17 18:37:22 +01:00
|
|
|
mysql_close(mysql_);
|
|
|
|
mysql_ = NULL;
|
2012-10-16 16:39:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-10-17 18:37:22 +01:00
|
|
|
MySqlLeaseMgr::addLease(isc::dhcp::Lease4Ptr /* lease */) {
|
2012-10-16 16:39:32 +01:00
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-10-17 18:37:22 +01:00
|
|
|
MySqlLeaseMgr::addLease(isc::dhcp::Lease6Ptr /* lease */) {
|
2012-10-16 16:39:32 +01:00
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Lease4Ptr
|
|
|
|
MySqlLeaseMgr::getLease4(isc::asiolink::IOAddress /* addr */,
|
|
|
|
SubnetID /* subnet_id */) const {
|
|
|
|
return (Lease4Ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
Lease4Ptr
|
|
|
|
MySqlLeaseMgr::getLease4(isc::asiolink::IOAddress /* addr */) const {
|
|
|
|
return (Lease4Ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
Lease4Collection
|
|
|
|
MySqlLeaseMgr::getLease4(const HWAddr& /* hwaddr */) const {
|
|
|
|
return (Lease4Collection());
|
|
|
|
}
|
|
|
|
|
|
|
|
Lease4Ptr
|
|
|
|
MySqlLeaseMgr::getLease4(const HWAddr& /* hwaddr */,
|
|
|
|
SubnetID /* subnet_id */) const {
|
|
|
|
return (Lease4Ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
Lease4Collection
|
|
|
|
MySqlLeaseMgr::getLease4(const ClientId& /* clientid */) const {
|
|
|
|
return (Lease4Collection());
|
|
|
|
}
|
|
|
|
|
|
|
|
Lease4Ptr
|
|
|
|
MySqlLeaseMgr::getLease4(const ClientId& /* clientid */,
|
|
|
|
SubnetID /* subnet_id */) const {
|
|
|
|
return (Lease4Ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
Lease6Ptr
|
|
|
|
MySqlLeaseMgr::getLease6(isc::asiolink::IOAddress /* addr */) const {
|
|
|
|
return (Lease6Ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
Lease6Collection
|
|
|
|
MySqlLeaseMgr::getLease6(const DUID& /* duid */, uint32_t /* iaid */) const {
|
|
|
|
return (Lease6Collection());
|
|
|
|
}
|
|
|
|
|
|
|
|
Lease6Ptr
|
|
|
|
MySqlLeaseMgr::getLease6(const DUID& /* duid */, uint32_t /* iaid */,
|
|
|
|
SubnetID /* subnet_id */) const {
|
|
|
|
return (Lease6Ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MySqlLeaseMgr::updateLease4(Lease4Ptr /* lease4 */) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MySqlLeaseMgr::updateLease6(Lease6Ptr /* lease6 */) {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
MySqlLeaseMgr::deleteLease4(uint32_t /* addr */) {
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
MySqlLeaseMgr::deleteLease6(isc::asiolink::IOAddress /* addr */) {
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
MySqlLeaseMgr::getName() const {
|
|
|
|
return (std::string(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
MySqlLeaseMgr::getDescription() const {
|
|
|
|
return (std::string(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<uint32_t, uint32_t>
|
|
|
|
MySqlLeaseMgr::getVersion() const {
|
|
|
|
return (std::make_pair(major_, minor_));
|
|
|
|
}
|
|
|
|
|
|
|
|
}; // end of isc::dhcp namespace
|
|
|
|
}; // end of isc namespace
|