summaryrefslogtreecommitdiff
path: root/native/ctsvc_restriction.c
diff options
context:
space:
mode:
authorHyungKyu Song <hk76.song@samsung.com>2013-02-16 19:06:08 +0900
committerHyungKyu Song <hk76.song@samsung.com>2013-02-16 19:06:08 +0900
commit2fe4ba6f7e660a945ed94559110c76852c5edd47 (patch)
tree1c3b126230f27c8e1451b5669a2e7f760be29fe1 /native/ctsvc_restriction.c
parenta1311c9da85162a82223c73aa63e6c9b7d91c565 (diff)
downloadcontacts-service-2fe4ba6f7e660a945ed94559110c76852c5edd47.tar.gz
contacts-service-2fe4ba6f7e660a945ed94559110c76852c5edd47.tar.bz2
contacts-service-2fe4ba6f7e660a945ed94559110c76852c5edd47.zip
Diffstat (limited to 'native/ctsvc_restriction.c')
-rwxr-xr-xnative/ctsvc_restriction.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/native/ctsvc_restriction.c b/native/ctsvc_restriction.c
new file mode 100755
index 0000000..bc8f27d
--- /dev/null
+++ b/native/ctsvc_restriction.c
@@ -0,0 +1,82 @@
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Youngjae Shin <yj99.shin@samsung.com>
+ *
+ * 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 <fcntl.h>
+#include <unistd.h>
+
+#include "contacts.h"
+#include "ctsvc_internal.h"
+#include "ctsvc_sqlite.h"
+#include "ctsvc_schema.h"
+
+static const char *CTS_RESTRICTION_CHECK_FILE="/opt/usr/data/contacts-svc/.CONTACTS_SVC_RESTRICTION_CHECK";
+static TLS int ctsvc_restriction_permit;
+
+int ctsvc_restriction_init(void)
+{
+ if (!ctsvc_restriction_permit) {
+ int fd = open(CTS_RESTRICTION_CHECK_FILE, O_RDONLY);
+ if (0 <= fd) {
+ close(fd);
+ ctsvc_restriction_permit = TRUE;
+ } else {
+ CTS_ERR("Restriction Mode");
+ }
+ }
+ if (!ctsvc_restriction_permit) {
+ int ret;
+ const char *query;
+ query = "CREATE TEMP VIEW "CTS_TABLE_RESTRICTED_DATA_VIEW" AS SELECT * FROM "CTS_TABLE_DATA" WHERE is_restricted != 1 AND is_my_profile = 0";
+
+ ret = ctsvc_query_exec(query);
+ RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "cts_query_exec() Failed(%d)", ret);
+ }
+ return CONTACTS_ERROR_NONE;
+}
+
+void ctsvc_restriction_deinit(void)
+{
+ ctsvc_restriction_permit = FALSE;
+}
+
+int ctsvc_restriction_get_permit(void)
+{
+ return ctsvc_restriction_permit;
+}
+#if 0
+/**
+ * This function make restricted contact.
+ * If process does not have permission for restriction, this function will be failed.
+ *
+ * @param[in] contact The contacts service struct
+ * @return #CTS_SUCCESS on success, Negative value(#cts_error) on error
+ */
+API int contacts_svc_struct_set_restriction(CTSstruct *contact)
+{
+ contact_t *record = (contact_t *)contact;
+
+ RETV_IF(NULL == contact, CTS_ERR_ARG_NULL);
+ RETV_IF(FALSE == ctsvc_restriction_permit, CTS_ERR_ENV_INVALID);
+
+ record->is_restricted = TRUE;
+
+ return CONTACTS_ERROR_NONE;
+}
+#endif