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