1 /*****************************************************************
3 | Platinum - File Media Server
5 | Copyright (c) 2004-2010, Plutinosoft, LLC.
7 | http://www.plutinosoft.com
9 | This program is free software; you can redistribute it and/or
10 | modify it under the terms of the GNU General Public License
11 | as published by the Free Software Foundation; either version 2
12 | of the License, or (at your option) any later version.
14 | OEMs, ISVs, VARs and other distributors that combine and
15 | distribute commercially licensed software with Platinum software
16 | and do not wish to distribute the source code for the commercially
17 | licensed software under version 2, or (at your option) any later
18 | version, of the GNU General Public License (the "GPL") must enter
19 | into a commercial license agreement with Plutinosoft, LLC.
20 | licensing@plutinosoft.com
22 | This program is distributed in the hope that it will be useful,
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 | GNU General Public License for more details.
27 | You should have received a copy of the GNU General Public License
28 | along with this program; see the file LICENSE.txt. If not, write to
29 | the Free Software Foundation, Inc.,
30 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 | http://www.gnu.org/licenses/gpl-2.0.html
33 ****************************************************************/
36 UPnP AV Filesystem based Media Server sample implementation
39 #ifndef _PLT_FILE_MEDIA_SERVER_H_
40 #define _PLT_FILE_MEDIA_SERVER_H_
42 /*----------------------------------------------------------------------
44 +---------------------------------------------------------------------*/
46 #include "PltMediaServer.h"
47 #include "PltMediaCache.h"
49 /*----------------------------------------------------------------------
50 | PLT_FileMediaServerDelegate
51 +---------------------------------------------------------------------*/
53 File Media Server Delegate.
54 The PLT_FileMediaServerDelegate class is an example of a PLT_MediaServerDelegate
55 implementation for a file system backed Media Server.
57 class PLT_FileMediaServerDelegate
: public PLT_MediaServerDelegate
61 static NPT_String
BuildSafeResourceUri(const NPT_HttpUrl
& base_uri
,
63 const char* file_path
);
64 // constructor & destructor
65 PLT_FileMediaServerDelegate(const char* url_root
, const char* file_root
, bool use_cache
= false);
66 ~PLT_FileMediaServerDelegate() override
;
69 // PLT_MediaServerDelegate methods
70 NPT_Result
OnBrowseMetadata(PLT_ActionReference
& action
,
71 const char* object_id
,
73 NPT_UInt32 starting_index
,
74 NPT_UInt32 requested_count
,
75 const char* sort_criteria
,
76 const PLT_HttpRequestContext
& context
) override
;
77 NPT_Result
OnBrowseDirectChildren(PLT_ActionReference
& action
,
78 const char* object_id
,
80 NPT_UInt32 starting_index
,
81 NPT_UInt32 requested_count
,
82 const char* sort_criteria
,
83 const PLT_HttpRequestContext
& context
) override
;
84 NPT_Result
OnSearchContainer(PLT_ActionReference
& action
,
85 const char* object_id
,
86 const char* search_criteria
,
88 NPT_UInt32 starting_index
,
89 NPT_UInt32 requested_count
,
90 const char* sort_criteria
,
91 const PLT_HttpRequestContext
& context
) override
;
92 NPT_Result
ProcessFileRequest(NPT_HttpRequest
& request
,
93 const NPT_HttpRequestContext
& context
,
94 NPT_HttpResponse
& response
) override
;
96 // overridable methods
97 virtual NPT_Result
ExtractResourcePath(const NPT_HttpUrl
& url
, NPT_String
& file_path
);
98 virtual NPT_String
BuildResourceUri(const NPT_HttpUrl
& base_uri
, const char* host
, const char* file_path
);
99 virtual NPT_Result
ServeFile(const NPT_HttpRequest
& request
,
100 const NPT_HttpRequestContext
& context
,
101 NPT_HttpResponse
& response
,
102 const NPT_String
& file_path
);
103 virtual NPT_Result
GetFilePath(const char* object_id
, NPT_String
& filepath
);
104 virtual bool ProcessFile(const NPT_String
&, const char* filter
= NULL
) { NPT_COMPILER_UNUSED(filter
); return true;}
105 virtual PLT_MediaObject
* BuildFromFilePath(const NPT_String
& filepath
,
106 const PLT_HttpRequestContext
& context
,
107 bool with_count
= true,
108 bool keep_extension_in_title
= false,
112 friend class PLT_MediaItem
;
114 NPT_String m_UrlRoot
;
115 NPT_String m_FileRoot
;
116 bool m_FilterUnknownOut
;
119 PLT_MediaCache
<NPT_Reference
<NPT_List
<NPT_String
> >, NPT_TimeStamp
> m_DirCache
;
122 /*----------------------------------------------------------------------
123 | PLT_FileMediaServer
124 +---------------------------------------------------------------------*/
127 The PLT_FileMediaServer class is an example of a PLT_MediaServer implementation
128 for a file system backed Media Server.
130 class PLT_FileMediaServer
: public PLT_MediaServer
,
131 public PLT_FileMediaServerDelegate
133 public: // constructor
134 PLT_FileMediaServer(const char* file_root
,
135 const char* friendly_name
,
136 bool show_ip
= false,
137 const char* uuid
= NULL
,
139 bool port_rebind
= false) :
140 PLT_MediaServer(friendly_name
,
145 PLT_FileMediaServerDelegate("/", file_root
) {SetDelegate(this);}
148 ~PLT_FileMediaServer() override
{}
151 #endif /* _PLT_FILE_MEDIA_SERVER_H_ */