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

📄 xsupgui_request2.c

📁 linux 下通过802.1认证的安装包
💻 C
📖 第 1 页 / 共 2 页
字号:
	xmlNodePtr n = NULL, t = NULL;
	int done = REQUEST_SUCCESS, err = 0;
	ipinfo_type *inf = NULL;
	char *temp = NULL;

	if (info == NULL) return IPC_ERROR_INVALID_PARAMETERS;

	(*info) = NULL;

	if (device == 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 request_get_ipinfo;
	}

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

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

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

	// Otherwise, parse it and see if we got what we wanted.
	err = xsupgui_request_check_exceptions(retdoc);
	if (err != 0) 
	{
		done = err;
		goto request_get_ipinfo;
	}

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

	inf = malloc(sizeof(ipinfo_type));
	if (inf == NULL)
	{
		done = IPC_ERROR_CANT_ALLOCATE_MEMORY;
		goto request_get_ipinfo;
	}

	memset(inf, 0x00, sizeof(ipinfo_type));

	// 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, "IP_Data");
	if (n == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE;
		free(inf);
		goto request_get_ipinfo;
	}

	// We don't care about the interface result for now.
	t = xsupgui_request_find_node(n->children, "IP_Address");
	if (t == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		free(inf);
		goto request_get_ipinfo;
	}

	inf->ipaddr = xmlNodeGetContent(t);

	t = xsupgui_request_find_node(n->children, "Netmask");
	if (t == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		free(inf);
		goto request_get_ipinfo;
	}

	inf->netmask = xmlNodeGetContent(t);

	t = xsupgui_request_find_node(n->children, "Gateway");
	if (t == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		free(inf);
		goto request_get_ipinfo;
	}

	inf->gateway = xmlNodeGetContent(t);

	t = xsupgui_request_find_node(n->children, "DNS1");
	if (t == NULL)
	  {
	    done = IPC_ERROR_BAD_RESPONSE_DATA;
		free(inf);
	    goto request_get_ipinfo;
	  }

	inf->dns1 = xmlNodeGetContent(t);

	t = xsupgui_request_find_node(n->children, "DNS2");
	if (t == NULL)
	  {
	    done = IPC_ERROR_BAD_RESPONSE_DATA;
		free(inf);
	    goto request_get_ipinfo;
	  }

	inf->dns2 = xmlNodeGetContent(t);

	t = xsupgui_request_find_node(n->children, "DNS3");
	if (t == NULL)
	  {
	    done = IPC_ERROR_BAD_RESPONSE_DATA;
		free(inf);
	    goto request_get_ipinfo;
	  }

	inf->dns3 = xmlNodeGetContent(t);

	done = REQUEST_SUCCESS;

request_get_ipinfo:
	if (doc != NULL) xmlFreeDoc(doc);
	if (retdoc != NULL) xmlFreeDoc(retdoc);

	(*info) = inf;

	return done;
}

/**
 *  \brief Request that we change to a new connection.
 *
 *  Request that the supplicant switch to a new connection.  This will
 *  cause the supplicant to disassociate from any currently associated network
 *  and attempt to associate to the network specified by the new connection
 *  block.
 *
 *  \retval REQUEST_SUCCESS on success
 *	\retval REQUEST_TIMEOUT on timeout.
 *	\retval >299 on other error.
 **/
int xsupgui_request_set_connection(char *device, char *conn_name)
{
	xmlDocPtr doc = NULL;
	xmlDocPtr retdoc = NULL;
	xmlNodePtr n = NULL, t = NULL;
	int done = 0, err = 0;
	char *temp = NULL;

	if ((device == NULL) || (conn_name == 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 request_set_conn;
	}

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

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

	xsupgui_xml_common_convert_amp(conn_name, &temp);
	if (xmlNewChild(t, NULL, "Connection_Name", temp) == NULL)
	{
		done = IPC_ERROR_UNSPEC_REQ_FAILURE;
		free(temp);
		goto request_set_conn;
	}
	free(temp);

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

	// Otherwise, parse it and see if we got what we wanted.
	err = xsupgui_request_check_exceptions(retdoc);
	if (err != 0) 
	{
		done = err;
		goto request_set_conn;
	}

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

	// 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 = n->children;
	if (xsupgui_request_find_node(n, "ACK") != NULL)
	{
		done = REQUEST_SUCCESS;
	}
	else
	{
		done = IPC_ERROR_NOT_ACK;
	}

request_set_conn:
	if (doc != NULL) xmlFreeDoc(doc);
	if (retdoc != NULL) xmlFreeDoc(retdoc);

	return done;
}

/**
 * \brief Request the connections available in the configuration file.
 *
 * @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_connections(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;
	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_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, "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(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(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, "Device_Description");
		if (t == NULL)
		{
			if (myconns != NULL) free(myconns);
			done = IPC_ERROR_BAD_RESPONSE;
			goto finish_enum_connections;
		}

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

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

		content = xmlNodeGetContent(t);
		if (content != NULL)
		{
			myconns[i].priority = atoi(content);
			free(content);
		}

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

		content = xmlNodeGetContent(t);
		if (content != NULL)
		{
			myconns[i].encryption = atoi(content);
			free(content);
		}

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

		content = xmlNodeGetContent(t);
		if ((content != NULL) && (strlen(content) > 0))
		{
			myconns[i].auth_type = atoi(content);
			free(content);
		}

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

		content = xmlNodeGetContent(t);
		if ((content != NULL) && (strlen(content) > 0))
		{
			myconns[i].assoc_type = atoi(content);
			free(content);
		}

		n = n->next;
	}

	(*connections) = myconns;
	done = REQUEST_SUCCESS;

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

	return done;  
}

⌨️ 快捷键说明

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