#include <libgen.h>
#include <sys/stat.h>
-#include <libxml/parser.h>
-#include <libxml/xmlreader.h>
-#include <libxml/xmlschemas.h>
#include <sqlite3.h>
#include <glib.h>
static bool _get_bool_value(const char *str)
{
- if (str == NULL)
- return false;
- else if (!strcasecmp(str, "true"))
+ if (str && !strcmp(str, "true"))
return true;
else
return false;
return;
}
-static int __child_element(xmlTextReaderPtr reader, int depth)
-{
- int ret = xmlTextReaderRead(reader);
- int cur = xmlTextReaderDepth(reader);
- while (ret == 1) {
-
- switch (xmlTextReaderNodeType(reader)) {
- case XML_READER_TYPE_ELEMENT:
- if (cur == depth + 1)
- return 1;
- break;
- case XML_READER_TYPE_TEXT:
- /*text is handled by each function separately*/
- if (cur == depth + 1)
- return 0;
- break;
- case XML_READER_TYPE_END_ELEMENT:
- if (cur == depth)
- return 0;
- break;
- default:
- if (cur <= depth)
- return 0;
- break;
- }
- ret = xmlTextReaderRead(reader);
- cur = xmlTextReaderDepth(reader);
- }
- return ret;
-}
-
long long _pkgmgr_calculate_dir_size(char *dirname)
{
long long total = 0;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
- if (info->pkg_info == NULL || info->pkg_info->type == NULL)
+ if (info->pkg_info == NULL)
return PMINFO_R_ERROR;
+ if (info->pkg_info->type == NULL)
+ info->pkg_info->type = strdup("");
*type = (char *)info->pkg_info->type;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
- if (info->pkg_info == NULL || info->pkg_info->version == NULL)
+ if (info->pkg_info == NULL)
return PMINFO_R_ERROR;
+ if (info->pkg_info->version == NULL)
+ info->pkg_info->version = strdup("");
*version = (char *)info->pkg_info->version;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
- if (info->pkg_info == NULL || info->pkg_info->api_version == NULL)
+ if (info->pkg_info == NULL)
return PMINFO_R_ERROR;
+ if (info->pkg_info->api_version == NULL)
+ info->pkg_info->api_version = strdup("");
*api_version = (char *)info->pkg_info->api_version;
if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
return PMINFO_R_ERROR;
- if (strlen(info->pkg_info->tep_name) == 0)
- return PMINFO_R_ERROR;
-
*tep_name = (char *)info->pkg_info->tep_name;
return PMINFO_R_OK;
if (info->pkg_info == NULL)
return PMINFO_R_ERROR;
+ if (info->pkg_info->zip_mount_file == NULL)
+ info->pkg_info->zip_mount_file = strdup("");
- if (info->pkg_info->zip_mount_file &&
- strlen(info->pkg_info->zip_mount_file) > 0)
- *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
+ *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
return PMINFO_R_OK;
}
API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
{
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+ char *temp = NULL;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
- if (info->pkg_info == NULL || info->pkg_info->package_size == NULL)
- return PMINFO_R_ERROR;
-
- *size = atoi((char *)info->pkg_info->package_size);
-
- return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
-{
- char *pkgid;
- char device_path[PKG_STRING_LEN_MAX] = { '\0', };
- long long rw_size = 0;
- long long ro_size = 0;
- long long tmp_size = 0;
- long long total_size = 0;
- struct stat fileinfo;
- int ret;
-
- retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
- retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
-
- ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
- if (ret < 0)
+ if (info->pkg_info == NULL)
return PMINFO_R_ERROR;
- /* RW area */
- snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
- if (lstat(device_path, &fileinfo) == 0) {
- if (!S_ISLNK(fileinfo.st_mode)) {
- tmp_size = _pkgmgr_calculate_dir_size(device_path);
- if (tmp_size > 0)
- rw_size += tmp_size;
- }
- }
-
- snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
- if (lstat(device_path, &fileinfo) == 0) {
- if (!S_ISLNK(fileinfo.st_mode)) {
- tmp_size = _pkgmgr_calculate_dir_size(device_path);
- if (tmp_size > 0)
- rw_size += tmp_size;
- }
- }
-
- snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
- if (lstat(device_path, &fileinfo) == 0) {
- if (!S_ISLNK(fileinfo.st_mode)) {
- tmp_size = _pkgmgr_calculate_dir_size(device_path);
- if (tmp_size > 0)
- rw_size += tmp_size;
- }
- }
-
- snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
- if (lstat(device_path, &fileinfo) == 0) {
- if (!S_ISLNK(fileinfo.st_mode)) {
- tmp_size = _pkgmgr_calculate_dir_size(device_path);
- if (tmp_size > 0)
- rw_size += tmp_size;
- }
- }
-
- snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
- if (lstat(device_path, &fileinfo) == 0) {
- if (!S_ISLNK(fileinfo.st_mode)) {
- tmp_size = _pkgmgr_calculate_dir_size(device_path);
- if (tmp_size > 0)
- rw_size += tmp_size;
- }
- }
-
- snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
- if (lstat(device_path, &fileinfo) == 0) {
- if (!S_ISLNK(fileinfo.st_mode)) {
- tmp_size = _pkgmgr_calculate_dir_size(device_path);
- if (tmp_size > 0)
- rw_size += tmp_size;
- }
- }
-
- /* RO area */
- snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
- if (lstat(device_path, &fileinfo) == 0) {
- if (!S_ISLNK(fileinfo.st_mode)) {
- tmp_size = _pkgmgr_calculate_dir_size(device_path);
- if (tmp_size > 0)
- ro_size += tmp_size;
- }
- }
-
- snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
- if (lstat(device_path, &fileinfo) == 0) {
- if (!S_ISLNK(fileinfo.st_mode)) {
- tmp_size = _pkgmgr_calculate_dir_size(device_path);
- if (tmp_size > 0)
- ro_size += tmp_size;
- }
- }
-
- snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
- if (lstat(device_path, &fileinfo) == 0) {
- if (!S_ISLNK(fileinfo.st_mode)) {
- tmp_size = _pkgmgr_calculate_dir_size(device_path);
- if (tmp_size > 0)
- ro_size += tmp_size;
- }
- }
-
- snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
- if (lstat(device_path, &fileinfo) == 0) {
- if (!S_ISLNK(fileinfo.st_mode)) {
- tmp_size = _pkgmgr_calculate_dir_size(device_path);
- if (tmp_size > 0)
- ro_size += tmp_size;
- }
- }
-
- snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
- if (lstat(device_path, &fileinfo) == 0) {
- if (!S_ISLNK(fileinfo.st_mode)) {
- tmp_size = _pkgmgr_calculate_dir_size(device_path);
- if (tmp_size > 0)
- ro_size += tmp_size;
- }
- }
-
- snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
- if (lstat(device_path, &fileinfo) == 0) {
- if (!S_ISLNK(fileinfo.st_mode)) {
- tmp_size = _pkgmgr_calculate_dir_size(device_path);
- if (tmp_size > 0)
- ro_size += tmp_size;
+ if (info->pkg_info->package_size == NULL) {
+ temp = strdup("");
+ if (temp == NULL) {
+ _LOGE("out of memory");
+ return PMINFO_R_ERROR;
+ } else {
+ info->pkg_info->package_size = temp;
}
}
- /* Total size */
- total_size = rw_size + ro_size;
- *size = (int)total_size;
-
- return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
-{
- char *pkgid;
- char device_path[PKG_STRING_LEN_MAX] = { '\0', };
- long long total_size = 0;
-
- retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
- retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
-
- if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) < 0)
- return PMINFO_R_ERROR;
-
- snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
- if (access(device_path, R_OK) == 0)
- total_size = _pkgmgr_calculate_dir_size(device_path);
- if (total_size < 0)
- return PMINFO_R_ERROR;
-
- *size = (int)total_size;
+ *size = atoi((char *)info->pkg_info->package_size);
return PMINFO_R_OK;
}
locale = info->locale;
retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
- if (info->pkg_info == NULL)
+ if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
return PMINFO_R_ERROR;
for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) {
ptr = (icon_x *)tmp->data;
if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
- !strcasecmp(ptr->text, "(null)") ||
strcmp(ptr->lang, locale))
continue;
*icon = (char *)ptr->text;
return PMINFO_R_OK;
}
- return PMINFO_R_ERROR;
+ *icon = "";
+
+ return PMINFO_R_OK;
}
API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
locale = info->locale;
retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
+ if (info->pkg_info == NULL || info->pkg_info->label == NULL)
+ return PMINFO_R_ERROR;
+
for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) {
ptr = (label_x *)tmp->data;
if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
return PMINFO_R_OK;
}
- return PMINFO_R_ERROR;
+ *label = "";
+
+ return PMINFO_R_OK;
}
API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
locale = info->locale;
retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
+ if (info->pkg_info == NULL || info->pkg_info->description == NULL)
+ return PMINFO_R_ERROR;
+
for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
ptr = (description_x *)tmp->data;
if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
return PMINFO_R_OK;
}
- return PMINFO_R_ERROR;
+ *description = "";
+
+ return PMINFO_R_OK;
}
API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
return PMINFO_R_ERROR;
author = (author_x *)info->pkg_info->author->data;
- if (author == NULL || author->text == NULL)
+ if (author == NULL)
return PMINFO_R_ERROR;
+ if (author->text == NULL)
+ author->text = strdup("");
*author_name = (char *)author->text;
return PMINFO_R_ERROR;
author = (author_x *)info->pkg_info->author->data;
- if (author == NULL || author->email == NULL)
+ if (author == NULL)
return PMINFO_R_ERROR;
+ if (author->email == NULL)
+ author->email = strdup("");
*author_email = (char *)author->email;
return PMINFO_R_ERROR;
author = (author_x *)info->pkg_info->author->data;
- if (author == NULL || author->href == NULL)
+ if (author == NULL)
return PMINFO_R_ERROR;
+ if (author->href == NULL)
+ author->href = strdup("");
*author_href = (char *)author->href;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
- if (info->pkg_info == NULL || info->pkg_info->storeclient_id == NULL)
+ if (info->pkg_info == NULL)
return PMINFO_R_ERROR;
+ if (info->pkg_info->storeclient_id == NULL)
+ info->pkg_info->storeclient_id = strdup("");
*storeclientid = (char *)info->pkg_info->storeclient_id;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
- if (info->pkg_info == NULL || info->pkg_info->package_url == NULL)
+ if (info->pkg_info == NULL)
return PMINFO_R_ERROR;
+ if (info->pkg_info->package_url == NULL)
+ info->pkg_info->package_url = strdup("");
*url = (char *)info->pkg_info->package_url;
return PMINFO_R_OK;
}
-API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
-{
- const char *val = NULL;
- const xmlChar *node;
- xmlTextReaderPtr reader;
- retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
- retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
-
- xmlInitParser();
- reader = xmlReaderForFile(manifest, NULL, 0);
-
- if (reader){
- if (__child_element(reader, -1)) {
- node = xmlTextReaderConstName(reader);
- if (!node) {
- _LOGE("xmlTextReaderConstName value is NULL\n");
- xmlFreeTextReader(reader);
- xmlCleanupParser();
- return PMINFO_R_ERROR;
- }
-
- if (!strcmp(ASC_CHAR(node), "manifest")) {
- if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
- val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
-
- if (val) {
- *size = atoi(val);
- } else {
- *size = 0;
- _LOGE("package size is not specified\n");
- xmlFreeTextReader(reader);
- xmlCleanupParser();
- return PMINFO_R_ERROR;
- }
- } else {
- _LOGE("Unable to create xml reader\n");
- xmlFreeTextReader(reader);
- xmlCleanupParser();
- return PMINFO_R_ERROR;
- }
- }
- } else {
- _LOGE("xmlReaderForFile value is NULL\n");
- xmlCleanupParser();
- return PMINFO_R_ERROR;
- }
-
- xmlFreeTextReader(reader);
- xmlCleanupParser();
-
- return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
-{
- const char *val = NULL;
- const xmlChar *node;
- xmlTextReaderPtr reader;
- retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
- retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
-
- xmlInitParser();
- reader = xmlReaderForFile(manifest, NULL, 0);
-
- if (reader) {
- if ( __child_element(reader, -1)) {
- node = xmlTextReaderConstName(reader);
- if (!node) {
- _LOGE("xmlTextReaderConstName value is NULL\n");
- xmlFreeTextReader(reader);
- xmlCleanupParser();
- return PMINFO_R_ERROR;
- }
-
- if (!strcmp(ASC_CHAR(node), "manifest")) {
- if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
- val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
-
- if (val) {
- if (strcmp(val, "internal-only") == 0)
- *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
- else if (strcmp(val, "prefer-external") == 0)
- *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
- else
- *location = PMINFO_INSTALL_LOCATION_AUTO;
- }
- } else {
- _LOGE("Unable to create xml reader\n");
- xmlFreeTextReader(reader);
- xmlCleanupParser();
- return PMINFO_R_ERROR;
- }
- }
- } else {
- _LOGE("xmlReaderForFile value is NULL\n");
- xmlCleanupParser();
- return PMINFO_R_ERROR;
- }
-
- xmlFreeTextReader(reader);
- xmlCleanupParser();
-
- return PMINFO_R_OK;
-}
-
-
API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
{
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
- if (info->pkg_info == NULL || info->pkg_info->csc_path == NULL)
+ if (info->pkg_info == NULL)
return PMINFO_R_ERROR;
+ if (info->pkg_info->csc_path == NULL)
+ info->pkg_info->csc_path = strdup("");
*path = (char *)info->pkg_info->csc_path;
}
/*check whether application is in internal or not */
- fp = fopen(app_dir_path, "r");
if (fp == NULL) {
_LOGD(" app path in internal memory not accesible\n");
*accessible = 0;