Skip to content
Snippets Groups Projects
Commit cd96dfb1 authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci Committed by Danilo K. S. Yorinori
Browse files

client.c: Created read_xml_file() to read the XML data file


read_xml_file() creates xmlInventory string and copies the XML data file,
returning a pointer to it in success or NULL in case of error.

Signed-off-by: default avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
Acked-by: default avatarDiego Giovane Pasqualin <dgp06@c3sl.ufpr.br>
Acked-by: default avatarJosiney de Souza <josineys@c3sl.ufpr.br>
Acked-by: default avatarRicardo Tavares de Oliveira <rto07@c3sl.ufpr.br>
Signed-off-by: default avatarDanilo K. S. Yorinori <danilok@c3sl.ufpr.br>
parent 01a04588
No related branches found
No related tags found
No related merge requests found
......@@ -244,3 +244,57 @@ void availability(struct soap *soap, char *url, char *inep, char *macAddr)
exit(6);
}
}
/*----------------------------------------------------------------------------
* Summary: Read XML data file and return the xmlInventory string.
* Parameters:
* basedir String with directory path
* Return: String with xml data.
*/
char *read_xml_file(char *basedir)
{
FILE *xmlFile;
int aux;
int i = 0;
int tam = 1;
char filePath[strlen(basedir) + strlen(COLLECTDATAFILE) + 1];
char *xmlInventory = NULL;
/* Construct filePath */
strcpy(filePath, basedir);
strcat(filePath, COLLECTDATAFILE);
if (DEBUG)
{
printf("%s %s %s\n", basedir, COLLECTDATAFILE, filePath);
}
/* Open XML collect data file and check for errors */
xmlFile = fopen(filePath, "r");
if ( xmlFile == NULL )
{
fprintf(stderr, "Problem while trying to open the ");
fprintf(stderr, "collect_data.xml file.\n");
return NULL;
}
/* Read and copy from data file to string */
xmlInventory = (char *) malloc(sizeof(char));
while ( (aux = fgetc(xmlFile)) != EOF )
{
if ( tam <= i )
{
tam *= 2;
xmlInventory = (char *) realloc(xmlInventory, tam * sizeof(char));
}
if (xmlInventory == NULL)
{
fprintf(stderr, "Memory allocation error for xmlInventory.\n");
return NULL;
}
xmlInventory[i++] = aux;
}
/* Close file and return a pointer to "xmlInventory" */
fclose(xmlFile);
return xmlInventory;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment