1 /*
2  * Copyright 2013 MongoDB, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "mongoc-prelude.h"
18 
19 #ifndef MONGOC_URI_H
20 #define MONGOC_URI_H
21 
22 #include <bson/bson.h>
23 
24 #include "mongoc-macros.h"
25 #include "mongoc-host-list.h"
26 #include "mongoc-read-prefs.h"
27 #include "mongoc-read-concern.h"
28 #include "mongoc-write-concern.h"
29 #include "mongoc-config.h"
30 
31 
32 #ifndef MONGOC_DEFAULT_PORT
33 #define MONGOC_DEFAULT_PORT 27017
34 #endif
35 
36 #define MONGOC_URI_APPNAME "appname"
37 #define MONGOC_URI_AUTHMECHANISM "authmechanism"
38 #define MONGOC_URI_AUTHMECHANISMPROPERTIES "authmechanismproperties"
39 #define MONGOC_URI_AUTHSOURCE "authsource"
40 #define MONGOC_URI_CANONICALIZEHOSTNAME "canonicalizehostname"
41 #define MONGOC_URI_CONNECTTIMEOUTMS "connecttimeoutms"
42 #define MONGOC_URI_COMPRESSORS "compressors"
43 #define MONGOC_URI_DIRECTCONNECTION "directconnection"
44 #define MONGOC_URI_GSSAPISERVICENAME "gssapiservicename"
45 #define MONGOC_URI_HEARTBEATFREQUENCYMS "heartbeatfrequencyms"
46 #define MONGOC_URI_JOURNAL "journal"
47 #define MONGOC_URI_LOCALTHRESHOLDMS "localthresholdms"
48 #define MONGOC_URI_MAXIDLETIMEMS "maxidletimems"
49 #define MONGOC_URI_MAXPOOLSIZE "maxpoolsize"
50 #define MONGOC_URI_MAXSTALENESSSECONDS "maxstalenessseconds"
51 #define MONGOC_URI_MINPOOLSIZE "minpoolsize"
52 #define MONGOC_URI_READCONCERNLEVEL "readconcernlevel"
53 #define MONGOC_URI_READPREFERENCE "readpreference"
54 #define MONGOC_URI_READPREFERENCETAGS "readpreferencetags"
55 #define MONGOC_URI_REPLICASET "replicaset"
56 #define MONGOC_URI_RETRYREADS "retryreads"
57 #define MONGOC_URI_RETRYWRITES "retrywrites"
58 #define MONGOC_URI_SAFE "safe"
59 #define MONGOC_URI_SERVERSELECTIONTIMEOUTMS "serverselectiontimeoutms"
60 #define MONGOC_URI_SERVERSELECTIONTRYONCE "serverselectiontryonce"
61 #define MONGOC_URI_SLAVEOK "slaveok"
62 #define MONGOC_URI_SOCKETCHECKINTERVALMS "socketcheckintervalms"
63 #define MONGOC_URI_SOCKETTIMEOUTMS "sockettimeoutms"
64 #define MONGOC_URI_TLS "tls"
65 #define MONGOC_URI_TLSCERTIFICATEKEYFILE "tlscertificatekeyfile"
66 #define MONGOC_URI_TLSCERTIFICATEKEYFILEPASSWORD "tlscertificatekeyfilepassword"
67 #define MONGOC_URI_TLSCAFILE "tlscafile"
68 #define MONGOC_URI_TLSALLOWINVALIDCERTIFICATES "tlsallowinvalidcertificates"
69 #define MONGOC_URI_TLSALLOWINVALIDHOSTNAMES "tlsallowinvalidhostnames"
70 #define MONGOC_URI_TLSINSECURE "tlsinsecure"
71 #define MONGOC_URI_TLSDISABLECERTIFICATEREVOCATIONCHECK \
72    "tlsdisablecertificaterevocationcheck"
73 #define MONGOC_URI_TLSDISABLEOCSPENDPOINTCHECK "tlsdisableocspendpointcheck"
74 #define MONGOC_URI_W "w"
75 #define MONGOC_URI_WAITQUEUEMULTIPLE "waitqueuemultiple"
76 #define MONGOC_URI_WAITQUEUETIMEOUTMS "waitqueuetimeoutms"
77 #define MONGOC_URI_WTIMEOUTMS "wtimeoutms"
78 #define MONGOC_URI_ZLIBCOMPRESSIONLEVEL "zlibcompressionlevel"
79 
80 /* Deprecated in MongoDB 4.2, use "tls" variants instead. */
81 #define MONGOC_URI_SSL "ssl"
82 #define MONGOC_URI_SSLCLIENTCERTIFICATEKEYFILE "sslclientcertificatekeyfile"
83 #define MONGOC_URI_SSLCLIENTCERTIFICATEKEYPASSWORD \
84    "sslclientcertificatekeypassword"
85 #define MONGOC_URI_SSLCERTIFICATEAUTHORITYFILE "sslcertificateauthorityfile"
86 #define MONGOC_URI_SSLALLOWINVALIDCERTIFICATES "sslallowinvalidcertificates"
87 #define MONGOC_URI_SSLALLOWINVALIDHOSTNAMES "sslallowinvalidhostnames"
88 
89 BSON_BEGIN_DECLS
90 
91 
92 typedef struct _mongoc_uri_t mongoc_uri_t;
93 
94 
95 MONGOC_EXPORT (mongoc_uri_t *)
96 mongoc_uri_copy (const mongoc_uri_t *uri);
97 MONGOC_EXPORT (void)
98 mongoc_uri_destroy (mongoc_uri_t *uri);
99 MONGOC_EXPORT (mongoc_uri_t *)
100 mongoc_uri_new (const char *uri_string) BSON_GNUC_WARN_UNUSED_RESULT;
101 MONGOC_EXPORT (mongoc_uri_t *)
102 mongoc_uri_new_with_error (const char *uri_string,
103                            bson_error_t *error) BSON_GNUC_WARN_UNUSED_RESULT;
104 MONGOC_EXPORT (mongoc_uri_t *)
105 mongoc_uri_new_for_host_port (const char *hostname,
106                               uint16_t port) BSON_GNUC_WARN_UNUSED_RESULT;
107 MONGOC_EXPORT (const mongoc_host_list_t *)
108 mongoc_uri_get_hosts (const mongoc_uri_t *uri);
109 MONGOC_EXPORT (const char *)
110 mongoc_uri_get_service (const mongoc_uri_t *uri);
111 MONGOC_EXPORT (const char *)
112 mongoc_uri_get_database (const mongoc_uri_t *uri);
113 MONGOC_EXPORT (bool)
114 mongoc_uri_set_database (mongoc_uri_t *uri, const char *database);
115 MONGOC_EXPORT (const bson_t *)
116 mongoc_uri_get_compressors (const mongoc_uri_t *uri);
117 MONGOC_EXPORT (const bson_t *)
118 mongoc_uri_get_options (const mongoc_uri_t *uri);
119 MONGOC_EXPORT (const char *)
120 mongoc_uri_get_password (const mongoc_uri_t *uri);
121 MONGOC_EXPORT (bool)
122 mongoc_uri_set_password (mongoc_uri_t *uri, const char *password);
123 MONGOC_EXPORT (bool)
124 mongoc_uri_has_option (const mongoc_uri_t *uri, const char *key);
125 MONGOC_EXPORT (bool)
126 mongoc_uri_option_is_int32 (const char *key);
127 MONGOC_EXPORT (bool)
128 mongoc_uri_option_is_int64 (const char *key);
129 MONGOC_EXPORT (bool)
130 mongoc_uri_option_is_bool (const char *key);
131 MONGOC_EXPORT (bool)
132 mongoc_uri_option_is_utf8 (const char *key);
133 MONGOC_EXPORT (int32_t)
134 mongoc_uri_get_option_as_int32 (const mongoc_uri_t *uri,
135                                 const char *option,
136                                 int32_t fallback);
137 MONGOC_EXPORT (int64_t)
138 mongoc_uri_get_option_as_int64 (const mongoc_uri_t *uri,
139                                 const char *option,
140                                 int64_t fallback);
141 MONGOC_EXPORT (bool)
142 mongoc_uri_get_option_as_bool (const mongoc_uri_t *uri,
143                                const char *option,
144                                bool fallback);
145 MONGOC_EXPORT (const char *)
146 mongoc_uri_get_option_as_utf8 (const mongoc_uri_t *uri,
147                                const char *option,
148                                const char *fallback);
149 MONGOC_EXPORT (bool)
150 mongoc_uri_set_option_as_int32 (mongoc_uri_t *uri,
151                                 const char *option,
152                                 int32_t value);
153 MONGOC_EXPORT (bool)
154 mongoc_uri_set_option_as_int64 (mongoc_uri_t *uri,
155                                 const char *option,
156                                 int64_t value);
157 MONGOC_EXPORT (bool)
158 mongoc_uri_set_option_as_bool (mongoc_uri_t *uri,
159                                const char *option,
160                                bool value);
161 MONGOC_EXPORT (bool)
162 mongoc_uri_set_option_as_utf8 (mongoc_uri_t *uri,
163                                const char *option,
164                                const char *value);
165 MONGOC_EXPORT (const bson_t *)
166 mongoc_uri_get_read_prefs (const mongoc_uri_t *uri)
167    BSON_GNUC_DEPRECATED_FOR (mongoc_uri_get_read_prefs_t);
168 MONGOC_EXPORT (const char *)
169 mongoc_uri_get_replica_set (const mongoc_uri_t *uri);
170 MONGOC_EXPORT (const char *)
171 mongoc_uri_get_string (const mongoc_uri_t *uri);
172 MONGOC_EXPORT (const char *)
173 mongoc_uri_get_username (const mongoc_uri_t *uri);
174 MONGOC_EXPORT (bool)
175 mongoc_uri_set_username (mongoc_uri_t *uri, const char *username);
176 MONGOC_EXPORT (const bson_t *)
177 mongoc_uri_get_credentials (const mongoc_uri_t *uri);
178 MONGOC_EXPORT (const char *)
179 mongoc_uri_get_auth_source (const mongoc_uri_t *uri);
180 MONGOC_EXPORT (bool)
181 mongoc_uri_set_auth_source (mongoc_uri_t *uri, const char *value);
182 MONGOC_EXPORT (const char *)
183 mongoc_uri_get_appname (const mongoc_uri_t *uri);
184 MONGOC_EXPORT (bool)
185 mongoc_uri_set_appname (mongoc_uri_t *uri, const char *value);
186 MONGOC_EXPORT (bool)
187 mongoc_uri_set_compressors (mongoc_uri_t *uri, const char *value);
188 MONGOC_EXPORT (const char *)
189 mongoc_uri_get_auth_mechanism (const mongoc_uri_t *uri);
190 MONGOC_EXPORT (bool)
191 mongoc_uri_set_auth_mechanism (mongoc_uri_t *uri, const char *value);
192 MONGOC_EXPORT (bool)
193 mongoc_uri_get_mechanism_properties (const mongoc_uri_t *uri,
194                                      bson_t *properties);
195 MONGOC_EXPORT (bool)
196 mongoc_uri_set_mechanism_properties (mongoc_uri_t *uri,
197                                      const bson_t *properties);
198 MONGOC_EXPORT (bool)
199 mongoc_uri_get_ssl (const mongoc_uri_t *uri)
200    BSON_GNUC_DEPRECATED_FOR (mongoc_uri_get_tls);
201 MONGOC_EXPORT (bool)
202 mongoc_uri_get_tls (const mongoc_uri_t *uri);
203 MONGOC_EXPORT (char *)
204 mongoc_uri_unescape (const char *escaped_string);
205 MONGOC_EXPORT (const mongoc_read_prefs_t *)
206 mongoc_uri_get_read_prefs_t (const mongoc_uri_t *uri);
207 MONGOC_EXPORT (void)
208 mongoc_uri_set_read_prefs_t (mongoc_uri_t *uri,
209                              const mongoc_read_prefs_t *prefs);
210 MONGOC_EXPORT (const mongoc_write_concern_t *)
211 mongoc_uri_get_write_concern (const mongoc_uri_t *uri);
212 MONGOC_EXPORT (void)
213 mongoc_uri_set_write_concern (mongoc_uri_t *uri,
214                               const mongoc_write_concern_t *wc);
215 MONGOC_EXPORT (const mongoc_read_concern_t *)
216 mongoc_uri_get_read_concern (const mongoc_uri_t *uri);
217 MONGOC_EXPORT (void)
218 mongoc_uri_set_read_concern (mongoc_uri_t *uri,
219                              const mongoc_read_concern_t *rc);
220 
221 BSON_END_DECLS
222 
223 
224 #endif /* MONGOC_URI_H */
225