There are two ways to execute the request, depending on how you want to process the response.
The aciObjectExecuteToString function returns the server response as an unparsed data buffer:
char *szResponse = NULL; int nResponseLen = 0; char *szContentType = NULL; aciObjectExecuteToString(pConnection, pCommand, &szResponse, &nResponseLen, &szContentType); // For most actions, szResponse now holds the raw xml and szContentType will be "application/xml" // Process the xml in whatever way you wish now (e.g. third-party XML processing API)
// Remember to tidy up afterwards free(szResponse); free(szContentType);
The aciObjectExecute function returns a t_aciObject that holds a parsed representation of the XML, which you can manipulate by using the acio set of functions in the C IDOL SDK. For example if the XML returned was from the UserReadAgentList action and the following response was retrieved:
<?xml version="1.0" encoding="UTF-8" ?> <autnresponse> <action>USERREADAGENTLIST</action> <response>SUCCESS</response> <responsedata> <maxagents>5</maxagents> <numagents>2</numagents> <agent>Housing</agent> <agent>Rock climbing</agent> </responsedata> </autnresponse>
Then you can obtain the list of agent names for the user as follows:
t_aciObject *pResult = NULL;
char **szAgentNames = NULL;
aciObjectExecute(pConnection, pCommand, &pResult);
if (aciObjectCheckforSuccess(pResult))
{
// Successful request so find out how many agents this user has
t_aciObject* pNumAgent = NULL;
pNumAgent = acioFindFirstOccurrence(pResult, "numagents");
if(pNumAgent)
{
int nNumAgents = 0;
acioParamGetInt(pNumAgent, ACI_DATA_NODE_VALUE, &nNumAgents);
if(nNumAgents > 0)
{
// This user has agents, construct array to hold names and
// retrieve agent names from response
t_aciObject* pAgentName = NULL;
int nAgent = 0;
saAgentNames = (char**)malloc(sizeof(char*)*nNumAgents);
// Find first agent entry
pAgentName = acioFindFirstOccurrence(pResult, "agent");
while(pAgentName)
{
acioParamGetString(pAgentName, ACI_DATA_NODE_VALUE,
&saAgentNames[nAgent]);
// Move to next agent entry
pAgentName = aciObjectNextEntry(pAgentName);
nAgent++
}
}
}
}
// Remember to tidy up afterwards
aciObjectDestroy(&pResult);
Although it is imperative to free the memory that is associated with an ACI structure in C, you must not free the structure returned by the acioFindFirstOccurrence function.
|
|