Revert "xmpp-parsers: Remove optional child from sm element"

Link Mauve created

This reverts commit 0a1b291574cb02090f26798e7c322b0db2ce42e7 once again.

This is currently required to connect to Prosody, otherwise the parser
will choke on the extra undocumented child.

I still wonder if required (4e0cd5d96bfe92f527dd36c51fd1e41526426f7c)
would be useful to support then, as it might also be found in the wild.

Change summary

parsers/ChangeLog    |  2 ++
parsers/src/sasl2.rs |  2 +-
parsers/src/sm.rs    | 12 +++++++++---
3 files changed, 12 insertions(+), 4 deletions(-)

Detailed changes

parsers/ChangeLog 🔗

@@ -109,6 +109,8 @@ XXXX-YY-ZZ RELEASER <admin@example.com>
       - JSON Containers (XEP-0335) (!546)
       - Verifying HTTP Requests via XMPP (XEP-0070)
     * Improvements:
+      - Add support for undocumented `<optional/> in XEP-0198 feature
+        advertisment, for compatibility with servers in the wild.
       - Add support application-specific error conditions in XEP-0198
       - Keep unsupported vCard elements as `minidom::Element`, so that they
         get serialized back instead of being dropped.  We now also test for

parsers/src/sasl2.rs 🔗

@@ -269,7 +269,7 @@ mod tests {
 
         let inline = auth.inline.unwrap();
         assert_eq!(inline.bind2.unwrap().inline_features.len(), 0);
-        assert_eq!(inline.sm.unwrap(), StreamManagement);
+        assert_eq!(inline.sm.unwrap(), StreamManagement { optional: false });
         assert_eq!(inline.payloads.len(), 0);
     }
 

parsers/src/sm.rs 🔗

@@ -136,7 +136,13 @@ pub struct Resumed {
 /// Represents availability of Stream Management in `<stream:features/>`.
 #[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
 #[xml(namespace = ns::SM, name = "sm")]
-pub struct StreamManagement;
+pub struct StreamManagement {
+    /// Undocumented `<optional/>` flag.
+    // TODO: Remove this flag once servers in the wild have been updated to not send it, as it is
+    // completely undocumented in XEP-0198, only appearing in the XML Schema before 1.6.3.
+    #[xml(flag)]
+    pub optional: bool,
+}
 
 /// Application-specific error condition to use when the peer acknowledges
 /// more stanzas than the local side has sent.
@@ -215,7 +221,7 @@ mod tests {
         assert_size!(R, 0);
         assert_size!(Resume, 16);
         assert_size!(Resumed, 16);
-        assert_size!(StreamManagement, 0);
+        assert_size!(StreamManagement, 1);
         assert_size!(HandledCountTooHigh, 8);
     }
 
@@ -230,7 +236,7 @@ mod tests {
         assert_size!(R, 0);
         assert_size!(Resume, 32);
         assert_size!(Resumed, 32);
-        assert_size!(StreamManagement, 0);
+        assert_size!(StreamManagement, 1);
         assert_size!(HandledCountTooHigh, 8);
     }