diff options
author | Petr Mrázek <peterix@gmail.com> | 2014-05-05 00:10:59 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2014-06-09 01:38:29 +0200 |
commit | 4c3bd416c65ec887209fa06b0a5634099b77f322 (patch) | |
tree | f656031d147aba8f8dd621de2bd452ea1bfd86b4 /logic/URNResolver.cpp | |
parent | aade36860c373268857ca821c14a13f38c880b1a (diff) | |
download | MultiMC-4c3bd416c65ec887209fa06b0a5634099b77f322.tar MultiMC-4c3bd416c65ec887209fa06b0a5634099b77f322.tar.gz MultiMC-4c3bd416c65ec887209fa06b0a5634099b77f322.tar.lz MultiMC-4c3bd416c65ec887209fa06b0a5634099b77f322.tar.xz MultiMC-4c3bd416c65ec887209fa06b0a5634099b77f322.zip |
Much change, very jarmod.
Diffstat (limited to 'logic/URNResolver.cpp')
-rw-r--r-- | logic/URNResolver.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/logic/URNResolver.cpp b/logic/URNResolver.cpp new file mode 100644 index 00000000..b6bdcf41 --- /dev/null +++ b/logic/URNResolver.cpp @@ -0,0 +1,98 @@ +#include "URNResolver.h" +#include <logger/QsLog.h> +#include "MultiMC.h" +#include "logic/forge/ForgeVersionList.h" +#include "logic/forge/ForgeVersion.h" + +QString unescapeNSS(QString RawNSS) +{ + QString NSS; + NSS.reserve(RawNSS.size()); + enum + { + Normal, + FirstHex, + SecondHex + } ParseState = Normal; + + QByteArray translator(" "); + + for (auto ch : RawNSS) + { + if(ParseState == Normal) + { + if(ch == '%') + { + ParseState = FirstHex; + continue; + } + else + { + NSS.append(ch); + } + } + if(ParseState == FirstHex) + { + translator[0] = ch.toLower().unicode(); + ParseState = SecondHex; + } + else if(ParseState == SecondHex) + { + translator[1] = ch.toLower().unicode(); + auto result = QByteArray::fromHex(translator); + if (result[0] == '\0') + return NSS; + NSS.append(result); + ParseState = Normal; + } + } + return NSS; +} + +bool URNResolver::parse(const QString &URN, QString &NID, QString &NSS) +{ + QRegExp URNPattern( + "^urn:([a-z0-9][a-z0-9-]{0,31}):(([a-z0-9()+,\\-.:=@;$_!*']|%[0-9a-f]{2})+).*", + Qt::CaseInsensitive); + if (URNPattern.indexIn(URN) == -1) + return false; + auto captures = URNPattern.capturedTexts(); + QString RawNID = captures[1]; + QString RawNSS = captures[2]; + + NID = RawNID.toLower(); + NSS = unescapeNSS(RawNSS); + return true; +} + +URNResolver::URNResolver() +{ +} + +QVariant URNResolver::resolve(QString URN) +{ + QString NID, NSS; + parse(URN, NID, NSS); + + if(NID != "x-mmc") + return QVariant(); + auto parts = NSS.split(":"); + if(parts.size() < 1) + return QVariant(); + unsigned int version = parts[0].toUInt(); + switch(version) + { + case 1: + return resolveV1(parts.mid(1)); + default: + return QVariant(); + } +} + +/** + * TODO: implement. + */ +QVariant URNResolver::resolveV1(QStringList parts) +{ + return QVariant(); +} |