static void cert_query_cb(void *arg, int status, int timeouts, unsigned char *abuf, int alen) { Bincert *bincert = NULL; ProxyContext *proxy_context = arg; struct ares_txt_reply *txt_out; struct ares_txt_reply *txt_out_current; (void) timeouts; DNSCRYPT_PROXY_CERTS_UPDATE_RECEIVED(); if (status != ARES_SUCCESS || ares_parse_txt_reply(abuf, alen, &txt_out) != ARES_SUCCESS) { logger_noformat(proxy_context, LOG_ERR, "Unable to retrieve server certificates"); cert_reschedule_query_after_failure(proxy_context); DNSCRYPT_PROXY_CERTS_UPDATE_ERROR_COMMUNICATION(); return; } txt_out_current = txt_out; while (txt_out_current != NULL) { cert_open_bincert(proxy_context, (const SignedBincert *) txt_out_current->txt, txt_out_current->length, &bincert); txt_out_current = txt_out_current->next; } ares_free_data(txt_out); if (bincert == NULL) { logger_noformat(proxy_context, LOG_ERR, "No useable certificates found"); cert_reschedule_query_after_failure(proxy_context); DNSCRYPT_PROXY_CERTS_UPDATE_ERROR_NOCERTS(); return; } COMPILER_ASSERT(sizeof proxy_context->resolver_publickey == sizeof bincert->server_publickey); memcpy(proxy_context->resolver_publickey, bincert->server_publickey, sizeof proxy_context->resolver_publickey); COMPILER_ASSERT(sizeof proxy_context->dnscrypt_magic_query == sizeof bincert->magic_query); memcpy(proxy_context->dnscrypt_magic_query, bincert->magic_query, sizeof proxy_context->dnscrypt_magic_query); cert_print_server_key(proxy_context); dnscrypt_client_init_magic_query(&proxy_context->dnscrypt_client, bincert->magic_query); memset(bincert, 0, sizeof *bincert); free(bincert); dnscrypt_client_init_nmkey(&proxy_context->dnscrypt_client, proxy_context->resolver_publickey); dnscrypt_proxy_start_listeners(proxy_context); proxy_context->cert_updater.query_retry_step = 0U; cert_reschedule_query_after_success(proxy_context); DNSCRYPT_PROXY_CERTS_UPDATE_DONE((unsigned char *) proxy_context->resolver_publickey); }
static void query_txt_cb(void *arg, int status,int timeouts, unsigned char *answer_buf, int answer_len) { PyGILState_STATE gstate = PyGILState_Ensure(); int parse_status; struct ares_txt_reply *txt_reply, *txt_ptr; PyObject *dns_result, *errorno, *tmp, *result, *callback; txt_reply = NULL; callback = (PyObject *)arg; ASSERT(callback); if (status != ARES_SUCCESS) { errorno = PyInt_FromLong((long)status); dns_result = Py_None; Py_INCREF(Py_None); goto callback; } parse_status = ares_parse_txt_reply(answer_buf, answer_len, &txt_reply); if (parse_status != ARES_SUCCESS) { errorno = PyInt_FromLong((long)parse_status); dns_result = Py_None; Py_INCREF(Py_None); goto callback; } dns_result = PyList_New(0); if (!dns_result) { PyErr_NoMemory(); PyErr_WriteUnraisable(Py_None); errorno = PyInt_FromLong((long)ARES_ENOMEM); dns_result = Py_None; Py_INCREF(Py_None); goto callback; } for (txt_ptr = txt_reply; txt_ptr != NULL; txt_ptr = txt_ptr->next) { tmp = Py_BuildValue("s", (const char *)txt_ptr->txt); if (tmp == NULL) { break; } PyList_Append(dns_result, tmp); Py_DECREF(tmp); } errorno = Py_None; Py_INCREF(Py_None); callback: result = PyObject_CallFunctionObjArgs(callback, dns_result, errorno, NULL); if (result == NULL) { PyErr_WriteUnraisable(callback); } Py_XDECREF(result); Py_DECREF(dns_result); Py_DECREF(errorno); if (txt_reply) { ares_free_data(txt_reply); } Py_DECREF(callback); PyGILState_Release(gstate); }
static void query_txt_cb(void *arg, int status,int timeouts, unsigned char *answer_buf, int answer_len) { PyGILState_STATE gstate = PyGILState_Ensure(); int parse_status; struct ares_txt_reply *txt_reply, *txt_ptr; ares_cb_data_t *data; DNSResolver *self; PyObject *dns_result, *errorno, *tmp, *result, *callback; ASSERT(arg); data = (ares_cb_data_t*)arg; self = data->resolver; callback = data->cb; ASSERT(self); /* Object could go out of scope in the callback, increase refcount to avoid it */ Py_INCREF(self); if (status != ARES_SUCCESS) { errorno = PyInt_FromLong((long)status); dns_result = Py_None; Py_INCREF(Py_None); goto callback; } parse_status = ares_parse_txt_reply(answer_buf, answer_len, &txt_reply); if (parse_status != ARES_SUCCESS) { errorno = PyInt_FromLong((long)parse_status); dns_result = Py_None; Py_INCREF(Py_None); goto callback; } dns_result = PyList_New(0); if (!dns_result) { PyErr_NoMemory(); PyErr_WriteUnraisable(Py_None); errorno = PyInt_FromLong((long)ARES_ENOMEM); dns_result = Py_None; Py_INCREF(Py_None); goto callback; } for (txt_ptr = txt_reply; txt_ptr != NULL; txt_ptr = txt_ptr->next) { tmp = PyString_FromString((const char *)txt_ptr->txt); if (tmp == NULL) { break; } PyList_Append(dns_result, tmp); Py_DECREF(tmp); } ares_free_data(txt_reply); errorno = Py_None; Py_INCREF(Py_None); callback: result = PyObject_CallFunctionObjArgs(callback, self, dns_result, errorno, NULL); if (result == NULL) { PyErr_WriteUnraisable(callback); } Py_XDECREF(result); Py_DECREF(callback); PyMem_Free(data); Py_DECREF(self); PyGILState_Release(gstate); }