~drizzle-trunk/drizzle/development

2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
1
/*
2
 * Drizzle Client & Protocol Library
3
 *
4
 * Copyright (C) 2008 Eric Day (eday@oddments.org)
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions are
9
 * met:
10
 *
11
 *     * Redistributions of source code must retain the above copyright
12
 * notice, this list of conditions and the following disclaimer.
13
 *
14
 *     * Redistributions in binary form must reproduce the above
15
 * copyright notice, this list of conditions and the following disclaimer
16
 * in the documentation and/or other materials provided with the
17
 * distribution.
18
 *
19
 *     * The names of its contributors may not be used to endorse or
20
 * promote products derived from this software without specific prior
21
 * written permission.
22
 *
23
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
 *
35
 */
36
2449.1.4 by Brian Aker
Complete update of libdrizzle
37
#pragma once
38
2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
39
/**
40
 * @file
41
 * @brief Drizzle Declarations
42
 */
43
44
#include <inttypes.h>
45
#include <sys/types.h>
46
47
#ifdef _WIN32
48
# define WIN32_LEAN_AND_MEAN
49
50
# include <Windows.h>
51
# include <winsock2.h>
52
# include <ws2tcpip.h>
53
# include <io.h>
54
55
# undef close
56
# define close _close
57
typedef unsigned int in_port_t;
58
typedef long ssize_t;
59
60
# define snprintf _snprintf
61
# define inline __inline
62
63
struct sockaddr_un
64
{
65
  short int sun_family;
66
  char sun_path[108];
67
};
68
69
# define poll WSAPoll
70
//# define pollfd WSAPOLLFD
71
72
#if defined(__GNUC__)
73
# include <stdbool.h>
74
#else
75
# if !defined(__cplusplus)
76
typedef enum { false = 0, true = 1 } _Bool;
77
typedef _Bool bool;
78
#endif 
79
#endif
80
81
#else
82
# if !defined(__cplusplus)
83
#  include <stdbool.h>
84
# endif
85
# include <sys/socket.h>
86
# include <netinet/in.h>
87
# include <arpa/inet.h>
88
# include <sys/un.h>
89
# include <netdb.h>
90
# include <poll.h>
91
#endif
92
93
#include <assert.h>
94
#include <errno.h>
95
2449.1.2 by Brian Aker
Additional fixes for libdrizzle.
96
#include <libdrizzle-2.0/visibility.h>
97
#include <libdrizzle-2.0/constants.h>
98
#include <libdrizzle-2.0/structs.h>
99
#include <libdrizzle-2.0/conn.h>
100
#include <libdrizzle-2.0/result.h>
101
#include <libdrizzle-2.0/column.h>
2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
102
103
#ifdef  __cplusplus
104
extern "C" {
105
#endif
106
107
/**
108
 * @addtogroup drizzle Drizzle Declarations
109
 * @ingroup drizzle_client_interface
110
 * @ingroup drizzle_server_interface
111
 *
112
 * This is the core library structure that other structures (such as
113
 * connections) are created from.
114
 *
115
 * There is no locking within a single drizzle_st structure, so for threaded
116
 * applications you must either ensure isolation in the application or use
117
 * multiple drizzle_st structures (for example, one for each thread).
118
 * @{
119
 */
120
121
/**
122
 * Get library version string.
123
 *
124
 * @return Pointer to static buffer in library that holds the version string.
125
 */
126
DRIZZLE_API
127
const char *drizzle_version(void);
128
129
/**
130
 * Get bug report URL.
131
 *
132
 * @return Bug report URL string.
133
 */
134
DRIZZLE_API
135
const char *drizzle_bugreport(void);
136
137
/**
138
 * Get string with the name of the given verbose level.
139
 *
140
 * @param[in] verbose Verbose logging level.
141
 * @return String form of verbose level.
142
 */
143
DRIZZLE_API
144
const char *drizzle_verbose_name(drizzle_verbose_t verbose);
145
146
/**
147
 * Initialize a drizzle structure. Always check the return value even if passing
148
 * in a pre-allocated structure. Some other initialization may have failed.
149
 *
150
 * @param[in] drizzle Caller allocated structure, or NULL to allocate one.
151
 * @return On success, a pointer to the (possibly allocated) structure. On
152
 * failure this will be NULL.
153
 */
154
DRIZZLE_API
2463.1.2 by Brian Aker
First pass, drizzle_create() no longer takes an argument. This means that we can now change drizzle_st without being concerned about ABI.
155
drizzle_st *drizzle_create();
2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
156
157
/**
158
 * Clone a drizzle structure.
159
 *
160
 * @param[in] drizzle Caller allocated structure, or NULL to allocate one.
161
 * @param[in] from Drizzle structure to use as a source to clone from.
162
 * @return Same return as drizzle_create().
163
 */
164
DRIZZLE_API
2463.1.2 by Brian Aker
First pass, drizzle_create() no longer takes an argument. This means that we can now change drizzle_st without being concerned about ABI.
165
drizzle_st *drizzle_clone(const drizzle_st *from);
2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
166
167
/**
168
 * Free a drizzle structure.
169
 *
170
 * @param[in] drizzle Drizzle structure previously initialized with
171
 *  drizzle_create() or drizzle_clone().
172
 */
173
DRIZZLE_API
174
void drizzle_free(drizzle_st *drizzle);
175
176
/**
177
 * Return an error string for last error encountered.
178
 *
179
 * @param[in] drizzle Drizzle structure previously initialized with
180
 *  drizzle_create() or drizzle_clone().
181
 * @return Pointer to static buffer in library that holds an error string.
182
 */
183
DRIZZLE_API
184
const char *drizzle_error(const drizzle_st *drizzle);
185
186
/**
187
 * Value of errno in the case of a DRIZZLE_RETURN_ERRNO return value.
188
 *
189
 * @param[in] drizzle Drizzle structure previously initialized with
190
 *  drizzle_create() or drizzle_clone().
191
 * @return An errno value as defined in your system errno.h file.
192
 */
193
DRIZZLE_API
194
int drizzle_errno(const drizzle_st *drizzle);
195
196
/**
197
 * Get server defined error code for the last result read.
198
 *
199
 * @param[in] drizzle Drizzle structure previously initialized with
200
 *  drizzle_create() or drizzle_clone().
201
 * @return An error code given back in the server response.
202
 */
203
DRIZZLE_API
204
uint16_t drizzle_error_code(const drizzle_st *drizzle);
205
206
/**
207
 * Get SQL state code for the last result read.
208
 *
209
 * @param[in] drizzle Drizzle structure previously initialized with
210
 *  drizzle_create() or drizzle_clone().
211
 * @return A SQLSTATE code given back in the server response.
212
 */
213
DRIZZLE_API
214
const char *drizzle_sqlstate(const drizzle_st *drizzle);
215
216
/**
217
 * Get application context pointer.
218
 *
219
 * @param[in] drizzle Drizzle structure previously initialized with
220
 *  drizzle_create() or drizzle_clone().
221
 * @return Application context that was previously set, or NULL.
222
 */
223
DRIZZLE_API
224
void *drizzle_context(const drizzle_st *drizzle);
225
226
/**
227
 * Set application context pointer.
228
 *
229
 * @param[in] drizzle Drizzle structure previously initialized with
230
 *  drizzle_create() or drizzle_clone().
231
 * @param[in] context Application context to set.
232
 */
233
DRIZZLE_API
234
void drizzle_set_context(drizzle_st *drizzle, void *context);
235
236
/**
237
 * Set function to call when the drizzle structure is being cleaned up so
238
 * the application can clean up the context pointer.
239
 *
240
 * @param[in] drizzle Drizzle structure previously initialized with
241
 *  drizzle_create() or drizzle_clone().
242
 * @param[in] function Function to call to clean up drizzle context.
243
 */
244
DRIZZLE_API
245
void drizzle_set_context_free_fn(drizzle_st *drizzle,
246
                                 drizzle_context_free_fn *function);
247
248
/**
249
 * Get current socket I/O activity timeout value.
250
 *
251
 * @param[in] drizzle Drizzle structure previously initialized with
252
 *  drizzle_create() or drizzle_clone().
253
 * @return Timeout in milliseconds to wait for I/O activity. A negative value
254
 *  means an infinite timeout.
255
 */
256
DRIZZLE_API
257
int drizzle_timeout(const drizzle_st *drizzle);
258
259
/**
260
 * Set socket I/O activity timeout for connections in a Drizzle structure.
261
 *
262
 * @param[in] drizzle Drizzle structure previously initialized with
263
 *  drizzle_create() or drizzle_clone().
264
 * @param[in] timeout Milliseconds to wait for I/O activity. A negative value
265
 *  means an infinite timeout.
266
 */
267
DRIZZLE_API
268
void drizzle_set_timeout(drizzle_st *drizzle, int timeout);
269
270
/**
271
 * Get current verbosity threshold for logging messages.
272
 *
273
 * @param[in] drizzle Drizzle structure previously initialized with
274
 *  drizzle_create() or drizzle_clone().
275
 * @return Current verbosity threshold.
276
 */
277
DRIZZLE_API
278
drizzle_verbose_t drizzle_verbose(const drizzle_st *drizzle);
279
280
/**
281
 * Set verbosity threshold for logging messages. If this is set above
282
 * DRIZZLE_VERBOSE_NEVER and the drizzle_set_log_fn() callback is set to NULL,
283
 * messages are printed to STDOUT.
284
 *
285
 * @param[in] drizzle Drizzle structure previously initialized with
286
 *  drizzle_create() or drizzle_clone().
287
 * @param[in] verbose Verbosity threshold of what to log.
288
 */
289
DRIZZLE_API
290
void drizzle_set_verbose(drizzle_st *drizzle, drizzle_verbose_t verbose);
291
292
/**
293
 * Set logging function for a drizzle structure. This function is only called
294
 * for log messages that are above the verbosity threshold set with
295
 * drizzle_set_verbose().
296
 *
297
 * @param[in] drizzle Drizzle structure previously initialized with
298
 *  drizzle_create() or drizzle_clone().
299
 * @param[in] function Function to call when there is a logging message.
300
 * @param[in] context Argument to pass into the callback function.
301
 */
302
DRIZZLE_API
303
void drizzle_set_log_fn(drizzle_st *drizzle, drizzle_log_fn *function,
304
                        void *context);
305
306
/**
307
 * Set a custom I/O event watcher function for a drizzle structure. Used to
308
 * integrate libdrizzle with a custom event loop. The callback will be invoked
309
 * to register or deregister interest in events for a connection. When the
310
 * events are triggered, drizzle_con_set_revents() should be called to
311
 * indicate which events are ready. The event loop should stop waiting for
312
 * these events, as libdrizzle will call the callback again if it is still
313
 * interested. To resume processing, the libdrizzle function that returned
314
 * DRIZZLE_RETURN_IO_WAIT should be called again. See drizzle_event_watch_fn().
315
 *
316
 * @param[in] drizzle Drizzle structure previously initialized with
317
 *  drizzle_create() or drizzle_clone().
318
 * @param[in] function Function to call when there is an I/O event.
319
 * @param[in] context Argument to pass into the callback function.
320
 */
321
DRIZZLE_API
322
void drizzle_set_event_watch_fn(drizzle_st *drizzle,
323
                                drizzle_event_watch_fn *function,
324
                                void *context);
325
326
/**
327
 * Initialize a connection structure. Always check the return value even if
328
 * passing in a pre-allocated structure. Some other initialization may have
329
 * failed.
330
 *
331
 * @param[in] drizzle Drizzle structure previously initialized with
332
 *  drizzle_create() or drizzle_clone().
333
 * @param[in] con Caller allocated structure, or NULL to allocate one.
334
 * @return On success, a pointer to the (possibly allocated) structure. On
335
 *  failure this will be NULL.
336
 */
337
DRIZZLE_API
2463.1.4 by Brian Aker
Remove con from being passed object.
338
drizzle_con_st *drizzle_con_create(drizzle_st *drizzle);
2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
339
340
/**
341
 * Clone a connection structure.
342
 *
343
 * @param[in] drizzle Drizzle structure previously initialized with
344
 *  drizzle_create() or drizzle_clone().
345
 * @param[in] con Caller allocated structure, or NULL to allocate one.
346
 * @param[in] from Connection structure to use as a source to clone from.
347
 * @return Same return as drizzle_con_create().
348
 */
349
DRIZZLE_API
2463.1.4 by Brian Aker
Remove con from being passed object.
350
drizzle_con_st *drizzle_con_clone(drizzle_st *drizzle, drizzle_con_st *con);
2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
351
2463.1.3 by Brian Aker
Redo the way options are handled.
352
DRIZZLE_API
353
drizzle_return_t drizzle_set_option(drizzle_st *drizzle, drizzle_options_t arg, bool set);
354
2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
355
/**
356
 * Free a connection structure.
357
 *
358
 * @param[in] con Connection structure previously initialized with
359
 *  drizzle_con_create(), drizzle_con_clone(), or related functions.
360
 */
361
DRIZZLE_API
362
void drizzle_con_free(drizzle_con_st *con);
363
364
/**
365
 * Free all connections in a drizzle structure.
366
 *
367
 * @param[in] drizzle Drizzle structure previously initialized with
368
 *  drizzle_create() or drizzle_clone().
369
 */
370
DRIZZLE_API
371
void drizzle_con_free_all(drizzle_st *drizzle);
372
373
/**
374
 * Wait for I/O on connections.
375
 *
376
 * @param[in] drizzle Drizzle structure previously initialized with
377
 *  drizzle_create() or drizzle_clone().
378
 * @return Standard drizzle return value.
379
 */
380
DRIZZLE_API
381
drizzle_return_t drizzle_con_wait(drizzle_st *drizzle);
382
383
/**
384
 * Get next connection that is ready for I/O.
385
 *
386
 * @param[in] drizzle Drizzle structure previously initialized with
387
 *  drizzle_create() or drizzle_clone().
388
 * @return Connection that is ready for I/O, or NULL if there are none.
389
 */
390
DRIZZLE_API
391
drizzle_con_st *drizzle_con_ready(drizzle_st *drizzle);
392
393
/** @} */
394
395
#ifdef  __cplusplus
396
}
397
#endif