mirror of
https://github.com/badaix/snapcast.git
synced 2025-06-07 05:11:43 +02:00
add clang-format file
reformat code
This commit is contained in:
parent
b733f646ea
commit
b20add3815
105 changed files with 7773 additions and 7723 deletions
|
@ -1,6 +1,6 @@
|
|||
/***
|
||||
This file is part of snapcast
|
||||
Copyright (C) 2014-2018 Johannes Pohl
|
||||
Copyright (C) 2014-2019 Johannes Pohl
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -17,9 +17,9 @@
|
|||
***/
|
||||
|
||||
#include "streamUri.h"
|
||||
#include "common/utils/string_utils.h"
|
||||
#include "common/strCompat.h"
|
||||
#include "aixlog.hpp"
|
||||
#include "common/strCompat.h"
|
||||
#include "common/utils/string_utils.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
@ -28,123 +28,116 @@ namespace strutils = utils::string;
|
|||
|
||||
StreamUri::StreamUri(const std::string& uri)
|
||||
{
|
||||
parse(uri);
|
||||
parse(uri);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void StreamUri::parse(const std::string& streamUri)
|
||||
{
|
||||
// https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
|
||||
// scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
|
||||
// would be more elegant with regex. Not yet supported on my dev machine's gcc 4.8 :(
|
||||
LOG(DEBUG) << "StreamUri: " << streamUri << "\n";
|
||||
size_t pos;
|
||||
uri = strutils::trim_copy(streamUri);
|
||||
while (!uri.empty() && ((uri[0] == '\'') || (uri[0] == '"')))
|
||||
uri = uri.substr(1);
|
||||
while (!uri.empty() && ((uri[uri.length()-1] == '\'') || (uri[uri.length()-1] == '"')))
|
||||
uri = uri.substr(0, this->uri.length()-1);
|
||||
// https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
|
||||
// scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
|
||||
// would be more elegant with regex. Not yet supported on my dev machine's gcc 4.8 :(
|
||||
LOG(DEBUG) << "StreamUri: " << streamUri << "\n";
|
||||
size_t pos;
|
||||
uri = strutils::trim_copy(streamUri);
|
||||
while (!uri.empty() && ((uri[0] == '\'') || (uri[0] == '"')))
|
||||
uri = uri.substr(1);
|
||||
while (!uri.empty() && ((uri[uri.length() - 1] == '\'') || (uri[uri.length() - 1] == '"')))
|
||||
uri = uri.substr(0, this->uri.length() - 1);
|
||||
|
||||
string decodedUri = strutils::uriDecode(uri);
|
||||
LOG(DEBUG) << "StreamUri: " << decodedUri << "\n";
|
||||
string decodedUri = strutils::uriDecode(uri);
|
||||
LOG(DEBUG) << "StreamUri: " << decodedUri << "\n";
|
||||
|
||||
string tmp(decodedUri);
|
||||
string tmp(decodedUri);
|
||||
|
||||
pos = tmp.find(':');
|
||||
if (pos == string::npos)
|
||||
throw invalid_argument("missing ':'");
|
||||
scheme = strutils::trim_copy(tmp.substr(0, pos));
|
||||
tmp = tmp.substr(pos + 1);
|
||||
LOG(DEBUG) << "scheme: '" << scheme << "' tmp: '" << tmp << "'\n";
|
||||
pos = tmp.find(':');
|
||||
if (pos == string::npos)
|
||||
throw invalid_argument("missing ':'");
|
||||
scheme = strutils::trim_copy(tmp.substr(0, pos));
|
||||
tmp = tmp.substr(pos + 1);
|
||||
LOG(DEBUG) << "scheme: '" << scheme << "' tmp: '" << tmp << "'\n";
|
||||
|
||||
if (tmp.find("//") != 0)
|
||||
throw invalid_argument("missing host separator: '//'");
|
||||
tmp = tmp.substr(2);
|
||||
if (tmp.find("//") != 0)
|
||||
throw invalid_argument("missing host separator: '//'");
|
||||
tmp = tmp.substr(2);
|
||||
|
||||
pos = tmp.find('/');
|
||||
if (pos == string::npos)
|
||||
throw invalid_argument("missing path separator: '/'");
|
||||
host = strutils::trim_copy(tmp.substr(0, pos));
|
||||
tmp = tmp.substr(pos);
|
||||
path = tmp;
|
||||
LOG(DEBUG) << "host: '" << host << "' tmp: '" << tmp << "' path: '" << path << "'\n";
|
||||
pos = tmp.find('/');
|
||||
if (pos == string::npos)
|
||||
throw invalid_argument("missing path separator: '/'");
|
||||
host = strutils::trim_copy(tmp.substr(0, pos));
|
||||
tmp = tmp.substr(pos);
|
||||
path = tmp;
|
||||
LOG(DEBUG) << "host: '" << host << "' tmp: '" << tmp << "' path: '" << path << "'\n";
|
||||
|
||||
pos = tmp.find('?');
|
||||
if (pos == string::npos)
|
||||
return;
|
||||
pos = tmp.find('?');
|
||||
if (pos == string::npos)
|
||||
return;
|
||||
|
||||
path = strutils::trim_copy(tmp.substr(0, pos));
|
||||
tmp = tmp.substr(pos + 1);
|
||||
string queryStr = tmp;
|
||||
LOG(DEBUG) << "path: '" << path << "' tmp: '" << tmp << "' query: '" << queryStr << "'\n";
|
||||
path = strutils::trim_copy(tmp.substr(0, pos));
|
||||
tmp = tmp.substr(pos + 1);
|
||||
string queryStr = tmp;
|
||||
LOG(DEBUG) << "path: '" << path << "' tmp: '" << tmp << "' query: '" << queryStr << "'\n";
|
||||
|
||||
pos = tmp.find('#');
|
||||
if (pos != string::npos)
|
||||
{
|
||||
queryStr = tmp.substr(0, pos);
|
||||
tmp = tmp.substr(pos + 1);
|
||||
fragment = strutils::trim_copy(tmp);
|
||||
LOG(DEBUG) << "query: '" << queryStr << "' fragment: '" << fragment << "' tmp: '" << tmp << "'\n";
|
||||
}
|
||||
pos = tmp.find('#');
|
||||
if (pos != string::npos)
|
||||
{
|
||||
queryStr = tmp.substr(0, pos);
|
||||
tmp = tmp.substr(pos + 1);
|
||||
fragment = strutils::trim_copy(tmp);
|
||||
LOG(DEBUG) << "query: '" << queryStr << "' fragment: '" << fragment << "' tmp: '" << tmp << "'\n";
|
||||
}
|
||||
|
||||
vector<string> keyValueList = strutils::split(queryStr, '&');
|
||||
for (auto& kv: keyValueList)
|
||||
{
|
||||
pos = kv.find('=');
|
||||
if (pos != string::npos)
|
||||
{
|
||||
string key = strutils::trim_copy(kv.substr(0, pos));
|
||||
string value = strutils::trim_copy(kv.substr(pos+1));
|
||||
query[key] = value;
|
||||
}
|
||||
}
|
||||
LOG(DEBUG) << "StreamUri.toString: " << toString() << "\n";
|
||||
vector<string> keyValueList = strutils::split(queryStr, '&');
|
||||
for (auto& kv : keyValueList)
|
||||
{
|
||||
pos = kv.find('=');
|
||||
if (pos != string::npos)
|
||||
{
|
||||
string key = strutils::trim_copy(kv.substr(0, pos));
|
||||
string value = strutils::trim_copy(kv.substr(pos + 1));
|
||||
query[key] = value;
|
||||
}
|
||||
}
|
||||
LOG(DEBUG) << "StreamUri.toString: " << toString() << "\n";
|
||||
}
|
||||
|
||||
|
||||
std::string StreamUri::toString() const
|
||||
{
|
||||
// scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
|
||||
stringstream ss;
|
||||
ss << scheme << "://" << host << "/" + path;
|
||||
if (!query.empty())
|
||||
{
|
||||
ss << "?";
|
||||
auto iter = query.begin();
|
||||
while (true)
|
||||
{
|
||||
ss << iter->first << "=" << iter->second;
|
||||
if (++iter == query.end())
|
||||
break;
|
||||
ss << "&";
|
||||
}
|
||||
}
|
||||
if (!fragment.empty())
|
||||
ss << "#" << fragment;
|
||||
// scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
|
||||
stringstream ss;
|
||||
ss << scheme << "://" << host << "/" + path;
|
||||
if (!query.empty())
|
||||
{
|
||||
ss << "?";
|
||||
auto iter = query.begin();
|
||||
while (true)
|
||||
{
|
||||
ss << iter->first << "=" << iter->second;
|
||||
if (++iter == query.end())
|
||||
break;
|
||||
ss << "&";
|
||||
}
|
||||
}
|
||||
if (!fragment.empty())
|
||||
ss << "#" << fragment;
|
||||
|
||||
return ss.str();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
json StreamUri::toJson() const
|
||||
{
|
||||
json j = {
|
||||
{"raw", toString()},
|
||||
{"scheme", scheme},
|
||||
{"host", host},
|
||||
{"path", path},
|
||||
{"fragment", fragment},
|
||||
{"query", query}
|
||||
};
|
||||
return j;
|
||||
json j = {{"raw", toString()}, {"scheme", scheme}, {"host", host}, {"path", path}, {"fragment", fragment}, {"query", query}};
|
||||
return j;
|
||||
}
|
||||
|
||||
|
||||
std::string StreamUri::getQuery(const std::string& key, const std::string& def) const
|
||||
{
|
||||
auto iter = query.find(key);
|
||||
if (iter != query.end())
|
||||
return iter->second;
|
||||
return def;
|
||||
auto iter = query.find(key);
|
||||
if (iter != query.end())
|
||||
return iter->second;
|
||||
return def;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue