|
Greenbone Vulnerability Management Libraries 22.32.0
|
Functions to convert different CPE notations into each other. More...
#include "cpeutils.h"#include <assert.h>#include <ctype.h>#include <errno.h>#include <glib.h>#include <string.h>

Go to the source code of this file.
Macros | |
| #define | G_LOG_DOMAIN "libgvm util" |
| GLib logging domain. | |
Functions | |
| static enum set_relation | compare_component (const char *source, const char *target) |
| Returns if the component "source" is a match for the component "target". That means that source is a superset of target. | |
| static enum set_relation | compare_strings (const char *source, const char *target) |
| Returns if the string of a component "source" is a match for the the string of a component "target". That means that source represents a superset of target. | |
| static int | count_escapes (const char *str, int start, int end) |
| Counts the number of unescaped escape signs ("\") in a specified part of a string. | |
| static gboolean | is_even_wildcards (const char *str, int index) |
| Returns true if an even number of escape (backslash) characters precede the character at the index "index" in string "str". | |
| static gboolean | has_wildcards (const char *str) |
| Returns if a given string contains wildcards ("*" or "?"). | |
| static int | index_of (const char *str, const char *sub_str, int offset) |
| Searches the string "str" for the first occurrence of the string "sub_str", starting at the offset "offset" in "str". | |
| static gboolean | is_string (const char *str) |
| Returns if a string is an ordinary string and does not represent one of the logical values "ANY" or "NA". | |
| static char * | get_uri_component (const char *uri_cpe, int index) |
| Get the indexth component of a URI CPE. | |
| static char * | decode_uri_component (const char *component) |
| Decode a component of a URI CPE. | |
| static void | unpack_sixth_uri_component (const char *component, cpe_struct_t *cpe) |
| Unpack the sixth component of a URI CPE. | |
| static char * | get_fs_component (const char *fs_cpe, int index) |
| Get the indexth component of a formatted string CPE. | |
| static char * | unbind_fs_component (char *component) |
| Unbind a formatted string CPE component. | |
| static char * | add_quoting (const char *component) |
| Handle the quoting for an unbind formatted string CPE component. | |
| static char * | bind_cpe_component_for_uri (const char *component) |
| Bind a CPE component for a URI CPE. | |
| static char * | transform_for_uri (const char *component) |
| Transform a CPE component for a URI CPE. | |
| static char * | pack_sixth_uri_component (const cpe_struct_t *cpe) |
| Pack the sixth component of a URI CPE. | |
| static char * | bind_cpe_component_for_fs (const char *component) |
| Bind a CPE component for a formatted string CPE. | |
| static char * | process_quoted_chars (const char *component) |
| Process the quoted characters of a CPE component for a formatted string CPE. | |
| static void | trim_pct (char *str) |
| Cut of trailing ':' signs. | |
| static void | get_code (char *code, const char *str) |
| Get the percent code from the start of a string. | |
| char * | uri_cpe_to_fs_cpe (const char *uri_cpe) |
| Convert a URI CPE to a formatted string CPE. | |
| char * | uri_cpe_to_fs_product (const char *uri_cpe) |
| Convert a URI CPE to a formatted string product. | |
| char * | uri_cpe_to_uri_product (const char *uri_cpe) |
| Convert a URI CPE to a formatted string product. | |
| char * | fs_cpe_to_uri_cpe (const char *fs_cpe) |
| Convert a formatted string CPE to a URI CPE. | |
| char * | fs_cpe_to_uri_product (const char *fs_cpe) |
| Convert a formatted string CPE to an URI product. | |
| void | uri_cpe_to_cpe_struct (const char *uri_cpe, cpe_struct_t *cpe) |
| Read a URI CPE into the CPE struct. | |
| char * | cpe_struct_to_uri_cpe (const cpe_struct_t *cpe) |
| Convert a CPE struct into a URI CPE. | |
| char * | cpe_struct_to_uri_product (const cpe_struct_t *cpe) |
| Convert a CPE struct into a URI product. | |
| char * | get_version_from_uri_cpe (const char *uri_cpe) |
| Get the version from an uri cpe. | |
| void | fs_cpe_to_cpe_struct (const char *fs_cpe, cpe_struct_t *cpe) |
| Read a formatted string CPE into the CPE struct. | |
| char * | cpe_struct_to_fs_cpe (const cpe_struct_t *cpe) |
| Convert a CPE struct into a formatted string CPE. | |
| char * | cpe_struct_to_fs_product (const cpe_struct_t *cpe) |
| Convert a CPE struct into a formatted string product. | |
| void | cpe_struct_init (cpe_struct_t *cpe) |
| Initialize a CPE struct. | |
| void | cpe_struct_free (cpe_struct_t *cpe) |
| Free a CPE struct. | |
| gboolean | cpe_struct_match (cpe_struct_t *source, cpe_struct_t *target) |
| Returns if source is a match for target. That means that source is a superset of target. | |
| gboolean | cpe_struct_match_tail (cpe_struct_t *source, cpe_struct_t *target) |
| Returns if the part behind the version of source is a match for that part of target. That means, that source is a superset of target if also the first part matches. | |
Functions to convert different CPE notations into each other.
This library provides functions to read the CPE 2.2 URI binding of a CPE or the CPE 2.3 formatted string binding of a CPE into a CPE struct that corresponds to the WFN naming of a CPE. Further functions to convert the CPE struct into the different bindings are provided. This file also contains a function that checks if one CPE (represented in a CPE struct) is a match for an other CPE (also represented in a CPE struct).
Definition in file cpeutils.c.
| #define G_LOG_DOMAIN "libgvm util" |
GLib logging domain.
Definition at line 30 of file cpeutils.c.
|
static |
Handle the quoting for an unbind formatted string CPE component.
| [in] | component | The component to add the quotings to. |
Definition at line 898 of file cpeutils.c.
Referenced by unbind_fs_component().

|
static |
Bind a CPE component for a formatted string CPE.
| [in] | component | The component to bind. |
Definition at line 1124 of file cpeutils.c.
References process_quoted_chars().
Referenced by cpe_struct_to_fs_cpe(), and cpe_struct_to_fs_product().


|
static |
Bind a CPE component for a URI CPE.
| [in] | component | The component to bind. |
Definition at line 989 of file cpeutils.c.
References transform_for_uri().
Referenced by cpe_struct_to_uri_cpe(), cpe_struct_to_uri_product(), and pack_sixth_uri_component().


|
static |
Returns if the component "source" is a match for the component "target". That means that source is a superset of target.
| [in] | source | The component of a cpe_struct. |
| [in] | target | The component of a cpe_struct that is checked if it is a subset of source meaning that it is matched by source. |
Definition at line 1391 of file cpeutils.c.
References compare_strings(), DISJOINT, EQUAL, has_wildcards(), is_string(), SUBSET, SUPERSET, and UNDEFINED.
Referenced by cpe_struct_match(), and cpe_struct_match_tail().


|
static |
Returns if the string of a component "source" is a match for the the string of a component "target". That means that source represents a superset of target.
| [in] | source | The string of a component of a cpe_struct. |
| [in] | target | The string of a component of a cpe_struct that is checked if it represents a subset of source meaning that it is matched by source. |
Definition at line 1468 of file cpeutils.c.
References count_escapes(), DISJOINT, index_of(), is_even_wildcards(), and SUPERSET.
Referenced by compare_component().


|
static |
Counts the number of unescaped escape signs ("\") in a specified part of a string.
| [in] | str | The string to be examined. |
| [in] | start | The start position in the string where the examination begins. |
| [in] | end | The end position in the string where the examination ends. |
Definition at line 1543 of file cpeutils.c.
Referenced by compare_strings().

| void cpe_struct_free | ( | cpe_struct_t * | cpe | ) |
Free a CPE struct.
| [in/out] | cpe The CPE to be freed. |
Definition at line 1214 of file cpeutils.c.
References cpe_struct_t::edition, cpe_struct_t::language, cpe_struct_t::other, cpe_struct_t::part, cpe_struct_t::product, cpe_struct_t::sw_edition, cpe_struct_t::target_hw, cpe_struct_t::target_sw, cpe_struct_t::update, cpe_struct_t::vendor, and cpe_struct_t::version.
Referenced by Ensure(), Ensure(), Ensure(), fs_cpe_to_uri_cpe(), fs_cpe_to_uri_product(), uri_cpe_to_fs_cpe(), uri_cpe_to_fs_product(), and uri_cpe_to_uri_product().

| void cpe_struct_init | ( | cpe_struct_t * | cpe | ) |
Initialize a CPE struct.
| [in/out] | cpe The pointer to the CPE to initialize. |
Definition at line 1190 of file cpeutils.c.
References cpe_struct_t::edition, cpe_struct_t::language, cpe_struct_t::other, cpe_struct_t::part, cpe_struct_t::product, cpe_struct_t::sw_edition, cpe_struct_t::target_hw, cpe_struct_t::target_sw, cpe_struct_t::update, cpe_struct_t::vendor, and cpe_struct_t::version.
Referenced by Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), fs_cpe_to_uri_cpe(), fs_cpe_to_uri_product(), uri_cpe_to_fs_cpe(), uri_cpe_to_fs_product(), and uri_cpe_to_uri_product().

| gboolean cpe_struct_match | ( | cpe_struct_t * | source, |
| cpe_struct_t * | target ) |
Returns if source is a match for target. That means that source is a superset of target.
| [in] | source | The cpe_struct that represents a set of CPEs. |
| [in] | target | The cpe_struct that represents a single CPE or or a set of CPEs that is checked if it is a subset of source meaning that it is matched by source. |
Definition at line 1295 of file cpeutils.c.
References compare_component(), cpe_struct_t::edition, EQUAL, cpe_struct_t::language, cpe_struct_t::other, cpe_struct_t::part, cpe_struct_t::product, SUPERSET, cpe_struct_t::sw_edition, cpe_struct_t::target_hw, cpe_struct_t::target_sw, cpe_struct_t::update, cpe_struct_t::vendor, and cpe_struct_t::version.
Referenced by Ensure(), and main().


| gboolean cpe_struct_match_tail | ( | cpe_struct_t * | source, |
| cpe_struct_t * | target ) |
Returns if the part behind the version of source is a match for that part of target. That means, that source is a superset of target if also the first part matches.
| [in] | source | The cpe_struct that represents a set of CPEs. |
| [in] | target | The cpe_struct that represents a single CPE or or a set of CPEs that is checked if it is a subset of source meaning that it is matched by source. |
Definition at line 1350 of file cpeutils.c.
References compare_component(), cpe_struct_t::edition, EQUAL, cpe_struct_t::language, cpe_struct_t::other, SUPERSET, cpe_struct_t::sw_edition, cpe_struct_t::target_hw, cpe_struct_t::target_sw, and cpe_struct_t::update.

| char * cpe_struct_to_fs_cpe | ( | const cpe_struct_t * | cpe | ) |
Convert a CPE struct into a formatted string CPE.
| [in] | cpe | A pointer to the CPE struct. |
Definition at line 402 of file cpeutils.c.
References bind_cpe_component_for_fs(), cpe_struct_t::edition, cpe_struct_t::language, cpe_struct_t::other, cpe_struct_t::part, cpe_struct_t::product, cpe_struct_t::sw_edition, cpe_struct_t::target_hw, cpe_struct_t::target_sw, cpe_struct_t::update, cpe_struct_t::vendor, and cpe_struct_t::version.
Referenced by Ensure(), main(), and uri_cpe_to_fs_cpe().


| char * cpe_struct_to_fs_product | ( | const cpe_struct_t * | cpe | ) |
Convert a CPE struct into a formatted string product.
| [in] | cpe | A pointer to the CPE struct. |
Definition at line 496 of file cpeutils.c.
References bind_cpe_component_for_fs(), cpe_struct_t::part, cpe_struct_t::product, and cpe_struct_t::vendor.
Referenced by uri_cpe_to_fs_product().


| char * cpe_struct_to_uri_cpe | ( | const cpe_struct_t * | cpe | ) |
Convert a CPE struct into a URI CPE.
| [in] | cpe | A pointer to the CPE struct. |
Definition at line 240 of file cpeutils.c.
References bind_cpe_component_for_uri(), cpe_struct_t::language, pack_sixth_uri_component(), cpe_struct_t::part, cpe_struct_t::product, trim_pct(), cpe_struct_t::update, cpe_struct_t::vendor, and cpe_struct_t::version.
Referenced by Ensure(), fs_cpe_to_uri_cpe(), and main().


| char * cpe_struct_to_uri_product | ( | const cpe_struct_t * | cpe | ) |
Convert a CPE struct into a URI product.
| [in] | cpe | A pointer to the CPE struct. |
Definition at line 309 of file cpeutils.c.
References bind_cpe_component_for_uri(), cpe_struct_t::part, cpe_struct_t::product, trim_pct(), and cpe_struct_t::vendor.
Referenced by fs_cpe_to_uri_product(), and uri_cpe_to_uri_product().


|
static |
Decode a component of a URI CPE.
| [in] | component | The component to decode. |
Definition at line 586 of file cpeutils.c.
References get_code().
Referenced by get_version_from_uri_cpe(), unpack_sixth_uri_component(), and uri_cpe_to_cpe_struct().


| void fs_cpe_to_cpe_struct | ( | const char * | fs_cpe, |
| cpe_struct_t * | cpe ) |
Read a formatted string CPE into the CPE struct.
| [in] | fs_cpe | A formatted string CPE. |
| [out] | cpe | Pointer to the filled CPE struct. |
Definition at line 366 of file cpeutils.c.
References cpe_struct_t::edition, get_fs_component(), cpe_struct_t::language, cpe_struct_t::other, cpe_struct_t::part, cpe_struct_t::product, cpe_struct_t::sw_edition, cpe_struct_t::target_hw, cpe_struct_t::target_sw, unbind_fs_component(), cpe_struct_t::update, cpe_struct_t::vendor, and cpe_struct_t::version.
Referenced by Ensure(), Ensure(), fs_cpe_to_uri_cpe(), fs_cpe_to_uri_product(), and main().


| char * fs_cpe_to_uri_cpe | ( | const char * | fs_cpe | ) |
Convert a formatted string CPE to a URI CPE.
| [in] | fs_cpe | A formatted string CPE. |
Definition at line 160 of file cpeutils.c.
References cpe_struct_free(), cpe_struct_init(), cpe_struct_to_uri_cpe(), and fs_cpe_to_cpe_struct().
Referenced by Ensure(), and main().


| char * fs_cpe_to_uri_product | ( | const char * | fs_cpe | ) |
Convert a formatted string CPE to an URI product.
| [in] | fs_cpe | A formatted string CPE. |
Definition at line 180 of file cpeutils.c.
References cpe_struct_free(), cpe_struct_init(), cpe_struct_to_uri_product(), and fs_cpe_to_cpe_struct().

|
static |
Get the percent code from the start of a string.
| [in] | str | The string to get the code from. |
| [out] | code | The percent code. |
Definition at line 1274 of file cpeutils.c.
Referenced by decode_uri_component().

|
static |
Get the indexth component of a formatted string CPE.
| [in] | fs_cpe | The formatted string CPE. |
| [in] | index | The number of the component to get. |
Definition at line 801 of file cpeutils.c.
Referenced by fs_cpe_to_cpe_struct().

|
static |
Get the indexth component of a URI CPE.
| [in] | uri_cpe | The URI CPE. |
| [in] | index | The number of the component to get. |
Definition at line 536 of file cpeutils.c.
Referenced by get_version_from_uri_cpe(), and uri_cpe_to_cpe_struct().

| char * get_version_from_uri_cpe | ( | const char * | uri_cpe | ) |
Get the version from an uri cpe.
| [in] | uri_cpe | The uri cpe to get the version from. |
Definition at line 350 of file cpeutils.c.
References decode_uri_component(), and get_uri_component().

|
static |
Returns if a given string contains wildcards ("*" or "?").
| [in] | str | The string to be examined. |
Definition at line 1588 of file cpeutils.c.
Referenced by compare_component().

|
static |
Searches the string "str" for the first occurrence of the string "sub_str", starting at the offset "offset" in "str".
| [in] | str | The string to be examined. |
| [in] | sub_str | The string to be searched for in "str". |
| [in] | offset | The offset where to start the search in "str". |
Definition at line 1620 of file cpeutils.c.
Referenced by compare_strings().

|
static |
Returns true if an even number of escape (backslash) characters precede the character at the index "index" in string "str".
| [in] | str | The string to be examined. |
| [in] | index | The index where the examination starts. |
Definition at line 1568 of file cpeutils.c.
Referenced by compare_strings().

|
static |
Returns if a string is an ordinary string and does not represent one of the logical values "ANY" or "NA".
| [in] | str | The string to be examined. |
Definition at line 1645 of file cpeutils.c.
Referenced by compare_component().

|
static |
Pack the sixth component of a URI CPE.
| [in] | component | The CPE struct with the components to pack into the sixth component of a URI CPE. |
Definition at line 1073 of file cpeutils.c.
References bind_cpe_component_for_uri(), cpe_struct_t::edition, cpe_struct_t::other, cpe_struct_t::sw_edition, cpe_struct_t::target_hw, and cpe_struct_t::target_sw.
Referenced by cpe_struct_to_uri_cpe().


|
static |
Process the quoted characters of a CPE component for a formatted string CPE.
| [in] | component | The component to process. |
Definition at line 1146 of file cpeutils.c.
Referenced by bind_cpe_component_for_fs().

|
static |
Transform a CPE component for a URI CPE.
| [in] | component | The component to transform. |
Definition at line 1010 of file cpeutils.c.
Referenced by bind_cpe_component_for_uri().

|
static |
Cut of trailing ':' signs.
| [in/out] | str The string to be processed. |
Definition at line 1248 of file cpeutils.c.
Referenced by cpe_struct_to_uri_cpe(), and cpe_struct_to_uri_product().

|
static |
Unbind a formatted string CPE component.
| [in] | component | The component to unbind. |
Definition at line 869 of file cpeutils.c.
References add_quoting().
Referenced by fs_cpe_to_cpe_struct().


|
static |
Unpack the sixth component of a URI CPE.
| [in] | component | The component to unpack. |
| [out] | cpe | Pointer to the CPE struct where the unpacked and decoded values of the component are stored. |
Definition at line 719 of file cpeutils.c.
References decode_uri_component(), cpe_struct_t::edition, cpe_struct_t::other, cpe_struct_t::sw_edition, cpe_struct_t::target_hw, and cpe_struct_t::target_sw.
Referenced by uri_cpe_to_cpe_struct().


| void uri_cpe_to_cpe_struct | ( | const char * | uri_cpe, |
| cpe_struct_t * | cpe ) |
Read a URI CPE into the CPE struct.
| [in] | uri_cpe | A CPE v2.2-conformant URI. |
| [out] | cpe | Pointer to the filled CPE struct. |
Definition at line 200 of file cpeutils.c.
References decode_uri_component(), cpe_struct_t::edition, get_uri_component(), cpe_struct_t::language, cpe_struct_t::part, cpe_struct_t::product, unpack_sixth_uri_component(), cpe_struct_t::update, cpe_struct_t::vendor, and cpe_struct_t::version.
Referenced by Ensure(), main(), uri_cpe_to_fs_cpe(), uri_cpe_to_fs_product(), and uri_cpe_to_uri_product().


| char * uri_cpe_to_fs_cpe | ( | const char * | uri_cpe | ) |
Convert a URI CPE to a formatted string CPE.
| [in] | uri_cpe | A CPE v2.2-conformant URI. |
Definition at line 100 of file cpeutils.c.
References cpe_struct_free(), cpe_struct_init(), cpe_struct_to_fs_cpe(), and uri_cpe_to_cpe_struct().
Referenced by Ensure(), and main().


| char * uri_cpe_to_fs_product | ( | const char * | uri_cpe | ) |
Convert a URI CPE to a formatted string product.
| [in] | uri_cpe | A CPE v2.2-conformant URI. |
Definition at line 120 of file cpeutils.c.
References cpe_struct_free(), cpe_struct_init(), cpe_struct_to_fs_product(), and uri_cpe_to_cpe_struct().

| char * uri_cpe_to_uri_product | ( | const char * | uri_cpe | ) |
Convert a URI CPE to a formatted string product.
| [in] | uri_cpe | A CPE v2.2-conformant URI. |
Definition at line 140 of file cpeutils.c.
References cpe_struct_free(), cpe_struct_init(), cpe_struct_to_uri_product(), and uri_cpe_to_cpe_struct().
Referenced by Ensure(), and main().

