2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Copyright The Music Player Daemon Project
|
2015-10-22 09:29:02 +02:00
|
|
|
|
|
|
|
#ifndef MPD_LOCATE_URI_HXX
|
|
|
|
#define MPD_LOCATE_URI_HXX
|
|
|
|
|
2018-11-19 12:49:45 +01:00
|
|
|
#include "config.h"
|
2015-10-22 09:29:02 +02:00
|
|
|
#include "fs/AllocatedPath.hxx"
|
|
|
|
|
2017-12-12 10:22:20 +01:00
|
|
|
#ifdef _WIN32
|
2015-10-22 09:29:02 +02:00
|
|
|
#include <windows.h>
|
|
|
|
/* damn you, windows.h! */
|
|
|
|
#ifdef ABSOLUTE
|
|
|
|
#undef ABSOLUTE
|
|
|
|
#endif
|
|
|
|
#ifdef RELATIVE
|
|
|
|
#undef RELATIVE
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2023-11-25 23:06:24 +01:00
|
|
|
class IClient;
|
2015-10-22 09:29:02 +02:00
|
|
|
|
|
|
|
#ifdef ENABLE_DATABASE
|
|
|
|
class Storage;
|
|
|
|
#endif
|
|
|
|
|
2019-04-18 10:03:15 +02:00
|
|
|
enum class UriPluginKind {
|
|
|
|
INPUT,
|
|
|
|
STORAGE,
|
|
|
|
PLAYLIST,
|
|
|
|
};
|
|
|
|
|
2015-10-22 09:29:02 +02:00
|
|
|
struct LocatedUri {
|
|
|
|
enum class Type {
|
|
|
|
/**
|
|
|
|
* An absolute URI with a supported scheme.
|
|
|
|
*/
|
|
|
|
ABSOLUTE,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A relative URI path.
|
|
|
|
*/
|
|
|
|
RELATIVE,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A local file. The #path attribute is valid.
|
|
|
|
*/
|
|
|
|
PATH,
|
|
|
|
} type;
|
|
|
|
|
|
|
|
const char *canonical_uri;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains the local file path if type==FILE.
|
|
|
|
*/
|
|
|
|
AllocatedPath path;
|
|
|
|
|
|
|
|
LocatedUri(Type _type, const char *_uri,
|
2018-01-17 12:17:41 +01:00
|
|
|
AllocatedPath &&_path=nullptr)
|
2015-10-22 09:29:02 +02:00
|
|
|
:type(_type), canonical_uri(_uri), path(std::move(_path)) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Classify a URI.
|
|
|
|
*
|
2016-10-27 21:59:17 +02:00
|
|
|
* Throws #std::runtime_error on error.
|
|
|
|
*
|
2023-11-25 23:06:24 +01:00
|
|
|
* @param client the #IClient that is used to determine whether a local
|
2015-10-22 09:29:02 +02:00
|
|
|
* file is allowed; nullptr disables the check and allows all local
|
|
|
|
* files
|
|
|
|
* @param storage a #Storage instance which may be used to convert
|
|
|
|
* absolute URIs to relative ones, using Storage::MapToRelativeUTF8();
|
|
|
|
* that feature is disabled if this parameter is nullptr
|
|
|
|
*/
|
|
|
|
LocatedUri
|
2019-04-18 10:03:15 +02:00
|
|
|
LocateUri(UriPluginKind kind,
|
2023-11-25 23:06:24 +01:00
|
|
|
const char *uri, const IClient *client
|
2015-10-22 09:29:02 +02:00
|
|
|
#ifdef ENABLE_DATABASE
|
2016-10-27 21:59:17 +02:00
|
|
|
, const Storage *storage
|
2015-10-22 09:29:02 +02:00
|
|
|
#endif
|
2016-10-27 21:59:17 +02:00
|
|
|
);
|
2015-10-22 09:29:02 +02:00
|
|
|
|
|
|
|
#endif
|