Changeset: 5e2eba22d3cf for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/5e2eba22d3cf
Modified Files:
        common/utils/msabaoth.c
        testing/Mtest.py.in
        testing/malmapi.py
        testing/process.py
        tools/merovingian/daemon/proxy.c
        tools/merovingian/daemon/proxy.h
Branch: Dec2025
Log Message:

Deal with both old and new monetdb/mapi URIs in .conn file.
Note that currently we still produce the old style in the .conn file,
but the new style now also works properly.  Code for producing the new
style has been added to msabaoth.c, however it is currently disabled.


diffs (190 lines):

diff --git a/common/utils/msabaoth.c b/common/utils/msabaoth.c
--- a/common/utils/msabaoth.c
+++ b/common/utils/msabaoth.c
@@ -420,8 +420,10 @@ msab_marchConnection(const char *host, c
        if ((f = MT_fopen(pathbuf, "a")) != NULL) {
                /* append to the file */
                if (port > 0) {
+//                     fprintf(f, "monetdb://%s:%d/%s\n", host, port, 
_sabaoth_internal_dbname);
                        fprintf(f, "mapi:monetdb://%s:%i/\n", host, port);
                } else {
+//                     fprintf(f, "monetdb:///%s?sock=%s\n", 
_sabaoth_internal_dbname, host);
                        fprintf(f, "mapi:monetdb://%s\n", host);
                }
                (void)fflush(f);
diff --git a/testing/Mtest.py.in b/testing/Mtest.py.in
--- a/testing/Mtest.py.in
+++ b/testing/Mtest.py.in
@@ -55,7 +55,7 @@ test_progress = 0
 # whether output goes to a tty
 isatty = os.isatty(sys.stdout.fileno())
 
-mapiportre = re.compile(r'mapi:monetdb://[-.a-zA-Z0-9_]+:(?P<port>\d+)/')
+mapiportre = re.compile(r'(mapi:)?monetdb://[-.a-zA-Z0-9_]+:(?P<port>\d+)/')
 
 geos_version = '@GEOS_VERSION@'.split('.')
 
@@ -2925,8 +2925,10 @@ class ServerClass:
                 res = mapiportre.search(connurl)
                 if res is not None:
                     port = res.group('port')
-                elif 'monetdb:///' in connurl and not usetcp:
-                    self.usock = connurl
+                elif not usetcp:
+                    if connurl.startswith('mapi:monetdb:///') or \
+                       (connurl.startswith('monetdb://') and 'sock=' in 
connurl):
+                        self.usock = connurl
         else:
             loadedseen = False
             endtime = time.time() + 30
diff --git a/testing/malmapi.py b/testing/malmapi.py
--- a/testing/malmapi.py
+++ b/testing/malmapi.py
@@ -104,8 +104,8 @@ class Connection(object):
         unix_socket is used if hostname is not defined.
         """
 
-        if database.startswith('monetdb:///'):
-            unix_socket = database[10:]
+        if database.startswith('monetdb://') and 'sock=' in database:
+            unix_socket = database[database.index('sock=')+5:]
             hostname = database = None
         elif database.startswith('mapi:monetdb:///'):
             unix_socket = database[15:]
diff --git a/testing/process.py b/testing/process.py
--- a/testing/process.py
+++ b/testing/process.py
@@ -19,6 +19,7 @@ import threading
 import signal
 import queue
 import shlex
+import re
 
 from subprocess import PIPE, TimeoutExpired
 try:
@@ -46,6 +47,9 @@ no_unix_sockets = False
 
 _dotmonetdbfile = []
 
+_mapiportre = 
re.compile(r'^(mapi:)?monetdb://(\[[0-9a-fA-F:]*\]|[^:/]*):(?P<port>[0-9]+)(/.*$)?',
 re.M)
+
+
 def _delfiles():
     for f in _dotmonetdbfile:
         try:
@@ -600,24 +604,20 @@ class server(Popen):
                 else:
                     # retrieve mapi port if available
                     for c in conn.splitlines():
-                        if 'monetdb:///' in c:
+                        if c.startswith('mapi:monetdb:///') or \
+                           (c.startswith('monetdb://') and 'sock=' in c):
                             if no_unix_sockets:
                                 continue
                             self.usock = c.strip()
                             if verbose:
                                 print(f'usock: {self.usock}')
                             continue
-                        c = c.rstrip('/')
-                        c = c.rsplit(':', maxsplit=1)
-                        if len(c) == 2:
-                            try:
-                                port = int(c[1])
-                            except ValueError:
-                                pass
-                            else:
-                                if verbose:
-                                    print(f'mapi port: {port}')
-                                self.dbport = f'{port}'
+                        res = _mapiportre.match(c)
+                        if res is not None:
+                            port = int(res.group('port'))
+                            if verbose:
+                                print(f'mapi port: {port}')
+                            self.dbport = f'{port}'
                 break
             # wait at most 30 seconds for the server to start
             if time.time() > starttime + 30:
diff --git a/tools/merovingian/daemon/proxy.c b/tools/merovingian/daemon/proxy.c
--- a/tools/merovingian/daemon/proxy.c
+++ b/tools/merovingian/daemon/proxy.c
@@ -97,10 +97,12 @@ proxyThread(void *d)
 }
 
 err
-startProxy(int psock, stream *cfdin, stream *cfout, char *url, char *client)
+startProxy(int psock, stream *cfdin, stream *cfout,
+                  const char *url, const char *client)
 {
        int ssock = -1;
-       char *port, *t, *conn, *endipv6;
+       char *port, *t, *conn = NULL, *endipv6;
+       char *usock = NULL;
        struct stat statbuf;
        stream *sfdin, *sfout;
        merovingian_proxy *pctos, *pstoc;
@@ -109,9 +111,12 @@ startProxy(int psock, stream *cfdin, str
        int thret;
 
        /* quick 'n' dirty parsing */
-       if (strncmp(url, "mapi:monetdb://", sizeof("mapi:monetdb://") - 1) == 
0) {
-               conn = strdup(url + sizeof("mapi:monetdb://") - 1);
-
+       if (strncmp(url, "mapi:monetdb://", 15) == 0) {
+               conn = strdup(url + 15);
+       } else if (strncmp(url, "monetdb://", 10) == 0) {
+               conn = strdup(url + 10);
+       }
+       if (conn != NULL) {
                if (*conn == '[') { /* check for an IPv6 address */
                        if ((endipv6 = strchr(conn, ']')) != NULL) {
                                if ((port = strchr(endipv6, ':')) != NULL) {
@@ -127,6 +132,11 @@ startProxy(int psock, stream *cfdin, str
                                free(conn);
                                return(newErr("invalid IPv6 address in 
redirect: %s", url));
                        }
+               } else if (strncmp(url, "monetdb://", 10) == 0 &&
+                                  (t = strstr(conn, "sock=")) != NULL &&
+                                  stat(t + 5, &statbuf) != -1) {
+                       ssock = 0;
+                       usock = t + 5;
                } else if ((port = strchr(conn, ':')) != NULL) { /* drop 
anything off after the hostname */
                        *port = '\0';
                        port++;
@@ -134,6 +144,7 @@ startProxy(int psock, stream *cfdin, str
                                *t = '\0';
                } else if (stat(conn, &statbuf) != -1) {
                        ssock = 0;
+                       usock = conn;
                } else {
                        free(conn);
                        return(newErr("can't find a port in redirect, "
@@ -143,7 +154,7 @@ startProxy(int psock, stream *cfdin, str
                return(newErr("unsupported protocol/scheme in redirect: %s", 
url));
        }
 
-       if (ssock != -1) {
+       if (usock != NULL) {
                /* UNIX socket connect, don't proxy, but pass socket fd */
                struct sockaddr_un server;
                struct msghdr msg;
@@ -156,7 +167,7 @@ startProxy(int psock, stream *cfdin, str
                server = (struct sockaddr_un) {
                        .sun_family = AF_UNIX,
                };
-               strcpy_len(server.sun_path, conn, sizeof(server.sun_path));
+               strcpy_len(server.sun_path, usock, sizeof(server.sun_path));
                free(conn);
                if ((ssock = socket(PF_UNIX, SOCK_STREAM
 #ifdef SOCK_CLOEXEC
diff --git a/tools/merovingian/daemon/proxy.h b/tools/merovingian/daemon/proxy.h
--- a/tools/merovingian/daemon/proxy.h
+++ b/tools/merovingian/daemon/proxy.h
@@ -15,6 +15,6 @@
 
 #include "merovingian.h"
 
-err startProxy(int psock, stream *cfdin, stream *cfout, char *url, char 
*client);
+err startProxy(int psock, stream *cfdin, stream *cfout, const char *url, const 
char *client);
 
 #endif
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to