Changeset: fe73197bdceb for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/fe73197bdceb Modified Files: clients/mapilib/connect.c clients/mapilib/mapi_intern.h clients/mapilib/msettings.c clients/mapilib/msettings.h Branch: clientinfo Log Message:
Send Xclientinfo from libmapi ApplicationName and ClientRemark can be set through msettings: - client_application/MP_CLIENT_APPLICATION, - client_remark/MP_CLIENT_REMARK, - client_info/MP_CLIENT_INFO to turn it on and off. There is no support yet for configuring arbitrary properties, only these two. Also the properties cannot yet be changed yet after connecting. diffs (200 lines): diff --git a/clients/mapilib/connect.c b/clients/mapilib/connect.c --- a/clients/mapilib/connect.c +++ b/clients/mapilib/connect.c @@ -24,6 +24,7 @@ #ifdef HAVE_SYS_SOCKET_H # include <arpa/inet.h> /* addr_in */ +# include <unistd.h> /* gethostname() */ #else /* UNIX specific */ #ifdef HAVE_WINSOCK_H /* Windows specific */ # include <winsock.h> @@ -380,6 +381,51 @@ connect_socket_tcp_addr(Mapi mid, struct return s; } +static void +send_all_clientinfo(Mapi mid) +{ + msettings *mp = mid->settings; + if (!mid->clientinfo_supported) + return; + if (!msetting_bool(mp, MP_CLIENT_INFO)) + return; + + + static char hostname[120] = { 0 }; + if (hostname[0] == '\0') { + if (gethostname(hostname, sizeof(hostname)) != 0) + hostname[0] = '\0'; + hostname[sizeof(hostname) - 1] = '\0'; + } + const char *application_name = msetting_string(mp, MP_CLIENT_APPLICATION); + const char *client_library = "libmapi " MONETDB_VERSION; + const char *client_remark = msetting_string(mp, MP_CLIENT_REMARK); + long pid = getpid(); + + char *buf = NULL; + size_t pos = 0, cap = 200; + + if (hostname[0]) + reallocprintf(&buf, &pos, &cap, "ClientHostName=%s\n", hostname); + if (application_name[0]) + reallocprintf(&buf, &pos, &cap, "ApplicationName=%s\n", application_name); + reallocprintf(&buf, &pos, &cap, "ClientLibrary=%s\n", client_library); + if (client_remark[0]) + reallocprintf(&buf, &pos, &cap, "ClientRemark=%s\n", client_remark); + if (pid > 0) + reallocprintf(&buf, &pos, &cap, "ClientPid=%ld\n", pid); + + if (pos > 1) { + assert(buf[pos - 1] == '\n'); + pos--; + buf[pos] = '\0'; + } + + if (pos <= cap) + mapi_Xcommand(mid, "clientinfo", buf); + free(buf); +} + static MapiMsg mapi_handshake(Mapi mid) { @@ -489,15 +535,22 @@ mapi_handshake(Mapi mid) } } - /* search for OOBINTR option, - * NOTE this consumes the rest of the challenge */ - char *rest = strtok_r(NULL, ":", &strtok_state); - while (rest != NULL) { - if (strcmp(rest, "OOBINTR=1") == 0) { + /* skip the binary option */ + char *binary = strtok_r(NULL, ":", &strtok_state); + (void)binary; + + char *oobintr = strtok_r(NULL, ":", &strtok_state); + if (oobintr) { + if (strcmp(oobintr, "OOBINTR=1") == 0) { mid->oobintr = true; - break; } - rest = strtok_r(NULL, ":", &strtok_state); + } + + char *clientinfo = strtok_r(NULL, ":", &strtok_state); + if (clientinfo) { + if (strcmp(oobintr, "OOBINTR=1") == 0) { + mid->clientinfo_supported = true; + } } /* hash password, if not already */ @@ -811,6 +864,9 @@ mapi_handshake(Mapi mid) mapi_set_time_zone(mid, msetting_long(mid->settings, MP_TIMEZONE)); } + if (mid->error == MOK) + send_all_clientinfo(mid); + return mid->error; } diff --git a/clients/mapilib/mapi_intern.h b/clients/mapilib/mapi_intern.h --- a/clients/mapilib/mapi_intern.h +++ b/clients/mapilib/mapi_intern.h @@ -246,6 +246,7 @@ struct MapiStruct { bool columnar_protocol; bool sizeheader; bool oobintr; + bool clientinfo_supported; MapiHdl first; /* start of doubly-linked list */ MapiHdl active; /* set when not all rows have been received */ diff --git a/clients/mapilib/msettings.c b/clients/mapilib/msettings.c --- a/clients/mapilib/msettings.c +++ b/clients/mapilib/msettings.c @@ -84,6 +84,9 @@ by_name[] = { { .name="binary", .parm=MP_BINARY }, { .name="cert", .parm=MP_CERT }, { .name="certhash", .parm=MP_CERTHASH }, + { .name="client_application", .parm=MP_CLIENT_APPLICATION }, + { .name="client_info", .parm=MP_CLIENT_INFO }, + { .name="client_remark", .parm=MP_CLIENT_REMARK }, { .name="clientcert", .parm=MP_CLIENTCERT }, { .name="clientkey", .parm=MP_CLIENTKEY }, { .name="connect_timeout", .parm=MP_CONNECT_TIMEOUT }, @@ -93,8 +96,8 @@ by_name[] = { { .name="map_to_long_varchar", .parm=MP_MAPTOLONGVARCHAR }, { .name="password", .parm=MP_PASSWORD }, { .name="port", .parm=MP_PORT }, + { .name="reply_timeout", .parm=MP_REPLY_TIMEOUT }, { .name="replysize", .parm=MP_REPLYSIZE }, - { .name="reply_timeout", .parm=MP_REPLY_TIMEOUT }, { .name="fetchsize", .parm=MP_REPLYSIZE }, { .name="schema", .parm=MP_SCHEMA }, { .name="sock", .parm=MP_SOCK }, @@ -140,6 +143,9 @@ mparm_name(mparm parm) case MP_BINARY: return "binary"; case MP_CERT: return "cert"; case MP_CERTHASH: return "certhash"; + case MP_CLIENT_APPLICATION: return "client_application"; + case MP_CLIENT_INFO: return "client_info"; + case MP_CLIENT_REMARK: return "client_remark"; case MP_CLIENTCERT: return "clientcert"; case MP_CLIENTKEY: return "clientkey"; case MP_CONNECT_TIMEOUT: return "connect_timeout"; @@ -190,6 +196,7 @@ struct msettings { bool dummy_start_bool; bool tls; bool autocommit; + bool client_info; bool dummy_end_bool; // Must match EXACTLY the order of enum mparm @@ -220,6 +227,8 @@ struct msettings { struct string schema; struct string binary; struct string logfile; + struct string client_application; + struct string client_remark; struct string dummy_end_string; char **unknown_parameters; @@ -241,6 +250,7 @@ static const msettings msettings_default_values = { .tls = false, .autocommit = true, + .client_info = true, .port = -1 , .timezone = 0, @@ -255,6 +265,7 @@ const msettings msettings_default_values .lang_is_mal = false, .lang_is_sql = true, .unix_sock_name_buffer = NULL, + .validated = false, }; diff --git a/clients/mapilib/msettings.h b/clients/mapilib/msettings.h --- a/clients/mapilib/msettings.h +++ b/clients/mapilib/msettings.h @@ -48,6 +48,7 @@ typedef enum mparm { // bool MP_TLS = MP__BOOL_START, MP_AUTOCOMMIT, + MP_CLIENT_INFO, // Note: if you change anything about this enum whatsoever, make sure to // make the corresponding change to struct msettings in msettings.c as well. @@ -78,6 +79,8 @@ typedef enum mparm { MP_SCHEMA, // TODO implement this MP_BINARY, MP_LOGFILE, + MP_CLIENT_APPLICATION, + MP_CLIENT_REMARK, // Note: if you change anything about this enum whatsoever, make sure to // make the corresponding change to struct msettings in msettings.c as well. _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org