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_INVALID_PARAMETER) {
328 } else if (ret == PRVINFO_ERROR_NO_MATCHING_PRIVILEGE) {
329 char* tempPrivilege = NULL;
333 tempPrivilege = strdup(privilege);
334 TryReturn(tempPrivilege != NULL, free(tempPrivilege), PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] tempPrivilege's strdup is failed.");
335 token = strtok_r(tempPrivilege, "/", &save);
338 token = strtok_r(NULL, "/", &save);
340 *display_name = (char*)calloc(strlen(temp) + 1, sizeof(char));
341 TryReturn(*display_name != NULL, free(tempPrivilege), PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed.");
342 memcpy(*display_name, temp, strlen(temp));
344 } else if (ret == PRVINFO_ERROR_NONE) {
345 ret = privilege_info_get_display_name_by_string_id(display_name_string_id, display_name);
346 free(display_name_string_id);
347 TryReturn(ret == PRVINFO_ERROR_NONE, , PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed.");
349 return PRVINFO_ERROR_INTERNAL_ERROR;
351 return PRVINFO_ERROR_NONE;
355 int privilege_info_get_description_string_id_by_pkgtype(const char* package_type, const char* api_version, const char *privilege, char **description_string_id)
357 TryReturn(package_type != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] package_type is NULL");
358 TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL");
359 TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL");
363 /* Check package_type */
366 if (strcmp(package_type, "PRVINFO_PACKAGE_TYPE_WEB") == 0) {
367 LOGD("package_type = %s", package_type);
368 ret = privilege_db_manager_get_privilege_description(PRIVILEGE_DB_MANAGER_PACKAGE_TYPE_WRT, privilege, api_version, &temp);
369 if (ret == PRIVILEGE_DB_MANAGER_ERR_NONE) {
371 *description_string_id = NULL;
372 else if (strcmp(temp, "") == 0)
373 *description_string_id = NULL;
376 } else if (ret != PRIVILEGE_DB_NO_EXIST_RESULT) {
377 goto err_internal_error;
384 } else if (strcmp(package_type, "PRVINFO_PACKAGE_TYPE_NATIVE") == 0) {
385 LOGD("package_type = %s", package_type);
387 LOGD("package_type = %s", package_type);
389 return PRVINFO_ERROR_INVALID_PARAMETER;
392 ret = privilege_db_manager_get_privilege_description(PRIVILEGE_DB_MANAGER_PACKAGE_TYPE_CORE, privilege, api_version, &temp);
394 if (ret == PRIVILEGE_DB_MANAGER_ERR_NONE) {
396 goto err_no_matching_privilege;
397 else if (strcmp(temp, "") == 0)
398 goto err_no_matching_privilege;
401 } else if (ret == PRIVILEGE_DB_NO_EXIST_RESULT) {
402 goto err_no_matching_privilege;
404 goto err_internal_error;
409 *description_string_id = (char*)calloc(strlen(temp) + 1, sizeof(char));
410 TryReturn(*description_string_id != NULL, free(temp), PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation is failed.");
411 memcpy(*description_string_id, temp, strlen(temp));
412 LOGD("description_string_id = %s", *description_string_id);
414 return PRVINFO_ERROR_NONE;
416 err_no_matching_privilege:
417 *description_string_id = NULL;
419 return PRVINFO_ERROR_NO_MATCHING_PRIVILEGE;
423 return PRVINFO_ERROR_INTERNAL_ERROR;
427 int privilege_info_get_description_by_pkgtype(const char* package_type, const char* api_version, const char* privilege, char** description)
430 char* description_string_id = NULL;
432 TryReturn(package_type != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] package_type is NULL");
433 TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL");
434 TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL");
436 ret = privilege_info_get_description_string_id_by_pkgtype(package_type, api_version, privilege, &description_string_id);
438 if (ret == PRVINFO_ERROR_INVALID_PARAMETER) {
440 } else if (ret == PRVINFO_ERROR_NO_MATCHING_PRIVILEGE) {
442 temp = dgettext("privilege", "IDS_TPLATFORM_BODY_THIS_PRIVILEGE_IS_NOT_DEFINED");
443 *description = (char*)calloc(strlen(temp) + 1, sizeof(char));
444 TryReturn(*description != NULL, , PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed.");
445 memcpy(*description, temp, strlen(temp));
446 /* return PRVINFO_ERROR_NO_MATCHING_PRIVILEGE; */
447 } else if (ret == PRVINFO_ERROR_NONE) {
448 ret = privilege_info_get_description_by_string_id(description_string_id, description);
449 free(description_string_id);
450 TryReturn(ret == PRVINFO_ERROR_NONE, , PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed.");
452 return PRVINFO_ERROR_INTERNAL_ERROR;
454 return PRVINFO_ERROR_NONE;