Merge from Z3
Merge from Z3
This commit is contained in:
@ -3,6 +3,7 @@ include ../makefile.inc
|
||||
|
||||
CC = gcc
|
||||
CPP = g++
|
||||
UTILS_PATH := $(ROOT_PATH)/utils
|
||||
|
||||
makeall: clean all
|
||||
|
||||
@ -13,7 +14,7 @@ clean:
|
||||
- $(DEL) *~
|
||||
|
||||
all:
|
||||
$(CPP) -c $(CFLAGS) \
|
||||
$(CPP) -c $(CFLAGS) -I$(UTILS_PATH) \
|
||||
-fPIC skygw_utils.cc -o skygw_utils.o
|
||||
|
||||
cleantests:
|
||||
|
||||
@ -123,7 +123,8 @@ typedef enum skygw_chk_t {
|
||||
CHK_NUM_SESCMD_CUR,
|
||||
CHK_NUM_BACKEND,
|
||||
CHK_NUM_BACKEND_REF,
|
||||
CHK_NUM_PREP_STMT
|
||||
CHK_NUM_PREP_STMT,
|
||||
CHK_NUM_PINFO
|
||||
} skygw_chk_t;
|
||||
|
||||
# define STRBOOL(b) ((b) ? "true" : "false")
|
||||
@ -133,7 +134,8 @@ typedef enum skygw_chk_t {
|
||||
((t) == QUERY_TYPE_SESSION_WRITE ? "QUERY_TYPE_SESSION_WRITE" : \
|
||||
((t) == QUERY_TYPE_UNKNOWN ? "QUERY_TYPE_UNKNOWN" : \
|
||||
((t) == QUERY_TYPE_LOCAL_READ ? "QUERY_TYPE_LOCAL_READ" : \
|
||||
"Unknown query type")))))
|
||||
((t) == QUERY_TYPE_EXEC_STMT ? "QUERY_TYPE_EXEC_STMT" : \
|
||||
"Unknown query type"))))))
|
||||
|
||||
#define STRLOGID(i) ((i) == LOGFILE_TRACE ? "LOGFILE_TRACE" : \
|
||||
((i) == LOGFILE_MESSAGE ? "LOGFILE_MESSAGE" : \
|
||||
@ -231,11 +233,13 @@ typedef enum skygw_chk_t {
|
||||
((c) == LEAST_BEHIND_MASTER ? "LEAST_BEHIND_MASTER" : \
|
||||
((c) == LEAST_CURRENT_OPERATIONS ? "LEAST_CURRENT_OPERATIONS" : "Unknown criteria")))))
|
||||
|
||||
#define STRSRVSTATUS(s) ((SERVER_IS_RUNNING(s) && SERVER_IS_MASTER(s)) ? "RUNNING MASTER" : \
|
||||
((SERVER_IS_RUNNING(s) && SERVER_IS_SLAVE(s)) ? "RUNNING SLAVE" : \
|
||||
((SERVER_IS_RUNNING(s) && SERVER_IS_JOINED(s)) ? "RUNNING JOINED" : \
|
||||
#define STRSRVSTATUS(s) (SERVER_IS_MASTER(s) ? "RUNNING MASTER" : \
|
||||
(SERVER_IS_SLAVE(s) ? "RUNNING SLAVE" : \
|
||||
(SERVER_IS_JOINED(s) ? "RUNNING JOINED" : \
|
||||
(SERVER_IS_NDB(s) ? "RUNNING NDB" : \
|
||||
((SERVER_IS_RUNNING(s) && SERVER_IN_MAINT(s)) ? "RUNNING MAINTENANCE" : \
|
||||
(SERVER_IS_RUNNING(s) ? "RUNNING (only)" : "NO STATUS")))))
|
||||
(SERVER_IS_RELAY_SERVER(s) ? "RUNNING RELAY" : \
|
||||
(SERVER_IS_RUNNING(s) ? "RUNNING (only)" : "NO STATUS")))))))
|
||||
|
||||
#define CHK_MLIST(l) { \
|
||||
ss_info_dassert((l->mlist_chk_top == CHK_NUM_MLIST && \
|
||||
@ -486,6 +490,13 @@ typedef enum skygw_chk_t {
|
||||
"Prepared statement struct has invalid check fields"); \
|
||||
}
|
||||
|
||||
#define CHK_PARSING_INFO(p) { \
|
||||
ss_info_dassert((p)->pi_chk_top == CHK_NUM_PINFO && \
|
||||
(p)->pi_chk_tail == CHK_NUM_PINFO, \
|
||||
"Parsing info struct has invalid check fields"); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if defined(SS_DEBUG)
|
||||
bool conn_open[10240];
|
||||
|
||||
@ -44,4 +44,7 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define MAX_ERROR_MSG PATH_MAX
|
||||
#define array_nelems(a) ((uint)(sizeof(a)/sizeof(a[0])))
|
||||
|
||||
#endif /* SKYGW_TYPES_H */
|
||||
|
||||
@ -23,9 +23,10 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <regex.h>
|
||||
#include "skygw_debug.h"
|
||||
#include "skygw_types.h"
|
||||
#include <skygw_types.h>
|
||||
#include "skygw_utils.h"
|
||||
|
||||
const char* timestamp_formatstr = "%04d-%02d-%02d %02d:%02d:%02d ";
|
||||
@ -1863,3 +1864,104 @@ void skygw_file_done(
|
||||
free(file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find the given needle - user-provided literal - and replace it with
|
||||
* replacement string. Separate user-provided literals from matching table names
|
||||
* etc. by searching only substrings preceded by non-letter and non-number.
|
||||
*
|
||||
* @param haystack Plain text query string, not to be freed
|
||||
* @param needle Substring to be searched, not to be freed
|
||||
* @param replacement Replacement text, not to be freed
|
||||
*
|
||||
* @return newly allocated string where needle is replaced
|
||||
*/
|
||||
char* replace_literal(
|
||||
char* haystack,
|
||||
const char* needle,
|
||||
const char* replacement)
|
||||
{
|
||||
const char* prefix = "[ ='\",\\(]"; /*< ' ','=','(',''',''"',',' are allowed before needle */
|
||||
const char* suffix = "([^[:alnum:]]|$)"; /*< alpha-num chars aren't allowed after the needle */
|
||||
char* search_re;
|
||||
char* newstr;
|
||||
regex_t re;
|
||||
regmatch_t match;
|
||||
int rc;
|
||||
size_t rlen = strlen(replacement);
|
||||
size_t nlen = strlen(needle);
|
||||
size_t hlen = strlen(haystack);
|
||||
|
||||
search_re = (char *)malloc(strlen(prefix)+nlen+strlen(suffix)+1);
|
||||
|
||||
if (search_re == NULL)
|
||||
{
|
||||
fprintf(stderr, "Regex memory allocation failed : %s\n",
|
||||
strerror(errno));
|
||||
newstr = haystack;
|
||||
goto retblock;
|
||||
}
|
||||
|
||||
sprintf(search_re, "%s%s%s", prefix, needle, suffix);
|
||||
/** Allocate memory for new string +1 for terminating byte */
|
||||
newstr = (char *)malloc(hlen-nlen+rlen+1);
|
||||
|
||||
if (newstr == NULL)
|
||||
{
|
||||
fprintf(stderr, "Regex memory allocation failed : %s\n",
|
||||
strerror(errno));
|
||||
free(search_re);
|
||||
free(newstr);
|
||||
newstr = haystack;
|
||||
goto retblock;
|
||||
}
|
||||
|
||||
rc = regcomp(&re, search_re, REG_EXTENDED|REG_ICASE);
|
||||
ss_dassert(rc == 0);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
char error_message[MAX_ERROR_MSG];
|
||||
regerror (rc, &re, error_message, MAX_ERROR_MSG);
|
||||
fprintf(stderr,
|
||||
"Regex error compiling '%s': %s\n",
|
||||
search_re,
|
||||
error_message);
|
||||
free(search_re);
|
||||
free(newstr);
|
||||
newstr = haystack;
|
||||
goto retblock;
|
||||
}
|
||||
rc = regexec(&re, haystack, 1, &match, 0);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
free(search_re);
|
||||
free(newstr);
|
||||
regfree(&re);
|
||||
newstr = haystack;
|
||||
goto retblock;
|
||||
}
|
||||
memcpy(newstr, haystack, match.rm_so+1);
|
||||
memcpy(newstr+match.rm_so+1, replacement, rlen);
|
||||
/** +1 is terminating byte */
|
||||
memcpy(newstr+match.rm_so+1+rlen, haystack+match.rm_so+1+nlen, hlen-(match.rm_so+1)-nlen+1);
|
||||
|
||||
regfree(&re);
|
||||
free(haystack);
|
||||
free(search_re);
|
||||
retblock:
|
||||
return newstr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -83,6 +83,7 @@ typedef enum { THR_INIT, THR_RUNNING, THR_STOPPED, THR_DONE } skygw_thr_state_t;
|
||||
typedef enum { MES_RC_FAIL, MES_RC_SUCCESS, MES_RC_TIMEOUT } skygw_mes_rc_t;
|
||||
|
||||
EXTERN_C_BLOCK_BEGIN
|
||||
|
||||
slist_cursor_t* slist_init(void);
|
||||
void slist_done(slist_cursor_t* c);
|
||||
|
||||
@ -192,4 +193,12 @@ int skygw_rwlock_init(skygw_rwlock_t** rwlock);
|
||||
|
||||
int atomic_add(int *variable, int value);
|
||||
|
||||
EXTERN_C_BLOCK_BEGIN
|
||||
|
||||
char* replace_literal(char* haystack,
|
||||
const char* needle,
|
||||
const char* replacement);
|
||||
|
||||
EXTERN_C_BLOCK_END
|
||||
|
||||
#endif /* SKYGW_UTILS_H */
|
||||
|
||||
Reference in New Issue
Block a user