File: SoapyURLUtils.hpp

package info (click to toggle)
soapyremote 0.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 504 kB
  • sloc: cpp: 6,740; makefile: 13
file content (90 lines) | stat: -rw-r--r-- 2,028 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright (c) 2015-2018 Josh Blum
// SPDX-License-Identifier: BSL-1.0

#pragma once
#include "SoapyRemoteConfig.hpp"
#include <cstddef>
#include <string>
#include <vector>

//forward declares
struct sockaddr;

//! A simple storage class for a sockaddr
class SOAPY_REMOTE_API SockAddrData
{
public:
    //! Create an empty socket address
    SockAddrData(void);

    //! Create a socket address from a pointer and length
    SockAddrData(const struct sockaddr *addr, const int addrlen);

    //! Get a pointer to the underlying data
    const struct sockaddr *addr(void) const;

    //! Length of the underlying structure
    size_t addrlen(void) const;

private:
    std::vector<char> _storage;
};

/*!
 * URL parsing, manipulation, lookup.
 */
class SOAPY_REMOTE_API SoapyURL
{
public:
    //! Create empty url object
    SoapyURL(void);

    //! Create URL from components
    SoapyURL(const std::string &scheme, const std::string &node, const std::string &service);

    //! Parse from url markup string
    SoapyURL(const std::string &url);

    //! Create URL from socket address
    SoapyURL(const struct sockaddr *addr);

    //! Create URL from socket address
    SoapyURL(const SockAddrData &addr);

    /*!
     * Convert to socket address + resolve address.
     * Return the error message on failure.
     */
    std::string toSockAddr(SockAddrData &addr) const;

    /*!
     * Convert to URL string markup.
     */
    std::string toString(void) const;

    //! Get the scheme
    std::string getScheme(void) const;

    //! Get the node
    std::string getNode(void) const;

    //! Get the service
    std::string getService(void) const;

    //! Set the scheme
    void setScheme(const std::string &scheme);

    //! Set the node
    void setNode(const std::string &node);

    //! Set the service
    void setService(const std::string &service);

    //! Get the socket type from the scheme
    int getType(void) const;

private:
    std::string _scheme;
    std::string _node;
    std::string _service;
};