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 : #include "ODBCGlobal.h"
14 : #include "ODBCAttrs.h"
15 :
16 : #ifdef HAVE_ODBCINST_H
17 : #include <odbcinst.h>
18 : #endif
19 :
20 : static const char *suggest_on_off[] = {
21 : "On",
22 : "Off",
23 : NULL,
24 : };
25 :
26 : static const char *suggest_monetdb[] = {
27 : "monetdb",
28 : NULL,
29 : };
30 :
31 : const struct attr_setting attr_settings[] = {
32 : { "UID", "User", MP_USER, .is_enum = false, .values = suggest_monetdb },
33 : { "PWD", "Password", MP_PASSWORD, .is_enum = false, .values = suggest_monetdb },
34 : { "DATABASE", "Database", MP_DATABASE },
35 : { "PORT", "Port", MP_PORT },
36 : { "HOST", "Server", MP_HOST, },
37 : { "SOCK", "Unix Socket", MP_SOCK },
38 : { "TLS", "Encrypt", MP_TLS, .is_enum = true, .values = suggest_on_off },
39 : { "CERT", "Server Certificate", MP_CERT },
40 : { "CERTHASH", "Server Certificate Hash", MP_CERTHASH },
41 : { "CLIENTKEY", "Client Key", MP_CLIENTKEY },
42 : { "CLIENTCERT", "Client Certificate", MP_CLIENTCERT },
43 : { "AUTOCOMMIT", "Autocommit", MP_AUTOCOMMIT, .is_enum = true, .values = suggest_on_off },
44 : { "SCHEMA", "Schema", MP_SCHEMA },
45 : { "TIMEZONE", "Time Zone", MP_TIMEZONE },
46 : { "REPLYSIZE", "Reply Size", MP_REPLYSIZE },
47 : { "LOGFILE", "Log File", MP_LOGFILE },
48 : { "LOGINTIMEOUT", "Login Timeout", MP_CONNECT_TIMEOUT},
49 : { "CONNECTIONTIMEOUT", "Connection Timeout", MP_REPLY_TIMEOUT},
50 : { "CLIENTINFO", "Send Client Info", MP_CLIENT_INFO },
51 : { "APPNAME", "Application Name", MP_CLIENT_APPLICATION },
52 : { "CLIENTREMARK", "Client Remark", MP_CLIENT_REMARK },
53 : { "MAPTOLONGVARCHAR", NULL, MP_MAPTOLONGVARCHAR },
54 : };
55 :
56 : const int attr_setting_count = sizeof(attr_settings) / sizeof(attr_settings[0]);
57 :
58 : int
59 63 : attr_setting_lookup(const char *attr_name, bool allow_alt_name)
60 : {
61 892 : for (int i = 0; i < attr_setting_count; i++) {
62 863 : const struct attr_setting *entry = &attr_settings[i];
63 863 : if (strcasecmp(attr_name, entry->name) == 0)
64 22 : return i;
65 841 : if (allow_alt_name && entry->alt_name && strcasecmp(attr_name, entry->alt_name) == 0)
66 12 : return i;
67 : }
68 : return -1;
69 : }
70 :
|