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