qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tr...@apache.org
Subject svn commit: r1583673 - in /qpid/proton/trunk: proton-c/src/ proton-c/src/posix/ proton-c/src/tests/ proton-j/src/main/java/org/apache/qpid/proton/messenger/impl/ proton-j/src/test/java/org/apache/qpid/proton/messenger/impl/
Date Tue, 01 Apr 2014 14:00:47 GMT
Author: tross
Date: Tue Apr  1 14:00:47 2014
New Revision: 1583673

URL: http://svn.apache.org/r1583673
Log:
PROTON-548 - Added IPv6 url syntax to C and Java URL parsers.  Added IPv6 handling to C driver.

Modified:
    qpid/proton/trunk/proton-c/src/posix/io.c
    qpid/proton/trunk/proton-c/src/tests/parse-url.c
    qpid/proton/trunk/proton-c/src/util.c
    qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/messenger/impl/Address.java
    qpid/proton/trunk/proton-j/src/test/java/org/apache/qpid/proton/messenger/impl/AddressTest.java

Modified: qpid/proton/trunk/proton-c/src/posix/io.c
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/posix/io.c?rev=1583673&r1=1583672&r2=1583673&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/posix/io.c (original)
+++ qpid/proton/trunk/proton-c/src/posix/io.c Tue Apr  1 14:00:47 2014
@@ -119,7 +119,7 @@ static void pn_configure_sock(pn_io_t *i
   }
 }
 
-static inline int pn_create_socket(void);
+static inline int pn_create_socket(int af);
 
 pn_socket_t pn_listen(pn_io_t *io, const char *host, const char *port)
 {
@@ -130,7 +130,7 @@ pn_socket_t pn_listen(pn_io_t *io, const
     return PN_INVALID_SOCKET;
   }
 
-  pn_socket_t sock = pn_create_socket();
+  pn_socket_t sock = pn_create_socket(addr->ai_family);
   if (sock == PN_INVALID_SOCKET) {
     pn_i_error_from_errno(io->error, "pn_create_socket");
     return PN_INVALID_SOCKET;
@@ -170,7 +170,7 @@ pn_socket_t pn_connect(pn_io_t *io, cons
     return PN_INVALID_SOCKET;
   }
 
-  pn_socket_t sock = pn_create_socket();
+  pn_socket_t sock = pn_create_socket(addr->ai_family);
   if (sock == PN_INVALID_SOCKET) {
     pn_i_error_from_errno(io->error, "pn_create_socket");
     return PN_INVALID_SOCKET;
@@ -195,7 +195,7 @@ pn_socket_t pn_connect(pn_io_t *io, cons
 pn_socket_t pn_accept(pn_io_t *io, pn_socket_t socket, char *name, size_t size)
 {
   struct sockaddr_in addr = {0};
-  addr.sin_family = AF_INET;
+  addr.sin_family = AF_UNSPEC;
   socklen_t addrlen = sizeof(addr);
   pn_socket_t sock = accept(socket, (struct sockaddr *) &addr, &addrlen);
   if (sock == PN_INVALID_SOCKET) {
@@ -224,8 +224,8 @@ ssize_t pn_send(pn_io_t *io, pn_socket_t
   return count;
 }
 
-static inline int pn_create_socket(void) {
-  return socket(AF_INET, SOCK_STREAM, getprotobyname("tcp")->p_proto);
+static inline int pn_create_socket(int af) {
+  return socket(af, SOCK_STREAM, getprotobyname("tcp")->p_proto);
 }
 #elif defined(SO_NOSIGPIPE)
 ssize_t pn_send(pn_io_t *io, pn_socket_t socket, const void *buf, size_t size) {
@@ -234,8 +234,8 @@ ssize_t pn_send(pn_io_t *io, pn_socket_t
   return count;
 }
 
-static inline int pn_create_socket(void) {
-  int sock = socket(AF_INET, SOCK_STREAM, getprotobyname("tcp")->p_proto);
+static inline int pn_create_socket(int af) {
+  int sock = socket(af, SOCK_STREAM, getprotobyname("tcp")->p_proto);
   if (sock == -1) return sock;
 
   int optval = 1;

Modified: qpid/proton/trunk/proton-c/src/tests/parse-url.c
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/tests/parse-url.c?rev=1583673&r1=1583672&r2=1583673&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/tests/parse-url.c (original)
+++ qpid/proton/trunk/proton-c/src/tests/parse-url.c Tue Apr  1 14:00:47 2014
@@ -74,6 +74,19 @@ int main(int argc, char **argv)
   assert(test_url_parse("user:1243^&^:pw@host:423", 0, "user", "1243^&^:pw", "host",
"423", 0));
   assert(test_url_parse("user:1243^&^:pw@host:423/Foo.bar:90087", 0, "user", "1243^&^:pw",
"host", "423", "Foo.bar:90087"));
   assert(test_url_parse("user:1243^&^:pw@host:423/Foo.bar:90087@somewhere", 0, "user",
"1243^&^:pw", "host", "423", "Foo.bar:90087@somewhere"));
+  assert(test_url_parse("[::1]", 0, 0, 0, "::1", 0, 0));
+  assert(test_url_parse("[::1]:amqp", 0, 0, 0, "::1", "amqp", 0));
+  assert(test_url_parse("user@[::1]", 0, "user", 0, "::1", 0, 0));
+  assert(test_url_parse("user@[::1]:amqp", 0, "user", 0, "::1", "amqp", 0));
+  assert(test_url_parse("user:1243^&^:pw@[::1]:amqp", 0, "user", "1243^&^:pw", "::1",
"amqp", 0));
+  assert(test_url_parse("user:1243^&^:pw@[::1]:amqp/Foo.bar:90087", 0, "user", "1243^&^:pw",
"::1", "amqp", "Foo.bar:90087"));
+  assert(test_url_parse("user:1243^&^:pw@[::1:amqp/Foo.bar:90087", 0, "user", "1243^&^:pw",
"[", ":1:amqp", "Foo.bar:90087"));
+  assert(test_url_parse("user:1243^&^:pw@::1]:amqp/Foo.bar:90087", 0, "user", "1243^&^:pw",
"", ":1]:amqp", "Foo.bar:90087"));
+  assert(test_url_parse("amqp://user@[::1]", "amqp", "user", 0, "::1", 0, 0));
+  assert(test_url_parse("amqp://user@[::1]:amqp", "amqp", "user", 0, "::1", "amqp", 0));
+  assert(test_url_parse("amqp://user@[1234:52:0:1260:f2de:f1ff:fe59:8f87]:amqp", "amqp",
"user", 0, "1234:52:0:1260:f2de:f1ff:fe59:8f87", "amqp", 0));
+  assert(test_url_parse("amqp://user:1243^&^:pw@[::1]:amqp", "amqp", "user", "1243^&^:pw",
"::1", "amqp", 0));
+  assert(test_url_parse("amqp://user:1243^&^:pw@[::1]:amqp/Foo.bar:90087", "amqp", "user",
"1243^&^:pw", "::1", "amqp", "Foo.bar:90087"));
   assert(test_url_parse("amqp://host", "amqp", 0, 0, "host", 0, 0));
   assert(test_url_parse("amqp://user@host", "amqp", "user", 0, "host", 0, 0));
   assert(test_url_parse("amqp://user@host/path:%", "amqp", "user", 0, "host", 0, "path:%"));

Modified: qpid/proton/trunk/proton-c/src/util.c
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/util.c?rev=1583673&r1=1583672&r2=1583673&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/util.c (original)
+++ qpid/proton/trunk/proton-c/src/util.c Tue Apr  1 14:00:47 2014
@@ -141,8 +141,17 @@ void pni_parse_url(char *url, char **sch
   }
 
   *host = url;
+  char *open = (*url == '[') ? url : 0;
+  if (open) {
+    char *close = strchr(open, ']');
+    if (close) {
+        *host = open + 1;
+        *close = '\0';
+        url = close + 1;
+    }
+  }
 
-  char *colon = strchr(*host, ':');
+  char *colon = strchr(url, ':');
   if (colon) {
     *colon = '\0';
     *port = colon + 1;

Modified: qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/messenger/impl/Address.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/messenger/impl/Address.java?rev=1583673&r1=1583672&r2=1583673&view=diff
==============================================================================
--- qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/messenger/impl/Address.java
(original)
+++ qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/messenger/impl/Address.java
Tue Apr  1 14:00:47 2014
@@ -87,12 +87,24 @@ class Address
             hp = uphp;
         }
 
-        int colon = hp.indexOf(':');
-        if (colon >= 0) {
-            _host = hp.substring(0, colon);
-            _port = hp.substring(colon + 1);
-        } else {
-            _host = hp;
+        if (hp.startsWith("[")) {
+            int close = hp.indexOf(']');
+            if (close >= 0) {
+                _host = hp.substring(1, close);
+                if (hp.substring(close + 1).startsWith(":")) {
+                    _port = hp.substring(close + 2);
+                }
+            }
+        }
+
+        if (_host == null) {
+            int colon = hp.indexOf(':');
+            if (colon >= 0) {
+                _host = hp.substring(0, colon);
+                _port = hp.substring(colon + 1);
+            } else {
+                _host = hp;
+            }
         }
 
         if (_host.startsWith("~")) {

Modified: qpid/proton/trunk/proton-j/src/test/java/org/apache/qpid/proton/messenger/impl/AddressTest.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/src/test/java/org/apache/qpid/proton/messenger/impl/AddressTest.java?rev=1583673&r1=1583672&r2=1583673&view=diff
==============================================================================
--- qpid/proton/trunk/proton-j/src/test/java/org/apache/qpid/proton/messenger/impl/AddressTest.java
(original)
+++ qpid/proton/trunk/proton-j/src/test/java/org/apache/qpid/proton/messenger/impl/AddressTest.java
Tue Apr  1 14:00:47 2014
@@ -24,7 +24,20 @@ public class AddressTest {
 		testParse("user@host", null, "user", null, "host", null, null);
 		testParse("user:1243^&^:pw@host:423", null, "user", "1243^&^:pw", "host", "423",
null);
 		testParse("user:1243^&^:pw@host:423/Foo.bar:90087", null, "user", "1243^&^:pw",
"host", "423", "Foo.bar:90087");
-		testParse("user:1243^&^:pw@host:423/Foo.bar:90087@somewhere", null, "user", "1243^&^:pw",
"host", "423", "Foo.bar:90087@somewhere");
+        testParse("user:1243^&^:pw@host:423/Foo.bar:90087@somewhere", null, "user", "1243^&^:pw",
"host", "423", "Foo.bar:90087@somewhere");
+        testParse("[::1]", null, null, null, "::1", null, null);
+        testParse("[::1]:amqp", null, null, null, "::1", "amqp", null);
+        testParse("user@[::1]", null, "user", null, "::1", null, null);
+        testParse("user@[::1]:amqp", null, "user", null, "::1", "amqp", null);
+        testParse("user:1243^&^:pw@[::1]:amqp", null, "user", "1243^&^:pw", "::1",
"amqp", null);
+        testParse("user:1243^&^:pw@[::1]:amqp/Foo.bar:90087", null, "user", "1243^&^:pw",
"::1", "amqp", "Foo.bar:90087");
+        testParse("user:1243^&^:pw@[::1:amqp/Foo.bar:90087", null, "user", "1243^&^:pw",
"[", ":1:amqp", "Foo.bar:90087");
+        testParse("user:1243^&^:pw@::1]:amqp/Foo.bar:90087", null, "user", "1243^&^:pw",
"", ":1]:amqp", "Foo.bar:90087");
+        testParse("amqp://user@[::1]", "amqp", "user", null, "::1", null, null);
+        testParse("amqp://user@[::1]:amqp", "amqp", "user", null, "::1", "amqp", null);
+        testParse("amqp://user@[1234:52:0:1260:f2de:f1ff:fe59:8f87]:amqp", "amqp", "user",
null, "1234:52:0:1260:f2de:f1ff:fe59:8f87", "amqp", null);
+        testParse("amqp://user:1243^&^:pw@[::1]:amqp", "amqp", "user", "1243^&^:pw",
"::1", "amqp", null);
+        testParse("amqp://user:1243^&^:pw@[::1]:amqp/Foo.bar:90087", "amqp", "user",
"1243^&^:pw", "::1", "amqp", "Foo.bar:90087");
 		testParse("amqp://host", "amqp", null, null, "host", null, null);
 		testParse("amqp://user@host", "amqp", "user", null, "host", null, null);
 		testParse("amqp://user@host/path:%", "amqp", "user", null, "host", null, "path:%");



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


Mime
View raw message