Multi user features :
[platform/core/appfw/ail.git] / tool / src / ail_package.c
1 /*
2  * ail
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>, Jaeho Lee <jaeho81.lee@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <sys/stat.h>
27 #include <sys/types.h>
28 #include <fcntl.h>
29
30 #include <ail.h>
31 #include "ail_private.h"
32
33 char *prop_tbl[] = {
34         AIL_PROP_PACKAGE_STR,
35         AIL_PROP_EXEC_STR,
36         AIL_PROP_NAME_STR,
37         AIL_PROP_TYPE_STR,
38         AIL_PROP_ICON_STR,
39         AIL_PROP_CATEGORIES_STR,
40         AIL_PROP_VERSION_STR,
41         AIL_PROP_MIMETYPE_STR,
42         AIL_PROP_X_SLP_SERVICE_STR,
43         AIL_PROP_X_SLP_PACKAGETYPE_STR,
44         AIL_PROP_X_SLP_PACKAGECATEGORIES_STR,
45         AIL_PROP_X_SLP_PACKAGEID_STR,
46         AIL_PROP_X_SLP_SVC_STR,
47         AIL_PROP_X_SLP_EXE_PATH,
48         AIL_PROP_X_SLP_APPID_STR,
49         AIL_PROP_X_SLP_PKGID_STR,
50         AIL_PROP_X_SLP_DOMAIN_STR,
51         AIL_PROP_X_SLP_SUBMODEMAINID_STR,
52         AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR,
53         AIL_PROP_NODISPLAY_BOOL,
54         AIL_PROP_X_SLP_TASKMANAGE_BOOL,
55         AIL_PROP_X_SLP_MULTIPLE_BOOL,
56         AIL_PROP_X_SLP_REMOVABLE_BOOL,
57         AIL_PROP_X_SLP_SUBMODE_BOOL,
58         NULL
59 };
60
61
62 static void _print_help(const char *cmd)
63 {
64         int i;
65
66         fprintf(stderr, "Usage:\n");
67         fprintf(stderr, "\n");
68         fprintf(stderr, "[Get appinfo value]\n");
69         fprintf(stderr, "       %s get <PACKAGE NAME> <COLUMN NAME>\n", cmd);
70         fprintf(stderr, "\n");
71         fprintf(stderr, "       <COLUMN NAME>\n");
72
73         for (i = 0; prop_tbl[i]; i++) {
74                 fprintf(stderr, "          %s\n", prop_tbl[i]);
75         }
76
77         fprintf(stderr, "\n");
78         fprintf(stderr, "       Ex) %s get com.samsung.menu-screen X_SLP_SERVICE\n", cmd);
79         fprintf(stderr, "\n");
80 }
81
82
83
84 static int _get_property(const char *property)
85 {
86         int i;
87
88         if (!property) {
89                 return 0;
90         }
91
92         for (i = 0; prop_tbl[i]; i++) {
93                 if (!strcasecmp(prop_tbl[i], property)) {
94                         return i;
95                 }
96         }
97
98         fprintf(stderr, "%s is not found\n", property);
99
100         return -1;
101 }
102
103
104
105 static ail_error_e _get_appinfo(const char *package, const char *property, uid_t uid)
106 {
107         ail_appinfo_h handle;
108         ail_error_e ret;
109         int prop, ival;
110         bool bval;
111         char *str;
112         struct element e;
113         struct element *p;
114         int t;
115     //__isadmin)
116         ret = ail_package_get_appinfo(package, &handle);
117         if (ret != AIL_ERROR_OK) {
118                 return AIL_ERROR_FAIL;
119         }
120
121         prop = _get_property(property);
122         if (prop < 0) {
123                 goto END;
124         }
125
126         e.prop = prop;
127         p = &e;
128         ELEMENT_TYPE(p,t);
129
130         if (t == VAL_TYPE_STR) {
131                 ret = ail_appinfo_get_str(handle, property, &str);
132                 if (ret != AIL_ERROR_OK) {
133                         goto END;
134                 }
135                 fprintf(stderr, "Package[%s], Property[%s] : %s\n", package, property, str);
136         } else if (t == VAL_TYPE_INT) {
137                 ret = ail_appinfo_get_int(handle, property, &ival);
138                 if (ret != AIL_ERROR_OK) {
139                         goto END;
140                 }
141                 fprintf(stderr, "Package[%s], Property[%s] : %d\n", package, property, ival);
142         } else if (t == VAL_TYPE_BOOL) {
143                 ret = ail_appinfo_get_bool(handle, property, &bval);
144                 if (ret != AIL_ERROR_OK) {
145                         goto END;
146                 }
147                 fprintf(stderr, "Package[%s], Property[%s] : %d\n", package, property, bval);
148         }
149
150 END:
151         ret = ail_package_destroy_appinfo(handle);
152         if (ret != AIL_ERROR_OK) {
153                 return AIL_ERROR_FAIL;
154         }
155
156         return AIL_ERROR_OK;
157 }
158
159 int main(int argc, char** argv)
160 {
161         ail_error_e ret = AIL_ERROR_OK;
162
163
164         if (4 == argc) {
165                 if (!strncmp(argv[1], "get", 3)) {
166                         ret = _get_appinfo(argv[2], argv[3], getuid());
167                 }
168         }
169         else {
170                 _print_help(argv[0]);
171                 return EXIT_FAILURE;
172         }
173
174         if (ret != AIL_ERROR_OK) {
175                 fprintf(stderr, "There are some problems\n");
176         }
177
178         return EXIT_SUCCESS;
179 }
180
181