You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2014/04/04 21:02:39 UTC
svn commit: r1584865 - in /qpid/proton/trunk/proton-c/src: tests/parse-url.c
util.c
Author: rhs
Date: Fri Apr 4 19:02:38 2014
New Revision: 1584865
URL: http://svn.apache.org/r1584865
Log:
PROTON-553: made pni_parse_url do url decoding on user and password
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=1584865&r1=1584864&r2=1584865&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/tests/parse-url.c (original)
+++ qpid/proton/trunk/proton-c/src/tests/parse-url.c Fri Apr 4 19:02:38 2014
@@ -91,5 +91,10 @@ int main(int argc, char **argv)
assert(test_url_parse("amqp://bigbird@host/queue@host", "amqp", "bigbird", 0, "host", 0, "queue@host"));
assert(test_url_parse("amqp://host/queue@host", "amqp", 0, 0, "host", 0, "queue@host"));
assert(test_url_parse("amqp://host:9765/queue@host", "amqp", 0, 0, "host", "9765", "queue@host"));
+ assert(test_url_parse("user:pass%2fword@host", 0, "user", "pass/word", "host", 0, 0));
+ assert(test_url_parse("user:pass%2Fword@host", 0, "user", "pass/word", "host", 0, 0));
+ 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));
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=1584865&r1=1584864&r2=1584865&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/util.c (original)
+++ qpid/proton/trunk/proton-c/src/util.c Fri Apr 4 19:02:38 2014
@@ -101,6 +101,42 @@ void pn_print_data(const char *bytes, si
pn_fprint_data(stdout, bytes, size);
}
+void pni_urldecode(const char *src, char *dst)
+{
+ const char *in = src;
+ char *out = dst;
+ while (*in != '\0')
+ {
+ if ('%' == *in)
+ {
+ if ((in[1] != '\0') && (in[2] != '\0'))
+ {
+ char esc[3];
+ esc[0] = in[1];
+ esc[1] = in[2];
+ esc[2] = '\0';
+ unsigned long d = strtoul(esc, NULL, 16);
+ *out = (char)d;
+ in += 3;
+ out++;
+ }
+ else
+ {
+ *out = *in;
+ in++;
+ out++;
+ }
+ }
+ else
+ {
+ *out = *in;
+ in++;
+ out++;
+ }
+ }
+ *out = '\0';
+}
+
// Parse URL syntax:
// [ <scheme> :// ] [ <user> [ : <password> ] @ ] <host> [ : <port> ] [ / <path> ]
// <user>, <password>, <host>, <port> cannot contain any of '@', ':', '/'
@@ -152,6 +188,8 @@ void pni_parse_url(char *url, char **sch
*port = colon + 1;
}
+ if (*user) pni_urldecode(*user, *user);
+ if (*pass) pni_urldecode(*pass, *pass);
}
void pn_vfatal(const char *fmt, va_list ap)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org