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@
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))
# 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 $<
{ 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
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
# 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
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
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)
# 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
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.
#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"
%}
};
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);
}
%}
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);
}
%}
%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);
}
%}
%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;
}
%}
};
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 {
%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]);
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)))
#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)
{
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");
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");
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)
{
}
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");
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;
}
{
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())
{
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));
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);
}
}
/**
-* 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,
#include <Python.h>
struct PyObject;
+#if S_SPLINT_S
+typedef struct PyObject PyObject;
+#endif
/**
* Global state for the module.
* 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) */