OpenVAS Libraries  9.0.1
Data Structures | Typedefs | Functions
xml.h File Reference
#include <glib.h>
#include <gnutls/gnutls.h>
#include <stdio.h>
#include "../misc/openvas_server.h"

Go to the source code of this file.

Data Structures

struct  entity_s
 XML element. More...
 
struct  xml_search_data_t
 Data for xml search functions. More...
 

Typedefs

typedef GSList * entities_t
 
typedef struct entity_sentity_t
 

Functions

entities_t next_entities (entities_t)
 Return all the entities from an entities_t after the first. More...
 
entity_t first_entity (entities_t)
 Return the first entity from an entities_t. More...
 
entity_t add_entity (entities_t *, const char *, const char *)
 Add an XML entity to a tree of entities. More...
 
int compare_entities (entity_t, entity_t)
 Compare two XML entity. More...
 
entity_t entity_child (entity_t, const char *)
 Get a child of an entity. More...
 
const char * entity_attribute (entity_t, const char *)
 Get an attribute of an entity. More...
 
char * entity_name (entity_t entity)
 Get the name an entity. More...
 
char * entity_text (entity_t entity)
 Get the text an entity. More...
 
void free_entity (entity_t)
 Free an entity, recursively. More...
 
void print_entity (FILE *, entity_t)
 Print an XML entity. More...
 
void print_entity_format (entity_t, gpointer indentation)
 Print an XML entity to stdout, recusively printing its children. More...
 
int try_read_entity_and_string (gnutls_session_t *, int, entity_t *, GString **)
 Try read an XML entity tree from the manager. More...
 
int try_read_entity_and_string_c (openvas_connection_t *, int, entity_t *, GString **)
 Try read an XML entity tree from the manager. More...
 
int read_entity_and_string (gnutls_session_t *, entity_t *, GString **)
 Try read an XML entity tree from the manager. More...
 
int read_entity_and_string_c (openvas_connection_t *, entity_t *, GString **)
 Try read an XML entity tree from the manager. More...
 
int read_entity_and_text (gnutls_session_t *, entity_t *, char **)
 Read an XML entity tree from the manager. More...
 
int read_entity_and_text_c (openvas_connection_t *, entity_t *, char **)
 Read an XML entity tree from the manager. More...
 
int try_read_entity (gnutls_session_t *, int, entity_t *)
 Try read an XML entity tree from the manager. More...
 
int try_read_entity_c (openvas_connection_t *, int, entity_t *)
 Try read an XML entity tree from the manager. More...
 
int read_entity (gnutls_session_t *, entity_t *)
 Read an XML entity tree from the manager. More...
 
int read_entity_c (openvas_connection_t *, entity_t *)
 Read an XML entity tree from the manager. More...
 
int read_string (gnutls_session_t *, GString **)
 Read entity and text. Free the entity immediately. More...
 
int read_string_c (openvas_connection_t *, GString **)
 Read entity and text. Free the entity immediately. More...
 
int parse_entity (const char *, entity_t *)
 Read an XML entity tree from a string. More...
 
void print_entity_to_string (entity_t entity, GString *string)
 Print an XML entity tree to a GString, appending it if string is not. More...
 
int xml_count_entities (entities_t)
 Count the number of entities. More...
 
void xml_string_append (GString *, const char *,...)
 Append formatted escaped XML to a string. More...
 
int find_element_in_xml_file (gchar *, gchar *, GHashTable *)
 Tests if an XML file contains an element with given attributes. More...
 

Typedef Documentation

◆ entities_t

typedef GSList* entities_t

◆ entity_t

typedef struct entity_s* entity_t

Function Documentation

◆ add_entity()

entity_t add_entity ( entities_t entities,
const char *  name,
const char *  text 
)

Add an XML entity to a tree of entities.

Parameters
[in]entitiesThe tree of entities
[in]nameName of the entity. Copied, copy is freed by free_entity.
[in]textText of the entity. Copied, copy is freed by free_entity.
Returns
The new entity.

◆ compare_entities()

int compare_entities ( entity_t  entity1,
entity_t  entity2 
)

Compare two XML entity.

Parameters
[in]entity1First entity.
[in]entity2First entity.
Returns
0 if equal, 1 otherwise.

◆ entity_attribute()

const char* entity_attribute ( entity_t  entity,
const char *  name 
)

Get an attribute of an entity.

Parameters
[in]entityEntity.
[in]nameName of the attribute.
Returns
Attribute if found, else NULL.

◆ entity_child()

entity_t entity_child ( entity_t  entity,
const char *  name 
)

Get a child of an entity.

Parameters
[in]entityEntity.
[in]nameName of the child.
Returns
Entity if found, else NULL.

◆ entity_name()

char* entity_name ( entity_t  entity)

Get the name an entity.

Parameters
[in]entityEntity.
Returns
Entity name, which is freed by free_entity.

◆ entity_text()

char* entity_text ( entity_t  entity)

Get the text an entity.

Parameters
[in]entityEntity.
Returns
Entity text, which is freed by free_entity.

◆ find_element_in_xml_file()

int find_element_in_xml_file ( gchar *  file_path,
gchar *  find_element,
GHashTable *  find_attributes 
)

Tests if an XML file contains an element with given attributes.

Parameters
[in]file_pathPath of the XML file.
[in]find_elementName of the element to find.
[in]find_attributesGHashTable of attributes to find.
Returns
1 if element was found, 0 if not.

◆ first_entity()

entity_t first_entity ( entities_t  entities)

Return the first entity from an entities_t.

Parameters
[in]entitiesThe list of entities.
Returns
The first entity.

◆ free_entity()

void free_entity ( entity_t  entity)

Free an entity, recursively.

Parameters
[in]entityThe entity, can be NULL.

◆ next_entities()

entities_t next_entities ( entities_t  entities)

Return all the entities from an entities_t after the first.

Parameters
[in]entitiesThe list of entities.
Returns
All the entities that follow the first.

◆ parse_entity()

int parse_entity ( const char *  string,
entity_t entity 
)

Read an XML entity tree from a string.

Parameters
[in]stringInput string.
[out]entityPointer to an entity tree.
Returns
0 success, -1 read error, -2 parse error, -3 XML ended prematurely.

◆ print_entity()

void print_entity ( FILE *  stream,
entity_t  entity 
)

Print an XML entity.

Parameters
[in]entityThe entity.
[in]streamThe stream to which to print.

◆ print_entity_format()

void print_entity_format ( entity_t  entity,
gpointer  indent 
)

Print an XML entity to stdout, recusively printing its children.

Does very basic indentation for pretty printing.

This function is used as the (callback) GFunc in g_slist_foreach.

Parameters
[in]entityThe entity.
[in]indentIndentation level, indentation width is 2 spaces. Use GINT_TO_POINTER to convert a integer value when passing this parameter.

◆ print_entity_to_string()

void print_entity_to_string ( entity_t  entity,
GString *  string 
)

Print an XML entity tree to a GString, appending it if string is not.

empty.

Parameters
[in]entityEntity tree to print to string.
[in,out]stringString to write to (will be created if NULL).

◆ read_entity()

int read_entity ( gnutls_session_t *  session,
entity_t entity 
)

Read an XML entity tree from the manager.

Parameters
[in]sessionPointer to GNUTLS session.
[out]entityPointer to an entity tree.
Returns
0 success, -1 read error, -2 parse error, -3 end of file.

◆ read_entity_and_string()

int read_entity_and_string ( gnutls_session_t *  session,
entity_t entity,
GString **  string_return 
)

Try read an XML entity tree from the manager.

Parameters
[in]sessionPointer to GNUTLS session.
[out]entityPointer to an entity tree.
[out]string_returnAn optional return location for the text read from the session. If NULL then it simply remains NULL. If a pointer to NULL then it points to a freshly allocated GString on successful return. Otherwise it points to an existing GString onto which the text is appended.
Returns
0 success, -1 read error, -2 parse error, -3 end of file.

◆ read_entity_and_string_c()

int read_entity_and_string_c ( openvas_connection_t connection,
entity_t entity,
GString **  string_return 
)

Try read an XML entity tree from the manager.

Parameters
[in]connectionConnection.
[out]entityPointer to an entity tree.
[out]string_returnAn optional return location for the text read from the session. If NULL then it simply remains NULL. If a pointer to NULL then it points to a freshly allocated GString on successful return. Otherwise it points to an existing GString onto which the text is appended.
Returns
0 success, -1 read error, -2 parse error, -3 end of file.

◆ read_entity_and_text()

int read_entity_and_text ( gnutls_session_t *  session,
entity_t entity,
char **  text 
)

Read an XML entity tree from the manager.

Parameters
[in]sessionPointer to GNUTLS session.
[out]entityPointer to an entity tree.
[out]textA pointer to a pointer, at which to store the address of a newly allocated string holding the text read from the session, if the text is required, else NULL.
Returns
0 success, -1 read error, -2 parse error, -3 end of file.

◆ read_entity_and_text_c()

int read_entity_and_text_c ( openvas_connection_t connection,
entity_t entity,
char **  text 
)

Read an XML entity tree from the manager.

Parameters
[in]connectionConnection.
[out]entityEntity tree.
[out]textA pointer to a pointer, at which to store the address of a newly allocated string holding the text read from the session, if the text is required, else NULL.
Returns
0 success, -1 read error, -2 parse error, -3 end of file.

◆ read_entity_c()

int read_entity_c ( openvas_connection_t connection,
entity_t entity 
)

Read an XML entity tree from the manager.

Parameters
[in]sessionPointer to GNUTLS session.
[out]entityPointer to an entity tree.
Returns
0 success, -1 read error, -2 parse error, -3 end of file.

◆ read_string()

int read_string ( gnutls_session_t *  session,
GString **  string 
)

Read entity and text. Free the entity immediately.

Parameters
[in]sessionPointer to GNUTLS session to read from.
[out]stringReturn location for the string.
Returns
0 success, -1 read error, -2 parse error, -3 end of file.

◆ read_string_c()

int read_string_c ( openvas_connection_t connection,
GString **  string 
)

Read entity and text. Free the entity immediately.

Parameters
[in]connectionConnection.
[out]stringReturn location for the string.
Returns
0 success, -1 read error, -2 parse error, -3 end of file.

◆ try_read_entity()

int try_read_entity ( gnutls_session_t *  session,
int  timeout,
entity_t entity 
)

Try read an XML entity tree from the manager.

Parameters
[in]sessionPointer to GNUTLS session.
[in]timeoutServer idle time before giving up, in seconds. 0 to wait forever.
[out]entityPointer to an entity tree.
Returns
0 success, -1 read error, -2 parse error, -3 end of file, -4 timeout.

◆ try_read_entity_and_string()

int try_read_entity_and_string ( gnutls_session_t *  session,
int  timeout,
entity_t entity,
GString **  string_return 
)

Try read an XML entity tree from the manager.

Parameters
[in]sessionPointer to GNUTLS session.
[in]timeoutServer idle time before giving up, in seconds. 0 to wait forever.
[out]entityPointer to an entity tree.
[out]stringAn optional return location for the text read from the session. If NULL then it simply remains NULL. If a pointer to NULL then it points to a freshly allocated GString on successful return. Otherwise it points to an existing GString onto which the text is appended.
Returns
0 success, -1 read error, -2 parse error, -3 end of file, -4 timeout.

◆ try_read_entity_and_string_c()

int try_read_entity_and_string_c ( openvas_connection_t connection,
int  timeout,
entity_t entity,
GString **  string_return 
)

Try read an XML entity tree from the manager.

Parameters
[in]connectionConnection.
[in]timeoutServer idle time before giving up, in seconds. 0 to wait forever.
[out]entityPointer to an entity tree.
[out]stringAn optional return location for the text read from the session. If NULL then it simply remains NULL. If a pointer to NULL then it points to a freshly allocated GString on successful return. Otherwise it points to an existing GString onto which the text is appended.
Returns
0 success, -1 read error, -2 parse error, -3 end of file, -4 timeout.

◆ try_read_entity_c()

int try_read_entity_c ( openvas_connection_t connection,
int  timeout,
entity_t entity 
)

Try read an XML entity tree from the manager.

Parameters
[in]connectionConnection.
[in]timeoutServer idle time before giving up, in seconds. 0 to wait forever.
[out]entityPointer to an entity tree.
Returns
0 success, -1 read error, -2 parse error, -3 end of file, -4 timeout.

◆ xml_count_entities()

int xml_count_entities ( entities_t  entities)

Count the number of entities.

Parameters
[in]entitiesEntities.
Returns
Number of entities.

◆ xml_string_append()

void xml_string_append ( GString *  xml,
const char *  format,
  ... 
)

Append formatted escaped XML to a string.

Parameters
[in]xmlXML string.
[in]formatFormat string.
[in]...Arguments for format string.
Returns
Result of XSL transformation.