LocateUri.hxx 2.2 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2021 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 * http://www.musicpd.org
 *
 * 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
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef MPD_LOCATE_URI_HXX
#define MPD_LOCATE_URI_HXX

23
#include "config.h"
24 25
#include "fs/AllocatedPath.hxx"

26
#ifdef _WIN32
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#include <windows.h>
/* damn you, windows.h! */
#ifdef ABSOLUTE
#undef ABSOLUTE
#endif
#ifdef RELATIVE
#undef RELATIVE
#endif
#endif

class Client;

#ifdef ENABLE_DATABASE
class Storage;
#endif

43 44 45 46 47 48
enum class UriPluginKind {
	INPUT,
	STORAGE,
	PLAYLIST,
};

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
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,
75
		   AllocatedPath &&_path=nullptr)
76 77 78 79 80 81
		:type(_type), canonical_uri(_uri), path(std::move(_path)) {}
};

/**
 * Classify a URI.
 *
82 83
 * Throws #std::runtime_error on error.
 *
84 85 86 87 88 89 90 91
 * @param client the #Client that is used to determine whether a local
 * 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
92 93
LocateUri(UriPluginKind kind,
	  const char *uri, const Client *client
94
#ifdef ENABLE_DATABASE
95
	  , const Storage *storage
96
#endif
97
	  );
98 99

#endif