diff options
Diffstat (limited to 'librabbitmq/amqp_url.c')
-rw-r--r-- | librabbitmq/amqp_url.c | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/librabbitmq/amqp_url.c b/librabbitmq/amqp_url.c index 277b5a6..72a4126 100644 --- a/librabbitmq/amqp_url.c +++ b/librabbitmq/amqp_url.c @@ -52,6 +52,7 @@ void amqp_default_connection_info(struct amqp_connection_info *ci) ci->host = "localhost"; ci->port = 5672; ci->vhost = "/"; + ci->ssl = false; } /* Scan for the next delimiter, handling percent-encodings on the way. */ @@ -116,11 +117,16 @@ int amqp_parse_url(char *url, struct amqp_connection_info *parsed) char *port = NULL; /* check the prefix */ - if (strncmp(url, "amqp://", 7)) { + if (!strncmp(url, "amqp://", 7)) { + /* do nothing */ + } else if (!strncmp(url, "amqps://", 8)) { + parsed->port = 5671; + parsed->ssl = true; + } else { goto out; } - host = start = url += 7; + host = start = url += (parsed->ssl ? 8 : 7); delim = find_delim(&url, 1); if (delim == ':') { @@ -135,9 +141,8 @@ int amqp_parse_url(char *url, struct amqp_connection_info *parsed) /* What might have been the host and port were in fact the username and password */ parsed->user = host; - if (port) { + if (port) parsed->password = port; - } port = NULL; host = start = url; @@ -147,16 +152,14 @@ int amqp_parse_url(char *url, struct amqp_connection_info *parsed) if (delim == '[') { /* IPv6 address. The bracket should be the first character in the host. */ - if (host != start || *host != 0) { + if (host != start || *host != 0) goto out; - } start = url; delim = find_delim(&url, 0); - if (delim != ']') { + if (delim != ']') goto out; - } parsed->host = start; start = url; @@ -164,14 +167,13 @@ int amqp_parse_url(char *url, struct amqp_connection_info *parsed) /* Closing bracket should be the last character in the host. */ - if (*start != 0) { + if (*start != 0) goto out; - } - } else { + } + else { /* If we haven't seen the host yet, this is it. */ - if (*host != 0) { + if (*host != 0) parsed->host = host; - } } if (delim == ':') { @@ -183,9 +185,8 @@ int amqp_parse_url(char *url, struct amqp_connection_info *parsed) char *end; long portnum = strtol(port, &end, 10); - if (port == end || *end != 0 || portnum < 0 || portnum > 65535) { + if (port == end || *end != 0 || portnum < 0 || portnum > 65535) goto out; - } parsed->port = portnum; } @@ -194,13 +195,13 @@ int amqp_parse_url(char *url, struct amqp_connection_info *parsed) start = url; delim = find_delim(&url, 1); - if (delim != 0) { + if (delim != 0) goto out; - } parsed->vhost = start; res = 0; - } else if (delim == 0) { + } + else if (delim == 0) { res = 0; } |