Qore ConnectionProvider Module Reference  1.0
 All Classes Namespaces Functions Variables Groups Pages
ConnectionProvider.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // @file ConnectionProvider.qm Qore user module providing an API for providing connections to %Qore
3 
4 /* ConnectionProvider.qm Copyright 2016 - 2017 Qore Technologies, s.r.o.
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23 */
24 
25 // this module requires Qore 0.8.13 or better
26 
27 
28 
29 
94 namespace ConnectionProvider {
97  public struct ConnectionInfo {
98  string name;
99  string desc;
101  bool loopback;
102  bool monitor;
104  string status;
105  string type;
106  bool up = False;
108  string url;
110  };
111 
113  public struct ConfigInfo {
114  string name;
115  string desc;
116  string url;
118  };
119 
121  public struct PingInfo {
122  string name;
123  string desc;
125  string url;
126  bool ok;
128  string info;
130  };
131 
133 
148  string get_connection_url(string str);
149 
150 
152 
167  AbstractConnection get_connection(string conn);
168 
169 
171 
186  *hash<string, AbstractConnection> get_connections(*bool verbose);
187 
188 
190 
205  *hash<string, hash<ConnectionInfo>> get_connection_hash(*bool verbose);
206 
207 
209 
212 
213 public:
214  public :
216  string name;
217 
219  string desc;
220 
222  string url;
223 
225  string safe_url;
226 
229 
232 
235 
238 
240  string status = "not checked";
241 
243  bool up = False;
244 
246  bool monitor;
247 
250 
252  bool loopback = False;
253 
255  static *code post_processing;
256 
257 public:
258 
259  private :
260  Mutex m();
261 
262 public:
263 
265 
273  constructor(string n_name, string n_desc, string n_url, bool n_monitor, *hash n_opts, hash n_urlh, *string n_safe_url);
274 
275 
277 
282 private:
283  static string getSafeUrl(hash urlh);
284 public:
285 
286 
288 
292  hash<PingInfo> ping(bool throw_exception = False);
293 
294 
296 
297 private:
298  hash<PingInfo> pingIntern(hash<PingInfo> rv);
299 public:
300 
301 
303 
307  hash<ConnectionInfo> getInfo(bool with_password = False);
308 
309 
311 
313  hash<ConfigInfo> getConfigHash();
314 
315 
317  *hash getOptions();
318 
319 
322 
323 
326 
327 
329  *hash getRealOptions();
330 
331 
333 
335  object get(bool connect = True, *hash rtopts);
336 
337 
339 
342 
343 
345 
351 private:
352  abstract object getImpl(bool connect = True, *hash rtopts);
353 public:
354 
356  abstract string getType();
357  };
358 
361 
362 public:
363  private :
364  string error;
365 
366 public:
367 
369  constructor(string n_name, string n_desc, string n_url, *hash n_opts, string n_error, hash urlh) ;
370 
371 
373  object getImpl (bool connect=True, *hash rtopts);
374 
375 
377  string getType();
378 
379  };
380 
383 
384 public:
385  public :
386  string real_url;
387 
388 public:
389 
390  constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh) ;
391 
392  };
393 
395 
400 
401 public:
403 
410  constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh) ;
411 
412 
414  string getType();
415 
416 
418 
423 
424 
426 
430 private:
431  FtpClient getImpl(bool connect = True, *hash rtopts);
432 public:
433 
434 
436  static FtpConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh);
437  };
438 
440 
454 
455 public:
456  public :
458  const Options = (
459  "http_version": True,
460  "max_redirects": True,
461  "proxy": True,
462  "timeout": True,
463  "connect_timeout": True,
464  "ssl_cert_path": True,
465  "ssl_key_password": True,
466  "ssl_key_path": True,
467  "ssl_verify_cert": True,
468  );
469 
471  const DefaultOptions = (
472  "timeout": 45s,
473  "connect_timeout": 45s,
474  );
475 
476  const OptionList = Options.keys();
477 
478 public:
479 
481 
488  constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh) ;
489 
490 
492 
496 private:
497  Qore::HTTPClient getImpl(bool connect = True, *hash rtopts);
498 public:
499 
500 
502 
515  hash getOptions();
516 
517 
519 
524 
525 
527  string getType();
528 
529 
531  static HttpConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh);
532  };
533 
535 
539 
540 public:
541  public :
543  const Options = (
544  "readonly": True,
545  );
546 
548  const OptionList = Options.keys();
549 
550 public:
551 
553 
560  constructor(string name, string desc, string url, bool monitor, *hash opts, hash n_urlh) ;
561 
562 
564  string getType();
565 
566 
568 
574 private:
575  Dir getImpl(bool connect = True, *hash rtopts);
576 public:
577 
578 
580 
583  hash getOptions();
584 
585 
587  static FilesystemConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh);
588  };
589 };
590 
591 // private, non-exported namespace
592 namespace Priv {
593  *hash priv_try_get_connections(string mod);
594 
595 
596  ConnectionProvider::AbstractConnection priv_try_get_connection(string mod, string conn);
597 
598 };
parseTextOptions()
this method is called when parsing connection file definitions from text files when loading into the ...
*hash getRuntimeOptions()
returns runtime options
string getType()
returns &quot;http&quot;
*hash< string, AbstractConnection > get_connections(*bool verbose)
returns all known connections as a hash keyed by connection identifier; values are AbstractConnection...
bool monitor
monitoring flag
Definition: ConnectionProvider.qm.dox.h:246
date date(date dt)
*hash opts
the options set on the connection
Definition: ConnectionProvider.qm.dox.h:117
base class for HTTP-based connections that need their URLs rewritten to create the real connection ob...
Definition: ConnectionProvider.qm.dox.h:382
date last_check
date/time of last check/ping
Definition: ConnectionProvider.qm.dox.h:237
hash< ConnectionInfo > getInfo(bool with_password=False)
returns a ConnectionInfo hash of information about the connection
constructor(string name, string desc, string url, bool monitor, *hash opts, hash n_urlh)
creates the FilesystemConnection object
*date last_check
the date/time value of the last connection check (or NOTHING if not checked)
Definition: ConnectionProvider.qm.dox.h:100
class for filesystem connections; returns an object of type Qore::Dir; this can be used to monitor fi...
Definition: ConnectionProvider.qm.dox.h:538
const Options
FilesystemConnection object connection options.
Definition: ConnectionProvider.qm.dox.h:543
string name
the connection name
Definition: ConnectionProvider.qm.dox.h:98
abstract object getImpl(bool connect=True, *hash rtopts)
this method must return the connection object corresponding to the object&#39;s configuration ...
constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
creates the FtpConnection object
*hash opts
connection options
Definition: ConnectionProvider.qm.dox.h:231
class for HTTP connections; returns Qore::HTTPClient objects
Definition: ConnectionProvider.qm.dox.h:453
string status
a string giving the connection&#39;s status
Definition: ConnectionProvider.qm.dox.h:104
static string getSafeUrl(hash urlh)
creates a &quot;safe&quot; URL string with password information removed
string info
a string giving the result of the ping (&quot;OK&quot; or an error message)
Definition: ConnectionProvider.qm.dox.h:128
const True
static FilesystemConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
static constructor
string name
connection name
Definition: ConnectionProvider.qm.dox.h:216
*hash getDefaultOptions()
returns default options
string url
the full URL (including any username &amp; password)
Definition: ConnectionProvider.qm.dox.h:116
string getType()
returns &quot;dir&quot;
AbstractConnection get_connection(string conn)
returns an AbstractConnection object if the identifier is known to a registered connection provider ...
*date updated
the date/time value of the update (or NOTHING if not updated)
Definition: ConnectionProvider.qm.dox.h:107
Dir getImpl(bool connect=True, *hash rtopts)
returns a Qore::Dir object
*hash getRuntimeOptions()
returns runtime options
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
hash urlh
broken down URL hash (as returned by Qore::parse_url())
Definition: ConnectionProvider.qm.dox.h:234
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
hash< PingInfo > ping(bool throw_exception=False)
returns a hash with the results of the ping operation
const False
const OptionList
FilesystemConnection object connection option list.
Definition: ConnectionProvider.qm.dox.h:548
string status
status string; in case of a connection error this string will be the error string ...
Definition: ConnectionProvider.qm.dox.h:240
*hash orig_opts
original connection options
Definition: ConnectionProvider.qm.dox.h:228
static FtpConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
static constructor
abstract base class for connections
Definition: ConnectionProvider.qm.dox.h:211
*hash getOptions()
returns static / initialization options
string safe_url
&quot;safe&quot; URL (password information removed)
Definition: ConnectionProvider.qm.dox.h:225
Qore::HTTPClient getImpl(bool connect=True, *hash rtopts)
returns an Qore::HTTPClient object
static HttpConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
static constructor
ping response info as returned by AbstractConnection::ping()
Definition: ConnectionProvider.qm.dox.h:121
string name
the name of the connection
Definition: ConnectionProvider.qm.dox.h:114
FtpClient getImpl(bool connect=True, *hash rtopts)
returns an Qore::FtpClient object
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
object getImpl(bool connect=True, *hash rtopts)
throws an exception because the object is invalid
string type
the connection type
Definition: ConnectionProvider.qm.dox.h:105
string url
a safe version of the URL (without passwords)
Definition: ConnectionProvider.qm.dox.h:125
this class is used to mark invalid connections so they can be loaded and reported as invalid ...
Definition: ConnectionProvider.qm.dox.h:360
bool monitor
a boolean vaue indicating if the connection should be monitored or not
Definition: ConnectionProvider.qm.dox.h:102
*hash getDefaultOptions()
returns default options
*hash opts
the options set on the connection
Definition: ConnectionProvider.qm.dox.h:124
config informaton as returned by AbstractConnection::getConfigHash()
Definition: ConnectionProvider.qm.dox.h:113
const DefaultOptions
HttpConnection default options.
Definition: ConnectionProvider.qm.dox.h:471
hash url_hash
a hash of URL information as returned by parse_url()
Definition: ConnectionProvider.qm.dox.h:109
bool loopback
a boolean vaue indicating if the connection is a loopback connection
Definition: ConnectionProvider.qm.dox.h:101
abstract string getType()
returns the string type name for the connection object
*hash getRealOptions()
returns options for saving the connection&#39;s configuration information
constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
creates the HttpConnection object
string desc
the description
Definition: ConnectionProvider.qm.dox.h:115
date time
a relative date/time value giving the elapsed time of the ping operation
Definition: ConnectionProvider.qm.dox.h:127
*hash opts
the original options used to create the object
Definition: ConnectionProvider.qm.dox.h:103
hash< ConfigInfo > getConfigHash()
returns a ConfigInfo hash of static configuration information about the connection ...
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
string desc
the description
Definition: ConnectionProvider.qm.dox.h:123
string desc
connection description
Definition: ConnectionProvider.qm.dox.h:219
date updated
date/time of last update
Definition: ConnectionProvider.qm.dox.h:249
string name
the name of the connection
Definition: ConnectionProvider.qm.dox.h:122
string get_connection_url(string str)
returns a URL string for the given identifier if the identifier is known to a registered connection p...
connection information hash as returned by AbstractConnection::getInfo()
Definition: ConnectionProvider.qm.dox.h:97
class for FTP connections; returns Qore::FtpClient objects
Definition: ConnectionProvider.qm.dox.h:399
bool up
connection status flag; set by monitoring or explicit pings/connections
Definition: ConnectionProvider.qm.dox.h:243
const Options
HttpConnection object connection options.
Definition: ConnectionProvider.qm.dox.h:458
bool ok
a boolean value giving the result of the ping
Definition: ConnectionProvider.qm.dox.h:126
*hash< string, hash< ConnectionInfo > > get_connection_hash(*bool verbose)
returns a hash of connection information keyed by connection identifier; values are ConnectionInfo ha...
*hash ping_info
an optional free-form hash giving additional info regarding ping operation or the remote system ...
Definition: ConnectionProvider.qm.dox.h:129
string url
connection URL (potentially with password info)
Definition: ConnectionProvider.qm.dox.h:222
hash hash(object obj)
constructor(string n_name, string n_desc, string n_url, *hash n_opts, string n_error, hash urlh)
creates the invalid connection object
string desc
the connection description
Definition: ConnectionProvider.qm.dox.h:99
hash< PingInfo > pingIntern(hash< PingInfo > rv)
performs the ping by executing get(); returns a PingInfo hash
bool loopback
set to True for loopback connections
Definition: ConnectionProvider.qm.dox.h:252
string getType()
returns &quot;ftp&quot;
string getType()
returns &quot;invalid&quot;