*/
#include "view_logic_uri_support.h"
+#include <string>
+#include <list>
#include <dpl/string.h>
#include <dpl/log/log.h>
#include <dpl/localization/w3c_file_localization.h>
-//#include <dpl/wrt-dao-ro/common_dao_types.h>
#include <widget_model.h>
#include <bundle.h>
#include <appsvc.h>
namespace UriSupport {
namespace {
+enum ServiceDataType
+{
+ SERVICE_DATA_TYPE_OPERATION,
+ SERVICE_DATA_TYPE_URI,
+ SERVICE_DATA_TYPE_MIME,
+ SERVICE_DATA_TYPE_MIME_ELEMENT
+};
+
char const * const SCHEME_TYPE_FILE = "file";
char const * const SCHEME_TYPE_WIDGET = "widget";
+char const * const SERVICE_DATA_WILD_CHAR = "*";
+char const * const SERVICE_DATA_MIME_TOKEN = "/";
+const unsigned int SIZE_OF_MIME_ELEMENT = 2;
+
+std::list<std::string> parsingMimeData(std::string origin, std::string token)
+{
+ std::list<std::string> parsedData;
+ size_t current = 0;
+ size_t next = 0;
+ do {
+ next = origin.find_first_of(token, current);
+ parsedData.push_back(origin.substr(current, next - current));
+ current = next + 1;
+ } while (next != std::string::npos && current < origin.length());
+ return parsedData;
+}
-std::string getSchemeType(std::string scheme)
+bool compareServiceData(ServiceDataType type,
+ std::string origin,
+ std::string other)
{
- std::string type = "";
- if (!scheme.empty())
+ if (SERVICE_DATA_TYPE_OPERATION == type) {
+ return origin == other;
+ } else if (SERVICE_DATA_TYPE_URI == type
+ || SERVICE_DATA_TYPE_MIME_ELEMENT == type)
{
- const char *end = strstr(scheme.c_str(), ":");
- if(!end)
- {
- LogError("Lack of scheme");
+ if (SERVICE_DATA_WILD_CHAR == origin) {
+ return true;
} else {
- std::string schemeTmp(scheme.c_str(), end);
- type = schemeTmp;
+ return origin == other;
+ }
+ } else if (SERVICE_DATA_TYPE_MIME == type) {
+ std::list<std::string> vectorOrigin =
+ parsingMimeData(origin, SERVICE_DATA_MIME_TOKEN);
+ if (SIZE_OF_MIME_ELEMENT != vectorOrigin.size()) {
+ return false;
+ }
+ std::list<std::string> vectorOther =
+ parsingMimeData(other, SERVICE_DATA_MIME_TOKEN);
+ if (SIZE_OF_MIME_ELEMENT != vectorOther.size()) {
+ return false;
}
+
+ FOREACH(it, vectorOrigin) {
+ if (!compareServiceData(SERVICE_DATA_TYPE_MIME_ELEMENT,
+ *it,
+ vectorOther.front()))
+ {
+ return false;
+ }
+ vectorOther.pop_front();
+ }
+ return true;
+ } else {
+ LogError("Wrong data type");
+ return false;
}
- return type;
}
}
const char* value = NULL;
value = appsvc_get_operation(bundle);
std::string operation = value ? value : "";
+ // ignore default operation that is reserved by system
+ if (operation == APPSVC_OPERATION_DEFAULT) {
+ return std::string("");
+ }
value = appsvc_get_uri(bundle);
std::string scheme = value ? value : "";
value = appsvc_get_mime(bundle);
- std::string mimeType = value ? value : "";
-
- // get scheme type from scheme uri
- std::string schemeType = getSchemeType(scheme);
+ std::string mime = value ? value : "";
LogDebug("operation : " << operation);
- LogDebug("schemeType : " << schemeType);
- LogDebug("mimetype : " << mimeType);
+ LogDebug("schemeType : " << scheme);
+ LogDebug("mimetype : " << mime);
WidgetApplicationServiceList appServiceList =
widgetModel->AppServiceList.Get();
FOREACH(appServiceIt, appServiceList) {
- std::string appServiceSchemeType =
- getSchemeType(DPL::ToUTF8String(appServiceIt->scheme));
-
- if (DPL::ToUTF8String(appServiceIt->operation) == operation &&
- (appServiceSchemeType == schemeType ||
- DPL::ToUTF8String(appServiceIt->scheme) == "*/*") &&
- (DPL::ToUTF8String(appServiceIt->mime) == mimeType ||
- DPL::ToUTF8String(appServiceIt->mime) == "*/*"))
+ if (compareServiceData(SERVICE_DATA_TYPE_OPERATION,
+ DPL::ToUTF8String(appServiceIt->operation),
+ operation) &&
+ compareServiceData(SERVICE_DATA_TYPE_URI,
+ DPL::ToUTF8String(appServiceIt->scheme),
+ scheme) &&
+ compareServiceData(SERVICE_DATA_TYPE_MIME,
+ DPL::ToUTF8String(appServiceIt->mime),
+ mime))
{
- // ignore default operation that is reserved by system
- if (operation == APPSVC_OPERATION_DEFAULT) {
- return std::string("");
- }
return DPL::ToUTF8String(appServiceIt->src);
}
}