libupnpp 0.16.0
A C++ wrapper for the Portable UPnP reference library
vdir.hxx
1/* Copyright (C) 2006-2016 J.F.Dockes
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301 USA
17 */
18#ifndef _VDIR_H_X_INCLUDED_
19#define _VDIR_H_X_INCLUDED_
20
21// This is normally supplied by config.h for the internal C++ code,
22// but we now avoid exposing this in the public include files. Note
23// that this is not optional as libupnp is always built with large
24// file support and we need to be the same
25#define _FILE_OFFSET_BITS 64
26
27#include <time.h>
28#include <sys/types.h>
29#include <stddef.h>
30
31#include <string>
32#include <functional>
33
34
47
48
49namespace UPnPProvider {
50
52public:
53 VirtualDir(const VirtualDir&) = delete;
54 VirtualDir& operator=(const VirtualDir&) = delete;
55
57 static VirtualDir* getVirtualDir();
58
64 bool addFile(const std::string& path, const std::string& name,
65 const std::string& content, const std::string& mimetype);
66
67 class FileInfo {
68 public:
69 off_t file_length{0};
70 time_t last_modified{0};
71 bool is_directory{false};
72 bool is_readable{true};
73 std::string mime;
74 };
75
76 class FileOps {
77 public:
78 std::function<int (const std::string&, FileInfo*)> getinfo;
79 std::function<void *(const std::string&)> open;
80 std::function<int (void *hdl, char* buf, size_t cnt)> read;
81 std::function<off_t (void *hdl, off_t offs, int whence)> seek;
82 std::function<void (void *hdl)> close;
83 };
84
87 bool addVDir(const std::string& path, FileOps fops);
88
89private:
90 VirtualDir() = default;
91};
92
93}
94
95#endif /* _VDIR_H_X_INCLUDED_ */
Definition vdir.hxx:76
Definition vdir.hxx:51
bool addVDir(const std::string &path, FileOps fops)
Add virtual directory entry.
Definition vdir.cxx:124
bool addFile(const std::string &path, const std::string &name, const std::string &content, const std::string &mimetype)
Add file entry, to be served internally.
Definition vdir.cxx:100
static VirtualDir * getVirtualDir()
Get hold of the global object.
Definition vdir.cxx:271
Virtual directory handler to satisfy libupnp miniserver GETs.
Definition devdevice.cxx:55