diff options
Diffstat (limited to 'pythonmod')
| -rw-r--r-- | pythonmod/interface.i | 24 | ||||
| -rw-r--r-- | pythonmod/pythonmod.h | 4 | ||||
| -rw-r--r-- | pythonmod/pythonmod_utils.c | 1 | ||||
| -rw-r--r-- | pythonmod/pythonmod_utils.h | 3 |
4 files changed, 26 insertions, 6 deletions
diff --git a/pythonmod/interface.i b/pythonmod/interface.i index cbee4f714764..5dae04aa404b 100644 --- a/pythonmod/interface.i +++ b/pythonmod/interface.i @@ -20,6 +20,7 @@ * called to perform operations on queries. */ #include <sys/types.h> + #include <time.h> #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif @@ -696,6 +697,8 @@ struct edns_data { /* ************************************************************************************ * Structure module_env * ************************************************************************************ */ +%rename(_now) module_env::now; +%rename(_now_tv) module_env::now_tv; struct module_env { struct config_file* cfg; struct slabhash* msg_cache; @@ -739,6 +742,19 @@ struct module_env { size_t edns_known_options_num; }; +%inline %{ + PyObject* _module_env_now_get(struct module_env* env) { + double ts = env->now_tv->tv_sec + env->now_tv->tv_usec / 1e6; + return PyFloat_FromDouble(ts); + } +%} +%extend module_env { + %pythoncode %{ + def _now_get(self): return _module_env_now_get(self) + now = property(_now_get) + %} +} + /* ************************************************************************************ * Structure module_qstate * ************************************************************************************ */ @@ -1525,13 +1541,14 @@ int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len, int python_inplace_cb_reply_generic(struct query_info* qinfo, struct module_qstate* qstate, struct reply_info* rep, int rcode, struct edns_data* edns, struct edns_option** opt_list_out, - struct comm_reply* repinfo, struct regional* region, int id, - void* python_callback) + struct comm_reply* repinfo, struct regional* region, + struct timeval* start_time, int id, void* python_callback) { PyObject *func, *py_edns, *py_qstate, *py_opt_list_out, *py_qinfo; PyObject *py_rep, *py_repinfo, *py_region; PyObject *py_args, *py_kwargs, *result; int res = 0; + double py_start_time = ((double)start_time->tv_sec) + ((double)start_time->tv_usec) / 1.0e6; PyGILState_STATE gstate = PyGILState_Ensure(); func = (PyObject *) python_callback; @@ -1546,7 +1563,8 @@ int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len, py_region = SWIG_NewPointerObj((void*) region, SWIGTYPE_p_regional, 0); py_args = Py_BuildValue("(OOOiOOO)", py_qinfo, py_qstate, py_rep, rcode, py_edns, py_opt_list_out, py_region); - py_kwargs = Py_BuildValue("{s:O}", "repinfo", py_repinfo); + py_kwargs = Py_BuildValue("{s:O,s:d}", "repinfo", py_repinfo, "start_time", + py_start_time); result = PyObject_Call(func, py_args, py_kwargs); Py_XDECREF(py_edns); Py_XDECREF(py_qstate); diff --git a/pythonmod/pythonmod.h b/pythonmod/pythonmod.h index ae8af27eb22b..26d74e09f42b 100644 --- a/pythonmod/pythonmod.h +++ b/pythonmod/pythonmod.h @@ -72,8 +72,8 @@ size_t pythonmod_get_mem(struct module_env* env, int id); int python_inplace_cb_reply_generic(struct query_info* qinfo, struct module_qstate* qstate, struct reply_info* rep, int rcode, struct edns_data* edns, struct edns_option** opt_list_out, - struct comm_reply* repinfo, struct regional* region, int id, - void* python_callback); + struct comm_reply* repinfo, struct regional* region, + struct timeval* start_time, int id, void* python_callback); /** Declared here for fptr_wlist access. The definition is in interface.i. */ int python_inplace_cb_query_generic( diff --git a/pythonmod/pythonmod_utils.c b/pythonmod/pythonmod_utils.c index 5d70f2b4bc04..9f7282540e77 100644 --- a/pythonmod/pythonmod_utils.c +++ b/pythonmod/pythonmod_utils.c @@ -39,6 +39,7 @@ * conversions. */ #include "config.h" +#include "pythonmod/pythonmod_utils.h" #include "util/module.h" #include "util/netevent.h" #include "util/net_help.h" diff --git a/pythonmod/pythonmod_utils.h b/pythonmod/pythonmod_utils.h index 768eb46de6ac..4ea86f9bee4c 100644 --- a/pythonmod/pythonmod_utils.h +++ b/pythonmod/pythonmod_utils.h @@ -43,6 +43,7 @@ #include "util/module.h" struct delegpt_addr; +struct sldns_buffer; /** * Store the reply_info and query_info pair in message cache (qstate->msg_cache) @@ -77,7 +78,7 @@ void invalidateQueryInCache(struct module_qstate* qstate, struct query_info* qin * @param pkt: a sldns_buffer which contains sldns_packet data * @return 0 on failure, out of memory or parse error. */ -int createResponse(struct module_qstate* qstate, sldns_buffer* pkt); +int createResponse(struct module_qstate* qstate, struct sldns_buffer* pkt); /** * Convert reply->addr to string |
