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

📄 xsupgui_request6.c

📁 linux 下通过802.1认证的安装包
💻 C
📖 第 1 页 / 共 3 页
字号:
/**
 * Licensed under a dual GPL/BSD license. (See LICENSE file for more info.)
 *
 * \file xsupgui_request6.c
 *
 * \author chris@open1x.org
 *
 * $Id: xsupgui_request6.c,v 1.1.2.24 2007/10/09 21:32:16 chessing Exp $
 * $Date: 2007/10/09 21:32:16 $
 **/

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

#ifdef WINDOWS
#include "../../src/stdintwin.h"
#endif

#include "xsupgui.h"
#include "xsupgui_request.h"
#include "xsupgui_xml_common.h"

#include "../libxsupconfig/xsupconfig_parse.h"
#include "../libxsupconfig/xsupconfig_parse_managed_networks.h"
#include "../libxsupconfwrite/xsupconfwrite_managed_networks.h"

/**
 * \brief Request that the supplicant delete (from memory) the managed network 
 *        identified by ouname.
 *
 * @param[in] ouname   The name of the OU that we want to delete from our configuration.
 *
 * \retval REQUEST_FAILURE on failure
 * \retval REQUEST_TIMEOUT on timeout
 * \retval REQUEST_SUCCESS on success
 **/
int xsupgui_request_delete_managed_network_config(char *ouname)
{
	return xsupgui_request_delete_some_conf("Delete_Managed_Network_Config", "OU", ouname);
}

/**
 * \brief Request the full configuration for the "<Managed_Network>" block that 
 *        can be identified by the OU specified by ouname.
 *
 * @param[in] ouname   The name of the OU that we want to get the data for.
 * @param[out] mnconfig   A config_managed_networks structure that contains the values
 *                        for all of the settings for the requested OU.
 *
 * \retval >299 on failure
 * \retval REQUEST_TIMEOUT on timeout
 * \retval REQUEST_SUCCESS on success
 **/
int xsupgui_request_get_managed_network_config(char *ouname, config_managed_networks **mnconfig)
{
	xmlDocPtr doc = NULL;
	xmlDocPtr retdoc = NULL;
	xmlNodePtr n = NULL, t = NULL;
	int done = REQUEST_SUCCESS;
	struct config_managed_networks *newn = NULL;
	int err = 0;
	char *temp = NULL;

	if ((ouname == NULL) || (mnconfig == NULL)) return IPC_ERROR_INVALID_PARAMETERS;

	(*mnconfig) = NULL;

	doc = xsupgui_xml_common_build_msg();
	if (doc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;

	n = xmlDocGetRootElement(doc);
	if (n == NULL)
	{
		done = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
		goto finish_get_managed_nets_conf;
	}

	t = xmlNewChild(n, NULL, "Get_Managed_Network_Config", NULL);
	if (t == NULL)
	{
		done = IPC_ERROR_CANT_CREATE_REQUEST;
		goto finish_get_managed_nets_conf;
	}

	xsupgui_xml_common_convert_amp(ouname, &temp);
	if (xmlNewChild(t, NULL, "OU", temp) == NULL)
	{
		done = IPC_ERROR_CANT_CREATE_REQUEST;
		free(temp);
		goto finish_get_managed_nets_conf;
	}
	free(temp);

	err = xsupgui_request_send(doc, &retdoc);
	if (err != REQUEST_SUCCESS)
	{
		done = err;
		goto finish_get_managed_nets_conf;
	}

	err = xsupgui_request_check_exceptions(retdoc);
	if (err != REQUEST_SUCCESS)
	{
		done = err;
		goto finish_get_managed_nets_conf;
	}

	// We now have an XML document that contains the configuration information we want.  It will be
	// the <Managed_Network> tag wrapped in a <Managed_Network_Config> response tag.
	n = xmlDocGetRootElement(retdoc);
	if (n == NULL)
	{
		done = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
		goto finish_get_managed_nets_conf;
	}

	n = xsupgui_request_find_node(n->children, "Managed_Network_Config");
	if (n == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE;
		goto finish_get_managed_nets_conf;
	}

	// Otherwise, we need to parse the data that is in the child node.
	xsupconfig_parse(n->children, managed_networks, &newn);
	if (newn == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		goto finish_get_managed_nets_conf;
	}

	(*mnconfig) = newn;

finish_get_managed_nets_conf:
	xmlFreeDoc(doc);
	xmlFreeDoc(retdoc);

	return done;
}

/**
 * \brief Request that a new configuration be created, or that an existing configuration
 *        be updated.  The decision to create or update will be based on the OU field
 *        in the structure matching an existing OU.
 *
 * @param[in] mnconfig   A managed network configuration structure that we want the
 *                       supplicant to update in memory.  
 *
 * \warning This function will *NOT* write the configuration file.  If you want the file
 *          written you will need to make another call.
 *
 * \retval >299 on failure
 * \retval REQUEST_TIMEOUT on timeout
 * \retval REQUEST_SUCCESS on success
 **/
int xsupgui_request_set_managed_network_config(config_managed_networks *mnconfig)
{
  xmlDocPtr doc = NULL;
  xmlDocPtr retdoc = NULL;
  xmlNodePtr n = NULL, t = NULL;
  int done = REQUEST_SUCCESS;
  int err = 0;

  if (mnconfig == NULL) return IPC_ERROR_INVALID_PARAMETERS;

  doc = xsupgui_xml_common_build_msg();
  if (doc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;

  n = xmlDocGetRootElement(doc);
  if (n == NULL)
    {
      done = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
      goto finish_set_managed_network_config;
    }

  n = xmlNewChild(n, NULL, "Set_Managed_Network_Config", NULL);
  if (n == NULL)
    {
      done = IPC_ERROR_CANT_CREATE_REQUEST;
      goto finish_set_managed_network_config;
    }

  t = xsupconfwrite_managed_network_create_tree(mnconfig, TRUE);
  if (t == NULL)
  {
	  done = IPC_ERROR_UNSPEC_REQ_FAILURE;
	  goto finish_set_managed_network_config;
  }

  if (xmlAddChild(n, t) == NULL)
  {
	  done = IPC_ERROR_CANT_ADD_NODE;
	  goto finish_set_managed_network_config;
  }

	err = xsupgui_request_send(doc, &retdoc);
	if (err != REQUEST_SUCCESS)
	{
		done = err;
		goto finish_set_managed_network_config;
	}

	// Check if we got errors.
	err = xsupgui_request_check_exceptions(retdoc);
	if (err != 0) 
	{
		done = err;
		goto finish_set_managed_network_config;
	}

	done = xsupgui_request_is_ack(retdoc); 

finish_set_managed_network_config:
	if (doc) xmlFreeDoc(doc);
	if (retdoc) xmlFreeDoc(retdoc);

	return done;
}

/**
 *  \brief Request that the supplicant send us a list of known interfaces from the  
 *         configuration file, and their descriptions.
 *
 *  \retval >299 on error (retints will contain nothing interesting)
 *  \retval REQUEST_SUCCESS on success (retints will be populated, with a NULL set at the end.)
 *  \retval REQUEST_TIMEOUT on timeout (retints will contain nothing interesting)
 *
 *  \note The caller is expected to free the memory that '**retints' occupies.  As this
 *        data is returned as an array, the caller should be able to free((*retints)) and 
 *        be fine.
 **/
int xsupgui_request_enum_ints_config(int_config_enum **retints)
{
	xmlDocPtr doc = NULL;
	xmlDocPtr retdoc = NULL;
	xmlNodePtr n = NULL, t = NULL;
	xmlChar *content = NULL;
	int done = REQUEST_SUCCESS;
	int numints = 0, i = 0, err = 0;
	int_config_enum *ints = NULL;

	if (retints == NULL) return IPC_ERROR_INVALID_PARAMETERS;

	(*retints) = NULL;

	doc = xsupgui_xml_common_build_msg();
	if (doc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;

	n = xmlDocGetRootElement(doc);
	if (n == NULL)
	{
		done = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
		goto finish_enum_ints;
	}

	if (xmlNewChild(n, NULL, "Enum_Config_Interfaces", NULL) == NULL)
	{
		done = IPC_ERROR_CANT_CREATE_REQUEST;
		goto finish_enum_ints;
	}

	err = xsupgui_request_send(doc, &retdoc);
	if (err != REQUEST_SUCCESS)
	{
		done = err;
		goto finish_enum_ints;
	}

	// Otherwise, parse it and see if we got what we wanted.

	// Check if we got errors.
	err = xsupgui_request_check_exceptions(retdoc);
	if (err != 0) 
	{
		done = err;
		goto finish_enum_ints;
	}

	n = xmlDocGetRootElement(retdoc);
	if (n == NULL)
	{
		done = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
		goto finish_enum_ints;
	}

	// If we get here, then we know that the document passed the
	// validation tests imposed.  So, we need to see if we got the result 
	// we wanted.
	n = xsupgui_request_find_node(n->children, "Interface_Config_List");
	if (n == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE;
		goto finish_enum_ints;
	}

	t = xsupgui_request_find_node(n->children, "Interface_Count");
	if (t == NULL) 
	{
		done = IPC_ERROR_BAD_RESPONSE;
		goto finish_enum_ints;
	}

	content = xmlNodeGetContent(t);
	if ((content == NULL) || (strlen(content) == 0))
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		goto finish_enum_ints;
	}

#ifdef REQUEST_DEBUG
	printf("%s interface(s) found!\n", content);
#endif
	if (content != NULL)
	{
		numints = atoi(content);

		if (content != NULL) free(content);
	}
	else
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		goto finish_enum_ints;
	}

	// Allocate memory for our return structure.
	ints = malloc(sizeof(int_config_enum)*(numints+1));
	if (ints == NULL) 
	{
#ifdef REQUEST_DEBUG
		printf("Couldn't allocate memory to return interface data!\n");
#endif
		done = IPC_ERROR_CANT_ALLOCATE_MEMORY;
		goto finish_enum_ints;
	}

	// Clear the memory.
	memset(ints, 0x00, (sizeof(int_config_enum)*(numints+1)));

	n = n->children;
	for (i=0; i <numints; i++)
	{
		n = xsupgui_request_find_node(n, "Interface");
		if (n == NULL) 
		{
			if (ints != NULL) free(ints);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish_enum_ints;
		}

		t = xsupgui_request_find_node(n->children, "Interface_MAC");
		if (t == NULL) 
		{
			if (ints != NULL) free(ints);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish_enum_ints;
		}

		ints[i].mac = xmlNodeGetContent(t);

		t = xsupgui_request_find_node(n->children, "Interface_Description");
		if (t == NULL)
		{
			if (ints != NULL) free(ints);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish_enum_ints;
		}

		ints[i].desc = xmlNodeGetContent(t);

		t = xsupgui_request_find_node(n->children, "Is_Wireless");
		if (t == NULL)
		{
			if (ints != NULL) free(ints);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish_enum_ints;
		}

		content = xmlNodeGetContent(t);
		if (strcmp(content, "YES") == 0)
		{
			ints[i].is_wireless = TRUE;
		}
		else
		{
			ints[i].is_wireless = FALSE;
		}

		xmlFree(content);

		t = xsupgui_request_find_node(n->children, "Default_Connection");
		if (t == NULL)
		{
			if (ints != NULL) free(ints);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish_enum_ints;
		}

		content = xmlNodeGetContent(t);
		if ((content == NULL) || (strlen(content) == 0))
		{
			ints[i].default_connection = NULL;
		}
		else
		{
			ints[i].default_connection = _strdup(content);
		}

		xmlFree(content);

		n = n->next;
	}

	(*retints) = ints;
	done = REQUEST_SUCCESS;

finish_enum_ints:
	if (doc) xmlFreeDoc(doc);
	if (retdoc) xmlFreeDoc(retdoc);

	return done;  
}

/**
 * \brief Request that the supplicant list all of the known SSIDs in it's SSID
 *        cache.
 *
 * \note This function will return the scan cache of the supplicant for a given
 *       interface.  The scan cache will likely have duplicate entries if more 
 *       that one AP is broadcasting the same SSID. 
 *
 * @param[in] device   The OS specific device name that we want to query the 
 *                     scan cache for.
 * @param[out] ssids   An array of ssid_info_enum that will contain the name
 *                     of an SSID, and any associated info.
 *
 *  \retval >299 on error (retints will contain nothing interesting)
 *  \retval REQUEST_SUCCESS on success (retints will be populated, with a NULL set at the end.)
 *  \retval REQUEST_TIMEOUT on timeout (retints will contain nothing interesting)
 **/ 
int xsupgui_request_enum_ssids(char *device, ssid_info_enum **ssids)
{
	xmlDocPtr doc = NULL;
	xmlDocPtr retdoc = NULL;
	xmlNodePtr n = NULL, t = NULL;
	xmlChar *content = NULL;
	int done = REQUEST_SUCCESS;
	int numssids = 0, i = 0, err = 0;
	ssid_info_enum *ssidarray = NULL;
	char *temp = NULL;

⌨️ 快捷键说明

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