]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
python module compiles.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Wed, 25 Mar 2009 16:20:34 +0000 (16:20 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Wed, 25 Mar 2009 16:20:34 +0000 (16:20 +0000)
git-svn-id: file:///svn/unbound/trunk@1557 be551aaa-1e26-0410-a405-d3ace91eadb9

Makefile.in
configure
configure.ac
doc/Changelog
pythonmod/interface.i
pythonmod/pythonmod.c
pythonmod/pythonmod.h
pythonmod/pythonmod_utils.c

index daac35d5f12449c77f3c8b34ba5531c448f3865a..867535bf54156ada5119aa282c4540b43fe0e579 100644 (file)
@@ -39,7 +39,9 @@ configfile=@ub_conf_file@
 UNBOUND_RUN_DIR=@UNBOUND_RUN_DIR@
 CHECKLOCK_SRC=@CHECKLOCK_SRC@
 UB_ON_WINDOWS=@UB_ON_WINDOWS@
+WITH_PYTHONMODULE=@WITH_PYTHONMODULE@
 
+SWIG=@SWIG@
 YACC=@YACC@
 LEX=@LEX@
 CC=@CC@
@@ -68,11 +70,14 @@ LINTFLAGS=+quiet -weak -warnposix -unrecog -Din_addr_t=uint32_t -Du_int=unsigned
 LINTFLAGS+="-DBN_ULONG=unsigned long" -Dkrb5_int32=int "-Dkrb5_ui_4=unsigned int" -DPQ_64BIT=uint64_t -DRC4_INT=unsigned
 
 INSTALL=$(srcdir)/install-sh
+ifeq "$(WITH_PYTHONMODULE)" "yes"
+PYTHONMOD_SRC=$(srcdir)/pythonmod/*.c
+endif
 
 COMMON_SRC=$(patsubst $(srcdir)/%,%, $(wildcard $(srcdir)/services/*.c \
        $(srcdir)/services/cache/*.c $(srcdir)/util/*.c \
        $(srcdir)/util/data/*.c $(srcdir)/util/storage/*.c \
-       $(srcdir)/iterator/*.c $(srcdir)/validator/*.c)) \
+       $(srcdir)/iterator/*.c $(srcdir)/validator/*.c $(PYTHONMOD_SRC))) \
        util/configparser.c util/configlexer.c $(CHECKLOCK_SRC)
 COMMON_OBJ=$(addprefix $(BUILD),$(COMMON_SRC:.c=.lo))
 COMPAT_OBJ=$(addprefix $(BUILD)compat/,$(LIBOBJS:.o=.lo))
@@ -272,6 +277,13 @@ unbound-control-setup:     $(srcdir)/smallapp/unbound-control-setup.sh
 #      cp $(ldnsdir)/examples/ldns-testpkts.c testcode/ldns-testpkts.c
 #      cp $(ldnsdir)/examples/ldns-testpkts.h testcode/ldns-testpkts.h
 
+ifeq "$(WITH_PYTHONMODULE)" "yes"
+pythonmod/pythonmod.c: pythonmod/interface.h
+%.h:   $(srcdir)/%.i $(srcdir)/config.h
+       $(INFO) Swig $<
+       $Q$(SWIG) $(CPPFLAGS) -o $@ -python $<
+endif
+
 util/config_file.c:    util/configparser.h
 util/configlexer.c:  $(srcdir)/util/configlexer.lex util/configparser.h
        $(INFO) Lex $<
index bdb0d5304167fc4006bb475e38a84c07443f43be..c1e6c8eb0912a2e9a612d2cca235dcb9f680885e 100755 (executable)
--- a/configure
+++ b/configure
@@ -22199,11 +22199,13 @@ echo "$as_me: WARNING: cannot determine SWIG version" >&2;}
 
       { echo "$as_me:$LINENO: checking SWIG" >&5
 echo $ECHO_N "checking SWIG... $ECHO_C" >&6; }
-      if test -z SWIG; then
+      if test -z "$SWIG"; then
          { echo "$as_me:$LINENO: result: failed" >&5
 echo "${ECHO_T}failed" >&6; }
          swig=""
 
+         ub_with_pyunbound=no
+         ub_with_pythonmod=no
       else
 
 cat >>confdefs.h <<\_ACEOF
@@ -22212,17 +22214,12 @@ _ACEOF
 
          swig="$SWIG"
 
-         { echo "$as_me:$LINENO: result: done" >&5
-echo "${ECHO_T}done" >&6; }
-      fi
-
-      # If have Python & SWIG
-      if test ! -z "SWIG"; then
+         { echo "$as_me:$LINENO: result: present" >&5
+echo "${ECHO_T}present" >&6; }
 
+         # If have Python & SWIG
          # Declare PythonMod
          if test x_$ub_with_pythonmod != x_no; then
-            { echo "$as_me:$LINENO: result: Will build Python module." >&5
-echo "${ECHO_T}Will build Python module." >&6; }
 
 cat >>confdefs.h <<\_ACEOF
 #define WITH_PYTHONMODULE 1
@@ -22234,8 +22231,6 @@ _ACEOF
 
          # Declare PyUnbound
          if test x_$ub_with_pyunbound != x_no; then
-            { echo "$as_me:$LINENO: result: Will build PyUnbound." >&5
-echo "${ECHO_T}Will build PyUnbound." >&6; }
 
 cat >>confdefs.h <<\_ACEOF
 #define WITH_PYUNBOUND 1
@@ -22244,15 +22239,10 @@ _ACEOF
             WITH_PYUNBOUND=yes
 
          fi
-      else
-         { echo "$as_me:$LINENO: result: SWIG libraries not found" >&5
-echo "${ECHO_T}SWIG libraries not found" >&6; }
-         ub_with_pyunbound=no
-         ub_with_pythonmod=no
       fi
    else
-      { echo "$as_me:$LINENO: result: Python libraries not found" >&5
-echo "${ECHO_T}Python libraries not found" >&6; }
+      { echo "$as_me:$LINENO: result: Python libraries not found, won't build PythonMod or PyUnbound" >&5
+echo "${ECHO_T}Python libraries not found, won't build PythonMod or PyUnbound" >&6; }
       ub_with_pyunbound=no
       ub_with_pythonmod=no
    fi
index f5f7d13711d26e6efd9f959d3aaafcce3c52f281..04fb9bc0028c26ad6180c6350205b5352ed5daf0 100644 (file)
@@ -250,21 +250,19 @@ if test x_$ub_test_python != x_no; then
       ub_have_swig=no
       AC_PROG_SWIG
       AC_MSG_CHECKING(SWIG)
-      if test -z SWIG; then
+      if test -z "$SWIG"; then
          AC_MSG_RESULT(failed, won't build Python module and PyUnbound)
          AC_SUBST(swig, "")
+         ub_with_pyunbound=no
+         ub_with_pythonmod=no
       else
          AC_DEFINE(HAVE_SWIG, 1, [Define if you have Swig libraries and header files.])
          AC_SUBST(swig, "$SWIG")
-         AC_MSG_RESULT(done)
-      fi
-
-      # If have Python & SWIG
-      if test ! -z "SWIG"; then
+         AC_MSG_RESULT(present)
 
+         # If have Python & SWIG
          # Declare PythonMod
          if test x_$ub_with_pythonmod != x_no; then
-            AC_MSG_RESULT(Will build Python module.)
             AC_DEFINE(WITH_PYTHONMODULE, 1, [Define if you want Python module.])
             WITH_PYTHONMODULE=yes
             AC_SUBST(WITH_PYTHONMODULE)
@@ -272,18 +270,13 @@ if test x_$ub_test_python != x_no; then
 
          # Declare PyUnbound
          if test x_$ub_with_pyunbound != x_no; then
-            AC_MSG_RESULT(Will build PyUnbound.)
             AC_DEFINE(WITH_PYUNBOUND, 1, [Define if you want PyUnbound.])
             WITH_PYUNBOUND=yes
             AC_SUBST(WITH_PYUNBOUND)
          fi
-      else
-         AC_MSG_RESULT(SWIG libraries not found, won't build PythonMod or PyUnbound)
-         ub_with_pyunbound=no
-         ub_with_pythonmod=no
       fi
    else
-      AC_MSG_RESULT(Python libraries not found, won't build PythonMod or PyUnbound)
+      AC_MSG_RESULT([Python libraries not found, won't build PythonMod or PyUnbound])
       ub_with_pyunbound=no
       ub_with_pythonmod=no
    fi
index ac8e92cfa7ba33cd845bdbab7a560ffec8e61282..35d4dc72f5350f2a10164b6001c50a02d6297f7a 100644 (file)
@@ -1,6 +1,7 @@
 25 March 2009: Wouter
        - initial import of the python contribution from Zdenek Vasicek and
          Marek Vavrusa.
+       - pythonmod in Makefile; changes to remove warnings/errors for 1.3.0.
 
 24 March 2009: Wouter
        - more neat configure.ac. Removed duplicate config.h includes.
index 399cbd59abe10bacff96eccd6863e5f2a72bf5a7..e8eabaf9a3e6ce6c6f6a6486965c881022981b7d 100644 (file)
@@ -16,6 +16,7 @@
    #include "util/config_file.h"
    #include "util/data/msgreply.h"
    #include "util/data/packed_rrset.h"
+   #include "util/data/dname.h"
    #include "util/storage/lruhash.h"
    #include "services/cache/dns.h"
 %}
@@ -137,11 +138,11 @@ struct query_info {
    };
 
    PyObject* _get_qname(struct query_info* q) {
-      return PyString_FromStringAndSize(q->qname, q->qname_len);
+      return PyString_FromStringAndSize((char*)q->qname, q->qname_len);
    } 
 
    PyObject* _get_qname_components(struct query_info* q) {
-      return GetNameAsLabelList(q->qname, q->qname_len);
+      return GetNameAsLabelList((const char*)q->qname, q->qname_len);
    }
 %}
 
@@ -149,7 +150,7 @@ struct query_info {
    PyObject* dnameAsStr(const char* dname) {
        char buf[LDNS_MAX_DOMAINLEN+1];
        buf[0] = '\0';
-       dname_str(dname, buf);
+       dname_str((uint8_t*)dname, buf);
        return PyString_FromString(buf);
    }
 %}
@@ -199,10 +200,10 @@ uint16_t ntohs(uint16_t netshort);
 
 %inline %{
    PyObject* _get_dname(struct packed_rrset_key* k) {
-      return PyString_FromStringAndSize(k->dname, k->dname_len);
+      return PyString_FromStringAndSize((char*)k->dname, k->dname_len);
    } 
    PyObject* _get_dname_components(struct packed_rrset_key* k) {
-      return GetNameAsLabelList(k->dname, k->dname_len);
+      return GetNameAsLabelList((char*)k->dname, k->dname_len);
    }
 %}
 
@@ -286,23 +287,28 @@ struct packed_rrset_data {
 
 %inline %{
    PyObject* _get_data_rr_len(struct packed_rrset_data* d, int idx) {
-     if ((d != NULL) && (idx >= 0) && (idx < (d->count+d->rrsig_count))) 
+     if ((d != NULL) && (idx >= 0) && 
+             ((size_t)idx < (d->count+d->rrsig_count))) 
         return PyInt_FromLong(d->rr_len[idx]);
      return Py_None;
    }
    void _set_data_rr_ttl(struct packed_rrset_data* d, int idx, uint32_t ttl)
    {
-     if ((d != NULL) && (idx >= 0) && (idx < (d->count+d->rrsig_count))) 
+     if ((d != NULL) && (idx >= 0) && 
+             ((size_t)idx < (d->count+d->rrsig_count))) 
         d->rr_ttl[idx] = ttl;
    }
    PyObject* _get_data_rr_ttl(struct packed_rrset_data* d, int idx) {
-     if ((d != NULL) && (idx >= 0) && (idx < (d->count+d->rrsig_count))) 
+     if ((d != NULL) && (idx >= 0) && 
+             ((size_t)idx < (d->count+d->rrsig_count))) 
         return PyInt_FromLong(d->rr_ttl[idx]);
      return Py_None;
    }
    PyObject* _get_data_rr_data(struct packed_rrset_data* d, int idx) {
-     if ((d != NULL) && (idx >= 0) && (idx < (d->count+d->rrsig_count))) 
-        return PyString_FromStringAndSize(d->rr_data[idx],d->rr_len[idx]);
+     if ((d != NULL) && (idx >= 0) && 
+             ((size_t)idx < (d->count+d->rrsig_count))) 
+        return PyString_FromStringAndSize((char*)d->rr_data[idx],
+                d->rr_len[idx]);
      return Py_None;
    }
 %}
@@ -346,8 +352,8 @@ struct reply_info {
 };
 
 struct rrset_ref {
-       struct ub_packed_rrset_key* key;
-       rrset_id_t id;
+   struct ub_packed_rrset_key* key;
+   rrset_id_t id;
 };
 
 struct dns_msg {
@@ -369,13 +375,13 @@ struct dns_msg {
 
 %inline %{
    struct ub_packed_rrset_key* _rrset_rrsets_get(struct reply_info* r, int idx) {
-     if ((r != NULL) && (idx >= 0) && (idx < r->rrset_count))
+     if ((r != NULL) && (idx >= 0) && ((size_t)idx < r->rrset_count))
         return r->rrsets[idx];
      return NULL;
    }
 
    struct rrset_ref* _rrset_ref_get(struct reply_info* r, int idx) {
-     if ((r != NULL) && (idx >= 0) && (idx < r->rrset_count)) {
+     if ((r != NULL) && (idx >= 0) && ((size_t)idx < r->rrset_count)) {
 //printf("_rrset_ref_get: %lX key:%lX\n", r->ref + idx, r->ref[idx].key);
              return &(r->ref[idx]);
 //        return &(r->ref[idx]);
@@ -705,9 +711,7 @@ int set_return_msg(struct module_qstate* qstate,
      ldns_pkt* pkt = 0;
      ldns_status status;
      ldns_rr_list* rr_list1 = 0,*rr_list2 = 0,*rr_list3 = 0,*rr_list4 = 0;
-        ldns_buffer *qb = 0;
-     struct dns_msg* m = 0;
-        struct msg_parse* p = 0;
+     ldns_buffer *qb = 0;
      int res = 1;
      
      if ((!checkList(question)) || (!checkList(answer)) || (!checkList(authority)) || (!checkList(additional)))
index 10068aeb3a07e464276489134873b84282d21791..1bffae7f890c5feb92e75074d1c6904dccfb7cb3 100644 (file)
 #include "pythonmod_utils.h"
 #include <Python.h>
 
-// Generated
+/* Generated */
 #include "pythonmod/interface.h"
 
 int pythonmod_init(struct module_env* env, int id)
 {
-   // Initialize module
+   /* Initialize module */
+   FILE* script_py = NULL;
+   PyObject* py_cfg, *res;
    struct pythonmod_env* pe = (struct pythonmod_env*)calloc(1, sizeof(struct pythonmod_env));
    if (!pe) 
    {
@@ -60,14 +62,14 @@ int pythonmod_init(struct module_env* env, int id)
    pe->data = NULL;
    pe->qstate = NULL;
 
-   // Initialize module
+   /* Initialize module */
    if ((pe->fname = env->cfg->python_script) == NULL) 
    {
       log_err("pythonmod: no script given.");
       return 0;
    }
 
-   // Initialize Python libraries
+   /* Initialize Python libraries */
    if (!Py_IsInitialized()) 
    {
       Py_SetProgramName("unbound");
@@ -78,7 +80,7 @@ int pythonmod_init(struct module_env* env, int id)
       SWIG_init();
    }
 
-   // Initialize Python
+   /* Initialize Python */
    PyRun_SimpleString("import sys \n");
    PyRun_SimpleString("sys.path.append('.') \n");
    PyRun_SimpleString("sys.path.append('"RUN_DIR"') \n");
@@ -88,22 +90,21 @@ int pythonmod_init(struct module_env* env, int id)
       return 0;
    }
 
-   // Check Python file load
-   FILE* script_py = NULL;
+   /* Check Python file load */
    if ((script_py = fopen(pe->fname, "r")) == NULL) 
    {
       log_err("pythonmod: can't open file %s for reading", pe->fname);
       return 0;
    }
 
-   // Load file
+   /* Load file */
    pe->module = PyImport_AddModule("__main__");
    pe->dict = PyModule_GetDict(pe->module);
    pe->data = Py_None;
    Py_INCREF(pe->data);
    PyModule_AddObject(pe->module, "mod_env", pe->data);
 
-   //TODO: deallocation of pe->... if an error occurs
+   /* TODO: deallocation of pe->... if an error occurs */
   
    if (PyRun_SimpleFile(script_py, pe->fname) < 0) 
    {
@@ -135,8 +136,8 @@ int pythonmod_init(struct module_env* env, int id)
    }
 
    PyEval_AcquireLock();
-   PyObject* py_cfg = SWIG_NewPointerObj((void*) env->cfg, SWIGTYPE_p_config_file, 0);
-   PyObject* res = PyObject_CallFunction(pe->func_init, "iO", id, py_cfg);
+   py_cfg = SWIG_NewPointerObj((void*) env->cfg, SWIGTYPE_p_config_file, 0);
+   res = PyObject_CallFunction(pe->func_init, "iO", id, py_cfg);
    if (PyErr_Occurred()) 
    {
       log_err("pythonmod: Exception occurred in function init");
@@ -156,25 +157,27 @@ void pythonmod_deinit(struct module_env* env, int id)
    if(pe == NULL)
       return;
 
-   // Free Python resources
+   /* Free Python resources */
    if(pe->module != NULL)
    {
-      // Deinit module
+      PyObject* res;
+
+      /* Deinit module */
       PyEval_AcquireLock();
-      PyObject* res = PyObject_CallFunction(pe->func_deinit, "i", id);
+      res = PyObject_CallFunction(pe->func_deinit, "i", id);
       if (PyErr_Occurred()) {
          log_err("pythonmod: Exception occurred in function deinit");
          PyErr_Print();
       }
-      // Free result if any
+      /* Free result if any */
       Py_XDECREF(res);
-      // Free shared data if any
+      /* Free shared data if any */
       Py_XDECREF(pe->data);
 
       Py_Finalize();
    }
 
-   // Module is deallocated in Python
+   /* Module is deallocated in Python */
    env->modinfo[id] = NULL;
 }
 
@@ -182,15 +185,17 @@ void pythonmod_inform_super(struct module_qstate* qstate, int id, struct module_
 {
    struct pythonmod_env* pe = (struct pythonmod_env*)qstate->env->modinfo[id];
    struct pythonmod_qstate* pq = (struct pythonmod_qstate*)qstate->minfo[id];
+   PyObject* py_qstate, *py_sqstate, *res;
 
    log_query_info(VERB_ALGO, "pythonmod: inform_super, sub is", &qstate->qinfo);
    log_query_info(VERB_ALGO, "super is", &super->qinfo);
 
-   PyObject* py_qstate = SWIG_NewPointerObj((void*) qstate, SWIGTYPE_p_module_qstate, 0);
-   PyObject* py_sqstate = SWIG_NewPointerObj((void*) super, SWIGTYPE_p_module_qstate, 0);
+   py_qstate = SWIG_NewPointerObj((void*) qstate, SWIGTYPE_p_module_qstate, 0);
+   py_sqstate = SWIG_NewPointerObj((void*) super, SWIGTYPE_p_module_qstate, 0);
 
    PyEval_AcquireLock();
-   PyObject* res = PyObject_CallFunction(pe->func_inform, "iOOO", id, py_qstate, py_sqstate, pq->data);
+   res = PyObject_CallFunction(pe->func_inform, "iOOO", id, py_qstate, 
+       py_sqstate, pq->data);
 
    if (PyErr_Occurred()) 
    {
@@ -211,27 +216,30 @@ void pythonmod_inform_super(struct module_qstate* qstate, int id, struct module_
    PyEval_ReleaseLock();
 }
 
-void pythonmod_operate(struct module_qstate* qstate, enum module_ev event, int id, struct outbound_entry* outbound)
+void pythonmod_operate(struct module_qstate* qstate, enum module_ev event, 
+       int id, struct outbound_entry* ATTR_UNUSED(outbound))
 {
    struct pythonmod_env* pe = (struct pythonmod_env*)qstate->env->modinfo[id];
    struct pythonmod_qstate* pq = (struct pythonmod_qstate*)qstate->minfo[id];
+   PyObject* py_qstate, *res;
 
    if ( pq == NULL)
    { 
-      // create qstate
+      /* create qstate */
       pq = qstate->minfo[id] = malloc(sizeof(struct pythonmod_qstate));
       
-      //Initialize per query data
+      /* Initialize per query data */
       pq->data = Py_None;
       Py_INCREF(pq->data);
    }
 
-   // Lock Python
+   /* Lock Python */
    PyEval_AcquireLock();
 
-   // Call operate
-   PyObject* py_qstate = SWIG_NewPointerObj((void*) qstate, SWIGTYPE_p_module_qstate, 0);
-   PyObject* res = PyObject_CallFunction(pe->func_operate, "iiOO", id, (int) event, py_qstate, pq->data);
+   /* Call operate */
+   py_qstate = SWIG_NewPointerObj((void*) qstate, SWIGTYPE_p_module_qstate, 0);
+   res = PyObject_CallFunction(pe->func_operate, "iiOO", id, (int) event, 
+       py_qstate, pq->data);
    if (PyErr_Occurred()) 
    {
       log_err("pythonmod: Exception occurred in function operate, event: %s", strmodulevent(event));
@@ -246,22 +254,22 @@ void pythonmod_operate(struct module_qstate* qstate, enum module_ev event, int i
    Py_XDECREF(res);
    Py_XDECREF(py_qstate);
 
-   // Unlock Python
+   /* Unlock Python */
    PyEval_ReleaseLock();
-
 }
 
 void pythonmod_clear(struct module_qstate* qstate, int id)
 {
+   struct pythonmod_qstate* pq;
    if (qstate == NULL)
       return;
 
-   struct pythonmod_qstate* pq = qstate->minfo[id];
+   pq = (struct pythonmod_qstate*)qstate->minfo[id];
    log_info("pythonmod: clear, id: %d, pq:%lX", id, (unsigned long int)pq);
    if(pq != NULL)
    {
       Py_DECREF(pq->data);
-      // Free qstate
+      /* Free qstate */
       free(pq);
    }
 
@@ -278,8 +286,8 @@ size_t pythonmod_get_mem(struct module_env* env, int id)
 }
 
 /**
-* The module function block 
-*/
+ * The module function block 
+ */
 static struct module_func_block pythonmod_block = {
    "python",
    &pythonmod_init, &pythonmod_deinit, &pythonmod_operate, &pythonmod_inform_super, 
index a394e5960f56c62c07006235257fbfbb4627fcc0..7d0aed7fc36cb7b575c24be21bf5d58f005d2cd6 100644 (file)
@@ -40,6 +40,9 @@
 #include <Python.h>
 
 struct PyObject;
+#if S_SPLINT_S
+typedef struct PyObject PyObject;
+#endif
 
 /**
  * Global state for the module. 
index 6ad6fde18820e7e9530d73ca59f6a7f45c56d891..08b311e0770fd9e075005586312d4d93c5d416c4 100644 (file)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
+#include "config.h"
 #include "util/module.h"
 #include "util/net_help.h"
 #include "services/cache/dns.h"
 #include "util/data/msgparse.h"
 #include "util/data/msgreply.h"
+#include "util/storage/slabhash.h"
+#include "util/regional.h"
 #include <Python.h>
 
 /** Store the reply_info and query_info pair in message cache (qstate->msg_cache) */