5 #include <privilege_db_manager.h>
6 #include "privilege_information.h"
9 #define LOG_TAG "PRIVILEGE_INFO"
12 #define TryReturn(condition, expr, returnValue, ...) \
20 #define PI_API __attribute__((visibility("default")))
24 PRVINFO_ERROR_NO_MATCHING_PRIVILEGE = TIZEN_ERROR_PRIVILEGE_INFORMATION | 0x01
25 } privilege_info_internal_error_e;
27 int privilege_info_get_display_name_string_id(const char* api_version, const char *privilege, char **display_name_string_id)
29 TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL");
30 TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL");
35 int ret = privilege_db_manager_get_privilege_display(PRIVILEGE_DB_MANAGER_PACKAGE_TYPE_CORE, privilege, api_version, &temp);
37 if (ret == PRIVILEGE_DB_MANAGER_ERR_NONE) {
39 *display_name_string_id = NULL;
40 else if (strcmp(temp, "") == 0)
41 *display_name_string_id = NULL;
44 } else if (ret != PRIVILEGE_DB_NO_EXIST_RESULT) {
45 goto err_internal_error;
54 ret = privilege_db_manager_get_privilege_display(PRIVILEGE_DB_MANAGER_PACKAGE_TYPE_WRT, privilege, api_version, &temp);
56 if (ret == PRIVILEGE_DB_MANAGER_ERR_NONE) {
58 goto err_no_matching_privilege;
59 else if (strcmp(temp, "") == 0)
60 goto err_no_matching_privilege;
63 } else if (ret == PRIVILEGE_DB_NO_EXIST_RESULT) {
64 goto err_no_matching_privilege;
66 goto err_internal_error;
70 *display_name_string_id = (char*)calloc(strlen(temp) + 1, sizeof(char));
71 TryReturn(*display_name_string_id != NULL, free(temp), PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation is failed.");
72 memcpy(*display_name_string_id, temp, strlen(temp));
73 LOGD("display_name_string_id = %s", *display_name_string_id);
75 return PRVINFO_ERROR_NONE;
77 err_no_matching_privilege:
78 *display_name_string_id = NULL;
80 return PRVINFO_ERROR_NO_MATCHING_PRIVILEGE;
84 return PRVINFO_ERROR_INTERNAL_ERROR;
88 int privilege_info_get_display_name_by_string_id(const char *string_id, char **display_name)
91 TryReturn(string_id != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] string_id is NULL");
93 temp = dgettext("privilege", string_id);
95 *display_name = (char*)calloc(strlen(temp) + 1, sizeof(char));
96 TryReturn(*display_name != NULL, , PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed.");
98 memcpy(*display_name, temp, strlen(temp));
100 return PRVINFO_ERROR_NONE;
104 int privilege_info_get_display_name(const char* api_version, const char* privilege, char** display_name)
107 char* display_name_string_id = NULL;
109 TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL");
110 TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL");
112 ret = privilege_info_get_display_name_string_id(api_version, privilege, &display_name_string_id);
114 if (ret == PRVINFO_ERROR_NO_MATCHING_PRIVILEGE) {
115 char* tempPrivilege = NULL;
120 tempPrivilege = strdup(privilege);
121 TryReturn(tempPrivilege != NULL, free(tempPrivilege), PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] tempPrivilege's strdup is failed.");
123 token = strtok_r(tempPrivilege, "/", &save);
126 token = strtok_r(NULL, "/", &save);
128 *display_name = (char*)calloc(strlen(temp) + 1, sizeof(char));
129 TryReturn(*display_name != NULL, free(tempPrivilege), PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed.");
130 memcpy(*display_name, temp, strlen(temp));
132 } else if (ret == PRVINFO_ERROR_NONE) {
133 ret = privilege_info_get_display_name_by_string_id(display_name_string_id, display_name);
134 free(display_name_string_id);
135 TryReturn(ret == PRVINFO_ERROR_NONE, , PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed.");
137 return PRVINFO_ERROR_INTERNAL_ERROR;
139 return PRVINFO_ERROR_NONE;
143 int privilege_info_get_description_string_id(const char* api_version, const char *privilege, char **description_string_id)
145 TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL");
146 TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL");
151 int ret = privilege_db_manager_get_privilege_description(PRIVILEGE_DB_MANAGER_PACKAGE_TYPE_CORE, privilege, api_version, &temp);
153 if (ret == PRIVILEGE_DB_MANAGER_ERR_NONE) {
155 *description_string_id = NULL;
156 else if (strcmp(temp, "") == 0)
157 *description_string_id = NULL;
160 } else if (ret != PRIVILEGE_DB_NO_EXIST_RESULT) {
161 goto err_internal_error;
169 ret = privilege_db_manager_get_privilege_description(PRIVILEGE_DB_MANAGER_PACKAGE_TYPE_WRT, privilege, api_version, &temp);
171 if (ret == PRIVILEGE_DB_MANAGER_ERR_NONE) {
173 goto err_no_matching_privilege;
174 else if (strcmp(temp, "") == 0)
175 goto err_no_matching_privilege;
178 } else if (ret == PRIVILEGE_DB_NO_EXIST_RESULT) {
179 goto err_no_matching_privilege;
181 goto err_internal_error;
185 *description_string_id = (char*)calloc(strlen(temp) + 1, sizeof(char));
186 TryReturn(*description_string_id != NULL, free(temp), PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation is failed.");
187 memcpy(*description_string_id, temp, strlen(temp));
188 LOGD("description_string_id = %s", *description_string_id);
190 return PRVINFO_ERROR_NONE;
192 err_no_matching_privilege:
193 *description_string_id = NULL;
195 return PRVINFO_ERROR_NO_MATCHING_PRIVILEGE;
199 return PRVINFO_ERROR_INTERNAL_ERROR;
202 int privilege_info_get_description_by_string_id(const char *string_id, char **description)
205 TryReturn(string_id != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] string_id is NULL");
207 temp = dgettext("privilege", string_id);
209 *description = (char*)calloc(strlen(temp) + 1, sizeof(char));
210 TryReturn(*description != NULL, , PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed.");
212 memcpy(*description, temp, strlen(temp));
214 return PRVINFO_ERROR_NONE;
218 int privilege_info_get_description(const char* api_version, const char* privilege, char** description)
221 char* description_string_id = NULL;
223 TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL");
224 TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL");
226 ret = privilege_info_get_description_string_id(api_version, privilege, &description_string_id);
228 if (ret == PRVINFO_ERROR_NO_MATCHING_PRIVILEGE) {
230 temp = dgettext("privilege", "IDS_TPLATFORM_BODY_THIS_PRIVILEGE_IS_NOT_DEFINED");
231 *description = (char*)calloc(strlen(temp) + 1, sizeof(char));
232 TryReturn(*description != NULL, , PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed.");
234 memcpy(*description, temp, strlen(temp));
235 } else if (ret == PRVINFO_ERROR_NONE) {
236 ret = privilege_info_get_description_by_string_id(description_string_id, description);
237 free(description_string_id);
238 TryReturn(ret == PRVINFO_ERROR_NONE, , PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed.");
240 return PRVINFO_ERROR_INTERNAL_ERROR;
242 return PRVINFO_ERROR_NONE;
245 int privilege_info_get_display_name_string_id_by_pkgtype(const char* package_type, const char* api_version, const char *privilege, char **display_name_string_id)
247 TryReturn(package_type != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] package_type is NULL");
248 TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL");
249 TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL");
253 /* Check package_type */
255 if (strcmp(package_type, "PRVINFO_PACKAGE_TYPE_NATIVE") == 0) {
256 LOGD("package_type = %s", package_type);
257 } else if (strcmp(package_type, "PRVINFO_PACKAGE_TYPE_WEB") == 0) {
258 LOGD("package_type = %s", package_type);
259 ret = privilege_db_manager_get_privilege_display(PRIVILEGE_DB_MANAGER_PACKAGE_TYPE_WRT, privilege, api_version, &temp);
260 if (ret == PRIVILEGE_DB_MANAGER_ERR_NONE) {
262 *display_name_string_id = NULL;
263 else if (strcmp(temp, "") == 0)
264 *display_name_string_id = NULL;
267 } else if (ret != PRIVILEGE_DB_NO_EXIST_RESULT) {
268 goto err_internal_error;
276 LOGD("package_type = %s", package_type);
278 return PRVINFO_ERROR_INVALID_PARAMETER;
281 ret = privilege_db_manager_get_privilege_display(PRIVILEGE_DB_MANAGER_PACKAGE_TYPE_CORE, privilege, api_version, &temp);
283 if (ret == PRIVILEGE_DB_MANAGER_ERR_NONE) {
285 goto err_no_matching_privilege;
286 else if (strcmp(temp, "") == 0)
287 goto err_no_matching_privilege;
290 } else if (ret == PRIVILEGE_DB_NO_EXIST_RESULT) {
291 goto err_no_matching_privilege;
293 goto err_internal_error;
297 *display_name_string_id = (char*)calloc(strlen(temp) + 1, sizeof(char));
298 TryReturn(*display_name_string_id != NULL, free(temp), PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation is failed.");
299 memcpy(*display_name_string_id, temp, strlen(temp));
300 LOGD("display_name_string_id = %s", *display_name_string_id);
302 return PRVINFO_ERROR_NONE;
304 err_no_matching_privilege:
305 *display_name_string_id = NULL;
307 return PRVINFO_ERROR_NO_MATCHING_PRIVILEGE;
311 return PRVINFO_ERROR_INTERNAL_ERROR;
315 int privilege_info_get_display_name_by_pkgtype(const const char* package_type, const char* api_version, const char* privilege, char** display_name)
318 char* display_name_string_id = NULL;
320 TryReturn(package_type != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] package_type is NULL");
321 TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL");
322 TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL");
324 ret = privilege_info_get_display_name_string_id_by_pkgtype(package_type, api_version, privilege, &display_name_string_id);
326 if (ret == PRVINFO_ERROR_NO_MATCHING_PRIVILEGE) {
327 char* tempPrivilege = NULL;
331 tempPrivilege = strdup(privilege);
332 TryReturn(tempPrivilege != NULL, free(tempPrivilege), PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] tempPrivilege's strdup is failed.");
333 token = strtok_r(tempPrivilege, "/", &save);
336 token = strtok_r(NULL, "/", &save);
338 *display_name = (char*)calloc(strlen(temp) + 1, sizeof(char));
339 TryReturn(*display_name != NULL, free(tempPrivilege), PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed.");
340 memcpy(*display_name, temp, strlen(temp));
342 } else if (ret == PRVINFO_ERROR_NONE) {
343 ret = privilege_info_get_display_name_by_string_id(display_name_string_id, display_name);
344 free(display_name_string_id);
345 TryReturn(ret == PRVINFO_ERROR_NONE, , PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed.");
347 return PRVINFO_ERROR_INTERNAL_ERROR;
349 return PRVINFO_ERROR_NONE;
353 int privilege_info_get_description_string_id_by_pkgtype(const char* package_type, const char* api_version, const char *privilege, char **description_string_id)
355 TryReturn(package_type != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] package_type is NULL");
356 TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL");
357 TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL");
361 /* Check package_type */
364 if (strcmp(package_type, "PRVINFO_PACKAGE_TYPE_WEB") == 0) {
365 LOGD("package_type = %s", package_type);
366 ret = privilege_db_manager_get_privilege_description(PRIVILEGE_DB_MANAGER_PACKAGE_TYPE_WRT, privilege, api_version, &temp);
367 if (ret == PRIVILEGE_DB_MANAGER_ERR_NONE) {
369 *description_string_id = NULL;
370 else if (strcmp(temp, "") == 0)
371 *description_string_id = NULL;
374 } else if (ret != PRIVILEGE_DB_NO_EXIST_RESULT) {
375 goto err_internal_error;
382 } else if (strcmp(package_type, "PRVINFO_PACKAGE_TYPE_NATIVE") == 0) {
383 LOGD("package_type = %s", package_type);
385 LOGD("package_type = %s", package_type);
387 return PRVINFO_ERROR_INVALID_PARAMETER;
390 ret = privilege_db_manager_get_privilege_description(PRIVILEGE_DB_MANAGER_PACKAGE_TYPE_CORE, privilege, api_version, &temp);
392 if (ret == PRIVILEGE_DB_MANAGER_ERR_NONE) {
394 goto err_no_matching_privilege;
395 else if (strcmp(temp, "") == 0)
396 goto err_no_matching_privilege;
399 } else if (ret == PRIVILEGE_DB_NO_EXIST_RESULT) {
400 goto err_no_matching_privilege;
402 goto err_internal_error;
407 *description_string_id = (char*)calloc(strlen(temp) + 1, sizeof(char));
408 TryReturn(*description_string_id != NULL, free(temp), PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation is failed.");
409 memcpy(*description_string_id, temp, strlen(temp));
410 LOGD("description_string_id = %s", *description_string_id);
412 return PRVINFO_ERROR_NONE;
414 err_no_matching_privilege:
415 *description_string_id = NULL;
417 return PRVINFO_ERROR_NO_MATCHING_PRIVILEGE;
421 return PRVINFO_ERROR_INTERNAL_ERROR;
425 int privilege_info_get_description_by_pkgtype(const char* package_type, const char* api_version, const char* privilege, char** description)
428 char* description_string_id = NULL;
430 TryReturn(package_type != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] package_type is NULL");
431 TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL");
432 TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL");
434 ret = privilege_info_get_description_string_id_by_pkgtype(package_type, api_version, privilege, &description_string_id);
436 if (ret == PRVINFO_ERROR_NO_MATCHING_PRIVILEGE) {
438 temp = dgettext("privilege", "IDS_TPLATFORM_BODY_THIS_PRIVILEGE_IS_NOT_DEFINED");
439 *description = (char*)calloc(strlen(temp) + 1, sizeof(char));
440 TryReturn(*description != NULL, , PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed.");
441 memcpy(*description, temp, strlen(temp));
442 /* return PRVINFO_ERROR_NO_MATCHING_PRIVILEGE; */
443 } else if (ret == PRVINFO_ERROR_NONE) {
444 ret = privilege_info_get_description_by_string_id(description_string_id, description);
445 free(description_string_id);
446 TryReturn(ret == PRVINFO_ERROR_NONE, , PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed.");
448 return PRVINFO_ERROR_INTERNAL_ERROR;
450 return PRVINFO_ERROR_NONE;