1#ifndef MYSQL_SERVICE_THD_RND_INCLUDED
2/* Copyright (C) 2017 MariaDB Corporation
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17/**
18 @file
19 This service provides access to the thd-local random number generator.
20
21 It's preferable over the global one, because concurrent threads
22 can generate random numbers without fighting each other over the access
23 to the shared rnd state.
24*/
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#ifndef MYSQL_ABI_CHECK
31#include <stdlib.h>
32#endif
33
34extern struct thd_rnd_service_st {
35 double (*thd_rnd_ptr)(MYSQL_THD thd);
36 void (*thd_c_r_p_ptr)(MYSQL_THD thd, char *to, size_t length);
37} *thd_rnd_service;
38
39#ifdef MYSQL_DYNAMIC_PLUGIN
40#define thd_rnd(A) thd_rnd_service->thd_rnd_ptr(A)
41#define thd_create_random_password(A,B,C) thd_rnd_service->thd_c_r_p_ptr(A,B,C)
42#else
43
44double thd_rnd(MYSQL_THD thd);
45
46/**
47 Generate string of printable random characters of requested length.
48
49 @param to[out] Buffer for generation; must be at least length+1 bytes
50 long; result string is always null-terminated
51 @param length[in] How many random characters to put in buffer
52*/
53void thd_create_random_password(MYSQL_THD thd, char *to, size_t length);
54
55#endif
56
57#ifdef __cplusplus
58}
59#endif
60
61#define MYSQL_SERVICE_THD_RND_INCLUDED
62#endif
63