in common/src/s_list.c [178:228]
PS_LIST_ENTRY s_list_find(PS_LIST_ENTRY list_head, S_LIST_MATCH_FUNCTION match_function, const void* match_context)
{
PS_LIST_ENTRY result;
if (
/* Codes_SRS_S_LIST_07_018: [ If list_head is NULL, s_list_find shall fail and return NULL. ]*/
(list_head == NULL) ||
/* Codes_SRS_S_LIST_07_019: [ If match_function is NULL, s_list_find shall fail and return NULL. ]*/
(match_function == NULL))
{
LogError("Invalid arguments (list_head=%p, match_function=%p)", list_head, match_function);
result = NULL;
}
else
{
PS_LIST_ENTRY current_item = list_head->next;
if (current_item == NULL)
{
/* Codes_SRS_S_LIST_07_025: [ If the list is empty, s_list_find shall return NULL. ]*/
result = NULL;
}
else
{
/* Codes_SRS_S_LIST_07_020: [ s_list_find shall iterate through all entris in the list and return the first entry that satisfies the match_function on success. ]*/
while (current_item != NULL)
{
/* Codes_SRS_S_LIST_07_021: [ s_list_find shall determine whether an item satisfies the match criteria by invoking the match_function for each entry in the list until a matching entry is found. ]*/
/* Codes_SRS_S_LIST_07_022: [ The match_function shall get as arguments the list entry being attempted to be matched and the match_context as is. ]*/
if (match_function(current_item, match_context) == true)
{
/* Codes_SRS_S_LIST_07_024: [ If the match_function returns true, s_list_find shall consider that item as matching. ]*/
break;
}
/* Codes_SRS_S_LIST_07_023: [ If the match_function returns false, s_list_find shall consider that item as not matching. ]*/
current_item = current_item->next;
}
if (current_item == NULL)
{
/* Codes_SRS_S_LIST_07_039: [ If the item is not found, s_list_find shall return NULL. ]*/
result = NULL;
}
else
{
result = current_item;
}
}
}
return result;
}