/* OpenIDA - Outil d'analyse de fichiers binaires * configuration.c - éléments de configuration du programme * * Copyright (C) 2009 Cyrille Bagard * * This file is part of OpenIDA. * * OpenIDA is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * OpenIDA is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Foobar. If not, see . */ #include "configuration.h" #include #include #include #include "xml.h" #include "common/extstr.h" /* Paramètres de configuration */ struct _configuration { config_param *params; /* Paramètres à consulter */ unsigned int count; /* Quantité de ces paramètres */ char *filename; /* Fichier externe */ xmlDocPtr xdoc; /* Document XML de configurat° */ xmlXPathContextPtr context; /* Contexte de recherche XPath */ }; /****************************************************************************** * * * Paramètres : name = désignation de la configuration. * * params = tableau de paramètres à consulter / mettre à jour. * * count = taille du tableau en question. * * * * Description : Charge la configuration principale. * * * * Retour : Configuration prête à emploi. * * * * Remarques : - * * * ******************************************************************************/ configuration *load_configuration(const char *name, config_param *params, unsigned int count) { configuration *result; /* Structure à retourner */ char *home; /* Répertoire de l'utilisateur */ result = (configuration *)calloc(1, sizeof(configuration)); result->params = params; result->count = count; /* FIXME : créer le répertoire, et en XDG */ home = strdup(getenv("HOME") != NULL ? getenv("HOME") : ""); result->filename = stradd(home, "/.openida/"); result->filename = stradd(result->filename, name); result->filename = stradd(result->filename, ".xml"); if (!open_xml_file(result->filename, &result->xdoc, &result->context)) create_new_xml_file(&result->xdoc, &result->context); return result; } /****************************************************************************** * * * Paramètres : config = configuration à libérer de la mémoire. * * * * Description : Décharge la configuration principale. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ void unload_configuration(configuration *config) { unsigned int i; /* Boucle de parcours */ printf("Writing '%s'\n", config->filename); for (i = 0; i < config->count; i++) switch (1) { case 1: add_content_to_node(config->xdoc, config->context, config->params[i].path, config->params[i].cur.string); break; } save_xml_file(config->xdoc, config->filename); free(config); }