Skip to content

Commit

Permalink
fix(linux): Parsing TXT record now closely follow RFC 6763.
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyost committed Nov 20, 2023
1 parent 8021657 commit f2e7d5b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/bonsoir_linux/lib/src/actions/action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract class AvahiBonsoirAction<T extends BonsoirEvent> extends BonsoirAction<
}

/// Triggered when an error occurs.
void onError(AvahiBonsoirError error) {
void onError(BonsoirLinuxError error) {
log(error.message);
_controller.addError(error);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bonsoir_linux/lib/src/actions/broadcast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class AvahiBonsoirBroadcast extends AvahiBonsoirAction<BonsoirBroadcastEvent> {
_sendServiceToAvahi();
break;
case AvahiEntryGroupState.AVAHI_ENTRY_GROUP_FAILURE:
onError(AvahiBonsoirError('Bonsoir service failed to broadcast : ${service.description}', event.error));
onError(BonsoirLinuxError('Bonsoir service failed to broadcast : ${service.description}', event.error));
break;
default:
onEvent(
Expand Down
12 changes: 6 additions & 6 deletions packages/bonsoir_linux/lib/src/actions/discovery/discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class AvahiBonsoirDiscovery extends AvahiBonsoirAction<BonsoirDiscoveryEvent> wi
Future<void> resolveService(BonsoirService service) async {
BonsoirService? serviceInstance = _findService(service.name, service.type);
if (serviceInstance == null) {
onError(AvahiBonsoirError('Trying to resolve an undiscovered service : ${service.name}', service.name));
onError(BonsoirLinuxError('Trying to resolve an undiscovered service : ${service.name}', service.name));
return;
}
_avahiHandler!.resolveService(this, serviceInstance, _foundServices[serviceInstance]!);
Expand Down Expand Up @@ -295,14 +295,14 @@ class AvahiBonsoirDiscovery extends AvahiBonsoirAction<BonsoirDiscoveryEvent> wi
currentIndex++;
if (currentIndex + lengthByte <= txtRecordData.length) {
String string = utf8.decode(txtRecordData.sublist(currentIndex, currentIndex + lengthByte));
List<String> parts = string.split('=');
int equalIndex = string.indexOf('=');
String key = string;
String value = '';
if (parts.length == 2) {
key = parts.first;
value = parts.last;
if (equalIndex != -1) {
key = string.substring(0, equalIndex);
value = string.substring(equalIndex + 1);
}
if (!result.containsKey(key)) {
if (!key.startsWith('=') && !result.containsKey(key)) {
result[key] = value;
}
currentIndex += lengthByte;
Expand Down
6 changes: 3 additions & 3 deletions packages/bonsoir_linux/lib/src/error.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/// Represents a Bonsoir error triggered on the Linux platform.
class AvahiBonsoirError implements Exception {
class BonsoirLinuxError implements Exception {
/// The message.
final String message;

/// The (possibly null) error code / message.
final Object? error;

/// Creates a new Avahi Bonsoir error instance.
AvahiBonsoirError(this.message, [this.error]);
BonsoirLinuxError(this.message, [this.error]);

@override
String toString() {
String string = 'AvahiBonsoirError';
String string = 'BonsoirLinuxError';
if (error != null) {
string += '(${error})';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bonsoir_linux/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ flutter:
implements: bonsoir
platforms:
linux:
dartPluginClass: AvahiBonsoir
dartPluginClass: BonsoirLinux

dependencies:
flutter:
Expand Down

0 comments on commit f2e7d5b

Please sign in to comment.