add from_heuristics.?? as a stub

LAS-10
Roker 2017-10-13 16:21:37 +02:00
parent c2c1e0d67c
commit 85565bbd79
4 changed files with 74 additions and 0 deletions

View File

@ -20,6 +20,7 @@ accountSettings_test: accountSettings_test.o libAccountSettings.a
libAccountSettings.a: account_settings_internal.o implementation.o \
isp_db.o \
from_heuristics.o \
from_srv.o
ar rcs $@ $^

59
src/from_heuristics.cc Normal file
View File

@ -0,0 +1,59 @@
#include "from_heuristics.hh"
#include "account_settings_internal.hh"
#include <ldns/ldns.h>
#include <stdexcept>
#include <memory>
class protocol_error : public std::runtime_error
{
public:
protocol_error() : std::runtime_error("Protocol error!")
{}
};
namespace
{
// TODO: implement!
class Protocol
{
public:
Protocol() = default;
};
AS_Server probe_server(const std::string& domain, std::initializer_list<std::string> names, Protocol p=Protocol() )
{
AS_Server ass { "", -1, AS_ACCESS(-1), "" };
throw protocol_error{};
}
} //end of anonymous namespace
AccountSettings* get_settings_from_heuristics(AccountSettings* as, const std::string& accountName, const std::string& domain, const std::string& provider)
{
if(as==nullptr)
{
throw std::runtime_error("get_settings_from_heuristics shall not be called with NULL pointer!");
}
// fprintf(stderr, "== IMAP ==\n");
try{
as->incoming = probe_server( domain, {"imap", "mail", "imaps", "imapmail", "imap-mail", "mx", "", "mbox",} );
}catch( const protocol_error& )
{
// ignore protocol errors
}
// fprintf(stderr, "== SMTP ==\n");
try{
as->outgoing = probe_server( domain, {"smtp", "mail", "smtps", "smtpmail", "smtp-mail", "mx", "", "smtpauth",} );
}catch( const protocol_error& )
{
// ignore protocol errors
}
return as;
}

8
src/from_heuristics.hh Normal file
View File

@ -0,0 +1,8 @@
#ifndef ACCOUNT_SETTINGS_FROM_HEURISTICS_HH
#define ACCOUNT_SETTINGS_FROM_HEURISTICS_HH
#include "account_settings_internal.hh"
AccountSettings* get_settings_from_heuristics(AccountSettings* as, const std::string& accountName, const std::string& domain, const std::string& provider);
#endif // ACCOUNT_SETTINGS_FROM_HEURISTICS_HH

View File

@ -4,6 +4,7 @@
#include <stdexcept>
#include "from_srv.hh"
#include "from_heuristics.hh"
namespace
{
@ -97,6 +98,11 @@ const AccountSettings* get_account_settings(const char* accountName, const char*
{
get_settings_from_srv(dyn_as, accountName, domain, provider );
}
if( dyn_as->status != AS_OK && (flags & AS_FLAG_USE_HEURISTICS) )
{
get_settings_from_heuristics(dyn_as, accountName, domain, provider );
}
return dyn_as;
}