[haiku-commits] r35970 - haiku/trunk/src/preferences/mail

  • From: stefano.ceccherini@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 27 Mar 2010 14:12:13 +0100 (CET)

Author: jackburton
Date: 2010-03-27 14:12:13 +0100 (Sat, 27 Mar 2010)
New Revision: 35970
Changeset: http://dev.haiku-os.org/changeset/35970/haiku
Ticket: http://dev.haiku-os.org/ticket/5655

Modified:
   haiku/trunk/src/preferences/mail/DNSQuery.cpp
   haiku/trunk/src/preferences/mail/DNSQuery.h
Log:
Added some error checking to DNSQuery::GetDNSServers(), since it could fail.
Temporarily enabled debug to help with ticket #5655.


Modified: haiku/trunk/src/preferences/mail/DNSQuery.cpp
===================================================================
--- haiku/trunk/src/preferences/mail/DNSQuery.cpp       2010-03-27 10:10:03 UTC 
(rev 35969)
+++ haiku/trunk/src/preferences/mail/DNSQuery.cpp       2010-03-27 13:12:13 UTC 
(rev 35970)
@@ -9,7 +9,7 @@
 #include <NetEndpoint.h>
 #include <Path.h> 
 
-// #define DEBUG 1
+ #define DEBUG 1
 
 #undef PRINT
 #ifdef DEBUG
@@ -149,9 +149,11 @@
 // #pragma mark - DNSTools
 
 
-void
+status_t
 DNSTools::GetDNSServers(BObjectList<BString>* serverList)
 {
+       // TODO: reading resolv.conf ourselves shouldn't be needed.
+       // we should have some function to retrieve the dns list
 #define        MATCH(line, name) \
        (!strncmp(line, name, sizeof(name) - 1) && \
        (line[sizeof(name) - 1] == ' ' || \
@@ -159,7 +161,7 @@
 
        BPath path;
        if (find_directory(B_COMMON_SETTINGS_DIRECTORY, &path) != B_OK)
-               return;
+               return B_ENTRY_NOT_FOUND;
 
        path.Append("network/resolv.conf");
 
@@ -167,7 +169,7 @@
        if (fp == NULL) {
                fprintf(stderr, "failed to open '%s' to read nameservers: 
%s\n", 
                        path.Path(), strerror(errno));
-               return;
+               return B_ENTRY_NOT_FOUND;
        }
 
        int nserv = 0;
@@ -198,6 +200,8 @@
        }
 
        fclose(fp);
+       
+       return B_OK;
 }
 
 
@@ -271,16 +275,14 @@
 {
        // list owns the items
        BObjectList<BString> dnsServerList(5, true);
-       DNSTools::GetDNSServers(&dnsServerList);
+       status_t status = DNSTools::GetDNSServers(&dnsServerList);
+       if (status != B_OK)
+               return status;
+               
        BString* firstDNS = dnsServerList.ItemAt(0);
-       int status = -1;
-       if (firstDNS)
-               status = inet_aton(firstDNS->String(), add);
-       else
+       if (firstDNS == NULL || inet_aton(firstDNS->String(), add) != 1)
                return B_ERROR;
 
-       if (status != 1)
-               return B_ERROR;
        PRINT("dns server found: %s \n", firstDNS->String());
        return B_OK;
 }

Modified: haiku/trunk/src/preferences/mail/DNSQuery.h
===================================================================
--- haiku/trunk/src/preferences/mail/DNSQuery.h 2010-03-27 10:10:03 UTC (rev 
35969)
+++ haiku/trunk/src/preferences/mail/DNSQuery.h 2010-03-27 13:12:13 UTC (rev 
35970)
@@ -51,7 +51,7 @@
 
 class DNSTools {
 public:
-               static void             GetDNSServers(BObjectList<BString>* 
serverList);
+               static status_t         GetDNSServers(BObjectList<BString>* 
serverList);
                static BString  ConvertToDNSName(const BString& string);
                static BString  ConvertFromDNSName(const BString& string);
 };


Other related posts:

  • » [haiku-commits] r35970 - haiku/trunk/src/preferences/mail - stefano . ceccherini