5e129c7be23d4bebfa8f7846ad6aab7cda355f9d
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgr-info-internal.c
1 /*
2  * pkgmgr-info
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 #include <stdlib.h>
24 #include <string.h>
25 #include <stdio.h>
26 #include "pkgmgr-info.h"
27 #include "pkgmgr-info-internal.h"
28
29 struct _pkginfo_str_map_t {
30         pkgmgrinfo_pkginfo_filter_prop_str prop;
31         const char *property;
32 };
33
34 static struct _pkginfo_str_map_t pkginfo_str_prop_map[] = {
35         {E_PMINFO_PKGINFO_PROP_PACKAGE_ID,              PMINFO_PKGINFO_PROP_PACKAGE_ID},
36         {E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE,            PMINFO_PKGINFO_PROP_PACKAGE_TYPE},
37         {E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION,         PMINFO_PKGINFO_PROP_PACKAGE_VERSION},
38         {E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION,PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION},
39         {E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE,PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE},
40         {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME,     PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME},
41         {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL,    PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL},
42         {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF,     PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF}
43 };
44
45 struct _pkginfo_int_map_t {
46         pkgmgrinfo_pkginfo_filter_prop_int prop;
47         const char *property;
48 };
49
50 static struct _pkginfo_int_map_t pkginfo_int_prop_map[] = {
51         {E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE,    PMINFO_PKGINFO_PROP_PACKAGE_SIZE}
52 };
53
54 struct _pkginfo_bool_map_t {
55         pkgmgrinfo_pkginfo_filter_prop_bool prop;
56         const char *property;
57 };
58
59 static struct _pkginfo_bool_map_t pkginfo_bool_prop_map[] = {
60         {E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE,       PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE},
61         {E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD,         PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD},
62         {E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY,        PMINFO_PKGINFO_PROP_PACKAGE_READONLY},
63         {E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE,          PMINFO_PKGINFO_PROP_PACKAGE_UPDATE},
64         {E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING,      PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING},
65         {E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING,       PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING}
66 };
67
68 struct _appinfo_str_map_t {
69         pkgmgrinfo_appinfo_filter_prop_str prop;
70         const char *property;
71 };
72
73 static struct _appinfo_str_map_t appinfo_str_prop_map[] = {
74         {E_PMINFO_APPINFO_PROP_APP_ID,          PMINFO_APPINFO_PROP_APP_ID},
75         {E_PMINFO_APPINFO_PROP_APP_COMPONENT,   PMINFO_APPINFO_PROP_APP_COMPONENT},
76         {E_PMINFO_APPINFO_PROP_APP_EXEC,        PMINFO_APPINFO_PROP_APP_EXEC},
77         {E_PMINFO_APPINFO_PROP_APP_ICON,        PMINFO_APPINFO_PROP_APP_ICON},
78         {E_PMINFO_APPINFO_PROP_APP_TYPE,        PMINFO_APPINFO_PROP_APP_TYPE},
79         {E_PMINFO_APPINFO_PROP_APP_OPERATION,   PMINFO_APPINFO_PROP_APP_OPERATION},
80         {E_PMINFO_APPINFO_PROP_APP_URI,         PMINFO_APPINFO_PROP_APP_URI},
81         {E_PMINFO_APPINFO_PROP_APP_MIME,        PMINFO_APPINFO_PROP_APP_MIME},
82         {E_PMINFO_APPINFO_PROP_APP_CATEGORY,    PMINFO_APPINFO_PROP_APP_CATEGORY},
83         {E_PMINFO_APPINFO_PROP_APP_HWACCELERATION,      PMINFO_APPINFO_PROP_APP_HWACCELERATION},
84         {E_PMINFO_APPINFO_PROP_APP_SCREENREADER,        PMINFO_APPINFO_PROP_APP_SCREENREADER},
85         {E_PMINFO_APPINFO_PROP_APP_PACKAGE,     PMINFO_APPINFO_PROP_APP_PACKAGE}
86 };
87
88 struct _appinfo_int_map_t {
89         pkgmgrinfo_appinfo_filter_prop_int prop;
90         const char *property;
91 };
92
93 static struct _appinfo_int_map_t appinfo_int_prop_map[] = {
94         /*Currently No Fields*/
95 };
96
97 struct _appinfo_bool_map_t {
98         pkgmgrinfo_appinfo_filter_prop_bool prop;
99         const char *property;
100 };
101
102 static struct _appinfo_bool_map_t appinfo_bool_prop_map[] = {
103         {E_PMINFO_APPINFO_PROP_APP_NODISPLAY,           PMINFO_APPINFO_PROP_APP_NODISPLAY},
104         {E_PMINFO_APPINFO_PROP_APP_MULTIPLE,            PMINFO_APPINFO_PROP_APP_MULTIPLE},
105         {E_PMINFO_APPINFO_PROP_APP_ONBOOT,              PMINFO_APPINFO_PROP_APP_ONBOOT},
106         {E_PMINFO_APPINFO_PROP_APP_AUTORESTART,         PMINFO_APPINFO_PROP_APP_AUTORESTART},
107         {E_PMINFO_APPINFO_PROP_APP_TASKMANAGE,          PMINFO_APPINFO_PROP_APP_TASKMANAGE},
108         {E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION,             PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION}
109 };
110
111 inline pkgmgrinfo_pkginfo_filter_prop_str _pminfo_pkginfo_convert_to_prop_str(const char *property)
112 {
113         int i = 0;
114         int max = 0;
115         pkgmgrinfo_pkginfo_filter_prop_str prop = -1;
116
117         if (property == NULL)
118                 return -1;
119         max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR + 1;
120         for (i = 0 ; i < max; i++) {
121                 if (strcmp(property, pkginfo_str_prop_map[i].property) == 0) {
122                         prop =  pkginfo_str_prop_map[i].prop;
123                         break;
124                 }
125         }
126         return prop;
127 }
128
129 inline pkgmgrinfo_pkginfo_filter_prop_int _pminfo_pkginfo_convert_to_prop_int(const char *property)
130 {
131         int i = 0;
132         int max = 0;
133         pkgmgrinfo_pkginfo_filter_prop_int prop = -1;
134
135         if (property == NULL)
136                 return -1;
137         max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT + 1;
138         for (i = 0 ; i < max; i++) {
139                 if (strcmp(property, pkginfo_int_prop_map[i].property) == 0) {
140                         prop =  pkginfo_int_prop_map[i].prop;
141                         break;
142                 }
143         }
144         return prop;
145 }
146
147 inline pkgmgrinfo_pkginfo_filter_prop_bool _pminfo_pkginfo_convert_to_prop_bool(const char *property)
148 {
149         int i = 0;
150         int max = 0;
151         pkgmgrinfo_pkginfo_filter_prop_bool prop = -1;
152
153         if (property == NULL)
154                 return -1;
155         max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL + 1;
156         for (i = 0 ; i < max; i++) {
157                 if (strcmp(property, pkginfo_bool_prop_map[i].property) == 0) {
158                         prop =  pkginfo_bool_prop_map[i].prop;
159                         break;
160                 }
161         }
162         return prop;
163 }
164
165 inline pkgmgrinfo_appinfo_filter_prop_str _pminfo_appinfo_convert_to_prop_str(const char *property)
166 {
167         int i = 0;
168         int max = 0;
169         pkgmgrinfo_appinfo_filter_prop_str prop = -1;
170
171         if (property == NULL)
172                 return -1;
173         max = E_PMINFO_APPINFO_PROP_APP_MAX_STR - E_PMINFO_APPINFO_PROP_APP_MIN_STR + 1;
174         for (i = 0 ; i < max; i++) {
175                 if (strcmp(property, appinfo_str_prop_map[i].property) == 0) {
176                         prop =  appinfo_str_prop_map[i].prop;
177                         break;
178                 }
179         }
180         return prop;
181 }
182
183 inline pkgmgrinfo_appinfo_filter_prop_int _pminfo_appinfo_convert_to_prop_int(const char *property)
184 {
185         int i = 0;
186         int max = 0;
187         pkgmgrinfo_appinfo_filter_prop_int prop = -1;
188
189         if (property == NULL)
190                 return -1;
191         max = E_PMINFO_APPINFO_PROP_APP_MAX_INT - E_PMINFO_APPINFO_PROP_APP_MIN_INT + 1;
192         for (i = 0 ; i < max; i++) {
193                 if (strcmp(property, appinfo_int_prop_map[i].property) == 0) {
194                         prop =  appinfo_int_prop_map[i].prop;
195                         break;
196                 }
197         }
198         return prop;
199 }
200
201 inline pkgmgrinfo_appinfo_filter_prop_bool _pminfo_appinfo_convert_to_prop_bool(const char *property)
202 {
203         int i = 0;
204         int max = 0;
205         pkgmgrinfo_appinfo_filter_prop_bool prop = -1;
206
207         if (property == NULL)
208                 return -1;
209         max = E_PMINFO_APPINFO_PROP_APP_MAX_BOOL - E_PMINFO_APPINFO_PROP_APP_MIN_BOOL + 1;
210         for (i = 0 ; i < max; i++) {
211                 if (strcmp(property, appinfo_bool_prop_map[i].property) == 0) {
212                         prop =  appinfo_bool_prop_map[i].prop;
213                         break;
214                 }
215         }
216         return prop;
217 }