LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CmdResourceHandlers.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef __CmdResourceHandlers_h__
23 #define __CmdResourceHandlers_h__
24 
25 
26 #include "Common.h"
27 
28 #include <regex.h>
29 #include <stdint.h>
30 #include <string>
31 #include <vector>
32 #include <map>
33 
39 class RedirectHandlerNode;
40 class ResourceHandlerNode;
41 
43 {
44  public:
45  RedirectHandler(const std::string& urlRe, const std::string& appId, bool schemeform );
46  RedirectHandler(const std::string& urlRe, const std::string& appId, bool schemeform, const std::string& handler_tag);
47  virtual ~RedirectHandler();
49 
50  const std::string& urlRe() const { return m_urlRe; }
51  const std::string& appId() const { return m_appId; }
52  bool matches(const std::string& url) const;
53  bool reValid() const;
54 
55  bool addVerb(const std::string& verb,const std::string& jsonizedParams);
56  void removeVerb(const std::string& verb);
57 
58  bool operator==(const RedirectHandler& c) const
59  {
60  return ((m_urlRe == c.m_urlRe) && (m_appId == c.m_appId));
61  }
62  bool operator!=(const RedirectHandler& c) const
63  {
64  return ((m_urlRe != c.m_urlRe) || (m_appId != c.m_appId));
65  }
66  bool equals(const std::string& url,const std::string& appId)
67  {
68  return ((m_urlRe == url) && (m_appId == appId));
69  }
70 
73 
74  friend class RedirectHandlerNode;
75 
76  bool valid() const { return m_valid;}
77  void markInvalid() { m_valid = false; }
78  bool isSchemeForm() const { return m_schemeForm;}
79 
80  const std::string& tag() const { return m_tag; }
81  void setTag(const std::string& newtag) { m_tag = newtag;}
82  uint32_t index() { return m_index; }
83  uint32_t setIndex(uint32_t newindex) { uint32_t t = m_index; m_index = newindex; return t;}
84 
85  std::string toJsonString();
86  struct json_object * toJson(); //WARNING: memory allocated; caller must clean
87 
88  const std::map<std::string,std::string>& verbs() { return m_verbs;}
89 
90  private:
91 
92  std::string m_urlRe;
93  std::string m_appId;
94  regex_t m_urlReg;
95  bool m_valid;
96  bool m_schemeForm;
97  std::string m_tag;
98  uint32_t m_index;
99  std::map<std::string,std::string> m_verbs; // < Verb , json-ized string of parameters >
100 
101 };
102 
108 {
109  public:
110  ResourceHandler( const std::string& ext,
111  const std::string& contentType,
112  const std::string& appId,
113  bool stream=false );
114  ResourceHandler( const std::string& ext,
115  const std::string& contentType,
116  const std::string& appId,
117  bool stream,
118  const std::string& handler_tag);
119 
121  ResourceHandler() : m_stream(false), m_valid(false), m_index(0) {}
122 
125 
126  bool operator==(const ResourceHandler& c) const
127  {
128  return ((m_fileExt == c.m_fileExt) && (m_contentType == c.m_contentType) && (m_appId == c.m_appId) && (m_stream == c.m_stream));
129  }
130 
131  bool operator!=(const ResourceHandler& c) const
132  {
133  return ((m_fileExt != c.m_fileExt) || (m_contentType != c.m_contentType) || (m_appId != c.m_appId) || (m_stream != c.m_stream));
134  }
135 
136  bool match(const std::string& extension,const std::string& appId,const std::string& mimeType,bool stream) const
137  {
138  return ((m_fileExt == extension) && (m_contentType == mimeType) && (m_appId == appId) && (m_stream == stream));
139  }
140  bool match(const std::string& extension,const std::string& appId,const std::string& mimeType) const
141  {
142  return ((m_fileExt == extension) && (m_contentType == mimeType) && (m_appId == appId));
143  }
144  bool match(const std::string& appId,const std::string& mimeType) const
145  {
146  return ((m_contentType == mimeType) && (m_appId == appId));
147  }
148 
149  const std::string& appId() const { return m_appId; }
150  const std::string& fileExt() const { return m_fileExt; }
151  const std::string& contentType() const { return m_contentType; }
152  const std::string& tag() const { return m_tag; }
153  void setTag(const std::string& newtag) { m_tag = newtag;}
154  uint32_t index() { return m_index; }
155  uint32_t setIndex(uint32_t newindex) { uint32_t t = m_index; m_index = newindex; return t;}
156  bool stream() const { return m_stream; }
157 
158  friend class ResourceHandlerNode;
159 
160  bool valid() { return m_valid;}
161  void markInvalid() { m_valid = false; }
162  bool addVerb(const std::string& verb,const std::string& jsonizedParams);
163  void removeVerb(const std::string& verb);
164 
165  std::string toJsonString();
166  struct json_object * toJson(); //WARNING: memory allocated; caller must clean
167 
168  const std::map<std::string,std::string>& verbs() { return m_verbs;}
169 
170  private:
171  std::string m_fileExt;
172  std::string m_contentType;
173  std::string m_appId;
174  bool m_stream;
175  bool m_valid;
176  std::string m_tag;
177  uint32_t m_index;
178  std::map<std::string,std::string> m_verbs; // < Verb , json-ized string of parameters >
179 };
180 
181 #endif