Skip to content

Commit

Permalink
mysql_query_rules.OK_msg #1045
Browse files Browse the repository at this point in the history
Extending mysql_query_rules with a new field: OK_msg

If OK_msg is not NULL, an OK packet is sent to the client with an optional
message as specified in OK_msg itself.
If OK_msg is an not NULL empty string, an OK packet is sent to the client
without any message.
If both error_msg and OK_msg are present, error_msg is returned.

This commit includes also few minor bugs, mostly related to typo that would
prevent online upgrade of mysql_query_rules from early release of 1.4.0 .
  • Loading branch information
renecannao committed Jun 17, 2017
1 parent fc5a56e commit 4188d20
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 34 deletions.
11 changes: 9 additions & 2 deletions include/query_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct _Query_Processor_rule_t {
int mirror_hostgroup;
int mirror_flagOUT;
char *error_msg;
char *OK_msg;
int sticky_conn;
int multiplex;
int log;
Expand All @@ -59,7 +60,8 @@ class Query_Processor_Output {
int timeout;
int retries;
int delay;
char *error_msg;
char *error_msg;
char *OK_msg;
int sticky_conn;
int multiplex;
int log;
Expand Down Expand Up @@ -94,13 +96,18 @@ class Query_Processor_Output {
log=-1;
new_query=NULL;
error_msg=NULL;
OK_msg=NULL;
comment=NULL; // #643
}
void destroy() {
if (error_msg) {
free(error_msg);
error_msg=NULL;
}
if (OK_msg) {
free(OK_msg);
OK_msg=NULL;
}
if (comment) { // #643
free(comment);
}
Expand Down Expand Up @@ -187,7 +194,7 @@ class Query_Processor {
void wrlock(); // explicit write lock, to be used in multi-isert
void wrunlock(); // explicit write unlock
bool insert(QP_rule_t *qr, bool lock=true); // insert a new rule. Uses a generic void pointer to a structure that may vary depending from the Query Processor
QP_rule_t * new_query_rule(int rule_id, bool active, char *username, char *schemaname, int flagIN, char *client_addr, char *proxy_addr, int proxy_port, char *digest, char *match_digest, char *match_pattern, bool negate_match_pattern, char *re_modifiers, int flagOUT, char *replace_pattern, int destination_hostgroup, int cache_ttl, int reconnect, int timeout, int retries, int delay, int next_query_flagIN, int mirror_hostgroup, int mirror_flagOUT, char *error_msg, int sticky_conn, int multiplex, int log, bool apply, char *comment); // to use a generic query rule struct, this is generated by this function and returned as generic void pointer
QP_rule_t * new_query_rule(int rule_id, bool active, char *username, char *schemaname, int flagIN, char *client_addr, char *proxy_addr, int proxy_port, char *digest, char *match_digest, char *match_pattern, bool negate_match_pattern, char *re_modifiers, int flagOUT, char *replace_pattern, int destination_hostgroup, int cache_ttl, int reconnect, int timeout, int retries, int delay, int next_query_flagIN, int mirror_hostgroup, int mirror_flagOUT, char *error_msg, char *OK_msg, int sticky_conn, int multiplex, int log, bool apply, char *comment); // to use a generic query rule struct, this is generated by this function and returned as generic void pointer
void delete_query_rule(QP_rule_t *qr); // destructor
Query_Processor_Output * process_mysql_query(MySQL_Session *sess, void *ptr, unsigned int size, Query_Info *qi);
void delete_QP_out(Query_Processor_Output *o);
Expand Down
11 changes: 11 additions & 0 deletions lib/MySQL_Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3292,6 +3292,17 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
return true;
}

if (qpo->OK_msg) {
client_myds->DSS=STATE_QUERY_SENT_NET;
unsigned int nTrx=NumActiveTransactions();
uint16_t setStatus = (nTrx ? SERVER_STATUS_IN_TRANS : 0 );
if (autocommit) setStatus += SERVER_STATUS_AUTOCOMMIT;
client_myds->myprot.generate_pkt_OK(true,NULL,NULL,client_myds->pkt_sid+1,0,0,setStatus,0,qpo->OK_msg);
l_free(pkt->size,pkt->ptr);
RequestEnd(NULL);
return true;
}

if (qpo->error_msg) {
client_myds->DSS=STATE_QUERY_SENT_NET;
client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,client_myds->pkt_sid+1,1148,(char *)"42000",qpo->error_msg);
Expand Down
Loading

0 comments on commit 4188d20

Please sign in to comment.