@ -68,7 +68,7 @@ struct __SQP_query_parser_t {
typedef struct __SQP_query_parser_t SQP_par_t ;
static char * commands_counters_desc [ MYSQL_COM_QUERY___NONE ] ;
//static char *commands_counters_desc[MYSQL_COM_QUERY___NONE];
@ -122,7 +122,7 @@ static void __reset_rules(std::vector<QP_rule_t *> * qrs) {
qrs - > clear ( ) ;
}
/*
class Command_Counter {
private :
int cmd_idx ;
@ -170,14 +170,14 @@ class Command_Counter {
free ( pta ) ;
}
} ;
*/
// per thread variables
__thread unsigned int _thr_SQP_version ;
__thread std : : vector < QP_rule_t * > * _thr_SQP_rules ;
//__thread unsigned int _thr_commands_counters[MYSQL_COM_QUERY___NONE];
__thread Command_Counter * _thr_commands_counters [ MYSQL_COM_QUERY___NONE ] ;
/*
class Standard_Query_Processor : public Query_Processor {
private :
@ -188,9 +188,9 @@ Command_Counter * commands_counters[MYSQL_COM_QUERY___NONE];
volatile unsigned int version ;
protected :
public :
Standard_Query_Processor ( ) {
*/
Query_Processor : : Query_Processor ( ) {
# ifdef DEBUG
if ( glovars . has_debug = = false ) {
# else
@ -250,13 +250,13 @@ Standard_Query_Processor() {
commands_counters_desc [ MYSQL_COM_QUERY_UNKNOWN ] = ( char * ) " UNKNOWN " ;
} ;
virtual ~ Standard_ Query_Processor( ) {
Query_Processor : : ~ Query_Processor( ) {
for ( int i = 0 ; i < MYSQL_COM_QUERY___NONE ; i + + ) delete commands_counters [ i ] ;
__reset_rules ( & rules ) ;
} ;
// This function is called by each thread when it starts. It create a Query Processor Table for each thread
virtual void init_thread( ) {
void Query_Processor : : init_thread( ) {
proxy_debug ( PROXY_DEBUG_MYSQL_QUERY_PROCESSOR , 4 , " Initializing Per-Thread Query Processor Table with version=0 \n " ) ;
_thr_SQP_version = 0 ;
_thr_SQP_rules = new std : : vector < QP_rule_t * > ;
@ -264,28 +264,28 @@ virtual void init_thread() {
} ;
virtual void end_thread( ) {
void Query_Processor : : end_thread( ) {
proxy_debug ( PROXY_DEBUG_MYSQL_QUERY_PROCESSOR , 4 , " Destroying Per-Thread Query Processor Table with version=%d \n " , _thr_SQP_version ) ;
__reset_rules ( _thr_SQP_rules ) ;
delete _thr_SQP_rules ;
for ( int i = 0 ; i < MYSQL_COM_QUERY___NONE ; i + + ) delete _thr_commands_counters [ i ] ;
} ;
virtual void print_version( ) {
void Query_Processor : : print_version( ) {
fprintf ( stderr , " Standard Query Processor rev. %s -- %s -- %s \n " , QUERY_PROCESSOR_VERSION , __FILE__ , __TIMESTAMP__ ) ;
} ;
virtual void wrlock( ) {
void Query_Processor : : wrlock( ) {
spin_wrlock ( & rwlock ) ;
} ;
virtual void wrunlock( ) {
void Query_Processor : : wrunlock( ) {
spin_wrunlock ( & rwlock ) ;
} ;
virtual QP_rule_t * new_query_rule( int rule_id , bool active , char * username , char * schemaname , int flagIN , char * match_pattern , bool negate_match_pattern , int flagOUT , char * replace_pattern , int destination_hostgroup , int cache_ttl , bool apply ) {
QP_rule_t * Query_Processor : : new_query_rule( int rule_id , bool active , char * username , char * schemaname , int flagIN , char * match_pattern , bool negate_match_pattern , int flagOUT , char * replace_pattern , int destination_hostgroup , int cache_ttl , bool apply ) {
QP_rule_t * newQR = ( QP_rule_t * ) malloc ( sizeof ( QP_rule_t ) ) ;
newQR - > rule_id = rule_id ;
newQR - > active = active ;
@ -306,17 +306,17 @@ virtual QP_rule_t * new_query_rule(int rule_id, bool active, char *username, cha
} ;
virtual void delete_query_rule( QP_rule_t * qr ) {
void Query_Processor : : delete_query_rule( QP_rule_t * qr ) {
__delete_query_rule ( qr ) ;
} ;
virtual void reset_all( bool lock ) {
void Query_Processor : : reset_all( bool lock ) {
if ( lock ) spin_wrlock ( & rwlock ) ;
__reset_rules ( & rules ) ;
if ( lock ) spin_wrunlock ( & rwlock ) ;
} ;
virtual bool insert( QP_rule_t * qr , bool lock ) {
bool Query_Processor : : insert( QP_rule_t * qr , bool lock ) {
bool ret = true ;
if ( lock ) spin_wrlock ( & rwlock ) ;
rules . push_back ( qr ) ;
@ -325,7 +325,7 @@ virtual bool insert(QP_rule_t *qr, bool lock) {
} ;
virtual void sort( bool lock ) {
void Query_Processor : : sort( bool lock ) {
if ( lock ) spin_wrlock ( & rwlock ) ;
proxy_debug ( PROXY_DEBUG_MYSQL_QUERY_PROCESSOR , 4 , " Sorting rules \n " ) ;
std : : sort ( rules . begin ( ) , rules . end ( ) , rules_sort_comp_function ) ;
@ -334,7 +334,7 @@ virtual void sort(bool lock) {
// when commit is called, the version number is increased and the this will trigger the mysql threads to get a new Query Processor Table
// The operation is asynchronous
virtual void commit( ) {
void Query_Processor : : commit( ) {
spin_wrlock ( & rwlock ) ;
__sync_add_and_fetch ( & version , 1 ) ;
proxy_debug ( PROXY_DEBUG_MYSQL_QUERY_PROCESSOR , 4 , " Increasing version number to %d - all threads will notice this and refresh their rules \n " , version ) ;
@ -342,7 +342,7 @@ virtual void commit() {
} ;
virtual SQLite3_result * get_stats_commands_counters( ) {
SQLite3_result * Query_Processor : : get_stats_commands_counters( ) {
proxy_debug ( PROXY_DEBUG_MYSQL_QUERY_PROCESSOR , 4 , " Dumping commands counters \n " ) ;
SQLite3_result * result = new SQLite3_result ( 15 ) ;
result - > add_column_definition ( SQLITE_TEXT , " Command " ) ;
@ -367,7 +367,7 @@ virtual SQLite3_result * get_stats_commands_counters() {
}
return result ;
}
virtual SQLite3_result * get_stats_query_rules( ) {
SQLite3_result * Query_Processor : : get_stats_query_rules( ) {
proxy_debug ( PROXY_DEBUG_MYSQL_QUERY_PROCESSOR , 4 , " Dumping query rules statistics, using Global version %d \n " , version ) ;
SQLite3_result * result = new SQLite3_result ( 2 ) ;
spin_rdlock ( & rwlock ) ;
@ -387,7 +387,7 @@ virtual SQLite3_result * get_stats_query_rules() {
return result ;
}
virtual SQLite3_result * get_current_query_rules( ) {
SQLite3_result * Query_Processor : : get_current_query_rules( ) {
proxy_debug ( PROXY_DEBUG_MYSQL_QUERY_PROCESSOR , 4 , " Dumping current query rules, using Global version %d \n " , version ) ;
SQLite3_result * result = new SQLite3_result ( 13 ) ;
spin_rdlock ( & rwlock ) ;
@ -417,7 +417,7 @@ virtual SQLite3_result * get_current_query_rules() {
}
virtual QP_out_t * process_mysql_query( MySQL_Session * sess , void * ptr , unsigned int size , bool delete_original ) {
QP_out_t * Query_Processor : : process_mysql_query( MySQL_Session * sess , void * ptr , unsigned int size , bool delete_original ) {
QP_out_t * ret = NULL ;
unsigned int len = size - sizeof ( mysql_hdr ) - 1 ;
char * query = ( char * ) l_alloc ( len + 1 ) ;
@ -557,11 +557,11 @@ __exit_process_mysql_query:
} ;
// this function is called by mysql_session to free the result generated by process_mysql_query()
virtual void delete_QP_out( QP_out_t * o ) {
void Query_Processor : : delete_QP_out( QP_out_t * o ) {
l_free ( sizeof ( QP_out_t ) , o ) ;
} ;
virtual void update_query_processor_stats( ) {
void Query_Processor : : update_query_processor_stats( ) {
// Note:
// this function is called by each thread to update global query statistics
//
@ -593,26 +593,26 @@ virtual void update_query_processor_stats() {
}
} ;
virtual void * query_parser_init( char * query , int query_length , int flags ) {
void * Query_Processor : : query_parser_init( char * query , int query_length , int flags ) {
SQP_par_t * qp = ( SQP_par_t * ) malloc ( sizeof ( SQP_par_t ) ) ;
libinjection_sqli_init ( & qp - > sf , query , query_length , FLAG_SQL_MYSQL ) ;
return ( void * ) qp ;
} ;
virtual enum MYSQL_COM_QUERY_command query_parser_command_type( void * args ) {
enum MYSQL_COM_QUERY_command Query_Processor : : query_parser_command_type( void * args ) {
enum MYSQL_COM_QUERY_command ret = __query_parser_command_type ( args ) ;
//_thr_commands_counters[ret]++;
return ret ;
}
virtual unsigned long long query_parser_update_counters( enum MYSQL_COM_QUERY_command c , unsigned long long t ) {
unsigned long long Query_Processor : : query_parser_update_counters( enum MYSQL_COM_QUERY_command c , unsigned long long t ) {
if ( c > = MYSQL_COM_QUERY___NONE ) return 0 ;
unsigned long long ret = _thr_commands_counters [ c ] - > add_time ( t ) ;
return ret ;
}
enum MYSQL_COM_QUERY_command __query_parser_command_type( void * args ) {
enum MYSQL_COM_QUERY_command Query_Processor : : __query_parser_command_type( void * args ) {
SQP_par_t * qp = ( SQP_par_t * ) args ;
while ( libinjection_sqli_tokenize ( & qp - > sf ) ) {
if ( qp - > sf . current - > type = = ' E ' | | qp - > sf . current - > type = = ' k ' | | qp - > sf . current - > type = = ' T ' ) {
@ -722,19 +722,9 @@ enum MYSQL_COM_QUERY_command __query_parser_command_type(void *args) {
return MYSQL_COM_QUERY_UNKNOWN ;
}
virtual char * query_parser_first_comment( void * args ) { return NULL ; }
char * Query_Processor : : query_parser_first_comment( void * args ) { return NULL ; }
virtual void query_parser_free( void * args ) {
void Query_Processor : : query_parser_free( void * args ) {
SQP_par_t * qp = ( SQP_par_t * ) args ;
free ( qp ) ;
} ;
} ;
extern " C " Query_Processor * create_Query_Processor_func ( ) {
return new Standard_Query_Processor ( ) ;
}
extern " C " void destroy_Query_Processor ( Query_Processor * qp ) {
delete qp ;
}