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

📄 xsupconfig_parse_globals.c

📁 linux 下通过802.1认证的安装包
💻 C
📖 第 1 页 / 共 2 页
字号:
/**
 * Licensed under a dual GPL/BSD license.  (See LICENSE file for more info.)
 *
 * \file xsupconfig_parse_globals.c
 *
 * \author chris@open1x.org
 *
 * $Id: xsupconfig_parse_globals.c,v 1.1.2.37 2008/01/21 22:51:44 chessing Exp $
 * $Date: 2008/01/21 22:51:44 $
 **/

#include <stdio.h>

#ifndef WINDOWS
#include <stdint.h>
#endif

#include <libxml/parser.h>
#include <libxml/tree.h>
#include <string.h>

#include "xsupconfig_structs.h"
#include "../../src/xsup_common.h"
#include "xsupconfig_parse.h"
#include "xsupconfig.h"
#include "xsupconfig_vars.h"
#include "xsupconfig_common.h"
#include "xsupconfig_defaults.h"
#include "../../src/xsup_debug.h"

multichoice association_choices[] = {
  { 0, "AUTO" },
  { 1, "MANUAL" },
  { -1, NULL}};

multichoice destination_choices[] = {
  { DEST_AUTO, "AUTO" },
  { DEST_AUTO, "auto" },
  { DEST_BSSID, "BSSID" },
  { DEST_BSSID, "bssid" },
  { DEST_MULTICAST, "MULTICAST" },
  { DEST_MULTICAST, "multicast" },
  { DEST_SOURCE, "SOURCE" },
  { DEST_SOURCE, "source" },
  { -1, NULL}};

multichoice roaming_choices[] = {
  { 1, "FIRMWARE" },
  { 0, "XSUPPLICANT" },
  { -1, NULL}};

multichoice debug_choices[] = {
	{DEBUG_NORMAL, "NORMAL"},
	{DEBUG_INT, "INTERFACE"},
	{DEBUG_PHYSICAL_STATE, "PHYSICAL"},
	{DEBUG_DOT1X_STATE, "DOT1X_STATE"},
	{DEBUG_1X_BE_STATE, "DOT1X_BACKEND_STATE"},
	{DEBUG_EAP_STATE, "EAP_STATE"},
	{DEBUG_KEY_STATE, "KEY_STATE"},
	{DEBUG_KEY, "KEY"},
	{DEBUG_AUTHTYPES, "AUTHTYPES"},
	{DEBUG_CONFIG_PARSE, "CONFIG_PARSE"},
	{DEBUG_CONFIG_WRITE, "CONFIG_WRITE"},
	{DEBUG_SMARTCARD, "SMARTCARD"},
	{DEBUG_SNMP, "SNMP"},
	{DEBUG_IPC, "IPC"},
	{DEBUG_INIT, "INIT"},
	{DEBUG_DEINIT, "DEINIT"},
	{DEBUG_CONTEXT, "CONTEXT"},
	{DEBUG_EVENT_CORE, "EVENT_CORE"},
	{DEBUG_TLS_CORE, "TLS_CORE"},
	{DEBUG_TIMERS, "TIMERS"},
	{DEBUG_CERTS, "CERTIFICATES"},
	{DEBUG_TNC, "TNC"},
	{DEBUG_TNC_IMC, "TNC_IMC"},
	{DEBUG_VERBOSE, "VERBOSE"},
	{DEBUG_ALL, "ALL"},
	{-1, NULL}};

void *xsupconfig_parse_build_globals(void **attr, xmlNodePtr node)
{
#ifdef PARSE_DEBUG
  printf("Building globals config.\n");
#endif

  conf_globals = malloc(sizeof(struct config_globals));
  if (conf_globals == NULL)
    {
      printf("Couldn't allocate memory to store global setting configuration!"
	     "  (Line %ld)\n", xsupconfig_parse_get_line_num());
      exit(1);
    }

  memset(conf_globals, 0x00, sizeof(struct config_globals));

  xsupconfig_defaults_set_globals(conf_globals);

  return conf_globals;
}

void *xsupconfig_parse_logpath(void **attr, xmlNodePtr node)
{
  struct config_globals *myglobals;
  char *value;

  value = xmlNodeGetContent(node);

#ifdef PARSE_DEBUG
  printf("Would write log files to '%s'\n", value);
#endif

  myglobals = (*attr);

	if ((value == NULL) || (strlen(value) == 0))
	{
		free(value);
		myglobals->logpath = NULL;
	}
	else
	{
		myglobals->logpath = value;
	}

  return myglobals;
}

void *xsupconfig_parse_friendly_warnings(void **attr, xmlNodePtr node)
{
  struct config_globals *myglobals;
  uint8_t result;
  char *value;

  value = xmlNodeGetContent(node);

#ifdef PARSE_DEBUG
  printf("Should parse friendly warnings = %s\n", value);
#endif

  myglobals = (*attr);
  result = xsupconfig_common_yesno(value);

  if (result == 1) 
    {
      UNSET_FLAG(myglobals->flags, CONFIG_GLOBALS_NO_FRIENDLY_WARNINGS);
    }
  else if (result == 0)
    {
      SET_FLAG(myglobals->flags, CONFIG_GLOBALS_NO_FRIENDLY_WARNINGS);
    }
  else
    {
      xsupconfig_common_log("Didn't understand value '%s' in the friendly warning tag. "
	     "(Line %ld)   Defaulting to yes.\n", (char *)value,
	     xsupconfig_parse_get_line_num());

      UNSET_FLAG(myglobals->flags, CONFIG_GLOBALS_NO_FRIENDLY_WARNINGS);
    }

  FREE(value);

  return myglobals;
}

void *xsupconfig_parse_log_facility(void **attr, xmlNodePtr node)
{
  struct config_globals *myglobals;
  char *value;

  value = xmlNodeGetContent(node);

#ifdef PARSE_DEBUG
  printf("Log facility : %s\n", value);
#endif

  myglobals = (*attr);

	if ((value == NULL) || (strlen(value) == 0))
	{
		free(value);
		myglobals->log_facility = NULL;
	}
	else
	{
		myglobals->log_facility = value;
	}

  return myglobals;
}

void *xsupconfig_parse_ipc_group(void **attr, xmlNodePtr node)
{
  struct config_globals *myglobals;
  char *value;

  value = xmlNodeGetContent(node);

#ifdef PARSE_DEBUG
  printf("IPC Group : %s\n", value);
#endif

  myglobals = (*attr);

	if ((value == NULL) || (strlen(value) == 0))
	{
		free(value);
		myglobals->ipc_group_name = NULL;
	}
	else
	{
		myglobals->ipc_group_name = value;
	}

  return myglobals;
}

void *xsupconfig_parse_auth_period(void **attr, xmlNodePtr node)
{
  struct config_globals *myglobals;
  char *value;

  value = xmlNodeGetContent(node);

#ifdef PARSE_DEBUG
  printf("Auth Period : %s\n", value);
#endif

  myglobals = (*attr);

  if (xsupconfig_common_is_number(value) == 0)
    {
      xsupconfig_common_log("Value assigned to Auth_Period is not a number!  (Line %ld)   "
	     "Using default!\n", xsupconfig_parse_get_line_num());
    }
  else
    {
      myglobals->auth_period = atoi(value);
    }

  FREE(value);

  return myglobals;
}

void *xsupconfig_parse_held_period(void **attr, xmlNodePtr node)
{
  struct config_globals *myglobals;
  char *value;

  value = xmlNodeGetContent(node);

#ifdef PARSE_DEBUG
  printf("Held Period : %s\n", value);
#endif

  myglobals = (*attr);
 
  if (xsupconfig_common_is_number(value) == 0)
    {
      xsupconfig_common_log("Value assigned to Held_Period is not a number!  (Line %ld)  "
	     "Using default!\n", xsupconfig_parse_get_line_num());
    }
  else
    {
      myglobals->held_period = atoi(value);
    }

  FREE(value);

  return myglobals;
}

void *xsupconfig_parse_idle_while(void **attr, xmlNodePtr node)
{
  struct config_globals *myglobals;
  char *value;

  value = xmlNodeGetContent(node);

#ifdef PARSE_DEBUG
  printf("Idle While : %s\n", value);
#endif

  myglobals = (*attr);

  if (xsupconfig_common_is_number(value) == 0)
    {
      xsupconfig_common_log("Value assigned to Idle_While is not a number!  (Line %ld)   "
	     "Using default!\n", xsupconfig_parse_get_line_num());
    }
  else
    {
      myglobals->idleWhile_timeout = atoi(value);
    }

  FREE(value);

  return myglobals;
}

void *xsupconfig_parse_association(void **attr, xmlNodePtr node)
{
  struct config_globals *myglobals;
  int result;
  char *value;

  value = xmlNodeGetContent(node);

#ifdef PARSE_DEBUG
  printf("Association : %s\n", value);
#endif

  myglobals = (*attr);

  result = xsupconfig_common_select_from_list(association_choices, value);
  
  if (result == 1)
    {
      // Set for auto association.
      SET_FLAG(myglobals->flags, CONFIG_GLOBALS_ASSOC_AUTO);
    }

  if (result == 0)
    {
      // Set for manual association.
      UNSET_FLAG(myglobals->flags, CONFIG_GLOBALS_ASSOC_AUTO);
    }

  if (result == -1)
    {
      // Got an error.  Use default.
      SET_FLAG(myglobals->flags, CONFIG_GLOBALS_ASSOC_AUTO);
    }

  FREE(value);

  return myglobals;
}

void *xsupconfig_parse_destination(void **attr, xmlNodePtr node)
{
  struct config_globals *myglobals;
  int result;
  char *value;

  value = xmlNodeGetContent(node);

#ifdef PARSE_DEBUG
  printf("Destination : %s\n", value);
#endif

  myglobals = (*attr);

  result = xsupconfig_common_select_from_list(destination_choices, value);

  if (result > -1)
    {
      myglobals->destination = result;
    }

  FREE(value);

  return myglobals;
}


void *xsupconfig_parse_stale_key_timeout(void **attr, xmlNodePtr node)
{
  struct config_globals *myglobals;
  char *value;

  value = xmlNodeGetContent(node);

#ifdef PARSE_DEBUG
  printf("Stale Key Timeout : %s\n", value);
#endif

  myglobals = (*attr);

  if (xsupconfig_common_is_number(value) == 0)
    {
      xsupconfig_common_log("Invalid value for Stale_Key_Timeout.  (Line %ld)  Using "
	     "default!\n", xsupconfig_parse_get_line_num());
    }
  else
    {
      myglobals->stale_key_timeout = atoi(value);
    }

  FREE(value);

  return myglobals;
}

void *xsupconfig_parse_max_starts(void **attr, xmlNodePtr node)
{
  struct config_globals *myglobals;
  char *value;

  value = xmlNodeGetContent(node);

#ifdef PARSE_DEBUG
  printf("Max Starts : %s\n", value);
#endif

  myglobals = (*attr);

  if (xsupconfig_common_is_number(value) == 0)
    {
      xsupconfig_common_log("Invalid value for Max_Starts.  (Line %ld)   Using default!\n",
	     xsupconfig_parse_get_line_num());
    }
  else
    {
      myglobals->max_starts = atoi(value);
    }

  FREE(value);

  return myglobals;
}

void *xsupconfig_parse_allmulti(void **attr, xmlNodePtr node)
{
  struct config_globals *myglobals;
  uint8_t result;
  char *value;

  value = xmlNodeGetContent(node);

#ifdef PARSE_DEBUG
  printf("Allmulti : %s\n", value);
#endif

  myglobals = (*attr);

  result = xsupconfig_common_yesno(value);

  if (result == 1)
    {
      SET_FLAG(myglobals->flags, CONFIG_GLOBALS_ALLMULTI);

⌨️ 快捷键说明

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