29
29
*/
30
30
#define G_LOG_DOMAIN "libgvm util"
31
31
32
+ static enum set_relation
33
+ compare_component (const char * , const char * );
34
+
35
+ static enum set_relation
36
+ compare_strings (const char * , const char * );
37
+
38
+ static int
39
+ count_escapes (const char * , int , int );
40
+
41
+ static gboolean
42
+ is_even_wildcards (const char * , int );
43
+
44
+ static gboolean
45
+ has_wildcards (const char * );
46
+
47
+ static int
48
+ index_of (const char * , const char * , int );
49
+
50
+ static gboolean
51
+ is_string (const char * );
52
+
53
+ static char *
54
+ get_uri_component (const char * , int );
55
+
56
+ static char *
57
+ decode_uri_component (const char * );
58
+
59
+ static void
60
+ unpack_sixth_uri_component (const char * , cpe_struct_t * );
61
+
62
+ static char *
63
+ get_fs_component (const char * , int );
64
+
65
+ static char *
66
+ unbind_fs_component (char * );
67
+
68
+ static char *
69
+ add_quoting (const char * );
70
+
71
+ static char *
72
+ bind_cpe_component_for_uri (const char * );
73
+
74
+ static char *
75
+ transform_for_uri (const char * );
76
+
77
+ static char *
78
+ pack_sixth_uri_component (const cpe_struct_t * );
79
+
80
+ static char *
81
+ bind_cpe_component_for_fs (const char * );
82
+
83
+ static char *
84
+ process_quoted_chars (const char * );
85
+
86
+ static void
87
+ trim_pct (char * );
88
+
89
+ static void
90
+ get_code (char * , const char * );
91
+
92
+ static void
93
+ str_cpy (char * * , const char * , int );
94
+
32
95
/**
33
96
* @brief Convert a URI CPE to a formatted string CPE.
34
97
*
@@ -49,6 +112,26 @@ uri_cpe_to_fs_cpe (const char *uri_cpe)
49
112
return (fs_cpe );
50
113
}
51
114
115
+ /**
116
+ * @brief Convert a URI CPE to a formatted string product.
117
+ *
118
+ * @param[in] uri_cpe A CPE v2.2-conformant URI.
119
+ *
120
+ * @return A formatted string product.
121
+ */
122
+ char *
123
+ uri_cpe_to_fs_product (const char * uri_cpe )
124
+ {
125
+ cpe_struct_t cpe ;
126
+ char * fs_cpe ;
127
+
128
+ cpe_struct_init (& cpe );
129
+ uri_cpe_to_cpe_struct (uri_cpe , & cpe );
130
+ fs_cpe = cpe_struct_to_fs_product (& cpe );
131
+ cpe_struct_free (& cpe );
132
+ return (fs_cpe );
133
+ }
134
+
52
135
/**
53
136
* @brief Convert a formatted string CPE to a URI CPE.
54
137
*
@@ -69,6 +152,26 @@ fs_cpe_to_uri_cpe (const char *fs_cpe)
69
152
return (uri_cpe );
70
153
}
71
154
155
+ /**
156
+ * @brief Convert a formatted string CPE to an URI product.
157
+ *
158
+ * @param[in] fs_cpe A formatted string CPE.
159
+ *
160
+ * @return An URI product.
161
+ */
162
+ char *
163
+ fs_cpe_to_uri_product (const char * fs_cpe )
164
+ {
165
+ cpe_struct_t cpe ;
166
+ char * uri_cpe ;
167
+
168
+ cpe_struct_init (& cpe );
169
+ fs_cpe_to_cpe_struct (fs_cpe , & cpe );
170
+ uri_cpe = cpe_struct_to_uri_product (& cpe );
171
+ cpe_struct_free (& cpe );
172
+ return (uri_cpe );
173
+ }
174
+
72
175
/**
73
176
* @brief Read a URI CPE into the CPE struct.
74
177
*
@@ -171,6 +274,44 @@ cpe_struct_to_uri_cpe (const cpe_struct_t *cpe)
171
274
return (result );
172
275
}
173
276
277
+ /**
278
+ * @brief Convert a CPE struct into a URI product.
279
+ *
280
+ * @param[in] cpe A pointer to the CPE struct.
281
+ *
282
+ * @return A CPE v2.2-conformant URI product.
283
+ */
284
+ char *
285
+ cpe_struct_to_uri_product (const cpe_struct_t * cpe )
286
+ {
287
+ GString * uri_cpe ;
288
+ char * bind_cpe_component ;
289
+ uri_cpe = g_string_new ("cpe:/" );
290
+
291
+ bind_cpe_component = bind_cpe_component_for_uri (cpe -> part );
292
+ if (bind_cpe_component )
293
+ {
294
+ g_string_append_printf (uri_cpe , "%s:" , bind_cpe_component );
295
+ g_free (bind_cpe_component );
296
+ }
297
+ bind_cpe_component = bind_cpe_component_for_uri (cpe -> vendor );
298
+ if (bind_cpe_component )
299
+ {
300
+ g_string_append_printf (uri_cpe , "%s:" , bind_cpe_component );
301
+ g_free (bind_cpe_component );
302
+ }
303
+ bind_cpe_component = bind_cpe_component_for_uri (cpe -> product );
304
+ if (bind_cpe_component )
305
+ {
306
+ g_string_append_printf (uri_cpe , "%s:" , bind_cpe_component );
307
+ g_free (bind_cpe_component );
308
+ }
309
+
310
+ char * result = g_string_free (uri_cpe , FALSE);
311
+ trim_pct (result );
312
+ return (result );
313
+ }
314
+
174
315
/**
175
316
* @brief Read a formatted string CPE into the CPE struct.
176
317
*
@@ -301,6 +442,42 @@ cpe_struct_to_fs_cpe (const cpe_struct_t *cpe)
301
442
return (g_string_free (fs_cpe , FALSE));
302
443
}
303
444
445
+ /**
446
+ * @brief Convert a CPE struct into a formatted string product.
447
+ *
448
+ * @param[in] cpe A pointer to the CPE struct.
449
+ *
450
+ * @return A formatted string product.
451
+ */
452
+ char *
453
+ cpe_struct_to_fs_product (const cpe_struct_t * cpe )
454
+ {
455
+ GString * fs_cpe ;
456
+ char * bind_cpe_component ;
457
+
458
+ fs_cpe = g_string_new ("cpe:2.3:" );
459
+
460
+ bind_cpe_component = bind_cpe_component_for_fs (cpe -> part );
461
+ if (bind_cpe_component )
462
+ {
463
+ g_string_append_printf (fs_cpe , "%s:" , bind_cpe_component );
464
+ g_free (bind_cpe_component );
465
+ }
466
+ bind_cpe_component = bind_cpe_component_for_fs (cpe -> vendor );
467
+ if (bind_cpe_component )
468
+ {
469
+ g_string_append_printf (fs_cpe , "%s:" , bind_cpe_component );
470
+ g_free (bind_cpe_component );
471
+ }
472
+ bind_cpe_component = bind_cpe_component_for_fs (cpe -> product );
473
+ if (bind_cpe_component )
474
+ {
475
+ g_string_append_printf (fs_cpe , "%s:" , bind_cpe_component );
476
+ g_free (bind_cpe_component );
477
+ }
478
+ return (g_string_free (fs_cpe , FALSE));
479
+ }
480
+
304
481
/**
305
482
* @brief Get the indexth component of a URI CPE.
306
483
*
0 commit comments