aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2010-07-08 20:09:24 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2010-07-08 20:09:24 +0400
commit9e02df3a67bdc1cae4f749abd06257b39fc8f25f (patch)
tree9945459777312f8cb326bc195819d0051cb1dc29 /test
parent3d1c40c972d68623f88875ec03ae7c8bafbadad5 (diff)
downloadrspamd-9e02df3a67bdc1cae4f749abd06257b39fc8f25f.tar.gz
rspamd-9e02df3a67bdc1cae4f749abd06257b39fc8f25f.zip
* Forgotten in previous commit
Diffstat (limited to 'test')
-rw-r--r--test/rspamd_dns_test.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/test/rspamd_dns_test.c b/test/rspamd_dns_test.c
new file mode 100644
index 000000000..35b43c9a5
--- /dev/null
+++ b/test/rspamd_dns_test.c
@@ -0,0 +1,91 @@
+
+#include "../src/config.h"
+#include "tests.h"
+#include "../src/dns.h"
+#include "../src/logger.h"
+#include "../src/events.h"
+#include "../src/cfg_file.h"
+
+static guint requests = 0;
+
+static void
+test_dns_cb (struct rspamd_dns_reply *reply, gpointer arg)
+{
+ union rspamd_reply_element *elt;
+ GList *cur;
+
+ msg_debug ("got reply with code %d", reply->code);
+ if (reply->code == DNS_RC_NOERROR) {
+ cur = reply->elements;
+ while (cur) {
+ elt = cur->data;
+ switch (reply->request->type) {
+ case DNS_REQUEST_A:
+ msg_debug ("got ip: %s", inet_ntoa (elt->a.addr[0]));
+ break;
+ case DNS_REQUEST_PTR:
+ msg_debug ("got name %s", elt->ptr.name);
+ break;
+ case DNS_REQUEST_TXT:
+ msg_debug ("got txt %s", elt->txt.data);
+ break;
+ case DNS_REQUEST_MX:
+ msg_debug ("got mx %s:%d", elt->mx.name, elt->mx.priority);
+ break;
+ }
+ cur = g_list_next (cur);
+ }
+ }
+ if (-- requests == 0) {
+ destroy_session (reply->request->session);
+ }
+}
+
+void
+session_fin (gpointer unused)
+{
+ struct timeval tv;
+
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ event_loopexit (&tv);
+}
+
+void
+rspamd_dns_test_func ()
+{
+ struct rspamd_dns_resolver *resolver;
+ struct config_file *cfg;
+ memory_pool_t *pool;
+ struct rspamd_async_session *s;
+
+ cfg = (struct config_file *)g_malloc (sizeof (struct config_file));
+ bzero (cfg, sizeof (struct config_file));
+ cfg->cfg_pool = memory_pool_new (memory_pool_get_size ());
+ cfg->dns_retransmits = 10;
+ cfg->dns_timeout = 1000;
+
+ pool = memory_pool_new (memory_pool_get_size ());
+
+ event_init ();
+ s = new_async_session (pool, session_fin, NULL);
+
+ resolver = dns_resolver_init (cfg);
+
+ requests ++;
+ g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_A, "google.com"));
+ requests ++;
+ g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_PTR, "81.19.70.3"));
+ requests ++;
+ g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_MX, "rambler.ru"));
+ requests ++;
+ g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_TXT, "rambler.ru"));
+ requests ++;
+ g_assert (make_dns_request (resolver, s, pool, test_dns_cb, NULL, DNS_REQUEST_TXT, "non-existent.arpa"));
+
+ g_assert (resolver != NULL);
+
+
+
+ event_loop (0);
+}