NCBI C++ ToolKit
Classes | Macros | Functions | Variables
Configuration

Handle reading of configuration. More...

+ Collaboration diagram for Configuration:

Classes

struct  tdsvername_t
 

Macros

#define TDS_FIND(k, b, c)   tds_find(k, b, sizeof(b)/sizeof(b[0]), sizeof(b[0]), c)
 
#define TDS_FIND(k, b, c)   tds_find(k, b, TDS_VECTOR_SIZE(b), sizeof(b[0]), c)
 
#define tds_get_compiletime_settings   tds_get_compiletime_settings_ver100
 Return a structure capturing the compile-time settings provided to the configure script. More...
 

Functions

TDSLOGINtds_read_config_info (TDSSOCKET *tds, TDSLOGIN *login, TDSLOCALE *locale)
 tds_read_config_info() will fill the tds connection structure based on configuration information gathered in the following order: 1) Program specified in TDSLOGIN structure 2) The environment variables TDSVER, TDSDUMP, TDSPORT, TDSQUERY, TDSHOST 3) A config file with the following search order: a) a readable file specified by environment variable FREETDSCONF b) a readable file in ~/.freetds.conf c) a readable file in $prefix/etc/freetds.conf 3) ~/.interfaces if exists 4) $SYBASE/interfaces if exists 5) TDS_DEF_* default values More...
 
void tds_fix_login (TDSLOGIN *login)
 Fix configuration after reading it. More...
 
static int tds_try_conf_file (const char *path, const char *how, const char *server, TDSLOGIN *login)
 
static char * tds_get_home_file (const char *file)
 Return filename from HOME directory. More...
 
int tds_read_conf_file (TDSLOGIN *login, const char *server)
 Read configuration info for given server return 0 on error. More...
 
static int tds_read_conf_sections (FILE *in, const char *server, TDSLOGIN *login)
 
int tds_parse_boolean (const char *value, int default_value)
 
int tds_config_boolean (const char *option, const char *value, TDSLOGIN *login)
 
static void tds_config_encryption (const char *value, TDSLOGIN *login)
 
int tds_read_conf_section (FILE *in, const char *section, TDSCONFPARSE tds_conf_parse, void *param)
 Read a section of configuration file (INI style file) More...
 
void tds_parse_conf_section (const char *option, const char *value, void *param)
 
static int tds_config_login (TDSLOGIN *connection, TDSLOGIN *login)
 
static int tds_config_env_tdsdump (TDSLOGIN *login)
 
static void tds_config_env_tdsport (TDSLOGIN *login)
 
static void tds_config_env_tdsver (TDSLOGIN *login)
 
static int tds_config_env_tdshost (TDSLOGIN *login)
 
static void * tds_find (const void *key, const void *base, size_t nelem, size_t width, int(*compar)(const void *, const void *))
 
static int tds_vernanme_cmp (const void *key, const void *pelem)
 
TDS_USMALLINTtds_config_verstr (const char *tdsver, TDSLOGIN *login)
 Set TDS version from given string. More...
 
TDSRET tds_set_interfaces_file_loc (const char *interf)
 Set the full name of interface file. More...
 
struct addrinfotds_lookup_host (const char *servername)
 Get the IP address for a hostname. More...
 
TDSRET tds_lookup_host_set (const char *servername, struct addrinfo **addr)
 
static int tds_lookup_port (const char *portname)
 Given a portname lookup the port. More...
 
static int hexdigit (int c)
 
static int hex2num (char *hex)
 
static int search_interface_file (TDSLOGIN *login, const char *dir, const char *file, const char *host)
 Open and read the file 'file' searching for a logical server by the name of 'host'. More...
 
static int tds_read_interfaces (const char *server, TDSLOGIN *login)
 Try to find the IP number and port for a (possibly) logical server name. More...
 
static int parse_server_name_for_port (TDSLOGIN *connection, TDSLOGIN *login)
 Check the server name to find port info first Warning: connection-> & login-> are all modified when needed. More...
 
const TDS_COMPILETIME_SETTINGStds_get_compiletime_settings (void)
 Return a structure capturing the compile-time settings provided to the configure script. More...
 
static int tds_vername_cmp (const void *key, const void *pelem)
 
static bool parse_server_name_for_port (TDSLOGIN *connection, TDSLOGIN *login, bool update_server)
 Check the server name to find port info first Warning: connection-> & login-> are all modified when needed. More...
 

Variables

struct {
   char   value [7]
 
   unsigned char   to_return
 
boolean_values []
 
struct {
   char   value [7]
 
   unsigned char   to_return
 
boolean_values []
 

Detailed Description

Handle reading of configuration.

Macro Definition Documentation

◆ TDS_FIND [1/2]

#define TDS_FIND (   k,
  b,
 
)    tds_find(k, b, sizeof(b)/sizeof(b[0]), sizeof(b[0]), c)

Definition at line 855 of file config.c.

◆ TDS_FIND [2/2]

#define TDS_FIND (   k,
  b,
 
)    tds_find(k, b, TDS_VECTOR_SIZE(b), sizeof(b[0]), c)

Definition at line 893 of file config.c.

◆ tds_get_compiletime_settings

const TDS_COMPILETIME_SETTINGS * tds_get_compiletime_settings (   void)    tds_get_compiletime_settings_ver100

Return a structure capturing the compile-time settings provided to the configure script.

Definition at line 171 of file rename_ftds_tds.h.

Referenced by ct_config().

Function Documentation

◆ hex2num()

static int hex2num ( char *  hex)
static

Definition at line 1021 of file config.c.

References hex(), and hexdigit().

Referenced by search_interface_file().

◆ hexdigit()

static int hexdigit ( int  c)
static

Definition at line 1009 of file config.c.

Referenced by hex2num().

◆ parse_server_name_for_port() [1/2]

static int parse_server_name_for_port ( TDSLOGIN connection,
TDSLOGIN login 
)
static

Check the server name to find port info first Warning: connection-> & login-> are all modified when needed.

Returns
1 when found, else 0

Definition at line 1266 of file config.c.

References tds_login::instance_name, login, tds_login::port, tds_login::server_name, tds_dstr_copy(), tds_dstr_copyn(), tds_dstr_cstr(), and tds_dstr_empty.

Referenced by tds_read_config_info().

◆ parse_server_name_for_port() [2/2]

static bool parse_server_name_for_port ( TDSLOGIN connection,
TDSLOGIN login,
bool  update_server 
)
static

Check the server name to find port info first Warning: connection-> & login-> are all modified when needed.

Returns
true when found, else false

Definition at line 1301 of file config.c.

References tds_login::instance_name, login, tds_login::port, tds_login::server_name, tds_dstr_copy(), tds_dstr_copyn(), tds_dstr_cstr(), and tds_dstr_empty.

Referenced by tds_read_config_info().

◆ search_interface_file()

static int search_interface_file ( TDSLOGIN login,
const char *  dir,
const char *  file,
const char *  host 
)
static

Open and read the file 'file' searching for a logical server by the name of 'host'.

If one is found then lookup the IP address and port number and store them in 'login'

Parameters
dirname of base directory for interface file
filename of the interface file
hostlogical host to search for
Returns
0 if not fount 1 if found

Definition at line 1037 of file config.c.

References addrinfo, file, free(), hex2num(), in(), tds_login::ip_addrs, login, NULL, tds_login::port, tds_login::server_host_name, strcat, util::strcmp(), strtok_r, tds_addrinfo2str, tds_config_verstr(), TDS_DBG_INFO1, TDS_DBG_WARN, tds_dstr_copy(), TDS_ISSPACE, tds_lookup_host_set(), tds_lookup_port(), tds_new, TDS_SDIR_SEPARATOR, TDS_SUCCEED, and tdsdump_log.

Referenced by tds_read_interfaces().

◆ tds_config_boolean()

int tds_config_boolean ( const char *  option,
const char *  value,
TDSLOGIN login 
)

◆ tds_config_encryption()

static void tds_config_encryption ( const char *  value,
TDSLOGIN login 
)
static

◆ tds_config_env_tdsdump()

static int tds_config_env_tdsdump ( TDSLOGIN login)
static

◆ tds_config_env_tdshost()

static int tds_config_env_tdshost ( TDSLOGIN login)
static

◆ tds_config_env_tdsport()

static void tds_config_env_tdsport ( TDSLOGIN login)
static

◆ tds_config_env_tdsver()

static void tds_config_env_tdsver ( TDSLOGIN login)
static

Definition at line 819 of file config.c.

References login, tds_config_verstr(), TDS_DBG_INFO1, and tdsdump_log.

Referenced by tds_fix_login().

◆ tds_config_login()

static int tds_config_login ( TDSLOGIN connection,
TDSLOGIN login 
)
static

◆ tds_config_verstr()

TDS_USMALLINT* tds_config_verstr ( const char *  tdsver,
TDSLOGIN login 
)

Set TDS version from given string.

Parameters
tdsvertds string version
loginwhere to store information
Returns
as encoded hex value: high nybble major, low nybble minor.

Definition at line 891 of file config.c.

References assert, login, NULL, TDS_DBG_INFO1, TDS_FIND, tds_vername_cmp(), tds_vernanme_cmp(), tds_login::tds_version, tdsdump_log, and tdsvername_t::version.

Referenced by search_interface_file(), tds_config_env_tdsver(), and tds_parse_conf_section().

◆ tds_find()

static void* tds_find ( const void *  key,
const void *  base,
size_t  nelem,
size_t  width,
int(*)(const void *, const void *)  compar 
)
static

Definition at line 859 of file config.c.

References i, ncbi::grid::netcache::search::fields::key, and NULL.

◆ tds_fix_login()

void tds_fix_login ( TDSLOGIN login)

Fix configuration after reading it.

Currently this read some environment variables and replace some options.

Definition at line 280 of file config.c.

References login, tds_config_env_tdsdump(), tds_config_env_tdshost(), tds_config_env_tdsport(), and tds_config_env_tdsver().

Referenced by tds_read_config_info().

◆ tds_get_compiletime_settings()

const TDS_COMPILETIME_SETTINGS* tds_get_compiletime_settings ( void  )

Return a structure capturing the compile-time settings provided to the configure script.

Definition at line 1310 of file config.c.

References assert, FREETDS_SYSCONFDIR, TDS_VERSION_NO, and tds_compiletime_settings::tdsver.

◆ tds_get_home_file()

static char* tds_get_home_file ( const char *  file)
static

Return filename from HOME directory.

Returns
allocated string or NULL if error

Definition at line 320 of file config.c.

References asprintf, file, free(), NULL, and tds_get_homedir.

Referenced by tds_read_conf_file(), and tds_read_interfaces().

◆ tds_lookup_host()

struct addrinfo* tds_lookup_host ( const char *  servername)

Get the IP address for a hostname.

Store server's IP address in the string 'ip' in dotted-decimal notation. (The "hostname" might itself be a dotted-decimal address.

If we can't determine the IP address then 'ip' will be set to empty string.

Definition at line 960 of file config.c.

References addrinfo, assert, getaddrinfo, and NULL.

Referenced by tds_lookup_host_set().

◆ tds_lookup_host_set()

TDSRET tds_lookup_host_set ( const char *  servername,
struct addrinfo **  addr 
)

◆ tds_lookup_port()

static int tds_lookup_port ( const char *  portname)
static

Given a portname lookup the port.

If we can't determine the port number then return 0.

Definition at line 999 of file config.c.

References tds_getservice.

Referenced by search_interface_file(), tds_config_env_tdsport(), and tds_read_interfaces().

◆ tds_parse_boolean()

int tds_parse_boolean ( const char *  value,
int  default_value 
)

Definition at line 443 of file config.c.

References boolean_values, strcasecmp, TDS_VECTOR_SIZE, to_return, and value.

Referenced by tds_config_boolean().

◆ tds_parse_conf_section()

void tds_parse_conf_section ( const char *  option,
const char *  value,
void *  param 
)

Definition at line 588 of file config.c.

References addrinfo, tds_login::block_size, tds_login::cafile, tds_login::check_ssl_hostname, tds_login::client_charset, tds_login::connect_timeout, tds_login::crlfile, tds_login::database, tds_login::db_filename, tds_login::debug_flags, tds_login::dump_file, tds_login::emul_little_endian, tds_login::enable_tls_v1, tds_login::enable_tls_v1_specified, flags, tds_login::gssapi_use_delegation, tds_login::instance_name, int, tds_login::ip_addrs, tds_login::language, login, tds_login::mutual_authentication, NULL, tds_login::openssl_ciphers, option, tds_login::port, tds_login::query_timeout, tds_login::readonly_intent, tds_login::server_charset, tds_login::server_host_name, tds_login::server_name, tds_login::server_realm_name, tds_login::server_spn, util::strcmp(), tds_addrinfo2str, tds_config_boolean(), tds_config_encryption(), tds_config_verstr(), TDS_DBG_FUNC, TDS_DBG_INFO1, TDS_DBG_WARN, tds_dstr_copy(), tds_dstr_cstr(), TDS_FAILED, tds_g_append_mode, TDS_GSSAPI_DELEGATION, tds_lookup_host_set(), TDS_STR_APPENDMODE, TDS_STR_ASA_DATABASE, TDS_STR_BLKSZ, TDS_STR_CAFILE, TDS_STR_CHARSET, TDS_STR_CHECKSSLHOSTNAME, TDS_STR_CLCHARSET, TDS_STR_CONNTIMEOUT, TDS_STR_CRLFILE, TDS_STR_DATABASE, TDS_STR_DBFILENAME, TDS_STR_DEBUGFLAGS, TDS_STR_DUMPFILE, TDS_STR_EMUL_LE, TDS_STR_ENABLE_TLS_V1, TDS_STR_ENCRYPTION, TDS_STR_HOST, TDS_STR_INSTANCE, TDS_STR_LANGUAGE, TDS_STR_MUTUAL_AUTHENTICATION, TDS_STR_PORT, TDS_STR_QUERY_TIMEOUT, TDS_STR_READONLY_INTENT, TDS_STR_REALM, TDS_STR_SPN, TDS_STR_SWAPDT, TDS_STR_TEXTSZ, TDS_STR_TIMEOUT, TDS_STR_USE_UTF_16, TDS_STR_USELANMAN, TDS_STR_USENTLMV2, TDS_STR_VERSION, tdsdump_log, tds_login::text_size, TLS_STR_OPENSSL_CIPHERS, tmp, tds_login::use_lanman, tds_login::use_ntlmv2, tds_login::use_ntlmv2_specified, tds_login::use_utf16, val, tds_login::valid_configuration, and value.

Referenced by tds_read_conf_sections().

◆ tds_read_conf_file()

int tds_read_conf_file ( TDSLOGIN login,
const char *  server 
)

Read configuration info for given server return 0 on error.

Parameters
loginwhere to store configuration
serversection of file configuration that hold configuration for a server

Definition at line 341 of file config.c.

References asprintf, free(), freetds_conf, FREETDS_SYSCONFFILE, interf_file, location, login, NULL, TDS_DBG_INFO2, tds_get_home_file(), tds_try_conf_file(), and tdsdump_log.

Referenced by tds_read_config_info().

◆ tds_read_conf_section()

int tds_read_conf_section ( FILE *  in,
const char *  section,
TDSCONFPARSE  tds_conf_parse,
void *  param 
)

Read a section of configuration file (INI style file)

Parameters
inconfiguration file
sectionsection to read
tds_conf_parsecallback that receive every entry in section
paramparameter to pass to callback function

Definition at line 498 of file config.c.

References i, in(), option, strcasecmp, TDS_DBG_INFO1, TDS_ISSPACE, tdsdump_log, tolower(), and value.

Referenced by tds_read_conf_sections().

◆ tds_read_conf_sections()

static int tds_read_conf_sections ( FILE *  in,
const char *  server,
TDSLOGIN login 
)
static

◆ tds_read_config_info()

TDSLOGIN* tds_read_config_info ( TDSSOCKET tds,
TDSLOGIN login,
TDSLOCALE locale 
)

tds_read_config_info() will fill the tds connection structure based on configuration information gathered in the following order: 1) Program specified in TDSLOGIN structure 2) The environment variables TDSVER, TDSDUMP, TDSPORT, TDSQUERY, TDSHOST 3) A config file with the following search order: a) a readable file specified by environment variable FREETDSCONF b) a readable file in ~/.freetds.conf c) a readable file in $prefix/etc/freetds.conf 3) ~/.interfaces if exists 4) $SYBASE/interfaces if exists 5) TDS_DEF_* default values

.tdsrc and freetds.conf have been added to make the package easier to integration with various Linux and *BSD distributions.

Definition at line 136 of file config.c.

References addrinfo, tds_login::app_name, asprintf, tds_login::block_size, tds_login::bulk_copy, tds_login::cafile, tds_login::check_ssl_hostname, tds_login::client_charset, tds_login::client_host_name, tds_login::connect_timeout, tds_login::crlfile, tds_login::database, tds_login::db_filename, tds_login::debug_flags, tds_login::dump_file, tds_login::emul_little_endian, tds_login::encryption_level, free(), tds_login::instance_name, tds_login::ip_addrs, tds_login::language, tds_login::library, locale, login, NULL, tds_login::openssl_ciphers, parse_server_name_for_port(), pid_config_logpath, tds_login::port, tds_login::query_timeout, tds_login::readonly_intent, tds_login::server_charset, tds_login::server_host_name, tds_login::server_name, tds_login::server_realm_name, tds_login::server_spn, tds_login::suppress_language, tds, tds_addrinfo2str, tds_alloc_login, tds_config_login(), TDS_DBG_INFO1, tds_debug_flags, tds_dstr_cstr(), tds_dstr_dup(), tds_dstr_isempty(), tds_fix_login(), tds_free_login, tds_get_ctx, tds_init_login, tds_lookup_host_set(), TDS_MAJOR, TDS_MINOR, tds_read_conf_file(), tds_read_interfaces(), TDS_SUCCEED, tdsdump_close, tdsdump_isopen, tdsdump_log, tdsdump_open, TDSEINTF, tdserror, tds_login::text_size, tmp, tds_login::use_utf16, and tds_login::user_name.

◆ tds_read_interfaces()

static int tds_read_interfaces ( const char *  server,
TDSLOGIN login 
)
static

Try to find the IP number and port for a (possibly) logical server name.

Note
This function uses only the interfaces file and is deprecated.

Definition at line 1160 of file config.c.

References free(), interf_file, interfaces_path, tds_login::ip_addrs, login, NULL, tds_login::port, search_interface_file(), tds_login::server_host_name, TDS_DBG_INFO1, TDS_DEF_PORT, tds_dstr_copy(), tds_get_home_file(), tds_lookup_host_set(), tds_lookup_port(), TDS_SUCCEED, and tdsdump_log.

Referenced by tds_read_config_info().

◆ tds_set_interfaces_file_loc()

TDSRET tds_set_interfaces_file_loc ( const char *  interf)

Set the full name of interface file.

Parameters
interffile name

Definition at line 934 of file config.c.

References interf_file, NULL, strdup, TDS_FAIL, TDS_SUCCESS, and TDS_ZERO_FREE.

◆ tds_try_conf_file()

static int tds_try_conf_file ( const char *  path,
const char *  how,
const char *  server,
TDSLOGIN login 
)
static

Definition at line 290 of file config.c.

References in(), login, NULL, TDS_DBG_INFO1, TDS_DBG_INFO2, tds_read_conf_sections(), and tdsdump_log.

Referenced by tds_read_conf_file().

◆ tds_vername_cmp()

static int tds_vername_cmp ( const void *  key,
const void *  pelem 
)
static

Definition at line 918 of file config.c.

References ncbi::grid::netcache::search::fields::key, and util::strcmp().

Referenced by tds_config_verstr().

◆ tds_vernanme_cmp()

static int tds_vernanme_cmp ( const void *  key,
const void *  pelem 
)
static

Definition at line 879 of file config.c.

References ncbi::grid::netcache::search::fields::key, and util::strcmp().

Referenced by tds_config_verstr().

Variable Documentation

◆  [1/2]

const { ... } boolean_values[]
Initial value:
= {
{ "yes", 1 },
{ "no", 0 },
{ "on", 1 },
{ "off", 0 },
{ "true", 1 },
{ "false", 0 }
}

Referenced by tds_parse_boolean().

◆  [2/2]

const { ... } boolean_values[]
Initial value:
= {
{ "yes", 1 },
{ "no", 0 },
{ "on", 1 },
{ "off", 0 },
{ "true", 1 },
{ "false", 0 }
}

Referenced by tds_parse_boolean().

◆  [1/2]

unsigned { ... } to_return

Definition at line 432 of file config.c.

◆  [2/2]

unsigned { ... } to_return

Definition at line 437 of file config.c.

◆  [1/2]

char { ... } value[7]

Definition at line 431 of file config.c.

◆  [2/2]

char { ... } value[7]

Definition at line 436 of file config.c.

Modified on Tue Apr 30 06:42:27 2024 by modify_doxy.py rev. 669887