Changeset: 2d856b72dba7 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2d856b72dba7
Modified Files:
        clients/ChangeLog.Jun2010
        clients/src/mapilib/Mapi.mx
        sql/src/backends/monet5/merovingian/merovingian.c
Branch: Jun2010
Log Message:

Fix implementation of mapi_mapiuri to deal with UNIX socket urls properly.  
This fixes one part of Bug #2567.


diffs (147 lines):

diff -r 357a239e7c37 -r 2d856b72dba7 clients/ChangeLog.Jun2010
--- a/clients/ChangeLog.Jun2010 Wed Jun 30 15:24:33 2010 +0200
+++ b/clients/ChangeLog.Jun2010 Thu Jul 01 14:01:29 2010 +0200
@@ -1,3 +1,6 @@
 # ChangeLog file for clients
 # This file is updated with Maddlog
 
+* Thr Jul  1 2010 Fabian Groffen <fab...@cwi.nl>
+- Fix implementation of mapi_mapiuri to deal with UNIX socket urls
+  properly.  This fixes one part of Bug #2567.
diff -r 357a239e7c37 -r 2d856b72dba7 clients/src/mapilib/Mapi.mx
--- a/clients/src/mapilib/Mapi.mx       Wed Jun 30 15:24:33 2010 +0200
+++ b/clients/src/mapilib/Mapi.mx       Thu Jul 01 14:01:29 2010 +0200
@@ -1303,6 +1303,7 @@
 static int unquote(const char *msg, char **start, const char **next, int 
endchar, size_t *lenp);
 static int mapi_slice_row(struct MapiResultSet *result, int cr);
 static void mapi_store_bind(struct MapiResultSet *result, int cr);
+static void parse_uri_query(Mapi mid, char *uri);
 
 static int mapi_initialized = 0;
 
@@ -2093,39 +2094,43 @@
        }
 
        /* copy to a writable working buffer */
-       snprintf(uri, 8096, "%s", url +sizeof("mapi:monetdb://") - 1);
-
-       if ((p = strchr(uri, ':')) == NULL) {
-               mapi_setError(mid, "URI must contain a port number after the 
hostname", "mapi_mapiuri", MERROR);
-               return mid;
-       }
-       *p++ = '\0';
-       host = uri;
-       dbname = p;             /* temp misuse */
-
-       if ((p = strchr(dbname, '/')) == NULL) {
-               p = dbname;
-               dbname = NULL;
-       } else {
+       snprintf(uri, 8096, "%s", url + sizeof("mapi:monetdb://") - 1);
+
+       if (uri[0] != '/') {
+               if ((p = strchr(uri, ':')) == NULL) {
+                       mapi_setError(mid, "URI must contain a port number 
after "
+                                       "the hostname", "mapi_mapiuri", MERROR);
+                       return mid;
+               }
                *p++ = '\0';
-               if (*p == '\0') {
+               dbname = p;             /* temp misuse */
+               host = uri;
+               if ((p = strchr(dbname, '/')) == NULL) {
                        p = dbname;
                        dbname = NULL;
                } else {
-                       char *t = dbname;
-                       dbname = p;
-                       p = t;
+                       *p++ = '\0';
+                       if (*p == '\0') {
+                               p = dbname;
+                               dbname = NULL;
+                       } else {
+                               char *t = dbname;
+                               dbname = p;
+                               p = t;
+                       }
                }
+               port = atoi(p);
+               if (port <= 0) {
+                       mapi_setError(mid, "URI contains invalid port",
+                                       "mapi_mapiuri", MERROR);
+                       return mid;
+               }
+       } else {
+               host = uri;
+               port = 0;
+               dbname = NULL;
        }
-       port = atoi(p);
-       if (port <= 0) {
-               mapi_setError(mid, "URI contains invalid port", "mapi_mapiuri", 
MERROR);
-               return mid;
-       }
-
-       if (mid->hostname)
-               free(mid->hostname);
-       mid->hostname = strdup(host);
+
        mid->port = port;
        if (mid->username != NULL)
                free(mid->username);
@@ -2145,7 +2150,18 @@
                mid->languageId = LANG_XQUERY;
        if (mid->database)
                free(mid->database);
-       mid->database = dbname == NULL ? NULL : strdup(dbname);
+       mid->database = NULL;
+
+       /* this is in particular important for unix sockets */
+       parse_uri_query(mid, uri);
+
+       /* doing this here, because parse_uri_query will terminate the
+        * string if a ? is in place */
+       if (mid->hostname)
+               free(mid->hostname);
+       mid->hostname = strdup(host);
+       if (mid->database == NULL && dbname != NULL)
+               mid->database = strdup(dbname);
 
        return mid;
 }
@@ -2267,7 +2283,7 @@
        if ((uri = strchr(uri, '?')) == NULL)
                return;
 
-       uri++;                  /* skip '?' */
+       *uri++ = '\0';                  /* skip '?' */
 
        do {
                if ((amp = strchr(uri, '&')) != NULL)
@@ -2281,6 +2297,14 @@
                        } else if (strcmp("language", uri) == 0) {
                                free(mid->language);
                                mid->language = strdup(val);
+                               if (strcmp(val, "mil") == 0)
+                                       mid->languageId = LANG_MIL;
+                               else if (strcmp(val, "mal") == 0)
+                                       mid->languageId = LANG_MAL;
+                               else if (strcmp(val, "sql") == 0)
+                                       mid->languageId = LANG_SQL;
+                               else if (strcmp(val, "xquery") == 0)
+                                       mid->languageId = LANG_XQUERY;
                        } else if (strcmp("user", uri) == 0) {
                                /* until we figure out how this can be
                                   done safely wrt security, ignore */
diff -r 357a239e7c37 -r 2d856b72dba7 
sql/src/backends/monet5/merovingian/merovingian.c
--- a/sql/src/backends/monet5/merovingian/merovingian.c Wed Jun 30 15:24:33 
2010 +0200
+++ b/sql/src/backends/monet5/merovingian/merovingian.c Thu Jul 01 14:01:29 
2010 +0200
@@ -1000,6 +1000,7 @@
 
        if (e != NO_ERR) {
                /* console */
+               Mfprintf(stderr, "%s\n", argv[0], e);
                Mfprintf(oerr, "%s: %s\n", argv[0], e);
                MERO_EXIT(1);
                /* logfile */
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to