Skip to content

Commit

Permalink
Fixed issue where nullptr was not returned when URL parsing failed
Browse files Browse the repository at this point in the history
  • Loading branch information
dimiden committed Nov 18, 2024
1 parent d361740 commit 4c4ca98
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 52 deletions.
34 changes: 17 additions & 17 deletions src/projects/base/ovlibrary/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ namespace ov
using UnderylingType = std::underlying_type_t<T>;
} // namespace ov

#define OV_DEFINE_SETTER(type, setter, member, extra_qualifier, pre_process, post_process) \
void setter(const type &value) extra_qualifier \
{ \
pre_process; \
member = value; \
post_process; \
#define OV_DEFINE_SETTER(value_type, setter_return, setter, member, extra_qualifier, pre_process, post_process) \
setter_return setter(const value_type &value) extra_qualifier \
{ \
pre_process; \
member = value; \
post_process; \
}

#define OV_DEFINE_GETTER(type, getter, member, extra_qualifier) \
type getter() extra_qualifier \
{ \
return member; \
}

#define OV_DEFINE_CONST_GETTER(type, getter, member, extra_qualifier) \
const type &getter() const extra_qualifier \
#define OV_DEFINE_GETTER(value_type, getter, member, extra_qualifier) \
value_type getter() extra_qualifier \
{ \
return member; \
}

#define OV_DEFINE_SETTER_CONST_GETTER(type, setter, getter, member, extra_qualifier, pre_process, post_process) \
OV_DEFINE_SETTER(type, setter, member, extra_qualifier, pre_process, post_process) \
OV_DEFINE_CONST_GETTER(type, getter, member, extra_qualifier)
#define OV_DEFINE_CONST_GETTER(value_type, getter, member, extra_qualifier) \
const value_type &getter() const extra_qualifier \
{ \
return member; \
}

#define OV_DEFINE_SETTER_CONST_GETTER(value_type, setter_return, setter, getter, member, extra_qualifier, pre_process, post_process) \
OV_DEFINE_SETTER(value_type, setter_return, setter, member, extra_qualifier, pre_process, post_process) \
OV_DEFINE_CONST_GETTER(value_type, getter, member, extra_qualifier)
61 changes: 37 additions & 24 deletions src/projects/base/ovlibrary/url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,14 @@ namespace ov
return result_string;
}

void Url::SetPath(const ov::String &path)
bool Url::SetPath(const ov::String &path)
{
_path = path;

_file = "";
_stream = "";
_app = "";

// split <path> to /<app>/<stream>/<file> (4 tokens)
auto tokens = _path.Split("/");

Expand All @@ -142,6 +146,8 @@ namespace ov
// Nothing to do
break;
}

return true;
}

bool Url::ParseFromSource()
Expand Down Expand Up @@ -186,9 +192,12 @@ namespace ov
{
auto object = std::make_shared<Url>();

object->SetSource(url);
if (object->SetSource(url))
{
return object;
}

return object;
return nullptr;
}

bool Url::PushBackQueryKey(const ov::String &key)
Expand Down Expand Up @@ -268,37 +277,37 @@ namespace ov
return true;
}

void Url::UpdateUrl(bool is_source_updated)
bool Url::UpdateUrl(bool is_source_updated)
{
if (is_source_updated)
{
// Get component values from the _source
ParseFromSource();
return ParseFromSource();
}
else
{
_source = ToUrlString();

_path = "";
_source = ToUrlString();

if (_app.IsEmpty() == false)
{
_path.Append("/");
_path.Append(_app);
}
_path = "";

if (_stream.IsEmpty() == false)
{
_path.Append("/");
_path.Append(_stream);
}
if (_app.IsEmpty() == false)
{
_path.Append("/");
_path.Append(_app);
}

if (_file.IsEmpty() == false)
{
_path.Append("/");
_path.Append(_file);
}
if (_stream.IsEmpty() == false)
{
_path.Append("/");
_path.Append(_stream);
}

if (_file.IsEmpty() == false)
{
_path.Append("/");
_path.Append(_file);
}

return true;
}

void Url::ParseQueryIfNeeded() const
Expand Down Expand Up @@ -383,6 +392,8 @@ namespace ov
{
_source = other._source;
_scheme = other._scheme;
_id = other._id;
_password = other._password;
_host = other._host;
_port = other._port;
_path = other._path;
Expand All @@ -401,6 +412,8 @@ namespace ov
{
_source = other._source;
_scheme = other._scheme;
_id = other._id;
_password = other._password;
_host = other._host;
_port = other._port;
_path = other._path;
Expand Down
22 changes: 11 additions & 11 deletions src/projects/base/ovlibrary/url.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ namespace ov
// <scheme>://<host>[:<port>][/<path/to/resource>][?<query string>]
static std::shared_ptr<Url> Parse(const ov::String &url);

OV_DEFINE_SETTER_CONST_GETTER(ov::String, SetSource, Source, _source, , , UpdateUrl(true))
OV_DEFINE_SETTER_CONST_GETTER(ov::String, SetScheme, Scheme, _scheme, , , UpdateUrl(false))
OV_DEFINE_SETTER_CONST_GETTER(ov::String, SetHost, Host, _host, , , UpdateUrl(false))
OV_DEFINE_SETTER_CONST_GETTER(uint32_t, SetPort, Port, _port, , , UpdateUrl(false))
OV_DEFINE_SETTER_CONST_GETTER(ov::String, bool, SetSource, Source, _source, , , return UpdateUrl(true))
OV_DEFINE_SETTER_CONST_GETTER(ov::String, bool, SetScheme, Scheme, _scheme, , , return UpdateUrl(false))
OV_DEFINE_SETTER_CONST_GETTER(ov::String, bool, SetHost, Host, _host, , , return UpdateUrl(false))
OV_DEFINE_SETTER_CONST_GETTER(uint32_t, bool, SetPort, Port, _port, , , return UpdateUrl(false))
OV_DEFINE_CONST_GETTER(ov::String, Path, _path, )
void SetPath(const ov::String &path);
OV_DEFINE_SETTER_CONST_GETTER(ov::String, SetApp, App, _app, , , UpdateUrl(false))
OV_DEFINE_SETTER_CONST_GETTER(ov::String, SetStream, Stream, _stream, , , UpdateUrl(false))
OV_DEFINE_SETTER_CONST_GETTER(ov::String, SetFile, File, _file, , , UpdateUrl(false))
OV_DEFINE_SETTER_CONST_GETTER(ov::String, SetId, Id, _id, , , UpdateUrl(false))
OV_DEFINE_SETTER_CONST_GETTER(ov::String, SetPassword, Password, _password, , , UpdateUrl(false))
bool SetPath(const ov::String &path);
OV_DEFINE_SETTER_CONST_GETTER(ov::String, bool, SetApp, App, _app, , , return UpdateUrl(false))
OV_DEFINE_SETTER_CONST_GETTER(ov::String, bool, SetStream, Stream, _stream, , , return UpdateUrl(false))
OV_DEFINE_SETTER_CONST_GETTER(ov::String, bool, SetFile, File, _file, , , return UpdateUrl(false))
OV_DEFINE_SETTER_CONST_GETTER(ov::String, bool, SetId, Id, _id, , , return UpdateUrl(false))
OV_DEFINE_SETTER_CONST_GETTER(ov::String, bool, SetPassword, Password, _password, , , return UpdateUrl(false))

bool HasQueryString() const;
const ov::String &Query() const;
Expand All @@ -57,7 +57,7 @@ namespace ov

protected:
bool ParseFromSource();
void UpdateUrl(bool is_source_updated);
bool UpdateUrl(bool is_source_updated);

private:
void ParseQueryIfNeeded() const;
Expand Down

0 comments on commit 4c4ca98

Please sign in to comment.