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 
49 namespace UPnPProvider {
50 
51 class VirtualDir {
52 public:
53 
55  static VirtualDir* getVirtualDir();
56 
62  bool addFile(const std::string& path, const std::string& name,
63  const std::string& content, const std::string& mimetype);
64 
65  class FileInfo {
66  public:
67  FileInfo()
68  : file_length(0), last_modified(0), is_directory(false),
69  is_readable(true) {
70  }
71 
72  off_t file_length;
73  time_t last_modified;
74  bool is_directory;
75  bool is_readable;
76  std::string mime;
77  };
78 
79  class FileOps {
80  public:
81  std::function<int (const std::string&, FileInfo*)> getinfo;
82  std::function<void *(const std::string&)> open;
83  std::function<int (void *hdl, char* buf, size_t cnt)> read;
84  std::function<off_t (void *hdl, off_t offs, int whence)> seek;
85  std::function<void (void *hdl)> close;
86  };
87 
90  bool addVDir(const std::string& path, FileOps fops);
91 
92 private:
93  VirtualDir() {}
94  VirtualDir(VirtualDir const&) = delete;
95  VirtualDir& operator=(VirtualDir const&) = delete;
96 };
97 
98 }
99 
100 #endif /* _VDIR_H_X_INCLUDED_ */
static VirtualDir * getVirtualDir()
Get hold of the global object.
Definition: vdir.cxx:270
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
Definition: vdir.hxx:79
Definition: vdir.hxx:65
Virtual directory handler to satisfy libupnp miniserver GETs.
Definition: device.cxx:49
bool addVDir(const std::string &path, FileOps fops)
Add virtual directory entry.
Definition: vdir.cxx:124
Definition: vdir.hxx:51