NetworkManager/src/backends/interface_parser.c
Ray Strode 278e500f99 2005-03-14 Ray Strode <rstrode@redhat.com>
Fourth (probably working) cut at porting to
	dbus 0.30 api and new hal. This cut adds
	some new logging macros to make debugging
	easier.

	* dispatcher-daemon/NetworkManagerDispatcher.c:
	* info-daemon/NetworkmanagerInfo.c:
	* info-daemon/NetworkManagerInfoPassphraseDialog.c:
	* info-daemon/NetworkManagerInfoVPN.c:
	* src/NetworkManager.c:
	* src/NetworkManagerAP.c:
	* src/NetworkManagerAPList.c:
	* src/NetworkManagerDHCP.c:
	* src/NetworkManagerDbus.c:
	* src/NetworkManagerDevice.c:
	* src/NetworkManagerPolicy.c:
	* src/NetworkManagerSystem.c:
	* src/NetworkManagerUtils.c:
	* src/NetworkManagerWireless.c:
	* src/autoip.c:
	* src/nm-dbus-nm.c:
	* src/backends/NetworkManagerDebian.c:
	* src/backends/NetworkManagerGentoo.c:
	* src/backends/NetworkManagerRedHat.c:
	* src/backends/NetworkManagerSlackware.c:
	use new logging macros.

	* dispatcher-daemon/NetworkManagerDispatcher.c:
	(nmd_dbus_filter): s/dbus_free/g_free/

	* info-daemon/Makefile.am: link in utils library.
	* info-daemon/NetworkmanagerInfo.c: use new logging
	macros.
	(nmi_dbus_get_network): don't assume enumerations
	are 32-bit.
	(nmi_dbus_nmi_message_handler): don't free what
	doesn't belong to us.

	* libnm_glib/libnm_glib.c:
	(libnm_glib_get_nm_status):
	(libnm_glib_init): don't free what doesn't
	belong to us.
	(libnm_glib_dbus): strdup result, so it doesn't get
	lost when message is unref'd.

	* panel-applet/NMWirelessAppletDbus.c:
	(nmwa_dbus_update_devices): s/dbus_free/g_free/

	* src/NetworkManager.c:
	(nm_monitor_wired_link_state): request initial status
	dump of all cards when we start up, instead of relying
	on /sys/.../carrier.
	(nm_info_handler), (nm_set_up_log_handlers):
	log handlers to specify what syslog priorites
	the logging macros default to.

	* src/NetworkManagerAPList.c:
	(nm_ap_list_populate_from_nmi):
	s/dbus_free_string_array/g_strfreev/

	* src/NetworkManagerDbus.c:
	(nm_dbus_get_network_object):
	validate d-bus message argument types.
	Advance message iterator after reading argument,
	prepend instead of append to GSList.

	* src/NetworkManagerDevice.c:
	(nm_device_probe_wired_link_status):
	remove redundant /sys in /sys path. remove wrong
	contents == NULL means has carrier assumption.

	* src/nm-netlink-monitor.c
	(nm_netlink_monitor_request_status): implement
	function to ask kernel to dump interface link
	status over netlink socket.

	* test/*.c: s/dbus_free/g_free/

	* utils/nm-utils.h:
	(nm_print_backtrace): new macro to print backtrace.
	(nm_get_timestamp): new macro to get sub-second precise
	unix timestamp.
	(nm_info), (nm_debug), (nm_warning), (nm_error):
	new logging functions. nm_info just prints,
	nm_debug includes timestamp and function,
	nm_warning includes function, nm_error includes
	backtrace and sigtrap.


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@497 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2005-03-15 05:30:15 +00:00

186 lines
3.8 KiB
C

/* NetworkManager -- Network link manager
*
* Tom Parker <palfrey@tevp.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* (C) Copyright 2004 Tom Parker
*/
#include "interface_parser.h"
#include "NetworkManagerUtils.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
if_block* first;
if_block* last;
if_data* last_data;
void add_block(const char *type, const char* name)
{
if_block *ret = (if_block*)calloc(1,sizeof(struct _if_block));
ret->name = g_strdup(name);
ret->type = g_strdup(type);
if (first == NULL)
first = last = ret;
else
{
last->next = ret;
last = ret;
}
last_data = NULL;
//printf("added block '%s' with type '%s'\n",name,type);
}
void add_data(const char *key,const char *data)
{
if_data *ret = (if_data*)calloc(1,sizeof(struct _if_data));
ret->key = g_strdup(key);
ret->data = g_strdup(data);
if (last->info == NULL)
{
last->info = ret;
last_data = ret;
}
else
{
last_data->next = ret;
last_data = last_data->next;
}
//printf("added data '%s' with key '%s'\n",data,key);
}
#define SPACE_OR_TAB(string,ret) {ret = strchr(string,' ');ret=(ret == NULL?strchr(string,'\t'):ret);}
void ifparser_init()
{
FILE *inp = fopen(INTERFACES,"r");
int ret = 0;
if (inp == NULL)
{
nm_warning ("Error: Can't open %s\n",INTERFACES);
return;
}
first = last = NULL;
while(1)
{
char *line,rline[255],*space;
ret = fscanf(inp,"%255[^\n]\n",rline);
if (ret == EOF)
break;
line = rline;
while(line[0] == ' ')
line++;
if (line[0]=='#' || line[0]=='\0')
continue;
SPACE_OR_TAB(line,space)
if (space == NULL)
{
nm_warning ("Error: Can't parse interface line '%s'\n",line);
continue;
}
space[0] = '\0';
if (strcmp(line,"iface")==0)
{
char *space2 = strchr(space+1,' ');
if (space2 == NULL)
{
nm_warning ("Error: Can't parse iface line '%s'\n",space+1);
continue;
}
space2[0]='\0';
add_block(line,space+1);
if (space2[1]!='\0')
{
space = strchr(space2+1,' ');
if (space == NULL)
{
nm_warning ("Error: Can't parse data '%s'\n",space2+1);
continue;
}
space[0] = '\0';
add_data(space2+1,space+1);
}
}
else if (strcmp(line,"auto")==0)
add_block(line,space+1);
else
add_data(line,space+1);
//printf("line: '%s' ret=%d\n",rline,ret);
}
fclose(inp);
}
void _destroy_data(if_data *ifd)
{
if (ifd == NULL)
return;
_destroy_data(ifd->next);
free(ifd->key);
free(ifd->data);
free(ifd);
return;
}
void _destroy_block(if_block* ifb)
{
if (ifb == NULL)
return;
_destroy_block(ifb->next);
_destroy_data(ifb->info);
free(ifb->name);
free(ifb->type);
free(ifb);
return;
}
void ifparser_destroy()
{
_destroy_block(first);
first = last = NULL;
}
if_block *ifparser_getif(const char* iface)
{
if_block *curr = first;
while(curr!=NULL)
{
if (strcmp(curr->type,"iface")==0 && strcmp(curr->name,iface)==0)
return curr;
curr = curr->next;
}
return NULL;
}
const char *ifparser_getkey(if_block* iface, const char *key)
{
if_data *curr = iface->info;
while(curr!=NULL)
{
if (strcmp(curr->key,key)==0)
return curr->data;
curr = curr->next;
}
return NULL;
}