From eda56fd465e5a577e75e02bb78d18793144ddf0d Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Fri, 5 Aug 2011 20:40:47 +0000 Subject: [PATCH] added spd_get_filtered_size to get sum of attributes matching attribute list --- include/btstack/sdp_util.h | 3 ++- src/sdp_util.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/btstack/sdp_util.h b/include/btstack/sdp_util.h index f1d14c68b..f22db24a1 100644 --- a/include/btstack/sdp_util.h +++ b/include/btstack/sdp_util.h @@ -125,8 +125,9 @@ int de_get_data_size(uint8_t * header); // MARK: SDP int sdp_append_attributes_in_attributeIDList(uint8_t *record, uint8_t *attributeIDList, uint16_t startIndex, uint16_t maxBytes, uint8_t *buffer); uint8_t * sdp_get_attribute_value_for_attribute_id(uint8_t * record, uint16_t attributeID); - uint8_t sdp_set_attribute_value_for_attribute_id(uint8_t * record, uint16_t attributeID, uint32_t value); +uint8_t sdp_set_attribute_value_for_attribute_id(uint8_t * record, uint16_t attributeID, uint32_t value); int sdp_record_matches_service_search_pattern(uint8_t *record, uint8_t *serviceSearchPattern); +int spd_get_filtered_size(uint8_t *record, uint8_t *attributeIDList); #if defined __cplusplus } diff --git a/src/sdp_util.c b/src/sdp_util.c index 15e680350..e6a36fcdd 100644 --- a/src/sdp_util.c +++ b/src/sdp_util.c @@ -348,6 +348,28 @@ int sdp_append_attributes_in_attributeIDList(uint8_t *record, uint8_t *attribute return -1; } +// MARK: Get sum of attributes matching attribute list +struct sdp_context_get_filtered_size { + uint8_t *attributeIDList; + uint16_t size; +}; + +static int sdp_traversal_get_filtered_size(uint16_t attributeID, uint8_t * attributeValue, de_type_t type, de_size_t size, void *my_context){ + struct sdp_context_get_filtered_size * context = (struct sdp_context_get_filtered_size *) my_context; + if (sdp_attribute_list_constains_id(context->attributeIDList, attributeID)) { + context->size += size; + } + return 0; +} + +int spd_get_filtered_size(uint8_t *record, uint8_t *attributeIDList){ + struct sdp_context_get_filtered_size context; + context.size = 0; + context.attributeIDList = attributeIDList; + sdp_attribute_list_traverse_sequence(record, sdp_traversal_get_filtered_size, &context); + return context.size; +} + // MARK: Get AttributeValue for AttributeID // find attribute (ELEMENT) by ID struct sdp_context_attribute_by_id {