mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 05:17:24 +02:00
Split MIMETypeLibrary file type detection into three separate functions
This commit is contained in:
parent
660d8c4e92
commit
19459c15a5
3 changed files with 21 additions and 4 deletions
|
@ -50,7 +50,14 @@ std::shared_ptr<Serializer> FormatRegistry::getSerializerForMIMEType(const hifi:
|
||||||
{
|
{
|
||||||
// TODO: shared_lock in C++14
|
// TODO: shared_lock in C++14
|
||||||
std::lock_guard<std::mutex> lock(*const_cast<std::mutex*>(&_libraryLock));
|
std::lock_guard<std::mutex> lock(*const_cast<std::mutex*>(&_libraryLock));
|
||||||
id = _mimeTypeLibrary.findMatchingMIMEType(data, url, webMediaType);
|
|
||||||
|
id = _mimeTypeLibrary.findMIMETypeForData(data);
|
||||||
|
if (id == INVALID_MIME_TYPE_ID) {
|
||||||
|
id = _mimeTypeLibrary.findMIMETypeForURL(url);
|
||||||
|
}
|
||||||
|
if (id == INVALID_MIME_TYPE_ID) {
|
||||||
|
id = _mimeTypeLibrary.findMIMETypeForMediaType(webMediaType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return getSerializerForMIMETypeID(id);
|
return getSerializerForMIMETypeID(id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ MIMEType MIMETypeLibrary::getMIMEType(const MIMETypeLibrary::ID& id) const {
|
||||||
return MIMEType::NONE;
|
return MIMEType::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
MIMETypeLibrary::ID MIMETypeLibrary::findMatchingMIMEType(const hifi::ByteArray& data, const hifi::URL& url, const std::string& webMediaType) const {
|
MIMETypeLibrary::ID MIMETypeLibrary::findMIMETypeForData(const hifi::ByteArray& data) const {
|
||||||
// Check file contents
|
// Check file contents
|
||||||
for (auto& mimeType : _mimeTypes) {
|
for (auto& mimeType : _mimeTypes) {
|
||||||
for (auto& fileSignature : mimeType.mimeType.fileSignatures) {
|
for (auto& fileSignature : mimeType.mimeType.fileSignatures) {
|
||||||
|
@ -46,6 +46,10 @@ MIMETypeLibrary::ID MIMETypeLibrary::findMatchingMIMEType(const hifi::ByteArray&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return INVALID_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
MIMETypeLibrary::ID MIMETypeLibrary::findMIMETypeForURL(const hifi::URL& url) const {
|
||||||
// Check file extension
|
// Check file extension
|
||||||
std::string urlString = url.path().toStdString();
|
std::string urlString = url.path().toStdString();
|
||||||
std::size_t extensionSeparator = urlString.rfind('.');
|
std::size_t extensionSeparator = urlString.rfind('.');
|
||||||
|
@ -60,6 +64,10 @@ MIMETypeLibrary::ID MIMETypeLibrary::findMatchingMIMEType(const hifi::ByteArray&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return INVALID_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
MIMETypeLibrary::ID MIMETypeLibrary::findMIMETypeForMediaType(const std::string& webMediaType) const {
|
||||||
// Check web media type
|
// Check web media type
|
||||||
if (webMediaType != "") {
|
if (webMediaType != "") {
|
||||||
for (auto& supportedFormat : _mimeTypes) {
|
for (auto& supportedFormat : _mimeTypes) {
|
||||||
|
@ -71,6 +79,5 @@ MIMETypeLibrary::ID MIMETypeLibrary::findMatchingMIMEType(const hifi::ByteArray&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supported file type not found.
|
|
||||||
return INVALID_ID;
|
return INVALID_ID;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,10 @@ public:
|
||||||
void unregisterMIMEType(const ID& id);
|
void unregisterMIMEType(const ID& id);
|
||||||
|
|
||||||
MIMEType getMIMEType(const ID& id) const;
|
MIMEType getMIMEType(const ID& id) const;
|
||||||
ID findMatchingMIMEType(const hifi::ByteArray& data, const hifi::URL& url, const std::string& webMediaType) const;
|
|
||||||
|
ID findMIMETypeForData(const hifi::ByteArray& data) const;
|
||||||
|
ID findMIMETypeForURL(const hifi::URL& url) const;
|
||||||
|
ID findMIMETypeForMediaType(const std::string& webMediaType) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ID nextID { 1 };
|
ID nextID { 1 };
|
||||||
|
|
Loading…
Reference in a new issue