1 Star 0 Fork 0

孤独剑3723/openCAPWAP-OpenWRT

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
WTPSettingsFile.c 6.73 KB
一键复制 编辑 原始数据 按行查看 历史
/*******************************************************************************************
* Copyright (c) 2006-7 Laboratorio di Sistemi di Elaborazione e Bioingegneria Informatica *
* Universita' Campus BioMedico - Italy *
* *
* 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. *
* *
* --------------------------------------------------------------------------------------- *
* Project: Capwap *
* *
* Author : Ludovico Rossi (ludo@bluepixysw.com) *
* Del Moro Andrea (andrea_delmoro@libero.it) *
* Giovannini Federica (giovannini.federica@gmail.com) *
* Massimo Vellucci (m.vellucci@unicampus.it) *
* Mauro Bisson (mauro.bis@gmail.com) *
*******************************************************************************************/
#include "CWCommon.h"
#ifdef DMALLOC
#include "../dmalloc-5.5.0/dmalloc.h"
#endif
#define CW_SETTINGS_FILE "settings.wtp.txt"
FILE *gSettingsFile = NULL;
char *gInterfaceName = NULL;
char *gEthInterfaceName = NULL;
char *gRadioInterfaceName_0 = NULL;
char *gBaseMACInterfaceName = NULL;
char gBoardReversionNo;
int gHostapd_port;
char *gHostapd_unix_path;
void CWExtractValue(char *start, char **startValue, char **endValue, int *offset)
{
*offset = strspn(start + 1, " \t\n\r");
*startValue = start + 1 + *offset;
*offset = strcspn(*startValue, " \t\n\r");
*endValue = *startValue + *offset - 1;
}
CWBool CWParseSettingsFile()
{
char *line = NULL;
gSettingsFile = fopen(CW_SETTINGS_FILE, "rb");
if (gSettingsFile == NULL) {
CWErrorRaiseSystemError(CW_ERROR_GENERAL);
}
while ((line = (char *)CWGetCommand(gSettingsFile)) != NULL) {
char *startTag = NULL;
char *endTag = NULL;
if ((startTag = strchr(line, '<')) == NULL) {
CW_FREE_OBJECT(line);
continue;
}
if ((endTag = strchr(line, '>')) == NULL) {
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag + 1, "IF_NAME", endTag - startTag - 1)) {
char *startValue = NULL;
char *endValue = NULL;
int offset = 0;
CWExtractValue(endTag, &startValue, &endValue, &offset);
CW_CREATE_STRING_ERR(gInterfaceName, offset, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
);
strncpy(gInterfaceName, startValue, offset);
gInterfaceName[offset] = '\0';
CWLog(": %s", gInterfaceName);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag + 1, "WTP_ETH_IF_NAME", endTag - startTag - 1)) {
char *startValue = NULL;
char *endValue = NULL;
int offset = 0;
CWExtractValue(endTag, &startValue, &endValue, &offset);
CW_CREATE_STRING_ERR(gEthInterfaceName, offset,
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
);
strncpy(gEthInterfaceName, startValue, offset);
gEthInterfaceName[offset] = '\0';
CWLog(": %s", gEthInterfaceName);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag + 1, "RADIO_0_IF_NAME", endTag - startTag - 1)) {
char *startValue = NULL;
char *endValue = NULL;
int offset = 0;
CWExtractValue(endTag, &startValue, &endValue, &offset);
CW_CREATE_STRING_ERR(gRadioInterfaceName_0, offset,
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
);
strncpy(gRadioInterfaceName_0, startValue, offset);
gRadioInterfaceName_0[offset] = '\0';
CWLog(": %s", gRadioInterfaceName_0);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag + 1, "BASE_MAC_IF_NAME", endTag - startTag - 1)) {
char *startValue = NULL;
char *endValue = NULL;
int offset = 0;
CWExtractValue(endTag, &startValue, &endValue, &offset);
CW_CREATE_STRING_ERR(gBaseMACInterfaceName, offset,
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
);
strncpy(gBaseMACInterfaceName, startValue, offset);
gBaseMACInterfaceName[offset] = '\0';
CWLog(": %s", gBaseMACInterfaceName);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag + 1, "BOARD_REVISION_NO", endTag - startTag - 1)) {
char *startValue = NULL;
char *endValue = NULL;
int offset = 0;
char reversion[16];
CWExtractValue(endTag, &startValue, &endValue, &offset);
strncpy(reversion, startValue, offset);
reversion[offset] = '\0';
gBoardReversionNo = atoi(reversion);
CWLog(": %d", gBoardReversionNo);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag + 1, "WTP_HOSTAPD_PORT", endTag - startTag - 1)) {
char *startValue = NULL;
char *endValue = NULL;
int offset = 0;
char port_str[16];
CWExtractValue(endTag, &startValue, &endValue, &offset);
strncpy(port_str, startValue, offset);
port_str[offset] = '\0';
gHostapd_port = atoi(port_str);
CWLog(": %d", gHostapd_port);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag + 1, "WTP_HOSTAPD_UNIX_PATH", endTag - startTag - 1)) {
char *startValue = NULL;
char *endValue = NULL;
int offset = 0;
CWExtractValue(endTag, &startValue, &endValue, &offset);
CW_CREATE_STRING_ERR(gHostapd_unix_path, offset,
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
);
strncpy(gHostapd_unix_path, startValue, offset);
gHostapd_unix_path[offset] = '\0';
CWLog(": %s", gHostapd_unix_path);
CW_FREE_OBJECT(line);
continue;
}
CW_FREE_OBJECT(line);
}
return CW_TRUE;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tyy123456/openCAPWAP-OpenWRT.git
git@gitee.com:tyy123456/openCAPWAP-OpenWRT.git
tyy123456
openCAPWAP-OpenWRT
openCAPWAP-OpenWRT
master

搜索帮助