OpenVAS Libraries  4.0+rc3.SVN
Functions
accessrules.c File Reference

Implementation of API to handle Access Rules. More...

#include <stdio.h>
#include "accessrules.h"

Functions

accessrule_taccessrule_new (void)
 Create a new access rule structure filled with the given values.
void accessrule_free (accessrule_t *r)
 Free memory of a access rules structure.
rule_t accessrule_rule (const accessrule_t *r)
 Get the rule type.
gchar * accessrule_ip (const accessrule_t *r)
 Get the IP string.
gchar * accessrule_comment (const accessrule_t *r)
 Get the comment string.
int accessrule_set_oid (accessrule_t *r, const rule_t rule)
 Set the rule type of a Access Rule.
int accessrule_set_ip (accessrule_t *r, const gchar *ip)
 Set the IP of a Access Rule.
int accessrule_set_comment (accessrule_t *r, const gchar *comment)
 Set the comment of a Access Rule.
gchar * accessrule_as_xml (const accessrule_t *r)
 Create a XML representation of a Access Rule.
accessrules_taccessrules_new ()
 Make a collection of Access Rules.
void accessrules_free (accessrules_t *rules)
 Free a collection of Access Rules.
guint accessrules_size (accessrules_t *rules)
 Get the size of a collection of Access Rules.
void accessrules_add (accessrules_t *rules, accessrule_t *r)
 Add an Access Rule to a collection of Access Rules.
accessrules_taccessrules_from_file (gchar *fn)
 Read a collection of Access Rules from a file.
guint accessrules_to_file (accessrules_t *rules, gchar *fn)
 Write the contents of a Access Rules collection to a file.

Detailed Description

Implementation of API to handle Access Rules.

This file contains all methods to handle Access Rule datasets (accessrule_t).

The module consequently uses glib datatypes and api for memory management etc.


Function Documentation

gchar* accessrule_as_xml ( const accessrule_t r)

Create a XML representation of a Access Rule.

Parameters:
rThe Access Rule structure.
Returns:
A newly allocated string with multi-line text. The string needs to be freed with g_free().
Todo:
Use g_markup_escape here
gchar* accessrule_comment ( const accessrule_t r)

Get the comment string.

Parameters:
rThe Access Rule structure of which the comment should be returned.
Returns:
The comment string. Don't free this.
void accessrule_free ( accessrule_t r)

Free memory of a access rules structure.

Parameters:
rThe structure to be freed.
gchar* accessrule_ip ( const accessrule_t r)

Get the IP string.

Parameters:
rThe Access Rule structure of which the IP should be returned.
Returns:
The IP string. Don't free this.
accessrule_t* accessrule_new ( void  )

Create a new access rule structure filled with the given values.

Returns:
NULL in case the memory could not be allocated. Else an empty accessrule structure which needs to be released using accessrule_free . The whole struct is initalized with 0's.
rule_t accessrule_rule ( const accessrule_t r)

Get the rule type.

Parameters:
rThe Access Rule structure of which the rule should be returned.
Returns:
The rule type.
int accessrule_set_comment ( accessrule_t r,
const gchar *  comment 
)

Set the comment of a Access Rule.

Parameters:
rThe Access Rule structure.
commentThe comment string to set. A copy will be created from this.
Returns:
0 for success. Anything else indicates an error.
int accessrule_set_ip ( accessrule_t r,
const gchar *  ip 
)

Set the IP of a Access Rule.

Parameters:
rThe Access Rule structure.
ipThe IP string to set. A copy will be created from this.
Returns:
0 for success. Anything else indicates an error.
int accessrule_set_oid ( accessrule_t r,
const rule_t  rule 
)

Set the rule type of a Access Rule.

Parameters:
rThe Access Rule structure.
ruleThe rule type to set. A copy will be created from this.
Returns:
0 for success. Anything else indicates an error.
void accessrules_add ( accessrules_t rules,
accessrule_t r 
)

Add an Access Rule to a collection of Access Rules.

Parameters:
rulesThe collection of Access Rules (must have ip set).
void accessrules_free ( accessrules_t rules)

Free a collection of Access Rules.

Parameters:
rulesThe collection of Access Rules.
accessrules_t* accessrules_from_file ( gchar *  fn)

Read a collection of Access Rules from a file.

Parameters:
fnThe filename from which to read.
Returns:
NULL in case an error occured. Else a collection of access rules which might be empty e.g. if the format was incorrect.
Todo:
Create a access_rules_t* and pass as user data
Todo:
error checks, handling
guint accessrules_size ( accessrules_t rules)

Get the size of a collection of Access Rules.

Returns:
The number of entries in the collection.
guint accessrules_to_file ( accessrules_t rules,
gchar *  fn 
)

Write the contents of a Access Rules collection to a file.

Parameters:
rulesThe collection of Access Rules.
fnThe filename where to store the Access Rules.
Returns:
0 in case of success, other values mean a failure.