⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 config.c

📁 AirFart监听 802.11流量
💻 C
字号:
/*   This file is part of AirFart.   AirFart 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.   AirFart 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 AirFart; if not, write to the Free Software   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/#include <stdio.h>#include <string.h>#include <ctype.h>#include <stdlib.h>#include "airfart.h"#include "config.h"#define MAX_VALUES 10struct parse {	char option[256];	char value[MAX_VALUES][4096];};struct general_settings_template global_general_settings; static struct parse *parse_line(char *line, struct parse *p){	char *c = line;	int inopt = 1, inval = 0, curval = -1;	int optlen = 0, vallen = 0, last_non_space = 0;	int x;	for (x = 0; x < MAX_VALUES; x++) {		p->value[x][0] = 0;	}	while (*c) {		if (*c == '\t') {			c++;			continue;		}				if (inopt) {			if ((*c < 'a' || *c > 'z') && *c != '_' && (*c < 'A' || *c > 'Z')) {				inopt = 0;				p->option[optlen] = 0;				c++;				continue;			}			p->option[optlen] = *c;			optlen++;			c++;			continue;		} else if (inval) {			if (*c == '\\') {				/* if we have a \ take the char after it literally.. */				c++;				p->value[curval][vallen] = *c;				vallen++;				last_non_space = vallen;				c++;				continue;			} else if (*c == '}') {				/* } that isn't escaped should end this chunk of data, and				 * should have a space before it.. */				p->value[curval][last_non_space] = 0;				inval = 0;				c++;				continue;			} else {				p->value[curval][vallen] = *c;				vallen++;				if (! isspace(*c))					last_non_space = vallen;				c++;				continue;			}		} else if (*c == '{') {			/* i really don't think this if ever succeeds, but i'm			 * not brave enough to take it out... */ 			if (*(c - 1) == '\\') {				p->value[curval][vallen] = *c;				c++;				continue;			} else {				/* { that isn't escaped should signify the start of a				 * piece of data and should have a space after it.. */				curval++;				vallen = 0;				last_non_space = vallen;				inval = 1;				c++;				while (*c && isspace(*c))				  c++;				continue;			}		}		c++;	}	return p;}static int rc_parse_tag(FILE *f){	char buf[2048];	char tag[256];	buf[0] = '#';	while (buf[0] == '#' && !feof(f))		fgets(buf, sizeof(buf), f);	if (feof(f))		return -1;	sscanf(buf, "%s {", tag);	if (!strcmp(tag, "general")) {		return 0;	}/* else if (!strcmp(tag, "options")) {		return 1;	} else if (!strcmp(tag, "away")) {		return 2;	} else if (!strcmp(tag, "plugins")) {		return 3;	} else if (!strcmp(tag, "pounce")) {		return 4;	} else if (!strcmp(tag, "sound_files")) {		return 6;	} else if (!strcmp(tag, "proxy")) {		return 7;	} else if (!strcmp(tag, "wgaim")) {		return 8;	}*/	return -1;}const gchar *get_home_dir(){	if(g_get_home_dir())		return g_get_home_dir();	else		return NULL;}void set_defaults(){	g_snprintf(global_general_settings.device, sizeof(global_general_settings.device), "wlan0");}void load_prefs(){	FILE *f;	char buf[1024];	int ver = 0;/*	if (is_saving_prefs) {		request_load_prefs = 1;		debug_printf("currently saving, will request load\n");		return;	}*/	if (get_home_dir())		g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S ".airfartrc", get_home_dir());	/*else {		set_defaults();		return;	}*/	if ((f = fopen(buf, "r"))) {	/*	is_loading_prefs = 1;*//*		fgets(buf, sizeof(buf), f);		sscanf(buf, "# .gaimrc v%d", &ver);		if ((ver <= 3) || (buf[0] != '#'))			set_defaults();*/		while (!feof(f)) {			int tag = rc_parse_tag(f);			switch (tag) {			case -1:				/* Let the loop end, EOF */				break;			case 0:				read_general_settings(f);				break;/*			case 1:				gaimrc_read_options(f);				break;			case 2:				gaimrc_read_away(f);				break;			case 3:				gaimrc_read_plugins(f);				break;			case 4:				gaimrc_read_pounce(f);				break;			case 6:				gaimrc_read_sounds(f);				break;			case 7:				gaimrc_read_proxy(f);				break;*/			default:				/* NOOP */				break;			}		}		fclose(f);		/*is_loading_prefs = 0;*//*		if (request_save_prefs) {			debug_printf("saving prefs on request\n");			save_prefs();			request_save_prefs = 0;		}*/	} else {		set_defaults();		save_prefs();	}}void save_prefs(){	FILE *f;	char buf[BUF_LONG];	/*	if (is_loading_prefs) {		request_save_prefs = 1;		debug_printf("currently loading, will request save\n");		return;	}	*/	if (get_home_dir()) {		g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S ".airfartrc", get_home_dir());	}	else {		return;	}	if ((f = fopen(buf, "w"))) {	/*	is_saving_prefs = 1;*/		write_general_settings(f);		/*gaimrc_write_options(f);		gaimrc_write_sounds(f);		gaimrc_write_away(f);		gaimrc_write_pounce(f);		gaimrc_write_plugins(f);		gaimrc_write_proxy(f);		*/		fclose(f);		/* chmod(buf, S_IRUSR | S_IWUSR);*/		/*is_saving_prefs = 0;*/	}	else	  printf("Error opening .airfartrc\n");	/*if (request_load_prefs) {		debug_printf("loading prefs on request\n");		load_prefs();		request_load_prefs = 0;	}*/}static void read_general_settings(FILE *f){	char buf[2048];	struct parse parse_buffer;	struct parse *p;	buf[0] = 0;	while (buf[0] != '}') {		if (buf[0] == '#')			continue;		if (!fgets(buf, sizeof(buf), f))			return;		p = parse_line(buf, &parse_buffer);		if (!strcmp(p->option, "device")) {			g_snprintf(global_general_settings.device,					sizeof(global_general_settings.device), "%s", p->value[0]);		} /* else if (!strcmp(p->option, "port")) {			global_proxy_info.proxyport = atoi(p->value[0]);		} else if (!strcmp(p->option, "type")) {			global_proxy_info.proxytype = atoi(p->value[0]);		} else if (!strcmp(p->option, "user")) {			g_snprintf(global_proxy_info.proxyuser,					sizeof(global_proxy_info.proxyuser), "%s", p->value[0]);		} else if (!strcmp(p->option, "pass")) {			g_snprintf(global_proxy_info.proxypass,					sizeof(global_proxy_info.proxypass), "%s", p->value[0]);		}*/	}	if (!global_general_settings.device)	{		g_snprintf(global_general_settings.device, sizeof(global_general_settings.device), "%s", "wlan0");	}}static void write_general_settings(FILE *f){		fprintf(f, "general {\n");		fprintf(f, "\tdevice { %s }\n", global_general_settings.device);		/*fprintf(f, "\tport { %d }\n", global_proxy_info.proxyport);		fprintf(f, "\ttype { %d }\n", global_proxy_info.proxytype);		fprintf(f, "\tuser { %s }\n", global_proxy_info.proxyuser);		fprintf(f, "\tpass { %s }\n",				(str = escape_text2(global_proxy_info.proxypass))); */		fprintf(f, "}\n");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -