"Fossies" - the Fresh Open Source Software Archive

Member "gvm-libs-11.0.1/util/xmlutils.h" (12 May 2020, 4230 Bytes) of package /linux/misc/openvas/gvm-libs-11.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "xmlutils.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 11.0.0_vs_11.0.1.

    1 /* Copyright (C) 2009-2019 Greenbone Networks GmbH
    2  *
    3  * SPDX-License-Identifier: GPL-2.0-or-later
    4  *
    5  * This program is free software; you can redistribute it and/or
    6  * modify it under the terms of the GNU General Public License
    7  * as published by the Free Software Foundation; either version 2
    8  * of the License, or (at your option) any later version.
    9  *
   10  * This program is distributed in the hope that it will be useful,
   11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  * GNU General Public License for more details.
   14  *
   15  * You should have received a copy of the GNU General Public License
   16  * along with this program; if not, write to the Free Software
   17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   18  */
   19 
   20 /**
   21  * @file
   22  * @brief Headers for simple XML reader.
   23  */
   24 
   25 #ifndef _GVM_XMLUTILS_H
   26 #define _GVM_XMLUTILS_H
   27 
   28 #include "serverutils.h"
   29 
   30 #include <glib.h>
   31 #include <gnutls/gnutls.h>
   32 #include <stdio.h>
   33 
   34 /**
   35  * @brief XML context.
   36  *
   37  * This structure is used to pass data between XML event handlers and the
   38  * caller of the XML parser.
   39  */
   40 typedef struct
   41 {
   42   GSList *first;   ///< The very first entity.
   43   GSList *current; ///< The element currently being parsed.
   44   gboolean done;   ///< Flag which is true when the first element is closed.
   45 } context_data_t;
   46 
   47 void
   48 xml_handle_start_element (context_data_t *, const gchar *, const gchar **,
   49                           const gchar **);
   50 
   51 void
   52 xml_handle_end_element (context_data_t *, const gchar *);
   53 
   54 void
   55 xml_handle_text (context_data_t *, const gchar *, gsize);
   56 
   57 /**
   58  * @brief Entities.
   59  */
   60 typedef GSList *entities_t;
   61 
   62 /**
   63  * @brief XML element.
   64  */
   65 struct entity_s
   66 {
   67   char *name;             ///< Name.
   68   char *text;             ///< Text.
   69   GHashTable *attributes; ///< Attributes.
   70   entities_t entities;    ///< Children.
   71 };
   72 typedef struct entity_s *entity_t;
   73 
   74 /**
   75  * @brief Data for xml search functions.
   76  */
   77 typedef struct
   78 {
   79   int found;                   /**< Founded.*/
   80   int done;                    /**< Done. */
   81   gchar *find_element;         /**< Element to be find. */
   82   GHashTable *find_attributes; /**< Attributes to find. */
   83 } xml_search_data_t;
   84 
   85 entities_t next_entities (entities_t);
   86 
   87 entity_t first_entity (entities_t);
   88 
   89 entity_t
   90 add_entity (entities_t *, const char *, const char *);
   91 
   92 int compare_entities (entity_t, entity_t);
   93 
   94 entity_t
   95 entity_child (entity_t, const char *);
   96 
   97 const char *
   98 entity_attribute (entity_t, const char *);
   99 
  100 char *
  101 entity_name (entity_t entity);
  102 
  103 char *
  104 entity_text (entity_t entity);
  105 
  106 void free_entity (entity_t);
  107 
  108 void
  109 print_entity (FILE *, entity_t);
  110 
  111 void
  112 print_entity_format (entity_t, gpointer indentation);
  113 
  114 int
  115 try_read_entity_and_string (gnutls_session_t *, int, entity_t *, GString **);
  116 
  117 int
  118 read_entity_and_string (gnutls_session_t *, entity_t *, GString **);
  119 
  120 int
  121 read_entity_and_string_c (gvm_connection_t *, entity_t *, GString **);
  122 
  123 int
  124 read_entity_and_text (gnutls_session_t *, entity_t *, char **);
  125 
  126 int
  127 read_entity_and_text_c (gvm_connection_t *, entity_t *, char **);
  128 
  129 int
  130 try_read_entity (gnutls_session_t *, int, entity_t *);
  131 
  132 int
  133 try_read_entity_c (gvm_connection_t *, int, entity_t *);
  134 
  135 int
  136 read_entity (gnutls_session_t *, entity_t *);
  137 
  138 int
  139 read_entity_s (int, entity_t *);
  140 
  141 int
  142 read_entity_c (gvm_connection_t *, entity_t *);
  143 
  144 int
  145 read_string (gnutls_session_t *, GString **);
  146 
  147 int
  148 read_string_c (gvm_connection_t *, GString **);
  149 
  150 int
  151 parse_entity (const char *, entity_t *);
  152 
  153 void
  154 print_entity_to_string (entity_t entity, GString *string);
  155 
  156 int xml_count_entities (entities_t);
  157 
  158 void
  159 xml_string_append (GString *, const char *, ...);
  160 
  161 
  162 /* XML file utilities */
  163 
  164 int
  165 find_element_in_xml_file (gchar *, gchar *, GHashTable *);
  166 
  167 
  168 /* The new faster parser that uses libxml2. */
  169 
  170 typedef struct _xmlNode *element_t;
  171 
  172 int
  173 parse_element (const gchar *, element_t *);
  174 
  175 void
  176 element_free (element_t);
  177 
  178 const gchar *
  179 element_name (element_t);
  180 
  181 gchar *
  182 element_attribute (element_t, const gchar *);
  183 
  184 gchar *
  185 element_text (element_t);
  186 
  187 element_t
  188 element_child (element_t, const gchar *);
  189 
  190 element_t
  191 element_first_child (element_t);
  192 
  193 element_t
  194 element_next (element_t);
  195 
  196 #endif /* not _GVM_XMLUTILS_H */