LCOV - code coverage report
Current view: top level - server_common - keyring.cc (source / functions) Hit Total Coverage
Test: report.info Lines: 19 19 100.0 %
Date: 2012-05-15 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 27 44 61.4 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
       2                 :            : //
       3                 :            : // Permission to use, copy, modify, and/or distribute this software for any
       4                 :            : // purpose with or without fee is hereby granted, provided that the above
       5                 :            : // copyright notice and this permission notice appear in all copies.
       6                 :            : //
       7                 :            : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
       8                 :            : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
       9                 :            : // AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
      10                 :            : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
      11                 :            : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
      12                 :            : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
      13                 :            : // PERFORMANCE OF THIS SOFTWARE.
      14                 :            : 
      15                 :            : #include <server_common/keyring.h>
      16                 :            : #include <server_common/logger.h>
      17                 :            : 
      18                 :            : using namespace isc::dns;
      19                 :            : using namespace isc::data;
      20                 :            : 
      21                 :            : namespace isc {
      22                 :            : namespace server_common {
      23                 :            : 
      24                 :            : typedef boost::shared_ptr<TSIGKeyRing> KeyringPtr;
      25                 :            : 
      26                 :          5 : KeyringPtr keyring;
      27                 :            : 
      28                 :            : namespace {
      29                 :            : 
      30                 :            : void
      31                 :         12 : updateKeyring(const std::string&, ConstElementPtr data,
      32                 :            :               const isc::config::ConfigData&) {
      33         [ +  - ]:         12 :     ConstElementPtr list(data->get("keys"));
      34 [ +  - ][ +  - ]:         12 :     KeyringPtr load(new TSIGKeyRing);
      35 [ +  - ][ +  - ]:         12 :     LOG_DEBUG(logger, DBG_TRACE_BASIC, SRVCOMM_KEYS_UPDATE);
         [ +  - ][ +  - ]
      36                 :            : 
      37                 :            :     // Note that 'data' only contains explicitly configured config parameters.
      38                 :            :     // So if we use the default list is NULL, rather than an empty list, and
      39                 :            :     // we must explicitly expect that case (and handle it just like an empty
      40                 :            :     // list).
      41 [ +  + ][ +  - ]:         30 :     for (size_t i(0); list && i < list->size(); ++ i) {
         [ +  + ][ +  + ]
      42 [ +  - ][ +  - ]:         18 :         load->add(TSIGKey(list->get(i)->stringValue()));
         [ +  - ][ +  - ]
                 [ +  - ]
      43                 :            :     }
      44                 :            :     keyring.swap(load);
      45                 :         12 : }
      46                 :            : 
      47                 :            : }
      48                 :            : 
      49                 :            : void
      50                 :         12 : initKeyring(config::ModuleCCSession& session) {
      51         [ +  + ]:         12 :     if (keyring) {
      52                 :            :         // We are already initialized
      53                 :         12 :         return;
      54                 :            :     }
      55         [ +  - ]:          9 :     LOG_DEBUG(logger, DBG_TRACE_BASIC, SRVCOMM_KEYS_INIT);
      56         [ +  - ]:          9 :     session.addRemoteConfig("tsig_keys", updateKeyring, false);
      57                 :            : }
      58                 :            : 
      59                 :            : void
      60                 :         12 : deinitKeyring(config::ModuleCCSession& session) {
      61         [ +  + ]:         12 :     if (!keyring) {
      62                 :            :         // Not initialized, ignore it
      63                 :         12 :         return;
      64                 :            :     }
      65         [ +  - ]:          9 :     LOG_DEBUG(logger, DBG_TRACE_BASIC, SRVCOMM_KEYS_DEINIT);
      66                 :            :     keyring.reset();
      67         [ +  - ]:          9 :     session.removeRemoteConfig("tsig_keys");
      68                 :            : }
      69                 :            : 
      70                 :            : }
      71                 :          5 : }

Generated by: LCOV version 1.9