1 /*****************************************************************
2 |
3 |   Platinum - AV Media Protocol Info
4 |
5 | Copyright (c) 2004-2010, Plutinosoft, LLC.
6 | All rights reserved.
7 | http://www.plutinosoft.com
8 |
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.
13 |
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
21 |
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.
26 |
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
32 |
33 ****************************************************************/
34 
35 /** @file
36  UPnP AV Media Object Protocol Info.
37  */
38 
39 #ifndef _PLT_PROTOCOL_INFO_H_
40 #define _PLT_PROTOCOL_INFO_H_
41 
42 /*----------------------------------------------------------------------
43 |   includes
44 +---------------------------------------------------------------------*/
45 #include "Neptune.h"
46 #include "PltHttp.h"
47 
48 /*----------------------------------------------------------------------
49 |   forward declarations
50 +---------------------------------------------------------------------*/
51 class PLT_HttpRequestContext;
52 
53 /*----------------------------------------------------------------------
54 |   typedefs
55 +---------------------------------------------------------------------*/
56 typedef struct PLT_HttpFileRequestHandler_DefaultDlnaExtMapEntry {
57     const char* mime_type;
58     const char* dlna_ext;
59 } PLT_HttpFileRequestHandler_DefaultDlnaExtMapEntry ;
60 
61 /*----------------------------------------------------------------------
62 |   PLT_ProtocolInfo
63 +---------------------------------------------------------------------*/
64 /**
65  The PLT_ProtocolInfo class holds information about the protocol info of a
66  given UPnP Media Item resource.
67  */
68 class PLT_ProtocolInfo
69 {
70 public:
71     class FieldEntry {
72     public:
FieldEntry(const char * key,const char * value)73         FieldEntry(const char* key, const char* value) :
74             m_Key(key), m_Value(value) {}
75         NPT_String m_Key;
76         NPT_String m_Value;
77     };
78 
79     // class methods
80     static NPT_String  GetMimeTypeFromProtocolInfo(const char* protocol_info);
81 
82     static const char* GetDlnaExtension(const char* mime_type,
83                                         const PLT_HttpRequestContext* context = NULL);
84     static const char* GetDlnaExtension(const char* mime_type,
85                                         PLT_DeviceSignature signature = PLT_DEVICE_UNKNOWN);
86 
87     static PLT_ProtocolInfo GetProtocolInfo(const char* filename,
88                                             bool with_dlna_extension = true,
89                                             const PLT_HttpRequestContext* context = NULL);
90     static PLT_ProtocolInfo GetProtocolInfo(const char* filename,
91                                             bool with_dlna_extension = true,
92                                             PLT_DeviceSignature signature = PLT_DEVICE_UNKNOWN);
93 
94     static PLT_ProtocolInfo GetProtocolInfoFromMimeType(const char* mime_type,
95                                                         bool with_dlna_extension = true,
96                                                         const PLT_HttpRequestContext* context = NULL);
97     static PLT_ProtocolInfo GetProtocolInfoFromMimeType(const char* mime_type,
98                                                         bool with_dlna_extension = true,
99                                                         PLT_DeviceSignature signature = PLT_DEVICE_UNKNOWN);
100 
101     // methods
102     PLT_ProtocolInfo();
103     //PLT_ProtocolInfo(NPT_String protocol_info);
104     PLT_ProtocolInfo(const char* protocol_info);
105     PLT_ProtocolInfo(const char* protocol,
106                      const char* mask,
107                      const char* content_type,
108                      const char* extra);
GetProtocol()109     const NPT_String& GetProtocol()     const { return m_Protocol;  }
GetMask()110     const NPT_String& GetMask()         const { return m_Mask; }
GetContentType()111     const NPT_String& GetContentType()  const { return m_ContentType;  }
GetExtra()112     const NPT_String& GetExtra()        const { return m_Extra; }
113 
GetDLNA_PN()114     const NPT_String& GetDLNA_PN()      const { return m_DLNA_PN; }
115 
IsValid()116     bool IsValid() { return m_Valid; }
117 
118     NPT_String ToString() const;
119 
120     bool Match(const PLT_ProtocolInfo& other) const;
121 
122 private:
123 	typedef enum {
124 		PLT_PROTINFO_PARSER_STATE_START,
125 		PLT_PROTINFO_PARSER_STATE_PN,
126 		PLT_PROTINFO_PARSER_STATE_OP,
127 		PLT_PROTINFO_PARSER_STATE_PS,
128 		PLT_PROTINFO_PARSER_STATE_CI,
129 		PLT_PROTINFO_PARSER_STATE_FLAGS,
130 		PLT_PROTINFO_PARSER_STATE_MAXSP,
131 		PLT_PROTINFO_PARSER_STATE_OTHER
132 	} PLT_ProtocolInfoParserState;
133 
134     NPT_Result SetProtocolInfo(const char* protocol_info);
135     NPT_Result ValidateField(const char*  val,
136                         const char*  valid_chars,
137                         NPT_Cardinal num_chars = 0); // 0 means variable number of chars
138     NPT_Result ParseExtra(NPT_List<FieldEntry>& entries);
139     NPT_Result ValidateExtra();
140 
141 private:
142     NPT_String           m_Protocol;
143     NPT_String           m_Mask;
144     NPT_String           m_ContentType;
145     NPT_String           m_Extra;
146 
147     NPT_String           m_DLNA_PN;    // DLNA.ORG_PN Parameter (pn-param)
148     NPT_String           m_DLNA_OP;    // Operations Parameter (op-param)
149     NPT_String           m_DLNA_PS;    // Server-Side PlaySpeeds Parameter (ps-param)
150     NPT_String           m_DLNA_CI;    // Conversion Indicator Flag (ci-param)
151     NPT_String           m_DLNA_FLAGS; // Flags Parameter (flags-param)
152     NPT_String           m_DLNA_MAXSP; // Maximum RTSP Speed Header value (maxsp-param)
153     NPT_List<FieldEntry> m_DLNA_OTHER; // Vendor-defined 4th field Parameters (other-param)
154 
155     bool                 m_Valid;
156 };
157 
158 #endif /* _PLT_PROTOCOL_INFO_H_ */
159