]> source.dussan.org Git - rspamd.git/commitdiff
* Forgotten in previous commit
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 8 Jul 2010 16:09:24 +0000 (20:09 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 8 Jul 2010 16:09:24 +0000 (20:09 +0400)
test/rspamd_dns_test.c [new file with mode: 0644]

diff --git a/test/rspamd_dns_test.c b/test/rspamd_dns_test.c
new file mode 100644 (file)
index 0000000..35b43c9
--- /dev/null
@@ -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);
+}