#include "ContextStoreService.h"
#include "Store.h"
#include "StoreManager.h"
+#include "QueryChecker.h"
#include "ContextStoreClient.h"
using namespace ctx;
+static QueryChecker __queryChecker;
+
ContextStoreClient::ContextStoreClient(ServiceBase* hostService, const std::string& busName) :
ClientBase(hostService, busName)
{
}
} catch (int error) {
methodCall->reply(error);
+ } catch (std::exception& e) {
+ _E("Exception: %s", e.what());
+ methodCall->reply(E_FAILED);
}
delete methodCall;
{
const char* uri = NULL;
g_variant_get_child(param, IDX_URI, "&s", &uri);
- if (!uri) {
- _E("Invalid URI");
+
+ if (!uri)
throw static_cast<int>(E_PARAM);
- }
+
return uri;
}
{
Store* store = NULL;
+ if (!__queryChecker.validateUri(uri))
+ throw static_cast<int>(E_PARAM);
+
if (isSystem()) {
store = __getStoreManager().getSystemStore(uri);
} else {
throw static_cast<int>(E_PARAM);
}
+ if (!__queryChecker.validateProjection(cols))
+ throw static_cast<int>(E_PARAM);
+
std::vector<Tuple*> tuples = Tuple::buildFrom(vals);
if (tuples.empty()) {
throw static_cast<int>(E_PARAM);
if (!projection || !selection || !sortOrder)
throw static_cast<int>(E_PARAM);
+ if (!__queryChecker.validateProjection(projection))
+ throw static_cast<int>(E_PARAM);
+
+ if (!__queryChecker.validateSelection(selection))
+ throw static_cast<int>(E_PARAM);
+
+ if (!__queryChecker.validateSortOrder(sortOrder))
+ throw static_cast<int>(E_PARAM);
+
std::vector<Tuple*> tuples;
int error = store.retrieve(*this, projection, selection, sortOrder, limit, &tuples);
if (error != E_NONE)
if (!selection)
throw static_cast<int>(E_PARAM);
+ if (!__queryChecker.validateSelection(selection))
+ throw static_cast<int>(E_PARAM);
+
methodCall.reply(store.remove(*this, selection));
}
--- /dev/null
+
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <regex>
+#include "QueryChecker.h"
+
+using namespace ctx;
+
+QueryChecker::QueryChecker()
+{
+}
+
+QueryChecker::~QueryChecker()
+{
+}
+
+bool QueryChecker::validateUri(const std::string& uri)
+{
+ static std::regex uriRegex(URI_REGEX("contextstore"), std::regex::optimize);
+ if (!std::regex_match(uri, uriRegex)) {
+ _E("Invalid parameter");
+ return false;
+ }
+ return true;
+}
+
+bool QueryChecker::validateProjection(const std::string& projection)
+{
+ // TODO
+ return true;
+}
+
+bool QueryChecker::validateSelection(const std::string& selection)
+{
+ // TODO
+ return true;
+}
+
+bool QueryChecker::validateSortOrder(const std::string& sortOrder)
+{
+ // TODO
+ return true;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CONTEXT_STORE_QUERY_CHECKER_H__
+#define __CONTEXT_STORE_QUERY_CHECKER_H__
+
+#include <ContextStoreTypesPrivate.h>
+
+namespace ctx {
+
+ class QueryChecker {
+ public:
+ QueryChecker();
+ ~QueryChecker();
+
+ bool validateUri(const std::string& uri);
+
+ bool validateProjection(const std::string& projection);
+
+ bool validateSelection(const std::string& selection);
+
+ bool validateSortOrder(const std::string& sortOrder);
+ };
+
+}
+
+#endif /* __CONTEXT_STORE_QUERY_CHECKER_H__ */
*/
-#define URI_REGEX(CATEGORY) R"~(^http:\/\/[\w-]+(\.[\w-]+)*\/)~" CATEGORY R"~(\/[\w-]+(\.[\w-]+)*(\/[\w-]+(\.[\w-]+)*)*$)~"
#define COL_REGEX "^[A-Za-z]+\\w*$"
#define CHK_NAME(NODE, NAME) (!xmlStrcmp(NODE->name, (const xmlChar*)(NAME)))
#define DEFAULT_QUERY_LIMIT 10
+#define URI_REGEX(CATEGORY) R"~(^http:\/\/[\w-]+(\.[\w-]+)*\/)~" CATEGORY R"~(\/[\w-]+(\.[\w-]+)*(\/[\w-]+(\.[\w-]+)*)*$)~"
+
#endif