+#include <stdlib.h>
+#include <sys/types.h>
+
+#include <unzip.h>
+
+#include <pkgmgr-info.h>
+
+#include "pkgmgr-server.h"
+
+struct manifest_and_type {
+ const char *manifest;
+ const char *type;
+};
+
+struct manifest_and_type type_map[] = {
+ { "res/wgt/config.xml", "wgt" },
+ { "config.xml", "wgt" },
+ { "tizen-manifest.xml", "tpk" },
+ { NULL, NULL }
+};
+
+const char *_get_pkgtype_from_file(const char *file_path)
+{
+ const char *type = NULL;
+ unzFile uf;
+ int i;
+
+ uf = unzOpen(file_path);
+ if (uf == NULL) {
+ ERR("failed to open zip file %s", file_path);
+ return NULL;
+ }
+
+ for (i = 0; type_map[i].manifest != NULL; i++) {
+ if (unzLocateFile(uf, type_map[i].manifest, 0) == UNZ_OK) {
+ DBG("pkgtype of %s: [%s]", file_path, type_map[i].type);
+ type = type_map[i].type;
+ break;
+ }
+ }
+
+ unzClose(uf);
+
+ return type;
+}
+
+char *_get_pkgtype_from_pkgid(const char *pkgid, uid_t uid)
+{
+ char *type;
+ char *pkgtype;
+ pkgmgrinfo_pkginfo_h info;
+ int ret;
+
+ ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &info);
+ if (ret != PMINFO_R_OK) {
+ ret = pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, uid,
+ &info);
+ if (ret != PMINFO_R_OK)
+ return NULL;
+ }
+
+ ret = pkgmgrinfo_pkginfo_get_type(info, &pkgtype);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_pkginfo_destroy_pkginfo(info);
+ return NULL;
+ }
+
+ DBG("pkgtype of %s: [%s]", pkgid, pkgtype);
+
+ type = strdup(pkgtype);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(info);
+
+ return type;
+}