qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject svn commit: r1630791 - in /qpid/proton/branches/examples/proton-c/src: tests/parse-url.c util.c
Date Fri, 10 Oct 2014 12:41:43 GMT
Author: gsim
Date: Fri Oct 10 12:41:43 2014
New Revision: 1630791

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

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

Modified: qpid/proton/branches/examples/proton-c/src/tests/parse-url.c
URL: http://svn.apache.org/viewvc/qpid/proton/branches/examples/proton-c/src/tests/parse-url.c?rev=1630791&r1=1630790&r2=1630791&view=diff
==============================================================================
--- qpid/proton/branches/examples/proton-c/src/tests/parse-url.c (original)
+++ qpid/proton/branches/examples/proton-c/src/tests/parse-url.c Fri Oct 10 12:41:43 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/branches/examples/proton-c/src/util.c
URL: http://svn.apache.org/viewvc/qpid/proton/branches/examples/proton-c/src/util.c?rev=1630791&r1=1630790&r2=1630791&view=diff
==============================================================================
--- qpid/proton/branches/examples/proton-c/src/util.c (original)
+++ qpid/proton/branches/examples/proton-c/src/util.c Fri Oct 10 12:41:43 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


Mime
View raw message