Create separate source file for internal, common code.
authorRafal Krypa <r.krypa@samsung.com>
Thu, 18 Apr 2013 15:08:06 +0000 (17:08 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 24 Apr 2013 13:47:24 +0000 (15:47 +0200)
[Issue#]       N/A
[Feature]      Refactorization.
[Cause]        Code starts to be duplicated.
[Solution]     Common internal source file.
[Verification] Build, install, run tests.

Change-Id: I233eede546d6a7bb9c0ab9cefd1e349be10364b1

Conflicts:

src/privilege-control.c

CMakeLists.txt
include/common.h [new file with mode: 0644]
src/access-db.c
src/common.c [new file with mode: 0644]
src/privilege-control.c

index 2c4f91b..a2bbc71 100644 (file)
@@ -41,6 +41,7 @@ INCLUDE_DIRECTORIES(${pkgs_INCLUDE_DIRS})
 SET(libprivilege-control_SOURCES
        ${src_dir}/privilege-control.c
        ${src_dir}/access-db.c
+       ${src_dir}/common.c
        )
 SET(libprivilege-control_LDFLAGS " -module -avoid-version ")
 SET(libprivilege-control_CFLAGS  " ${CFLAGS} -fPIC -I${include_dir}")
diff --git a/include/common.h b/include/common.h
new file mode 100644 (file)
index 0000000..cc523f0
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * libprivilege control
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Rafal Krypa <r.krypa@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.
+ *
+ */
+
+#ifndef COMMON_H_
+#define COMMON_H_
+
+#include <dlog.h>
+
+
+#ifdef LOG_TAG
+    #undef LOG_TAG
+#endif // LOG_TAG
+#ifndef LOG_TAG
+    #define LOG_TAG "PRIVILEGE_CONTROL"
+#endif // LOG_TAG
+
+// conditional log macro for dlogutil (debug)
+#ifdef DLOG_DEBUG_ENABLED
+#define C_LOGD(...) LOGD(__VA_ARGS__)
+#else
+#define C_LOGD(...) do { } while(0)
+#endif //DDLOG_DEBUG_ENABLED
+
+// conditional log macro for dlogutil (error)
+#ifdef DLOG_ERROR_ENABLED
+#define C_LOGE(...) LOGE(__VA_ARGS__)
+#else
+#define C_LOGE(...) do { } while(0)
+#endif //DLOG_ERROR_ENABLED
+
+#ifdef SMACK_ENABLED
+int smack_label_is_valid(const char* smack_label);
+#endif
+
+#endif /* COMMON_H_ */
index fc51cfc..40de59c 100644 (file)
 #include <dlog.h>
 #include <ctype.h>
 
+#include "access-db.h"
 #include "privilege-control.h"
-
-#ifdef LOG_TAG
-    #undef LOG_TAG
-#endif // LOG_TAG
-#ifndef LOG_TAG
-    #define LOG_TAG "PRIVILEGE_CONTROL"
-#endif // LOG_TAG
-
-// conditional log macro for dlogutil (debug)
-#ifdef DLOG_DEBUG_ENABLED
-#define C_LOGD(...) LOGD(__VA_ARGS__)
-#else
-#define C_LOGD(...) do { } while(0)
-#endif //DDLOG_DEBUG_ENABLED
-
-// conditional log macro for dlogutil (error)
-#ifdef DLOG_ERROR_ENABLED
-#define C_LOGE(...) LOGE(__VA_ARGS__)
-#else
-#define C_LOGE(...) do { } while(0)
-#endif //DLOG_ERROR_ENABLED
+#include "common.h"
 
 typedef enum {
        DB_APP_TYPE_APPLICATION,
@@ -106,37 +87,6 @@ static int remove_list(element_t* first_elem)
        return 0;
 }
 
-/* TODO: implement such function in libsmack instead -- copied from privilege-control.c*/
-static int smack_label_is_valid(const char* smack_label)
-{
-       C_LOGD("Enter function: %s", __func__);
-       int i;
-
-       if (!smack_label || smack_label[0] == '\0' || !smack_label[0] == '-')
-               goto err;
-
-       for (i = 0; smack_label[i]; ++i) {
-               if (i >= SMACK_LABEL_LEN)
-                       return 0;
-               switch (smack_label[i]) {
-               case '~':
-               case ' ':
-               case '/':
-               case '"':
-               case '\\':
-               case '\'':
-                       goto err;
-               default:
-                       break;
-               }
-       }
-
-       return 1;
-err:
-       C_LOGE("Invalid Smack label: %s", smack_label);
-       return 0;
-}
-
 static int add_id_to_database_internal(const char * id, db_app_type_t app_type)
 {
        C_LOGD("Enter function: %s", __func__);
diff --git a/src/common.c b/src/common.c
new file mode 100644 (file)
index 0000000..cf44ba2
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * libprivilege control
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Rafal Krypa <r.krypa@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 <sys/smack.h>
+#include "common.h"
+
+#ifdef SMACK_ENABLED
+/* TODO: implement such function in libsmack instead */
+int smack_label_is_valid(const char* smack_label)
+{
+       C_LOGD("Enter function: %s", __func__);
+       int i;
+
+       if (!smack_label || smack_label[0] == '\0' || smack_label[0] == '-')
+               goto err;
+
+       for (i = 0; smack_label[i]; ++i) {
+               if (i >= SMACK_LABEL_LEN)
+                       return 0;
+               switch (smack_label[i]) {
+               case '~':
+               case ' ':
+               case '/':
+               case '"':
+               case '\\':
+               case '\'':
+                       goto err;
+               default:
+                       break;
+               }
+       }
+
+       return 1;
+err:
+       C_LOGE("Invalid Smack label: %s", smack_label);
+       return 0;
+}
+#endif
index 6e94f06..477a59b 100644 (file)
@@ -42,6 +42,7 @@
 
 #include "privilege-control.h"
 #include "access-db.h"
+#include "common.h"
 
 #define APP_GID        5000
 #define APP_UID        5000
 static int set_smack_for_wrt(const char* widget_id);
 #endif
 
-#ifdef LOG_TAG
-    #undef LOG_TAG
-#endif // LOG_TAG
-#ifndef LOG_TAG
-    #define LOG_TAG "PRIVILEGE_CONTROL"
-#endif // LOG_TAG
-
-// conditional log macro for dlogutil (debug)
-#ifdef DLOG_DEBUG_ENABLED
-#define C_LOGD(...) LOGD(__VA_ARGS__)
-#else
-#define C_LOGD(...) do { } while(0)
-#endif //DDLOG_DEBUG_ENABLED
-
-// conditional log macro for dlogutil (error)
-#ifdef DLOG_ERROR_ENABLED
-#define C_LOGE(...) LOGE(__VA_ARGS__)
-#else
-#define C_LOGE(...) do { } while(0)
-#endif //DLOG_ERROR_ENABLED
-
 typedef struct {
        char user_name[10];
        int uid;
@@ -442,36 +422,6 @@ error:
 }
 
 #ifdef SMACK_ENABLED
-/* TODO: implement such function in libsmack instead */
-static int smack_label_is_valid(const char* smack_label)
-{
-       C_LOGD("Enter function: %s", __func__);
-       int i;
-
-       if (!smack_label || smack_label[0] == '\0' || smack_label[0] != '-')
-               goto err;
-
-       for (i = 0; smack_label[i]; ++i) {
-               if (i >= SMACK_LABEL_LEN)
-                       return 0;
-               switch (smack_label[i]) {
-               case '~':
-               case ' ':
-               case '/':
-               case '"':
-               case '\\':
-               case '\'':
-                       goto err;
-               default:
-                       break;
-               }
-       }
-
-       return 1;
-err:
-       C_LOGE("Invalid Smack label: %s", smack_label);
-       return 0;
-}
 
 /**
  * Set process SMACK label from EXEC label of a file.