LCOV - code coverage report
Current view: top level - dns - rrttl.cc (source / functions) Hit Total Coverage
Test: report.info Lines: 26 26 100.0 %
Date: 2012-05-15 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 18 77.8 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2010  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 <stdint.h>
      16                 :            : 
      17                 :            : #include <sstream>
      18                 :            : #include <ostream>
      19                 :            : 
      20                 :            : #include <util/buffer.h>
      21                 :            : #include <dns/messagerenderer.h>
      22                 :            : #include <dns/rrttl.h>
      23                 :            : 
      24                 :            : using namespace std;
      25                 :            : using namespace isc::dns;
      26                 :            : using namespace isc::util;
      27                 :            : 
      28                 :            : namespace isc {
      29                 :            : namespace dns {
      30                 :            : 
      31                 :      14208 : RRTTL::RRTTL(const string& ttlstr) {
      32                 :            :     // Some systems (at least gcc-4.4) flow negative values over into
      33                 :            :     // unsigned integer, where older systems failed to parse. We want
      34                 :            :     // that failure here, so we extract into int64 and check the value
      35                 :            :     int64_t val;
      36                 :            : 
      37                 :      28416 :     istringstream iss(ttlstr);
      38                 :      14208 :     iss >> dec >> val;
      39 [ +  + ][ +  + ]:      14208 :     if (iss.rdstate() == ios::eofbit && val >= 0 && val <= 0xffffffff) {
         [ +  + ][ +  + ]
      40                 :      14195 :         ttlval_ = static_cast<uint32_t>(val);
      41                 :            :     } else {
      42 [ +  - ][ +  - ]:         26 :         isc_throw(InvalidRRTTL, "invalid TTL");
      43                 :            :     }
      44                 :      14195 : }
      45                 :            : 
      46                 :          4 : RRTTL::RRTTL(InputBuffer& buffer) {
      47         [ +  + ]:          4 :     if (buffer.getLength() - buffer.getPosition() < sizeof(uint32_t)) {
      48         [ +  - ]:          4 :         isc_throw(IncompleteRRTTL, "incomplete wire-format TTL value");
      49                 :            :     }
      50                 :          2 :     ttlval_ = buffer.readUint32();
      51                 :          2 : }
      52                 :            : 
      53                 :            : const string
      54                 :       6702 : RRTTL::toText() const {
      55                 :      13404 :     ostringstream oss;
      56                 :       6702 :     oss << ttlval_;
      57                 :       6702 :     return (oss.str());
      58                 :            : }
      59                 :            : 
      60                 :            : void
      61                 :         75 : RRTTL::toWire(OutputBuffer& buffer) const {
      62                 :         75 :     buffer.writeUint32(ttlval_);
      63                 :         75 : }
      64                 :            : 
      65                 :            : void
      66                 :        646 : RRTTL::toWire(AbstractMessageRenderer& renderer) const {
      67                 :        646 :     renderer.writeUint32(ttlval_);
      68                 :        646 : }
      69                 :            : 
      70                 :            : ostream&
      71                 :         69 : operator<<(ostream& os, const RRTTL& rrttl) {
      72         [ +  - ]:         69 :     os << rrttl.toText();
      73                 :         69 :     return (os);
      74                 :            : }
      75                 :            : }
      76                 :      21477 : }

Generated by: LCOV version 1.9