1
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
2
/* NetworkManager -- Network link manager
4
* Tom Parker <palfrey@tevp.net>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
* (C) Copyright 2004 Tom Parker
24
#include "interface_parser.h"
25
#include "NetworkManagerUtils.h"
36
void add_block(const char *type, const char* name)
38
if_block *ret = (if_block*)calloc(1,sizeof(struct _if_block));
39
ret->name = g_strdup(name);
40
ret->type = g_strdup(type);
49
//printf("added block '%s' with type '%s'\n",name,type);
52
void add_data(const char *key,const char *data)
56
// Check if there is a block where we can attach our data
60
ret = (if_data*) calloc(1,sizeof(struct _if_data));
61
ret->key = g_strdup(key);
62
ret->data = g_strdup(data);
64
if (last->info == NULL)
71
last_data->next = ret;
72
last_data = last_data->next;
74
//printf("added data '%s' with key '%s'\n",data,key);
77
#define SPACE_OR_TAB(string,ret) {ret = strchr(string,' ');ret=(ret == NULL?strchr(string,'\t'):ret);}
79
void ifparser_init(void)
81
FILE *inp = fopen(ENI_INTERFACES_FILE, "r");
89
nm_warning ("Error: Can't open %s\n", ENI_INTERFACES_FILE);
96
ret = fscanf(inp,"%255[^\n]\n",rline);
99
// If the line did not match, skip it
101
fgets(rline, 255, inp);
106
while(line[0] == ' ')
108
if (line[0]=='#' || line[0]=='\0')
111
SPACE_OR_TAB(line,space)
114
nm_warning ("Error: Can't parse interface line '%s'\n",line);
119
// There are four different stanzas:
120
// iface, mapping, auto and allow-*. Create a block for each of them.
121
if (strcmp(line,"iface")==0)
123
char *space2 = strchr(space+1,' ');
126
nm_warning ("Error: Can't parse iface line '%s'\n",space+1);
130
add_block(line,space+1);
134
space = strchr(space2+1,' ');
137
nm_warning ("Error: Can't parse data '%s'\n",space2+1);
141
add_data(space2+1,space+1);
144
else if (strcmp(line,"auto")==0)
145
add_block(line,space+1);
146
else if (strcmp(line,"mapping")==0)
147
add_block(line,space+1);
148
else if (strncmp(line,"allow-",6)==0)
149
add_block(line,space+1);
151
add_data(line,space+1);
153
//printf("line: '%s' ret=%d\n",rline,ret);
158
void _destroy_data(if_data *ifd)
162
_destroy_data(ifd->next);
169
void _destroy_block(if_block* ifb)
173
_destroy_block(ifb->next);
174
_destroy_data(ifb->info);
181
void ifparser_destroy(void)
183
_destroy_block(first);
187
if_block *ifparser_getfirst(void)
192
if_block *ifparser_getif(const char* iface)
194
if_block *curr = first;
197
if (strcmp(curr->type,"iface")==0 && strcmp(curr->name,iface)==0)
204
const char *ifparser_getkey(if_block* iface, const char *key)
206
if_data *curr = iface->info;
209
if (strcmp(curr->key,key)==0)