/home/pvrabec/openscap/openscap-0.5.6/src/common/util.h File Reference

Common openscap utilities. More...

#include <stdbool.h>
#include <assert.h>
#include "public/oscap.h"
#include "public/alloc.h"

Go to the source code of this file.

Data Structures

struct  oscap_string_map
 Define mapping between symbolic constant and its string representation. More...

Defines

#define __attribute__nonnull__(x)   assert((x) != NULL)
#define OSCAP_HIDDEN_START   _Pragma("GCC visibility push(hidden)")
#define OSCAP_HIDDEN_END   _Pragma("GCC visibility pop")
#define OSCAP_GENERIC_GETTER_CONV(RTYPE, CONV, SNAME, MNAME, MEXP)   RTYPE SNAME##_get_##MNAME(const struct SNAME* item) { return (CONV(item->MEXP)); }
 Generate a getter function with an optional conversion.
#define OSCAP_GENERIC_GETTER(RTYPE, SNAME, MNAME, MEXP)   OSCAP_GENERIC_GETTER_CONV(RTYPE,,SNAME,MNAME,MEXP)
 Generate a getter function.
#define OSCAP_GENERIC_GETTER_FORCE(RTYPE, SNAME, MNAME, MEXP)   OSCAP_GENERIC_GETTER_CONV(RTYPE,(RTYPE),SNAME,MNAME,MEXP)
 Generate a getter function with an explicit conversion to the target data type.
#define OSCAP_GETTER_FORCE(RTYPE, SNAME, MNAME)   OSCAP_GENERIC_GETTER_FORCE(RTYPE,SNAME,MNAME,MNAME)
 Generate a getter function with an explicit conversion to the target data type.
#define OSCAP_GETTER(RTYPE, SNAME, MNAME)   OSCAP_GENERIC_GETTER(RTYPE,SNAME,MNAME,MNAME)
 Generate a getter function.
#define ITERATOR_CAST(x)   ((struct oscap_iterator*)(x))
#define OSCAP_ITERATOR(n)   struct n##_iterator*
#define OSCAP_ITERATOR_FWD(n)   struct n##_iterator;
#define OSCAP_ITERATOR_HAS_MORE(n)   bool n##_iterator_has_more(OSCAP_ITERATOR(n) it) { return oscap_iterator_has_more(ITERATOR_CAST(it)); }
#define OSCAP_ITERATOR_NEXT(t, n)   t n##_iterator_next(OSCAP_ITERATOR(n) it) { return oscap_iterator_next(ITERATOR_CAST(it)); }
#define OSCAP_ITERATOR_FREE(n)   void n##_iterator_free(OSCAP_ITERATOR(n) it) { oscap_iterator_free(ITERATOR_CAST(it)); }
#define OSCAP_ITERATOR_DETACH(t, n)   t n##_iterator_detach(OSCAP_ITERATOR(n) it) { return oscap_iterator_detach(ITERATOR_CAST(it)); }
#define OSCAP_ITERATOR_GEN_T(t, n)   OSCAP_ITERATOR_FWD(n) OSCAP_ITERATOR_HAS_MORE(n) OSCAP_ITERATOR_NEXT(t,n) OSCAP_ITERATOR_FREE(n)
#define OSCAP_ITERATOR_GEN(n)   OSCAP_ITERATOR_GEN_T(struct n*,n)
#define OSCAP_ITERATOR_REMOVE_T(t, n, destructor)   void n##_iterator_remove(OSCAP_ITERATOR(n) it) { destructor(oscap_iterator_detach(ITERATOR_CAST(it))); }
#define OSCAP_ITERATOR_REMOVE(n, destructor)   OSCAP_ITERATOR_REMOVE_T(struct n*,n,destructor)
#define OSCAP_ITERATOR_REMOVE_F(n)   OSCAP_ITERATOR_REMOVE(n, n##_free)
#define OSCAP_IGETTER_CONV(ITYPE, SNAME, MNAME, CONV)
 Generate an iterator getter function.
#define OSCAP_IGETTER(ITYPE, SNAME, MNAME)   OSCAP_IGETTER_CONV(ITYPE,SNAME,MNAME,)
 Generate an iterator getter function.
#define OSCAP_IGETTER_GEN(ITYPE, SNAME, MNAME)   OSCAP_IGETTER(ITYPE,SNAME,MNAME) OSCAP_ITERATOR_GEN(ITYPE)
 Generate an iterator and its getter.
#define OSCAP_HGETTER_EXP(RTYPE, SNAME, MNAME, MEXP)
 Generete a geter function from a hash table.
#define OSCAP_HGETTER(RTYPE, SNAME, MNAME)   OSCAP_HGETTER_EXP(RTYPE,SNAME,MNAME,MNAME)
 Generete a geter function from a hash table.
#define OSCAP_HGETTER_STRUCT(RTYPE, SNAME, MNAME)   OSCAP_HGETTER_EXP(struct RTYPE*,SNAME,MNAME,MNAME)
 Generete a geter function from a hash table.
#define OSCAP_SETTER_HEADER(SNAME, MTYPE, MNAME)   bool SNAME##_set_##MNAME(struct SNAME *obj, MTYPE item)
#define OSCAP_SETTER_GENERIC_CHECK(SNAME, MTYPE, MNAME, CHECK, DELETER, ASSIGNER)
 Generete a setter function with a check.
#define OSCAP_SETTER_GENERIC(SNAME, MTYPE, MNAME, DELETER, ASSIGNER)
 Generete a setter function without a check.
#define OSCAP_SETTER_GENERIC_NODELETE(SNAME, MTYPE, MNAME, ASSIGNER)
 Generete a setter function without a check that does not delete the previous value.
#define OSCAP_SETTER_SIMPLE(SNAME, MTYPE, MNAME)   OSCAP_SETTER_GENERIC_NODELETE(SNAME, MTYPE, MNAME, )
 Generete a setter function using a simple assignment.
#define OSCAP_SETTER_STRING(SNAME, MNAME)   OSCAP_SETTER_GENERIC(SNAME, const char *, MNAME, free, oscap_strdup)
 Assign a string value to a structure member.
#define OSCAP_ACCESSOR_STRING(SNAME, MNAME)   OSCAP_SETTER_STRING(SNAME, MNAME) OSCAP_GETTER(const char*, SNAME, MNAME)
 Define both, getter and setter for a string structure member.
#define OSCAP_ACCESSOR_SIMPLE(MTYPE, SNAME, MNAME)   OSCAP_SETTER_SIMPLE(SNAME, MTYPE, MNAME) OSCAP_GETTER(MTYPE, SNAME, MNAME)
 Define both, getter and setter for a structure member using simple get/set.
#define OSCAP_INSERTER(SNAME, FNAME, MTYPE, MNAME)
 Generate function to insert an item into a list.
#define OSCAP_IGETINS(ITYPE, SNAME, MNAME, FNAME)   OSCAP_IGETTER(ITYPE, SNAME, MNAME) OSCAP_INSERTER(SNAME, FNAME, ITYPE, MNAME)
#define OSCAP_IGETINS_GEN(ITYPE, SNAME, MNAME, FNAME)   OSCAP_IGETTER_GEN(ITYPE, SNAME, MNAME) OSCAP_INSERTER(SNAME, FNAME, ITYPE, MNAME)

Typedefs

typedef void(* oscap_destruct_func )(void *)
 Function pointer to an object destructor.
typedef void(* oscap_consumer_func )(void *, void *)
 Function pointer to an object consumer.

Functions

char * oscap_strdup (const char *str)
 Use strdup on string, if string is NULL, return NULL.
char * oscap_strsep (char **str, const char *delim)
 Use strsep on string We can't use strsep from string.h because of compatibility issues.

Detailed Description

Common openscap utilities.


Define Documentation

#define OSCAP_GENERIC_GETTER ( RTYPE,
SNAME,
MNAME,
MEXP   )     OSCAP_GENERIC_GETTER_CONV(RTYPE,,SNAME,MNAME,MEXP)

Generate a getter function.

Parameters:
RTYPE return type
SNAME name of the structure of which we are getting a member
MNAME member name affects how the resultant function will be called
MEXP expression to get the member
See also:
OSCAP_GENERIC_GETTER_CONV
#define OSCAP_GENERIC_GETTER_CONV ( RTYPE,
CONV,
SNAME,
MNAME,
MEXP   )     RTYPE SNAME##_get_##MNAME(const struct SNAME* item) { return (CONV(item->MEXP)); }

Generate a getter function with an optional conversion.

Header of the generated function will look like this (substitute the capital letter sequences with the actual parametres):

 RTYPE SNAME_MNAME(const struct SNAME*); 
Parameters:
RTYPE return type
CONV conversion expression, i.e. either a type conversion of form '(type)' or an unary function identifier
SNAME name of the structure of which we are getting a member (without the struct keyword)
MNAME member name affects how the resultant function will be called
MEXP expression to get the member
#define OSCAP_GENERIC_GETTER_FORCE ( RTYPE,
SNAME,
MNAME,
MEXP   )     OSCAP_GENERIC_GETTER_CONV(RTYPE,(RTYPE),SNAME,MNAME,MEXP)

Generate a getter function with an explicit conversion to the target data type.

Parameters:
RTYPE return type
SNAME name of the structure of which we are getting a member
MNAME member name affects how the resultant function will be called
MEXP expression to get the member
See also:
OSCAP_GENERIC_GETTER_CONV
#define OSCAP_GETTER ( RTYPE,
SNAME,
MNAME   )     OSCAP_GENERIC_GETTER(RTYPE,SNAME,MNAME,MNAME)

Generate a getter function.

Member name and second part of the generated function's name must match.

Parameters:
RTYPE return type
SNAME name of the structure of which we are getting a member
MNAME member name affects how the resultant function will be called
MEXP expression to get the member
See also:
OSCAP_GENERIC_GETTER
#define OSCAP_GETTER_FORCE ( RTYPE,
SNAME,
MNAME   )     OSCAP_GENERIC_GETTER_FORCE(RTYPE,SNAME,MNAME,MNAME)

Generate a getter function with an explicit conversion to the target data type.

Member name and second part of the generated function's name must match.

Parameters:
RTYPE return type
SNAME name of the structure of which we are getting a member
MNAME member name affects how the resultant function will be called
MEXP expression to get the member
See also:
OSCAP_GENERIC_GETTER_FORCE
#define OSCAP_HGETTER ( RTYPE,
SNAME,
MNAME   )     OSCAP_HGETTER_EXP(RTYPE,SNAME,MNAME,MNAME)

Generete a geter function from a hash table.

Signature of the generated function will be as follows (substitute uppercase strings with actual params):

 RTYPE SNAME_MNAME(const struct SNAME* item, const char* key); 
Parameters:
RTYPE type of the hash table item
SNAME name of the structure
MNAME structure member name
#define OSCAP_HGETTER_EXP ( RTYPE,
SNAME,
MNAME,
MEXP   ) 
Value:
RTYPE SNAME##_get_##MNAME(const struct SNAME* item, const char* key) \
        { return oscap_htable_get(item->MEXP, key); }

Generete a geter function from a hash table.

Signature of the generated function will be as follows (substitute uppercase strings with actual params):

 RTYPE SNAME_MNAME(const struct SNAME* item, const char* key); 
Parameters:
RTYPE type of the hash table item
SNAME name of the structure
MNAME structure member name
MEXP expression to get the member variable (i.e. the hash table)
#define OSCAP_HGETTER_STRUCT ( RTYPE,
SNAME,
MNAME   )     OSCAP_HGETTER_EXP(struct RTYPE*,SNAME,MNAME,MNAME)

Generete a geter function from a hash table.

Signature of the generated function will be as follows (substitute uppercase strings with actual params):

 struct RTYPE* SNAME_MNAME(const struct SNAME* item, const char* key); 
Parameters:
RTYPE type of the hash table item
SNAME name of the structure
MNAME structure member name
#define OSCAP_IGETTER ( ITYPE,
SNAME,
MNAME   )     OSCAP_IGETTER_CONV(ITYPE,SNAME,MNAME,)

Generate an iterator getter function.

Signature of the generated function will be as follows (substitute uppercase strings with actual params):

 struct ITYPE_iterator* SNAME_MNAME(const struct SNAME*); 
Parameters:
ITYPE iterator type (without the '_iterator' suffix)
SNAME name of type the structure containing the list
MANME list itself
#define OSCAP_IGETTER_CONV ( ITYPE,
SNAME,
MNAME,
CONV   ) 
Value:
struct ITYPE##_iterator* SNAME##_get_##MNAME(const struct SNAME* item) \
        { return oscap_iterator_new((CONV(item))->MNAME); }

Generate an iterator getter function.

Signature of the generated function will be as follows (substitute uppercase strings with actual params):

 struct ITYPE_iterator* SNAME_MNAME(const struct SNAME*); 
Parameters:
ITYPE iterator type (without the '_iterator' suffix)
SNAME name of type the structure containing the list
MANME list itself
CONV convert expression
#define OSCAP_IGETTER_GEN ( ITYPE,
SNAME,
MNAME   )     OSCAP_IGETTER(ITYPE,SNAME,MNAME) OSCAP_ITERATOR_GEN(ITYPE)

Generate an iterator and its getter.

See also:
OSCAP_IGETTER
OSCAP_ITERATOR_GEN
#define OSCAP_INSERTER ( SNAME,
FNAME,
MTYPE,
MNAME   ) 
Value:
bool SNAME##_add_##FNAME(struct SNAME *obj, struct MTYPE *item) \
        { oscap_list_add(obj->MNAME, item); return true; }

Generate function to insert an item into a list.

Signature of the generated function will be as follows (substitute uppercase strings with actual params):

 bool SNAME_add_FNAME(struct SNAME *obj, struct MTYPE *item); 
Parameters:
SNAME structure typename (w/o the struct keyword)
FNAME how should function name part after the _add_ look like
MTYPE list member type
MNAME name of the list within the structure
#define OSCAP_SETTER_GENERIC ( SNAME,
MTYPE,
MNAME,
DELETER,
ASSIGNER   ) 
Value:
OSCAP_SETTER_HEADER(SNAME, MTYPE, MNAME) \
        { DELETER(obj->MNAME); obj->MNAME = ASSIGNER(item); return true; }

Generete a setter function without a check.

See also:
OSCAP_SETTER_GENERIC_CHECK
#define OSCAP_SETTER_GENERIC_CHECK ( SNAME,
MTYPE,
MNAME,
CHECK,
DELETER,
ASSIGNER   ) 
Value:
OSCAP_SETTER_HEADER(SNAME, MTYPE, MNAME) \
        { if (!(CHECK)) return false; DELETER(obj->MNAME); obj->MNAME = ASSIGNER(item); return true; }

Generete a setter function with a check.

Signature of the generated function will be as follows (substitute uppercase strings with actual params):

 bool SNAME_get_MNAME(struct SNAME *obj, MTYPE *item); 
Parameters:
SNAME Name of the structure.
MTYPE Type of the member item to set.
MNAME Name of the member item to set.
CHECK Code to check validity of the assignment (you can use obj and item variables here).
DELETER Function used to delete the old value (or empty string).
ASSIGNER Function used to assign value to the item.
#define OSCAP_SETTER_GENERIC_NODELETE ( SNAME,
MTYPE,
MNAME,
ASSIGNER   ) 
Value:
OSCAP_SETTER_HEADER(SNAME, MTYPE, MNAME) \
        { obj->MNAME = ASSIGNER(item); return true; }

Generete a setter function without a check that does not delete the previous value.

See also:
OSCAP_SETTER_GENERIC_CHECK
#define OSCAP_SETTER_SIMPLE ( SNAME,
MTYPE,
MNAME   )     OSCAP_SETTER_GENERIC_NODELETE(SNAME, MTYPE, MNAME, )

Generete a setter function using a simple assignment.

See also:
OSCAP_SETTER_GENERIC_CHECK
#define OSCAP_SETTER_STRING ( SNAME,
MNAME   )     OSCAP_SETTER_GENERIC(SNAME, const char *, MNAME, free, oscap_strdup)

Assign a string value to a structure member.

Parameters:
SNAME Structure name
MNAME Name of structure member containing the string to be set.

Function Documentation

char* oscap_strdup ( const char *  str  ) 

Use strdup on string, if string is NULL, return NULL.

Parameters:
str String we want to duplicate
char* oscap_strsep ( char **  str,
const char *  delim 
)

Use strsep on string We can't use strsep from string.h because of compatibility issues.

Parameters:
str String we want to split
delim Delimiter of string parts

Generated on 4 Jan 2010 for Open SCAP Library by  doxygen 1.6.1