Changeset: 0ccf9e59b868 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0ccf9e59b868
Modified Files:
        ctest/tools/monetdbe/example_remote.c
        tools/monetdbe/monetdbe.c
        tools/monetdbe/monetdbe.h
Branch: default
Log Message:

Consolidate all proxy configuration in monetdbe_options::remote.


diffs (103 lines):

diff --git a/ctest/tools/monetdbe/example_remote.c 
b/ctest/tools/monetdbe/example_remote.c
--- a/ctest/tools/monetdbe/example_remote.c
+++ b/ctest/tools/monetdbe/example_remote.c
@@ -20,9 +20,11 @@ main(void)
        char* err = NULL;
        monetdbe_database mdbe = NULL;
        monetdbe_result* result = NULL;
+       monetdbe_remote remote = {.host="localhost", .port=50000, 
.database="devdb", .username="monetdb", .password="monetdb"};
+       monetdbe_options opts = {.remote = &remote};
 
        // second argument is a string for the db directory or NULL for 
in-memory mode
-       if (monetdbe_open(&mdbe, 
"monetdb://localhost:5000/sf1?user=monetdb&password=monetdb", NULL))
+       if (monetdbe_open(&mdbe, NULL, &opts))
                expected_error("Failed to open database")
        /*if ((err = monetdbe_query(mdbe, "CREATE TABLE test (x integer, y 
string)", NULL, NULL)) != NULL)
                error(err)
diff --git a/tools/monetdbe/monetdbe.c b/tools/monetdbe/monetdbe.c
--- a/tools/monetdbe/monetdbe.c
+++ b/tools/monetdbe/monetdbe.c
@@ -646,13 +646,31 @@ static bool urls_matches(const char* l, 
        return (l && r && (strcmp(l, r) == 0)) || (l == NULL && r == NULL);
 }
 
+static inline str
+monetdbe_create_uri(const char* host, const int port, const char* database) {
+       const char* protocol = "mapi:monetdb://";
+
+       const int sl_protocol = strlen(protocol);
+       const int sl_host = strlen(host);
+       const int sl_max_port = 6; // 2^16-1 < 100 000 = 10^5, i.e. always less 
then 6 digits.
+       const int sl_database = strlen(database);
+
+       const int sl_total = sl_protocol + sl_host + 1 /*:*/ + sl_max_port + 1 
+ /*/*/ + sl_database ;
+
+       str uri_buffer = GDKmalloc(sl_total + 1 /*terminator*/);
+
+       snprintf(uri_buffer, sl_total, "%s%s:%d/%s", protocol, host, port, 
database);
+
+       return uri_buffer;
+}
+
 static int
-monetdbe_open_remote(monetdbe_database_internal *mdbe, char *url, 
monetdbe_options *opts) {
+monetdbe_open_remote(monetdbe_database_internal *mdbe, monetdbe_options *opts) 
{
        assert(opts);
 
        monetdbe_remote* remote = opts->remote;
        if (!remote) {
-               mdbe->msg = createException(MAL, 
"monetdbe.monetdbe_open_remote", "Missing user credential for monetdbe remote 
proxy set up");
+               mdbe->msg = createException(MAL, 
"monetdbe.monetdbe_open_remote", "Missing remote proxy settings");
                return -1;
        }
 
@@ -670,6 +688,8 @@ monetdbe_open_remote(monetdbe_database_i
                return -2;
        }
 
+       char* url = monetdbe_create_uri(remote->host, remote->port, 
remote->database);
+
        MalBlkPtr mb = c->curprg->def;
 
        InstrPtr q = getInstrPtr(mb, 0);
@@ -683,6 +703,9 @@ monetdbe_open_remote(monetdbe_database_i
        p = pushStr(mb, p, "msql");
        p = pushBit(mb, p, 1);
 
+       GDKfree(url);
+       url = NULL;
+
        q = newInstruction(mb, NULL, NULL);
        q->barrier= RETURNsymbol;
        q = pushReturn(mb, q, getArg(p, 0));
@@ -735,8 +758,8 @@ monetdbe_open(monetdbe_database *dbhdl, 
                 * it is still necessary to have an initialized monetdbe. E.g. 
for BAT life cycle management.
                 * Use an ephemeral/anonymous dbfarm when there is no 
initialized monetdbe yet.
                 */
-               char* _url = is_remote?NULL:url;
-               monetdbe_startup(mdbe, _url, opts);
+               assert(!is_remote||url==NULL);
+               monetdbe_startup(mdbe, url, opts);
        }
        else if (!is_remote && !urls_matches(monetdbe_embedded_url, url)) {
                mdbe->msg = createException(MAL, "monetdbe.monetdbe_open", 
"monetdbe_open currently only one active database is supported");
@@ -745,7 +768,7 @@ monetdbe_open(monetdbe_database *dbhdl, 
                res = monetdbe_open_internal(mdbe);
 
        if (res == 0 && is_remote)
-               res = monetdbe_open_remote(mdbe, url, opts);
+               res = monetdbe_open_remote(mdbe, opts);
 
        MT_lock_unset(&embedded_lock);
        if (mdbe->msg)
diff --git a/tools/monetdbe/monetdbe.h b/tools/monetdbe/monetdbe.h
--- a/tools/monetdbe/monetdbe.h
+++ b/tools/monetdbe/monetdbe.h
@@ -89,6 +89,7 @@ typedef void* monetdbe_database;
 typedef struct {
        const char *host;
        int port;
+       const char *database;
        const char *username;
        const char *password;
        const char *lang;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to