summaryrefslogtreecommitdiffstats
path: root/raul
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-01-20 13:07:29 +0100
committerDavid Robillard <d@drobilla.net>2018-01-21 00:31:38 +0100
commit5eb7a555de2291f4df8c75ce261c555552725beb (patch)
tree38e075a0841e64996e7abeba1a36286a6c002c5f /raul
parent6a8f9d519bcce0f7b90d18af56458c4a6701a927 (diff)
downloadraul-5eb7a555de2291f4df8c75ce261c555552725beb.tar.gz
raul-5eb7a555de2291f4df8c75ce261c555552725beb.tar.bz2
raul-5eb7a555de2291f4df8c75ce261c555552725beb.zip
Remove URI class
Diffstat (limited to 'raul')
-rw-r--r--raul/Socket.hpp53
-rw-r--r--raul/URI.hpp111
2 files changed, 27 insertions, 137 deletions
diff --git a/raul/Socket.hpp b/raul/Socket.hpp
index a569511..c42485f 100644
--- a/raul/Socket.hpp
+++ b/raul/Socket.hpp
@@ -18,6 +18,7 @@
#define RAUL_SOCKET_HPP
#include <memory>
+#include <string>
#include <errno.h>
#include <netdb.h>
@@ -31,7 +32,6 @@
#include <unistd.h>
#include "raul/Noncopyable.hpp"
-#include "raul/URI.hpp"
namespace Raul {
@@ -47,11 +47,11 @@ public:
explicit Socket(Type t);
/** Wrap an existing open socket. */
- Socket(Type t,
- const Raul::URI& uri,
- struct sockaddr* addr,
- socklen_t addr_len,
- int fd);
+ Socket(Type t,
+ const std::string& uri,
+ struct sockaddr* addr,
+ socklen_t addr_len,
+ int fd);
~Socket();
@@ -60,13 +60,13 @@ public:
* Use "*" as hostname to listen on all interfaces.
* @return True on success.
*/
- bool bind(const Raul::URI& uri);
+ bool bind(const std::string& uri);
/** Connect a client socket to a server address.
* @param uri Address URI, e.g. unix:///tmp/foo or tcp://somehost:1234
* @return True on success.
*/
- bool connect(const Raul::URI& uri);
+ bool connect(const std::string& uri);
/** Mark server socket as passive to listen for incoming connections.
* @return True on success.
@@ -81,7 +81,7 @@ public:
/** Return the file descriptor for the socket. */
int fd() { return _sock; }
- const Raul::URI& uri() const { return _uri; }
+ const std::string& uri() const { return _uri; }
/** Close the socket. */
void close();
@@ -93,9 +93,9 @@ public:
void shutdown();
private:
- bool set_addr(const Raul::URI& uri);
+ bool set_addr(const std::string& uri);
- Raul::URI _uri;
+ std::string _uri;
struct sockaddr* _addr;
socklen_t _addr_len;
Type _type;
@@ -125,16 +125,16 @@ Socket::Socket(Type t)
}
inline
-Socket::Socket(Type t,
- const Raul::URI& uri,
- struct sockaddr* addr,
- socklen_t addr_len,
- int fd)
- : _uri(uri)
- , _addr(addr)
- , _addr_len(addr_len)
- , _type(t)
- , _sock(fd)
+Socket::Socket(Type t,
+ const std::string& uri,
+ struct sockaddr* addr,
+ socklen_t addr_len,
+ int fd)
+ : _uri(uri)
+ , _addr(addr)
+ , _addr_len(addr_len)
+ , _type(t)
+ , _sock(fd)
{
}
@@ -146,7 +146,7 @@ Socket::~Socket()
}
inline bool
-Socket::set_addr(const Raul::URI& uri)
+Socket::set_addr(const std::string& uri)
{
free(_addr);
if (_type == Type::UNIX && uri.substr(0, strlen("unix://")) == "unix://") {
@@ -189,7 +189,7 @@ Socket::set_addr(const Raul::URI& uri)
}
inline bool
-Socket::bind(const Raul::URI& uri)
+Socket::bind(const std::string& uri)
{
if (set_addr(uri) && ::bind(_sock, _addr, _addr_len) != -1) {
return true;
@@ -199,7 +199,7 @@ Socket::bind(const Raul::URI& uri)
}
inline bool
-Socket::connect(const Raul::URI& uri)
+Socket::connect(const std::string& uri)
{
if (set_addr(uri) && ::connect(_sock, _addr, _addr_len) != -1) {
return true;
@@ -230,13 +230,14 @@ Socket::accept()
return std::shared_ptr<Socket>();
}
- Raul::URI client_uri = _uri;
+ std::string client_uri = _uri;
if (_type != Type::UNIX) {
char host[NI_MAXHOST];
char serv[NI_MAXSERV];
if (!getnameinfo(client_addr, client_addr_len,
host, sizeof(host), serv, sizeof(serv), 0)) {
- client_uri = Raul::URI(_uri.scheme() + "://" + host + ":" + serv);
+ const std::string scheme = _uri.substr(0, _uri.find(':'));
+ client_uri = std::string(scheme + "://" + host + ":" + serv);
}
}
diff --git a/raul/URI.hpp b/raul/URI.hpp
deleted file mode 100644
index 7bf2763..0000000
--- a/raul/URI.hpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- This file is part of Raul.
- Copyright 2007-2015 David Robillard <http://drobilla.net>
-
- Raul is free software: you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation, either version 3 of the License, or any later version.
-
- Raul is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Raul. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef RAUL_URI_HPP
-#define RAUL_URI_HPP
-
-#include <string>
-
-#include "raul/Exception.hpp"
-
-namespace Raul {
-
-/** A URI (RFC3986) string.
- *
- * @ingroup raul
- */
-class URI : public std::basic_string<char> {
-public:
- /** Attempt to construct an invalid URI. */
- class BadURI : public Exception {
- public:
- explicit BadURI(const std::string& uri) : Exception(uri) {}
- };
-
- /** Construct a URI from a C++ string.
- *
- * This will throw an exception if `uri` is invalid. To avoid this, use
- * is_valid() first to check.
- */
- explicit URI(const std::basic_string<char>& uri)
- : std::basic_string<char>(uri)
- {
- if (!is_valid(uri)) {
- throw BadURI(uri);
- }
- }
-
- /** Construct a URI from a C string.
- *
- * This will throw an exception if `uri` is invalid. To avoid this, use
- * is_valid() first to check.
- */
- explicit URI(const char* uri)
- : std::basic_string<char>(uri)
- {
- if (!is_valid(uri)) {
- throw BadURI(uri);
- }
- }
-
- /** Copy a URI.
- *
- * Note this is faster than constructing a URI from another URI's string
- * since validation is unnecessary.
- */
- URI(const URI& uri) = default;
-
- URI& operator=(const URI& uri) = default;
-
- /** Return true iff `c` is a valid URI start character. */
- static inline bool is_valid_start_char(char c) {
- return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
- }
-
- /** Return true iff `c` is a valid URI scheme character. */
- static inline bool is_valid_scheme_char(char c) {
- // S3.1: scheme ::= ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
- return is_valid_start_char(c) || (c >= '0' && c <= '9') ||
- c == '+' || c == '-' || c == '.';
- }
-
- /** Return true iff `str` is a valid URI.
- *
- * Currently this only checks that `str` starts with a valid URI scheme.
- */
- static inline bool is_valid(const std::basic_string<char>& str) {
- if (!is_valid_start_char(str[0])) {
- return false; // Must start with a-z A-Z
- }
-
- for (size_t i = 1; i < str.length(); ++i) {
- if (str[i] == ':') {
- return true; // Starts with a valid scheme
- } else if (!is_valid_scheme_char(str[i])) {
- return false; // Invalid scheme character encountered
- }
- }
-
- return false; // Must start with a scheme followed by ':'
- }
-
- /** Return the URI scheme (everything before the first ':') */
- inline std::string scheme() const { return substr(0, find(":")); }
-};
-
-} // namespace Raul
-
-#endif // RAUL_URI_HPP