uri_facade_lin.cpp
Go to the documentation of this file.
1 
11 
12 #include <opc/common/uri_facade.h>
13 
14 #include <opc/common/exception.h>
15 
16 #include <regex>
17 
18 namespace Common
19 {
20 
21 void Uri::Initialize(const std::string &uriString)
22 {
23  /*
24  acording to wiki https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#URI_resolution
25 
26  The scheme, consisting of a sequence of characters beginning with a letter and followed by any combination of letters, digits, plus (+), period (.), or hyphen (-)
27  ([a-zA-Z][a-zA-Z0-9.+-]*)
28 
29  An optional authentication section of a user name and password, separated by a colon, followed by an at symbol (@)
30  (([^@:]*)(:([^@]+))?@)?
31 
32  A host, consisting of either a registered name (including but not limited to a hostname), or an IP address.
33  IPv4 addresses must be in dot-decimal notation, and IPv6 addresses must be enclosed in brackets ([ ])
34  ([^/:?]+)
35 
36  An optional port number, separated from the hostname by a colon
37  (:([0-9]+))?
38 
39  A path, which contains data, usually organized in hierarchical form, that appears as a sequence of segments separated by slashes.
40  Such a sequence may resemble or map exactly to a file system path, but does not always imply a relation to one.
41  The path must begin with a single slash (/) if an authority part was present
42  (/[^?#]*)?
43 
44  rest of URI is query + fragment, currently not used in freeopcua
45  (.*)
46  */
47  std::regex uri_regex("([a-zA-Z][a-zA-Z0-9.+-]*)://(([^@:]*)(:([^@]+))?@)?([^/:?]+)(:([0-9]+))?(/[^?#]*)?(.*)");
48  std::smatch uri_match;
49  if (!std::regex_match(uriString, uri_match, uri_regex))
50  {
51  THROW_ERROR1(CannotParseUri, uriString);
52  }
53 
54 
55  enum {Scheme = 1, User = 3, Password = 5, Host = 6, Port = 8, Path = 9, QueryAndFragment = 10};
56 
57  SchemeStr = uri_match[Scheme].str();
58  PasswordStr = uri_match[Password].str();
59  UserStr = uri_match[User].str();
60  HostStr = uri_match[Host].str();
61  try {
62  std::string n = uri_match[Port].str();
63  PortNum = n.empty()? 0: stoul(n);
64  }
65  catch (...) {
66  THROW_ERROR1(CannotParseUri, uriString);
67  }
68 
69  if (SchemeStr.empty() || HostStr.empty())
70  {
71  THROW_ERROR1(CannotParseUri, uriString);
72  }
73 }
74 
75 } // namespace Common
76 
77 
std::string Password() const
Definition: uri_facade.h:36
Addon interface definition GNU LGPL.
std::string Scheme() const
Definition: uri_facade.h:26
std::string User() const
Definition: uri_facade.h:31
void Initialize(const std::string &uriString)
std::string PasswordStr
Definition: uri_facade.h:57
unsigned Port() const
Definition: uri_facade.h:46
std::string SchemeStr
Definition: uri_facade.h:55
unsigned PortNum
Definition: uri_facade.h:59
std::string UserStr
Definition: uri_facade.h:56
#define THROW_ERROR1(data, param1)
Definition: exception.h:212
std::string HostStr
Definition: uri_facade.h:58
Common::ErrorData CannotParseUri
std::string Host() const
Definition: uri_facade.h:41


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:12:08