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

📄 xsupgui_request.c

📁 linux 下通过802.1认证的安装包
💻 C
📖 第 1 页 / 共 2 页
字号:
	if (t == NULL)
	{
		// See if we have a deprecated block.
		t = xsupgui_request_find_node(n, "Deprecated");
	}

	if (t == NULL) return REQUEST_SUCCESS;   // Everything is good.

	err = xsupgui_request_find_node(t->children, "Error_Code");
	if (err == NULL) return IPC_ERROR_NO_ERROR_CODE;   // WTF!?  We didn't get an error code?

	resval = xmlNodeGetContent(err);
	if ((resval == NULL) || (strlen(resval) == 0))
		return IPC_ERROR_NO_ERROR_CODE;  // ACK we won't know what the error code is!

	done = atoi(resval);
	free(resval);

	return done;  
}

/**
 * \brief Take an XML document pointer, convert it to text, and send it
 *        across the communications media. 
 *
 * @param[in] indoc   An xmlDocPtr that contains the IPC request that
 *                    will be sent to the supplicant.
 * @param[out] outdoc   An xmlDocPtr that contains the response to the
 *                      IPC request specified by indoc.
 *
 * \retval REQUEST_SUCCESS   success
 * \retval REQUEST_TIMEOUT   request timed out
 * \retval >299   Error message was received.  (See error "#defines" in \ref xsupgui_request.h for
 *         more information.)
 **/
int xsupgui_request_send(xmlDocPtr indoc, xmlDocPtr *outdoc)
{
	xmlChar *docbuf = NULL;
	int bufsize = 0;
	char *resultbuf = NULL;
	int resbufsize = 0;
	int err = 0;

	if (indoc == NULL) return IPC_ERROR_NULL_DOCUMENT;

	// Create a text representation of the document in memory.  Unformatted.
	xmlDocDumpFormatMemory(indoc, &docbuf, &bufsize, 0);
#ifdef REQUEST_DEBUG
	printf("Sending document : %s\n", docbuf);
#endif

	if (docbuf == NULL) return IPC_ERROR_NULL_REQUEST;

	err = xsupgui_send(docbuf, bufsize, &resultbuf, &resbufsize);

	// We are done with docbuf.
	free(docbuf);

	if (err != REQUEST_SUCCESS)
	{
		if (resultbuf != NULL) free(resultbuf);
		return err;
	}

#ifdef REQUEST_DEBUG
	printf("Result document : %s\n", (char *)resultbuf);
#endif

	(*outdoc) = xsupgui_xml_common_validate_msg(resultbuf, resbufsize);
	if ((*outdoc) == NULL) 
	{
#ifdef REQUEST_DEBUG
		printf("Invalid document!\n");
#endif
		if (resultbuf != NULL) free(resultbuf);
		return IPC_ERROR_NULL_RESPONSE;
	}

	if (resultbuf != NULL) free(resultbuf);
	return REQUEST_SUCCESS;
}

/**
 *  \brief Request that the supplicant send us a list of known interfaces from the OS, 
 *         and their descriptions.
 *
 *  \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)
 *  \retval >299 on other error (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_live_ints(int_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_enum *ints = NULL;

	// Set their pointer to NULL in case they don't check the return value, and feed us
	// back an invalid pointer to free. :-/
	(*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_Live_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_Live_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_DATA;
		goto finish_enum_ints;
	}

	content = xmlNodeGetContent(t);
	if (content == NULL)
	{
		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_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_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_Name");
		if (t == NULL) 
		{
			if (ints != NULL) free(ints);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish_enum_ints;
		}

		ints[i].name = 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, "Interface_Is_Wireless");
		if (t == NULL)
		{
			if (ints != NULL) free(ints);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish_enum_ints;
		}

		content = xmlNodeGetContent(t);
		if (content == NULL)
		{
			ints[i].is_wireless = 0;
		}
		else
		{
			ints[i].is_wireless = atoi(content);
			if (content != NULL) free(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 send us a list of known EAP methods, and their
 *         descriptions.
 *
 *  \retval REQUEST_SUCCESS on success (eaptypes will be populated, with a NULL set at the end.)
 *  \retval REQUEST_TIMEOUT on timeout (eaptypes will contain nothing interesting)
 *  \retval >299 on other error (eaptypes will contain nothing interesting)
 *
 *  \note The caller is expected to free the memory that '**eaptypes' occupies.  As this
 *        data is returned as an array, the caller should be able to free((*eaptypes)) and 
 *        be fine.
 **/
int xsupgui_request_enum_eap_methods(eap_enum **eaptypes)
{
	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;
	eap_enum *myeaps = 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_eap_methods;
	}

	if (xmlNewChild(n, NULL, "Enum_EAP_Methods", NULL) == NULL)
	{
		done = IPC_ERROR_CANT_CREATE_REQUEST;
		goto finish_enum_eap_methods;
	}

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

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

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

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

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

	content = xmlNodeGetContent(t);
	if (content == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		goto finish_enum_eap_methods;
	}

#ifdef REQUEST_DEBUG
	printf("%s interface(s) found!\n", content);
#endif

	numints = atoi(content);

	if (content != NULL) free(content);

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

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

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

		t = xsupgui_request_find_node(n->children, "Method_Name");
		if (t == NULL) 
		{
			if (myeaps != NULL) free(myeaps);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish_enum_eap_methods;
		}

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

		t = xsupgui_request_find_node(n->children, "Method_Number");
		if (t == NULL)
		{
			if (myeaps != NULL) free(myeaps);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish_enum_eap_methods;
		}

		content = xmlNodeGetContent(t);
		if (content != NULL)
		{
			myeaps[i].num = atoi(content);
			free(content);
		}
		else
		{
			myeaps[i].num = 0;
		}

		n = n->next;
	}

	(*eaptypes) = myeaps;
	done = REQUEST_SUCCESS;

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

	return done;  
}

⌨️ 快捷键说明

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