42 VerbInfo(
const std::string& verb,
const std::string& params,
const std::string handlerAppId, uint32_t handlerIndex) :
77 static MimeSystem *
instance(
const std::string& baseConfigFile,
const std::string& customizedConfigFile);
80 int getAllAppIdForResource(std::string mimeType,std::string& r_active,std::vector<std::string>& r_handlerAppIds);
86 int getAllAppIdForRedirect(
const std::string& url,
bool doNotUseRegexpMatch,std::string& r_active,std::vector<std::string>& r_handlerAppIds);
91 std::string
getAppIdByVerbForResource(std::string mimeType,
const std::string& verb,std::string& r_params,uint32_t& r_index);
96 std::string
getAppIdByVerbForRedirect(
const std::string& url,
bool disallowSchemeForms,
const std::string& verb,std::string& r_params,uint32_t& r_index);
108 int addResourceHandler(std::string& extension,std::string mimeType,
bool shouldDownload,
const std::string appId,
const std::map<std::string,std::string> * pVerbs,
bool sysDefault);
109 int addResourceHandler(std::string extension,
bool shouldDownload,
const std::string appId,
const std::map<std::string,std::string> * pVerbs,
bool sysDefault);
110 int addRedirectHandler(
const std::string& url,
const std::string appId,
const std::map<std::string,std::string> * pVerbs,
bool isSchemeForm,
bool sysDefault);
112 int addVerbsToResourceHandler(std::string mimeType,
const std::string& appId,
const std::map<std::string,std::string>& verbs);
113 int addVerbsToRedirectHandler(
const std::string& url,
const std::string& appId,
const std::map<std::string,std::string>& verbs);
114 int addVerbsDirect(uint32_t index,
const std::map<std::string,std::string>& verbs);
139 bool saveMimeTable(
const std::string& file,std::string& r_err);
158 int populateFromJson(
struct json_object * jobj);
162 class VerbCacheEntry {
165 VerbCacheEntry() : activeIndex(0) , useCount(0) {}
166 VerbCacheEntry(uint32_t index) : activeIndex(index) , useCount(1) {}
167 VerbCacheEntry(
const VerbCacheEntry& c) : activeIndex(c.activeIndex) , useCount(c.useCount) {}
168 VerbCacheEntry& operator=(
const VerbCacheEntry& c) {
171 activeIndex = c.activeIndex;
172 useCount = c.useCount;
175 uint32_t activeIndex;
179 class RedirectHandlerNode {
181 RedirectHandlerNode(
const std::string& urlRe,
const std::string& appId ,
bool schemeForm) : m_redirectHandler(urlRe,appId,schemeForm) {
182 m_handlersByIndex[m_redirectHandler.index()] = &m_redirectHandler;
185 std::vector<RedirectHandler *> m_alternates;
187 std::map<std::string,VerbCacheEntry> m_verbCache;
188 std::map<uint32_t,RedirectHandler *> m_handlersByIndex;
191 int removeAppId(
const std::string& appId);
192 int swapHandler(uint32_t index);
196 bool isCurrentVerbHandler(
const std::string& verb,
RedirectHandler& handler);
197 bool pickRandomVerbHandler(
const std::string& verb,uint32_t& r_chosenIndex);
198 bool reassignRandomVerbHandler(
const std::string& verb);
200 bool exists(
const std::string& urlRe,
const std::string& appId) {
201 if (m_redirectHandler.equals(urlRe,appId))
203 for (std::vector<RedirectHandler *>::iterator it=m_alternates.begin();
204 it != m_alternates.end();++it)
206 if ((*it)->equals(urlRe,appId))
212 virtual ~RedirectHandlerNode();
214 std::string toJsonString();
215 struct json_object * toJson();
216 static MimeSystem::RedirectHandlerNode * fromJsonString(
const std::string& jsonString);
217 static MimeSystem::RedirectHandlerNode * fromJson(
struct json_object * jobj);
219 int fixupVerbCacheTable(
struct json_object * jsonHandlerNodeEntry);
222 class ResourceHandlerNode {
224 ResourceHandlerNode(
const std::string& ext,
225 const std::string& contentType,
226 const std::string& appId,
227 bool stream=
false ) : m_resourceHandler(ext,contentType,appId,stream) {
228 m_handlersByIndex[m_resourceHandler.index()] = &m_resourceHandler;
232 std::vector<ResourceHandler *> m_alternates;
233 std::map<std::string,VerbCacheEntry> m_verbCache;
234 std::map<uint32_t,ResourceHandler *> m_handlersByIndex;
237 int removeAppId(
const std::string& appId);
238 int swapHandler(uint32_t index);
242 bool isCurrentVerbHandler(
const std::string& verb,
ResourceHandler& handler);
243 bool pickRandomVerbHandler(
const std::string& verb,uint32_t& r_chosenIndex);
244 bool reassignRandomVerbHandler(
const std::string& verb);
246 bool exists(
const std::string& extension,
const std::string& appId,
const std::string& contentType,
bool stream) {
247 if (m_resourceHandler.match(extension,appId,contentType,stream))
249 for (std::vector<ResourceHandler *>::iterator it=m_alternates.begin();
250 it != m_alternates.end();++it)
252 if ((*it)->match(extension,appId,contentType,stream))
258 bool exists(
const std::string& appId,
const std::string& contentType) {
259 if (m_resourceHandler.match(appId,contentType))
261 for (std::vector<ResourceHandler *>::iterator it=m_alternates.begin();
262 it != m_alternates.end();++it)
264 if ((*it)->match(appId,contentType))
270 virtual ~ResourceHandlerNode();
272 std::string toJsonString();
273 struct json_object * toJson();
274 static MimeSystem::ResourceHandlerNode * fromJsonString(
const std::string& jsonString);
275 static MimeSystem::ResourceHandlerNode * fromJson(
struct json_object * jobj);
277 int fixupVerbCacheTable(
struct json_object * jsonHandlerNodeEntry);
280 static void reclaimIndex(uint32_t idx);
282 static int addVerbs(
const std::map<std::string,std::string>& verbs,ResourceHandlerNode& resourceHandlerNode,
ResourceHandler& newHandler);
283 static int addVerbs(
const std::map<std::string,std::string>& verbs,RedirectHandlerNode& redirectHandlerNode,
RedirectHandler& newHandler);
300 ResourceHandlerNode * getResourceHandlerNode(
const std::string& mimeType);
301 RedirectHandlerNode * getRedirectHandlerNode(
const std::string& url);
302 RedirectHandlerNode * getSchemeHandlerNode(
const std::string& url);
308 static Mutex s_mutex;
311 std::map<std::string,MimeSystem::ResourceHandlerNode *> m_resourceHandlerMap;
312 std::map<std::string,MimeSystem::RedirectHandlerNode *> m_redirectHandlerMap;
314 std::map<std::string,std::string> m_extensionToMimeMap;
315 static uint32_t s_genIndex;
316 static uint32_t s_lastAssignedIndex;
317 static std::vector<uint32_t> s_indexRecycler;
319 typedef std::map<std::string,MimeSystem::ResourceHandlerNode *> ResourceMapType;
320 typedef std::map<std::string,MimeSystem::ResourceHandlerNode *>::iterator ResourceMapIterType;
321 typedef std::map<std::string,MimeSystem::RedirectHandlerNode *> RedirectMapType;
322 typedef std::map<std::string,MimeSystem::RedirectHandlerNode *>::iterator RedirectMapIterType;
323 typedef std::map<std::string,MimeSystem::VerbCacheEntry> VerbCacheMapType;
324 typedef std::map<std::string,MimeSystem::VerbCacheEntry>::iterator VerbCacheMapIterType;