-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.c
67 lines (58 loc) · 1.42 KB
/
config.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "y.tab.h"
extern struct config_interfaces *cur_if;
extern struct config_ssid *cur_ssid;
FILE *yyin;
int yyparse();
const char config_file[] = "/etc/wlan-daemon.conf";
void
clear_ssid(struct config_ssid * ssid) {
if (!ssid)
return;
clear_ssid(ssid->next);
free(ssid);
}
void
clear_config(struct config_interfaces * conf) {
if (!conf)
return;
clear_ssid(conf->ssids);
clear_config(conf->next);
free(conf);
}
int
parse_config() {
FILE *fp = fopen(config_file, "r");
if (!fp)
return 1;
config = 0;
cur_if = 0;
cur_ssid = 0;
yyin = fp;
yyparse();
fclose(fp);
struct config_interfaces *cur = config;
while (cur) {
printf("config: %s (", cur->if_name);
struct config_ssid *c2 = cur->ssids;
while (c2) {
printf(" %s", c2->ssid_name);
c2 = c2->next;
}
printf(" )\n");
cur = cur->next;
}
return 0;
}
struct config_interfaces *
find_config(char *interface) {
struct config_interfaces *cur = config;
while (cur) {
if (strcmp(cur->if_name, interface) == 0)
return cur;
cur = cur->next;
}
return 0;
}