Update License
[platform/framework/web/livebox-viewer.git] / src / util.c
index a62a7d0..a99e85b 100644 (file)
@@ -1,11 +1,11 @@
 /*
- * Copyright 2012  Samsung Electronics Co., Ltd
+ * Copyright 2013  Samsung Electronics Co., Ltd
  *
  * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 
 #include <dlog.h>
+#include <livebox-errno.h> /* For error code */
 
 #include "debug.h"
 #include "util.h"
@@ -35,7 +36,7 @@ int util_check_extension(const char *filename, const char *check_ptr)
        name_len = strlen(filename);
        while (--name_len >= 0 && *check_ptr) {
                if (filename[name_len] != *check_ptr)
-                       return -EINVAL;
+                       return LB_STATUS_ERROR_INVALID;
 
                check_ptr ++;
        }
@@ -75,14 +76,14 @@ static inline int check_native_livebox(const char *pkgname)
        path = malloc(len + 1);
        if (!path) {
                ErrPrint("Heap: %s\n", strerror(errno));
-               return -ENOMEM;
+               return LB_STATUS_ERROR_MEMORY;
        }
 
        snprintf(path, len, "/opt/usr/live/%s/libexec/liblive-%s.so", pkgname, pkgname);
        if (access(path, F_OK | R_OK) != 0) {
                ErrPrint("%s is not a valid package\n", pkgname);
                free(path);
-               return -EINVAL;
+               return LB_STATUS_ERROR_INVALID;
        }
 
        free(path);
@@ -100,14 +101,14 @@ static inline int check_web_livebox(const char *pkgname)
        path = malloc(len + 1);
        if (!path) {
                ErrPrint("Heap: %s\n", strerror(errno));
-               return -ENOMEM;
+               return LB_STATUS_ERROR_MEMORY;
        }
 
        snprintf(path, len, "/opt/usr/apps/%s/res/wgt/livebox/index.html", pkgname);
        if (access(path, F_OK | R_OK) != 0) {
                ErrPrint("%s is not a valid package\n", pkgname);
                free(path);
-               return -EINVAL;
+               return LB_STATUS_ERROR_INVALID;
        }
 
        free(path);
@@ -118,13 +119,13 @@ int util_validate_livebox_package(const char *pkgname)
 {
        if (!pkgname) {
                ErrPrint("Invalid argument\n");
-               return -EINVAL;
+               return LB_STATUS_ERROR_INVALID;
        }
 
        if (!check_native_livebox(pkgname) || !check_web_livebox(pkgname))
                return 0;
 
-       return -EINVAL;
+       return LB_STATUS_ERROR_INVALID;
 }
 
 const char *util_uri_to_path(const char *uri)
@@ -138,4 +139,34 @@ const char *util_uri_to_path(const char *uri)
        return uri + len;
 }
 
+int util_unlink(const char *filename)
+{
+       char *descfile;
+       int desclen;
+       int ret;
+
+       if (!filename)
+               return LB_STATUS_ERROR_INVALID;
+
+       desclen = strlen(filename) + 6; /* .desc */
+       descfile = malloc(desclen);
+       if (!descfile) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return LB_STATUS_ERROR_MEMORY;
+       }
+
+       ret = snprintf(descfile, desclen, "%s.desc", filename);
+       if (ret < 0) {
+               ErrPrint("Error: %s\n", strerror(errno));
+               free(descfile);
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       (void)unlink(descfile);
+       free(descfile);
+       (void)unlink(filename);
+
+       return LB_STATUS_SUCCESS;
+}
+
 /* End of a file */