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; PyGILState_STATE gil = PyGILState_Ensure(); if ( pq == NULL) { /* create qstate */ pq = qstate->minfo[id] = malloc(sizeof(struct pythonmod_qstate)); /* Initialize per query data */ pq->data = Py_None; Py_INCREF(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)); log_py_err(); qstate->ext_state[id] = module_error; } else if ((res == NULL) || (!PyObject_IsTrue(res))) { log_err("pythonmod: python returned bad code, event: %s", strmodulevent(event)); qstate->ext_state[id] = module_error; } Py_XDECREF(res); Py_XDECREF(py_qstate); PyGILState_Release(gil); }
void cachedb_operate(struct module_qstate* qstate, enum module_ev event, int id, struct outbound_entry* outbound) { struct cachedb_env* ie = (struct cachedb_env*)qstate->env->modinfo[id]; struct cachedb_qstate* iq = (struct cachedb_qstate*)qstate->minfo[id]; verbose(VERB_QUERY, "cachedb[module %d] operate: extstate:%s event:%s", id, strextstate(qstate->ext_state[id]), strmodulevent(event)); if(iq) log_query_info(VERB_QUERY, "cachedb operate: query", &qstate->qinfo); /* perform cachedb state machine */ if((event == module_event_new || event == module_event_pass) && iq == NULL) { if(!cachedb_new(qstate, id)) { (void)error_response(qstate, id, LDNS_RCODE_SERVFAIL); return; } iq = (struct cachedb_qstate*)qstate->minfo[id]; } if(iq && (event == module_event_pass || event == module_event_new)) { cachedb_handle_query(qstate, iq, ie, id); return; } if(iq && (event == module_event_moddone)) { cachedb_handle_response(qstate, iq, ie, id); return; } if(iq && outbound) { /* cachedb does not need to process responses at this time * ignore it. cachedb_process_response(qstate, iq, ie, id, outbound, event); */ return; } if(event == module_event_error) { verbose(VERB_ALGO, "got called with event error, giving up"); (void)error_response(qstate, id, LDNS_RCODE_SERVFAIL); return; } if(!iq && (event == module_event_moddone)) { /* during priming, module done but we never started */ qstate->ext_state[id] = module_finished; return; } log_err("bad event for cachedb"); (void)error_response(qstate, id, LDNS_RCODE_SERVFAIL); }