mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-16 08:42:28 +00:00
use fallback to latin1 for invalid UTF8 names
This commit is contained in:
parent
3a3bdd0105
commit
c84ced3eff
@ -449,18 +449,26 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
// get lenght: first null byte or max 248 chars
|
// get lenght: first null byte or max 248 chars
|
||||||
int nameLen = 0;
|
int nameLen = 0;
|
||||||
while (nameLen < 248 && packet[9+nameLen]) nameLen++;
|
while (nameLen < 248 && packet[9+nameLen]) nameLen++;
|
||||||
|
// Bluetooth specification mandates UTF-8 encoding...
|
||||||
NSString *name = [[NSString alloc] initWithBytes:&packet[9] length:nameLen encoding:NSUTF8StringEncoding];
|
NSString *name = [[NSString alloc] initWithBytes:&packet[9] length:nameLen encoding:NSUTF8StringEncoding];
|
||||||
device.name = name;
|
// but fallback to latin-1 for non-standard products like old Microsoft Wireless Presenter
|
||||||
// set in device info
|
if (!name){
|
||||||
NSString *addrString = [[device addressString] retain];
|
name = [[NSString alloc] initWithBytes:&packet[9] length:nameLen encoding:NSISOLatin1StringEncoding];
|
||||||
NSMutableDictionary * deviceDict = [deviceInfo objectForKey:addrString];
|
}
|
||||||
if (!deviceDict){
|
// check again
|
||||||
deviceDict = [NSMutableDictionary dictionaryWithCapacity:3];
|
if (name){
|
||||||
[deviceInfo setObject:deviceDict forKey:addrString];
|
device.name = name;
|
||||||
|
// set in device info
|
||||||
|
NSString *addrString = [[device addressString] retain];
|
||||||
|
NSMutableDictionary * deviceDict = [deviceInfo objectForKey:addrString];
|
||||||
|
if (!deviceDict){
|
||||||
|
deviceDict = [NSMutableDictionary dictionaryWithCapacity:3];
|
||||||
|
[deviceInfo setObject:deviceDict forKey:addrString];
|
||||||
|
}
|
||||||
|
[deviceDict setObject:name forKey:PREFS_REMOTE_NAME];
|
||||||
|
[addrString release];
|
||||||
|
[self sendDeviceInfo:device];
|
||||||
}
|
}
|
||||||
[deviceDict setObject:name forKey:PREFS_REMOTE_NAME];
|
|
||||||
[addrString release];
|
|
||||||
[self sendDeviceInfo:device];
|
|
||||||
}
|
}
|
||||||
discoveryDeviceIndex++;
|
discoveryDeviceIndex++;
|
||||||
[self discoveryRemoteName];
|
[self discoveryRemoteName];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user