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

📄 xsupgui_request7.c

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

#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"

/**
 * \brief Answer a yes/no TNC UI request.
 *
 * @param[in] imcID   The ID of the IMC that generated the request that we are answering.
 * @param[in] connID   The connection ID that the IMC is using to track this connection.
 * @param[in] oui   The OUI of the IMC that generated the request.
 * @param[in] response   The response (TRUE/FALSE) to send to the IMC.
 *
 * \retval >299 the request to the supplicant failed.
 * \retval REQUEST_TIMEOUT the request timed out
 * \retval REQUEST_SUCCESS the request succeeded.
 **/
int xsupgui_request_answer_tnc_ui_request(uint32_t imcID, uint32_t connID, 
										  uint32_t oui, uint32_t notification, 
										  uint32_t response)
{
	xmlDocPtr doc = NULL;
	xmlDocPtr retdoc = NULL;
	xmlNodePtr n = NULL, t = NULL;
	char tempstatic[100];
	int retval = REQUEST_SUCCESS;
	int err = 0;

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

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

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

	sprintf((char *)&tempstatic, "%d", imcID);
	if (xmlNewChild(t, NULL, "imcID", tempstatic) == NULL)
	{
		retval = IPC_ERROR_CANT_CREATE_REQUEST;
		goto done;
	}

	sprintf((char *)&tempstatic, "%d", connID);
	if (xmlNewChild(t, NULL, "connID", tempstatic) == NULL)
	{
		retval = IPC_ERROR_CANT_CREATE_REQUEST;
		goto done;
	}

	sprintf((char *)&tempstatic, "%d", oui);
	if (xmlNewChild(t, NULL, "OUI", tempstatic) == NULL)
	{
		retval = IPC_ERROR_CANT_CREATE_REQUEST;
		goto done;
	}

	sprintf((char *)&tempstatic, "%d", response);
	if (xmlNewChild(t, NULL, "Response", tempstatic) == NULL)
	{
		retval = IPC_ERROR_CANT_CREATE_REQUEST;
		goto done;
	}

	sprintf((char *)&tempstatic, "%d", notification);
	if (xmlNewChild(t, NULL, "Notification", tempstatic) == NULL)
	{
		retval = IPC_ERROR_CANT_CREATE_REQUEST;
		goto done;
	}

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

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

	retval = xsupgui_request_is_ack(retdoc);

done:
	xmlFreeDoc(doc);
	xmlFreeDoc(retdoc);

	return retval;
}

/**
 * \brief Given an OS specific interface name, get the information about it.
 *
 * @param[in] intname   The OS specific interface name that we need to get information
 *                      for.
 * @param[out] intdesc   The interface description tied to the OS specific interface name.
 * @param[out] mac   The string representation of the MAC address for the interface.
 *                   (Suitable for inclusion in the configuration file structures.)
 * @param[out] iswireless   TRUE or FALSE indicating if the interface named is wireless.
 *
 * \retval >299 the request to the supplicant failed.
 * \retval REQUEST_TIMEOUT the request timed out
 * \retval REQUEST_SUCCESS the request succeeded.
 **/
int xsupgui_request_get_os_specific_int_data(char *intname, char **intdesc, char **mac, 
											 int *iswireless)
{
	xmlDocPtr doc = NULL;
	xmlDocPtr retdoc = NULL;
	xmlNodePtr n = NULL, t = NULL;
	char tempstatic[100];
	char *value = NULL;
	int retval = REQUEST_SUCCESS;
	int err = 0;
	char *temp = NULL;

	if ((intname == NULL) || (intdesc == NULL) || (mac == NULL) || (iswireless == NULL))
		return IPC_ERROR_INVALID_PARAMETERS;

	(*intdesc) = NULL;
	(*mac) = NULL;

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

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

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

	xsupgui_xml_common_convert_amp(intname, &temp);
	if (xmlNewChild(t, NULL, "Interface", temp) == NULL)
	{
		retval = IPC_ERROR_CANT_CREATE_INT_NODE;
		free(temp);
		goto done;
	}
	free(temp);

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

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

	n = xmlDocGetRootElement(retdoc);
	if (n == NULL)
	{
		retval = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
		goto done;
	}

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

	n = n->children;
	t = xsupgui_request_find_node(n, "Description");
	if (t == NULL)
	{
		retval = IPC_ERROR_BAD_RESPONSE_DATA;
		goto done;
	}

	(*intdesc) = xmlNodeGetContent(t);

	t = xsupgui_request_find_node(n, "MAC");
	if (t == NULL)
	{
		retval = IPC_ERROR_BAD_RESPONSE_DATA;
		goto done;
	}

	(*mac) = xmlNodeGetContent(t);

	t = xsupgui_request_find_node(n, "Wireless");
	if (t == NULL)
	{
		retval = IPC_ERROR_BAD_RESPONSE_DATA;
		goto done;
	}

	value = xmlNodeGetContent(t);

	(*iswireless) = atoi(value);

done:
	xmlFreeDoc(doc);
	xmlFreeDoc(retdoc);

	return retval;
}

/**
 * \brief Given an interface name, get it's connection name back.
 *
 * @param[in] intname   The OS specific interface name that we need to get information
 *                      for.
 * @param[out] connname   The interface connection name.
 *
 * \retval >299 the request to the supplicant failed.
 * \retval REQUEST_TIMEOUT the request timed out
 * \retval REQUEST_SUCCESS the request succeeded.
 **/
int xsupgui_request_get_conn_name_from_int(char *intname, char **connname)
{
	xmlDocPtr doc = NULL;
	xmlDocPtr retdoc = NULL;
	xmlNodePtr n = NULL, t = NULL;
	char *value = NULL;
	int retval = REQUEST_SUCCESS;
	int err = 0;
	char *temp = NULL;

	if ((intname == NULL) || (connname == NULL)) return IPC_ERROR_INVALID_PARAMETERS;

	(*connname) = NULL;

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

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

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

	xsupgui_xml_common_convert_amp(intname, &temp);
	if (xmlNewChild(t, NULL, "Interface", temp) == NULL)
	{
		retval = IPC_ERROR_CANT_CREATE_INT_NODE;
		free(temp);
		goto done;
	}
	free(temp);

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

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

	n = xmlDocGetRootElement(retdoc);
	if (n == NULL)
	{
		retval = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
		goto done;
	}

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

	n = n->children;
 
	t = xsupgui_request_find_node(n, "Connection");
	if (t == NULL)
	{
		retval = IPC_ERROR_BAD_RESPONSE_DATA;
		goto done;
	}

	(*connname) = xmlNodeGetContent(t);

done:
	xmlFreeDoc(doc);
	xmlFreeDoc(retdoc);

	return retval;
}

/**
 * \brief Request that the supplicant return any error messages that might be in the queue.
 *
 * \note If the return value is IPC_ERROR_NO_ERRORS_IN_QUEUE, then there is nothing wrong with the
 *       supplicant.  It just means that there is nothing to show.
 *
 * @param[in] emsg_enum   The resulting array of error message strings.
 *
 * \retval >299 the request to the supplicant failed.
 * \retval REQUEST_TIMEOUT the request timed out
 * \retval REQUEST_SUCCESS the request succeeded.
 **/ 
int xsupgui_request_get_error_msgs(error_messages **emsg_enum)
{
	int retval = REQUEST_SUCCESS;
	int err = 0, numevents = 0, i = 0;
	xmlDocPtr doc = NULL;
	xmlDocPtr retdoc = NULL;
	xmlNodePtr n = NULL, t = NULL;
	char *value = NULL;
	error_messages *msgs = NULL;

	if (emsg_enum == NULL) return IPC_ERROR_INVALID_PARAMETERS;

	(*emsg_enum) = NULL;

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

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

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

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

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

	n = xmlDocGetRootElement(retdoc);
	if (n == NULL)
	{
		retval = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
		goto done;
	}

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

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

	value = xmlNodeGetContent(t);

	if ((value == NULL) || (strlen(value) == 0))
	{
		retval = IPC_ERROR_INVALID_NUMBER_OF_EVENTS;
		goto done;
	}

	numevents = atoi(value);
	free(value);
	value = NULL;

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

	msgs = (error_messages *)Malloc((sizeof(error_messages) * (numevents + 1)));
	if (msgs == NULL)
	{
		retval = IPC_ERROR_CANT_ALLOCATE_MEMORY;
		goto done;
	}

	t = t->children;

	for (i = 0; i<numevents; i++)
	{
		t = xsupgui_request_find_node(t, "Message");
		if (t == NULL)
		{
			retval = IPC_ERROR_BAD_RESPONSE;
			free(msgs);
			goto done;
		}

		msgs[i].errmsgs = xmlNodeGetContent(t);

		t = t->next;
	}

	(*emsg_enum) = msgs;

done:
	xmlFreeDoc(doc);
	xmlFreeDoc(retdoc);

	return retval;
}

/**
 * \brief Clean up all of the memory that was used by the error message enum.
 *
 * @param[in] errmsg_enum   The error message enum that was returned from xsupgui_request_get_error_msgs().
 **/
void xsupgui_request_free_error_msgs(error_messages **errmsg_enum)
{
	error_messages *cur = NULL;
	int i = 0;

	if (errmsg_enum == NULL) return;   // Nothing to free.

	cur = (*errmsg_enum);

	if(cur != NULL)
	{
		while (cur[i].errmsgs != NULL)
		{
			free(cur[i].errmsgs);
			i++;
		}
	}

	free((*errmsg_enum));
	(*errmsg_enum) = NULL;
}

/**
 * \brief Request the connections that the supplicant might be able to connect to.
 *
 * @param[out] connections   A structure that contains a list of connections, and information
 *                           about each one.
 *
 * \retval REQUEST_SUCCESS on success
 * \retval REQUEST_TIMEOUT on timeout.
 * \retval >299 on other error.
 *
 **/
int xsupgui_request_enum_possible_connections(poss_conn_enum **connections)
{
	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;
	poss_conn_enum *myconns = NULL;

	if (connections == NULL) return IPC_ERROR_INVALID_PARAMETERS;

	(*connections) = 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_connections;
	}

	if (xmlNewChild(n, NULL, "Get_Possible_Connections", NULL) == NULL)
	{
		done = IPC_ERROR_CANT_CREATE_REQUEST;
		goto finish_enum_connections;
	}

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

	// 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_connections;
	}

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

	// 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, "Possible_Connections");
	if (n == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE;
		goto finish_enum_connections;
	}

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

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

#ifdef REQUEST_DEBUG
	printf("%s connection(s) found!\n", content);
#endif
	numints = atoi(content);
	free(content);

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

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

	n = n->children;
	for (i=0; i <numints; i++)
	{
		n = xsupgui_request_find_node(n, "Connection");
		if (n == NULL) 
		{
			if (myconns != NULL) free(myconns);
			done = IPC_ERROR_BAD_RESPONSE;
			goto finish_enum_connections;
		}

		t = xsupgui_request_find_node(n->children, "Connection_Name");
		if (t == NULL) 
		{
			if (myconns != NULL) free(myconns);
			done = IPC_ERROR_BAD_RESPONSE;
			goto finish_enum_connections;
		}

		myconns[i].name = xmlNodeGetContent(t);

		t = xsupgui_request_find_node(n->children, "SSID_Name");
		if (t == NULL)
		{
			if (myconns != NULL) free(myconns);
			done = IPC_ERROR_BAD_RESPONSE;
			goto finish_enum_connections;
		}

		myconns[i].ssid = xmlNodeGetContent(t);

		t = xsupgui_request_find_node(n->children, "Flags");

⌨️ 快捷键说明

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