You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by jd...@apache.org on 2020/07/23 06:38:58 UTC

[qpid-dispatch] branch master updated: DISPATCH-960 - Resolve service port when using http listener (#294)

This is an automated email from the ASF dual-hosted git repository.

jdanek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git


The following commit(s) were added to refs/heads/master by this push:
     new b46405d  DISPATCH-960 - Resolve service port when using http listener (#294)
b46405d is described below

commit b46405d2360b7b21de936249f94964986e75fa3b
Author: Fernando Giorgetti <fg...@users.noreply.github.com>
AuthorDate: Thu Jul 23 03:38:47 2020 -0300

    DISPATCH-960 - Resolve service port when using http listener (#294)
---
 src/amqp.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/amqp.c b/src/amqp.c
index 4e9419c..33fff42 100644
--- a/src/amqp.c
+++ b/src/amqp.c
@@ -21,6 +21,9 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#include <netdb.h>
+#include <sys/types.h>
+#include <sys/socket.h>
 
 const char * const QD_MA_PREFIX  = "x-opt-qd.";
 const char * const QD_MA_INGRESS = "x-opt-qd.ingress";
@@ -91,11 +94,29 @@ const char * const QD_AMQP_COND_MESSAGE_SIZE_EXCEEDED = "amqp:link:message-size-
 const char * const QD_AMQP_PORT_STR = "5672";
 const char * const QD_AMQPS_PORT_STR = "5671";
 
+const char * const QD_AMQP_DFLT_PROTO = "tcp";
+
 int qd_port_int(const char* port_str) {
-    if (!strcmp(port_str, QD_AMQP_PORT_STR)) return QD_AMQP_PORT_INT;
-    if (!strcmp(port_str, QD_AMQPS_PORT_STR)) return QD_AMQPS_PORT_INT;
     errno = 0;
     unsigned long n = strtoul(port_str, NULL, 10);
     if (errno || n > 0xFFFF) return -1;
+
+    // Port is not an integer (port = 'amqp' or 'amqps')
+    if ( !n && strlen(port_str) > 0 ) {
+        // Resolve service port
+        struct servent serv_info;
+        struct servent *serv_info_res;
+        int buf_len = 4096;
+        char *buf = calloc(buf_len, sizeof(char));
+
+        // Service port is resolved
+        if ( !getservbyname_r(port_str, QD_AMQP_DFLT_PROTO, &serv_info, buf, buf_len, &serv_info_res) ) {
+            n = ntohs(serv_info.s_port);
+        } else {
+            n = -1;
+        }
+        free(buf);
+    }
+
     return n;
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org