tizen 2.3.1 release
[framework/api/package-manager.git] / tool / main.c
1 /*
2  * package-manager
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7  * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <unistd.h>
28 #include <sys/stat.h>
29 #include <sys/types.h>
30 #include <fcntl.h>
31
32 #include <package_manager.h>
33
34
35
36 static void _print_help(const char *cmd)
37 {
38         fprintf(stderr, "Usage:\n");
39         fprintf(stderr, "\n");
40         fprintf(stderr, "[Get packageinfo value]\n");
41         fprintf(stderr, "    %s <package>\n", cmd);
42         fprintf(stderr, "\n");
43         fprintf(stderr, "Ex) %s org.tizen.memo\n", cmd);
44         fprintf(stderr, "\n");
45 }
46
47
48 static bool _cert_info_cb(package_info_h handle, package_cert_type_e cert_type,
49                                                 const char *cert_value, void *user_data)
50 {
51         fprintf(stderr, "cert_info[%d] \t= [%s]\n", cert_type, cert_value);
52
53         return true;
54 }
55
56 static int _get_packageinfo(const char *package)
57 {
58         package_info_h package_info;
59         int ret;
60         char *pkg = NULL;
61         char *label = NULL;
62         char *icon = NULL;
63         char *version = NULL;
64         char *type = NULL;
65         package_info_installed_storage_type_e storage;
66         bool system;
67         bool removable;
68         bool preload;
69
70
71         ret = package_manager_get_package_info(package, &package_info);
72         if (ret != PACKAGE_MANAGER_ERROR_NONE) {
73                 return PACKAGE_MANAGER_ERROR_INVALID_PARAMETER;
74         }
75
76         package_info_get_package(package_info, &pkg);
77         package_info_get_label(package_info, &label);
78         package_info_get_icon(package_info, &icon);
79         package_info_get_version(package_info, &version);
80         package_info_get_type(package_info, &type);
81         package_info_get_installed_storage(package_info, &storage);
82         package_info_is_system_package(package_info, &system);
83         package_info_is_removable_package(package_info, &removable);
84         package_info_is_preload_package(package_info, &preload);
85
86         fprintf(stderr, "pkg \t= [%s]\n", pkg);
87         fprintf(stderr, "label \t= [%s]\n", label);
88         fprintf(stderr, "icon \t= [%s]\n", icon);
89         fprintf(stderr, "version \t= [%s]\n", version);
90         fprintf(stderr, "type \t= [%s]\n", type);
91         fprintf(stderr, "storage \t= [%d]\n", storage);
92         fprintf(stderr, "system \t= [%d]\n", system);
93         fprintf(stderr, "removable \t= [%d]\n", removable);
94         fprintf(stderr, "preload \t= [%d]\n", preload);
95
96         package_info_foreach_cert_info(package_info, _cert_info_cb, NULL);
97
98         free(pkg);
99         free(label);
100         free(icon);
101         free(version);
102         free(type);
103
104         ret = package_info_destroy(package_info);
105         if (ret != PACKAGE_MANAGER_ERROR_NONE) {
106                 return PACKAGE_MANAGER_ERROR_INVALID_PARAMETER;
107         }
108
109         return PACKAGE_MANAGER_ERROR_NONE;
110 }
111
112 static int _get_appinfo(const char *appid)
113 {
114         int ret = 0;
115         char *package_id = NULL;
116         ret = package_manager_get_package_id_by_app_id(appid, &package_id);
117         if (ret < 0)
118                 fprintf(stderr, "package_manager_get_package_id_by_app_id fail \n");
119
120         fprintf(stderr, "app_id \t= [%s]\n", appid);
121         fprintf(stderr, "package_id \t= [%s]\n", package_id);
122
123         if (package_id)
124                 free(package_id);
125
126         return PACKAGE_MANAGER_ERROR_NONE;
127 }
128
129 int main(int argc, char** argv)
130 {
131         int ret = PACKAGE_MANAGER_ERROR_NONE;
132
133         if (2 == argc) {
134                 ret = _get_packageinfo(argv[1]);
135         } else if (3 == argc) {
136                 ret = _get_appinfo(argv[1]);
137         }
138
139         else {
140                 _print_help(argv[0]);
141                 return EXIT_FAILURE;
142         }
143
144         if (ret != PACKAGE_MANAGER_ERROR_NONE) {
145                 fprintf(stderr, "There are some problems\n");
146         }
147
148         return EXIT_SUCCESS;
149 }
150
151