2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <sys/types.h>
25 #include <system_info.h>
26 #include <system_info_private.h>
28 #define KEY_PREFIX "http://"
33 #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
35 static int get_tizenid(char *val, size_t len)
40 fp = fopen(TIZEN_ID_PATH, "r");
42 _E("Failed to open file (%s)", TIZEN_ID_PATH); //LCOV_EXCL_LINE
43 return SYSTEM_INFO_ERROR_IO_ERROR; //LCOV_EXCL_LINE
46 if (fgets(id, sizeof(id), fp) == NULL) {
47 _E("Failed to get string (errno:%d)", errno); //LCOV_EXCL_LINE
48 fclose(fp); //LCOV_EXCL_LINE
49 return SYSTEM_INFO_ERROR_IO_ERROR; //LCOV_EXCL_LINE
54 if (strlen(id) == 0) {
55 _E("String length of id is 0"); //LCOV_EXCL_LINE
56 return SYSTEM_INFO_ERROR_IO_ERROR; //LCOV_EXCL_LINE
59 snprintf(val, len, "%s", id);
60 return SYSTEM_INFO_ERROR_NONE;
63 struct system_info_file_key {
65 int (*get_value)(char *val, size_t len);
66 system_info_type_e type;
68 { "http://tizen.org/system/tizenid", get_tizenid, SYSTEM_INFO_STRING },
71 int system_info_get_file(const char *key, char *value, size_t len)
78 return SYSTEM_INFO_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
80 if (strstr(key, KEY_PREFIX) == key)
81 snprintf(p_key, sizeof(p_key), "%s", key);
83 snprintf(p_key, sizeof(p_key), "%s%s", KEY_PREFIX, key);
85 p_len = strlen(p_key) + 1;
86 for (i = 0 ; i < ARRAY_SIZE(info_file_key); i++)
87 if (!strncmp(p_key, info_file_key[i].key, p_len))
88 return info_file_key[i].get_value(value, len);
90 return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
93 int system_info_get_type_file(const char *key, system_info_type_e *type)
99 return SYSTEM_INFO_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
101 if (strstr(key, KEY_PREFIX) == key)
102 snprintf(p_key, sizeof(p_key), "%s", key);
104 snprintf(p_key, sizeof(p_key), "%s%s", KEY_PREFIX, key);
106 len = strlen(p_key) + 1;
107 for (i = 0 ; i < ARRAY_SIZE(info_file_key); i++) {
108 if (strncmp(p_key, info_file_key[i].key, len))
110 *type = info_file_key[i].type;
111 return SYSTEM_INFO_ERROR_NONE;
114 return SYSTEM_INFO_ERROR_INVALID_PARAMETER;