qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astitc...@apache.org
Subject [1/4] qpid-proton git commit: PROTON-804: On an error in protocol autodetection switch to a special layer that just returns end of stream for both input and output.
Date Fri, 13 Feb 2015 20:36:28 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master 566baf1e0 -> fc91e9bfe


PROTON-804: On an error in protocol autodetection switch to a special
layer that just returns end of stream for both input and output.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/fc91e9bf
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/fc91e9bf
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/fc91e9bf

Branch: refs/heads/master
Commit: fc91e9bfef72ca316fd2391301674bc5897f61be
Parents: bc91eb6
Author: Andrew Stitcher <astitcher@apache.org>
Authored: Tue Jan 27 15:33:10 2015 -0500
Committer: Andrew Stitcher <astitcher@apache.org>
Committed: Fri Feb 13 15:28:30 2015 -0500

----------------------------------------------------------------------
 proton-c/src/transport/transport.c     | 34 +++++++++++++++++++++++++++--
 tests/python/proton_tests/transport.py | 27 +++++++++++++++++++++++
 2 files changed, 59 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/fc91e9bf/proton-c/src/transport/transport.c
----------------------------------------------------------------------
diff --git a/proton-c/src/transport/transport.c b/proton-c/src/transport/transport.c
index 0cc4697..c49044d 100644
--- a/proton-c/src/transport/transport.c
+++ b/proton-c/src/transport/transport.c
@@ -103,6 +103,9 @@ static void pni_default_tracer(pn_transport_t *transport, const char *message)
 static ssize_t pn_io_layer_input_passthru(pn_transport_t *, unsigned int, const char *, size_t
);
 static ssize_t pn_io_layer_output_passthru(pn_transport_t *, unsigned int, char *, size_t
);
 
+static ssize_t pn_io_layer_input_error(pn_transport_t *, unsigned int, const char *, size_t
);
+static ssize_t pn_io_layer_output_error(pn_transport_t *, unsigned int, char *, size_t );
+
 static ssize_t pn_io_layer_input_setup(pn_transport_t *transport, unsigned int layer, const
char *bytes, size_t available);
 static ssize_t pn_io_layer_output_setup(pn_transport_t *transport, unsigned int layer, char
*bytes, size_t available);
 
@@ -164,6 +167,13 @@ const pn_io_layer_t pni_passthru_layer = {
     NULL
 };
 
+const pn_io_layer_t pni_error_layer = {
+    pn_io_layer_input_error,
+    pn_io_layer_output_error,
+    NULL,
+    NULL
+};
+
 /* Set up the transport protocol layers depending on what is configured */
 static void pn_io_layer_setup(pn_transport_t *transport, unsigned int layer)
 {
@@ -203,6 +213,11 @@ ssize_t pn_io_layer_output_setup(pn_transport_t *transport, unsigned
int layer,
   return transport->io_layers[layer]->process_output(transport, layer, bytes, available);
 }
 
+static void pni_set_error_layer(pn_transport_t *transport)
+{
+    transport->io_layers[0] = &pni_error_layer;
+}
+
 // Autodetect the layer by reading the protocol header
 ssize_t pn_io_layer_input_autodetect(pn_transport_t *transport, unsigned int layer, const
char *bytes, size_t available)
 {
@@ -210,6 +225,7 @@ ssize_t pn_io_layer_input_autodetect(pn_transport_t *transport, unsigned
int lay
   bool eos = pn_transport_capacity(transport)==PN_EOS;
   if (eos && available==0) {
     pn_do_error(transport, "amqp:connection:framing-error", "No valid protocol header found");
+    pni_set_error_layer(transport);
     return PN_EOS;
   }
   pni_protocol_type_t protocol = pni_sniff_header(bytes, available);
@@ -246,7 +262,8 @@ ssize_t pn_io_layer_input_autodetect(pn_transport_t *transport, unsigned
int lay
       } else {
         pn_do_error(transport, "amqp:connection:policy-error",
                     "Client skipped SASL exchange - forbidden");
-        return PN_EOS;
+        pni_set_error_layer(transport);
+        return 8;
       }
     }
     transport->io_layers[layer] = &amqp_write_header_layer;
@@ -270,7 +287,8 @@ ssize_t pn_io_layer_input_autodetect(pn_transport_t *transport, unsigned
int lay
   pn_do_error(transport, "amqp:connection:framing-error",
               "%s: '%s'%s", error, quoted,
               !eos ? "" : " (connection aborted)");
-  return PN_EOS;
+  pni_set_error_layer(transport);
+  return 0;
 }
 
 // We don't know what the output should be - do nothing
@@ -295,6 +313,18 @@ ssize_t pn_io_layer_output_passthru(pn_transport_t *transport, unsigned
int laye
     return PN_EOS;
 }
 
+/** Input handler after detected error */
+ssize_t pn_io_layer_input_error(pn_transport_t *transport, unsigned int layer, const char
*data, size_t available)
+{
+    return PN_EOS;
+}
+
+/** Output handler after detected error */
+ssize_t pn_io_layer_output_error(pn_transport_t *transport, unsigned int layer, char *data,
size_t available)
+{
+    return PN_EOS;
+}
+
 static void pn_transport_initialize(void *object)
 {
   pn_transport_t *transport = (pn_transport_t *)object;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/fc91e9bf/tests/python/proton_tests/transport.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/transport.py b/tests/python/proton_tests/transport.py
index e5bbe24..dcf7636 100644
--- a/tests/python/proton_tests/transport.py
+++ b/tests/python/proton_tests/transport.py
@@ -20,6 +20,7 @@
 import os, common
 from proton import *
 
+
 class Test(common.Test):
   pass
 
@@ -161,3 +162,29 @@ class TransportTest(Test):
     self.peer.push(dat1)
     self.peer.push(dat2[len(dat1):])
     self.peer.push(dat3)
+
+  def testEOSAfterSASL(self):
+    srv = Transport(mode=Transport.SERVER)
+    srv.sasl().mechanisms("ANONYMOUS")
+    srv.sasl().done(SASL.OK)
+
+    self.peer.sasl().mechanisms("ANONYMOUS")
+
+    # this should send over the sasl header plus a sasl-init set up
+    # for anonymous
+    p = self.peer.pending()
+    srv.push(self.peer.peek(p))
+    self.peer.pop(p)
+
+    # now we send EOS
+    srv.close_tail()
+
+    # the server may send an error back
+    p = srv.pending()
+    while p>0:
+      self.peer.push(srv.peek(p))
+      srv.pop(p)
+      p = srv.pending()
+
+    # server closed
+    assert srv.pending() < 0


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message