diff options
Diffstat (limited to 'src/analysis')
| -rw-r--r-- | src/analysis/binary.c | 158 | ||||
| -rw-r--r-- | src/analysis/binary.h | 13 | 
2 files changed, 64 insertions, 107 deletions
| diff --git a/src/analysis/binary.c b/src/analysis/binary.c index d7d050b..c528e96 100644 --- a/src/analysis/binary.c +++ b/src/analysis/binary.c @@ -39,6 +39,7 @@  #include "line_comment.h"  #include "line_prologue.h"  #include "prototype.h" +#include "../common/extstr.h"  #include "../panel/log.h"  #include "../plugins/pglist.h" @@ -160,7 +161,8 @@ openida_binary *load_binary_file(const char *filename)  /******************************************************************************  *                                                                             * -*  Paramètres  : xpathObj = point de lecture de tous les éléments.            * +*  Paramètres  : context = contexte pour les recherches XPath.                * +*                path    = chemin d'accès au noeud XML à lire.                *  *                                                                             *  *  Description : Charge en mémoire le contenu d'un fichier à partir d'XML.    *  *                                                                             * @@ -170,20 +172,69 @@ openida_binary *load_binary_file(const char *filename)  *                                                                             *  ******************************************************************************/ -openida_binary *load_binary_file_from_xml(xmlXPathObjectPtr xpathObj) +openida_binary *g_binary_file_new_from_xml(xmlXPathContextPtr context, const char *path)  {      openida_binary *result;                 /* Adresse à retourner         */ +    size_t access_len;                      /* Taille d'un chemin interne  */ +    char *access;                           /* Chemin pour une sous-config.*/ +    char *filename;                         /* Chemin du binaire à charger */ -    int i; +    result = NULL; -    result = (openida_binary *)calloc(1, sizeof(openida_binary)); +    /* Chemin du fichier à retrouver */ + +    access_len = strlen(path) + strlen("/Filename") + 1; + +    access = calloc(access_len, sizeof(char)); +    snprintf(access, access_len, "%s/Filename", path); + +    filename = get_node_text_value(context, access); + +    free(access); + +    /* Chargement */ + +    if (filename != NULL) +    { +        result = load_binary_file(filename); +        free(filename); +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : binary  = élément binaire à traiter.                         * +*                xdoc    = structure XML en cours d'édition.                  * +*                context = contexte à utiliser pour les recherches.           * +*                path    = chemin d'accès réservé au binaire.                 * +*                                                                             * +*  Description : Ecrit une sauvegarde du binaire dans un fichier XML.         * +*                                                                             * +*  Retour      : true si l'opération a bien tourné, false sinon.              * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ -    for (i = 0; i < XPATH_OBJ_NODES_COUNT(xpathObj); i++) -        if (xmlStrEqual(NODE_FROM_PATH_OBJ(xpathObj, i)->name, BAD_CAST "Filename")) -            result->filename = qck_get_node_text_value(NODE_FROM_PATH_OBJ(xpathObj, i)); +bool g_openida_binary_save(const openida_binary *binary, xmlDocPtr xdoc, xmlXPathContextPtr context, const char *path) +{ +    bool result;                            /* Bilan à faire remonter      */ +    char *access;                           /* Chemin d'accès à un élément */ + +    result = true; + +    /* Nom du fichier associé */ +    access = strdup(path); +    access = stradd(access, "/Filename"); +    result &= add_content_to_node(xdoc, context, access, binary->filename); +    free(access);      return result; @@ -332,99 +383,6 @@ GRenderingLine *get_openida_binary_lines(const openida_binary *binary) -/****************************************************************************** -*                                                                             * -*  Paramètres  : xpathCtx = contexte à utiliser pour mener les parcours.      * -*                base     = première partie de l'expression XPath d'accès.    * -*                index    = indice de la élément dans la liste des voisins.   * -*                                                                             * -*  Description : Lit un élément binaire depuis un fichier XML.                * -*                                                                             * -*  Retour      : Représentation mise en place à libérer de la mémoire.        * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -openida_binary *read_openida_binary_from_xml(xmlXPathContextPtr xpathCtx, const char *base, unsigned int index) -{ -    openida_binary *result;                 /* Représentation à retourner  */ -    size_t expr_len;                        /* Taille d'une expression     */ -    char *expr;                             /* Chemin XPath reconstitué    */ -    xmlXPathObjectPtr xpathObj;             /* Cible d'une recherche       */ -    char *value;                            /* Type d'élément rencontré    */ -    size_t sub_expr_len;                    /* Taille d'une expression #2  */ -    char *sub_expr;                         /* Chemin XPath reconstitué #2 */ -    int i;                                  /* Boucle de parcours          */ - -    result = NULL; - -    /* S'occupe en premier lieu du niveau courant */ - -    expr_len = strlen(base) + strlen("/*[position()=") + strlen("4294967295") /* UINT_MAX */ + strlen("]") + 1; - -    expr = (char *)calloc(expr_len, sizeof(char)); -    snprintf(expr, expr_len, "%s/*[position()=%u]", base, index); - -    xpathObj = get_node_xpath_object(xpathCtx, expr); - -    value = qck_get_node_prop_value(NODE_FROM_PATH_OBJ(xpathObj, 0), "type"); - -    xmlXPathFreeObject(xpathObj); - -    if (value == NULL) goto robfx_err1; - -    /* Raffinement au second passage */ - -    sub_expr_len = expr_len + strlen("/*"); -    sub_expr = (char *)calloc(sub_expr_len, sizeof(char)); -    snprintf(sub_expr, sub_expr_len, "%s/*", expr); - -    xpathObj = get_node_xpath_object(xpathCtx, sub_expr); - -    if (strcmp(value, "file") == 0) result = load_binary_file_from_xml(xpathObj); - -    xmlXPathFreeObject(xpathObj); - -    free(sub_expr); - - robfx_err1: - -    free(expr); - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : binary = élément binaire à traiter.                          * -*                writer = rédacteur dédié à l'écriture.                       * -*                                                                             * -*  Description : Ecrit une sauvegarde du binaire dans un fichier XML.         * -*                                                                             * -*  Retour      : true si l'opération a bien tourné, false sinon.              * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bool write_openida_binary_to_xml(const openida_binary *binary, xmlTextWriterPtr writer) -{ -    bool result;                            /* Bilan à faire remonter      */ - -    result = open_xml_element(writer, "Binary"); - -    result &= write_xml_attribute(writer, "type", "file"); - -    result &= write_xml_element_with_content(writer, "Filename", "%s", binary->filename); - -    result &= close_xml_element(writer); - -    return result; - -} diff --git a/src/analysis/binary.h b/src/analysis/binary.h index 0c63738..cf47492 100644 --- a/src/analysis/binary.h +++ b/src/analysis/binary.h @@ -42,6 +42,12 @@ typedef struct _openida_binary openida_binary;  /* Charge en mémoire le contenu d'un fichier. */  openida_binary *load_binary_file(const char *); +/* Charge en mémoire le contenu d'un fichier à partir d'XML. */ +openida_binary *g_binary_file_new_from_xml(xmlXPathContextPtr, const char *); + +/* Ecrit une sauvegarde du binaire dans un fichier XML. */ +bool g_openida_binary_save(const openida_binary *, xmlDocPtr, xmlXPathContextPtr, const char *); +  /* Décharge de la mémoire le contenu d'un fichier. */  void unload_binary_file(openida_binary *); @@ -65,13 +71,6 @@ GRenderingLine *get_openida_binary_lines(const openida_binary *); -/* Lit un élément binaire depuis un fichier XML. */ -openida_binary *read_openida_binary_from_xml(xmlXPathContextPtr, const char *, unsigned int); - -/* Ecrit une sauvegarde du binaire dans un fichier. */ -bool write_openida_binary_to_xml(const openida_binary *, xmlTextWriterPtr); - - | 
