Greenbone Vulnerability Management Libraries 22.32.0
cpeutils.h File Reference

Headers for CPE utils. More...

#include <glib.h>
#include <stdio.h>
Include dependency graph for cpeutils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  cpe_struct_t
 XML context. More...

Macros

#define CPE_COMPONENT_IS_ANY(component)

Enumerations

enum  set_relation {
  DISJOINT , EQUAL , SUBSET , SUPERSET ,
  UNDEFINED
}

Functions

char * uri_cpe_to_fs_cpe (const char *)
 Convert a URI CPE to a formatted string CPE.
char * uri_cpe_to_fs_product (const char *)
 Convert a URI CPE to a formatted string product.
char * uri_cpe_to_uri_product (const char *)
 Convert a URI CPE to a formatted string product.
char * fs_cpe_to_uri_cpe (const char *)
 Convert a formatted string CPE to a URI CPE.
char * fs_cpe_to_uri_product (const char *)
 Convert a formatted string CPE to an URI product.
void uri_cpe_to_cpe_struct (const char *, cpe_struct_t *)
 Read a URI CPE into the CPE struct.
char * cpe_struct_to_uri_cpe (const cpe_struct_t *)
 Convert a CPE struct into a URI CPE.
char * cpe_struct_to_uri_product (const cpe_struct_t *)
 Convert a CPE struct into a URI product.
char * get_version_from_uri_cpe (const char *)
 Get the version from an uri cpe.
void fs_cpe_to_cpe_struct (const char *, cpe_struct_t *)
 Read a formatted string CPE into the CPE struct.
char * cpe_struct_to_fs_cpe (const cpe_struct_t *)
 Convert a CPE struct into a formatted string CPE.
char * cpe_struct_to_fs_product (const cpe_struct_t *)
 Convert a CPE struct into a formatted string product.
void cpe_struct_init (cpe_struct_t *)
 Initialize a CPE struct.
void cpe_struct_free (cpe_struct_t *)
 Free a CPE struct.
gboolean cpe_struct_match (cpe_struct_t *, cpe_struct_t *)
 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 *, cpe_struct_t *)
 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.

Detailed Description

Headers for CPE utils.

Definition in file cpeutils.h.

Macro Definition Documentation

◆ CPE_COMPONENT_IS_ANY

#define CPE_COMPONENT_IS_ANY ( component)
Value:
(component[0] == 'A')

Definition at line 94 of file cpeutils.h.

Enumeration Type Documentation

◆ set_relation

Enumerator
DISJOINT 
EQUAL 
SUBSET 
SUPERSET 
UNDEFINED 

Definition at line 85 of file cpeutils.h.

86{
88 EQUAL,
89 SUBSET,
92};
@ SUBSET
Definition cpeutils.h:89
@ DISJOINT
Definition cpeutils.h:87
@ EQUAL
Definition cpeutils.h:88
@ UNDEFINED
Definition cpeutils.h:91
@ SUPERSET
Definition cpeutils.h:90

Function Documentation

◆ cpe_struct_free()

void cpe_struct_free ( cpe_struct_t * cpe)

Free a CPE struct.

Parameters
[in/out]cpe The CPE to be freed.

Definition at line 1214 of file cpeutils.c.

1215{
1216 if (!cpe)
1217 return;
1218 if (cpe->part)
1219 g_free (cpe->part);
1220 if (cpe->vendor)
1221 g_free (cpe->vendor);
1222 if (cpe->product)
1223 g_free (cpe->product);
1224 if (cpe->version)
1225 g_free (cpe->version);
1226 if (cpe->update)
1227 g_free (cpe->update);
1228 if (cpe->edition)
1229 g_free (cpe->edition);
1230 if (cpe->sw_edition)
1231 g_free (cpe->sw_edition);
1232 if (cpe->target_sw)
1233 g_free (cpe->target_sw);
1234 if (cpe->target_hw)
1235 g_free (cpe->target_hw);
1236 if (cpe->other)
1237 g_free (cpe->other);
1238 if (cpe->language)
1239 g_free (cpe->language);
1240}
char * sw_edition
Definition cpeutils.h:30
char * target_sw
Definition cpeutils.h:31
char * vendor
Definition cpeutils.h:25
char * version
Definition cpeutils.h:27
char * update
Definition cpeutils.h:28
char * product
Definition cpeutils.h:26
char * part
Definition cpeutils.h:24
char * edition
Definition cpeutils.h:29
char * language
Definition cpeutils.h:34
char * target_hw
Definition cpeutils.h:32
char * other
Definition cpeutils.h:33

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().

Here is the caller graph for this function:

◆ cpe_struct_init()

void cpe_struct_init ( cpe_struct_t * cpe)

Initialize a CPE struct.

Parameters
[in/out]cpe The pointer to the CPE to initialize.

Definition at line 1190 of file cpeutils.c.

1191{
1192 cpe->part = NULL;
1193 cpe->vendor = NULL;
1194 cpe->product = NULL;
1195 cpe->version = NULL;
1196 cpe->update = NULL;
1197 cpe->edition = NULL;
1198 cpe->sw_edition = NULL;
1199 cpe->target_sw = NULL;
1200 cpe->target_hw = NULL;
1201 cpe->other = NULL;
1202 cpe->language = NULL;
1203
1204 /* to keep the compiler satisfied */
1205 cpe->part = cpe->part;
1206}

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().

Here is the caller graph for this function:

◆ cpe_struct_match()

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.

Parameters
[in]sourceThe cpe_struct that represents a set of CPEs.
[in]targetThe 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.
Returns
Returns if source is a match for target.

Definition at line 1295 of file cpeutils.c.

1296{
1297 enum set_relation relation;
1298
1299 relation = compare_component (source->part, target->part);
1300 if (relation != SUPERSET && relation != EQUAL)
1301 return FALSE;
1302 relation = compare_component (source->vendor, target->vendor);
1303 if (relation != SUPERSET && relation != EQUAL)
1304 return FALSE;
1305 relation = compare_component (source->product, target->product);
1306 if (relation != SUPERSET && relation != EQUAL)
1307 return FALSE;
1308 relation = compare_component (source->version, target->version);
1309 if (relation != SUPERSET && relation != EQUAL)
1310 return FALSE;
1311 relation = compare_component (source->update, target->update);
1312 if (relation != SUPERSET && relation != EQUAL)
1313 return FALSE;
1314 relation = compare_component (source->edition, target->edition);
1315 if (relation != SUPERSET && relation != EQUAL)
1316 return FALSE;
1317 relation = compare_component (source->sw_edition, target->sw_edition);
1318 if (relation != SUPERSET && relation != EQUAL)
1319 return FALSE;
1320 relation = compare_component (source->target_sw, target->target_sw);
1321 if (relation != SUPERSET && relation != EQUAL)
1322 return FALSE;
1323 relation = compare_component (source->target_hw, target->target_hw);
1324 if (relation != SUPERSET && relation != EQUAL)
1325 return FALSE;
1326 relation = compare_component (source->other, target->other);
1327 if (relation != SUPERSET && relation != EQUAL)
1328 return FALSE;
1329 relation = compare_component (source->language, target->language);
1330 if (relation != SUPERSET && relation != EQUAL)
1331 return FALSE;
1332
1333 return TRUE;
1334}
static enum set_relation compare_component(const char *, const char *)
Returns if the component "source" is a match for the component "target". That means that source is a ...
Definition cpeutils.c:1391
set_relation
Definition cpeutils.h:86

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpe_struct_match_tail()

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.

Parameters
[in]sourceThe cpe_struct that represents a set of CPEs.
[in]targetThe 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.
Returns
Returns if source is a match for target.

Definition at line 1350 of file cpeutils.c.

1351{
1352 enum set_relation relation;
1353
1354 relation = compare_component (source->update, target->update);
1355 if (relation != SUPERSET && relation != EQUAL)
1356 return FALSE;
1357 relation = compare_component (source->edition, target->edition);
1358 if (relation != SUPERSET && relation != EQUAL)
1359 return FALSE;
1360 relation = compare_component (source->sw_edition, target->sw_edition);
1361 if (relation != SUPERSET && relation != EQUAL)
1362 return FALSE;
1363 relation = compare_component (source->target_sw, target->target_sw);
1364 if (relation != SUPERSET && relation != EQUAL)
1365 return FALSE;
1366 relation = compare_component (source->target_hw, target->target_hw);
1367 if (relation != SUPERSET && relation != EQUAL)
1368 return FALSE;
1369 relation = compare_component (source->other, target->other);
1370 if (relation != SUPERSET && relation != EQUAL)
1371 return FALSE;
1372 relation = compare_component (source->language, target->language);
1373 if (relation != SUPERSET && relation != EQUAL)
1374 return FALSE;
1375
1376 return TRUE;
1377}

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.

Here is the call graph for this function:

◆ cpe_struct_to_fs_cpe()

char * cpe_struct_to_fs_cpe ( const cpe_struct_t * cpe)

Convert a CPE struct into a formatted string CPE.

Parameters
[in]cpeA pointer to the CPE struct.
Returns
A formatted string CPE.

Definition at line 402 of file cpeutils.c.

403{
404 GString *fs_cpe;
405 char *bind_cpe_component;
406
407 fs_cpe = g_string_new ("cpe:2.3:");
408
409 bind_cpe_component = bind_cpe_component_for_fs (cpe->part);
410 if (bind_cpe_component)
411 {
412 g_string_append (fs_cpe, bind_cpe_component);
413 g_string_append_c (fs_cpe, ':');
414 g_free (bind_cpe_component);
415 }
416 bind_cpe_component = bind_cpe_component_for_fs (cpe->vendor);
417 if (bind_cpe_component)
418 {
419 g_string_append (fs_cpe, bind_cpe_component);
420 g_string_append_c (fs_cpe, ':');
421 g_free (bind_cpe_component);
422 }
423 bind_cpe_component = bind_cpe_component_for_fs (cpe->product);
424 if (bind_cpe_component)
425 {
426 g_string_append (fs_cpe, bind_cpe_component);
427 g_string_append_c (fs_cpe, ':');
428 g_free (bind_cpe_component);
429 }
430 bind_cpe_component = bind_cpe_component_for_fs (cpe->version);
431 if (bind_cpe_component)
432 {
433 g_string_append (fs_cpe, bind_cpe_component);
434 g_string_append_c (fs_cpe, ':');
435 g_free (bind_cpe_component);
436 }
437 bind_cpe_component = bind_cpe_component_for_fs (cpe->update);
438 if (bind_cpe_component)
439 {
440 g_string_append (fs_cpe, bind_cpe_component);
441 g_string_append_c (fs_cpe, ':');
442 g_free (bind_cpe_component);
443 }
444 bind_cpe_component = bind_cpe_component_for_fs (cpe->edition);
445 if (bind_cpe_component)
446 {
447 g_string_append (fs_cpe, bind_cpe_component);
448 g_string_append_c (fs_cpe, ':');
449 g_free (bind_cpe_component);
450 }
451 bind_cpe_component = bind_cpe_component_for_fs (cpe->language);
452 if (bind_cpe_component)
453 {
454 g_string_append (fs_cpe, bind_cpe_component);
455 g_string_append_c (fs_cpe, ':');
456 g_free (bind_cpe_component);
457 }
458 bind_cpe_component = bind_cpe_component_for_fs (cpe->sw_edition);
459 if (bind_cpe_component)
460 {
461 g_string_append (fs_cpe, bind_cpe_component);
462 g_string_append_c (fs_cpe, ':');
463 g_free (bind_cpe_component);
464 }
465 bind_cpe_component = bind_cpe_component_for_fs (cpe->target_sw);
466 if (bind_cpe_component)
467 {
468 g_string_append (fs_cpe, bind_cpe_component);
469 g_string_append_c (fs_cpe, ':');
470 g_free (bind_cpe_component);
471 }
472 bind_cpe_component = bind_cpe_component_for_fs (cpe->target_hw);
473 if (bind_cpe_component)
474 {
475 g_string_append (fs_cpe, bind_cpe_component);
476 g_string_append_c (fs_cpe, ':');
477 g_free (bind_cpe_component);
478 }
479 bind_cpe_component = bind_cpe_component_for_fs (cpe->other);
480 if (bind_cpe_component)
481 {
482 g_string_append (fs_cpe, bind_cpe_component);
483 g_free (bind_cpe_component);
484 }
485 return (g_string_free (fs_cpe, FALSE));
486}
static char * bind_cpe_component_for_fs(const char *)
Bind a CPE component for a formatted string CPE.
Definition cpeutils.c:1124

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpe_struct_to_fs_product()

char * cpe_struct_to_fs_product ( const cpe_struct_t * cpe)

Convert a CPE struct into a formatted string product.

Parameters
[in]cpeA pointer to the CPE struct.
Returns
A formatted string product.

Definition at line 496 of file cpeutils.c.

497{
498 GString *fs_cpe;
499 char *bind_cpe_component;
500
501 fs_cpe = g_string_new ("cpe:2.3:");
502
503 bind_cpe_component = bind_cpe_component_for_fs (cpe->part);
504 if (bind_cpe_component)
505 {
506 g_string_append (fs_cpe, bind_cpe_component);
507 g_string_append_c (fs_cpe, ':');
508 g_free (bind_cpe_component);
509 }
510 bind_cpe_component = bind_cpe_component_for_fs (cpe->vendor);
511 if (bind_cpe_component)
512 {
513 g_string_append (fs_cpe, bind_cpe_component);
514 g_string_append_c (fs_cpe, ':');
515 g_free (bind_cpe_component);
516 }
517 bind_cpe_component = bind_cpe_component_for_fs (cpe->product);
518 if (bind_cpe_component)
519 {
520 g_string_append (fs_cpe, bind_cpe_component);
521 g_string_append_c (fs_cpe, ':');
522 g_free (bind_cpe_component);
523 }
524 return (g_string_free (fs_cpe, FALSE));
525}

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpe_struct_to_uri_cpe()

char * cpe_struct_to_uri_cpe ( const cpe_struct_t * cpe)

Convert a CPE struct into a URI CPE.

Parameters
[in]cpeA pointer to the CPE struct.
Returns
A CPE v2.2-conformant URI.

Definition at line 240 of file cpeutils.c.

241{
242 GString *uri_cpe;
243 char *bind_cpe_component;
244 uri_cpe = g_string_new ("cpe:/");
245
246 bind_cpe_component = bind_cpe_component_for_uri (cpe->part);
247 if (bind_cpe_component)
248 {
249 g_string_append (uri_cpe, bind_cpe_component);
250 g_string_append_c (uri_cpe, ':');
251 g_free (bind_cpe_component);
252 }
253 bind_cpe_component = bind_cpe_component_for_uri (cpe->vendor);
254 if (bind_cpe_component)
255 {
256 g_string_append (uri_cpe, bind_cpe_component);
257 g_string_append_c (uri_cpe, ':');
258 g_free (bind_cpe_component);
259 }
260 bind_cpe_component = bind_cpe_component_for_uri (cpe->product);
261 if (bind_cpe_component)
262 {
263 g_string_append (uri_cpe, bind_cpe_component);
264 g_string_append_c (uri_cpe, ':');
265 g_free (bind_cpe_component);
266 }
267 bind_cpe_component = bind_cpe_component_for_uri (cpe->version);
268 if (bind_cpe_component)
269 {
270 g_string_append (uri_cpe, bind_cpe_component);
271 g_string_append_c (uri_cpe, ':');
272 g_free (bind_cpe_component);
273 }
274 bind_cpe_component = bind_cpe_component_for_uri (cpe->update);
275 if (bind_cpe_component)
276 {
277 g_string_append (uri_cpe, bind_cpe_component);
278 g_string_append_c (uri_cpe, ':');
279 g_free (bind_cpe_component);
280 }
281 bind_cpe_component = pack_sixth_uri_component (cpe);
282 if (bind_cpe_component)
283 {
284 g_string_append (uri_cpe, bind_cpe_component);
285 g_string_append_c (uri_cpe, ':');
286 g_free (bind_cpe_component);
287 }
288 bind_cpe_component = bind_cpe_component_for_uri (cpe->language);
289 if (bind_cpe_component)
290 {
291 g_string_append (uri_cpe, bind_cpe_component);
292 g_string_append_c (uri_cpe, ':');
293 g_free (bind_cpe_component);
294 }
295
296 char *result = g_string_free (uri_cpe, FALSE);
297 trim_pct (result);
298 return result;
299}
static char * bind_cpe_component_for_uri(const char *)
Bind a CPE component for a URI CPE.
Definition cpeutils.c:989
static char * pack_sixth_uri_component(const cpe_struct_t *)
Pack the sixth component of a URI CPE.
Definition cpeutils.c:1073
static void trim_pct(char *)
Cut of trailing ':' signs.
Definition cpeutils.c:1248

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpe_struct_to_uri_product()

char * cpe_struct_to_uri_product ( const cpe_struct_t * cpe)

Convert a CPE struct into a URI product.

Parameters
[in]cpeA pointer to the CPE struct.
Returns
A CPE v2.2-conformant URI product.

Definition at line 309 of file cpeutils.c.

310{
311 GString *uri_cpe;
312 char *bind_cpe_component;
313 uri_cpe = g_string_new ("cpe:/");
314
315 bind_cpe_component = bind_cpe_component_for_uri (cpe->part);
316 if (bind_cpe_component)
317 {
318 g_string_append (uri_cpe, bind_cpe_component);
319 g_string_append_c (uri_cpe, ':');
320 g_free (bind_cpe_component);
321 }
322 bind_cpe_component = bind_cpe_component_for_uri (cpe->vendor);
323 if (bind_cpe_component)
324 {
325 g_string_append (uri_cpe, bind_cpe_component);
326 g_string_append_c (uri_cpe, ':');
327 g_free (bind_cpe_component);
328 }
329 bind_cpe_component = bind_cpe_component_for_uri (cpe->product);
330 if (bind_cpe_component)
331 {
332 g_string_append (uri_cpe, bind_cpe_component);
333 g_string_append_c (uri_cpe, ':');
334 g_free (bind_cpe_component);
335 }
336
337 char *result = g_string_free (uri_cpe, FALSE);
338 trim_pct (result);
339 return result;
340}

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fs_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.

Parameters
[in]fs_cpeA formatted string CPE.
[out]cpePointer to the filled CPE struct.

Definition at line 366 of file cpeutils.c.

367{
368 char *fs_component;
369
370 fs_component = get_fs_component (fs_cpe, 2);
371 cpe->part = unbind_fs_component (fs_component);
372 fs_component = get_fs_component (fs_cpe, 3);
373 cpe->vendor = unbind_fs_component (fs_component);
374 fs_component = get_fs_component (fs_cpe, 4);
375 cpe->product = unbind_fs_component (fs_component);
376 fs_component = get_fs_component (fs_cpe, 5);
377 cpe->version = unbind_fs_component (fs_component);
378 fs_component = get_fs_component (fs_cpe, 6);
379 cpe->update = unbind_fs_component (fs_component);
380 fs_component = get_fs_component (fs_cpe, 7);
381 cpe->edition = unbind_fs_component (fs_component);
382 fs_component = get_fs_component (fs_cpe, 8);
383 cpe->language = unbind_fs_component (fs_component);
384 fs_component = get_fs_component (fs_cpe, 9);
385 cpe->sw_edition = unbind_fs_component (fs_component);
386 fs_component = get_fs_component (fs_cpe, 10);
387 cpe->target_sw = unbind_fs_component (fs_component);
388 fs_component = get_fs_component (fs_cpe, 11);
389 cpe->target_hw = unbind_fs_component (fs_component);
390 fs_component = get_fs_component (fs_cpe, 12);
391 cpe->other = unbind_fs_component (fs_component);
392}
static char * get_fs_component(const char *, int)
Get the indexth component of a formatted string CPE.
Definition cpeutils.c:801
static char * unbind_fs_component(char *)
Unbind a formatted string CPE component.
Definition cpeutils.c:869

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fs_cpe_to_uri_cpe()

char * fs_cpe_to_uri_cpe ( const char * fs_cpe)

Convert a formatted string CPE to a URI CPE.

Parameters
[in]fs_cpeA formatted string CPE.
Returns
A CPE v2.2-conformant URI.

Definition at line 160 of file cpeutils.c.

161{
162 cpe_struct_t cpe;
163 char *uri_cpe;
164
165 cpe_struct_init (&cpe);
166 fs_cpe_to_cpe_struct (fs_cpe, &cpe);
167 uri_cpe = cpe_struct_to_uri_cpe (&cpe);
168 cpe_struct_free (&cpe);
169 return uri_cpe;
170}
void fs_cpe_to_cpe_struct(const char *fs_cpe, cpe_struct_t *cpe)
Read a formatted string CPE into the CPE struct.
Definition cpeutils.c:366
char * cpe_struct_to_uri_cpe(const cpe_struct_t *cpe)
Convert a CPE struct into a URI CPE.
Definition cpeutils.c:240
void cpe_struct_init(cpe_struct_t *cpe)
Initialize a CPE struct.
Definition cpeutils.c:1190
void cpe_struct_free(cpe_struct_t *cpe)
Free a CPE struct.
Definition cpeutils.c:1214
XML context.
Definition cpeutils.h:23

References cpe_struct_free(), cpe_struct_init(), cpe_struct_to_uri_cpe(), and fs_cpe_to_cpe_struct().

Referenced by Ensure(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fs_cpe_to_uri_product()

char * fs_cpe_to_uri_product ( const char * fs_cpe)

Convert a formatted string CPE to an URI product.

Parameters
[in]fs_cpeA formatted string CPE.
Returns
An URI product.

Definition at line 180 of file cpeutils.c.

181{
182 cpe_struct_t cpe;
183 char *uri_cpe;
184
185 cpe_struct_init (&cpe);
186 fs_cpe_to_cpe_struct (fs_cpe, &cpe);
187 uri_cpe = cpe_struct_to_uri_product (&cpe);
188 cpe_struct_free (&cpe);
189 return uri_cpe;
190}
char * cpe_struct_to_uri_product(const cpe_struct_t *cpe)
Convert a CPE struct into a URI product.
Definition cpeutils.c:309

References cpe_struct_free(), cpe_struct_init(), cpe_struct_to_uri_product(), and fs_cpe_to_cpe_struct().

Here is the call graph for this function:

◆ get_version_from_uri_cpe()

char * get_version_from_uri_cpe ( const char * uri_cpe)

Get the version from an uri cpe.

Parameters
[in]uri_cpeThe uri cpe to get the version from.
Returns
The version of the uri cpe.

Definition at line 350 of file cpeutils.c.

351{
352 char *version = get_uri_component (uri_cpe, 4);
353 char *decoded_version = decode_uri_component (version);
354 g_free (version);
355 return decoded_version;
356}
static char * get_uri_component(const char *, int)
Get the indexth component of a URI CPE.
Definition cpeutils.c:536
static char * decode_uri_component(const char *)
Decode a component of a URI CPE.
Definition cpeutils.c:586

References decode_uri_component(), and get_uri_component().

Here is the call graph for this function:

◆ 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.

Parameters
[in]uri_cpeA CPE v2.2-conformant URI.
[out]cpePointer to the filled CPE struct.

Definition at line 200 of file cpeutils.c.

201{
202 char *uri_component;
203
204 uri_component = get_uri_component (uri_cpe, 1);
205 cpe->part = decode_uri_component (uri_component);
206 g_free (uri_component);
207 uri_component = get_uri_component (uri_cpe, 2);
208 cpe->vendor = decode_uri_component (uri_component);
209 g_free (uri_component);
210 uri_component = get_uri_component (uri_cpe, 3);
211 cpe->product = decode_uri_component (uri_component);
212 g_free (uri_component);
213 uri_component = get_uri_component (uri_cpe, 4);
214 cpe->version = decode_uri_component (uri_component);
215 g_free (uri_component);
216 uri_component = get_uri_component (uri_cpe, 5);
217 cpe->update = decode_uri_component (uri_component);
218 g_free (uri_component);
219 uri_component = get_uri_component (uri_cpe, 6);
220 if (strcmp (uri_component, "") == 0 || strcmp (uri_component, "-") == 0
221 || *uri_component != '~')
222 cpe->edition = decode_uri_component (uri_component);
223 else
224 unpack_sixth_uri_component (uri_component, cpe);
225 g_free (uri_component);
226
227 uri_component = get_uri_component (uri_cpe, 7);
228 cpe->language = decode_uri_component (uri_component);
229 g_free (uri_component);
230}
static void unpack_sixth_uri_component(const char *, cpe_struct_t *)
Unpack the sixth component of a URI CPE.
Definition cpeutils.c:719

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uri_cpe_to_fs_cpe()

char * uri_cpe_to_fs_cpe ( const char * uri_cpe)

Convert a URI CPE to a formatted string CPE.

Parameters
[in]uri_cpeA CPE v2.2-conformant URI.
Returns
A formatted string CPE.

Definition at line 100 of file cpeutils.c.

101{
102 cpe_struct_t cpe;
103 char *fs_cpe;
104
105 cpe_struct_init (&cpe);
106 uri_cpe_to_cpe_struct (uri_cpe, &cpe);
107 fs_cpe = cpe_struct_to_fs_cpe (&cpe);
108 cpe_struct_free (&cpe);
109 return fs_cpe;
110}
char * cpe_struct_to_fs_cpe(const cpe_struct_t *cpe)
Convert a CPE struct into a formatted string CPE.
Definition cpeutils.c:402
void uri_cpe_to_cpe_struct(const char *uri_cpe, cpe_struct_t *cpe)
Read a URI CPE into the CPE struct.
Definition cpeutils.c:200

References cpe_struct_free(), cpe_struct_init(), cpe_struct_to_fs_cpe(), and uri_cpe_to_cpe_struct().

Referenced by Ensure(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uri_cpe_to_fs_product()

char * uri_cpe_to_fs_product ( const char * uri_cpe)

Convert a URI CPE to a formatted string product.

Parameters
[in]uri_cpeA CPE v2.2-conformant URI.
Returns
A formatted string product.

Definition at line 120 of file cpeutils.c.

121{
122 cpe_struct_t cpe;
123 char *fs_cpe;
124
125 cpe_struct_init (&cpe);
126 uri_cpe_to_cpe_struct (uri_cpe, &cpe);
127 fs_cpe = cpe_struct_to_fs_product (&cpe);
128 cpe_struct_free (&cpe);
129 return fs_cpe;
130}
char * cpe_struct_to_fs_product(const cpe_struct_t *cpe)
Convert a CPE struct into a formatted string product.
Definition cpeutils.c:496

References cpe_struct_free(), cpe_struct_init(), cpe_struct_to_fs_product(), and uri_cpe_to_cpe_struct().

Here is the call graph for this function:

◆ uri_cpe_to_uri_product()

char * uri_cpe_to_uri_product ( const char * uri_cpe)

Convert a URI CPE to a formatted string product.

Parameters
[in]uri_cpeA CPE v2.2-conformant URI.
Returns
A CPE v2.2-conformant URI product.

Definition at line 140 of file cpeutils.c.

141{
142 cpe_struct_t cpe;
143 char *fs_cpe;
144
145 cpe_struct_init (&cpe);
146 uri_cpe_to_cpe_struct (uri_cpe, &cpe);
147 fs_cpe = cpe_struct_to_uri_product (&cpe);
148 cpe_struct_free (&cpe);
149 return fs_cpe;
150}

References cpe_struct_free(), cpe_struct_init(), cpe_struct_to_uri_product(), and uri_cpe_to_cpe_struct().

Referenced by Ensure(), and main().

Here is the call graph for this function:
Here is the caller graph for this function: