#include <wrt-commons/custom-handler-dao-ro/CustomHandlerDatabase.h>
#include <wrt-commons/custom-handler-dao-ro/custom_handler_dao_read_only.h>
#include <stdio.h>
+#include <pcrecpp.h>
namespace ViewModule {
namespace UriSupport {
enum ServiceDataType
{
SERVICE_DATA_TYPE_OPERATION,
+ SERVICE_DATA_TYPE_URI,
SERVICE_DATA_TYPE_URI_SCHEME,
- SERVICE_DATA_TYPE_MIME,
- SERVICE_DATA_TYPE_MIME_ELEMENT
+ SERVICE_DATA_TYPE_MIME
};
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;
-}
/**
* Parses scheme from appsvc. From mailto:test@wacapps.net
return schemeParts;
}
+bool wildcardCompare(std::string wildcardString, std::string target)
+{
+ std::string re = wildcardString;
+
+ // replace special character to meaning character
+ pcrecpp::RE("\\\\").GlobalReplace("\\\\\\\\", &re);
+ pcrecpp::RE("\\.").GlobalReplace("\\\\.", &re);
+ pcrecpp::RE("\\+").GlobalReplace("\\\\+", &re);
+ pcrecpp::RE("\\?").GlobalReplace("\\\\?", &re);
+ pcrecpp::RE("\\^").GlobalReplace("\\\\^", &re);
+ pcrecpp::RE("\\$").GlobalReplace("\\\\$", &re);
+ pcrecpp::RE("\\[").GlobalReplace("\\\\[", &re);
+ pcrecpp::RE("\\]").GlobalReplace("\\\\]", &re);
+ pcrecpp::RE("\\{").GlobalReplace("\\\\{", &re);
+ pcrecpp::RE("\\}").GlobalReplace("\\\\}", &re);
+ pcrecpp::RE("\\(").GlobalReplace("\\\\(", &re);
+ pcrecpp::RE("\\)").GlobalReplace("\\\\)", &re);
+ pcrecpp::RE("\\|").GlobalReplace("\\\\|", &re);
+
+ // replace wildcard character to regex type
+ pcrecpp::RE("\\\*").GlobalReplace(".*", &re);
+
+ return pcrecpp::RE(re).FullMatch(target);
+}
+
bool compareServiceData(ServiceDataType type,
std::string origin,
std::string other)
{
- if (SERVICE_DATA_TYPE_OPERATION == type) {
+ if (SERVICE_DATA_TYPE_OPERATION == type)
+ {
return origin == other;
- } else if (SERVICE_DATA_TYPE_URI_SCHEME == type
- || SERVICE_DATA_TYPE_MIME_ELEMENT == type)
+ }
+ else if (SERVICE_DATA_TYPE_URI == type)
+ {
+ return wildcardCompare(origin, other);
+ }
+ else if (SERVICE_DATA_TYPE_URI_SCHEME == type)
+ {
+ return origin == other;
+ }
+ else if (SERVICE_DATA_TYPE_MIME == type)
+ {
+ return wildcardCompare(origin, other);
+ }
+ else
{
- if (SERVICE_DATA_WILD_CHAR == origin) {
- return true;
- } else {
- return origin == other;
- }
- } else if (SERVICE_DATA_TYPE_MIME == type) {
- if (other == "") {
- return origin == other;
- }
-
- 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;
}
std::string getAppServiceUri(bundle *bundle, WidgetModel *widgetModel)
{
- if (!bundle) {
+ if (!bundle)
+ {
LogError("Bundle is empty");
return std::string("");
}
value = appsvc_get_uri(bundle);
std::string uri = value ? value : "";
+
std::vector<std::string> schemeParts = parseScheme(uri);
std::string scheme = (schemeParts.empty()) ? "" : schemeParts[0];
std::string ignoreScheme = "file";
-
if (scheme == ignoreScheme)
{
LogInfo("exception : 'file' scheme is ignored.");
+ uri = "";
scheme = "";
}
- LogDebug("operation : " << operation);
- LogDebug("schemeType : " << scheme);
- LogDebug("mimetype : " << mime);
-
- WidgetApplicationServiceList appServiceList =
- widgetModel->AppServiceList.Get();
- FOREACH(appServiceIt, appServiceList) {
- if (compareServiceData(SERVICE_DATA_TYPE_OPERATION,
- DPL::ToUTF8String(appServiceIt->operation),
- operation) &&
- compareServiceData(SERVICE_DATA_TYPE_URI_SCHEME,
- DPL::ToUTF8String(appServiceIt->scheme),
- scheme) &&
- compareServiceData(SERVICE_DATA_TYPE_MIME,
- DPL::ToUTF8String(appServiceIt->mime),
- mime))
+ LogDebug("AppService Information");
+ LogDebug(" - operation : " << operation);
+ LogDebug(" - uri : " << uri);
+ LogDebug(" - scheme : " << scheme);
+ LogDebug(" - mimetype : " << mime);
+
+ WidgetApplicationServiceList appServiceList = widgetModel->AppServiceList.Get();
+
+ FOREACH(appServiceIt, appServiceList)
+ {
+ if (compareServiceData(SERVICE_DATA_TYPE_OPERATION, DPL::ToUTF8String(appServiceIt->operation), operation))
{
- return DPL::ToUTF8String(appServiceIt->src);
+ if (compareServiceData(SERVICE_DATA_TYPE_URI_SCHEME, DPL::ToUTF8String(appServiceIt->scheme), scheme) ||
+ compareServiceData(SERVICE_DATA_TYPE_URI, DPL::ToUTF8String(appServiceIt->scheme), uri) )
+ {
+ if (compareServiceData(SERVICE_DATA_TYPE_MIME, DPL::ToUTF8String(appServiceIt->mime), mime))
+ {
+ LogDebug("AppService Matched with : " << appServiceIt->src);
+ LogDebug(" - operation : " << appServiceIt->operation);
+ LogDebug(" - uri : " << appServiceIt->scheme);
+ LogDebug(" - mimetype : " << appServiceIt->mime);
+
+ return DPL::ToUTF8String(appServiceIt->src);
+ }
+ }
}
}