implemented continuation handling for sdp_handle_service_attribute_request

This commit is contained in:
matthias.ringwald 2010-06-13 09:58:38 +00:00
parent e170797053
commit 231e1adb5d
2 changed files with 26 additions and 9 deletions

View File

@ -74,6 +74,6 @@ void de_add_data( uint8_t *seq, de_type_t type, uint16_t size, uint8_t *data);
int de_get_data_size(uint8_t * header);
#pragma mark SDP
void sdp_append_attributes_in_attributeIDList(uint8_t *record, uint8_t *attributeIDList, uint8_t *buffer, uint16_t maxBytes);
uint16_t 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);
int sdp_record_matches_service_search_pattern(uint8_t *record, uint8_t *serviceSearchPattern);

View File

@ -257,41 +257,58 @@ int sdp_attribute_list_constains_id(uint8_t *attributeIDList, uint16_t attribute
#pragma mark Append Attributes for AttributeIDList
// pre: buffer contains DES with 2 byte length field
// context: { buffer, data_size, maxBytes, attributeListID }
struct sdp_context_append_attributes {
uint8_t * buffer;
uint16_t dataSize;
uint16_t startIndex; // index of first to examine
uint16_t attributeIndex; // index over list
uint16_t maxBytes;
uint8_t *attributeIDList;
uint8_t moreData; // extra data: attributeIndex has to be examined next
};
static int sdp_traversal_append_attributes(uint8_t * element, de_type_t type, de_size_t size, void *my_context){
struct sdp_context_append_attributes * context = (struct sdp_context_append_attributes *) my_context;
// check each Attribute in root DES
int attributeDataSize = de_get_data_size(element);
int attributeLen = de_get_len(element);
// Attribute must be DES with more than sizeof(UINT16 element)
if (type == DE_DES && attributeDataSize >= 3){
// Attribute must be DES with more than sizeof(UINT16 element) and index at least continuation index
if (type == DE_DES && attributeDataSize >= 3 && context->attributeIndex >= context->startIndex){
int attributeIDPos = de_get_header_size(element);
de_size_t attributeIDSize = de_get_size_type(element+attributeIDPos);
if (attributeIDSize == DE_SIZE_16) {
uint16_t attributeID = READ_NET_16(element, attributeIDPos+1);
if ((context->dataSize + 3< context->maxBytes) && sdp_attribute_list_constains_id(context->attributeIDList, attributeID)){
// copy Attribute
memcpy( context->buffer + 3 + context->dataSize, element, attributeLen);
context->dataSize += attributeLen;
if ( sdp_attribute_list_constains_id(context->attributeIDList, attributeID)){
if (context->dataSize + 3< context->maxBytes) {
// copy Attribute
memcpy( context->buffer + 3 + context->dataSize, element, attributeLen);
context->dataSize += attributeLen;
} else {
// not enought space left -> continuation
context->moreData = 1;
return 1;
}
}
}
}
context->attributeIndex++;
return 0;
}
void sdp_append_attributes_in_attributeIDList(uint8_t *record, uint8_t *attributeIDList, uint8_t *buffer, uint16_t maxBytes){
// returns index of the next attribute index to process, if not all could be passed on, 0 = all processed
uint16_t sdp_append_attributes_in_attributeIDList(uint8_t *record, uint8_t *attributeIDList, uint16_t startIndex, uint16_t maxBytes, uint8_t *buffer){
struct sdp_context_append_attributes context;
context.buffer = buffer;
context.dataSize = READ_NET_16(buffer,1);
context.maxBytes = maxBytes;
context.attributeIndex = 0;
context.startIndex = startIndex;
context.moreData = 0;
context.attributeIDList = attributeIDList;
de_traverse_sequence(record, sdp_traversal_append_attributes, &context);
net_store_16(buffer, 1, context.dataSize);
if (!context.moreData) {
context.attributeIndex = 0;
}
return context.attributeIndex;
}
#pragma mark Get AttributeValue for AttributeID