blob: 91c7a301ac223665c1e1aa2b9d65bfde895f5aee [file] [log] [blame]
Alexander Afanasyev7b9347b2014-02-28 08:37:56 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#ifndef NFD_CORE_FACE_URI_H
8#define NFD_CORE_FACE_URI_H
9
10#include "common.hpp"
11
12namespace nfd {
13
14class FaceUri
15{
16public:
17 class Error : public std::runtime_error
18 {
19 public:
20 Error(const std::string& what) : std::runtime_error(what) {}
21 };
22
23 FaceUri();
24
25 /** \brief Construct URI object
26 *
27 * Expected format: scheme://domain:port/path?query_string#fragment_id
28 *
29 * \throw FaceUri::Error if URI cannot be parsed
30 */
31 explicit
32 FaceUri(const std::string& uri);
33
34 /** \brief Exception-safe parsing of URI
35 */
36 bool
37 parse(const std::string& uri);
38
39 /** \brief Get scheme (protocol) extracted from URI
40 */
41 const std::string&
42 getScheme() const;
43
44 /** \brief Get domain extracted from URI
45 */
46 const std::string&
47 getDomain() const;
48
49 /** \brief Get port extracted from URI
50 *
51 * \return Extracted port or empty string if port wasn't present
52 */
53 const std::string&
54 getPort() const;
55
56 // other getters should be added, when necessary
57
58private:
59 std::string m_scheme;
60 std::string m_domain;
61 std::string m_port;
62};
63
64inline
65FaceUri::FaceUri()
66{
67}
68
69inline const std::string&
70FaceUri::getScheme() const
71{
72 return m_scheme;
73}
74
75inline const std::string&
76FaceUri::getDomain() const
77{
78 return m_domain;
79}
80
81inline const std::string&
82FaceUri::getPort() const
83{
84 return m_port;
85}
86
87} // namespace nfd
88
89#endif // NFD_CORE_FACE_URI_H