struct tTransmission GetTransmission(char *id)
{
char *global_cfgfile; // fichier de configuration
tTransmission transmission; // transmission
char * attValue=NULL; // permet la récupération des attributs
// Génération de l'expression XPath pour noeud "get" en fonction de l'@id "trans"
char *XPathExp;
XPathExp = "//trans[@id=";
strcat(XPathExp, id);
strcat(XPathExp, "]/get");
//printf("%s\n",XPathExp);
int returnValue = 0;
// Initialisation et déclaration variables XML
xmlDoc *doc = NULL;
xmlXPathContextPtr xpathCtx = NULL;
xmlXPathObjectPtr xpathObj = NULL;
// Récupération chemin du fichier de config
if ((global_cfgfile = getenv(HOSADUPLIC_CFG)) == NULL) {
printf("error : HOSADUPLIC_CFG\n");
returnValue = -1;
goto end;
}
// chargement du fichier de configuration
doc = xmlReadFile(global_cfgfile, NULL, 0);
if (doc == NULL) {
printf("error: could not parse file %s\n", global_cfgfile);
returnValue = -1;
goto end;
}
// création du context XPath et évaluation de l'expression
xpathCtx = xmlXPathNewContext(doc);
xpathObj = xmlXPathEvalExpression(reinterpret_cast<xmlChar*>(XPathExp), xpathCtx);
attValue = (char *) xmlGetProp(xpathObj->nodesetval->nodeTab[0],(xmlChar *) "type");
transmission.id = id;
transmission.source.type = attValue;
end:
// on libére et on nettoie
xmlXPathFreeObject(xpathObj);
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
xmlCleanupParser();
return transmission;
}
Partager