remove getting TZ_USER_ICONS path
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_private.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 <ctype.h>
27
28 #include <vconf.h>
29 #include <sqlite3.h>
30 #include <glib.h>
31
32 #include "pkgmgr-info.h"
33 #include "pkgmgrinfo_debug.h"
34 #include "pkgmgrinfo_private.h"
35 #include "pkgmgr_parser.h"
36
37 struct _pkginfo_str_map_t {
38         pkgmgrinfo_pkginfo_filter_prop_str prop;
39         const char *property;
40 };
41
42 static struct _pkginfo_str_map_t pkginfo_str_prop_map[] = {
43         {E_PMINFO_PKGINFO_PROP_PACKAGE_ID,      PMINFO_PKGINFO_PROP_PACKAGE_ID},
44         {E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE,    PMINFO_PKGINFO_PROP_PACKAGE_TYPE},
45         {E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION, PMINFO_PKGINFO_PROP_PACKAGE_VERSION},
46         {E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION,        PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION},
47         {E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE,       PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE},
48         {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME,     PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME},
49         {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL,    PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL},
50         {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF,     PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF},
51         {E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE,       PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE}
52 };
53
54 struct _pkginfo_int_map_t {
55         pkgmgrinfo_pkginfo_filter_prop_int prop;
56         const char *property;
57 };
58
59 static struct _pkginfo_int_map_t pkginfo_int_prop_map[] = {
60         {E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE,    PMINFO_PKGINFO_PROP_PACKAGE_SIZE}
61 };
62
63 struct _pkginfo_bool_map_t {
64         pkgmgrinfo_pkginfo_filter_prop_bool prop;
65         const char *property;
66 };
67
68 static struct _pkginfo_bool_map_t pkginfo_bool_prop_map[] = {
69         {E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE,       PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE},
70         {E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD,         PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD},
71         {E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY,        PMINFO_PKGINFO_PROP_PACKAGE_READONLY},
72         {E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE,          PMINFO_PKGINFO_PROP_PACKAGE_UPDATE},
73         {E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING,      PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING},
74         {E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING,       PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING},
75         {E_PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE, PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE},
76         {E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE}
77 };
78
79 struct _appinfo_str_map_t {
80         pkgmgrinfo_appinfo_filter_prop_str prop;
81         const char *property;
82 };
83
84 static struct _appinfo_str_map_t appinfo_str_prop_map[] = {
85         {E_PMINFO_APPINFO_PROP_APP_ID,          PMINFO_APPINFO_PROP_APP_ID},
86         {E_PMINFO_APPINFO_PROP_APP_COMPONENT,   PMINFO_APPINFO_PROP_APP_COMPONENT},
87         {E_PMINFO_APPINFO_PROP_APP_EXEC,        PMINFO_APPINFO_PROP_APP_EXEC},
88         {E_PMINFO_APPINFO_PROP_APP_ICON,        PMINFO_APPINFO_PROP_APP_ICON},
89         {E_PMINFO_APPINFO_PROP_APP_TYPE,        PMINFO_APPINFO_PROP_APP_TYPE},
90         {E_PMINFO_APPINFO_PROP_APP_OPERATION,   PMINFO_APPINFO_PROP_APP_OPERATION},
91         {E_PMINFO_APPINFO_PROP_APP_URI, PMINFO_APPINFO_PROP_APP_URI},
92         {E_PMINFO_APPINFO_PROP_APP_MIME,        PMINFO_APPINFO_PROP_APP_MIME},
93         {E_PMINFO_APPINFO_PROP_APP_CATEGORY,    PMINFO_APPINFO_PROP_APP_CATEGORY},
94         {E_PMINFO_APPINFO_PROP_APP_HWACCELERATION,      PMINFO_APPINFO_PROP_APP_HWACCELERATION},
95         {E_PMINFO_APPINFO_PROP_APP_SCREENREADER,        PMINFO_APPINFO_PROP_APP_SCREENREADER},
96         {E_PMINFO_APPINFO_PROP_APP_METADATA_KEY,        PMINFO_APPINFO_PROP_APP_METADATA_KEY},
97         {E_PMINFO_APPINFO_PROP_APP_METADATA_VALUE,      PMINFO_APPINFO_PROP_APP_METADATA_VALUE},
98         {E_PMINFO_APPINFO_PROP_APP_PACKAGE,     PMINFO_APPINFO_PROP_APP_PACKAGE}
99 };
100
101 struct _appinfo_int_map_t {
102         pkgmgrinfo_appinfo_filter_prop_int prop;
103         const char *property;
104 };
105
106 static struct _appinfo_int_map_t appinfo_int_prop_map[] = {
107         {E_PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER,    PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER}
108 };
109
110 struct _appinfo_bool_map_t {
111         pkgmgrinfo_appinfo_filter_prop_bool prop;
112         const char *property;
113 };
114
115 static struct _appinfo_bool_map_t appinfo_bool_prop_map[] = {
116         {E_PMINFO_APPINFO_PROP_APP_NODISPLAY,           PMINFO_APPINFO_PROP_APP_NODISPLAY},
117         {E_PMINFO_APPINFO_PROP_APP_MULTIPLE,            PMINFO_APPINFO_PROP_APP_MULTIPLE},
118         {E_PMINFO_APPINFO_PROP_APP_ONBOOT,              PMINFO_APPINFO_PROP_APP_ONBOOT},
119         {E_PMINFO_APPINFO_PROP_APP_AUTORESTART,         PMINFO_APPINFO_PROP_APP_AUTORESTART},
120         {E_PMINFO_APPINFO_PROP_APP_TASKMANAGE,          PMINFO_APPINFO_PROP_APP_TASKMANAGE},
121         {E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION,             PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION},
122         {E_PMINFO_APPINFO_PROP_APP_UI_GADGET,           PMINFO_APPINFO_PROP_APP_UI_GADGET},
123         {E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE,             PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE},
124         {E_PMINFO_APPINFO_PROP_APP_DISABLE,             PMINFO_APPINFO_PROP_APP_DISABLE}
125 };
126
127 inline pkgmgrinfo_pkginfo_filter_prop_str _pminfo_pkginfo_convert_to_prop_str(const char *property)
128 {
129         int i = 0;
130         int max = 0;
131         pkgmgrinfo_pkginfo_filter_prop_str prop = -1;
132
133         if (property == NULL)
134                 return -1;
135         max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR + 1;
136         for (i = 0 ; i < max; i++) {
137                 if (strcmp(property, pkginfo_str_prop_map[i].property) == 0) {
138                         prop =  pkginfo_str_prop_map[i].prop;
139                         break;
140                 }
141         }
142         return prop;
143 }
144
145 inline pkgmgrinfo_pkginfo_filter_prop_int _pminfo_pkginfo_convert_to_prop_int(const char *property)
146 {
147         int i = 0;
148         int max = 0;
149         pkgmgrinfo_pkginfo_filter_prop_int prop = -1;
150
151         if (property == NULL)
152                 return -1;
153         max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT + 1;
154         for (i = 0 ; i < max; i++) {
155                 if (strcmp(property, pkginfo_int_prop_map[i].property) == 0) {
156                         prop =  pkginfo_int_prop_map[i].prop;
157                         break;
158                 }
159         }
160         return prop;
161 }
162
163 inline pkgmgrinfo_pkginfo_filter_prop_bool _pminfo_pkginfo_convert_to_prop_bool(const char *property)
164 {
165         int i = 0;
166         int max = 0;
167         pkgmgrinfo_pkginfo_filter_prop_bool prop = -1;
168
169         if (property == NULL)
170                 return -1;
171         max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL + 1;
172         for (i = 0 ; i < max; i++) {
173                 if (strcmp(property, pkginfo_bool_prop_map[i].property) == 0) {
174                         prop =  pkginfo_bool_prop_map[i].prop;
175                         break;
176                 }
177         }
178         return prop;
179 }
180
181 inline pkgmgrinfo_appinfo_filter_prop_str _pminfo_appinfo_convert_to_prop_str(const char *property)
182 {
183         int i = 0;
184         int max = 0;
185         pkgmgrinfo_appinfo_filter_prop_str prop = -1;
186
187         if (property == NULL)
188                 return -1;
189         max = E_PMINFO_APPINFO_PROP_APP_MAX_STR - E_PMINFO_APPINFO_PROP_APP_MIN_STR + 1;
190         for (i = 0 ; i < max; i++) {
191                 if (strcmp(property, appinfo_str_prop_map[i].property) == 0) {
192                         prop =  appinfo_str_prop_map[i].prop;
193                         break;
194                 }
195         }
196         return prop;
197 }
198
199 inline pkgmgrinfo_appinfo_filter_prop_int _pminfo_appinfo_convert_to_prop_int(const char *property)
200 {
201         int i = 0;
202         int max = 0;
203         pkgmgrinfo_appinfo_filter_prop_int prop = -1;
204
205         if (property == NULL)
206                 return -1;
207         max = E_PMINFO_APPINFO_PROP_APP_MAX_INT - E_PMINFO_APPINFO_PROP_APP_MIN_INT + 1;
208         for (i = 0 ; i < max; i++) {
209                 if (strcmp(property, appinfo_int_prop_map[i].property) == 0) {
210                         prop =  appinfo_int_prop_map[i].prop;
211                         break;
212                 }
213         }
214         return prop;
215 }
216
217 inline pkgmgrinfo_appinfo_filter_prop_bool _pminfo_appinfo_convert_to_prop_bool(const char *property)
218 {
219         int i = 0;
220         int max = 0;
221         pkgmgrinfo_appinfo_filter_prop_bool prop = -1;
222
223         if (property == NULL)
224                 return -1;
225         max = E_PMINFO_APPINFO_PROP_APP_MAX_BOOL - E_PMINFO_APPINFO_PROP_APP_MIN_BOOL + 1;
226         for (i = 0 ; i < max; i++) {
227                 if (strcmp(property, appinfo_bool_prop_map[i].property) == 0) {
228                         prop =  appinfo_bool_prop_map[i].prop;
229                         break;
230                 }
231         }
232         return prop;
233 }
234
235 int __get_filter_condition(gpointer data, char **condition, GList **params)
236 {
237         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
238         char buf[MAX_QUERY_LEN] = {'\0'};
239         int flag = 0;
240         char *ptr = NULL;
241         char *saveptr = NULL;
242
243         switch (node->prop) {
244         case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
245                 snprintf(buf, sizeof(buf), "pi.package=?");
246                 break;
247         case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
248                 snprintf(buf, sizeof(buf), "pi.package_type=?");
249                 break;
250         case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
251                 snprintf(buf, sizeof(buf), "pi.package_version=?");
252                 break;
253         case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
254                 snprintf(buf, sizeof(buf), "pi.install_location=?");
255                 break;
256         case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
257                 snprintf(buf, sizeof(buf), "pi.installed_storage=?");
258                 break;
259         case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
260                 snprintf(buf, sizeof(buf), "pi.author_name=?");
261                 break;
262         case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
263                 snprintf(buf, sizeof(buf), "pi.author_href=?");
264                 break;
265         case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
266                 snprintf(buf, sizeof(buf), "pi.author_email=?");
267                 break;
268         case E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE:
269                 snprintf(buf, sizeof(buf), "package_privilege_info.privilege=?");
270                 flag = E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO;
271                 break;
272         case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
273                 snprintf(buf, sizeof(buf), "pi.package_size=?");
274                 break;
275         case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
276                 snprintf(buf, sizeof(buf), "pi.package_removable=? COLLATE NOCASE");
277                 break;
278         case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
279                 snprintf(buf, sizeof(buf), "pi.package_preload=? COLLATE NOCASE");
280                 break;
281         case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
282                 snprintf(buf, sizeof(buf), "pi.package_readonly=? COLLATE NOCASE");
283                 break;
284         case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
285                 snprintf(buf, sizeof(buf), "pi.package_update=? COLLATE NOCASE");
286                 break;
287         case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
288                 snprintf(buf, sizeof(buf), "pi.package_appsetting=? COLLATE NOCASE");
289                 break;
290         case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
291                 snprintf(buf, sizeof(buf), "pi.package_nodisplay=? COLLATE NOCASE");
292                 break;
293         case E_PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE:
294                 snprintf(buf, sizeof(buf), "pi.package_support_disable=? COLLATE NOCASE");
295                 break;
296         case E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE:
297                 snprintf(buf, sizeof(buf), "pi.package_disable=? COLLATE NOCASE");
298                 break;
299
300         case E_PMINFO_APPINFO_PROP_APP_ID:
301                 snprintf(buf, sizeof(buf), "ai.app_id=?");
302                 break;
303         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
304                 snprintf(buf, sizeof(buf), "ai.app_component=?");
305                 break;
306         case E_PMINFO_APPINFO_PROP_APP_EXEC:
307                 snprintf(buf, sizeof(buf), "ai.app_exec=?");
308                 break;
309         case E_PMINFO_APPINFO_PROP_APP_ICON:
310                 snprintf(buf, sizeof(buf), "package_app_localized_info.app_icon=?");
311                 flag = E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO;
312                 break;
313         case E_PMINFO_APPINFO_PROP_APP_TYPE:
314                 snprintf(buf, sizeof(buf), "ai.app_type=?");
315                 break;
316         case E_PMINFO_APPINFO_PROP_APP_OPERATION:
317                 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE ?||'|%%%%|%%%%'");
318                 flag = E_PMINFO_APPINFO_JOIN_APP_CONTROL;
319                 break;
320         case E_PMINFO_APPINFO_PROP_APP_URI:
321                 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE '%%%%|'||?||'|%%%%'");
322                 flag = E_PMINFO_APPINFO_JOIN_APP_CONTROL;
323                 break;
324         case E_PMINFO_APPINFO_PROP_APP_MIME:
325                 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE '%%%%|%%%%|'||?");
326                 flag = E_PMINFO_APPINFO_JOIN_APP_CONTROL;
327                 break;
328         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
329                 snprintf(buf, sizeof(buf), "package_app_app_category.category IN (");
330                 ptr = strtok_r(node->value, ",", &saveptr);
331                 if (ptr == NULL)
332                         return 0;
333                 strncat(buf, "?", MAX_QUERY_LEN - 2);
334                 *params = g_list_append(*params, strdup(ptr));
335                 while ((ptr = strtok_r(NULL, ",", &saveptr))) {
336                         strncat(buf, ", ?", MAX_QUERY_LEN - strlen(", ?") - 1);
337                         *params = g_list_append(*params, strdup(ptr));
338                 }
339                 strncat(buf, ")", MAX_QUERY_LEN - 2);
340                 *condition = strdup(buf);
341                 flag = E_PMINFO_APPINFO_JOIN_CATEGORY;
342
343                 return flag;
344         case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
345                 snprintf(buf, sizeof(buf), "ai.app_nodisplay=? COLLATE NOCASE");
346                 break;
347         case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
348                 snprintf(buf, sizeof(buf), "ai.app_multiple=? COLLATE NOCASE");
349                 break;
350         case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
351                 snprintf(buf, sizeof(buf), "ai.app_onboot=? COLLATE NOCASE");
352                 break;
353         case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
354                 snprintf(buf, sizeof(buf), "ai.app_autorestart=? COLLATE NOCASE");
355                 break;
356         case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
357                 snprintf(buf, sizeof(buf), "ai.app_taskmanage=? COLLATE NOCASE");
358                 break;
359         case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
360                 snprintf(buf, sizeof(buf), "ai.app_hwacceleration=?");
361                 break;
362         case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
363                 snprintf(buf, sizeof(buf), "ai.app_screenreader=?");
364                 break;
365         case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
366                 snprintf(buf, sizeof(buf), "ai.app_launchcondition=? COLLATE NOCASE");
367                 break;
368         case E_PMINFO_APPINFO_PROP_APP_PACKAGE:
369                 snprintf(buf, sizeof(buf), "ai.package=?");
370                 break;
371         case E_PMINFO_APPINFO_PROP_APP_UI_GADGET:
372                 snprintf(buf, sizeof(buf), "ai.app_ui_gadget=? COLLATE NOCASE");
373                 break;
374         case E_PMINFO_APPINFO_PROP_APP_METADATA_KEY:
375                 snprintf(buf, sizeof(buf), "package_app_app_metadata.md_key=?");
376                 flag = E_PMINFO_APPINFO_JOIN_METADATA;
377                 break;
378         case E_PMINFO_APPINFO_PROP_APP_METADATA_VALUE:
379                 snprintf(buf, sizeof(buf), "package_app_app_metadata.md_value=?");
380                 flag = E_PMINFO_APPINFO_JOIN_METADATA;
381                 break;
382         case E_PMINFO_APPINFO_PROP_APP_DISABLE:
383                 snprintf(buf, MAX_QUERY_LEN, "ai.app_disable=? COLLATE NOCASE");
384                 break;
385         case E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE:
386                 snprintf(buf, MAX_QUERY_LEN, "ai.app_support_disable=? COLLATE NOCASE");
387                 break;
388         case E_PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER:
389                 snprintf(buf, MAX_QUERY_LEN, "ai.app_id NOT IN "
390                                 "(SELECT app_id from package_app_info_for_uid WHERE uid=? " \
391                                 "AND is_disabled='true' COLLATE NOCASE)");
392                 break;
393         default:
394                 _LOGE("Invalid Property Type\n");
395                 *condition = NULL;
396                 return 0;
397         }
398         *condition = strdup(buf);
399         *params = g_list_append(*params, strdup(node->value));
400         return flag;
401 }
402
403 char *_get_system_locale(void)
404 {
405         char *lang;
406         char *locale;
407
408         lang = vconf_get_str(VCONFKEY_LANGSET);
409         if (lang == NULL) {
410                 locale = strdup(DEFAULT_LOCALE);
411                 if (locale == NULL) {
412                         LOGE("out of memory");
413                         return NULL;
414                 }
415                 return locale;
416         }
417
418         locale = malloc(sizeof(char) * 6);
419         if (locale == NULL) {
420                 LOGE("out of memory");
421                 free(lang);
422                 return NULL;
423         }
424
425         strncpy(locale, lang, 2);
426         locale[2] = '-';
427         locale[3] = tolower(lang[3]);
428         locale[4] = tolower(lang[4]);
429         locale[5] = '\0';
430
431         free(lang);
432
433         return locale;
434 }
435