mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-01 04:20:33 +00:00
store client connection in service_record_item_t, set connection on register, check connection on unregister, remove service records for client on disconnect
This commit is contained in:
parent
c1b43b8cbf
commit
41901ee404
24
src/sdp.c
24
src/sdp.c
@ -50,6 +50,9 @@ typedef struct {
|
|||||||
// linked list - assert: first field
|
// linked list - assert: first field
|
||||||
linked_item_t item;
|
linked_item_t item;
|
||||||
|
|
||||||
|
// client connection
|
||||||
|
connection_t * connection;
|
||||||
|
|
||||||
// data is contained in same memory
|
// data is contained in same memory
|
||||||
uint32_t service_record_handle;
|
uint32_t service_record_handle;
|
||||||
uint8_t service_record[0];
|
uint8_t service_record[0];
|
||||||
@ -130,6 +133,9 @@ uint32_t sdp_register_service_internal(connection_t *connection, uint8_t * recor
|
|||||||
// alloc memory for new service_record_item
|
// alloc memory for new service_record_item
|
||||||
service_record_item_t * newRecordItem = (service_record_item_t *) malloc(recordSize + sizeof(service_record_item_t));
|
service_record_item_t * newRecordItem = (service_record_item_t *) malloc(recordSize + sizeof(service_record_item_t));
|
||||||
if (!newRecordItem) return 0;
|
if (!newRecordItem) return 0;
|
||||||
|
|
||||||
|
// link new service item to client connection
|
||||||
|
newRecordItem->connection = connection;
|
||||||
|
|
||||||
// set new handle
|
// set new handle
|
||||||
newRecordItem->service_record_handle = record_handle;
|
newRecordItem->service_record_handle = record_handle;
|
||||||
@ -160,15 +166,27 @@ uint32_t sdp_register_service_internal(connection_t *connection, uint8_t * recor
|
|||||||
}
|
}
|
||||||
|
|
||||||
// unregister service record internally
|
// unregister service record internally
|
||||||
|
//
|
||||||
|
// makes sure one client cannot remove service records of other clients
|
||||||
|
//
|
||||||
void sdp_unregister_service_internal(connection_t *connection, uint32_t service_record_handle){
|
void sdp_unregister_service_internal(connection_t *connection, uint32_t service_record_handle){
|
||||||
service_record_item_t * record_item = sdp_get_record_for_handle(service_record_handle);
|
service_record_item_t * record_item = sdp_get_record_for_handle(service_record_handle);
|
||||||
if (record_item) {
|
if (record_item && record_item->connection == connection) {
|
||||||
linked_list_remove(&sdp_service_records, (linked_item_t *) record_item);
|
linked_list_remove(&sdp_service_records, (linked_item_t *) record_item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove all service record for a client
|
// remove all service record for a client connection
|
||||||
void sdp_unregister_services_for_connection(connection_t *connectino){
|
void sdp_unregister_services_for_connection(connection_t *connection){
|
||||||
|
linked_item_t *it = (linked_item_t *) &sdp_service_records;
|
||||||
|
while (it->next){
|
||||||
|
if (((service_record_item_t *)it->next)->connection == connection){
|
||||||
|
it->next = it->next->next;
|
||||||
|
free(it);
|
||||||
|
} else {
|
||||||
|
it = it->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PDU
|
// PDU
|
||||||
|
Loading…
x
Reference in New Issue
Block a user