summaryrefslogtreecommitdiff
path: root/librabbitmq/amqp_url.c
diff options
context:
space:
mode:
authorAlan Antonuk <alan.antonuk@gmail.com>2013-04-08 14:52:53 -0700
committerAlan Antonuk <alan.antonuk@gmail.com>2013-04-08 14:52:53 -0700
commitad2b116059e22d393b7e44ad54f345a3fb4e267b (patch)
treecfd98876757f85d9fe7bfe56d179bd5fb63a8ff0 /librabbitmq/amqp_url.c
parentf3074030723b840690458983b63c746549aa3bd5 (diff)
downloadrabbitmq-c-github-ask-ad2b116059e22d393b7e44ad54f345a3fb4e267b.tar.gz
Formatted source code with astyle utilty
Diffstat (limited to 'librabbitmq/amqp_url.c')
-rw-r--r--librabbitmq/amqp_url.c298
1 files changed, 153 insertions, 145 deletions
diff --git a/librabbitmq/amqp_url.c b/librabbitmq/amqp_url.c
index 367376d..d3e6724 100644
--- a/librabbitmq/amqp_url.c
+++ b/librabbitmq/amqp_url.c
@@ -43,159 +43,167 @@
void amqp_default_connection_info(struct amqp_connection_info *ci)
{
- /* Apply defaults */
- ci->user = "guest";
- ci->password = "guest";
- ci->host = "localhost";
- ci->port = 5672;
- ci->vhost = "/";
+ /* Apply defaults */
+ ci->user = "guest";
+ ci->password = "guest";
+ ci->host = "localhost";
+ ci->port = 5672;
+ ci->vhost = "/";
}
/* Scan for the next delimiter, handling percent-encodings on the way. */
static char find_delim(char **pp, int colon_and_at_sign_are_delims)
{
- char *from = *pp;
- char *to = from;
-
- for (;;) {
- char ch = *from++;
-
- switch (ch) {
- case ':':
- case '@':
- if (!colon_and_at_sign_are_delims) {
- *to++ = ch;
- break;
- }
-
- /* fall through */
- case 0:
- case '/':
- case '?':
- case '#':
- case '[':
- case ']':
- *to = 0;
- *pp = from;
- return ch;
-
- case '%': {
- unsigned int val;
- int chars;
- int res = sscanf(from, "%2x%n", &val, &chars);
-
- if (res == EOF || res < 1 || chars != 2)
- /* Return a surprising delimiter to
- force an error. */
- return '%';
-
- *to++ = val;
- from += 2;
- break;
- }
-
- default:
- *to++ = ch;
- break;
- }
- }
+ char *from = *pp;
+ char *to = from;
+
+ for (;;) {
+ char ch = *from++;
+
+ switch (ch) {
+ case ':':
+ case '@':
+ if (!colon_and_at_sign_are_delims) {
+ *to++ = ch;
+ break;
+ }
+
+ /* fall through */
+ case 0:
+ case '/':
+ case '?':
+ case '#':
+ case '[':
+ case ']':
+ *to = 0;
+ *pp = from;
+ return ch;
+
+ case '%': {
+ unsigned int val;
+ int chars;
+ int res = sscanf(from, "%2x%n", &val, &chars);
+
+ if (res == EOF || res < 1 || chars != 2)
+ /* Return a surprising delimiter to
+ force an error. */
+ {
+ return '%';
+ }
+
+ *to++ = val;
+ from += 2;
+ break;
+ }
+
+ default:
+ *to++ = ch;
+ break;
+ }
+ }
}
/* Parse an AMQP URL into its component parts. */
int amqp_parse_url(char *url, struct amqp_connection_info *parsed)
{
- int res = -ERROR_BAD_AMQP_URL;
- char delim;
- char *start;
- char *host;
- char *port = NULL;
-
- /* check the prefix */
- if (strncmp(url, "amqp://", 7))
- goto out;
-
- host = start = url += 7;
- delim = find_delim(&url, 1);
-
- if (delim == ':') {
- /* The colon could be introducing the port or the
- password part of the userinfo. We don't know yet,
- so stash the preceding component. */
- port = start = url;
- delim = find_delim(&url, 1);
- }
-
- if (delim == '@') {
- /* What might have been the host and port were in fact
- the username and password */
- parsed->user = host;
- if (port)
- parsed->password = port;
-
- port = NULL;
- host = start = url;
- delim = find_delim(&url, 1);
- }
-
- if (delim == '[') {
- /* IPv6 address. The bracket should be the first
- character in the host. */
- if (host != start || *host != 0)
- goto out;
-
- start = url;
- delim = find_delim(&url, 0);
-
- if (delim != ']')
- goto out;
-
- parsed->host = start;
- start = url;
- delim = find_delim(&url, 1);
-
- /* Closing bracket should be the last character in the
- host. */
- if (*start != 0)
- goto out;
- }
- else {
- /* If we haven't seen the host yet, this is it. */
- if (*host != 0)
- parsed->host = host;
- }
-
- if (delim == ':') {
- port = start = url;
- delim = find_delim(&url, 1);
- }
-
- if (port) {
- char *end;
- long portnum = strtol(port, &end, 10);
-
- if (port == end || *end != 0 || portnum < 0 || portnum > 65535)
- goto out;
-
- parsed->port = portnum;
- }
-
- if (delim == '/') {
- start = url;
- delim = find_delim(&url, 1);
-
- if (delim != 0)
- goto out;
-
- parsed->vhost = start;
- res = 0;
- }
- else if (delim == 0) {
- res = 0;
- }
-
- /* Any other delimiter is bad, and we will return
- ERROR_BAD_AMQP_URL. */
-
- out:
- return res;
+ int res = -ERROR_BAD_AMQP_URL;
+ char delim;
+ char *start;
+ char *host;
+ char *port = NULL;
+
+ /* check the prefix */
+ if (strncmp(url, "amqp://", 7)) {
+ goto out;
+ }
+
+ host = start = url += 7;
+ delim = find_delim(&url, 1);
+
+ if (delim == ':') {
+ /* The colon could be introducing the port or the
+ password part of the userinfo. We don't know yet,
+ so stash the preceding component. */
+ port = start = url;
+ delim = find_delim(&url, 1);
+ }
+
+ if (delim == '@') {
+ /* What might have been the host and port were in fact
+ the username and password */
+ parsed->user = host;
+ if (port) {
+ parsed->password = port;
+ }
+
+ port = NULL;
+ host = start = url;
+ delim = find_delim(&url, 1);
+ }
+
+ if (delim == '[') {
+ /* IPv6 address. The bracket should be the first
+ character in the host. */
+ if (host != start || *host != 0) {
+ goto out;
+ }
+
+ start = url;
+ delim = find_delim(&url, 0);
+
+ if (delim != ']') {
+ goto out;
+ }
+
+ parsed->host = start;
+ start = url;
+ delim = find_delim(&url, 1);
+
+ /* Closing bracket should be the last character in the
+ host. */
+ if (*start != 0) {
+ goto out;
+ }
+ } else {
+ /* If we haven't seen the host yet, this is it. */
+ if (*host != 0) {
+ parsed->host = host;
+ }
+ }
+
+ if (delim == ':') {
+ port = start = url;
+ delim = find_delim(&url, 1);
+ }
+
+ if (port) {
+ char *end;
+ long portnum = strtol(port, &end, 10);
+
+ if (port == end || *end != 0 || portnum < 0 || portnum > 65535) {
+ goto out;
+ }
+
+ parsed->port = portnum;
+ }
+
+ if (delim == '/') {
+ start = url;
+ delim = find_delim(&url, 1);
+
+ if (delim != 0) {
+ goto out;
+ }
+
+ parsed->vhost = start;
+ res = 0;
+ } else if (delim == 0) {
+ res = 0;
+ }
+
+ /* Any other delimiter is bad, and we will return
+ ERROR_BAD_AMQP_URL. */
+
+out:
+ return res;
}