30#define G_LOG_DOMAIN "libgvm util"
48index_of (
const char *,
const char *,
int);
93str_cpy (
char **,
const char *,
int);
189 g_free (uri_component);
192 g_free (uri_component);
195 g_free (uri_component);
198 g_free (uri_component);
201 g_free (uri_component);
203 if (strcmp (uri_component,
"") == 0 || strcmp (uri_component,
"-") == 0
204 || *uri_component !=
'~')
208 g_free (uri_component);
212 g_free (uri_component);
226 char *bind_cpe_component;
227 uri_cpe = g_string_new (
"cpe:/");
230 if (bind_cpe_component)
232 g_string_append_printf (uri_cpe,
"%s:", bind_cpe_component);
233 g_free (bind_cpe_component);
236 if (bind_cpe_component)
238 g_string_append_printf (uri_cpe,
"%s:", bind_cpe_component);
239 g_free (bind_cpe_component);
242 if (bind_cpe_component)
244 g_string_append_printf (uri_cpe,
"%s:", bind_cpe_component);
245 g_free (bind_cpe_component);
248 if (bind_cpe_component)
250 g_string_append_printf (uri_cpe,
"%s:", bind_cpe_component);
251 g_free (bind_cpe_component);
254 if (bind_cpe_component)
256 g_string_append_printf (uri_cpe,
"%s:", bind_cpe_component);
257 g_free (bind_cpe_component);
260 if (bind_cpe_component)
262 g_string_append_printf (uri_cpe,
"%s:", bind_cpe_component);
263 g_free (bind_cpe_component);
266 if (bind_cpe_component)
268 g_string_append_printf (uri_cpe,
"%s:", bind_cpe_component);
269 g_free (bind_cpe_component);
272 char *result = g_string_free (uri_cpe, FALSE);
288 char *bind_cpe_component;
289 uri_cpe = g_string_new (
"cpe:/");
292 if (bind_cpe_component)
294 g_string_append_printf (uri_cpe,
"%s:", bind_cpe_component);
295 g_free (bind_cpe_component);
298 if (bind_cpe_component)
300 g_string_append_printf (uri_cpe,
"%s:", bind_cpe_component);
301 g_free (bind_cpe_component);
304 if (bind_cpe_component)
306 g_string_append_printf (uri_cpe,
"%s:", bind_cpe_component);
307 g_free (bind_cpe_component);
310 char *result = g_string_free (uri_cpe, FALSE);
331 g_free (fs_component);
334 g_free (fs_component);
337 g_free (fs_component);
340 g_free (fs_component);
343 g_free (fs_component);
346 g_free (fs_component);
349 g_free (fs_component);
352 g_free (fs_component);
355 g_free (fs_component);
358 g_free (fs_component);
372 char *bind_cpe_component;
374 fs_cpe = g_string_new (
"cpe:2.3:");
377 if (bind_cpe_component)
379 g_string_append_printf (fs_cpe,
"%s:", bind_cpe_component);
380 g_free (bind_cpe_component);
383 if (bind_cpe_component)
385 g_string_append_printf (fs_cpe,
"%s:", bind_cpe_component);
386 g_free (bind_cpe_component);
389 if (bind_cpe_component)
391 g_string_append_printf (fs_cpe,
"%s:", bind_cpe_component);
392 g_free (bind_cpe_component);
395 if (bind_cpe_component)
397 g_string_append_printf (fs_cpe,
"%s:", bind_cpe_component);
398 g_free (bind_cpe_component);
401 if (bind_cpe_component)
403 g_string_append_printf (fs_cpe,
"%s:", bind_cpe_component);
404 g_free (bind_cpe_component);
407 if (bind_cpe_component)
409 g_string_append_printf (fs_cpe,
"%s:", bind_cpe_component);
410 g_free (bind_cpe_component);
413 if (bind_cpe_component)
415 g_string_append_printf (fs_cpe,
"%s:", bind_cpe_component);
416 g_free (bind_cpe_component);
419 if (bind_cpe_component)
421 g_string_append_printf (fs_cpe,
"%s:", bind_cpe_component);
422 g_free (bind_cpe_component);
425 if (bind_cpe_component)
427 g_string_append_printf (fs_cpe,
"%s:", bind_cpe_component);
428 g_free (bind_cpe_component);
431 if (bind_cpe_component)
433 g_string_append_printf (fs_cpe,
"%s:", bind_cpe_component);
434 g_free (bind_cpe_component);
437 if (bind_cpe_component)
439 g_string_append_printf (fs_cpe,
"%s", bind_cpe_component);
440 g_free (bind_cpe_component);
442 return (g_string_free (fs_cpe, FALSE));
456 char *bind_cpe_component;
458 fs_cpe = g_string_new (
"cpe:2.3:");
461 if (bind_cpe_component)
463 g_string_append_printf (fs_cpe,
"%s:", bind_cpe_component);
464 g_free (bind_cpe_component);
467 if (bind_cpe_component)
469 g_string_append_printf (fs_cpe,
"%s:", bind_cpe_component);
470 g_free (bind_cpe_component);
473 if (bind_cpe_component)
475 g_string_append_printf (fs_cpe,
"%s:", bind_cpe_component);
476 g_free (bind_cpe_component);
478 return (g_string_free (fs_cpe, FALSE));
492 char *component = NULL;
494 char *component_start, *component_end;
499 c = (
char *) uri_cpe;
502 for (
int i = 0; *c !=
'\0' && i < index; c++)
508 if (index == 1 && *c !=
'\0')
514 if (*component_start ==
'\0')
515 component_end = component_start;
518 for (c = component_start; *c !=
'\0' && *c !=
':'; c++)
524 if (component_start >= component_end || component_end == 0)
525 component = (
char *) g_strdup (
"");
527 str_cpy (&component, component_start, component_end - component_start);
542 GString *decoded_component;
543 char *escapes =
"!\"#$%&'()*+,/:;<=>?@[\\]^`{|}~";
545 char code_a[4], code_b[4], code_c[4];
546 long unsigned int index;
552 if (strcmp (component,
"") == 0 || strcmp (component,
" ") == 0)
554 return (g_strdup (
"ANY"));
556 if (strcmp (component,
"-") == 0)
558 return (g_strdup (
"NA"));
561 tmp_component = g_strdup (component);
564 char *c = tmp_component;
570 decoded_component = g_string_new (
"");
574 while (index < strlen (tmp_component))
576 l = *(tmp_component + index);
578 if (l ==
'.' || l ==
'-' || l ==
'~')
580 g_string_append_printf (decoded_component,
"\\%c", l);
587 g_string_append_printf (decoded_component,
"%c", l);
593 get_code (code_a, tmp_component + index);
595 if (strcmp (code_a,
"%01") == 0)
598 get_code (code_b, tmp_component + index - 3);
601 if (strlen (tmp_component) >= index + 6)
602 get_code (code_c, tmp_component + index + 3);
605 if ((index == 0 || index == strlen (tmp_component) - 3)
606 || (!embedded && strcmp (code_b,
"%01"))
607 || (embedded && strcmp (code_c,
"%01")))
609 g_string_append_printf (decoded_component,
"%c",
'?');
615 g_string_free (decoded_component, TRUE);
616 g_free (tmp_component);
621 if (strcmp (code_a,
"%02") == 0)
623 if (index == 0 || index == strlen (tmp_component) - 3)
625 g_string_append_printf (decoded_component,
"%c",
'*');
631 g_string_free (decoded_component, TRUE);
632 g_free (tmp_component);
637 unescaped = g_uri_unescape_string (code_a, NULL);
638 if (unescaped && strchr (escapes, *unescaped))
640 g_string_append_printf (decoded_component,
"\\%s", unescaped);
645 g_string_append_printf (decoded_component,
"%s", unescaped);
650 g_string_free (decoded_component, TRUE);
651 g_free (tmp_component);
658 g_free (tmp_component);
659 return (g_string_free (decoded_component, FALSE));
673 const char *start = component + 1;
676 char *edition, *sw_edition, *target_sw, *target_hw, *other;
678 end = strchr (start,
'~');
679 if (start >= end || end == NULL)
680 edition = strdup (
"");
682 str_cpy (&edition, start, end - start);
687 end = strchr (start,
'~');
688 if (start >= end || end == NULL)
689 sw_edition = strdup (
"");
691 str_cpy (&sw_edition, start, end - start);
694 sw_edition = strdup (
"");
699 end = strchr (start,
'~');
700 if (start >= end || end == NULL)
701 target_sw = strdup (
"");
703 str_cpy (&target_sw, start, end - start);
706 target_sw = strdup (
"");
711 end = strchr (start,
'~');
712 if (start >= end || end == NULL)
713 target_hw = strdup (
"");
715 str_cpy (&target_hw, start, end - start);
718 target_hw = strdup (
"");
723 end = component + strlen (component);
727 str_cpy (&other, start, end - start);
755 char *component = NULL;
757 char *component_start, *component_end;
763 return ((
char *) g_strdup (
""));
772 for (
int i = 0; *c !=
'\0' && i < index; c++)
774 if (*c ==
':' && c == fs_cpe)
776 else if (c > fs_cpe && *c ==
':' && *(c - 1) !=
'\\')
783 if (*component_start ==
'\0')
784 component_end = component_start;
787 for (c = component_start; *c !=
'\0' && *c !=
':'; c++)
793 if (component_start >= component_end || component_end == NULL)
794 component = (
char *) g_strdup (
"");
796 str_cpy (&component, component_start, component_end - component_start);
811 if (strcmp (component,
"*") == 0)
812 return ((
char *) g_strdup (
"ANY"));
813 if (strcmp (component,
"-") == 0)
814 return ((
char *) g_strdup (
"NA"));
829 GString *quoted_component;
837 quoted_component = g_string_new (
"");
838 tmp_component = (
char *) g_strdup (component);
842 for (c = tmp_component; *c; c++)
848 if (g_ascii_isalnum (*c) || *c ==
'_')
850 g_string_append_printf (quoted_component,
"%c", *c);
860 g_string_append_printf (quoted_component,
"\\%c", *c);
868 if ((c == tmp_component)
869 || (c == tmp_component + strlen (tmp_component - 1)))
871 g_string_append_printf (quoted_component,
"%c", *c);
878 g_free (tmp_component);
884 if ((c == tmp_component)
885 || (c == tmp_component + strlen (tmp_component - 1))
886 || (!embedded && (c > tmp_component) && (*(c - 1) ==
'?'))
887 || (embedded && *(c + 1) ==
'?'))
889 g_string_append_printf (quoted_component,
"%c", *c);
896 g_free (tmp_component);
900 g_string_append_printf (quoted_component,
"\\%c", *c);
904 g_free (tmp_component);
905 return (g_string_free (quoted_component, FALSE));
919 return (g_strdup (
""));
920 if (strcmp (component,
"") == 0)
921 return (g_strdup (
""));
922 if (strcmp (component,
"ANY") == 0)
923 return (g_strdup (
""));
924 if (strcmp (component,
"NA") == 0)
925 return (g_strdup (
"-"));
944 return (g_strdup (
""));
945 if (strcmp (component,
"") == 0)
946 return (g_strdup (
""));
948 tmp_component = g_strdup (component);
951 for (c = tmp_component; *c; c++)
954 result = g_string_new (
"");
959 if ((g_ascii_isalnum (*c) || *c ==
'_') && *c !=
'-')
961 g_string_append_printf (result,
"%c", *c);
974 escaped = g_uri_escape_string (to_escape, NULL, FALSE);
975 g_string_append_printf (result,
"%s", escaped);
982 g_string_append_printf (result,
"%s",
"%01");
984 g_string_append_printf (result,
"%s",
"%02");
987 g_free (tmp_component);
988 return (g_string_free (result, FALSE));
1005 && (cpe->
other == NULL || strcmp (cpe->
other,
"") == 0))
1007 if (strcmp (cpe->
edition,
"ANY") == 0)
1008 return (g_strdup (
""));
1009 if (strcmp (cpe->
edition,
"NA") == 0)
1010 return (g_strdup (
"-"));
1011 return (g_strdup (cpe->
edition));
1020 component = g_string_new (
"");
1021 if (!((!sw_edition || strcmp (sw_edition,
"") == 0)
1022 && (!target_sw || strcmp (target_sw,
"") == 0)
1023 && (!target_hw || strcmp (target_hw,
"") == 0)
1024 && (!other || strcmp (other,
"") == 0)))
1025 g_string_append_printf (component,
"~%s~%s~%s~%s~%s", edition, sw_edition,
1026 target_sw, target_hw, other);
1028 g_string_append_printf (component,
"%s", edition);
1033 g_free (sw_edition);
1040 return (g_string_free (component, FALSE));
1054 return (g_strdup (
"*"));
1055 if (strcmp (component,
"") == 0)
1056 return (g_strdup (
"*"));
1057 if (strcmp (component,
"ANY") == 0)
1058 return (g_strdup (
"*"));
1059 if (strcmp (component,
"NA") == 0)
1060 return (g_strdup (
"-"));
1076 return (g_strdup (
""));
1077 if (strcmp (component,
"") == 0)
1078 return (g_strdup (
""));
1080 GString *fs_component;
1081 fs_component = g_string_new (
"");
1082 char *c = (
char *) component;
1089 g_string_append_printf (fs_component,
"%c", *c);
1095 if (next_c ==
'.' || next_c ==
'-' || next_c ==
'_')
1097 g_string_append_printf (fs_component,
"%c", next_c);
1102 g_string_append_printf (fs_component,
"\\%c", next_c);
1107 return (g_string_free (fs_component, FALSE));
1161 g_free (cpe->
other);
1178 c = str + strlen (str) - 1;
1201 code[1] = *(str + 1);
1202 code[2] = *(str + 2);
1218 *dest = (
char *) g_malloc (size + 1);
1219 memset (*dest, 0, size + 1);
1220 strncpy (*dest, src, size);
1292 char *source_cpy, *target_cpy;
1296 source_cpy = g_strdup (source);
1298 source_cpy = g_strdup (
"ANY");
1300 target_cpy = g_strdup (target);
1302 target_cpy = g_strdup (
"ANY");
1307 for (c = source_cpy; *c; c++)
1313 for (c = target_cpy; *c; c++)
1318 g_free (source_cpy);
1319 g_free (target_cpy);
1322 if (strcmp (source_cpy, target_cpy) == 0)
1324 g_free (source_cpy);
1325 g_free (target_cpy);
1328 if (strcmp (source_cpy,
"ANY") == 0)
1330 g_free (source_cpy);
1331 g_free (target_cpy);
1334 if (strcmp (target_cpy,
"ANY") == 0)
1336 g_free (source_cpy);
1337 g_free (target_cpy);
1340 if (strcmp (target_cpy,
"NA") == 0 || strcmp (source_cpy,
"NA") == 0)
1342 g_free (source_cpy);
1343 g_free (target_cpy);
1348 g_free (source_cpy);
1349 g_free (target_cpy);
1369 int end = strlen (source);
1382 while (start < (
int) strlen (source) && *(source + start) ==
'?')
1395 while (end > 0 && *(source + end - 1) ==
'?'
1403 str_cpy (&sub_source, source + start, end - start);
1406 int leftover = strlen (target);
1408 while (leftover > 0)
1410 index =
index_of (target, sub_source, index + 1);
1414 if (index > 0 && begins != -1 && begins < (index - escapes))
1416 escapes =
count_escapes (target, index + 1, strlen (target));
1417 leftover = strlen (target) - index - escapes - strlen (sub_source);
1418 if (leftover > 0 && (ends != -1 && leftover > ends))
1420 g_free (sub_source);
1423 g_free (sub_source);
1444 gboolean active = FALSE;
1446 for (
int i = 0; i < end && *(str + i) !=
'\0'; i++)
1448 active = (!active && *(str + i) ==
'\\');
1449 if (active && i >= start)
1470 while (index > 0 && *(str + index - 1) ==
'\\')
1475 return ((result % 2) == 0);
1488 char *c = (
char *) str;
1489 gboolean active = FALSE;
1493 if (!active && (*c ==
'?' || *c ==
'*'))
1496 if (!active && *c ==
'\\')
1518index_of (
const char *str,
const char *sub_str,
int offset)
1523 if (offset > (
int) strlen (str))
1526 start = (
char *) str + offset;
1527 begin_substr = strstr (start, sub_str);
1528 if (begin_substr == NULL)
1530 return (begin_substr - str);
1548 return (strcmp (str,
"ANY") && strcmp (str,
"NA"));
char * fs_cpe_to_uri_cpe(const char *fs_cpe)
Convert a formatted string CPE to a URI CPE.
Definition cpeutils.c:143
static char * bind_cpe_component_for_fs(const char *)
Bind a CPE component for a formatted string CPE.
Definition cpeutils.c:1051
char * uri_cpe_to_fs_cpe(const char *uri_cpe)
Convert a URI CPE to a formatted string CPE.
Definition cpeutils.c:103
static enum set_relation compare_strings(const char *, const char *)
Returns if the string of a component "source" is a match for the the string of a component "target"....
Definition cpeutils.c:1366
static char * bind_cpe_component_for_uri(const char *)
Bind a CPE component for a URI CPE.
Definition cpeutils.c:916
static char * get_fs_component(const char *, int)
Get the indexth component of a formatted string CPE.
Definition cpeutils.c:753
static gboolean is_even_wildcards(const char *, int)
Returns true if an even number of escape (backslash) characters precede the character at the index "i...
Definition cpeutils.c:1466
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.
Definition cpeutils.c:1236
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:1289
char * fs_cpe_to_uri_product(const char *fs_cpe)
Convert a formatted string CPE to an URI product.
Definition cpeutils.c:163
static void get_code(char *, const char *)
Get the percent code from the start of a string.
Definition cpeutils.c:1198
static void unpack_sixth_uri_component(const char *, cpe_struct_t *)
Unpack the sixth component of a URI CPE.
Definition cpeutils.c:671
char * cpe_struct_to_fs_cpe(const cpe_struct_t *cpe)
Convert a CPE struct into a formatted string CPE.
Definition cpeutils.c:369
static char * unbind_fs_component(char *)
Unbind a formatted string CPE component.
Definition cpeutils.c:809
static char * get_uri_component(const char *, int)
Get the indexth component of a URI CPE.
Definition cpeutils.c:490
static char * decode_uri_component(const char *)
Decode a component of a URI CPE.
Definition cpeutils.c:540
static void str_cpy(char **, const char *, int)
Copy size characters of a string to an newly allocated new string.
Definition cpeutils.c:1216
static char * process_quoted_chars(const char *)
Process the quoted characters of a CPE component for a formatted string CPE.
Definition cpeutils.c:1073
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:323
static char * add_quoting(const char *)
Handle the quoting for an unbind formatted string CPE component.
Definition cpeutils.c:827
char * cpe_struct_to_uri_product(const cpe_struct_t *cpe)
Convert a CPE struct into a URI product.
Definition cpeutils.c:285
char * cpe_struct_to_uri_cpe(const cpe_struct_t *cpe)
Convert a CPE struct into a URI CPE.
Definition cpeutils.c:223
void cpe_struct_init(cpe_struct_t *cpe)
Initialize a CPE struct.
Definition cpeutils.c:1116
char * cpe_struct_to_fs_product(const cpe_struct_t *cpe)
Convert a CPE struct into a formatted string product.
Definition cpeutils.c:453
static int index_of(const char *, const char *, int)
Searches the string "str" for the first occurrence of the string "sub_str", starting at the offset "o...
Definition cpeutils.c:1518
static gboolean is_string(const char *)
Returns if a string is an ordinary string and does not represent one of the logical values "ANY" or "...
Definition cpeutils.c:1543
void cpe_struct_free(cpe_struct_t *cpe)
Free a CPE struct.
Definition cpeutils.c:1140
static char * pack_sixth_uri_component(const cpe_struct_t *)
Pack the sixth component of a URI CPE.
Definition cpeutils.c:1000
static char * transform_for_uri(const char *)
Transform a CPE component for a URI CPE.
Definition cpeutils.c:937
static gboolean has_wildcards(const char *)
Returns if a given string contains wildcards ("*" or "?").
Definition cpeutils.c:1486
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:183
static int count_escapes(const char *, int, int)
Counts the number of unescaped escape signs ("\") in a specified part of a string.
Definition cpeutils.c:1441
static void trim_pct(char *)
Cut of trailing ':' signs.
Definition cpeutils.c:1172
char * uri_cpe_to_fs_product(const char *uri_cpe)
Convert a URI CPE to a formatted string product.
Definition cpeutils.c:123
set_relation
Definition cpeutils.h:77
@ SUBSET
Definition cpeutils.h:80
@ DISJOINT
Definition cpeutils.h:78
@ EQUAL
Definition cpeutils.h:79
@ UNDEFINED
Definition cpeutils.h:82
@ SUPERSET
Definition cpeutils.h:81
XML context.
Definition cpeutils.h:23
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