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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/crt/io/Uri.h>
namespace Aws
{
namespace Crt
{
namespace Io
{
Uri::Uri() noexcept : m_lastError(AWS_ERROR_SUCCESS), m_isInit(false) { AWS_ZERO_STRUCT(m_uri); }
Uri::~Uri()
{
if (m_isInit)
{
aws_uri_clean_up(&m_uri);
m_isInit = false;
}
}
Uri::Uri(const ByteCursor &cursor, Allocator *allocator) noexcept
: m_lastError(AWS_ERROR_SUCCESS), m_isInit(false)
{
if (!aws_uri_init_parse(&m_uri, allocator, &cursor))
{
m_isInit = true;
}
else
{
m_lastError = aws_last_error();
}
}
Uri::Uri(aws_uri_builder_options &builderOptions, Allocator *allocator) noexcept
: m_lastError(AWS_ERROR_SUCCESS), m_isInit(false)
{
if (!aws_uri_init_from_builder_options(&m_uri, allocator, &builderOptions))
{
m_isInit = true;
}
else
{
m_lastError = aws_last_error();
}
}
Uri::Uri(const Uri &other) : m_lastError(AWS_ERROR_SUCCESS), m_isInit(false)
{
if (other.m_isInit)
{
ByteCursor uriCursor = other.GetFullUri();
if (!aws_uri_init_parse(&m_uri, other.m_uri.allocator, &uriCursor))
{
m_isInit = true;
}
else
{
m_lastError = aws_last_error();
}
}
}
Uri &Uri::operator=(const Uri &other)
{
if (this != &other)
{
m_isInit = false;
m_lastError = AWS_ERROR_SUCCESS;
if (other.m_isInit)
{
ByteCursor uriCursor = other.GetFullUri();
if (!aws_uri_init_parse(&m_uri, other.m_uri.allocator, &uriCursor))
{
m_isInit = true;
}
else
{
m_lastError = aws_last_error();
}
}
}
return *this;
}
Uri::Uri(Uri &&uri) noexcept : m_lastError(AWS_ERROR_SUCCESS), m_isInit(uri.m_isInit)
{
if (uri.m_isInit)
{
m_uri = uri.m_uri;
AWS_ZERO_STRUCT(uri.m_uri);
uri.m_isInit = false;
}
}
Uri &Uri::operator=(Uri &&uri) noexcept
{
if (this != &uri)
{
if (m_isInit)
{
aws_uri_clean_up(&m_uri);
}
if (uri.m_isInit)
{
m_uri = uri.m_uri;
AWS_ZERO_STRUCT(uri.m_uri);
uri.m_isInit = false;
m_isInit = true;
m_lastError = AWS_ERROR_SUCCESS;
}
else
{
m_lastError = uri.m_lastError;
}
}
return *this;
}
ByteCursor Uri::GetScheme() const noexcept { return m_uri.scheme; }
ByteCursor Uri::GetAuthority() const noexcept { return m_uri.authority; }
ByteCursor Uri::GetPath() const noexcept { return m_uri.path; }
ByteCursor Uri::GetQueryString() const noexcept { return m_uri.query_string; }
ByteCursor Uri::GetHostName() const noexcept { return m_uri.host_name; }
uint16_t Uri::GetPort() const noexcept { return m_uri.port; }
ByteCursor Uri::GetPathAndQuery() const noexcept { return m_uri.path_and_query; }
ByteCursor Uri::GetFullUri() const noexcept { return ByteCursorFromByteBuf(m_uri.uri_str); }
} // namespace Io
} // namespace Crt
} // namespace Aws
|