4e5eada4dd00fa5df3fd748f010cc043f5324ec1
[platform/core/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         package_info_get_package(package_info, &pkg);
76         package_info_get_label(package_info, &label);
77         package_info_get_icon(package_info, &icon);
78         package_info_get_version(package_info, &version);
79         package_info_get_type(package_info, &type);
80         package_info_get_installed_storage(package_info, &storage);
81         package_info_is_system_package(package_info, &system);
82         package_info_is_removable_package(package_info, &removable);
83         package_info_is_preload_package(package_info, &preload);
84
85         fprintf(stderr, "pkg \t= [%s]\n", pkg);
86         fprintf(stderr, "label \t= [%s]\n", label);
87         fprintf(stderr, "icon \t= [%s]\n", icon);
88         fprintf(stderr, "version \t= [%s]\n", version);
89         fprintf(stderr, "type \t= [%s]\n", type);
90         fprintf(stderr, "storage \t= [%d]\n", storage);
91         fprintf(stderr, "system \t= [%d]\n", system);
92         fprintf(stderr, "removable \t= [%d]\n", removable);
93         fprintf(stderr, "preload \t= [%d]\n", preload);
94
95         package_info_foreach_cert_info(package_info, _cert_info_cb, NULL);
96
97         free(pkg);
98         free(label);
99         free(icon);
100         free(version);
101         free(type);
102
103         ret = package_info_destroy(package_info);
104         if (ret != PACKAGE_MANAGER_ERROR_NONE)
105                 return PACKAGE_MANAGER_ERROR_INVALID_PARAMETER;
106
107         return PACKAGE_MANAGER_ERROR_NONE;
108 }
109
110 static int _get_appinfo(const char *appid)
111 {
112         char *package_id = NULL;
113         package_manager_get_package_id_by_app_id(appid, &package_id);
114
115         fprintf(stderr, "app_id \t= [%s]\n", appid);
116         fprintf(stderr, "package_id \t= [%s]\n", package_id);
117
118         return PACKAGE_MANAGER_ERROR_NONE;
119 }
120
121 int main(int argc, char **argv)
122 {
123         int ret = PACKAGE_MANAGER_ERROR_NONE;
124
125         if (1 == argc) {
126                 fprintf(stderr, "mising operand\n");
127                 return EXIT_FAILURE;
128         } else if (2 == argc) {
129                 ret = _get_packageinfo(argv[1]);
130         } else if (3 == argc) {
131                 ret = _get_appinfo(argv[1]);
132         }
133
134         else {
135                 _print_help(argv[0]);
136                 return EXIT_FAILURE;
137         }
138
139         if (ret != PACKAGE_MANAGER_ERROR_NONE) {
140                 fprintf(stderr, "There are some problems\n");
141                 return EXIT_FAILURE;
142         }
143
144         return EXIT_SUCCESS;
145 }
146
147