aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/provider/MCMXRecordResolverOperation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/provider/MCMXRecordResolverOperation.cpp')
-rw-r--r--src/core/provider/MCMXRecordResolverOperation.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/core/provider/MCMXRecordResolverOperation.cpp b/src/core/provider/MCMXRecordResolverOperation.cpp
new file mode 100644
index 00000000..6f8226cd
--- /dev/null
+++ b/src/core/provider/MCMXRecordResolverOperation.cpp
@@ -0,0 +1,72 @@
+//
+// MCFetchAsyncMXRecord.cpp
+// mailcore2
+//
+// Created by Christopher Hockley on 29/01/15.
+// Copyright (c) 2015 MailCore. All rights reserved.
+//
+
+#include "MCMXRecordResolverOperation.h"
+
+#include <arpa/inet.h>
+#include <resolv.h>
+
+using namespace mailcore;
+
+MXRecordResolverOperation::MXRecordResolverOperation()
+{
+ mHostname = NULL;
+ mMXRecords = NULL;
+}
+
+MXRecordResolverOperation::~MXRecordResolverOperation()
+{
+ MC_SAFE_RELEASE(mMXRecords);
+}
+
+void MXRecordResolverOperation::setHostname(String * hostname)
+{
+ MC_SAFE_REPLACE_COPY(String, mHostname, hostname);
+}
+
+String * MXRecordResolverOperation::hostname()
+{
+ return mHostname;
+}
+
+Array * MXRecordResolverOperation::mxRecords()
+{
+ return mMXRecords;
+}
+
+void MXRecordResolverOperation::main()
+{
+ mMXRecords = new Array();
+ unsigned char response[NS_PACKETSZ];
+ ns_msg handle;
+ ns_rr rr;
+ int len;
+ char dispbuf[4096];
+
+ if (((len = res_search(MCUTF8(mHostname), ns_c_in, ns_t_mx, response, sizeof(response))) >= 0) and
+ (ns_initparse(response, len, &handle) >= 0) and
+ (ns_msg_count(handle, ns_s_an) >= 0)) {
+
+
+
+ for (int ns_index = 0; ns_index < len; ns_index++) {
+ if (ns_parserr(&handle, ns_s_an, ns_index, &rr)) {
+ /* WARN: ns_parserr failed */
+ continue;
+ }
+ ns_sprintrr (&handle, &rr, NULL, NULL, dispbuf, sizeof (dispbuf));
+ if (ns_rr_class(rr) == ns_c_in and ns_rr_type(rr) == ns_t_mx) {
+ char mxname[4096];
+ dn_expand(ns_msg_base(handle), ns_msg_base(handle) + ns_msg_size(handle), ns_rr_rdata(rr) + NS_INT16SZ, mxname, sizeof(mxname));
+ String * str = String::stringWithUTF8Characters(mxname);
+ mMXRecords->addObject(str);
+ }
+ }
+ }
+}
+