Implemented targeted SWID request

This commit is contained in:
Andreas Steffen
2013-09-06 22:06:39 +02:00
parent 70aefb9430
commit 3adffcd9eb
5 changed files with 86 additions and 29 deletions
+60 -6
View File
@@ -52,7 +52,8 @@ struct private_swid_inventory_t {
linked_list_t *list;
};
static bool collect_tags(private_swid_inventory_t *this, char *pathname)
static bool collect_tags(private_swid_inventory_t *this, char *pathname,
swid_inventory_t *targets)
{
char *rel_name, *abs_name;
struct stat st;
@@ -73,26 +74,50 @@ static bool collect_tags(private_swid_inventory_t *this, char *pathname)
char * start, *stop;
chunk_t tag_creator;
chunk_t unique_sw_id = chunk_empty, unique_seq_id = chunk_empty;
if (!strstr(rel_name, "regid."))
{
continue;
}
if (S_ISDIR(st.st_mode))
{
if (!collect_tags(this, abs_name))
/* In case of a targeted request */
if (targets->get_count(targets))
{
enumerator_t *target_enumerator;
swid_tag_id_t *tag_id;
bool match = FALSE;
target_enumerator = targets->create_enumerator(targets);
while (target_enumerator->enumerate(target_enumerator, &tag_id))
{
if (chunk_equals(tag_id->get_tag_creator(tag_id),
chunk_from_str(rel_name)))
{
match = TRUE;
break;
}
}
target_enumerator->destroy(target_enumerator);
if (!match)
{
continue;
}
}
if (!collect_tags(this, abs_name, targets))
{
goto end;
}
continue;
}
DBG2(DBG_IMC, " %s", rel_name);
/* parse the regid filename into its components */
start = rel_name;
stop = strchr(start, '_');
if (!stop)
{
DBG1(DBG_IMC, " %s", rel_name);
DBG1(DBG_IMC, " '_' separator not found");
goto end;
}
@@ -109,6 +134,7 @@ static bool collect_tags(private_swid_inventory_t *this, char *pathname)
stop = strstr(start, ".swidtag");
if (!stop)
{
DBG1(DBG_IMC, " %s", rel_name);
DBG1(DBG_IMC, " swidtag postfix not found");
goto end;
}
@@ -121,6 +147,34 @@ static bool collect_tags(private_swid_inventory_t *this, char *pathname)
unique_sw_id = chunk_create(start, stop-start);
}
/* In case of a targeted request */
if (targets->get_count(targets))
{
enumerator_t *target_enumerator;
swid_tag_id_t *tag_id;
bool match = FALSE;
target_enumerator = targets->create_enumerator(targets);
while (target_enumerator->enumerate(target_enumerator, &tag_id))
{
if (chunk_equals(tag_id->get_tag_creator(tag_id),
tag_creator) &&
chunk_equals(tag_id->get_unique_sw_id(tag_id, NULL),
unique_sw_id))
{
match = TRUE;
break;
}
}
target_enumerator->destroy(target_enumerator);
if (!match)
{
continue;
}
}
DBG2(DBG_IMC, " %s", rel_name);
if (this->full_tags)
{
swid_tag_t *tag;
@@ -177,9 +231,9 @@ end:
}
METHOD(swid_inventory_t, collect, bool,
private_swid_inventory_t *this, char *directory)
private_swid_inventory_t *this, char *directory, swid_inventory_t *targets)
{
return collect_tags(this, directory);
return collect_tags(this, directory, targets);
}
METHOD(swid_inventory_t, add, void,