Changeset: d73a1a6b3d41 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/d73a1a6b3d41
Modified Files:
        monetdb5/mal/mal_client.c
        monetdb5/mal/mal_client.h
        monetdb5/modules/mal/clients.c
        sql/backends/monet5/sql_upgrades.c
        sql/scripts/22_clients.sql
Branch: clientinfo
Log Message:

Add sys.setclientinfo(property string, value string)


diffs (127 lines):

diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c
--- a/monetdb5/mal/mal_client.c
+++ b/monetdb5/mal/mal_client.c
@@ -642,3 +642,56 @@ MCprintinfo(void)
        printf("%d active clients, %d finishing clients, %d blocked clients\n",
                   nrun, nfinish, nblock);
 }
+
+
+void
+MCsetClientInfo(Client c, const char *property, const char *value)
+{
+       if (strlen(property) < 7)
+               return;
+
+       // 012345 6 78...
+       // Client H ostname
+       // Applic a tionName
+       // Client L ibrary
+       // Client R emark
+       // Client P id
+       int discriminant = toupper(property[6]);
+
+       switch (discriminant) {
+               case 'H':
+                       if (strcasecmp(property, "ClientHostname") == 0) {
+                               GDKfree(c->client_hostname);
+                               c->client_hostname = GDKstrdup(value);
+                       }
+                       break;
+               case 'A':
+                       if (strcasecmp(property, "ApplicationName") == 0) {
+                               GDKfree(c->client_application);
+                               c->client_application = GDKstrdup(value);
+                       }
+                       break;
+               case 'L':
+                       if (strcasecmp(property, "ClientLibrary") == 0) {
+                               GDKfree(c->client_library);
+                               c->client_library = GDKstrdup(value);
+                       }
+                       break;
+               case 'R':
+                       if (strcasecmp(property, "ClientRemark") == 0) {
+                               GDKfree(c->client_remark);
+                               c->client_remark = GDKstrdup(value);
+                       }
+                       break;
+               case 'P':
+                       if (strcasecmp(property, "ClientPid") == 0) {
+                               char *end;
+                               long n = strtol(value, &end, 10);
+                               if (*value && !*end)
+                                       c->client_pid = n;
+                       }
+                       break;
+               default:
+                       break;
+       }
+}
diff --git a/monetdb5/mal/mal_client.h b/monetdb5/mal/mal_client.h
--- a/monetdb5/mal/mal_client.h
+++ b/monetdb5/mal/mal_client.h
@@ -195,5 +195,6 @@ mal_export str MCawakeClient(int id);
 mal_export int MCpushClientInput(Client c, bstream *new_input, int listing,
                                                                 const char 
*prompt);
 mal_export int MCvalid(Client c);
+mal_export void MCsetClientInfo(Client c, const char *property, const char 
*value);
 
 #endif /* _MAL_CLIENT_H_ */
diff --git a/monetdb5/modules/mal/clients.c b/monetdb5/modules/mal/clients.c
--- a/monetdb5/modules/mal/clients.c
+++ b/monetdb5/modules/mal/clients.c
@@ -983,6 +983,17 @@ CLTgetSessionID(Client cntxt, MalBlkPtr 
        return MAL_SUCCEED;
 }
 
+static str
+CLTsetClientInfo(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+       (void)mb;
+       str property = *getArgReference_str(stk, pci, 1);
+       str value = *getArgReference_str(stk, pci, 2);
+
+       MCsetClientInfo(cntxt, property, value);
+       return MAL_SUCCEED;
+}
+
 #include "mel.h"
 mel_func clients_init_funcs[] = {
  pattern("clients", "setListing", CLTsetListing, true, "Turn on/off echo of 
MAL instructions:\n1 - echo input,\n2 - show mal instruction,\n4 - show details 
of type resolutoin, \n8 - show binding information.", args(1,2, 
arg("",int),arg("flag",int))),
@@ -1021,6 +1032,7 @@ mel_func clients_init_funcs[] = {
  pattern("clients", "getPasswordHash", CLTgetPasswordHash, false, "Return the 
password hash of the given user", args(1,2, arg("",str),arg("user",str))),
  pattern("clients", "checkPermission", CLTcheckPermission, false, "Check 
permission for a user, requires hashed password (backendsum)", args(1,3, 
arg("",void),arg("usr",str),arg("pw",str))),
  pattern("clients", "current_sessionid", CLTgetSessionID, false, "return 
current session ID", args(1,1, arg("",int))),
+ pattern("clients", "setinfo", CLTsetClientInfo, true, "set a clientinfo 
property", args(1, 3, arg("",str), arg("property", str), arg("value", str))),
  { .imp=NULL }
 };
 #include "mal_import.h"
diff --git a/sql/backends/monet5/sql_upgrades.c 
b/sql/backends/monet5/sql_upgrades.c
--- a/sql/backends/monet5/sql_upgrades.c
+++ b/sql/backends/monet5/sql_upgrades.c
@@ -7129,6 +7129,10 @@ sql_update_default(Client c, mvc *sql, s
                        " )\n"
                        " external name sql.sessions;\n"
                        "create view sys.sessions as select * from 
sys.sessions();\n"
+                       "create procedure sys.setclientinfo(property string, 
value string)\n"
+                       " external name clients.setinfo;\n"
+                       "grant execute on procedure sys.setclientinfo(string, 
string) to public;\n"
+                       "update sys.functions set system = true where schema_id 
= 2000 and name = 'setclientinfo';";
                        ;
                sql_schema *sys = mvc_bind_schema(sql, "sys");
                sql_table *t = mvc_bind_table(sql, sys, "sessions");
diff --git a/sql/scripts/22_clients.sql b/sql/scripts/22_clients.sql
--- a/sql/scripts/22_clients.sql
+++ b/sql/scripts/22_clients.sql
@@ -41,6 +41,10 @@ external name sql.sessions;
 create view sys.sessions as select * from sys.sessions();
 -- we won't grant sys.sessions to the public
 
+create procedure sys.setclientinfo(property string, value string)
+       external name clients.setinfo;
+grant execute on procedure sys.setclientinfo(string, string) to public;
+
 -- routines to bring the system down quickly
 create procedure sys.shutdown(delay tinyint)
        external name sql.shutdown;
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to