onSasl2FeaturesReceived method

  1. @override
Future<List<XMLNode>> onSasl2FeaturesReceived(
  1. XMLNode sasl2Features
)
override

Called by the SASL2 negotiator when we received the SASL2 stream features sasl2Features. The return value is a list of XML elements that should be added to the SASL2 nonza. This method is only called when the element contains an item with xmlns equal to negotiatingXmlns.

Implementation

@override
Future<List<XMLNode>> onSasl2FeaturesReceived(XMLNode sasl2Features) async {
  final children = List<XMLNode>.empty(growable: true);
  if (_negotiators.isNotEmpty) {
    final inline = sasl2Features
        .firstTag('inline')!
        .firstTag('bind', xmlns: bind2Xmlns)!
        .firstTag('inline');
    if (inline != null) {
      final features = inline.children
          .where((child) => child.tag == 'feature')
          .map((child) => child.attributes['var']! as String)
          .toList();

      // Only call the negotiators if Bind2 allows doing stuff inline
      for (final negotiator in _negotiators) {
        children.addAll(await negotiator.onBind2FeaturesReceived(features));
      }
    }
  }

  return [
    XMLNode.xmlns(
      tag: 'bind',
      xmlns: bind2Xmlns,
      children: [
        if (tag != null)
          XMLNode(
            tag: 'tag',
            text: tag,
          ),
        ...children,
      ],
    ),
  ];
}