fix dlog format check error
[platform/core/system/setup-adaptor.git] / src / input_file.c
1 /*
2  * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <glib.h>
17 #include <stdio.h>
18 #include <unistd.h>
19 #include <stdlib.h>
20 #include <pthread.h>
21 #include <sys/types.h>
22 #include <sys/inotify.h>
23 #include <fcntl.h>
24 #include <json.h>
25 #include <errno.h>
26 #include "sa_common.h"
27 #include "sa_types.h"
28 #include "input_file.h"
29
30 #define CONFIG_FILE "/opt/etc/setup-adaptor/config.json"
31 #define CONFIG_FOLDER "/opt/etc/setup-adaptor"
32 #define CONFIG_NAME "config.json"
33 #define EVENT_NAME_MAX 256
34 #define EVENT_SIZE      (sizeof(struct inotify_event))
35 #define EVENT_BUF_LEN   (512 * (EVENT_SIZE + EVENT_NAME_MAX))
36 /*
37 static void *__config_main_loop(void *arg)
38 {
39         int fd = 0;
40         int wd = 0;
41         int i = 0;
42         file_state_cb callback;
43         char *buffer = NULL;
44
45         _D("__config_main_loop start\n");
46
47         callback = (file_state_cb) arg;
48
49         if (callback == NULL) {
50                 _D("Ccallback is null for event");
51                 return NULL;
52         }
53
54         fd = inotify_init();
55
56         if (fd < 0) {
57                 _E("inotify_init error");
58                 return NULL;
59         }
60
61         wd = inotify_add_watch(fd, CONFIG_FOLDER, IN_MODIFY | IN_CREATE | IN_DELETE);
62
63         if (wd < 0) {
64                 _E("inotify_add_watch fail");
65                 close(fd);
66                 return NULL;
67         }
68
69         buffer = (char *) malloc(EVENT_BUF_LEN);
70
71         if (buffer != NULL) {
72                 // Start callack
73                 _D("Registerd Callback Triggered");
74                 callback(SA_FILE_STATE_REGISTERED, NULL, NULL);
75                 while (1) {
76                         int length = 0;
77                         length = read(fd, buffer, EVENT_BUF_LEN);
78
79                         if (length <= 0) {
80                                 _E("read error");
81                                 break;
82                         }
83
84                         i = 0;
85                         while (i < length && i < (EVENT_BUF_LEN-EVENT_SIZE)) {
86                                 struct inotify_event *event = (struct inotify_event *)&buffer[i];
87                                 if (event->len > 0 && event->len < EVENT_NAME_MAX) {
88                                         if (event->mask & IN_CREATE) {
89                                                 if (event->mask & IN_ISDIR) {
90                                                         _D("The directory was created");
91                                                 } else {
92                                                         if (!strcmp(event->name, CONFIG_NAME))
93                                                                 _D("config.json is created!!");
94                                                 }
95                                         } else if (event->mask & IN_DELETE) {
96                                                 if (event->mask & IN_ISDIR) {
97                                                         _D("The directory was deleted.");
98                                                 } else {
99                                                         if (!strcmp(event->name, CONFIG_NAME))
100                                                                 _D("config.json is deleted!!");
101                                                 }
102                                         } else if (event->mask & IN_MODIFY) {
103                                                 if (event->mask & IN_ISDIR) {
104                                                         _D("The directory was modified");
105                                                 } else {
106                                                         if (!strcmp(event->name, CONFIG_NAME))
107                                                                 callback(SA_FILE_STATE_CHANGED, NULL, NULL);
108                                                 }
109                                         }
110                                         i += EVENT_SIZE + event->len;
111                                 } else {
112                                         _E("event->len is wrong");
113                                         break;
114                                 }
115                         }
116                 }
117         } else {
118                 _E("buffer is NULL");
119         }
120
121         inotify_rm_watch(fd, wd);
122         close(fd);
123
124         if (buffer != NULL)
125                 free(buffer);
126
127         return NULL;
128 }
129
130 static int __init_event_listener(file_state_cb callback)
131 {
132 #if 0
133         pthread_t p_thread;
134
135         // Start thread to create in order to receive event
136         if (pthread_create(&p_thread, NULL, &__config_main_loop, callback) < 0) {
137                 _D("__init_event_listener create error");
138                 return -1;
139         }
140 #else
141         __config_main_loop(callback);
142 #endif
143
144         return 0;
145 }
146 */
147 static int json_get_int_from_obj(json_object * inputObj, char *key)
148 {
149         struct json_object *bodyObj;
150         enum json_type type;
151         int ret = 0;
152
153         type = json_object_get_type(inputObj);
154
155         if (type == json_type_object) {
156                 if (json_object_object_get_ex(inputObj, key, &bodyObj))
157                         ret = json_object_get_int(bodyObj);
158         }
159         return ret;
160 }
161
162 static int json_get_boolean_from_obj(json_object * inputObj, char *key)
163 {
164         struct json_object *bodyObj;
165         enum json_type type;
166         int ret = 0;
167
168         type = json_object_get_type(inputObj);
169
170         if (type == json_type_object) {
171                 if (json_object_object_get_ex(inputObj, key, &bodyObj))
172                         ret = json_object_get_boolean(bodyObj);
173         }
174         return ret;
175 }
176
177 static char *json_get_string_from_obj(json_object * inputObj, char *key)
178 {
179         const char *buf = NULL;
180         char *ret_buf = NULL;
181         json_object *elementObj = NULL;
182         int i = 0, j = 0;
183
184         if (json_object_object_get_ex(inputObj, key, &elementObj)) {
185                 buf = json_object_to_json_string_ext(elementObj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
186                 ret_buf = malloc(strlen(buf) - 1);
187                 if (ret_buf != NULL) {
188                         memset(ret_buf, 0x00, strlen(buf) - 1); // "<-- exclude
189                         for (i = 1, j = 0; i < strlen(buf) - 1; i++) {  // "\ <-- exclude
190                                 if (buf[i] == '\\')
191                                         continue;
192                                 ret_buf[j++] = buf[i];
193                         }
194                 } else {
195                         return NULL;
196                 }
197         } else {
198                 return NULL;
199         }
200
201         _D("string object [%s]", ret_buf);
202         return ret_buf;
203 }
204
205 static void print_config_network_static_info(sa_network_static_s * staticInfo)
206 {
207         if (staticInfo != NULL) {
208                 if (strlen(staticInfo->ipAddress) > 0)
209                         _D("static::ipAddress[%s]", staticInfo->ipAddress);
210                 if (strlen(staticInfo->netmask) > 0)
211                         _D("static::netmask[%s]", staticInfo->netmask);
212                 if (strlen(staticInfo->defaultGateway) > 0)
213                         _D("static::defaultGateway[%s]", staticInfo->defaultGateway);
214                 if (strlen(staticInfo->primaryDnsServer) > 0)
215                         _D("static::primaryDnsServer[%s]", staticInfo->primaryDnsServer);
216                 if (strlen(staticInfo->secondaryDnsServer) > 0)
217                         _D("static::secondaryDnsServer[%s]", staticInfo->secondaryDnsServer);
218         }
219 }
220
221 static void print_network_config(sa_network_s * network)
222 {
223         sa_wifi_s *wifi = NULL;
224         sa_eth_s *eth = NULL;
225
226         if (network != NULL) {
227                 wifi = network->wifi;
228                 if (wifi != NULL) {
229                         _D("Network::wifi::enabled[%d]", wifi->enabled);
230                         _D("Network::wifi::dhcpEnabled[%d]", wifi->dhcpEnabled);
231                         _D("Network::wifi::ssid[%s]", wifi->ssid);
232                         _D("Network::wifi::password[%s]", wifi->password);
233
234                         if (wifi->dhcpEnabled == 0)
235                                 print_config_network_static_info(wifi->staticInfo);
236                 }
237
238                 eth = network->eth;
239                 if (eth != NULL) {
240                         _D("Network::eth::enabled[%d]", eth->enabled);
241                         _D("Network::eth::dhcpEnabled[%d]", eth->dhcpEnabled);
242
243                         if (eth->dhcpEnabled == 0)
244                                 print_config_network_static_info(eth->staticInfo);
245                 }
246         }
247 }
248
249 static void print_system_config(sa_system_s * systemData)
250 {
251         if (systemData != NULL) {
252                 if (systemData->proxy != NULL) {
253                         _D("systemData::httpProxyHost [%s]", systemData->proxy->httpProxyHost);
254                         _D("systemData::HttpProxyPort [%d]", systemData->proxy->httpProxyPort);
255                 }
256         }
257 }
258
259 static void print_config_info(sa_config_s * config)
260 {
261         if (config != NULL) {
262                 _D("Version [%s]", config->version);
263
264                 if (config->networkData)
265                         print_network_config(config->networkData);
266
267                 if (config->systemData)
268                         print_system_config(config->systemData);
269         }
270 }
271
272 static int __parse_network_static_info(json_object * inputObj, sa_network_static_s * staticInfo)
273 {
274         char *ipAddress = NULL;
275         char *netmask = NULL;
276         char *defaultGateway = NULL;
277         char *primaryDnsServer = NULL;
278         char *secondaryDnsServer = NULL;
279
280         if (inputObj == NULL || staticInfo == NULL) {
281                 _D("__parse_network_static_info input error");
282                 return -1;
283         }
284         //ipAddress
285         ipAddress = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_IPADDRESS);
286         if (ipAddress != NULL) {
287                 _D("ipaddress = %s", ipAddress);
288
289                 memcpy(staticInfo->ipAddress, ipAddress, MIN(strlen(ipAddress), sizeof(staticInfo->ipAddress) - 1));
290                 free(ipAddress);
291                 ipAddress = NULL;
292         }
293         //netmask
294         netmask = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_NETMASK);
295         if (netmask != NULL) {
296                 memcpy(staticInfo->netmask, netmask, MIN(strlen(netmask), sizeof(staticInfo->netmask) - 1));
297                 free(netmask);
298                 netmask = NULL;
299         }
300         //defaultGateway
301         defaultGateway = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_DEFAULTGATEWAY);
302         if (defaultGateway != NULL) {
303                 memcpy(staticInfo->defaultGateway, defaultGateway, MIN(strlen(defaultGateway), sizeof(staticInfo->defaultGateway) - 1));
304                 free(defaultGateway);
305                 defaultGateway = NULL;
306         }
307         //primaryDnsServer
308         primaryDnsServer = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_PRIMARYDNSSERVER);
309         if (primaryDnsServer != NULL) {
310                 memcpy(staticInfo->primaryDnsServer, primaryDnsServer, MIN(strlen(primaryDnsServer), sizeof(staticInfo->primaryDnsServer) - 1));
311                 free(primaryDnsServer);
312                 primaryDnsServer = NULL;
313         }
314         //secondaryDnsServer
315         secondaryDnsServer = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_SECONDARYDNSSERVER);
316         if (secondaryDnsServer != NULL) {
317                 memcpy(staticInfo->secondaryDnsServer, secondaryDnsServer, MIN(strlen(secondaryDnsServer), sizeof(staticInfo->secondaryDnsServer) - 1));
318                 free(secondaryDnsServer);
319                 secondaryDnsServer = NULL;
320         }
321
322         return 0;
323 }
324
325 static int __parse_network_eth(json_object * inputObj, sa_eth_s * eth)
326 {
327         int ret = 0;
328
329         if (inputObj == NULL || eth == NULL) {
330                 _D("__parse_network_eth input error");
331                 return -1;
332         }
333         // enabled
334         eth->enabled = json_get_boolean_from_obj(inputObj, SA_CONFIG_NETWORKDATA_ENABLED);
335
336         // dhcpEnabled
337         eth->dhcpEnabled = json_get_boolean_from_obj(inputObj, SA_CONFIG_NETWORKDATA_DHCPENABLED);
338         if (eth->dhcpEnabled == FALSE) {
339                 eth->staticInfo = (sa_network_static_s *) malloc(sizeof(sa_network_static_s));
340                 if (eth->staticInfo != NULL)
341                         ret = __parse_network_static_info(inputObj, eth->staticInfo);
342                 else
343                         ret = -1;
344         }
345
346         return ret;
347 }
348
349 static int __parse_network_wifi(json_object * inputObj, sa_wifi_s * wifi)
350 {
351         char *ssid = NULL;
352         char *password = NULL;
353         int ret = 0;
354
355         if (inputObj == NULL || wifi == NULL) {
356                 _D("__parse_network_wifi input error");
357                 return -1;
358         }
359         // enabled
360         wifi->enabled = json_get_boolean_from_obj(inputObj, SA_CONFIG_NETWORKDATA_ENABLED);
361
362         // ssid
363         ssid = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_WIFI_SSID);
364         if (ssid != NULL) {
365                 memcpy(wifi->ssid, ssid, MIN(strlen(ssid), sizeof(wifi->ssid) - 1));
366                 free(ssid);
367                 ssid = NULL;
368         } else {
369                 ret = -1;
370         }
371
372         // password
373         password = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_WIFI_PASSWORD);
374         if (password != NULL) {
375                 memcpy(wifi->password, password, MIN(strlen(password), sizeof(wifi->password) - 1));
376                 free(password);
377                 password = NULL;
378         } else {
379                 ret = -1;
380         }
381
382         // dhcpEnabled
383         wifi->dhcpEnabled = json_get_boolean_from_obj(inputObj, SA_CONFIG_NETWORKDATA_DHCPENABLED);
384         if (wifi->dhcpEnabled == FALSE) {
385                 wifi->staticInfo = (sa_network_static_s *) malloc(sizeof(sa_network_static_s));
386                 if (wifi->staticInfo != NULL)
387                         ret = __parse_network_static_info(inputObj, wifi->staticInfo);
388                 else
389                         ret = -1;
390         }
391
392         return ret;
393 }
394
395 static int __parse_network_data(json_object * inputObj, sa_config_s * setupConfig)
396 {
397         struct json_object *wifiObj = NULL;
398         struct json_object *ethernetObj = NULL;
399         int wifiRet = 0, ethRet = 0;
400
401         if (inputObj == NULL) {
402                 _D("__parse_network_data input error");
403                 return -1;
404         }
405
406         setupConfig->networkData = (sa_network_s *) malloc(sizeof(sa_network_s));
407         if (setupConfig->networkData != NULL) {
408                 //parse wifi
409                 if (json_object_object_get_ex(inputObj, SA_CONFIG_NETWORKDATA_WIFI, &wifiObj)) {
410                         if (json_object_get_type(wifiObj) == json_type_object) {
411                                 // malloc
412                                 setupConfig->networkData->wifi = (sa_wifi_s *) malloc(sizeof(sa_wifi_s));
413                                 if (setupConfig->networkData->wifi != NULL)
414                                         wifiRet = __parse_network_wifi(wifiObj, setupConfig->networkData->wifi);
415                                 else
416                                         _D("network->wifi malloc fail");
417                         }
418                 }
419                 //parse eth
420                 if (json_object_object_get_ex(inputObj, SA_CONFIG_NETWORKDATA_ETHERNET, &ethernetObj)) {
421                         if (json_object_get_type(ethernetObj) == json_type_object) {
422                                 // malloc
423                                 setupConfig->networkData->eth = (sa_eth_s *) malloc(sizeof(sa_eth_s));
424                                 if (setupConfig->networkData->eth != NULL)
425                                         ethRet = __parse_network_eth(ethernetObj, setupConfig->networkData->eth);
426                                 else
427                                         _D("network->eth malloc fail");
428                         }
429                 }
430         } else {
431                 _D("malloc fail etupConfig->networkData");
432         }
433
434         // if both of network interfaces are failed, it would return -1
435         if (wifiRet != 0 && ethRet != 0) {
436                 _D("__parse_network_data fail");
437                 return -1;
438         }
439
440         return 0;
441 }
442
443 static int __parse_system_data(json_object * inputObj, sa_config_s * setupConfig)
444 {
445         int ret = 0;
446         char *httpProxyHost = NULL;
447         if (inputObj == NULL) {
448                 _D("__parse_system_data input error");
449                 return -1;
450         }
451         //httpProxyHost
452         httpProxyHost = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_HTTPPROXYHOST);
453         if (httpProxyHost != NULL) {
454                 setupConfig->systemData = (sa_system_s *) malloc(sizeof(sa_system_s));
455                 if (setupConfig->systemData != NULL) {
456                         setupConfig->systemData->proxy = (sa_proxy_s *) malloc(sizeof(sa_proxy_s));
457                         if (setupConfig->systemData->proxy != NULL) {
458                                 memcpy(setupConfig->systemData->proxy->httpProxyHost, httpProxyHost, MIN(strlen(httpProxyHost), sizeof(setupConfig->systemData->proxy->httpProxyHost) - 1));
459                                 //httpProxyPort
460                                 setupConfig->systemData->proxy->httpProxyPort = json_get_int_from_obj(inputObj, SA_CONFIG_NETWORKDATA_HTTPPROXYPORT);
461
462                         } else {
463                                 ret = -1;
464                                 _D("malloc fail setupConfig->systemData->proxy");
465                         }
466                 } else {
467                         ret = -1;
468                         _D("malloc fail setupConfig->systemData");
469                 }
470
471                 free(httpProxyHost);
472                 httpProxyHost = NULL;
473         }
474
475         return ret;
476 }
477
478 static int __parse_version(json_object * inputObj, sa_config_s * setupConfig)
479 {
480         char *version = NULL;
481
482         if (inputObj == NULL) {
483                 _D("__parse_version input error");
484                 return -1;
485         }
486
487         version = json_get_string_from_obj(inputObj, SA_CONFIG_VERSION);
488
489         if (version != NULL) {
490                 memcpy(setupConfig->version, version, MIN(strlen(version), sizeof(setupConfig->version) - 1));
491                 free(version);
492                 version = NULL;
493         }
494
495         return 0;
496 }
497
498 static int __parse_config(char *file, sa_config_s * setupConfig)
499 {
500         struct json_object *configObj = NULL;
501         char *jsonData = NULL;
502         int readLen = 0;
503         int fd = 0;
504         int len = 0;
505         int ret = 0;
506
507         fd = open(file, O_RDONLY);
508         if (fd < 0) {
509                 _E("config file can't be opened");
510                 return -1;
511         }
512
513         len = lseek(fd, 0L, SEEK_END);
514
515         if (len > 0) {
516                 lseek(fd, 0L, SEEK_SET);
517                 jsonData = (char *)malloc(len + 1);
518                 if (jsonData != NULL) {
519                         memset(jsonData, 0x00, len + 1);
520                         readLen = read(fd, jsonData, len);
521                         _D("JSON full data[%s]", jsonData);
522
523                         configObj = json_tokener_parse(jsonData);
524
525                         if (configObj != NULL && readLen > 0) {
526                                 // parse version
527                                 ret = __parse_version(configObj, setupConfig);
528                                 if (ret == 0)
529                                         ret = __parse_system_data(configObj, setupConfig);
530
531                                 if (ret == 0)
532                                         ret = __parse_network_data(configObj, setupConfig);
533
534                         } else {
535                                 ret = -1;
536                                 _D("ConfigObj is not existed");
537                         }
538
539                         json_object_put(configObj);
540                         free(jsonData);
541                 } else {
542                         ret = -1;
543                         _D("memory allocation fail for jsonData");
544                 }
545         }
546
547         close(fd);
548
549         return ret;
550 }
551
552 sa_error_e sa_inputfile_get_config_info(sa_config_s * config)
553 {
554         sa_error_e ret = SA_ERROR_NONE;
555         // check file
556         if (access(CONFIG_FILE, 0) != 0)
557                 return SA_ERROR_NOT_SUPPORTED;
558
559         // parsing and fill into struct
560         ret = __parse_config(CONFIG_FILE, config);
561         if (ret != 0) {
562                 _D("Config parsing error");
563                 return SA_ERROR_PARSING;
564         }
565
566         print_config_info(config);
567
568         return ret;
569 }
570
571 sa_file_state_e sa_inputfile_get_config_state(void)
572 {
573         sa_file_state_e ret = SA_FILE_STATE_NOT_EXISTED;
574
575         if (access(CONFIG_FILE, F_OK) != -1)
576                 ret = SA_FILE_STATE_EXIST;
577         else
578                 ret = SA_FILE_STATE_NOT_EXISTED;
579
580         return ret;
581 }
582
583 static void release_system_resource(sa_system_s * system)
584 {
585         if (system != NULL) {
586                 if (system->proxy != NULL)
587                         free(system->proxy);
588
589                 free(system);
590         }
591 }
592
593 static void release_network_resource(sa_network_s * network)
594 {
595         if (network != NULL) {
596                 if (network->wifi != NULL) {
597                         if (network->wifi->staticInfo != NULL)
598                                 free(network->wifi->staticInfo);
599
600                         free(network->wifi);
601                 }
602
603                 if (network->eth != NULL) {
604                         if (network->eth->staticInfo != NULL)
605                                 free(network->eth->staticInfo);
606
607                         free(network->eth);
608                 }
609
610                 free(network);
611         }
612 }
613
614 gboolean sa_inputfile_thread(GSource * source, GSourceFunc callbackFuntion, gpointer user_data)
615 {
616         _D("GSourceFuncs>>>Execution !!!");
617
618 #if 0
619         sa_error_e ret = SA_ERROR_NONE;
620
621         if (__init_event_listener(callback))
622                 ret = SA_ERROR_UNKNOWN;
623 #else
624         callbackFuntion(NULL);
625 #endif
626
627         if (user_data)
628                 g_main_loop_quit((GMainLoop *) user_data);
629
630         // if return value is "FALSE", function stop
631         // if return value is "TRUE", function restart
632         return FALSE;
633 }
634
635 void sa_inputfile_release_resource(sa_config_s * config)
636 {
637
638         if (config != NULL) {
639                 if (config->networkData != NULL)
640                         release_network_resource(config->networkData);
641
642                 if (config->systemData != NULL)
643                         release_system_resource(config->systemData);
644         }
645 }
646
647 #define FLAG_FILE_SYSTEM "/opt/etc/setup-adaptor/system_executed"
648 #define FLAG_FILE_ETH "/opt/etc/setup-adaptor/ethernet_executed"
649 #define FLAG_FILE_WIFI "/opt/etc/setup-adaptor/wifi_executed"
650
651 void sa_inputfile_remove(void)
652 {
653         char buff[256];
654
655         if (remove(CONFIG_FILE) != 0) {
656                 if (strerror_r(errno, buff, sizeof(buff)) == 0)
657                         _E("Can't remove file{%s}! %s", CONFIG_FILE, buff);
658         } else
659                 _D("file removed successfully..{%s}", CONFIG_FILE);
660 }
661
662 void sa_inputfile_clear_completion_flag(void)
663 {
664         if (remove(FLAG_FILE_SYSTEM) == 0)
665                 _D("file removed successfully..{%s}", FLAG_FILE_SYSTEM);
666
667         if (remove(FLAG_FILE_ETH) == 0)
668                 _D("file removed successfully..{%s}", FLAG_FILE_ETH);
669
670         if (remove(FLAG_FILE_WIFI) == 0)
671                 _D("file removed successfully..{%s}", FLAG_FILE_WIFI);
672
673 }
674
675 void sa_inputfile_set_completion_flag(sa_file_config_e config_type)
676 {
677         int fd = 0;
678         char buff[256];
679
680         switch (config_type) {
681         case SA_FILE_CONFIG_SYSTEM:
682                 fd = creat(FLAG_FILE_SYSTEM, 0644);
683                 break;
684         case SA_FILE_CONFIG_ETHERNET:
685                 fd = creat(FLAG_FILE_ETH, 0644);
686                 break;
687         case SA_FILE_CONFIG_WIFI:
688                 fd = creat(FLAG_FILE_WIFI, 0644);
689                 break;
690         default:
691                 _E("unknown parameter (%d)", config_type);
692                 break;
693         }
694
695         if (fd == -1) {
696                 if (strerror_r(errno, buff, sizeof(buff)) == 0)
697                         _E("Can't create file for {%d}! %s", config_type, buff);
698         } else
699                 close(fd);
700 }
701
702 // return TRUE if set
703 gboolean sa_inputfile_get_completion_flag(sa_file_config_e config_type)
704 {
705         int ret = 0;
706
707         switch (config_type) {
708         case SA_FILE_CONFIG_SYSTEM:
709                 ret = access(FLAG_FILE_SYSTEM, 0);
710                 break;
711         case SA_FILE_CONFIG_ETHERNET:
712                 ret = access(FLAG_FILE_ETH, 0);
713                 break;
714         case SA_FILE_CONFIG_WIFI:
715                 ret = access(FLAG_FILE_WIFI, 0);
716                 break;
717         case SA_FILE_CONFIG_ALL:
718                 ret = access(FLAG_FILE_SYSTEM, 0);
719                 if (ret == 0)
720                         ret = access(FLAG_FILE_ETH, 0);
721
722                 if (ret == 0)
723                         ret = access(FLAG_FILE_WIFI, 0);
724
725                 break;
726         default:
727                 _E("unknown parameter (%d)", config_type);
728                 break;
729         }
730         if (ret == 0)
731                 return TRUE;
732         else
733                 return FALSE;
734 }