LCOV - code coverage report
Current view: top level - clients/mapilib - msettings.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 4 4 100.0 %
Date: 2024-04-25 20:03:45 Functions: 0 0 -

          Line data    Source code
       1             : /*
       2             :  * SPDX-License-Identifier: MPL-2.0
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * Copyright 2024 MonetDB Foundation;
       9             :  * Copyright August 2008 - 2023 MonetDB B.V.;
      10             :  * Copyright 1997 - July 2008 CWI.
      11             :  */
      12             : 
      13             : #ifndef _MSETTINGS_H
      14             : #define _MSETTINGS_H 1
      15             : 
      16             : #include "mapi.h"
      17             : #include <stdbool.h>
      18             : 
      19             : #define MP__BOOL_START (100)
      20             : #define MP__LONG_START (200)
      21             : #define MP__STRING_START (300)
      22             : 
      23             : #ifdef __cplusplus
      24             : extern "C" {
      25             : #endif
      26             : 
      27             : /* avoid using "#ifdef WIN32" so that this file does not need our config.h */
      28             : #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__)
      29             : #ifndef LIBMAPI
      30             : #define mapi_export extern __declspec(dllimport)
      31             : #else
      32             : #define mapi_export extern __declspec(dllexport)
      33             : #endif
      34             : #else
      35             : #define mapi_export extern
      36             : #endif
      37             : 
      38             : /////////////////////////////////////////////////////////////////////
      39             : // This enum identifies properties that can be set that affect how a
      40             : // connection is made. In particular we have functies to parse strings
      41             : // into a an enum value, and back.
      42             : 
      43             : typedef enum mparm {
      44             :         MP_UNKNOWN,
      45             :         MP_IGNORE,
      46             : 
      47             :         // bool
      48             :         MP_TLS = MP__BOOL_START,
      49             :         MP_AUTOCOMMIT,
      50             : 
      51             :         // long
      52             :         MP_PORT = MP__LONG_START,
      53             :         MP_TIMEZONE,
      54             :         MP_REPLYSIZE,
      55             : 
      56             :         // string
      57             :         MP_SOCK = MP__STRING_START,
      58             :         MP_SOCKDIR,
      59             :         MP_CERT,
      60             :         MP_CLIENTKEY,
      61             :         MP_CLIENTCERT,
      62             :         MP_HOST,
      63             :         MP_DATABASE,
      64             :         MP_TABLESCHEMA,
      65             :         MP_TABLE,
      66             :         MP_CERTHASH,
      67             :         MP_USER,
      68             :         MP_PASSWORD,
      69             :         MP_LANGUAGE,
      70             :         MP_SCHEMA,              // TODO implement this
      71             :         MP_BINARY,
      72             : } mparm;
      73             : 
      74             : typedef enum mparm_class {
      75             :         MPCLASS_BOOL,
      76             :         MPCLASS_LONG,
      77             :         MPCLASS_STRING,
      78             : } mparm_class;
      79             : 
      80             : static inline mparm_class
      81       76989 : mparm_classify(mparm parm)
      82             : {
      83       76989 :         if (parm < MP__LONG_START)
      84             :                 return MPCLASS_BOOL;
      85       69174 :         else if (parm >= MP__STRING_START)
      86             :                 return MPCLASS_STRING;
      87             :         else
      88       39234 :                 return MPCLASS_LONG;
      89             : }
      90             : 
      91             : 
      92             : /* returns NULL if not found, pointer to mparm if found */
      93             : mapi_export mparm mparm_parse(const char *name);
      94             : const char *mparm_name(mparm parm);
      95             : bool mparm_is_core(mparm parm);
      96             : 
      97             : 
      98             : /////////////////////////////////////////////////////////////////////
      99             : // This type hold all properties that can be set that affect how a
     100             : // connection is made. There are methods to create/destroy etc.,
     101             : // getters and setters based on enum mparm above, and getters
     102             : // and setters based on string values.
     103             : // Also, msettings_validate, msettings_parse_url and a number
     104             : // of helper functions.
     105             : 
     106             : typedef struct msettings msettings;
     107             : 
     108             : /* NULL means OK. non-NULL is error message. Valid until next call. Do not free. */
     109             : typedef const char *msettings_error;
     110             : 
     111             : /* returns NULL if could not allocate */
     112             : mapi_export msettings *msettings_create(void);
     113             : msettings *msettings_clone(const msettings *mp);
     114             : extern const msettings *msettings_default;
     115             : 
     116             : /* always returns NULL */
     117             : mapi_export msettings *msettings_destroy(msettings *mp);
     118             : 
     119             : /* retrieve and set; call abort() on type error */
     120             : 
     121             : mapi_export const char* msetting_string(const msettings *mp, mparm parm);
     122             : msettings_error msetting_set_string(msettings *mp, mparm parm, const char* value)
     123             :         __attribute__((__nonnull__(3)));
     124             : 
     125             : mapi_export long msetting_long(const msettings *mp, mparm parm);
     126             : msettings_error msetting_set_long(msettings *mp, mparm parm, long value);
     127             : 
     128             : mapi_export bool msetting_bool(const msettings *mp, mparm parm);
     129             : msettings_error msetting_set_bool(msettings *mp, mparm parm, bool value);
     130             : 
     131             : /* parse into the appropriate type, or format into newly malloc'ed string (NULL means malloc failed) */
     132             : msettings_error msetting_parse(msettings *mp, mparm parm, const char *text);
     133             : char *msetting_as_string(msettings *mp, mparm parm);
     134             : 
     135             : /* store ignored parameter */
     136             : msettings_error msetting_set_ignored(msettings *mp, const char *key, const char *value);
     137             : 
     138             : /* store named parameter */
     139             : mapi_export msettings_error msetting_set_named(msettings *mp, bool allow_core, const char *key, const char *value);
     140             : 
     141             : /* update the msettings from the URL. set *error_buffer to NULL and return true
     142             :  * if success, set *error_buffer to malloc'ed error message and return false on failure.
     143             :  * if return value is true but *error_buffer is NULL, malloc failed. */
     144             : mapi_export bool msettings_parse_url(msettings *mp, const char *url, char **error_buffer);
     145             : 
     146             : /* 1 = true, 0 = false, -1 = could not parse */
     147             : mapi_export int msetting_parse_bool(const char *text);
     148             : 
     149             : /* return an error message if the validity rules are not satisfied */
     150             : mapi_export bool msettings_validate(msettings *mp, char **errmsg);
     151             : 
     152             : 
     153             : /* virtual parameters */
     154             : enum msetting_tls_verify {
     155             :         verify_none,
     156             :         verify_system,
     157             :         verify_cert,
     158             :         verify_hash,
     159             : };
     160             : mapi_export bool msettings_connect_scan(const msettings *mp);
     161             : mapi_export const char *msettings_connect_unix(const msettings *mp);
     162             : mapi_export const char *msettings_connect_tcp(const msettings *mp);
     163             : mapi_export long msettings_connect_port(const msettings *mp);
     164             : mapi_export const char *msettings_connect_certhash_digits(const msettings *mp);
     165             : mapi_export long msettings_connect_binary(const msettings *mp);
     166             : mapi_export enum msetting_tls_verify msettings_connect_tls_verify(const msettings *mp);
     167             : mapi_export const char *msettings_connect_clientkey(const msettings *mp);
     168             : mapi_export const char *msettings_connect_clientcert(const msettings *mp);
     169             : 
     170             : /* automatically incremented each time the corresponding field is updated */
     171             : long msettings_user_generation(const msettings *mp);
     172             : long msettings_password_generation(const msettings *mp);
     173             : 
     174             : /* convenience helpers*/
     175             : bool msettings_lang_is_mal(const msettings *mp);
     176             : bool msettings_lang_is_sql(const msettings *mp);
     177             : bool msettings_lang_is_profiler(const msettings *mp);
     178             : 
     179             : /////////////////////////////////////////////////////////////////////
     180             : // Extend mapi.h
     181             : 
     182             : // Mutable access settings of existing Mapi.
     183             : // Do not make changes while connected.
     184             : mapi_export msettings *mapi_get_settings(Mapi mid)
     185             :         __attribute__((__nonnull__(1)));
     186             : 
     187             : // Create Mapi from settings.
     188             : // Takes ownership of the settings except if malloc fails etc.
     189             : // In that case NULL is returned and ownership of the settings remains with
     190             : // the caller.
     191             : mapi_export Mapi mapi_settings(msettings *settings)
     192             :         __attribute__((__nonnull__(1)));
     193             : 
     194             : 
     195             : #ifdef __cplusplus
     196             : }
     197             : #endif
     198             : #endif                          /* _MSETTINGS_H */

Generated by: LCOV version 1.14