You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2014/09/04 07:09:04 UTC

svn commit: r1622400 - in /qpid/proton/trunk/proton-c/src: tests/parse-url.c util.c

Author: astitcher
Date: Thu Sep  4 05:09:04 2014
New Revision: 1622400

URL: http://svn.apache.org/r1622400
Log:
PROTON-655: Fix url parsing to cope with ActiveMQ generated URLS
- Also add some more unit test urls

Modified:
    qpid/proton/trunk/proton-c/src/tests/parse-url.c
    qpid/proton/trunk/proton-c/src/util.c

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=1622400&r1=1622399&r2=1622400&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/tests/parse-url.c (original)
+++ qpid/proton/trunk/proton-c/src/tests/parse-url.c Thu Sep  4 05:09:04 2014
@@ -64,6 +64,8 @@ static bool test_url_parse(const char* u
 
 int main(int argc, char **argv)
 {
+  assert(test_url_parse("", 0, 0, 0, "", 0, 0));
+  assert(test_url_parse("/Foo.bar:90087@somewhere", 0, 0, 0, "", 0, "Foo.bar:90087@somewhere"));
   assert(test_url_parse("host", 0, 0, 0, "host", 0, 0));
   assert(test_url_parse("host:423", 0, 0, 0, "host", "423", 0));
   assert(test_url_parse("user@host", 0, "user", 0, "host", 0, 0));
@@ -96,5 +98,10 @@ int main(int argc, char **argv)
   assert(test_url_parse("us%2fer:password@host", 0, "us/er", "password", "host", 0, 0));
   assert(test_url_parse("us%2Fer:password@host", 0, "us/er", "password", "host", 0, 0));
   assert(test_url_parse("user:pass%2fword%@host", 0, "user", "pass/word%", "host", 0, 0));
+  assert(test_url_parse("localhost/temp-queue://ID:ganymede-36663-1408448359876-2:123:0", 0, 0, 0, "localhost", 0, "temp-queue://ID:ganymede-36663-1408448359876-2:123:0"));
+  assert(test_url_parse("/temp-queue://ID:ganymede-36663-1408448359876-2:123:0", 0, 0, 0, "", 0, "temp-queue://ID:ganymede-36663-1408448359876-2:123:0"));
+  assert(test_url_parse("amqp://localhost/temp-queue://ID:ganymede-36663-1408448359876-2:123:0", "amqp", 0, 0, "localhost", 0, "temp-queue://ID:ganymede-36663-1408448359876-2:123:0"));
+  // Really perverse url
+  assert(test_url_parse("://:@://:", "", "", "", "", "", "/:"));
   return 0;
 }

Modified: qpid/proton/trunk/proton-c/src/util.c
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/util.c?rev=1622400&r1=1622399&r2=1622400&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/util.c (original)
+++ qpid/proton/trunk/proton-c/src/util.c Thu Sep  4 05:09:04 2014
@@ -139,20 +139,28 @@ void pni_urldecode(const char *src, char
 
 // Parse URL syntax:
 // [ <scheme> :// ] [ <user> [ : <password> ] @ ] <host> [ : <port> ] [ / <path> ]
-// <user>, <password>, <host>, <port> cannot contain any of '@', ':', '/'
+// <scheme>, <user>, <password>, <port> cannot contain any of '@', ':', '/'
+// If the first character of <host> is '[' then it can contain any character up to ']' (this is to allow IPv6
+// literal syntax). Otherwise it also cannot contain '@', ':', '/'
+// <host> is not optional but it can be null! If it is not present an empty string will be returned
 // <path> can contain any character
 void pni_parse_url(char *url, char **scheme, char **user, char **pass, char **host, char **port, char **path)
 {
   if (!url) return;
 
-  char *scheme_end = strstr(url, "://");
-  if (scheme_end) {
-    *scheme_end = '\0';
-    *scheme = url;
-    url = scheme_end + 3;
+  char *slash = strchr(url, '/');
+
+  if (slash && slash>url) {
+    char *scheme_end = strstr(slash-1, "://");
+
+    if (scheme_end && scheme_end<slash) {
+      *scheme_end = '\0';
+      *scheme = url;
+      url = scheme_end + 3;
+      slash = strchr(url, '/');
+    }
   }
 
-  char *slash = strchr(url, '/');
   if (slash) {
     *slash = '\0';
     *path = slash + 1;



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