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.
26 #include <livebox-errno.h> /* For error code */
27 #include <tzplatform_config.h>
33 #if defined(_USE_ECORE_TIME_GET)
37 .type = CLOCK_MONOTONIC,
41 int util_check_extension(const char *filename, const char *check_ptr)
45 name_len = strlen(filename);
46 while (--name_len >= 0 && *check_ptr) {
47 if (filename[name_len] != *check_ptr) {
48 return LB_STATUS_ERROR_INVALID;
57 double util_timestamp(void)
59 #if defined(_USE_ECORE_TIME_GET)
63 if (clock_gettime(s_info.type, &ts) == 0) {
64 return ts.tv_sec + ts.tv_nsec / 1000000000.0f;
67 ErrPrint("%d: %s\n", s_info.type, strerror(errno));
68 if (s_info.type == CLOCK_MONOTONIC) {
69 s_info.type = CLOCK_REALTIME;
70 } else if (s_info.type == CLOCK_REALTIME) {
72 if (gettimeofday(&tv, NULL) < 0) {
73 ErrPrint("gettimeofday: %s\n", strerror(errno));
77 return tv.tv_sec + tv.tv_usec / 1000000.0f;
85 if (gettimeofday(&tv, NULL) < 0) {
86 ErrPrint("gettimeofday: %s\n", strerror(errno));
91 return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
95 const char *util_basename(const char *name)
98 length = name ? strlen(name) : 0;
103 while (--length > 0 && name[length] != '/');
105 return length <= 0 ? name : name + length + (name[length] == '/');
108 static inline int check_native_livebox(const char *pkgname)
113 /* get lenght of path */
114 len = snprintf(NULL, 0, "%s/%s/libexec/liblive-%s.so",tzplatform_getenv(TZ_USER_LIVE),pkgname, pkgname);
116 path = malloc(len + 1);
118 ErrPrint("Heap: %s\n", strerror(errno));
119 return LB_STATUS_ERROR_MEMORY;
122 snprintf(path, len, "%s/%s/libexec/liblive-%s.so",tzplatform_getenv(TZ_USER_LIVE),pkgname, pkgname);
123 if (access(path, F_OK | R_OK) != 0) {
124 ErrPrint("%s is not a valid package\n", pkgname);
126 return LB_STATUS_ERROR_INVALID;
133 static inline int check_web_livebox(const char *pkgname)
138 /* get lenght of path*/
139 len = snprintf(NULL, 0, "%s/%s/res/wgt/livebox/index.html",tzplatform_getenv(TZ_USER_APP),pkgname);
141 path = malloc(len + 1);
143 ErrPrint("Heap: %s\n", strerror(errno));
144 return LB_STATUS_ERROR_MEMORY;
147 snprintf(path, len, "%s/%s/res/wgt/livebox/index.html",tzplatform_getenv(TZ_USER_APP) ,pkgname);
148 if (access(path, F_OK | R_OK) != 0) {
149 ErrPrint("%s is not a valid package\n", pkgname);
151 return LB_STATUS_ERROR_INVALID;
158 int util_validate_livebox_package(const char *pkgname)
161 ErrPrint("Invalid argument\n");
162 return LB_STATUS_ERROR_INVALID;
165 if (!check_native_livebox(pkgname) || !check_web_livebox(pkgname)) {
169 return LB_STATUS_ERROR_INVALID;
172 const char *util_uri_to_path(const char *uri)
176 len = strlen(SCHEMA_FILE);
177 if (strncasecmp(uri, SCHEMA_FILE, len)) {
184 int util_unlink(const char *filename)
191 return LB_STATUS_ERROR_INVALID;
194 desclen = strlen(filename) + 6; /* .desc */
195 descfile = malloc(desclen);
197 ErrPrint("Heap: %s\n", strerror(errno));
198 return LB_STATUS_ERROR_MEMORY;
201 ret = snprintf(descfile, desclen, "%s.desc", filename);
203 ErrPrint("Error: %s\n", strerror(errno));
205 return LB_STATUS_ERROR_FAULT;
208 (void)unlink(descfile);
210 (void)unlink(filename);
212 return LB_STATUS_SUCCESS;