2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
25 #include <livebox-errno.h> /* For error code */
32 int util_check_extension(const char *filename, const char *check_ptr)
36 name_len = strlen(filename);
37 while (--name_len >= 0 && *check_ptr) {
38 if (filename[name_len] != *check_ptr) {
39 return LB_STATUS_ERROR_INVALID;
48 double util_timestamp(void)
52 gettimeofday(&tv, NULL);
54 return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
57 const char *util_basename(const char *name)
60 length = name ? strlen(name) : 0;
65 while (--length > 0 && name[length] != '/');
67 return length <= 0 ? name : name + length + (name[length] == '/');
70 static inline int check_native_livebox(const char *pkgname)
75 len = strlen(pkgname) * 2;
76 len += strlen("/opt/usr/live/%s/libexec/liblive-%s.so");
78 path = malloc(len + 1);
80 ErrPrint("Heap: %s\n", strerror(errno));
81 return LB_STATUS_ERROR_MEMORY;
84 snprintf(path, len, "/opt/usr/live/%s/libexec/liblive-%s.so", pkgname, pkgname);
85 if (access(path, F_OK | R_OK) != 0) {
86 ErrPrint("%s is not a valid package\n", pkgname);
88 return LB_STATUS_ERROR_INVALID;
95 static inline int check_web_livebox(const char *pkgname)
100 len = strlen(pkgname) * 2;
101 len += strlen("/opt/usr/apps/%s/res/wgt/livebox/index.html");
103 path = malloc(len + 1);
105 ErrPrint("Heap: %s\n", strerror(errno));
106 return LB_STATUS_ERROR_MEMORY;
109 snprintf(path, len, "/opt/usr/apps/%s/res/wgt/livebox/index.html", pkgname);
110 if (access(path, F_OK | R_OK) != 0) {
111 ErrPrint("%s is not a valid package\n", pkgname);
113 return LB_STATUS_ERROR_INVALID;
120 int util_validate_livebox_package(const char *pkgname)
123 ErrPrint("Invalid argument\n");
124 return LB_STATUS_ERROR_INVALID;
127 if (!check_native_livebox(pkgname) || !check_web_livebox(pkgname)) {
131 return LB_STATUS_ERROR_INVALID;
134 const char *util_uri_to_path(const char *uri)
138 len = strlen(SCHEMA_FILE);
139 if (strncasecmp(uri, SCHEMA_FILE, len)) {
146 int util_unlink(const char *filename)
153 return LB_STATUS_ERROR_INVALID;
156 desclen = strlen(filename) + 6; /* .desc */
157 descfile = malloc(desclen);
159 ErrPrint("Heap: %s\n", strerror(errno));
160 return LB_STATUS_ERROR_MEMORY;
163 ret = snprintf(descfile, desclen, "%s.desc", filename);
165 ErrPrint("Error: %s\n", strerror(errno));
167 return LB_STATUS_ERROR_FAULT;
170 (void)unlink(descfile);
172 (void)unlink(filename);
174 return LB_STATUS_SUCCESS;