mirror of https://github.com/sysown/proxysql
parent
5ccf176c5b
commit
59507675e5
@ -1,27 +1,54 @@
|
||||
#ifndef __CLASS_MYSQL_AUTHENTICATION_H
|
||||
#define __CLASS_MYSQL_AUTHENTICATION_H
|
||||
|
||||
#include "btree_map.h"
|
||||
#include "proxysql.h"
|
||||
#include "cpp.h"
|
||||
|
||||
|
||||
typedef struct _account_details_t {
|
||||
char *username;
|
||||
char *password;
|
||||
bool use_ssl;
|
||||
int default_hostgroup;
|
||||
char *default_schema;
|
||||
bool schema_locked;
|
||||
bool transaction_persistent;
|
||||
bool fast_forward;
|
||||
} account_details_t;
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DEB "_DEBUG"
|
||||
#else
|
||||
#define DEB ""
|
||||
#endif /* DEBUG */
|
||||
#define MYSQL_AUTHENTICATION_VERSION "0.1.0706" DEB
|
||||
|
||||
typedef btree::btree_map<uint64_t, account_details_t *> BtMap_auth;
|
||||
|
||||
class PtrArray;
|
||||
|
||||
typedef struct _creds_group_t {
|
||||
rwlock_t lock;
|
||||
BtMap_auth bt_map;
|
||||
PtrArray *cred_array;
|
||||
} creds_group_t;
|
||||
|
||||
enum cred_username_type { USERNAME_BACKEND, USERNAME_FRONTEND };
|
||||
|
||||
class MySQL_Authentication {
|
||||
private:
|
||||
creds_group_t creds_backends;
|
||||
creds_group_t creds_frontends;
|
||||
bool _reset(enum cred_username_type usertype);
|
||||
public:
|
||||
MySQL_Authentication() {};
|
||||
virtual ~MySQL_Authentication() {};
|
||||
//virtual bool add(char *username, char *password, enum cred_username_type usertype, bool use_ssl) { return false; };
|
||||
virtual bool add(char *username, char *password, enum cred_username_type usertype, bool use_ssl, int default_hostgroup, char *default_schema, bool schema_locked, bool transaction_persistent, bool fast_forward) { return false; };
|
||||
virtual bool del(char *username, enum cred_username_type usertype) { return false; };
|
||||
// virtual bool reset(unsigned char *) { return false; };
|
||||
virtual bool reset() { return false; };
|
||||
// virtual bool refresh() { return false; };
|
||||
virtual void print_version() {};
|
||||
// virtual char * lookup(char *username, enum cred_username_type usertype, bool *use_ssl) {return NULL; };
|
||||
virtual char * lookup(char *username, enum cred_username_type usertype, bool *use_ssl, int *default_hostgroup, char **default_schema, bool *schema_locked, bool *transaction_persistent, bool *fast_forward) {return NULL; };
|
||||
MySQL_Authentication();
|
||||
~MySQL_Authentication();
|
||||
bool add(char *username, char *password, enum cred_username_type usertype, bool use_ssl, int default_hostgroup, char *default_schema, bool schema_locked, bool transaction_persistent, bool fast_forward);
|
||||
bool del(char *username, enum cred_username_type usertype);
|
||||
bool reset();
|
||||
void print_version();
|
||||
char * lookup(char *username, enum cred_username_type usertype, bool *use_ssl, int *default_hostgroup, char **default_schema, bool *schema_locked, bool *transaction_persistent, bool *fast_forward);
|
||||
};
|
||||
|
||||
typedef MySQL_Authentication * create_MySQL_Authentication_t();
|
||||
typedef void destroy_MyAuth_t(MySQL_Authentication *);
|
||||
|
||||
#endif /* __CLASS_MYSQL_AUTHENTICATION_H */
|
||||
|
||||
@ -0,0 +1,288 @@
|
||||
#ifndef __CLASS_MYSQL_THREAD_H
|
||||
#define __CLASS_MYSQL_THREAD_H
|
||||
#define ____CLASS_STANDARD_MYSQL_THREAD_H
|
||||
#include "proxysql.h"
|
||||
#include "cpp.h"
|
||||
|
||||
|
||||
#define MIN_POLL_LEN 8
|
||||
#define MIN_POLL_DELETE_RATIO 8
|
||||
|
||||
|
||||
#define ADMIN_HOSTGROUP -2
|
||||
#define STATS_HOSTGROUP -3
|
||||
|
||||
|
||||
static unsigned int near_pow_2 (unsigned int n) {
|
||||
unsigned int i = 1;
|
||||
while (i < n) i <<= 1;
|
||||
return i ? i : n;
|
||||
}
|
||||
|
||||
class ProxySQL_Poll {
|
||||
|
||||
private:
|
||||
void shrink() {
|
||||
unsigned int new_size=near_pow_2(len+1);
|
||||
fds=(struct pollfd *)realloc(fds,new_size*sizeof(struct pollfd));
|
||||
myds=(MySQL_Data_Stream **)realloc(myds,new_size*sizeof(MySQL_Data_Stream *));
|
||||
last_recv=(unsigned long long *)realloc(last_recv,new_size*sizeof(unsigned long long));
|
||||
last_sent=(unsigned long long *)realloc(last_sent,new_size*sizeof(unsigned long long));
|
||||
size=new_size;
|
||||
};
|
||||
void expand(unsigned int more) {
|
||||
if ( (len+more) > size ) {
|
||||
unsigned int new_size=near_pow_2(len+more);
|
||||
fds=(struct pollfd *)realloc(fds,new_size*sizeof(struct pollfd));
|
||||
myds=(MySQL_Data_Stream **)realloc(myds,new_size*sizeof(MySQL_Data_Stream *));
|
||||
last_recv=(unsigned long long *)realloc(last_recv,new_size*sizeof(unsigned long long));
|
||||
last_sent=(unsigned long long *)realloc(last_sent,new_size*sizeof(unsigned long long));
|
||||
size=new_size;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
int poll_timeout;
|
||||
unsigned long loops;
|
||||
StatCounters *loop_counters;
|
||||
unsigned int len;
|
||||
unsigned int size;
|
||||
struct pollfd *fds;
|
||||
MySQL_Data_Stream **myds;
|
||||
unsigned long long *last_recv;
|
||||
unsigned long long *last_sent;
|
||||
volatile int pending_listener_add;
|
||||
volatile int pending_listener_del;
|
||||
|
||||
ProxySQL_Poll() {
|
||||
loop_counters=new StatCounters(15,10,false);
|
||||
poll_timeout=0;
|
||||
loops=0;
|
||||
len=0;
|
||||
pending_listener_add=0;
|
||||
pending_listener_del=0;
|
||||
size=MIN_POLL_LEN;
|
||||
fds=(struct pollfd *)malloc(size*sizeof(struct pollfd));
|
||||
myds=(MySQL_Data_Stream **)malloc(size*sizeof(MySQL_Data_Stream *));
|
||||
last_recv=(unsigned long long *)malloc(size*sizeof(unsigned long long));
|
||||
last_sent=(unsigned long long *)malloc(size*sizeof(unsigned long long));
|
||||
};
|
||||
|
||||
~ProxySQL_Poll() {
|
||||
unsigned int i;
|
||||
for (i=0;i<len;i++) {
|
||||
if (myds[i]->myds_type==MYDS_LISTENER) {
|
||||
delete myds[i];
|
||||
}
|
||||
}
|
||||
free(myds);
|
||||
free(fds);
|
||||
free(last_recv);
|
||||
free(last_sent);
|
||||
delete loop_counters;
|
||||
};
|
||||
|
||||
|
||||
|
||||
void add(uint32_t _events, int _fd, MySQL_Data_Stream *_myds, unsigned long long sent_time) {
|
||||
if (len==size) {
|
||||
expand(1);
|
||||
}
|
||||
myds[len]=_myds;
|
||||
fds[len].fd=_fd;
|
||||
fds[len].events=_events;
|
||||
fds[len].revents=0;
|
||||
if (_myds) {
|
||||
_myds->mypolls=this;
|
||||
_myds->poll_fds_idx=len; // fix a serious bug
|
||||
}
|
||||
last_recv[len]=monotonic_time();
|
||||
last_sent[len]=sent_time;
|
||||
len++;
|
||||
};
|
||||
|
||||
void remove_index_fast(unsigned int i) {
|
||||
if ((int)i==-1) return;
|
||||
myds[i]->poll_fds_idx=-1; // this prevents further delete
|
||||
if (i != (len-1)) {
|
||||
myds[i]=myds[len-1];
|
||||
fds[i].fd=fds[len-1].fd;
|
||||
fds[i].events=fds[len-1].events;
|
||||
fds[i].revents=fds[len-1].revents;
|
||||
myds[i]->poll_fds_idx=i; // fix a serious bug
|
||||
last_recv[i]=last_recv[len-1];
|
||||
last_sent[i]=last_sent[len-1];
|
||||
}
|
||||
len--;
|
||||
if ( ( len>MIN_POLL_LEN ) && ( size > len*MIN_POLL_DELETE_RATIO ) ) {
|
||||
shrink();
|
||||
}
|
||||
};
|
||||
|
||||
int find_index(int fd) {
|
||||
unsigned int i;
|
||||
for (i=0; i<len; i++) {
|
||||
if (fds[i].fd==fd) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class MySQL_Thread
|
||||
{
|
||||
|
||||
private:
|
||||
MySQL_Connection **my_idle_conns;
|
||||
MySQL_Data_Stream **my_idle_myds;
|
||||
bool processing_idles;
|
||||
unsigned long long last_processing_idles;
|
||||
PtrArray *mysql_sessions_connections_handler;
|
||||
|
||||
|
||||
protected:
|
||||
int nfds;
|
||||
|
||||
public:
|
||||
|
||||
int pipefd[2];
|
||||
unsigned long long curtime;
|
||||
|
||||
ProxySQL_Poll mypolls;
|
||||
pthread_t thread_id;
|
||||
int shutdown;
|
||||
PtrArray *mysql_sessions;
|
||||
|
||||
|
||||
|
||||
rwlock_t thread_mutex;
|
||||
MySQL_Thread();
|
||||
~MySQL_Thread();
|
||||
MySQL_Session * create_new_session_and_client_data_stream(int _fd);
|
||||
bool init();
|
||||
void run();
|
||||
void poll_listener_add(int sock);
|
||||
void poll_listener_del(int sock);
|
||||
void register_session(MySQL_Session*);
|
||||
void unregister_session(int);
|
||||
struct pollfd * get_pollfd(unsigned int i);
|
||||
void process_data_on_data_stream(MySQL_Data_Stream *myds, unsigned int n);
|
||||
void process_all_sessions();
|
||||
void refresh_variables();
|
||||
void process_all_sessions_connections_handler();
|
||||
void register_session_connection_handler(MySQL_Session *_sess);
|
||||
void unregister_session_connection_handler(int idx);
|
||||
void myds_backend_set_failed_connect(MySQL_Data_Stream *myds, unsigned int n);
|
||||
void myds_backend_pause_connect(MySQL_Data_Stream *myds);
|
||||
void myds_backend_first_packet_after_connect(MySQL_Data_Stream *myds, unsigned int n);
|
||||
void listener_handle_new_connection(MySQL_Data_Stream *myds, unsigned int n);
|
||||
SQLite3_result * SQL3_Thread_status(MySQL_Session *sess);
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef MySQL_Thread * create_MySQL_Thread_t();
|
||||
typedef void destroy_MySQL_Thread_t(MySQL_Thread *);
|
||||
|
||||
|
||||
|
||||
class iface_info {
|
||||
public:
|
||||
char *iface;
|
||||
char *address;
|
||||
int port;
|
||||
int fd;
|
||||
iface_info(char *_i, char *_a, int p, int f) {
|
||||
iface=strdup(_i);
|
||||
address=strdup(_a);
|
||||
port=p;
|
||||
fd=f;
|
||||
}
|
||||
~iface_info() {
|
||||
free(iface);
|
||||
free(address);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class MySQL_Listeners_Manager {
|
||||
private:
|
||||
PtrArray *ifaces;
|
||||
public:
|
||||
MySQL_Listeners_Manager();
|
||||
~MySQL_Listeners_Manager();
|
||||
int add(const char *iface);
|
||||
int add(const char *address, int port);
|
||||
int find_idx(const char *iface);
|
||||
int find_idx(const char *address, int port);
|
||||
int get_fd(unsigned int idx);
|
||||
void del(unsigned int idx);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class MySQL_Threads_Handler
|
||||
{
|
||||
private:
|
||||
int shutdown_;
|
||||
size_t stacksize;
|
||||
pthread_attr_t attr;
|
||||
rwlock_t rwlock;
|
||||
struct {
|
||||
int ping_interval_server;
|
||||
int ping_timeout_server;
|
||||
int connect_timeout_server;
|
||||
char *connect_timeout_server_error;
|
||||
char *default_schema;
|
||||
char *interfaces;
|
||||
char *server_version;
|
||||
uint8_t default_charset;
|
||||
bool servers_stats;
|
||||
bool commands_stats;
|
||||
bool have_compress;
|
||||
#ifdef DEBUG
|
||||
bool session_debug;
|
||||
#endif /* DEBUG */
|
||||
uint16_t server_capabilities;
|
||||
int poll_timeout;
|
||||
int poll_timeout_on_failure;
|
||||
} variables;
|
||||
PtrArray *bind_fds;
|
||||
MySQL_Listeners_Manager *MLM;
|
||||
public:
|
||||
unsigned int num_threads;
|
||||
proxysql_mysql_thread_t *mysql_threads;
|
||||
//virtual const char *version() {return NULL;};
|
||||
void wrlock();
|
||||
void wrunlock();
|
||||
void commit();
|
||||
char *get_variable(char *name);
|
||||
bool set_variable(char *name, char *value);
|
||||
char **get_variables_list();
|
||||
|
||||
MySQL_Threads_Handler();
|
||||
~MySQL_Threads_Handler();
|
||||
SQLite3_result * SQL3_Threads_status(MySQL_Session *);
|
||||
|
||||
char *get_variable_string(char *name);
|
||||
uint8_t get_variable_uint8(char *name);
|
||||
uint16_t get_variable_uint16(char *name);
|
||||
int get_variable_int(char *name);
|
||||
void print_version();
|
||||
void init(unsigned int num=0, size_t stack=0);
|
||||
proxysql_mysql_thread_t *create_thread(unsigned int tn, void *(*start_routine) (void *));
|
||||
void shutdown_threads();
|
||||
int listener_add(const char *iface);
|
||||
int listener_add(const char *address, int port);
|
||||
int listener_del(const char *iface);
|
||||
int listener_del(const char *address, int port);
|
||||
void start_listeners();
|
||||
void signal_all_threads();
|
||||
};
|
||||
|
||||
|
||||
#endif /* __CLASS_MYSQL_THREAD_H */
|
||||
@ -1,38 +0,0 @@
|
||||
#ifndef __CLASS_STANDARD_MYSQL_THREAD_H
|
||||
#define __CLASS_STANDARD_MYSQL_THREAD_H
|
||||
|
||||
|
||||
class Standard_MySQL_Thread: public MySQL_Thread
|
||||
{
|
||||
private:
|
||||
MySQL_Connection **my_idle_conns;
|
||||
MySQL_Data_Stream **my_idle_myds;
|
||||
bool processing_idles;
|
||||
unsigned long long last_processing_idles;
|
||||
PtrArray *mysql_sessions_connections_handler;
|
||||
|
||||
public:
|
||||
rwlock_t thread_mutex;
|
||||
Standard_MySQL_Thread();
|
||||
virtual ~Standard_MySQL_Thread();
|
||||
MySQL_Session * create_new_session_and_client_data_stream(int _fd);
|
||||
bool init();
|
||||
void run();
|
||||
void poll_listener_add(int sock);
|
||||
void poll_listener_del(int sock);
|
||||
void register_session(MySQL_Session*);
|
||||
void unregister_session(int);
|
||||
struct pollfd * get_pollfd(unsigned int i);
|
||||
void process_data_on_data_stream(MySQL_Data_Stream *myds, unsigned int n);
|
||||
void process_all_sessions();
|
||||
void refresh_variables();
|
||||
void process_all_sessions_connections_handler();
|
||||
void register_session_connection_handler(MySQL_Session *_sess);
|
||||
void unregister_session_connection_handler(int idx);
|
||||
void myds_backend_set_failed_connect(MySQL_Data_Stream *myds, unsigned int n);
|
||||
void myds_backend_pause_connect(MySQL_Data_Stream *myds);
|
||||
void myds_backend_first_packet_after_connect(MySQL_Data_Stream *myds, unsigned int n);
|
||||
void listener_handle_new_connection(MySQL_Data_Stream *myds, unsigned int n);
|
||||
SQLite3_result * SQL3_Thread_status(MySQL_Session *sess);
|
||||
};
|
||||
#endif /* __CLASS_STANDARD_MYSQL_THREAD_H */
|
||||
@ -1,410 +0,0 @@
|
||||
#ifndef __CLASS_MYSQL_THREAD_H
|
||||
#define __CLASS_MYSQL_THREAD_H
|
||||
#include "proxysql.h"
|
||||
#include "cpp.h"
|
||||
|
||||
/*
|
||||
#define MYSQL_THREAD_EPOLL_MAXEVENTS 1000
|
||||
#define MIN_POLL_FDS_PER_THREAD 1024
|
||||
*/
|
||||
|
||||
|
||||
#define MIN_POLL_LEN 8
|
||||
#define MIN_POLL_DELETE_RATIO 8
|
||||
|
||||
|
||||
#define ADMIN_HOSTGROUP -2
|
||||
#define STATS_HOSTGROUP -3
|
||||
|
||||
|
||||
static unsigned int near_pow_2 (unsigned int n) {
|
||||
unsigned int i = 1;
|
||||
while (i < n) i <<= 1;
|
||||
return i ? i : n;
|
||||
}
|
||||
|
||||
/*
|
||||
// this structure tries to emulate epoll()
|
||||
|
||||
class ProxySQL_Poll {
|
||||
|
||||
private:
|
||||
void shrink() {
|
||||
unsigned int new_size=near_pow_2(len+1);
|
||||
fds=(struct pollfd *)realloc(fds,new_size*sizeof(struct pollfd));
|
||||
myds=(MySQL_Data_Stream **)realloc(myds,new_size*sizeof(MySQL_Data_Stream *));
|
||||
// status=(unsigned char *)realloc(status,new_size*sizeof(unsigned char));
|
||||
size=new_size;
|
||||
};
|
||||
void expand(unsigned int more) {
|
||||
if ( (len+more) > size ) {
|
||||
unsigned int new_size=near_pow_2(len+more);
|
||||
fds=(struct pollfd *)realloc(fds,new_size*sizeof(struct pollfd));
|
||||
myds=(MySQL_Data_Stream **)realloc(myds,new_size*sizeof(MySQL_Data_Stream *));
|
||||
// status=(unsigned char *)realloc(status,new_size*sizeof(unsigned char));
|
||||
size=new_size;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
unsigned int len=0;
|
||||
unsigned int size=0;
|
||||
struct pollfd *fds=NULL;
|
||||
MySQL_Data_Stream **myds=NULL;
|
||||
// unsigned char *status=NULL; // this should be moved within the Data Stream
|
||||
ProxySQL_Poll() {
|
||||
size=MIN_POLL_LEN;
|
||||
// preallocate MIN_POLL_LEN slots
|
||||
fds=(struct pollfd *)malloc(size*sizeof(struct pollfd));
|
||||
myds=(MySQL_Data_Stream **)malloc(size*sizeof(MySQL_Data_Stream *));
|
||||
//status=(unsigned char *)malloc(size*sizeof(unsigned char));
|
||||
};
|
||||
|
||||
~ProxySQL_Poll() {
|
||||
unsigned int i;
|
||||
for (i=0;i<len;i++) {
|
||||
if (myds[i]->myds_type==MYDS_LISTENER) {
|
||||
delete myds[i];
|
||||
}
|
||||
}
|
||||
free(myds);
|
||||
free(fds);
|
||||
}
|
||||
|
||||
void add(uint32_t _events, int _fd, MySQL_Data_Stream *_myds) {
|
||||
if (len==size) {
|
||||
expand(1);
|
||||
}
|
||||
myds[len]=_myds;
|
||||
fds[len].fd=_fd;
|
||||
fds[len].events=_events;
|
||||
fds[len].revents=0;
|
||||
len++;
|
||||
};
|
||||
|
||||
void remove_index_fast(unsigned int i) {
|
||||
if (i != (len-1)) {
|
||||
myds[i]=myds[len-1];
|
||||
fds[i].fd=fds[len-1].fd;
|
||||
fds[i].events=fds[len-1].events;
|
||||
fds[i].revents=fds[len-1].revents;
|
||||
//status[i]=status[len-1];
|
||||
}
|
||||
len--;
|
||||
if ( ( len>MIN_POLL_LEN ) && ( size > len*MIN_POLL_DELETE_RATIO ) ) {
|
||||
shrink();
|
||||
}
|
||||
};
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
class ProxySQL_Poll;
|
||||
*/
|
||||
|
||||
class ProxySQL_Poll {
|
||||
|
||||
private:
|
||||
void shrink() {
|
||||
unsigned int new_size=near_pow_2(len+1);
|
||||
fds=(struct pollfd *)realloc(fds,new_size*sizeof(struct pollfd));
|
||||
myds=(MySQL_Data_Stream **)realloc(myds,new_size*sizeof(MySQL_Data_Stream *));
|
||||
// status=(unsigned char *)realloc(status,new_size*sizeof(unsigned char));
|
||||
last_recv=(unsigned long long *)realloc(last_recv,new_size*sizeof(unsigned long long));
|
||||
last_sent=(unsigned long long *)realloc(last_sent,new_size*sizeof(unsigned long long));
|
||||
size=new_size;
|
||||
};
|
||||
void expand(unsigned int more) {
|
||||
if ( (len+more) > size ) {
|
||||
unsigned int new_size=near_pow_2(len+more);
|
||||
fds=(struct pollfd *)realloc(fds,new_size*sizeof(struct pollfd));
|
||||
myds=(MySQL_Data_Stream **)realloc(myds,new_size*sizeof(MySQL_Data_Stream *));
|
||||
// status=(unsigned char *)realloc(status,new_size*sizeof(unsigned char));
|
||||
last_recv=(unsigned long long *)realloc(last_recv,new_size*sizeof(unsigned long long));
|
||||
last_sent=(unsigned long long *)realloc(last_sent,new_size*sizeof(unsigned long long));
|
||||
size=new_size;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
int poll_timeout;
|
||||
unsigned long loops;
|
||||
StatCounters *loop_counters;
|
||||
unsigned int len;
|
||||
unsigned int size;
|
||||
struct pollfd *fds;
|
||||
MySQL_Data_Stream **myds;
|
||||
unsigned long long *last_recv;
|
||||
unsigned long long *last_sent;
|
||||
volatile int pending_listener_add;
|
||||
volatile int pending_listener_del;
|
||||
// unsigned char *status=NULL; // this should be moved within the Data Stream
|
||||
ProxySQL_Poll() {
|
||||
loop_counters=new StatCounters(15,10,false);
|
||||
poll_timeout=0;
|
||||
loops=0;
|
||||
len=0;
|
||||
pending_listener_add=0;
|
||||
pending_listener_del=0;
|
||||
size=MIN_POLL_LEN;
|
||||
// preallocate MIN_POLL_LEN slots
|
||||
fds=(struct pollfd *)malloc(size*sizeof(struct pollfd));
|
||||
myds=(MySQL_Data_Stream **)malloc(size*sizeof(MySQL_Data_Stream *));
|
||||
//status=(unsigned char *)malloc(size*sizeof(unsigned char));
|
||||
last_recv=(unsigned long long *)malloc(size*sizeof(unsigned long long));
|
||||
last_sent=(unsigned long long *)malloc(size*sizeof(unsigned long long));
|
||||
};
|
||||
|
||||
~ProxySQL_Poll() {
|
||||
unsigned int i;
|
||||
for (i=0;i<len;i++) {
|
||||
if (myds[i]->myds_type==MYDS_LISTENER) {
|
||||
delete myds[i];
|
||||
}
|
||||
}
|
||||
free(myds);
|
||||
free(fds);
|
||||
free(last_recv);
|
||||
free(last_sent);
|
||||
delete loop_counters;
|
||||
};
|
||||
|
||||
|
||||
|
||||
void add(uint32_t _events, int _fd, MySQL_Data_Stream *_myds, unsigned long long sent_time) {
|
||||
//fprintf(stderr,"ProxySQL_Poll: Adding fd %d\n",_fd);
|
||||
if (len==size) {
|
||||
expand(1);
|
||||
}
|
||||
myds[len]=_myds;
|
||||
fds[len].fd=_fd;
|
||||
fds[len].events=_events;
|
||||
fds[len].revents=0;
|
||||
if (_myds) {
|
||||
_myds->mypolls=this;
|
||||
_myds->poll_fds_idx=len; // fix a serious bug
|
||||
}
|
||||
last_recv[len]=monotonic_time();
|
||||
last_sent[len]=sent_time;
|
||||
len++;
|
||||
};
|
||||
|
||||
void remove_index_fast(unsigned int i) {
|
||||
//fprintf(stderr,"ProxySQL_Poll: Removing fd %d\n",fds[i].fd);
|
||||
if ((int)i==-1) return;
|
||||
myds[i]->poll_fds_idx=-1; // this prevents further delete
|
||||
if (i != (len-1)) {
|
||||
myds[i]=myds[len-1];
|
||||
fds[i].fd=fds[len-1].fd;
|
||||
fds[i].events=fds[len-1].events;
|
||||
fds[i].revents=fds[len-1].revents;
|
||||
myds[i]->poll_fds_idx=i; // fix a serious bug
|
||||
//status[i]=status[len-1];
|
||||
last_recv[i]=last_recv[len-1];
|
||||
last_sent[i]=last_sent[len-1];
|
||||
}
|
||||
len--;
|
||||
if ( ( len>MIN_POLL_LEN ) && ( size > len*MIN_POLL_DELETE_RATIO ) ) {
|
||||
shrink();
|
||||
}
|
||||
};
|
||||
|
||||
int find_index(int fd) {
|
||||
unsigned int i;
|
||||
for (i=0; i<len; i++) {
|
||||
if (fds[i].fd==fd) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class MySQL_Thread
|
||||
{
|
||||
protected:
|
||||
int nfds;
|
||||
|
||||
// ProxySQL_Poll mypolls;
|
||||
|
||||
public:
|
||||
|
||||
int pipefd[2];
|
||||
unsigned long long curtime;
|
||||
|
||||
ProxySQL_Poll mypolls;
|
||||
pthread_t thread_id;
|
||||
int shutdown;
|
||||
PtrArray *mysql_sessions;
|
||||
|
||||
MySQL_Thread() {};
|
||||
virtual ~MySQL_Thread() {};
|
||||
virtual bool init() {return false;};
|
||||
virtual void poll_listener_add(int fd) {};
|
||||
virtual void poll_listener_del(int fd) {};
|
||||
virtual void run() {};
|
||||
|
||||
virtual SQLite3_result * SQL3_Thread_status(MySQL_Session *) {return NULL;};
|
||||
|
||||
virtual void register_session(MySQL_Session *) {};
|
||||
virtual void unregister_session(int) {};
|
||||
virtual MySQL_Session * create_new_session_and_client_data_stream(int) {return NULL;};
|
||||
|
||||
virtual struct pollfd * get_pollfd(unsigned int) {return NULL;};
|
||||
};
|
||||
|
||||
typedef MySQL_Thread * create_MySQL_Thread_t();
|
||||
typedef void destroy_MySQL_Thread_t(MySQL_Thread *);
|
||||
|
||||
|
||||
|
||||
class iface_info {
|
||||
public:
|
||||
char *iface;
|
||||
char *address;
|
||||
int port;
|
||||
int fd;
|
||||
iface_info(char *_i, char *_a, int p, int f) {
|
||||
iface=strdup(_i);
|
||||
address=strdup(_a);
|
||||
port=p;
|
||||
fd=f;
|
||||
}
|
||||
~iface_info() {
|
||||
free(iface);
|
||||
free(address);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class MySQL_Listeners_Manager {
|
||||
private:
|
||||
PtrArray *ifaces;
|
||||
public:
|
||||
MySQL_Listeners_Manager();
|
||||
~MySQL_Listeners_Manager();
|
||||
int add(const char *iface);
|
||||
int add(const char *address, int port);
|
||||
int find_idx(const char *iface);
|
||||
int find_idx(const char *address, int port);
|
||||
int get_fd(unsigned int idx);
|
||||
void del(unsigned int idx);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class MySQL_Threads_Handler
|
||||
{
|
||||
public:
|
||||
unsigned int num_threads;
|
||||
proxysql_mysql_thread_t *mysql_threads;
|
||||
MySQL_Threads_Handler() {};
|
||||
virtual ~MySQL_Threads_Handler() {};
|
||||
virtual const char *version() {return NULL;};
|
||||
virtual void print_version() {};
|
||||
virtual void init(unsigned int num=0, size_t stack=0) {};
|
||||
virtual proxysql_mysql_thread_t *create_thread(unsigned int tn, void *(*start_routine) (void *)) {return NULL;};
|
||||
virtual void shutdown_threads() {};
|
||||
virtual void wrlock() {};
|
||||
virtual void wrunlock() {};
|
||||
virtual void commit() {};
|
||||
virtual char *get_variable(char *name) {return NULL;};
|
||||
virtual bool set_variable(char *name, char *value) {return false;};
|
||||
virtual char **get_variables_list() {return NULL;}
|
||||
virtual SQLite3_result * SQL3_Threads_status(MySQL_Session *) {return NULL;}
|
||||
virtual int listener_add(const char *iface) {return -1;}
|
||||
virtual int listener_add(const char *address, int port) {return -1;}
|
||||
virtual int listener_del(const char *iface) {return -1;}
|
||||
virtual int listener_del(const char *address, int port) {return -1;}
|
||||
virtual void start_listeners() {};
|
||||
virtual void signal_all_threads() {};
|
||||
};
|
||||
|
||||
class Standard_MySQL_Threads_Handler: public MySQL_Threads_Handler
|
||||
{
|
||||
private:
|
||||
int shutdown_;
|
||||
size_t stacksize;
|
||||
pthread_attr_t attr;
|
||||
rwlock_t rwlock;
|
||||
struct {
|
||||
int ping_interval_server;
|
||||
int ping_timeout_server;
|
||||
int connect_timeout_server;
|
||||
char *connect_timeout_server_error;
|
||||
char *default_schema;
|
||||
char *interfaces;
|
||||
char *server_version;
|
||||
uint8_t default_charset;
|
||||
bool servers_stats;
|
||||
bool commands_stats;
|
||||
bool have_compress;
|
||||
#ifdef DEBUG
|
||||
bool session_debug;
|
||||
#endif /* DEBUG */
|
||||
uint16_t server_capabilities;
|
||||
int poll_timeout;
|
||||
int poll_timeout_on_failure;
|
||||
} variables;
|
||||
PtrArray *bind_fds;
|
||||
MySQL_Listeners_Manager *MLM;
|
||||
public:
|
||||
Standard_MySQL_Threads_Handler();
|
||||
virtual ~Standard_MySQL_Threads_Handler();
|
||||
virtual SQLite3_result * SQL3_Threads_status(MySQL_Session *);
|
||||
|
||||
virtual void wrlock();
|
||||
virtual void wrunlock();
|
||||
virtual void commit();
|
||||
|
||||
char *get_variable_string(char *name);
|
||||
uint8_t get_variable_uint8(char *name);
|
||||
uint16_t get_variable_uint16(char *name);
|
||||
int get_variable_int(char *name);
|
||||
virtual char * get_variable(char *name); // this is the public function, accessible from admin
|
||||
virtual bool set_variable(char *name, char *value);// this is the public function, accessible from admin
|
||||
virtual char **get_variables_list();
|
||||
virtual void print_version();
|
||||
virtual void init(unsigned int num, size_t stack);
|
||||
virtual proxysql_mysql_thread_t *create_thread(unsigned int tn, void *(*start_routine) (void *));
|
||||
virtual void shutdown_threads();
|
||||
virtual int listener_add(const char *iface);
|
||||
virtual int listener_add(const char *address, int port);
|
||||
virtual int listener_del(const char *iface);
|
||||
virtual void start_listeners();
|
||||
virtual void signal_all_threads();
|
||||
// virtual int listener_del(const char *address, int port);
|
||||
// pthread_t connection_manager_thread_id;
|
||||
// void connection_manager_thread();
|
||||
};
|
||||
|
||||
|
||||
typedef MySQL_Threads_Handler * create_MySQL_Threads_Handler_t();
|
||||
typedef void destroy_MySQL_Threads_Handler_t(MySQL_Threads_Handler *);
|
||||
|
||||
|
||||
/*
|
||||
#ifndef MYSQL_THREAD_IMPLEMENTATION
|
||||
#define __EXTERN extern
|
||||
#else
|
||||
#define __EXTERN
|
||||
#endif */ /* MYSQL_THREAD_IMPLEMENTATION */
|
||||
/*
|
||||
__EXTERN __thread char *mysql_thread___default_schema;
|
||||
__EXTERN __thread char *mysql_thread___server_version;
|
||||
__EXTERN __thread int mysql_thread___ping_interval_server;
|
||||
__EXTERN __thread int mysql_thread___ping_timeout_server;
|
||||
__EXTERN __thread int mysql_thread___connect_timeout_server;
|
||||
__EXTERN __thread char *mysql_thread___connect_timeout_server_error;
|
||||
__EXTERN __thread uint16_t mysql_thread___server_capabilities;
|
||||
__EXTERN __thread int mysql_thread___poll_timeout;
|
||||
__EXTERN __thread bool mysql_thread___servers_stats;
|
||||
#ifdef DEBUG
|
||||
__EXTERN __thread bool mysql_thread___session_debug;
|
||||
#endif */ /* DEBUG */
|
||||
|
||||
#endif /* __CLASS_MYSQL_THREAD_H */
|
||||
@ -0,0 +1,184 @@
|
||||
#include "btree_map.h"
|
||||
#include "proxysql.h"
|
||||
#include "cpp.h"
|
||||
#include "proxysql_atomic.h"
|
||||
#include "SpookyV2.h"
|
||||
|
||||
/*
|
||||
typedef struct _account_details_t {
|
||||
char *username;
|
||||
char *password;
|
||||
bool use_ssl;
|
||||
int default_hostgroup;
|
||||
char *default_schema;
|
||||
bool schema_locked;
|
||||
bool transaction_persistent;
|
||||
bool fast_forward;
|
||||
} account_details_t;
|
||||
*/
|
||||
|
||||
//#ifdef DEBUG
|
||||
//#define DEB "_DEBUG"
|
||||
//#else
|
||||
//#define DEB ""
|
||||
//#endif /* DEBUG */
|
||||
//#define MYSQL_AUTHENTICATION_VERSION "0.1.0706" DEB
|
||||
|
||||
/*
|
||||
typedef btree::btree_map<uint64_t, account_details_t *> BtMap;
|
||||
|
||||
typedef struct _creds_group_t {
|
||||
rwlock_t lock;
|
||||
BtMap bt_map;
|
||||
PtrArray cred_array;
|
||||
} creds_group_t;
|
||||
*/
|
||||
|
||||
|
||||
MySQL_Authentication::MySQL_Authentication() {
|
||||
#ifdef DEBUG
|
||||
if (glovars.has_debug==false) {
|
||||
#else
|
||||
if (glovars.has_debug==true) {
|
||||
#endif /* DEBUG */
|
||||
perror("Incompatible debagging version");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
spinlock_rwlock_init(&creds_backends.lock);
|
||||
spinlock_rwlock_init(&creds_frontends.lock);
|
||||
creds_backends.cred_array = new PtrArray();
|
||||
creds_frontends.cred_array = new PtrArray();
|
||||
};
|
||||
|
||||
MySQL_Authentication::~MySQL_Authentication() {
|
||||
reset();
|
||||
};
|
||||
|
||||
void MySQL_Authentication::print_version() {
|
||||
fprintf(stderr,"Standard MySQL Authentication rev. %s -- %s -- %s\n", MYSQL_AUTHENTICATION_VERSION, __FILE__, __TIMESTAMP__);
|
||||
};
|
||||
|
||||
bool MySQL_Authentication::add(char * username, char * password, enum cred_username_type usertype, bool use_ssl, int default_hostgroup, char *default_schema, bool schema_locked, bool transaction_persistent, bool fast_forward) {
|
||||
uint64_t hash1, hash2;
|
||||
SpookyHash *myhash=new SpookyHash();
|
||||
myhash->Init(1,2);
|
||||
myhash->Update(username,strlen(username));
|
||||
myhash->Final(&hash1,&hash2);
|
||||
delete myhash;
|
||||
|
||||
creds_group_t &cg=(usertype==USERNAME_BACKEND ? creds_backends : creds_frontends);
|
||||
|
||||
spin_wrlock(&cg.lock);
|
||||
btree::btree_map<uint64_t, account_details_t *>::iterator lookup;
|
||||
lookup = cg.bt_map.find(hash1);
|
||||
if (lookup != cg.bt_map.end()) {
|
||||
account_details_t *ad=lookup->second;
|
||||
cg.cred_array->remove_fast(ad);
|
||||
cg.bt_map.erase(lookup);
|
||||
free(ad->username);
|
||||
free(ad->password);
|
||||
free(ad->default_schema);
|
||||
free(ad);
|
||||
}
|
||||
account_details_t *ad=(account_details_t *)malloc(sizeof(account_details_t));
|
||||
ad->username=strdup(username);
|
||||
ad->password=strdup(password);
|
||||
ad->use_ssl=use_ssl;
|
||||
ad->default_hostgroup=default_hostgroup;
|
||||
ad->default_schema=strdup(default_schema);
|
||||
ad->schema_locked=schema_locked;
|
||||
ad->transaction_persistent=transaction_persistent;
|
||||
ad->fast_forward=fast_forward;
|
||||
cg.bt_map.insert(std::make_pair(hash1,ad));
|
||||
cg.cred_array->add(ad);
|
||||
spin_wrunlock(&cg.lock);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
bool MySQL_Authentication::del(char * username, enum cred_username_type usertype) {
|
||||
bool ret=false;
|
||||
uint64_t hash1, hash2;
|
||||
SpookyHash *myhash=new SpookyHash();
|
||||
myhash->Init(1,2);
|
||||
myhash->Update(username,strlen(username));
|
||||
myhash->Final(&hash1,&hash2);
|
||||
delete myhash;
|
||||
|
||||
creds_group_t &cg=(usertype==USERNAME_BACKEND ? creds_backends : creds_frontends);
|
||||
|
||||
spin_wrlock(&cg.lock);
|
||||
btree::btree_map<uint64_t, account_details_t *>::iterator lookup;
|
||||
lookup = cg.bt_map.find(hash1);
|
||||
if (lookup != cg.bt_map.end()) {
|
||||
account_details_t *ad=lookup->second;
|
||||
cg.cred_array->remove_fast(ad);
|
||||
cg.bt_map.erase(lookup);
|
||||
free(ad->username);
|
||||
free(ad->password);
|
||||
free(ad->default_schema);
|
||||
free(ad);
|
||||
ret=true;
|
||||
}
|
||||
spin_wrunlock(&cg.lock);
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
|
||||
char * MySQL_Authentication::lookup(char * username, enum cred_username_type usertype, bool *use_ssl, int *default_hostgroup, char **default_schema, bool *schema_locked, bool *transaction_persistent, bool *fast_forward) {
|
||||
char *ret=NULL;
|
||||
uint64_t hash1, hash2;
|
||||
SpookyHash myhash;
|
||||
myhash.Init(1,2);
|
||||
myhash.Update(username,strlen(username));
|
||||
myhash.Final(&hash1,&hash2);
|
||||
|
||||
creds_group_t &cg=(usertype==USERNAME_BACKEND ? creds_backends : creds_frontends);
|
||||
|
||||
spin_rdlock(&cg.lock);
|
||||
btree::btree_map<uint64_t, account_details_t *>::iterator lookup;
|
||||
lookup = cg.bt_map.find(hash1);
|
||||
if (lookup != cg.bt_map.end()) {
|
||||
account_details_t *ad=lookup->second;
|
||||
ret=l_strdup(ad->password);
|
||||
if (use_ssl) *use_ssl=ad->use_ssl;
|
||||
if (default_hostgroup) *default_hostgroup=ad->default_hostgroup;
|
||||
if (default_schema) *default_schema=l_strdup(ad->default_schema);
|
||||
if (schema_locked) *schema_locked=ad->schema_locked;
|
||||
if (transaction_persistent) *transaction_persistent=ad->transaction_persistent;
|
||||
if (fast_forward) *fast_forward=ad->fast_forward;
|
||||
}
|
||||
spin_rdunlock(&cg.lock);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
bool MySQL_Authentication::_reset(enum cred_username_type usertype) {
|
||||
creds_group_t &cg=(usertype==USERNAME_BACKEND ? creds_backends : creds_frontends);
|
||||
|
||||
spin_wrlock(&cg.lock);
|
||||
btree::btree_map<uint64_t, account_details_t *>::iterator lookup;
|
||||
|
||||
while (cg.bt_map.size()) {
|
||||
lookup = cg.bt_map.begin();
|
||||
if ( lookup != cg.bt_map.end() ) {
|
||||
account_details_t *ad=lookup->second;
|
||||
cg.cred_array->remove_fast(ad);
|
||||
cg.bt_map.erase(lookup);
|
||||
free(ad->username);
|
||||
free(ad->password);
|
||||
free(ad);
|
||||
}
|
||||
}
|
||||
spin_wrunlock(&cg.lock);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
bool MySQL_Authentication::reset() {
|
||||
_reset(USERNAME_BACKEND);
|
||||
_reset(USERNAME_FRONTEND);
|
||||
return true;
|
||||
}
|
||||
@ -1,195 +0,0 @@
|
||||
#include "btree_map.h"
|
||||
#include "proxysql.h"
|
||||
#include "cpp.h"
|
||||
#include "proxysql_atomic.h"
|
||||
#include "SpookyV2.h"
|
||||
|
||||
|
||||
typedef struct _account_details_t {
|
||||
char *username;
|
||||
char *password;
|
||||
bool use_ssl;
|
||||
int default_hostgroup;
|
||||
char *default_schema;
|
||||
bool schema_locked;
|
||||
bool transaction_persistent;
|
||||
bool fast_forward;
|
||||
} account_details_t;
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DEB "_DEBUG"
|
||||
#else
|
||||
#define DEB ""
|
||||
#endif /* DEBUG */
|
||||
#define MYSQL_AUTHENTICATION_VERSION "0.1.0706" DEB
|
||||
|
||||
typedef btree::btree_map<uint64_t, account_details_t *> BtMap;
|
||||
|
||||
typedef struct _creds_group_t {
|
||||
rwlock_t lock;
|
||||
BtMap bt_map;
|
||||
PtrArray cred_array;
|
||||
} creds_group_t;
|
||||
|
||||
class Standard_MySQL_Authentication: public MySQL_Authentication {
|
||||
private:
|
||||
creds_group_t creds_backends;
|
||||
creds_group_t creds_frontends;
|
||||
public:
|
||||
Standard_MySQL_Authentication() {
|
||||
#ifdef DEBUG
|
||||
if (glovars.has_debug==false) {
|
||||
#else
|
||||
if (glovars.has_debug==true) {
|
||||
#endif /* DEBUG */
|
||||
perror("Incompatible debagging version");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
spinlock_rwlock_init(&creds_backends.lock);
|
||||
spinlock_rwlock_init(&creds_frontends.lock);
|
||||
};
|
||||
|
||||
~Standard_MySQL_Authentication() {
|
||||
reset();
|
||||
};
|
||||
|
||||
virtual void print_version() {
|
||||
fprintf(stderr,"Standard MySQL Authentication rev. %s -- %s -- %s\n", MYSQL_AUTHENTICATION_VERSION, __FILE__, __TIMESTAMP__);
|
||||
};
|
||||
|
||||
virtual bool add(char * username, char * password, enum cred_username_type usertype, bool use_ssl, int default_hostgroup, char *default_schema, bool schema_locked, bool transaction_persistent, bool fast_forward) {
|
||||
uint64_t hash1, hash2;
|
||||
SpookyHash *myhash=new SpookyHash();
|
||||
myhash->Init(1,2);
|
||||
myhash->Update(username,strlen(username));
|
||||
myhash->Final(&hash1,&hash2);
|
||||
delete myhash;
|
||||
|
||||
creds_group_t &cg=(usertype==USERNAME_BACKEND ? creds_backends : creds_frontends);
|
||||
|
||||
spin_wrlock(&cg.lock);
|
||||
btree::btree_map<uint64_t, account_details_t *>::iterator lookup;
|
||||
lookup = cg.bt_map.find(hash1);
|
||||
if (lookup != cg.bt_map.end()) {
|
||||
account_details_t *ad=lookup->second;
|
||||
cg.cred_array.remove_fast(ad);
|
||||
cg.bt_map.erase(lookup);
|
||||
free(ad->username);
|
||||
free(ad->password);
|
||||
free(ad->default_schema);
|
||||
free(ad);
|
||||
}
|
||||
account_details_t *ad=(account_details_t *)malloc(sizeof(account_details_t));
|
||||
ad->username=strdup(username);
|
||||
ad->password=strdup(password);
|
||||
ad->use_ssl=use_ssl;
|
||||
ad->default_hostgroup=default_hostgroup;
|
||||
ad->default_schema=strdup(default_schema);
|
||||
ad->schema_locked=schema_locked;
|
||||
ad->transaction_persistent=transaction_persistent;
|
||||
ad->fast_forward=fast_forward;
|
||||
cg.bt_map.insert(std::make_pair(hash1,ad));
|
||||
cg.cred_array.add(ad);
|
||||
spin_wrunlock(&cg.lock);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
virtual bool del(char * username, enum cred_username_type usertype) {
|
||||
bool ret=false;
|
||||
uint64_t hash1, hash2;
|
||||
SpookyHash *myhash=new SpookyHash();
|
||||
myhash->Init(1,2);
|
||||
myhash->Update(username,strlen(username));
|
||||
myhash->Final(&hash1,&hash2);
|
||||
delete myhash;
|
||||
|
||||
creds_group_t &cg=(usertype==USERNAME_BACKEND ? creds_backends : creds_frontends);
|
||||
|
||||
spin_wrlock(&cg.lock);
|
||||
btree::btree_map<uint64_t, account_details_t *>::iterator lookup;
|
||||
lookup = cg.bt_map.find(hash1);
|
||||
if (lookup != cg.bt_map.end()) {
|
||||
account_details_t *ad=lookup->second;
|
||||
cg.cred_array.remove_fast(ad);
|
||||
cg.bt_map.erase(lookup);
|
||||
free(ad->username);
|
||||
free(ad->password);
|
||||
free(ad->default_schema);
|
||||
free(ad);
|
||||
ret=true;
|
||||
}
|
||||
spin_wrunlock(&cg.lock);
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
|
||||
virtual char * lookup(char * username, enum cred_username_type usertype, bool *use_ssl, int *default_hostgroup, char **default_schema, bool *schema_locked, bool *transaction_persistent, bool *fast_forward) {
|
||||
char *ret=NULL;
|
||||
uint64_t hash1, hash2;
|
||||
SpookyHash myhash;
|
||||
myhash.Init(1,2);
|
||||
myhash.Update(username,strlen(username));
|
||||
myhash.Final(&hash1,&hash2);
|
||||
|
||||
creds_group_t &cg=(usertype==USERNAME_BACKEND ? creds_backends : creds_frontends);
|
||||
|
||||
spin_rdlock(&cg.lock);
|
||||
btree::btree_map<uint64_t, account_details_t *>::iterator lookup;
|
||||
lookup = cg.bt_map.find(hash1);
|
||||
if (lookup != cg.bt_map.end()) {
|
||||
account_details_t *ad=lookup->second;
|
||||
ret=l_strdup(ad->password);
|
||||
if (use_ssl) *use_ssl=ad->use_ssl;
|
||||
if (default_hostgroup) *default_hostgroup=ad->default_hostgroup;
|
||||
if (default_schema) *default_schema=l_strdup(ad->default_schema);
|
||||
if (schema_locked) *schema_locked=ad->schema_locked;
|
||||
if (transaction_persistent) *transaction_persistent=ad->transaction_persistent;
|
||||
if (fast_forward) *fast_forward=ad->fast_forward;
|
||||
}
|
||||
spin_rdunlock(&cg.lock);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
bool _reset(enum cred_username_type usertype) {
|
||||
|
||||
creds_group_t &cg=(usertype==USERNAME_BACKEND ? creds_backends : creds_frontends);
|
||||
|
||||
spin_wrlock(&cg.lock);
|
||||
btree::btree_map<uint64_t, account_details_t *>::iterator lookup;
|
||||
|
||||
while (cg.bt_map.size()) {
|
||||
lookup = cg.bt_map.begin();
|
||||
if ( lookup != cg.bt_map.end() ) {
|
||||
account_details_t *ad=lookup->second;
|
||||
cg.cred_array.remove_fast(ad);
|
||||
cg.bt_map.erase(lookup);
|
||||
free(ad->username);
|
||||
free(ad->password);
|
||||
free(ad);
|
||||
}
|
||||
}
|
||||
spin_wrunlock(&cg.lock);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
virtual bool reset() {
|
||||
_reset(USERNAME_BACKEND);
|
||||
_reset(USERNAME_FRONTEND);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
extern "C" MySQL_Authentication * create_MySQL_Authentication_func() {
|
||||
return new Standard_MySQL_Authentication();
|
||||
}
|
||||
|
||||
extern "C" void destroy_MyAuth(MySQL_Authentication * myauth) {
|
||||
delete myauth;
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue