summaryrefslogtreecommitdiffstats
path: root/xbmc/DbUrl.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
commitc04dcc2e7d834218ef2d4194331e383402495ae1 (patch)
tree7333e38d10d75386e60f336b80c2443c1166031d /xbmc/DbUrl.cpp
parentInitial commit. (diff)
downloadkodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz
kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/DbUrl.cpp')
-rw-r--r--xbmc/DbUrl.cpp136
1 files changed, 136 insertions, 0 deletions
diff --git a/xbmc/DbUrl.cpp b/xbmc/DbUrl.cpp
new file mode 100644
index 0000000..170a736
--- /dev/null
+++ b/xbmc/DbUrl.cpp
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2012-2018 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "DbUrl.h"
+
+#include "utils/URIUtils.h"
+
+CDbUrl::CDbUrl()
+{
+ Reset();
+}
+
+CDbUrl::~CDbUrl() = default;
+
+void CDbUrl::Reset()
+{
+ m_valid = false;
+ m_type.clear();
+ m_url.Reset();
+ m_options.clear();
+}
+
+std::string CDbUrl::ToString() const
+{
+ if (!m_valid)
+ return "";
+
+ return m_url.Get();
+}
+
+bool CDbUrl::FromString(const std::string &dbUrl)
+{
+ Reset();
+
+ m_url.Parse(dbUrl);
+ m_valid = parse();
+
+ if (!m_valid)
+ Reset();
+
+ return m_valid;
+}
+
+void CDbUrl::AppendPath(const std::string &subPath)
+{
+ if (!m_valid || subPath.empty())
+ return;
+
+ m_url.SetFileName(URIUtils::AddFileToFolder(m_url.GetFileName(), subPath));
+}
+
+void CDbUrl::AddOption(const std::string &key, const char *value)
+{
+ if (!validateOption(key, value))
+ return;
+
+ CUrlOptions::AddOption(key, value);
+ updateOptions();
+}
+
+void CDbUrl::AddOption(const std::string &key, const std::string &value)
+{
+ if (!validateOption(key, value))
+ return;
+
+ CUrlOptions::AddOption(key, value);
+ updateOptions();
+}
+
+void CDbUrl::AddOption(const std::string &key, int value)
+{
+ if (!validateOption(key, value))
+ return;
+
+ CUrlOptions::AddOption(key, value);
+ updateOptions();
+}
+
+void CDbUrl::AddOption(const std::string &key, float value)
+{
+ if (!validateOption(key, value))
+ return;
+
+ CUrlOptions::AddOption(key, value);
+ updateOptions();
+}
+
+void CDbUrl::AddOption(const std::string &key, double value)
+{
+ if (!validateOption(key, value))
+ return;
+
+ CUrlOptions::AddOption(key, value);
+ updateOptions();
+}
+
+void CDbUrl::AddOption(const std::string &key, bool value)
+{
+ if (!validateOption(key, value))
+ return;
+
+ CUrlOptions::AddOption(key, value);
+ updateOptions();
+}
+
+void CDbUrl::AddOptions(const std::string &options)
+{
+ CUrlOptions::AddOptions(options);
+ updateOptions();
+}
+
+void CDbUrl::RemoveOption(const std::string &key)
+{
+ CUrlOptions::RemoveOption(key);
+ updateOptions();
+}
+
+bool CDbUrl::validateOption(const std::string &key, const CVariant &value)
+{
+ return !key.empty();
+}
+
+void CDbUrl::updateOptions()
+{
+ // Update the options string in the CURL object
+ std::string options = GetOptionsString();
+ if (!options.empty())
+ options = "?" + options;
+
+ m_url.SetOptions(options);
+}