d69920fce81da1e16f5f17adec5c1c7b8ced7126
[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 static void _print_help(const char *cmd)
62 {
63         int i;
64
65         fprintf(stderr, "Usage:\n");
66         fprintf(stderr, "\n");
67         fprintf(stderr, "[Get appinfo value]\n");
68         fprintf(stderr, "       %s get <PACKAGE NAME> <COLUMN NAME>\n", cmd);
69         fprintf(stderr, "\n");
70         fprintf(stderr, "       <COLUMN NAME>\n");
71
72         for (i = 0; prop_tbl[i]; i++)
73                 fprintf(stderr, "          %s\n", prop_tbl[i]);
74
75         fprintf(stderr, "\n");
76         fprintf(stderr, "       Ex) %s get com.samsung.menu-screen X_SLP_SERVICE\n", cmd);
77         fprintf(stderr, "\n");
78 }
79
80 static int _get_property(const char *property)
81 {
82         int i;
83
84         if (!property)
85                 return 0;
86
87         for (i = 0; prop_tbl[i]; i++) {
88                 if (!strcasecmp(prop_tbl[i], property))
89                         return i;
90         }
91
92         fprintf(stderr, "%s is not found\n", property);
93
94         return -1;
95 }
96
97 static ail_error_e _get_appinfo(const char *package, const char *property, uid_t uid)
98 {
99         ail_appinfo_h handle;
100         ail_error_e ret;
101         int prop, ival;
102         bool bval;
103         char *str = NULL;;
104         struct element e;
105         struct element *p;
106         int t;
107
108         /* __is admin */
109         ret = ail_get_appinfo(package, &handle);
110         if (ret != AIL_ERROR_OK)
111                 return AIL_ERROR_FAIL;
112
113         prop = _get_property(property);
114         if (prop < 0)
115                 goto END;
116
117         e.prop = prop;
118         p = &e;
119         ELEMENT_TYPE(p, t);
120
121         if (t == VAL_TYPE_STR) {
122                 ret = ail_appinfo_get_str(handle, property, &str);
123                 if (ret != AIL_ERROR_OK)
124                         goto END;
125
126                 fprintf(stderr, "Package[%s], Property[%s] : %s\n", package, property, str);
127         } else if (t == VAL_TYPE_INT) {
128                 ret = ail_appinfo_get_int(handle, property, &ival);
129                 if (ret != AIL_ERROR_OK)
130                         goto END;
131
132                 fprintf(stderr, "Package[%s], Property[%s] : %d\n", package, property, ival);
133         } else if (t == VAL_TYPE_BOOL) {
134                 ret = ail_appinfo_get_bool(handle, property, &bval);
135                 if (ret != AIL_ERROR_OK)
136                         goto END;
137
138                 fprintf(stderr, "Package[%s], Property[%s] : %d\n", package, property, bval);
139         }
140
141 END:
142         free(str);
143
144         ret = ail_destroy_appinfo(handle);
145         if (ret != AIL_ERROR_OK)
146                 return AIL_ERROR_FAIL;
147
148         return AIL_ERROR_OK;
149 }
150
151 int main(int argc, char** argv)
152 {
153         ail_error_e ret = AIL_ERROR_OK;
154
155
156         if (argc == 4) {
157                 if (!strncmp(argv[1], "get", 3))
158                         ret = _get_appinfo(argv[2], argv[3], getuid());
159         } else {
160                 _print_help(argv[0]);
161                 return EXIT_FAILURE;
162         }
163
164         if (ret != AIL_ERROR_OK)
165                 fprintf(stderr, "There are some problems\n");
166
167         return EXIT_SUCCESS;
168 }