/home/pvrabec/tmp/openscap/openscap-0.1.4/src/CPE/cpeuri.c File Reference

Interface to Common Product Enumeration (CPE) URI. More...

#include <string.h>
#include <stdio.h>
#include <pcre.h>
#include <ctype.h>
#include <assert.h>
#include "cpeuri.h"

Functions

cpe_tcpe_new (const char *cpestr)
char ** cpe_split (char *str, const char *delim)
bool cpe_urldecode (char *str)
bool cpe_name_match_one (const cpe_t *cpe, const cpe_t *against)
bool cpe_name_match_cpes (const cpe_t *name, size_t n, cpe_t **namelist)
int cpe_name_match_strs (const char *candidate, size_t n, char **targets)
bool cpe_check (const char *str)
const char * as_str (const char *str)
char * cpe_get_uri (const cpe_t *cpe)
int cpe_write (const cpe_t *cpe, FILE *f)
bool cpe_assign_values (cpe_t *cpe, char **fields)
void cpe_delete (cpe_t *cpe)
size_t ptrarray_length (void **arr)

Variables

const char * CPE_PART_CHAR [] = { NULL, "h", "o", "a" }
const char * CPE_SCHEMA = "cpe:/"
const char CPE_SEP_CHAR = ':'
const char * CPE_SEP_STR = ":"
const size_t CPE_SPLIT_INIT_ALLOC = 8


Detailed Description

Interface to Common Product Enumeration (CPE) URI.

See more details at http://nvd.nist.gov/cpe.cfm


Function Documentation

bool cpe_assign_values ( cpe_t cpe,
char **  fields 
)

Fill cpe structure with parsed fields.

Fields can be obtained via cpe_split(). Pointers in target sructure will point to same strings as pointers in fields do. No string duplication is performed.

See also:
cpe_split
Parameters:
cpe structure to be filled
fields NULL-terminated array of strings representing individual fields
Returns:
true on success

bool cpe_check ( const char *  str  ) 

Ensures str is in proper CPE format.

Parameters:
str string to be validated

void cpe_delete ( cpe_t cpe  ) 

Destructor. Frees any used resources and safely destroys cpe.

Parameters:
cpe CPE to be deleted

char* cpe_get_uri ( const cpe_t cpe  ) 

Return CPE URI as a new string.

Note:
Returned string is newly allocated and is caller's responsibility to free it.
Parameters:
cpe CPE to be converted
Returns:
CPE URI as string
Return values:
NULL on failure

bool cpe_name_match_cpes ( const cpe_t name,
size_t  n,
cpe_t **  namelist 
)

Check if CPE name matches any CPE in namelist.

Parameters:
name name to be looked-up
n number of items in namelist
namelist list of names to search in
Returns:
true if name was found within namelist

bool cpe_name_match_one ( const cpe_t cpe,
const cpe_t against 
)

Check if candidate CPE cpe matches CPE against according to CPE specification v 2.1.

int cpe_name_match_strs ( const char *  candidate,
size_t  n,
char **  targets 
)

Match CPE URI candidate against list of n CPE URIs given by targets.

Parameters:
candidate candidarte CPE URI as string
n number of items in targets
targets list of CPE URIs to be candidate matched against
Todo:
maybe it should go into libcpe library itself
Returns:
index of first URI in targets, that matched
Return values:
-1 on mismatch
-2 invalid CPE URI was given as parameter

cpe_t* cpe_new ( const char *  cpe  ) 

Create new CPE structure from string cpe.

Note:
If cpe is NULL, empty cpe will be created.
Parameters:
cpe CPE URI string to be parsed
Returns:
new structure holding parsed data
Return values:
NULL on failure

char** cpe_split ( char *  str,
const char *  delim 
)

Split CPE string into individual fields separated by delim.

This function returns NULL-terminated array of pointers to strings.

Note:
Return value must be freed explicitly by caller.

This function modifies its first argument.

Parameters:
str string to be parsed, will be changed as side-effect of this function
delim delimiter
Returns:
newly allocated NULL-terminated array of ponters to strings representing individual parts
Return values:
NULL on failure

bool cpe_urldecode ( char *  str  ) 

In-place decodes a -encoded string.

Parameters:
str string to be decoded (will be modified)
Returns:
true on success

int cpe_write ( const cpe_t cpe,
FILE *  f 
)

Write CPE URI cpe to file a descriptor f

Parameters:
cpe cpe to write
f file descriptor to write CPE URI to
Returns:
number of written characters
Return values:
<0 on failure

size_t ptrarray_length ( void **  arr  ) 

Return number of elements in NULL-terminated array of pointers.

Parameters:
array of pointers
Returns:
number of members


Generated on Sun Mar 29 13:29:21 2009 for Open SCAP Library by  doxygen 1.5.6