LCOV - code coverage report
Current view: top level - python/isc/acl - dns.cc (source / functions) Hit Total Coverage
Test: report.info Lines: 21 28 75.0 %
Date: 2012-05-15 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 13 36 36.1 %

           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 <Python.h>
      16                 :            : 
      17                 :            : #include <stdexcept>
      18                 :            : #include <boost/shared_ptr.hpp>
      19                 :            : 
      20                 :            : #include <util/python/pycppwrapper_util.h>
      21                 :            : 
      22                 :            : #include <cc/data.h>
      23                 :            : 
      24                 :            : #include <acl/acl.h>
      25                 :            : #include <acl/dns.h>
      26                 :            : 
      27                 :            : #include "dns.h"
      28                 :            : #include "dns_requestcontext_python.h"
      29                 :            : #include "dns_requestacl_python.h"
      30                 :            : #include "dns_requestloader_python.h"
      31                 :            : 
      32                 :            : using namespace std;
      33                 :            : using boost::shared_ptr;
      34                 :            : using namespace isc::util::python;
      35                 :            : using namespace isc::data;
      36                 :            : using namespace isc::acl::dns;
      37                 :            : using namespace isc::acl::dns::python;
      38                 :            : 
      39                 :            : #include "dnsacl_inc.cc"
      40                 :            : 
      41                 :            : namespace {
      42                 :            : // This is a Python binding object corresponding to the singleton loader used
      43                 :            : // in the C++ version of the library.
      44                 :            : // We can define it as a pure object rather than through an accessor function,
      45                 :            : // because in Python we can ensure it has been created and initialized
      46                 :            : // in the module initializer by the time it's actually used.
      47                 :            : s_RequestLoader* po_REQUEST_LOADER;
      48                 :            : 
      49                 :            : PyMethodDef methods[] = {
      50                 :            :     { NULL, NULL, 0, NULL }
      51                 :            : };
      52                 :            : 
      53                 :            : PyModuleDef dnsacl = {
      54                 :            :     { PyObject_HEAD_INIT(NULL) NULL, 0, NULL},
      55                 :            :     "isc.acl._dns",
      56                 :            :     dnsacl_doc,
      57                 :            :     -1,
      58                 :            :     methods,
      59                 :            :     NULL,
      60                 :            :     NULL,
      61                 :            :     NULL,
      62                 :            :     NULL
      63                 :            : };
      64                 :            : } // end of unnamed namespace
      65                 :            : 
      66                 :            : namespace isc {
      67                 :            : namespace acl {
      68                 :            : namespace dns {
      69                 :            : namespace python {
      70                 :            : PyObject*
      71                 :         65 : getACLException(const char* ex_name) {
      72                 :         65 :     PyObject* ex_obj = NULL;
      73                 :            : 
      74                 :         65 :     PyObject* acl_module = PyImport_AddModule("isc.acl.acl");
      75         [ +  - ]:         65 :     if (acl_module != NULL) {
      76                 :         65 :         PyObject* acl_dict = PyModule_GetDict(acl_module);
      77         [ +  - ]:         65 :         if (acl_dict != NULL) {
      78                 :         65 :             ex_obj = PyDict_GetItemString(acl_dict, ex_name);
      79                 :            :         }
      80                 :            :     }
      81                 :            : 
      82         [ -  + ]:         65 :     if (ex_obj == NULL) {
      83                 :          0 :         ex_obj = PyExc_RuntimeError;
      84                 :            :     }
      85                 :         65 :     return (ex_obj);
      86                 :            : }
      87                 :            : }
      88                 :            : }
      89                 :            : }
      90                 :            : }
      91                 :            : 
      92                 :            : PyMODINIT_FUNC
      93                 :          2 : PyInit__dns(void) {
      94                 :          2 :     PyObject* mod = PyModule_Create(&dnsacl);
      95         [ +  - ]:          2 :     if (mod == NULL) {
      96                 :            :         return (NULL);
      97                 :            :     }
      98                 :            : 
      99         [ -  + ]:          2 :     if (!initModulePart_RequestContext(mod)) {
     100         [ #  # ]:          0 :         Py_DECREF(mod);
     101                 :            :         return (NULL);
     102                 :            :     }
     103         [ -  + ]:          2 :     if (!initModulePart_RequestACL(mod)) {
     104         [ #  # ]:          0 :         Py_DECREF(mod);
     105                 :            :         return (NULL);
     106                 :            :     }
     107         [ -  + ]:          2 :     if (!initModulePart_RequestLoader(mod)) {
     108         [ #  # ]:          0 :         Py_DECREF(mod);
     109                 :            :         return (NULL);
     110                 :            :     }
     111                 :            : 
     112                 :            :     // Module constants
     113                 :            :     try {
     114         [ +  - ]:          2 :         if (po_REQUEST_LOADER == NULL) {
     115                 :            :             po_REQUEST_LOADER = static_cast<s_RequestLoader*>(
     116         [ +  - ]:          2 :                 requestloader_type.tp_alloc(&requestloader_type, 0));
     117                 :            :         }
     118         [ +  - ]:          2 :         if (po_REQUEST_LOADER != NULL) {
     119                 :            :             // We gain and keep our own reference to the singleton object
     120                 :            :             // for the same reason as that for exception objects (see comments
     121                 :            :             // in pycppwrapper_util for more details).  Note also that we don't
     122                 :            :             // bother to release the reference even if exception is thrown
     123                 :            :             // below (in fact, we cannot delete the singleton loader).
     124         [ +  - ]:          2 :             po_REQUEST_LOADER->cppobj = &getRequestLoader();
     125                 :          2 :             Py_INCREF(po_REQUEST_LOADER);
     126                 :            :         }
     127                 :            :         PyObjectContainer(po_REQUEST_LOADER).installToModule(mod,
     128 [ +  - ][ +  - ]:          2 :                                                              "REQUEST_LOADER");
     129                 :          0 :     } catch (...) {
     130 [ #  # ][ #  # ]:          0 :         Py_DECREF(mod);
     131                 :            :         return (NULL);
     132                 :            :     }
     133                 :            : 
     134                 :            :     return (mod);
     135                 :          0 : }

Generated by: LCOV version 1.9