Man page of tw_parse_config(3)
Index
- NAME
- SYNOPSIS
- DESCRIPTION
- PARAMETERS
- CONFIGURATION FILE SYNTAX
- RETURN VALUE
- NOTES
- EXAMPLE CONFIGURATION FILE
- EXAMPLE
- SEE ALSO
- COPYRIGHT
NAME
tw_parse_config - parse a Textweiser configuration file
SYNOPSIS
C/C++ #include <tw.h> tw_errno_t tw_parse_config(const char *path, tw_config_t *config);
DESCRIPTION
tw_parse_config() parses a Textweiser configuration file and stores its contained configuration settings to config. Using a configuration file allows to configure Textweiser database access more easily.
PARAMETERS
- path (const char *)
-
Path to the configuration file within the filesystem.
- config (tw_config_t *)
-
Pointer to a configuration data structure.
It is recommended to initialize config using the TW_CONFIG_INITIALIZER macro on declaration.
config is re-initialized on any call of the function. Any settings that may have been previously stored within will be lost.
If tw_parse_config() succeeds, config will contain the settings given in the configuration file.
CONFIGURATION FILE SYNTAX
The syntax of Textweiser configuration files follows an easy to use
key/value scheme.
Empty lines and any leading/trailing whitespace is ignored.
Lines starting with the character # are considered comments.
Values may be enclosed within matching single or double quotes and are
assigned to keys using the = character.
SUPPORTED KEYS
- host
-
Hostname of the database server.
- user
-
Username for database authentification.
- passwd
-
Password for database authentification.
- db_name
-
Name of the Textweiser database.
- port
-
Port number of the database server.
- instance
-
Name of the Microsoft SQL Server instance.
- encrypt
-
Enable/disable communication encryption.
The following values are recognized:
- "yes" or "on"
-
Enable encryption.
- "no" or "off"
-
Disable encryption.
In order to trust a server's certificate, append the "trust-cert" token to the value, separated by a comma and/or whitespace, i.e.
encrypt = "yes, trust-cert"
RETURN VALUE
tw_parse_config() returns an error indicator (tw_errno_t).
A return value of TW_OK indicates success, any other value discriminates
the occurred error.
The function tw_strerror(3) can be used to obtain a natural language error message.
NOTES
- o
-
If the tw_config_t object is not needed anymore, tw_free_config_t(3) should be used to free its allocated memory.
- o
-
Any variable of type tw_config_t should be initialized using the macro TW_CONFIG_INITIALIZER on declaration.
- o
-
A passed config variable is re-initialized on any call of the function. Any settings that may have been previously stored within will be lost.
- o
-
Whenever the
tw_config_tdata structure has either been assigned to manually or modified, tw_free_config_t(3) must not be used to free the allocated memory.
EXAMPLE CONFIGURATION FILE
# this is a Textweiser example configuration file host = "localhost" user = 'test' passwd = 'secret' db_name = Textweiser encrypt = "yes, trust-cert" # port not set -> use default
EXAMPLE
C/C++ #include <stdio.h> #include <stdlib.h> #include <tw.h> int main(int argc, char *argv[]) { tw_errno_t rv = TW_OK; tw_config_t cfg; if (argc != 2) { fprintf(stderr, "usage: %s config-file\n", argv[0]); return(EXIT_FAILURE); } rv = tw_parse_config(argv[1], &cfg); if (rv != TW_OK) { fprintf(stderr, "Error: %s\n", tw_strerror(rv)); return(EXIT_FAILURE); } printf("== %s ==\n\n", argv[1]); printf("host -> %s\n", cfg.host ? cfg.host : "-"); printf("user -> %s\n", cfg.user ? cfg.user : "-"); printf("passwd -> %s\n", cfg.passwd ? cfg.passwd : "-"); printf("db_name -> %s\n", cfg.db_name ? cfg.db_name : "-"); printf("instance -> %s\n", cfg.instance ? cfg.instance : "-"); printf("port -> %u\n", cfg.port); printf("encrypt -> %s, trust-cert? %s\n", (cfg.encrypt & TW_ENCRYPT_ON ? "On" : "Off"), (cfg.encrypt & TW_ENCRYPT_TRUST_CERT ? "Yes" : "No")); tw_free_config_t(&cfg); return(EXIT_SUCCESS); }
The following example shows the output when used with the configuration file given in EXAMPLE CONFIGURATION FILE:
$ ./example_parse_config example.cfg == example.cfg == host -> localhost user -> test passwd -> secret db_name -> Textweiser instance -> - port -> 0 encrypt -> On, trust-cert? Yes
SEE ALSO
tw_free_config_t(3), tw_strerror(3)
Textweiser User Manual
http://www.lingua-systems.com/text-classifier/textweiser-library/
COPYRIGHT
Copyright (c) 2010-2011 Lingua-Systems Software GmbH


