summaryrefslogtreecommitdiff
path: root/librabbitmq
diff options
context:
space:
mode:
authorMichael Steinert <mike.steinert@gmail.com>2012-05-24 19:14:45 -0600
committerAlan Antonuk <alan.antonuk@gmail.com>2013-04-09 15:29:58 -0700
commit07751706f51a2bfe029d9fd9c41f153695526774 (patch)
tree13976207dffcf784d18f1910eaeea4dbf66519b1 /librabbitmq
parent06bf34769c8118c11aa5fc6a5093a85fba6a1c23 (diff)
downloadrabbitmq-c-github-ask-07751706f51a2bfe029d9fd9c41f153695526774.tar.gz
Add amqps:// support to the URL parser
Signed-off-by: Michael Steinert <mike.steinert@gmail.com>
Diffstat (limited to 'librabbitmq')
-rw-r--r--librabbitmq/amqp.h2
-rw-r--r--librabbitmq/amqp_url.c37
2 files changed, 21 insertions, 18 deletions
diff --git a/librabbitmq/amqp.h b/librabbitmq/amqp.h
index d1bfe4e..825e9ff 100644
--- a/librabbitmq/amqp.h
+++ b/librabbitmq/amqp.h
@@ -124,6 +124,7 @@ struct iovec;
# define AMQP_CALL
#endif
+#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@@ -569,6 +570,7 @@ struct amqp_connection_info {
char *host;
char *vhost;
int port;
+ bool ssl;
};
AMQP_PUBLIC_FUNCTION
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;
}