lease_mgr.cc 2.26 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// 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.

#include <sstream>
#include <iostream>
#include <map>
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <exceptions/exceptions.h>
#include <boost/foreach.hpp>
#include <boost/algorithm/string.hpp>
#include "lease_mgr.h"

using namespace std;

using namespace isc::dhcp;

LeaseMgr::LeaseMgr(const std::string& dbconfig) {

Tomek Mrugalski's avatar
Tomek Mrugalski committed
34
35
36
37
    if (dbconfig.length() == 0) {
        return;
    }

38
39
    vector<string> tokens;

40
41
42
43
    // we need to pass a string to is_any_of, not just char *. Otherwise there
    // are cryptic warnings on Debian6 running g++ 4.4 in /usr/include/c++/4.4
    // /bits/stl_algo.h:2178 "array subscript is above array bounds"
    boost::split(tokens, dbconfig, boost::is_any_of( string("\t ") ));
44
45
46
47
48
49
50
51
52
53
54
55
    BOOST_FOREACH(std::string token, tokens) {
        size_t pos = token.find("=");
        if (pos != string::npos) {
            string name = token.substr(0, pos);
            string value = token.substr(pos + 1, -1);
            parameters_.insert(pair<string,string>(name, value));
        } else {
            isc_throw(InvalidParameter, "Cannot parse " << token
                      << ", expected format is name=value");
        }

    }
Tomek Mrugalski's avatar
Tomek Mrugalski committed
56
}
57

Tomek Mrugalski's avatar
Tomek Mrugalski committed
58
std::string LeaseMgr::getParameter(const std::string& name) const {
59
60
    std::map<std::string, std::string>::const_iterator param
        = parameters_.find(name);
Tomek Mrugalski's avatar
Tomek Mrugalski committed
61
62
63
64
    if (param == parameters_.end()) {
        isc_throw(BadValue, "Parameter not found");
    }
    return (param->second);
65
66
67
68
}

LeaseMgr::~LeaseMgr() {
}