Changeset: cf2cbb1a1567 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/cf2cbb1a1567 Modified Files: clients/Tests/exports.stable.out clients/mapilib/CMakeLists.txt clients/mapilib/mapi.c clients/mapilib/mapi_intern.h clients/mapilib/msettings.h Branch: monetdburl Log Message:
Make msettings accessible from outside diffs (195 lines): diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out --- a/clients/Tests/exports.stable.out +++ b/clients/Tests/exports.stable.out @@ -646,6 +646,7 @@ int64_t mapi_get_querytime(MapiHdl hdl) int mapi_get_querytype(MapiHdl hdl) __attribute__((__nonnull__(1))); int64_t mapi_get_row_count(MapiHdl hdl) __attribute__((__nonnull__(1))); int mapi_get_scale(MapiHdl hdl, int fnr) __attribute__((__nonnull__(1))); +msettings *mapi_get_settings(Mapi mid) __attribute__((__nonnull__(1))); int64_t mapi_get_sqloptimizertime(MapiHdl hdl) __attribute__((__nonnull__(1))); char *mapi_get_table(MapiHdl hdl, int fnr) __attribute__((__nonnull__(1))); int mapi_get_tableid(MapiHdl hdl) __attribute__((__nonnull__(1))); @@ -693,6 +694,7 @@ MapiMsg mapi_set_time_zone(Mapi mid, int MapiMsg mapi_set_timeout(Mapi mid, unsigned int timeout, bool (*callback)(void *), void *callback_data) __attribute__((__nonnull__(1))); void mapi_setfilecallback(Mapi mid, char *(*getfunc)(void *priv, const char *filename, bool binary, uint64_t offset, size_t *size), char *(*putfunc)(void *priv, const char *filename, const void *data, size_t size), void *priv) __attribute__((__nonnull__(1))); void mapi_setfilecallback2(Mapi mid, char *(*getfunc)(void *priv, const char *filename, bool binary, uint64_t offset, size_t *size), char *(*putfunc)(void *priv, const char *filename, bool binary, const void *data, size_t size), void *priv) __attribute__((__nonnull__(1))); +Mapi mapi_settings(msettings *settings) __attribute__((__nonnull__(1))); int mapi_split_line(MapiHdl hdl) __attribute__((__nonnull__(1))); MapiMsg mapi_store_field(MapiHdl hdl, int fnr, int outtype, void *outparam) __attribute__((__nonnull__(1))); MapiMsg mapi_timeout(Mapi mid, unsigned int time) __attribute__((__nonnull__(1))); diff --git a/clients/mapilib/CMakeLists.txt b/clients/mapilib/CMakeLists.txt --- a/clients/mapilib/CMakeLists.txt +++ b/clients/mapilib/CMakeLists.txt @@ -32,7 +32,8 @@ target_sources(mapi $<BUILD_INTERFACE:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/mapi_querytype.h> $<BUILD_INTERFACE:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/msettings.h> $<INSTALL_INTERFACE:$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/monetdb>/mapi.h> - $<INSTALL_INTERFACE:$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/monetdb>/mapi_querytype.h>) + $<INSTALL_INTERFACE:$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/monetdb>/mapi_querytype.h> + $<INSTALL_INTERFACE:$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/monetdb>/msettings.h>) target_include_directories(mapi PUBLIC @@ -58,7 +59,7 @@ set_target_properties(mapi PROPERTIES VERSION ${MAPI_VERSION} SOVERSION ${MAPI_VERSION_MAJOR} - PUBLIC_HEADER "mapi.h;mapi_querytype.h") + PUBLIC_HEADER "mapi.h;mapi_querytype.h;msettings.h") if (NOT WIN32) configure_file(monetdb-mapi.pc.in diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c --- a/clients/mapilib/mapi.c +++ b/clients/mapilib/mapi.c @@ -1772,17 +1772,18 @@ const struct MapiStruct MapiStructDefaul /* Allocate a new connection handle. */ Mapi -mapi_new(void) +mapi_new(msettings *settings) { Mapi mid; - msettings *settings; static ATOMIC_TYPE index = ATOMIC_VAR_INIT(0); mid = malloc(sizeof(*mid)); - settings = msettings_create(); - if (mid == NULL || settings == NULL) { + if (mid == NULL) + return NULL; + if (settings == NULL) + settings = msettings_create(); + if (settings == NULL) { free(mid); - msettings_destroy(settings); return NULL; } @@ -1889,7 +1890,7 @@ mapi_mapiuri(const char *url, const char return NULL; } - mid = mapi_new(); + mid = mapi_new(NULL); if (mid == NULL) return NULL; @@ -1948,7 +1949,7 @@ mapi_mapi(const char *host, int port, co return NULL; } - mid = mapi_new(); + mid = mapi_new(NULL); if (mid == NULL) return NULL; msettings *settings = mid->settings; @@ -1987,6 +1988,19 @@ mapi_mapi(const char *host, int port, co return mid; } +Mapi +mapi_settings(msettings *settings) +{ + assert(settings); + Mapi mid = mapi_new(settings); + if (mid == NULL) + return mid; + + set_uri(mid); + return mid; +} + + /* Close a connection and free all memory associated with the connection handle. */ MapiMsg @@ -4665,6 +4679,12 @@ mapi_get_active(Mapi mid) return mid->active; } +msettings* +mapi_get_settings(Mapi mid) +{ + return mid->settings; +} + MapiMsg mapi_wrap_streams(Mapi mid, stream *rstream, stream *wstream) 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 @@ -315,7 +315,8 @@ MapiMsg mapi_Xcommand(Mapi mid, const ch extern const struct MapiStruct MapiStructDefaults; -Mapi mapi_new(void); +// 'settings' will be newly allocated if NULL +Mapi mapi_new(msettings *settings); MapiMsg wrap_tls(Mapi mid, SOCKET sock); MapiMsg mapi_wrap_streams(Mapi mid, stream *rstream, stream *wstream); diff --git a/clients/mapilib/msettings.h b/clients/mapilib/msettings.h --- a/clients/mapilib/msettings.h +++ b/clients/mapilib/msettings.h @@ -10,6 +10,8 @@ #ifndef _MSETTINGS_H #define _MSETTINGS_H 1 + +#include "mapi.h" #include <stdbool.h> #define MP__BOOL_START (100) @@ -31,6 +33,11 @@ extern "C" { #define mapi_export extern #endif +///////////////////////////////////////////////////////////////////// +// This enum identifies properties that can be set that affect how a +// connection is made. In particular we have functies to parse strings +// into a an enum value, and back. + typedef enum mparm { MP_UNKNOWN, MP_IGNORE, @@ -85,6 +92,15 @@ mapi_export mparm mparm_parse(const char const char *mparm_name(mparm parm); bool mparm_is_core(mparm parm); + +///////////////////////////////////////////////////////////////////// +// This type hold all properties that can be set that affect how a +// connection is made. There are methods to create/destroy etc., +// getters and setters based on enum mparm above, and getters +// and setters based on string values. +// Also, msettings_validate, msettings_parse_url and a number +// of helper functions. + typedef struct msettings msettings; /* NULL means OK. non-NULL is error message. Valid until next call. Do not free. */ @@ -158,6 +174,22 @@ bool msettings_lang_is_mal(const msettin bool msettings_lang_is_sql(const msettings *mp); bool msettings_lang_is_profiler(const msettings *mp); +///////////////////////////////////////////////////////////////////// +// Extend mapi.h + +// Mutable access settings of existing Mapi. +// Do not make changes while connected. +mapi_export msettings *mapi_get_settings(Mapi mid) + __attribute__((__nonnull__(1))); + +// Create Mapi from settings. +// Takes ownership of the settings except if malloc fails etc. +// In that case NULL is returned and ownership of the settings remains with +// the caller. +mapi_export Mapi mapi_settings(msettings *settings) + __attribute__((__nonnull__(1))); + + #ifdef __cplusplus } #endif _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org