📄 xsupgui_request4.c
字号:
/**
* Licensed under a dual GPL/BSD license. (See LICENSE file for more info.)
*
* \file xsupgui_request4.c
*
* \author chris@open1x.org
*
* $Id: xsupgui_request4.c,v 1.1.2.24 2007/08/14 01:45:17 chessing Exp $
* $Date: 2007/08/14 01:45:17 $
**/
#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_profile.h"
#include "../libxsupconfig/xsupconfig_parse_connection.h"
#include "../libxsupconfig/xsupconfig_parse_trusted_servers.h"
#include "../libxsupconfig/xsupconfig_parse_devices.h"
#include "../libxsupconfwrite/xsupconfwrite_connection.h"
/**
* \brief Generic call to delete configuration settings.
*
* \warning This call should never be used by an outside program. (i.e. A program that
* links this library.)
*
* @param[in] deletefrom The command that we want to use to delete a block. As an example,
* if we wanted to delete something from the <Managed_Networks> block,
* this value would be set to "Delete_Managed_Network_Config".
* @param[in] searchtag The name of the XML tag that the supplicant will be using to identify
* the block to be deleted. Adding to the example above, we would need
* to set this value to OU in order to match the proper configuration
* data in the Managed_Network configuration structures.
* @param[in] searchitem The value that will be used with the searchtag to determine the
* exact configuration block that we should delete. So, if we wanted
* to delete a <Managed_Network> block with an <OU> of foo, we would
* set this value to foo.
*
* @param[in] force Should we force the deletion of the item. (That is, delete it even if it is still
* referenced somewhere else in the config.) This parameter can take three different
* values. TRUE, FALSE, and -1. The -1 means that this parameter isn't relevant to the
* request, and should be left out.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_TIMEOUT on timeout
* \retval >299 on error
**/
int xsupgui_request_delete_some_conf(char *deletefrom, char *searchtag, char *searchitem, int force)
{
xmlDocPtr doc = NULL;
xmlDocPtr retdoc = NULL;
xmlNodePtr n = NULL, t = NULL;
int done = REQUEST_SUCCESS;
int err = 0;
char *temp = NULL;
char tempstr[10];
if ((deletefrom == NULL) || (searchtag == NULL) || (searchitem == 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_delete_some_conf;
}
t = xmlNewChild(n, NULL, deletefrom, NULL);
if (t == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
goto finish_delete_some_conf;
}
xsupgui_xml_common_convert_amp(searchitem, &temp);
if (xmlNewChild(t, NULL, searchtag, temp) == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
free(temp);
goto finish_delete_some_conf;
}
free(temp);
if (force >= 0)
{
sprintf((char *)&tempstr, "%d", force);
if (xmlNewChild(t, NULL, "Force", tempstr) == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
goto finish_delete_some_conf;
}
}
err = xsupgui_request_send(doc, &retdoc);
if (err != REQUEST_SUCCESS)
{
done = err;
goto finish_delete_some_conf;
}
// Check if we got errors.
err = xsupgui_request_check_exceptions(retdoc);
if (err != 0)
{
done = err;
goto finish_delete_some_conf;
}
done = xsupgui_request_is_ack(retdoc);
finish_delete_some_conf:
xmlFreeDoc(doc);
xmlFreeDoc(retdoc);
return done;
}
/**
* \brief Free a string that was allocated by one of the request functions.
*
* @param[in] data A double dereferenced pointer to the memory that was allocated by
* one of the xsupgui_request_* functions.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_FAILURE on failure
**/
int xsupgui_request_free_str(char **data)
{
if ((*data) == NULL) return REQUEST_SUCCESS; // Nothing to do.
free((*data));
(*data) = NULL;
return REQUEST_SUCCESS;
}
/**
* \brief Free an int_enum that was allocated by one of the request functions.
*
* @param[in] data A double dereferenced pointer to the memory that was allocated by
* one of the xsupgui_request_* functions.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_FAILURE on failure
**/
int xsupgui_request_free_int_enum(int_enum **data)
{
int i;
int_enum *intenum;
intenum = (*data);
if (intenum == NULL) return REQUEST_SUCCESS; // Nothing to do.
i = 0;
while (intenum[i].name != NULL)
{
if (intenum[i].name != NULL) free(intenum[i].name);
if (intenum[i].desc != NULL) free(intenum[i].desc);
i++;
}
free((*data));
(*data) = NULL;
return REQUEST_SUCCESS;
}
/**
* \brief Free an int_config_enum that was allocated by one of the request functions.
*
* @param[in] data A double dereferenced pointer to the memory that was allocated by
* one of the xsupgui_request_* functions.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_FAILURE on failure
**/
int xsupgui_request_free_int_config_enum(int_config_enum **data)
{
int i;
int_config_enum *intenum;
intenum = (*data);
if (intenum == NULL) return REQUEST_SUCCESS; // Nothing to do.
i = 0;
while (intenum[i].desc != NULL)
{
if (intenum[i].desc != NULL) free(intenum[i].desc);
if (intenum[i].mac != NULL) free(intenum[i].mac);
i++;
}
free((*data));
(*data) = NULL;
return REQUEST_SUCCESS;
}
/**
* \brief Free a namedesc_enum that was allocated by one of the request functions.
*
* @param[in] data A double dereferenced pointer to the memory that was allocated by
* one of the xsupgui_request_* functions.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_FAILURE on failure
**/
int xsupgui_request_free_namedesc_enum(namedesc_enum **data)
{
int i;
namedesc_enum *ndenum;
ndenum = (*data);
if (ndenum == NULL) return REQUEST_SUCCESS; // Nothing to do.
i = 0;
while (ndenum[i].name != NULL)
{
if (ndenum[i].desc == NULL) free(ndenum[i].desc);
if (ndenum[i].name == NULL) free(ndenum[i].name);
i++;
}
free((*data));
(*data) = NULL;
return REQUEST_SUCCESS;
}
/**
* \brief Free a profile_enum that was allocated by one of the request functions.
*
* @param[in] data A double dereferenced pointer to the memory that was allocated by
* one of the xsupgui_request_* functions.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_FAILURE on failure
**/
int xsupgui_request_free_profile_enum(profile_enum **data)
{
int i;
profile_enum *penum;
penum = (*data);
if (penum == NULL) return REQUEST_SUCCESS;
i = 0;
while (penum[i].name != NULL)
{
if (penum[i].name != NULL) free(penum[i].name);
i++;
}
free((*data));
(*data) = NULL;
return REQUEST_SUCCESS;
}
/**
* \brief Free a conn_enum that was allocated by one of the request functions.
*
* @param[in] data A double dereferenced pointer to the memory that was allocated by
* one of the xsupgui_request_* functions.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_FAILURE on failure
**/
int xsupgui_request_free_conn_enum(conn_enum **data)
{
int i = 0;
conn_enum *cenum = NULL;
cenum = (*data);
if (cenum == NULL) return REQUEST_SUCCESS;
i = 0;
while (cenum[i].name != NULL)
{
if (cenum[i].dev_desc != NULL) free(cenum[i].dev_desc);
if (cenum[i].name != NULL) free(cenum[i].name);
if (cenum[i].ssid != NULL) free(cenum[i].ssid);
i++;
}
free((*data));
(*data) = NULL;
return REQUEST_SUCCESS;
}
/**
* \brief Free an eap_enum that was allocated by one of the request functions.
*
* @param[in] data A double dereferenced pointer to the memory that was allocated by
* one of the xsupgui_request_* functions.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_FAILURE on failure
**/
int xsupgui_request_free_eap_enum(eap_enum **data)
{
int i;
eap_enum *eenum;
eenum = (*data);
if (eenum == NULL) return REQUEST_SUCCESS; // Nothing to do.
i = 0;
while (eenum[i].name != NULL)
{
if (eenum[i].name != NULL) free(eenum[i].name);
i++;
}
free((*data));
(*data) = NULL;
return REQUEST_SUCCESS;
}
/**
* \brief Free an ipinfo_type struct that was allocated by one of the request functions.
*
* @param[in] data A double dereferenced pointer to the memory that was allocated by
* one of the xsupgui_request_* functions.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_FAILURE on failure
**/
int xsupgui_request_free_ip_info(ipinfo_type **data)
{
ipinfo_type *ipi;
ipi = (*data);
if (ipi == NULL) return REQUEST_SUCCESS;
if (ipi->dns1 != NULL) free(ipi->dns1);
if (ipi->dns2 != NULL) free(ipi->dns2);
if (ipi->dns3 != NULL) free(ipi->dns3);
if (ipi->netmask != NULL) free(ipi->netmask);
if (ipi->gateway != NULL) free(ipi->gateway);
if (ipi->ipaddr != NULL) free(ipi->ipaddr);
return REQUEST_SUCCESS;
}
/**
* \brief Request the entire "<Globals>" block from the configuration in the
* supplicant's memory.
*
* @param[out] globals_config A pointer to the buffer that will return a text
* version of the current globals block in memory.
*
* \warning In extremely weird circumstances this call could return REQUEST_SUCCESS, but the
* value of globals is NULL. The caller should check for this!!!!
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_TIMEOUT on timeout
* \retval >299 on failure
**/
int xsupgui_request_get_globals_config(config_globals **globals)
{
xmlDocPtr doc = NULL;
xmlDocPtr retdoc = NULL;
xmlNodePtr n = NULL, t = NULL;
int done = REQUEST_SUCCESS;
struct config_globals *newg = NULL;
int err = 0;
if (globals == NULL) return IPC_ERROR_INVALID_PARAMETERS;
(*globals) = 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_globals;
}
t = xmlNewChild(n, NULL, "Get_Globals_Config", NULL);
if (t == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
goto finish_get_globals;
}
err = xsupgui_request_send(doc, &retdoc);
if (err != REQUEST_SUCCESS)
{
done = err;
goto finish_get_globals;
}
err = xsupgui_request_check_exceptions(retdoc);
if (err != REQUEST_SUCCESS)
{
done = err;
goto finish_get_globals;
}
// 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_globals;
}
n = xsupgui_request_find_node(n->children, "Globals_Config");
if (n == NULL)
{
done = IPC_ERROR_BAD_RESPONSE;
goto finish_get_globals;
}
// Otherwise, we need to parse the data that is in the child node.
xsupconfig_parse(n->children, global_and_network, &newg);
if (newg == NULL)
{
done = IPC_ERROR_BAD_RESPONSE_DATA;
goto finish_get_globals;
}
(*globals) = newg;
finish_get_globals:
xmlFreeDoc(doc);
xmlFreeDoc(retdoc);
return done;
}
/**
* \brief Get the "<Profile>" block for a single named profile.
*
* @param[in] prof_name The name of the profile that we want to get the configuration
* block for.
* @param[out] prof_config A pointer to a buffer that will return a text version
* of the requested profile in the supplicant's memory.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_TIMEOUT on timeout
* \retval >299 on failure
**/
int xsupgui_request_get_profile_config(char *prof_name, config_profiles **prof_config)
{
xmlDocPtr doc = NULL;
xmlDocPtr retdoc = NULL;
xmlNodePtr n = NULL, t = NULL;
int done = REQUEST_SUCCESS;
struct config_profiles *newp = NULL;
int err = 0;
char *temp = NULL;
if ((prof_name == NULL) || (prof_config == NULL)) return IPC_ERROR_INVALID_PARAMETERS;
(*prof_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_profile;
}
t = xmlNewChild(n, NULL, "Get_Profile_Config", NULL);
if (t == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -