📄 xsupgui_request3.c
字号:
n = n->children;
t = xsupgui_request_find_node(n, "Device_Name");
if (t == NULL)
{
done = IPC_ERROR_BAD_RESPONSE;
goto request_get_devname_done;
}
t = xsupgui_request_find_node(t->children, "Interface");
if (t == NULL)
{
done = IPC_ERROR_BAD_RESPONSE;
goto request_get_devname_done;
}
(*device) = xmlNodeGetContent(t);
done = REQUEST_SUCCESS;
request_get_devname_done:
if (doc != NULL) xmlFreeDoc(doc);
if (retdoc != NULL) xmlFreeDoc(retdoc);
return done;
}
/**
* \brief Set the username and password for a given connection.
*
* @param[in] conn_name The name of the connection that we want to set the username and
* password for.
* @param[in] username The new username that will be applied to this connection. (May
* be NULL if the connection is a WPA-PSK connection.)
* @param[in] password The new password that will be applied to this connection.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_TIMEOUT on timeout
* \retval >299 on other error.
**/
int xsupgui_request_set_connection_upw(char *conn_name, char *username, char *password)
{
xmlDocPtr doc = NULL, retdoc = NULL;
xmlNodePtr n = NULL, t = NULL;
int err = 0;
int done = REQUEST_SUCCESS;
char *temp = NULL;
if (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_upw_done;
}
t = xmlNewChild(n, NULL, "Set_Connection_UPW", NULL);
if (t == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
goto request_set_upw_done;
}
xsupgui_xml_common_convert_amp(conn_name, &temp);
if (xmlNewChild(t, NULL, "Connection_Name", temp) == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
free(temp);
goto request_set_upw_done;
}
free(temp);
xsupgui_xml_common_convert_amp(username, &temp);
if (xmlNewChild(t, NULL, "Username", temp) == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
free(temp);
goto request_set_upw_done;
}
free(temp);
xsupgui_xml_common_convert_amp(password, &temp);
if (xmlNewChild(t, NULL, "Password", temp) == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
free(temp);
goto request_set_upw_done;
}
free(temp);
err = xsupgui_request_send(doc, &retdoc);
if (err != REQUEST_SUCCESS)
{
done = err;
goto request_set_upw_done;
}
// 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_upw_done;
}
n = xmlDocGetRootElement(retdoc);
if (n == NULL)
{
done = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
goto request_set_upw_done;
}
// 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;
n = xsupgui_request_find_node(n, "Set_Connection_UPW_Result");
if (n != NULL)
{
done = IPC_ERROR_BAD_RESPONSE;
goto request_set_upw_done;
}
t = xsupgui_request_find_node(n, "ACK");
if (t != NULL)
{
done = IPC_ERROR_NOT_ACK;
goto request_set_upw_done;
}
done = REQUEST_SUCCESS;
request_set_upw_done:
if (doc != NULL) xmlFreeDoc(doc);
if (retdoc != NULL) xmlFreeDoc(retdoc);
return done;
}
/**
* \brief Request that the supplicant return it's currently known profiles.
*
* @param[out] profs An array of data containing the name and type of each
* profile that is currently in memory. This list will be
* terminated by all members being NULL, or 0.
*
* \retval REQUEST_SUCCESS The supplicant's response contains a valid set of profiles,
* and the data in "profs" is valid.
* \retval REQUEST_TIMEOUT on timeout
* \retval >299 An error occurred.
**/
int xsupgui_request_enum_profiles(profile_enum **profs)
{
xmlDocPtr doc = NULL;
xmlDocPtr retdoc = NULL;
xmlNodePtr n = NULL, t = NULL;
xmlChar *content = NULL;
int done = REQUEST_SUCCESS;
int numprofs = 0, i = 0, err = 0;
profile_enum *myprofs = NULL;
if (profs == NULL) return IPC_ERROR_INVALID_PARAMETERS;
(*profs) = 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_profiles;
}
if (xmlNewChild(n, NULL, "Enum_Profiles", NULL) == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
goto finish_enum_profiles;
}
err = xsupgui_request_send(doc, &retdoc);
if (err != REQUEST_SUCCESS)
{
done = err;
goto finish_enum_profiles;
}
// 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_profiles;
}
n = xmlDocGetRootElement(retdoc);
if (n == NULL)
{
done = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
goto finish_enum_profiles;
}
// 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, "Profiles_List");
if (n == NULL)
{
done = IPC_ERROR_BAD_RESPONSE;
goto finish_enum_profiles;
}
t = xsupgui_request_find_node(n->children, "Number_Of_Profiles");
if (t == NULL)
{
done = IPC_ERROR_BAD_RESPONSE_DATA;
goto finish_enum_profiles;
}
content = xmlNodeGetContent(t);
if ((content == NULL) || (strlen(content) == 0))
{
done = IPC_ERROR_BAD_RESPONSE_DATA;
goto finish_enum_profiles;
}
numprofs = atoi(content);
if (content != NULL) free(content);
// Allocate memory for our return structure.
myprofs = malloc(sizeof(profile_enum)*(numprofs+1));
if (myprofs == NULL)
{
done = IPC_ERROR_CANT_ALLOCATE_MEMORY;
goto finish_enum_profiles;
}
// Clear the memory.
memset(myprofs, 0x00, (sizeof(profile_enum)*(numprofs+1)));
n = n->children;
for (i=0; i <numprofs; i++)
{
n = xsupgui_request_find_node(n, "Profile");
if (n == NULL)
{
if (myprofs != NULL) free(myprofs);
done = IPC_ERROR_BAD_RESPONSE_DATA;
goto finish_enum_profiles;
}
t = xsupgui_request_find_node(n->children, "Profile_Name");
if (t == NULL)
{
if (myprofs != NULL) free(myprofs);
done = IPC_ERROR_BAD_RESPONSE_DATA;
goto finish_enum_profiles;
}
myprofs[i].name = xmlNodeGetContent(t);
n = n->next;
}
(*profs) = myprofs;
done = REQUEST_SUCCESS;
finish_enum_profiles:
if (doc) xmlFreeDoc(doc);
if (retdoc) xmlFreeDoc(retdoc);
return done;
}
/**
* \brief See if the character array passed in is a valid XML ACK document.
*
* @param[in] indoc The character array that makes up an XML document to
* check for an ACK message.
* @param[in] insize The size of the character array that makes up the
* XML document.
*
* \retval REQUEST_SUCCESS The XML document contains an ACK.
* \retval REQUEST_FAILURE The XML document does not contain an ACK.
* \retval >299 An error occurred trying to check the document.
**/
int xsupgui_request_is_ack(xmlDocPtr indoc)
{
xmlNodePtr t;
int retval = REQUEST_SUCCESS;
if (indoc == NULL) return IPC_ERROR_NULL_DOCUMENT;
t = xmlDocGetRootElement(indoc);
if (t == NULL)
{
retval = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
goto is_ack_done;
}
t = xsupgui_request_find_node(t->children, "ACK");
if (t == NULL)
{
retval = REQUEST_FAILURE;
goto is_ack_done;
}
is_ack_done:
return retval;
}
/**
* \brief Build the XML document that requests that a socket be turned in
* to an event only socket.
*
* @param[out] request A character array that contains a text representation
* of the XML document to send to the backend supplicant.
* It is up to the caller to free the memory when the
* they are finished with the request.
* @param[out] requestsize The length of the character array that makes up
* the request.
*
* \retval REQUEST_SUCCESS The data in request, and requestsize are valid, and
* can be used to request the socket change.
* \retval REQUEST_FAILURE An error occurred creating the XML document.
* \retval >299 An error occurred attempting to set the connection type.
**/
int xsupgui_request_set_as_event(char **request, int *requestsize)
{
xmlDocPtr outdoc;
xmlNodePtr n;
int done = REQUEST_SUCCESS;
if ((request == NULL) || (requestsize == NULL))
return IPC_ERROR_INVALID_PARAMETERS;
outdoc = xsupgui_xml_common_build_msg();
if (outdoc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;
n = xmlDocGetRootElement(outdoc);
if (n == NULL)
{
done = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
goto set_as_event_done;
}
n = xmlNewChild(n, NULL, "Change_Socket_Type", NULL);
if (n == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
goto set_as_event_done;
}
n = xmlNewChild(n, NULL, "Socket_Event_Only", NULL);
if (n == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
goto set_as_event_done;
}
xmlDocDumpFormatMemory(outdoc, request, requestsize, 0);
set_as_event_done:
if (outdoc != NULL) xmlFreeDoc(outdoc);
return done;
}
/**
* \brief Request the OS specific device description given a device name from the configuration
* file.
*
* @param[in] device The OS specific device name that maps to the description from
* the configuration file.
* @param[out] dev_desc The description that is from the configuration file.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_TIMEOUT on timeout
* \retval >299 on other error.
**/
int xsupgui_request_get_devdesc(char *device, char **dev_desc)
{
xmlDocPtr doc = NULL, retdoc = NULL;
xmlNodePtr n = NULL, t = NULL;
int err = 0;
int done = REQUEST_SUCCESS;
char *temp = NULL;
if ((dev_desc == NULL) || (device == NULL)) return IPC_ERROR_INVALID_PARAMETERS;
(*dev_desc) = 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 request_get_devname_done;
}
t = xmlNewChild(n, NULL, "Get_Device_Description", NULL);
if (t == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
goto request_get_devname_done;
}
xsupgui_xml_common_convert_amp(device, &temp);
if (xmlNewChild(t, NULL, "Interface", temp) == NULL)
{
done = IPC_ERROR_UNSPEC_REQ_FAILURE;
free(temp);
goto request_get_devname_done;
}
free(temp);
err = xsupgui_request_send(doc, &retdoc);
if (err != REQUEST_SUCCESS)
{
done = err;
goto request_get_devname_done;
}
// 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_devname_done;
}
n = xmlDocGetRootElement(retdoc);
if (n == NULL)
{
done = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
goto request_get_devname_done;
}
// 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;
t = xsupgui_request_find_node(n, "Device_Description");
if (t == NULL)
{
done = IPC_ERROR_BAD_RESPONSE;
goto request_get_devname_done;
}
t = xsupgui_request_find_node(t->children, "Description");
if (t == NULL)
{
done = IPC_ERROR_BAD_RESPONSE;
goto request_get_devname_done;
}
(*dev_desc) = xmlNodeGetContent(t);
done = REQUEST_SUCCESS;
request_get_devname_done:
if (doc != NULL) xmlFreeDoc(doc);
if (retdoc != NULL) xmlFreeDoc(retdoc);
return done;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -