43 result =
Spec(
"exit" ,
"0" ) ;
48 result =
Spec(
"exit" , tail ) ;
53 result =
Spec(
"net" , tail ) ;
58 result =
Spec(
"account" , tail ) ;
59 checkRange( result ) ;
63 result =
Spec(
"file" , tail ) ;
64 fixFile( result , base_dir , app_dir ) ;
65 checkFile( result , warnings_p ) ;
69 result =
Spec(
"file" , spec_in ) ;
70 fixFile( result , base_dir , app_dir ) ;
71 checkFile( result , warnings_p ) ;
79 if( spec.first ==
"exit" )
81 return std::make_unique<InternalVerifier>() ;
83 else if( spec.first ==
"net" )
85 return std::make_unique<NetworkVerifier>( es , config , spec.second ) ;
87 else if( spec.first ==
"account" )
89 return std::make_unique<UserVerifier>( es , config , spec.second ) ;
91 else if( spec.first ==
"file" )
93 return std::make_unique<ExecutableVerifier>( es , config ,
G::Path(spec.second) ) ;
99void GVerifiers::VerifierFactory::checkExit( Spec & result )
103 result.first.clear() ;
108void GVerifiers::VerifierFactory::checkNet( Spec & result )
114 catch( std::exception & e )
116 result.first.clear() ;
117 result.second = e.what() ;
121void GVerifiers::VerifierFactory::checkRange( Spec & result )
125 std::string_view spec_view( result.second ) ;
129 G::Range::check( t() ) ;
132 catch( std::exception & e )
134 result.first.clear() ;
135 result.second = e.what() ;
139void GVerifiers::VerifierFactory::fixFile( Spec & result ,
const G::Path & base_dir ,
const G::Path & app_dir )
141 if( !app_dir.
empty() && result.second.find(
"@app") == 0U )
144 result.second = (base_dir/result.second).str() ;
147void GVerifiers::VerifierFactory::checkFile( Spec & result ,
G::StringArray * warnings_p )
149 if( result.second.empty() )
151 result.first.clear() ;
152 result.second =
"empty file path" ;
156 warnings_p->push_back( std::string(
"verifier program does not exist: ").append(result.second) ) ;
160 warnings_p->push_back( std::string(
"invalid program: ").append(result.second) ) ;
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
static Location nosocks(const std::string &spec, int family=AF_UNSPEC)
Factory function for a remote location but not allowing the extended syntax for socks.
static Spec parse(std::string_view spec, const G::Path &base_dir={}, const G::Path &app_dir={}, G::StringArray *warnings_p=nullptr)
Parses a verifier specification string like "/usr/bin/foo" or "net:127.0.0.1:99" or "net:/run/spamd....
std::unique_ptr< GSmtp::Verifier > newVerifier(GNet::EventState, const GSmtp::Verifier::Config &config, const GSmtp::VerifierFactoryBase::Spec &spec) override
Returns a Verifier on the heap.
VerifierFactory()
Constructor.
A general-purpose exception class derived from std::exception and containing an error message.
static bool isDirectory(const Path &path, std::nothrow_t)
Returns true if the path exists() and is a directory.
static bool exists(const Path &file)
Returns true if the file (directory, device etc.) exists.
A Path object represents a file system path.
bool isRelative() const noexcept
Returns true if the path is a relative path or empty().
std::string str() const
Returns the path string.
bool empty() const noexcept
Returns true if the path is empty.
static bool isUInt(std::string_view s) noexcept
Returns true if the string can be converted into an unsigned integer without throwing an exception.
static bool headMatch(std::string_view in, std::string_view head) noexcept
Returns true if the string has the given start (or head is empty).
static bool isNumeric(std::string_view s, bool allow_minus_sign=false) noexcept
Returns true if every character is a decimal digit.
static std::string printable(const std::string &in, char escape='\\')
Returns a printable representation of the given input string, using chacter code ranges 0x20 to 0x7e ...
static std::string_view tailView(std::string_view in, std::size_t pos, std::string_view default_={}) noexcept
Like tail() but returning a view into the input string.
static bool replace(std::string &s, std::string_view from, std::string_view to, std::size_t *pos_p=nullptr)
A std::string_view overload.
A zero-copy string token iterator where the token separators are runs of whitespace characters,...
std::vector< std::string > StringArray
A std::vector of std::strings.
Verifier specification tuple for GSmtp::VerifierFactoryBase::newVerifier().
Configuration passed to address verifier constructors.