All Classes Namespaces Functions Variables Groups Pages
ConnectionProvider.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
// @file ConnectionProvider.qm Qore user module providing an API for providing connections to %Qore
/* ConnectionProvider.qm Copyright 2016 - 2017 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// this module requires Qore 0.8.13 or better
namespace ConnectionProvider {
public struct ConnectionInfo {
string name;
string desc;
*date last_check;
bool loopback;
bool monitor;
*hash opts;
string status;
string type;
bool up = False;
*date updated;
string url;
hash url_hash;
};
public struct ConfigInfo {
string name;
string desc;
string url;
*hash opts;
};
public struct PingInfo {
string name;
string desc;
*hash opts;
string url;
bool ok;
date time;
string info;
*hash ping_info;
};
string get_connection_url(string str);
AbstractConnection get_connection(string conn);
*hash<string, AbstractConnection> get_connections(*bool verbose);
*hash<string, hash<ConnectionInfo>> get_connection_hash(*bool verbose);
class AbstractConnection {
public:
public :
string name;
string desc;
string url;
string safe_url;
*hash orig_opts;
*hash opts;
hash urlh;
date last_check;
string status = "not checked";
bool up = False;
bool monitor;
date updated;
bool loopback = False;
static *code post_processing;
public:
private :
Mutex m();
public:
constructor(string n_name, string n_desc, string n_url, bool n_monitor, *hash n_opts, hash n_urlh, *string n_safe_url);
private:
static string getSafeUrl(hash urlh);
public:
hash<PingInfo> ping(bool throw_exception = False);
private:
hash<PingInfo> pingIntern(hash<PingInfo> rv);
public:
hash<ConnectionInfo> getInfo(bool with_password = False);
hash<ConfigInfo> getConfigHash();
*hash getOptions();
*hash getRuntimeOptions();
*hash getDefaultOptions();
*hash getRealOptions();
object get(bool connect = True, *hash rtopts);
parseTextOptions();
private:
abstract object getImpl(bool connect = True, *hash rtopts);
public:
abstract string getType();
};
class InvalidConnection : public AbstractConnection {
public:
private :
string error;
public:
constructor(string n_name, string n_desc, string n_url, *hash n_opts, string n_error, hash urlh) ;
object getImpl (bool connect=True, *hash rtopts);
string getType();
};
class HttpBasedConnection : public AbstractConnection {
public:
public :
string real_url;
public:
constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh) ;
};
class FtpConnection : public AbstractConnection {
public:
constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh) ;
string getType();
*hash getRuntimeOptions();
private:
FtpClient getImpl(bool connect = True, *hash rtopts);
public:
static FtpConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh);
};
class HttpConnection : public AbstractConnection {
public:
public :
const Options = (
"http_version": True,
"max_redirects": True,
"proxy": True,
"timeout": True,
"connect_timeout": True,
"ssl_cert_path": True,
"ssl_key_password": True,
"ssl_key_path": True,
"ssl_verify_cert": True,
);
const DefaultOptions = (
"timeout": 45s,
"connect_timeout": 45s,
);
const OptionList = Options.keys();
public:
constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh) ;
private:
Qore::HTTPClient getImpl(bool connect = True, *hash rtopts);
public:
hash getOptions();
*hash getDefaultOptions();
string getType();
static HttpConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh);
};
class FilesystemConnection : public AbstractConnection {
public:
public :
const Options = (
"readonly": True,
);
const OptionList = Options.keys();
public:
constructor(string name, string desc, string url, bool monitor, *hash opts, hash n_urlh) ;
string getType();
private:
Dir getImpl(bool connect = True, *hash rtopts);
public:
hash getOptions();
static FilesystemConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh);
};
};
// private, non-exported namespace
namespace Priv {
*hash priv_try_get_connections(string mod);
ConnectionProvider::AbstractConnection priv_try_get_connection(string mod, string conn);
};
ConnectionProvider::AbstractConnection::parseTextOptions
parseTextOptions()
this method is called when parsing connection file definitions from text files when loading into the ...
ConnectionProvider::AbstractConnection::getRuntimeOptions
*hash getRuntimeOptions()
returns runtime options
ConnectionProvider::HttpConnection::getType
string getType()
returns &quot;http&quot;
ConnectionProvider::get_connections
*hash< string, AbstractConnection > get_connections(*bool verbose)
returns all known connections as a hash keyed by connection identifier; values are AbstractConnection...
ConnectionProvider::AbstractConnection::monitor
bool monitor
monitoring flag
Definition: ConnectionProvider.qm.dox.h:246
date
date date(date dt)
ConnectionProvider::ConfigInfo::opts
*hash opts
the options set on the connection
Definition: ConnectionProvider.qm.dox.h:117
ConnectionProvider::HttpBasedConnection
base class for HTTP-based connections that need their URLs rewritten to create the real connection ob...
Definition: ConnectionProvider.qm.dox.h:382
ConnectionProvider::AbstractConnection::last_check
date last_check
date/time of last check/ping
Definition: ConnectionProvider.qm.dox.h:237
ConnectionProvider::AbstractConnection::getInfo
hash< ConnectionInfo > getInfo(bool with_password=False)
returns a ConnectionInfo hash of information about the connection
ConnectionProvider::FilesystemConnection::constructor
constructor(string name, string desc, string url, bool monitor, *hash opts, hash n_urlh)
creates the FilesystemConnection object
ConnectionProvider::ConnectionInfo::last_check
*date last_check
the date/time value of the last connection check (or NOTHING if not checked)
Definition: ConnectionProvider.qm.dox.h:100
ConnectionProvider::FilesystemConnection
class for filesystem connections; returns an object of type Qore::Dir; this can be used to monitor fi...
Definition: ConnectionProvider.qm.dox.h:538
ConnectionProvider::FilesystemConnection::Options
const Options
FilesystemConnection object connection options.
Definition: ConnectionProvider.qm.dox.h:543
ConnectionProvider::ConnectionInfo::name
string name
the connection name
Definition: ConnectionProvider.qm.dox.h:98
ConnectionProvider::AbstractConnection::getImpl
abstract object getImpl(bool connect=True, *hash rtopts)
this method must return the connection object corresponding to the object&#39;s configuration ...
ConnectionProvider::FtpConnection::constructor
constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
creates the FtpConnection object
ConnectionProvider::AbstractConnection::opts
*hash opts
connection options
Definition: ConnectionProvider.qm.dox.h:231
ConnectionProvider::HttpConnection
class for HTTP connections; returns Qore::HTTPClient objects
Definition: ConnectionProvider.qm.dox.h:453
ConnectionProvider::ConnectionInfo::status
string status
a string giving the connection&#39;s status
Definition: ConnectionProvider.qm.dox.h:104
ConnectionProvider::AbstractConnection::getSafeUrl
static string getSafeUrl(hash urlh)
creates a &quot;safe&quot; URL string with password information removed
ConnectionProvider::PingInfo::info
string info
a string giving the result of the ping (&quot;OK&quot; or an error message)
Definition: ConnectionProvider.qm.dox.h:128
True
const True
ConnectionProvider::FilesystemConnection::make
static FilesystemConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
static constructor
ConnectionProvider::AbstractConnection::name
string name
connection name
Definition: ConnectionProvider.qm.dox.h:216
ConnectionProvider::AbstractConnection::getDefaultOptions
*hash getDefaultOptions()
returns default options
ConnectionProvider::ConfigInfo::url
string url
the full URL (including any username &amp; password)
Definition: ConnectionProvider.qm.dox.h:116
ConnectionProvider::FilesystemConnection::getType
string getType()
returns &quot;dir&quot;
ConnectionProvider::get_connection
AbstractConnection get_connection(string conn)
returns an AbstractConnection object if the identifier is known to a registered connection provider ...
ConnectionProvider::ConnectionInfo::updated
*date updated
the date/time value of the update (or NOTHING if not updated)
Definition: ConnectionProvider.qm.dox.h:107
ConnectionProvider::FilesystemConnection::getImpl
Dir getImpl(bool connect=True, *hash rtopts)
returns a Qore::Dir object
ConnectionProvider::FtpConnection::getRuntimeOptions
*hash getRuntimeOptions()
returns runtime options
ConnectionProvider::ConnectionInfo::up
bool up
a boolean vaue indicating the connection is known to be up (will be False if not checked) ...
Definition: ConnectionProvider.qm.dox.h:106
ConnectionProvider::AbstractConnection::urlh
hash urlh
broken down URL hash (as returned by Qore::parse_url())
Definition: ConnectionProvider.qm.dox.h:234
ConnectionProvider::AbstractConnection::post_processing
static *code post_processing
optional code for default post-processing of objects created by getImpl(); must take the object creat...
Definition: ConnectionProvider.qm.dox.h:255
ConnectionProvider::AbstractConnection::ping
hash< PingInfo > ping(bool throw_exception=False)
returns a hash with the results of the ping operation
False
const False
ConnectionProvider::FilesystemConnection::OptionList
const OptionList
FilesystemConnection object connection option list.
Definition: ConnectionProvider.qm.dox.h:548
ConnectionProvider::AbstractConnection::status
string status
status string; in case of a connection error this string will be the error string ...
Definition: ConnectionProvider.qm.dox.h:240
ConnectionProvider::AbstractConnection::orig_opts
*hash orig_opts
original connection options
Definition: ConnectionProvider.qm.dox.h:228
ConnectionProvider::FtpConnection::make
static FtpConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
static constructor
ConnectionProvider::AbstractConnection
abstract base class for connections
Definition: ConnectionProvider.qm.dox.h:211
ConnectionProvider::AbstractConnection::getOptions
*hash getOptions()
returns static / initialization options
ConnectionProvider::AbstractConnection::safe_url
string safe_url
&quot;safe&quot; URL (password information removed)
Definition: ConnectionProvider.qm.dox.h:225
ConnectionProvider::HttpConnection::getImpl
Qore::HTTPClient getImpl(bool connect=True, *hash rtopts)
returns an Qore::HTTPClient object
ConnectionProvider::HttpConnection::make
static HttpConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
static constructor
ConnectionProvider::PingInfo
ping response info as returned by AbstractConnection::ping()
Definition: ConnectionProvider.qm.dox.h:121
ConnectionProvider::ConfigInfo::name
string name
the name of the connection
Definition: ConnectionProvider.qm.dox.h:114
ConnectionProvider::FtpConnection::getImpl
FtpClient getImpl(bool connect=True, *hash rtopts)
returns an Qore::FtpClient object
Qore::HTTPClient
ConnectionProvider::AbstractConnection::constructor
constructor(string n_name, string n_desc, string n_url, bool n_monitor, *hash n_opts, hash n_urlh, *string n_safe_url)
creates the AbstractConnection object
ConnectionProvider::InvalidConnection::getImpl
object getImpl(bool connect=True, *hash rtopts)
throws an exception because the object is invalid
ConnectionProvider::ConnectionInfo::type
string type
the connection type
Definition: ConnectionProvider.qm.dox.h:105
ConnectionProvider::PingInfo::url
string url
a safe version of the URL (without passwords)
Definition: ConnectionProvider.qm.dox.h:125
ConnectionProvider::InvalidConnection
this class is used to mark invalid connections so they can be loaded and reported as invalid ...
Definition: ConnectionProvider.qm.dox.h:360
ConnectionProvider::ConnectionInfo::monitor
bool monitor
a boolean vaue indicating if the connection should be monitored or not
Definition: ConnectionProvider.qm.dox.h:102
ConnectionProvider::HttpConnection::getDefaultOptions
*hash getDefaultOptions()
returns default options
ConnectionProvider::PingInfo::opts
*hash opts
the options set on the connection
Definition: ConnectionProvider.qm.dox.h:124
ConnectionProvider::ConfigInfo
config informaton as returned by AbstractConnection::getConfigHash()
Definition: ConnectionProvider.qm.dox.h:113
ConnectionProvider::HttpConnection::DefaultOptions
const DefaultOptions
HttpConnection default options.
Definition: ConnectionProvider.qm.dox.h:471
ConnectionProvider::ConnectionInfo::url_hash
hash url_hash
a hash of URL information as returned by parse_url()
Definition: ConnectionProvider.qm.dox.h:109
ConnectionProvider::ConnectionInfo::loopback
bool loopback
a boolean vaue indicating if the connection is a loopback connection
Definition: ConnectionProvider.qm.dox.h:101
ConnectionProvider::AbstractConnection::getType
abstract string getType()
returns the string type name for the connection object
ConnectionProvider::AbstractConnection::getRealOptions
*hash getRealOptions()
returns options for saving the connection&#39;s configuration information
ConnectionProvider::HttpConnection::constructor
constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
creates the HttpConnection object
ConnectionProvider::ConfigInfo::desc
string desc
the description
Definition: ConnectionProvider.qm.dox.h:115
ConnectionProvider::PingInfo::time
date time
a relative date/time value giving the elapsed time of the ping operation
Definition: ConnectionProvider.qm.dox.h:127
ConnectionProvider::ConnectionInfo::opts
*hash opts
the original options used to create the object
Definition: ConnectionProvider.qm.dox.h:103
ConnectionProvider::AbstractConnection::getConfigHash
hash< ConfigInfo > getConfigHash()
returns a ConfigInfo hash of static configuration information about the connection ...
ConnectionProvider::ConnectionInfo::url
string url
the URL for the connection including the password (if any present and the with_password argument is T...
Definition: ConnectionProvider.qm.dox.h:108
ConnectionProvider::PingInfo::desc
string desc
the description
Definition: ConnectionProvider.qm.dox.h:123
ConnectionProvider::AbstractConnection::desc
string desc
connection description
Definition: ConnectionProvider.qm.dox.h:219
ConnectionProvider::AbstractConnection::updated
date updated
date/time of last update
Definition: ConnectionProvider.qm.dox.h:249
ConnectionProvider::PingInfo::name
string name
the name of the connection
Definition: ConnectionProvider.qm.dox.h:122
ConnectionProvider::get_connection_url
string get_connection_url(string str)
returns a URL string for the given identifier if the identifier is known to a registered connection p...
ConnectionProvider::ConnectionInfo
connection information hash as returned by AbstractConnection::getInfo()
Definition: ConnectionProvider.qm.dox.h:97
ConnectionProvider::FtpConnection
class for FTP connections; returns Qore::FtpClient objects
Definition: ConnectionProvider.qm.dox.h:399
ConnectionProvider::AbstractConnection::up
bool up
connection status flag; set by monitoring or explicit pings/connections
Definition: ConnectionProvider.qm.dox.h:243
ConnectionProvider::HttpConnection::Options
const Options
HttpConnection object connection options.
Definition: ConnectionProvider.qm.dox.h:458
ConnectionProvider::PingInfo::ok
bool ok
a boolean value giving the result of the ping
Definition: ConnectionProvider.qm.dox.h:126
ConnectionProvider::get_connection_hash
*hash< string, hash< ConnectionInfo > > get_connection_hash(*bool verbose)
returns a hash of connection information keyed by connection identifier; values are ConnectionInfo ha...
ConnectionProvider::PingInfo::ping_info
*hash ping_info
an optional free-form hash giving additional info regarding ping operation or the remote system ...
Definition: ConnectionProvider.qm.dox.h:129
ConnectionProvider::HttpConnection::getOptions
hash getOptions()
gets options
ConnectionProvider::AbstractConnection::url
string url
connection URL (potentially with password info)
Definition: ConnectionProvider.qm.dox.h:222
hash
hash hash(object obj)
ConnectionProvider::InvalidConnection::constructor
constructor(string n_name, string n_desc, string n_url, *hash n_opts, string n_error, hash urlh)
creates the invalid connection object
ConnectionProvider::ConnectionInfo::desc
string desc
the connection description
Definition: ConnectionProvider.qm.dox.h:99
ConnectionProvider::AbstractConnection::pingIntern
hash< PingInfo > pingIntern(hash< PingInfo > rv)
performs the ping by executing get(); returns a PingInfo hash
ConnectionProvider::FilesystemConnection::getOptions
hash getOptions()
gets options
ConnectionProvider::AbstractConnection::loopback
bool loopback
set to True for loopback connections
Definition: ConnectionProvider.qm.dox.h:252
ConnectionProvider::FtpConnection::getType
string getType()
returns &quot;ftp&quot;
ConnectionProvider::InvalidConnection::getType
string getType()
returns &quot;invalid&quot;