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

📄 xsupgui_request4.c

📁 linux 下通过802.1认证的安装包
💻 C
📖 第 1 页 / 共 2 页
字号:
		goto finish_get_profile;
	}

	xsupgui_xml_common_convert_amp(prof_name, &temp);
	if (xmlNewChild(t, NULL, "Name", temp) == NULL)
	{
		done = IPC_ERROR_CANT_CREATE_REQUEST;
		free(temp);
		goto finish_get_profile;
	}
	free(temp);

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

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

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

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

	n = xsupgui_request_find_node(n->children, "Profile");
	if (n == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		goto finish_get_profile;
	}

	if (xsupconfig_defaults_create_profile(&newp) != 0)
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		goto finish_get_profile;
	}

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

	(*prof_config) = newp;

finish_get_profile:
	xmlFreeDoc(doc);
	xmlFreeDoc(retdoc);

	return done;
}

/**
 * \brief Get the "<Connection>" block for a single named connection.
 *
 * \note The caller is expected to free the memory returned by **conn_config.
 *
 * @param[in] conn_name   The name of the connection that we want to get the 
 *                        configuration block for.
 * @param[out] conn_config   A pointer to a buffer that will return a text version
 *                           of the requested connection in the supplicant's memory.
 *
 * \retval REQUEST_SUCCESS on success
 * \retval REQUEST_TIMEOUT on timeout
 * \retval >299 on failure
 **/
int xsupgui_request_get_connection_config(char *conn_name, config_connection **conn_config)
{
	xmlDocPtr doc = NULL;
	xmlDocPtr retdoc = NULL;
	xmlNodePtr n = NULL, t = NULL;
	int done = REQUEST_SUCCESS;
	struct config_connection *newc = NULL;
	int err = 0;
	char *temp = NULL;

	if ((conn_name == NULL) || (conn_config == NULL)) return IPC_ERROR_INVALID_PARAMETERS;

	(*conn_config) = 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_connection;
	}

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

	xsupgui_xml_common_convert_amp(conn_name, &temp);
	if (xmlNewChild(t, NULL, "Name", temp) == NULL)
	{
		done = IPC_ERROR_CANT_CREATE_REQUEST;
		free(temp);
		goto finish_get_connection;
	}
	free(temp);

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

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

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

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

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

	if (xsupconfig_defaults_create_connection(&newc) != 0)
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		goto finish_get_connection;
	}

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

	(*conn_config) = newc;

finish_get_connection:
	xmlFreeDoc(doc);
	xmlFreeDoc(retdoc);

	return done;
}

/**
 * \brief Get the "<Trusted_Server>" block for the single named interface.
 *
 * @param[in] servname   The name of the server that we want to get the 
 *                       configuration block for.
 * @param[out] int_config   A pointer to a buffer that will return a text version
 *                          of the requested interface in the supplicant's memory.
 *
 * \retval REQUEST_SUCCESS on success
 * \retval REQUEST_TIMEOUT on timeout
 * \retval >299 on failure
 **/
int xsupgui_request_get_trusted_server_config(char *servname, config_trusted_server **ts_config)
{
	xmlDocPtr doc = NULL;
	xmlDocPtr retdoc = NULL;
	xmlNodePtr n = NULL, t = NULL;
	int done = REQUEST_SUCCESS;
	void *temp = NULL, *temp2 = NULL;
	struct config_trusted_server *news = NULL;
	int err = 0;
	
	if ((servname == NULL) || (ts_config == NULL)) return IPC_ERROR_INVALID_PARAMETERS;

	(*ts_config) = 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_ts;
	}

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

	xsupgui_xml_common_convert_amp(servname, &temp);
	if (xmlNewChild(t, NULL, "Name", temp) == NULL)
	{
		done = IPC_ERROR_CANT_CREATE_REQUEST;
		free(temp);
		goto finish_get_ts;
	}
	free(temp);

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

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

	// We now have an XML document that contains the configuration information we want.
	n = xmlDocGetRootElement(retdoc);
	if (n == NULL)
	{
		done = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
		goto finish_get_ts;
	}

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

	// The temp/temp2 stuff below needs a little explaining.  Because of the way the config parser works, 
	// when you request a parse, you pass in the structure to the parent, and it returns the newly created
	// child node.   So, when we make the call to xsupconfig_parse, we need to pass in a 
	// struct config_trusted_servers, but the result will be a struct config_trusted_server.  So, we need
	// to create a temp variable that is the size of "struct config_trusted_servers", and save it's 
	// location, so that we can free it when we are done with xsupconfig_parse().  This is because the
	// value coming back will point to something different.  (If we don't track it, we will leak memory.)

	temp = malloc(sizeof(struct config_trusted_servers));
	if (temp == NULL)
	{
		done = REQUEST_FAILURE;
		goto finish_get_ts;
	}

	memset(temp, 0x00, sizeof(struct config_trusted_servers));
	temp2 = temp;

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

	free(temp);

	(*ts_config) = temp2;

finish_get_ts:
	xmlFreeDoc(doc);
	xmlFreeDoc(retdoc);

	return done;
}

/**
 * \brief Get the "<Interface>" block for a single named interface.
 * 
 * \note The caller is expected to free the memory returned by **int_config.
 *
 * @param[in] intname   The name of the interface that we want to get the 
 *                      configuration block for.
 * @param[out] int_config   A pointer to a buffer that will return a text version
 *                          of the requested interface in the supplicant's memory.
 *
 * \retval REQUEST_SUCCESS on success
 * \retval REQUEST_TIMEOUT on timeout
 * \retval >299 on failure
 **/
int xsupgui_request_get_interface_config(char *intname, config_interfaces **int_config)
{
	xmlDocPtr doc = NULL;
	xmlDocPtr retdoc = NULL;
	xmlNodePtr n = NULL, t = NULL;
	int done = REQUEST_SUCCESS;
	void *temp = NULL, *temp2 = NULL;
	config_interfaces *newi = NULL;
	int err = 0;

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

	(*int_config) = 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_int;
	}

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

	xsupgui_xml_common_convert_amp(intname, &temp);
	if (xmlNewChild(t, NULL, "Description", temp) == NULL)
	{
		done = IPC_ERROR_CANT_CREATE_REQUEST;
		free(temp);
		goto finish_get_int;
	}
	free(temp);

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

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

	// We now have an XML document that contains the configuration information we want.
	n = xmlDocGetRootElement(retdoc);
	if (n == NULL)
	{
		done = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
		goto finish_get_int;
	}

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

	// The temp/temp2 stuff below needs a little explaining.  Because of the way the config parser works, 
	// when you request a parse, you pass in the structure to the parent, and it returns the newly created
	// child node.   So, when we make the call to xsupconfig_parse, we need to pass in a 
	// struct config_trusted_servers, but the result will be a struct config_trusted_server.  So, we need
	// to create a temp variable that is the size of "struct config_trusted_servers", and save it's 
	// location, so that we can free it when we are done with xsupconfig_parse().  This is because the
	// value coming back will point to something different.  (If we don't track it, we will leak memory.)

	temp = malloc(sizeof(config_interfaces));
	if (temp == NULL)
	{
		done = IPC_ERROR_CANT_ALLOCATE_MEMORY;
		goto finish_get_int;
	}

	memset(temp, 0x00, sizeof(config_interfaces));
	temp2 = temp;

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

	free(temp);

	(*int_config) = temp2;

finish_get_int:
	xmlFreeDoc(doc);
	xmlFreeDoc(retdoc);

	return done;
}

/**
 * \brief Set the connection configuration for a single connection.
 *
 * @param[in] conn_config   A pointer to a libxml2 version of the new connection 
 *                          configuration that we want to store in the 
 *                          supplicant's memory.
 *
 * \retval REQUEST_SUCCESS on success
 * \retval REQUEST_TIMEOUT on timeout
 * \retval >299 on failure
 **/
int xsupgui_request_set_connection_config(config_connection *conn_config)
{
  xmlDocPtr doc = NULL;
  xmlDocPtr retdoc = NULL;
  xmlNodePtr n = NULL, t = NULL;
  int done = REQUEST_SUCCESS;
  int err = 0;

  if (conn_config == 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_connection_config;
    }

  n = xmlNewChild(n, NULL, "Set_Connection_Config", NULL);
  if (n == NULL)
    {
      done = IPC_ERROR_CANT_CREATE_REQUEST;
      goto finish_set_connection_config;
    }

  t = xsupconfwrite_connection_create_tree(conn_config, TRUE);
  if (t == NULL)
  {
	  done = IPC_ERROR_CANT_CREATE_REQUEST;
	  goto finish_set_connection_config;
  }

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

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

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

	done = xsupgui_request_is_ack(retdoc); 

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

	return done;
}

⌨️ 快捷键说明

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