mirror of
https://gitee.com/wangbin579/cetus.git
synced 2024-12-02 03:47:41 +08:00
Merge pull request #66 from wangbin579/master
Optimize code hinted by coverity scan and cppcheck
This commit is contained in:
commit
69a9aa8f34
@ -407,7 +407,7 @@ sql_expr_list_find_fullname(sql_expr_list_t *list, const sql_expr_t *expr)
|
||||
int
|
||||
sql_expr_list_find_aggregate(sql_expr_list_t *list)
|
||||
{
|
||||
int i, index = 0;
|
||||
int i;
|
||||
enum sql_func_type_t type;
|
||||
for (i = 0; i < list->len; ++i) {
|
||||
sql_expr_t *p = g_ptr_array_index(list, i);
|
||||
|
@ -2042,10 +2042,10 @@ admin_save_settings(network_mysqld_con *con, const char *sql)
|
||||
chassis *srv = con->srv;
|
||||
GKeyFile *keyfile = g_key_file_new();
|
||||
g_key_file_set_list_separator(keyfile, ',');
|
||||
GError *gerr = NULL;
|
||||
gint ret = 0;
|
||||
gint ret = ASSIGN_OK;
|
||||
gint effected_rows = 0;
|
||||
GString *free_path = g_string_new(NULL);
|
||||
|
||||
if(srv->default_file == NULL) {
|
||||
free_path = g_string_append(free_path, get_current_dir_name());
|
||||
free_path = g_string_append(free_path, "/default.conf");
|
||||
@ -2064,48 +2064,51 @@ admin_save_settings(network_mysqld_con *con, const char *sql)
|
||||
if(free_path) {
|
||||
g_string_free(free_path, TRUE);
|
||||
}
|
||||
//1 rename config file
|
||||
/* rename config file */
|
||||
if(srv->default_file) {
|
||||
GString *new_file = g_string_new(NULL);
|
||||
new_file = g_string_append(new_file, srv->default_file);
|
||||
new_file = g_string_append(new_file, ".old");
|
||||
remove(new_file->str);
|
||||
g_debug("remove operate, filename:%s, errno:%d", new_file->str == NULL? "":new_file->str, errno);
|
||||
|
||||
if (remove(new_file->str)) {
|
||||
g_debug("remove operate, filename:%s, errno:%d",
|
||||
new_file->str == NULL? "":new_file->str, errno);
|
||||
}
|
||||
|
||||
if(rename(srv->default_file, new_file->str)) {
|
||||
g_debug("rename operate failed, filename:%s, filename:%s, errno:%d", (srv->default_file == NULL ? "":srv->default_file),
|
||||
g_debug("rename operate failed, filename:%s, filename:%s, errno:%d",
|
||||
(srv->default_file == NULL ? "":srv->default_file),
|
||||
(new_file->str == NULL ? "":new_file->str), errno);
|
||||
ret = RENAME_ERROR;
|
||||
}
|
||||
g_string_free(new_file, TRUE);
|
||||
}
|
||||
|
||||
if(0 == ret) {
|
||||
//2 save new config
|
||||
if(ret == ASSIGN_OK) {
|
||||
/* save new config */
|
||||
effected_rows = chassis_options_save(keyfile, srv->options, srv);
|
||||
gsize file_size = 0;
|
||||
gchar *file_buf = g_key_file_to_data(keyfile, &file_size, NULL);
|
||||
GError *gerr = NULL;
|
||||
if (FALSE == g_file_set_contents(srv->default_file, file_buf, file_size, &gerr)) {
|
||||
ret = SAVE_ERROR;
|
||||
} else {
|
||||
if((ret = chmod(srv->default_file, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP))) {
|
||||
g_debug("remove operate failed, filename:%s, errno:%d", (srv->default_file == NULL? "":srv->default_file), errno);
|
||||
g_debug("remove operate failed, filename:%s, errno:%d",
|
||||
(srv->default_file == NULL? "":srv->default_file), errno);
|
||||
ret = CHMOD_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(0 == ret) {
|
||||
if(ret == ASSIGN_OK) {
|
||||
network_mysqld_con_send_ok_full(con->client, effected_rows, 0, SERVER_STATUS_AUTOCOMMIT, 0);
|
||||
} else if(RENAME_ERROR == ret) {
|
||||
} else if(ret == RENAME_ERROR) {
|
||||
network_mysqld_con_send_error_full(con->client, C("rename file failed"), 1066, "28000");
|
||||
} else if(SAVE_ERROR == ret) {
|
||||
} else if(ret == SAVE_ERROR) {
|
||||
network_mysqld_con_send_error_full(con->client, C("save file failed"), 1066, "28000");
|
||||
} else if(REMOVE_ERROR == ret) {
|
||||
network_mysqld_con_send_error_full(con->client, C("remove old file failed"), 1066, "28000");
|
||||
} else if(CHMOD_ERROR == ret) {
|
||||
} else if(ret == CHMOD_ERROR) {
|
||||
network_mysqld_con_send_error_full(con->client, C("chmod file failed"), 1066, "28000");
|
||||
} else {
|
||||
network_mysqld_con_send_error_full(con->client, C("unknown error happened"), 1066, "28000");
|
||||
}
|
||||
|
||||
return PROXY_SEND_RESULT;
|
||||
|
@ -2275,9 +2275,7 @@ show_proxy_read_only_backend_address(gpointer param) {
|
||||
free_str->str[free_str->len -1] = '\0';
|
||||
ret = g_strdup(free_str->str);
|
||||
}
|
||||
if(free_str) {
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -2306,7 +2304,7 @@ show_proxy_backend_addresses(gpointer param) {
|
||||
if(free_str->len) {
|
||||
free_str->str[free_str->len -1] = '\0';
|
||||
}
|
||||
//handle defaults
|
||||
/* handle defaults */
|
||||
if(!strcasecmp(free_str->str, "127.0.0.1:3306")) {
|
||||
ret = NULL;
|
||||
} else {
|
||||
@ -2314,9 +2312,8 @@ show_proxy_backend_addresses(gpointer param) {
|
||||
ret = g_strdup(free_str->str);
|
||||
}
|
||||
}
|
||||
if(free_str) {
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -2329,7 +2326,7 @@ show_proxy_connect_timeout(gpointer param) {
|
||||
return g_strdup_printf("%lf (s)", config->connect_timeout_dbl);
|
||||
}
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
//handle default
|
||||
/* handle default */
|
||||
if(config->connect_timeout_dbl == -1) {
|
||||
return NULL;
|
||||
}
|
||||
@ -2367,7 +2364,7 @@ show_proxy_read_timeout(gpointer param) {
|
||||
return g_strdup_printf("%lf (s)", config->read_timeout_dbl);
|
||||
}
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
//handle default
|
||||
/* handle default */
|
||||
if(config->read_timeout_dbl == -1) {
|
||||
return NULL;
|
||||
}
|
||||
@ -2454,9 +2451,8 @@ show_proxy_allow_ip(gpointer param) {
|
||||
ret = g_strdup(free_str->str);
|
||||
}
|
||||
}
|
||||
if(free_str) {
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
|
||||
g_string_free(free_str, TRUE);
|
||||
if(free_list) {
|
||||
g_list_free(free_list);
|
||||
}
|
||||
@ -2484,9 +2480,8 @@ show_proxy_deny_ip(gpointer param) {
|
||||
ret = g_strdup(free_str->str);
|
||||
}
|
||||
}
|
||||
if(free_str) {
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
|
||||
g_string_free(free_str, TRUE);
|
||||
if(free_list) {
|
||||
g_list_free(free_list);
|
||||
}
|
||||
@ -2502,7 +2497,7 @@ show_read_master_percentage(gpointer param) {
|
||||
return g_strdup_printf("%d", config->read_master_percentage);
|
||||
}
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
//handle default
|
||||
/* handle default */
|
||||
if(config->read_master_percentage == 0) {
|
||||
return NULL;
|
||||
}
|
||||
@ -2520,7 +2515,7 @@ assign_read_master_percentage(const gchar *newval, gpointer param) {
|
||||
if(NULL != newval) {
|
||||
gint value = 0;
|
||||
if(try_get_int_value(newval, &value)) {
|
||||
if(value >= 0 || value <= 100) {
|
||||
if(value >= 0 && value <= 100) {
|
||||
config->read_master_percentage = value;
|
||||
ret = ASSIGN_OK;
|
||||
} else {
|
||||
|
@ -2108,21 +2108,19 @@ show_proxy_read_only_backend_address(gpointer param) {
|
||||
for (i = 0; i < bs->backends->len; i++) {
|
||||
network_backend_t *old_backend = g_ptr_array_index(bs->backends, i);
|
||||
if(old_backend && old_backend->type == BACKEND_TYPE_RO) {
|
||||
free_str = g_string_append(free_str, old_backend->address->str);
|
||||
if(old_backend->server_group && old_backend->server_group->len) {
|
||||
free_str = g_string_append(free_str, "@");
|
||||
free_str = g_string_append(free_str, old_backend->server_group->str);
|
||||
free_str = g_string_append(free_str, old_backend->address->str);
|
||||
if(old_backend->server_group && old_backend->server_group->len) {
|
||||
free_str = g_string_append(free_str, "@");
|
||||
free_str = g_string_append(free_str, old_backend->server_group->str);
|
||||
}
|
||||
free_str = g_string_append(free_str, ",");
|
||||
}
|
||||
free_str = g_string_append(free_str, ",");
|
||||
}
|
||||
}
|
||||
if(free_str->len) {
|
||||
free_str->str[free_str->len -1] = '\0';
|
||||
ret = g_strdup(free_str->str);
|
||||
}
|
||||
if(free_str) {
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
if(free_str->len) {
|
||||
free_str->str[free_str->len -1] = '\0';
|
||||
ret = g_strdup(free_str->str);
|
||||
}
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -2158,9 +2156,8 @@ show_proxy_backend_addresses(gpointer param) {
|
||||
ret = g_strdup(free_str->str);
|
||||
}
|
||||
}
|
||||
if(free_str) {
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -409,35 +409,6 @@ cetus_monitor_open(cetus_monitor_t *monitor, monitor_type_t monitor_type)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cetus_monitor_close(cetus_monitor_t *monitor, monitor_type_t monitor_type)
|
||||
{
|
||||
switch (monitor_type) {
|
||||
case MONITOR_TYPE_CHECK_ALIVE:
|
||||
if (monitor->check_alive_timer.ev_base) {
|
||||
evtimer_del(&monitor->check_alive_timer);
|
||||
}
|
||||
g_message("check_alive monitor close.");
|
||||
break;
|
||||
case MONITOR_TYPE_CHECK_DELAY:
|
||||
if (monitor->write_master_timer.ev_base) {
|
||||
evtimer_del(&monitor->write_master_timer);
|
||||
}
|
||||
if (monitor->read_slave_timer.ev_base) {
|
||||
evtimer_del(&monitor->read_slave_timer);
|
||||
}
|
||||
g_message("check_slave monitor close.");
|
||||
break;
|
||||
case MONITOR_TYPE_CHECK_CONFIG:
|
||||
if (monitor->check_config_timer.ev_base) {
|
||||
evtimer_del(&monitor->check_config_timer);
|
||||
}
|
||||
g_message("check_config monitor close.");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void *
|
||||
cetus_monitor_mainloop(void *data)
|
||||
|
@ -40,8 +40,6 @@ void cetus_monitor_free(cetus_monitor_t *);
|
||||
|
||||
void cetus_monitor_open(cetus_monitor_t *, monitor_type_t);
|
||||
|
||||
void cetus_monitor_close(cetus_monitor_t *, monitor_type_t);
|
||||
|
||||
void cetus_monitor_start_thread(cetus_monitor_t *, chassis *data);
|
||||
|
||||
void cetus_monitor_stop_thread(cetus_monitor_t *);
|
||||
|
@ -162,9 +162,7 @@ show_plugins(gpointer param) {
|
||||
free_str->str[free_str->len - 1] = '\0';
|
||||
ret = g_strdup_printf("%s", free_str->str);
|
||||
}
|
||||
if(free_str) {
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -1116,13 +1114,10 @@ chassis_options_save(GKeyFile *keyfile, chassis_options_t *opts, chassis *chas)
|
||||
if (value != NULL) {
|
||||
g_key_file_set_value(keyfile, "cetus", opt->long_name, value);
|
||||
effected_rows++;
|
||||
}
|
||||
if(value) {
|
||||
g_free(value);
|
||||
}
|
||||
if(opt_param) {
|
||||
g_free(opt_param);
|
||||
}
|
||||
|
||||
g_free(opt_param);
|
||||
}
|
||||
}
|
||||
return effected_rows;
|
||||
|
@ -37,15 +37,15 @@
|
||||
#define CAN_SHOW_OPTS_PROPERTY(opt_property) ((opt_property) & SHOW_OPTS_PROPERTY)
|
||||
#define CAN_SAVE_OPTS_PROPERTY(opt_property) ((opt_property) & SAVE_OPTS_PROPERTY)
|
||||
|
||||
#define ASSIGN_OK 0
|
||||
#define ASSIGN_ERROR -1
|
||||
#define ASSIGN_NOT_SUPPORT -2
|
||||
#define ASSIGN_VALUE_INVALID -3
|
||||
#define SAVE_ERROR -10
|
||||
#define RENAME_ERROR -11
|
||||
#define CHMOD_ERROR -12
|
||||
#define REMOVE_ERROR -13
|
||||
#define NOT_EXIST -14
|
||||
enum {
|
||||
ASSIGN_OK,
|
||||
ASSIGN_ERROR,
|
||||
ASSIGN_NOT_SUPPORT,
|
||||
ASSIGN_VALUE_INVALID,
|
||||
SAVE_ERROR,
|
||||
RENAME_ERROR,
|
||||
CHMOD_ERROR
|
||||
};
|
||||
|
||||
/* show utils */
|
||||
CHASSIS_API gchar* show_verbose_shutdown(gpointer param);
|
||||
|
@ -87,70 +87,6 @@ chassis_option_set(chassis_option_t *opt,
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *
|
||||
chassis_option_get_value_str(chassis_option_t *opt)
|
||||
{
|
||||
gchar *value = NULL;
|
||||
switch (opt->arg) {
|
||||
case OPTION_ARG_NONE:
|
||||
value = g_strdup((*(gint *)opt->arg_data) ? "true" : "false");
|
||||
break;
|
||||
case OPTION_ARG_INT:
|
||||
value = g_strdup_printf("%u", *(gint *)(opt->arg_data));
|
||||
break;
|
||||
case OPTION_ARG_INT64:
|
||||
value = g_strdup_printf("%lu", *(gint64 *)(opt->arg_data));
|
||||
break;
|
||||
case OPTION_ARG_DOUBLE:
|
||||
value = g_strdup_printf("%f", *(double *)(opt->arg_data));
|
||||
break;
|
||||
case OPTION_ARG_STRING:
|
||||
value = g_strdup(*(char **)opt->arg_data);
|
||||
break;
|
||||
default:
|
||||
value = g_strdup("error value");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
gboolean
|
||||
chassis_option_set_value(chassis_option_t *opt, const char *value)
|
||||
{
|
||||
switch (opt->arg) {
|
||||
case OPTION_ARG_NONE:
|
||||
if (strcasecmp(value, "true") == 0 || strcasecmp(value, "1") == 0) {
|
||||
*(gint *)opt->arg_data = 1;
|
||||
return TRUE;
|
||||
} else if (strcasecmp(value, "false") == 0 || strcasecmp(value, "0") == 0) {
|
||||
*(gint *)opt->arg_data = 0;
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
case OPTION_ARG_INT:{
|
||||
char *endptr = NULL;
|
||||
int num = strtol(value, &endptr, 0);
|
||||
if (endptr[0] == '\0') {
|
||||
*(gint *)opt->arg_data = num; /* TODO: apply lower/upper bounds */
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
case OPTION_ARG_INT64:{
|
||||
char *endptr = NULL;
|
||||
gint64 num = strtoll(value, &endptr, 0);
|
||||
if (endptr[0] == '\0') {
|
||||
*(gint64 *)opt->arg_data = num; /* TODO: apply lower/upper bounds */
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* create a command-line option
|
||||
@ -212,19 +148,6 @@ chassis_options_add(chassis_options_t *opts,
|
||||
}
|
||||
}
|
||||
|
||||
chassis_option_t *
|
||||
chassis_options_get(GList *opts, const char *long_name)
|
||||
{
|
||||
GList *l = opts;
|
||||
for (l = opts; l; l = l->next) {
|
||||
chassis_option_t *opt = l->data;
|
||||
if (strcmp(opt->long_name, long_name) == 0) {
|
||||
return opt;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define NO_ARG(entry) ((entry)->arg == OPTION_ARG_NONE)
|
||||
|
||||
#define OPTIONAL_ARG(entry) FALSE
|
||||
|
@ -84,12 +84,6 @@ int chassis_option_set(chassis_option_t *opt,
|
||||
const char *description,
|
||||
const char *arg_desc,
|
||||
chas_opt_assign_hook assign_hook, chas_opt_show_hook show_hook, gint opt_property);
|
||||
/**
|
||||
* @return newly allocated string, need to be freed
|
||||
*/
|
||||
char *chassis_option_get_value_str(chassis_option_t *opt);
|
||||
|
||||
gboolean chassis_option_set_value(chassis_option_t *opt, const char *);
|
||||
|
||||
typedef struct chassis_options_t {
|
||||
GList *options; /* List of chassis_option_t */
|
||||
@ -120,8 +114,6 @@ int chassis_options_add(chassis_options_t *opts,
|
||||
const char *arg_desc,
|
||||
chas_opt_assign_hook assign_hook, chas_opt_show_hook show_hook, gint opt_property);
|
||||
|
||||
chassis_option_t *chassis_options_get(GList *opts, const char *long_name);
|
||||
|
||||
gboolean chassis_options_parse_cmdline(chassis_options_t *context, int *argc, char ***argv, GError **error);
|
||||
|
||||
#endif
|
||||
|
@ -902,7 +902,7 @@ main_cmdline(int argc, char **argv)
|
||||
{
|
||||
gint i = 0;
|
||||
srv->plugin_names = g_new(char *, (srv->modules->len + 1));
|
||||
for (i = 0; frontend->plugin_names && frontend->plugin_names[i]; i++) {
|
||||
for (i = 0; frontend->plugin_names[i]; i++) {
|
||||
if (!g_strcmp0("", frontend->plugin_names[i])) {
|
||||
continue;
|
||||
}
|
||||
@ -1072,7 +1072,7 @@ main_cmdline(int argc, char **argv)
|
||||
if (frontend && !frontend->print_version) {
|
||||
/* add a tag to the logfile */
|
||||
g_log(G_LOG_DOMAIN,
|
||||
(srv->verbose_shutdown ? G_LOG_LEVEL_CRITICAL : G_LOG_LEVEL_MESSAGE),
|
||||
((srv && srv->verbose_shutdown) ? G_LOG_LEVEL_CRITICAL : G_LOG_LEVEL_MESSAGE),
|
||||
"shutting down normally, exit code is: %d", exit_code);
|
||||
}
|
||||
#ifdef HAVE_SIGACTION
|
||||
|
@ -133,7 +133,7 @@ network_backends_new()
|
||||
void
|
||||
network_backends_free(network_backends_t *bs)
|
||||
{
|
||||
gsize i, j;
|
||||
gsize i;
|
||||
|
||||
if (!bs)
|
||||
return;
|
||||
|
@ -1140,28 +1140,6 @@ network_mysqld_auth_challenge_free(network_mysqld_auth_challenge *shake)
|
||||
g_free(shake);
|
||||
}
|
||||
|
||||
network_mysqld_auth_challenge *
|
||||
network_mysqld_auth_challenge_copy(const network_mysqld_auth_challenge *src)
|
||||
{
|
||||
network_mysqld_auth_challenge *dst;
|
||||
|
||||
if (!src)
|
||||
return NULL;
|
||||
|
||||
dst = network_mysqld_auth_challenge_new();
|
||||
dst->protocol_version = src->protocol_version;
|
||||
dst->server_version = src->server_version;
|
||||
dst->thread_id = src->thread_id;
|
||||
dst->capabilities = src->capabilities;
|
||||
dst->charset = src->charset;
|
||||
dst->server_status = src->server_status;
|
||||
dst->server_version_str = g_strdup(src->server_version_str);
|
||||
g_string_assign_len(dst->auth_plugin_data, S(src->auth_plugin_data));
|
||||
g_string_assign_len(dst->auth_plugin_name, S(src->auth_plugin_name));
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
void
|
||||
network_mysqld_auth_challenge_set_challenge(network_mysqld_auth_challenge *shake)
|
||||
{
|
||||
@ -1513,99 +1491,6 @@ network_mysqld_proto_get_auth_response(network_packet *packet, network_mysqld_au
|
||||
return err ? -1 : 0;
|
||||
}
|
||||
|
||||
/* Change the auth process to the simple auth process */
|
||||
int
|
||||
network_mysqld_proto_get_and_change_auth_response(network_packet *packet, network_mysqld_auth_response *auth)
|
||||
{
|
||||
int err = 0;
|
||||
guint32 mysql_packet_len = 0;
|
||||
guint16 l_cap;
|
||||
/* extract the default db from it */
|
||||
|
||||
/*
|
||||
* @\0\0\1
|
||||
* \215\246\3\0 - client-flags
|
||||
* \0\0\0\1 - max-packet-len
|
||||
* \10 - charset-num
|
||||
* \0\0\0\0
|
||||
* \0\0\0\0
|
||||
* \0\0\0\0
|
||||
* \0\0\0\0
|
||||
* \0\0\0\0
|
||||
* \0\0\0 - fillers
|
||||
* root\0 - username
|
||||
* \24 - len of the scrambled buf
|
||||
* ~ \272 \361 \346
|
||||
* \211 \353 D \351
|
||||
* \24 \243 \223 \257
|
||||
* \0 ^ \n \254
|
||||
* t \347 \365 \244
|
||||
*
|
||||
* world\0
|
||||
*/
|
||||
|
||||
err = err || network_mysqld_proto_get_int24(packet, &mysql_packet_len);
|
||||
if (err)
|
||||
return -1;
|
||||
|
||||
packet->offset = NET_HEADER_SIZE;
|
||||
mysql_packet_len += NET_HEADER_SIZE;
|
||||
|
||||
/* 4.0 uses 2 byte, 4.1+ uses 4 bytes, but the proto-flag is in the lower 2 bytes */
|
||||
err = err || network_mysqld_proto_peek_int16(packet, &l_cap);
|
||||
if (err)
|
||||
return -1;
|
||||
|
||||
if (l_cap & CLIENT_PROTOCOL_41) {
|
||||
unsigned char *cap = (unsigned char *)packet->data->str + packet->offset;
|
||||
/* unset connect attrs and plugin auth flags in Extended Client Capabilities */
|
||||
cap[2] &= ~(8 | 16);
|
||||
err = err || network_mysqld_proto_get_int32(packet, &auth->client_capabilities);
|
||||
|
||||
err = err || network_mysqld_proto_get_int32(packet, &auth->max_packet_size);
|
||||
err = err || network_mysqld_proto_get_int8(packet, &auth->charset);
|
||||
|
||||
err = err || network_mysqld_proto_skip(packet, 23);
|
||||
|
||||
err = err || network_mysqld_proto_get_gstr(packet, auth->username);
|
||||
|
||||
guint8 len;
|
||||
/* new auth is 1-byte-len + data */
|
||||
err = err || network_mysqld_proto_get_int8(packet, &len);
|
||||
|
||||
err = err || network_mysqld_proto_get_gstr_len(packet, len, auth->auth_plugin_data);
|
||||
|
||||
if ((auth->server_capabilities & CLIENT_CONNECT_WITH_DB) &&
|
||||
(auth->client_capabilities & CLIENT_CONNECT_WITH_DB)) {
|
||||
err = err || network_mysqld_proto_get_gstr(packet, auth->database);
|
||||
}
|
||||
|
||||
if (mysql_packet_len != packet->offset) {
|
||||
network_mysqld_proto_set_packet_len(packet->data, packet->offset - NET_HEADER_SIZE);
|
||||
packet->data->len = packet->offset;
|
||||
}
|
||||
/* if ((auth->server_capabilities & CLIENT_PLUGIN_AUTH) &&
|
||||
(auth->client_capabilities & CLIENT_PLUGIN_AUTH)) {
|
||||
err = err || network_mysqld_proto_get_gstr(packet, auth->auth_plugin_name);
|
||||
} */
|
||||
} else {
|
||||
err = err || network_mysqld_proto_get_int16(packet, &l_cap);
|
||||
err = err || network_mysqld_proto_get_int24(packet, &auth->max_packet_size);
|
||||
err = err || network_mysqld_proto_get_gstr(packet, auth->username);
|
||||
if (packet->data->len != packet->offset) {
|
||||
/* if there is more, it is the password without a terminating \0 */
|
||||
err = err || network_mysqld_proto_get_gstr_len(packet,
|
||||
packet->data->len - packet->offset, auth->auth_plugin_data);
|
||||
}
|
||||
|
||||
if (!err) {
|
||||
auth->client_capabilities = l_cap;
|
||||
}
|
||||
}
|
||||
|
||||
return err ? -1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* append the auth struct to the mysqld packet
|
||||
*/
|
||||
|
@ -211,7 +211,6 @@ NETWORK_API void network_mysqld_auth_challenge_free(network_mysqld_auth_challeng
|
||||
NETWORK_API int network_mysqld_proto_get_auth_challenge(network_packet *, network_mysqld_auth_challenge *);
|
||||
NETWORK_API int network_mysqld_proto_append_auth_challenge(GString *, network_mysqld_auth_challenge *);
|
||||
NETWORK_API void network_mysqld_auth_challenge_set_challenge(network_mysqld_auth_challenge *);
|
||||
NETWORK_API network_mysqld_auth_challenge *network_mysqld_auth_challenge_copy(const network_mysqld_auth_challenge *);
|
||||
|
||||
struct network_mysqld_auth_response {
|
||||
guint32 client_capabilities;
|
||||
@ -230,7 +229,6 @@ NETWORK_API void network_mysqld_auth_response_free(network_mysqld_auth_response
|
||||
NETWORK_API int network_mysqld_proto_append_auth_response(GString *, network_mysqld_auth_response *);
|
||||
int network_mysqld_proto_append_auth_switch(GString *, char *method_name, GString* salt);
|
||||
NETWORK_API int network_mysqld_proto_get_auth_response(network_packet *, network_mysqld_auth_response *);
|
||||
NETWORK_API int network_mysqld_proto_get_and_change_auth_response(network_packet *, network_mysqld_auth_response *);
|
||||
|
||||
/* COM_STMT_* */
|
||||
|
||||
|
@ -591,226 +591,6 @@ network_socket_read(network_socket *sock)
|
||||
return NETWORK_SOCKET_SUCCESS;
|
||||
}
|
||||
|
||||
static network_socket_retval_t
|
||||
network_socket_compressed_write(network_socket *con, int send_chunks)
|
||||
{
|
||||
gssize len;
|
||||
int os_errno;
|
||||
|
||||
if (con->last_compressed_packet) {
|
||||
char *str = con->last_compressed_packet->str + con->compressed_unsend_offset;
|
||||
int unsend_len = con->last_compressed_packet->len - con->compressed_unsend_offset;
|
||||
|
||||
len = send(con->fd, str, unsend_len, 0);
|
||||
|
||||
g_debug("%s: tcp write, comp:%d, write len:%d", G_STRLOC, (int)unsend_len, (int)len);
|
||||
|
||||
os_errno = errno;
|
||||
|
||||
if (len > 0) {
|
||||
if (len != unsend_len) {
|
||||
g_debug("%s: tcp write len not equal to compressed packet, comp:%d, len:%d",
|
||||
G_STRLOC, unsend_len, (int)len);
|
||||
con->compressed_unsend_offset = len + con->compressed_unsend_offset;
|
||||
return NETWORK_SOCKET_WAIT_FOR_EVENT;
|
||||
} else {
|
||||
g_string_free(con->last_compressed_packet, TRUE);
|
||||
con->last_compressed_packet = NULL;
|
||||
con->compressed_unsend_offset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (-1 == len) {
|
||||
switch (os_errno) {
|
||||
case E_NET_WOULDBLOCK:
|
||||
case EAGAIN:
|
||||
return NETWORK_SOCKET_WAIT_FOR_EVENT;
|
||||
case EPIPE:
|
||||
case E_NET_CONNRESET:
|
||||
case E_NET_CONNABORTED:
|
||||
/** remote side closed the connection */
|
||||
return NETWORK_SOCKET_ERROR;
|
||||
default:
|
||||
g_message("%s: send(%s, ...) failed: %s", G_STRLOC, con->dst->name->str, g_strerror(errno));
|
||||
return NETWORK_SOCKET_ERROR;
|
||||
}
|
||||
} else if (len == 0) {
|
||||
return NETWORK_SOCKET_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (send_chunks == 0)
|
||||
return NETWORK_SOCKET_SUCCESS;
|
||||
|
||||
gint chunk_count;
|
||||
chunk_count = send_chunks > 0 ? send_chunks : (gint)con->send_queue->chunks->length;
|
||||
|
||||
if (chunk_count == 0)
|
||||
return NETWORK_SOCKET_SUCCESS;
|
||||
|
||||
g_assert_cmpint(chunk_count, >, 0); /* make sure it is never negative */
|
||||
|
||||
z_stream strm;
|
||||
cetus_compress_init(&strm);
|
||||
|
||||
GString *compress_packet = g_string_sized_new(16384);
|
||||
|
||||
network_mysqld_proto_append_packet_len(compress_packet, 0);
|
||||
network_mysqld_proto_append_packet_id(compress_packet, con->compressed_packet_id);
|
||||
con->compressed_packet_id++;
|
||||
network_mysqld_proto_append_packet_len(compress_packet, 0);
|
||||
|
||||
int uncompressed_len = 0, is_too_large = 0;
|
||||
|
||||
GList *chunk;
|
||||
gint chunk_id;
|
||||
|
||||
int need_more_write = 0;
|
||||
|
||||
for (chunk = con->send_queue->chunks->head, chunk_id = 0;
|
||||
chunk && chunk_id < chunk_count; chunk_id++, chunk = chunk->next) {
|
||||
GString *s = chunk->data;
|
||||
|
||||
int end = 0;
|
||||
|
||||
if (!chunk->next || (chunk_id + 1 >= chunk_count)) {
|
||||
end = 1;
|
||||
}
|
||||
|
||||
char *str;
|
||||
int str_len;
|
||||
if (chunk_id == 0) {
|
||||
str = s->str + con->send_queue->offset;
|
||||
str_len = s->len - con->send_queue->offset;
|
||||
} else {
|
||||
str = s->str;
|
||||
str_len = s->len;
|
||||
}
|
||||
|
||||
g_debug("%s: offset:%d, str_len:%d, s->len:%d", G_STRLOC, (int)con->send_queue->offset, str_len, (int)s->len);
|
||||
|
||||
if (!con->do_strict_compress && uncompressed_len < MIN_COMPRESS_LENGTH && end) {
|
||||
g_string_append_len(compress_packet, str, str_len);
|
||||
if (con->send_queue->offset != 0) {
|
||||
g_warning("%s:con->send_queue->offset is not zero here", G_STRLOC);
|
||||
}
|
||||
} else {
|
||||
|
||||
con->do_strict_compress = 1;
|
||||
uncompressed_len += str_len;
|
||||
if (uncompressed_len > PACKET_LEN_MAX) {
|
||||
g_message("%s:too large packet:%d, s->len:%d", G_STRLOC, uncompressed_len, (int)str_len);
|
||||
uncompressed_len -= str_len;
|
||||
str_len = PACKET_LEN_MAX - uncompressed_len;
|
||||
if (str_len == 0) {
|
||||
cetus_compress(&strm, compress_packet, NULL, 0, 1);
|
||||
con->send_queue->offset = 0;
|
||||
} else {
|
||||
uncompressed_len = PACKET_LEN_MAX;
|
||||
cetus_compress(&strm, compress_packet, str, str_len, 1);
|
||||
con->send_queue->offset += str_len;
|
||||
}
|
||||
is_too_large = 1;
|
||||
} else {
|
||||
cetus_compress(&strm, compress_packet, str, str_len, end);
|
||||
con->send_queue->offset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (end || is_too_large) {
|
||||
cetus_compress_end(&strm);
|
||||
}
|
||||
|
||||
con->total_output += str_len;
|
||||
|
||||
if (is_too_large) {
|
||||
need_more_write = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int compressed_len = compress_packet->len - NET_HEADER_SIZE - COMP_HEADER_SIZE;
|
||||
|
||||
if (compressed_len > PACKET_LEN_MAX || uncompressed_len > PACKET_LEN_MAX || (is_too_large && uncompressed_len == 0)) {
|
||||
g_warning("%s:too large for compression:%d, compressed len:%d", G_STRLOC, uncompressed_len, compressed_len);
|
||||
g_string_free(compress_packet, TRUE);
|
||||
return NETWORK_SOCKET_ERROR;
|
||||
}
|
||||
|
||||
int i;
|
||||
char *s = compress_packet->str;
|
||||
for (i = 0; i < 3; i++) {
|
||||
s[i] = compressed_len & 0xff;
|
||||
compressed_len >>= 8;
|
||||
}
|
||||
|
||||
s = s + 4;
|
||||
for (i = 0; i < 3; i++) {
|
||||
s[i] = uncompressed_len & 0xff;
|
||||
uncompressed_len >>= 8;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
for (chunk = con->send_queue->chunks->head; chunk;) {
|
||||
if (i >= chunk_id) {
|
||||
break;
|
||||
}
|
||||
GString *s = chunk->data;
|
||||
g_string_free(s, TRUE);
|
||||
g_queue_delete_link(con->send_queue->chunks, chunk);
|
||||
chunk = con->send_queue->chunks->head;
|
||||
i++;
|
||||
}
|
||||
|
||||
g_debug("%s: network socket:%p, send (src:%s, dst:%s) fd:%d",
|
||||
G_STRLOC, con, con->src->name->str, con->dst->name->str, con->fd);
|
||||
|
||||
len = send(con->fd, compress_packet->str, compress_packet->len, 0);
|
||||
os_errno = errno;
|
||||
|
||||
g_debug("%s: tcp write, comp:%d, write len:%d, total len:%d",
|
||||
G_STRLOC, (int)compress_packet->len, (int)len, con->total_output);
|
||||
|
||||
if (len > 0) {
|
||||
if (len != compress_packet->len) {
|
||||
g_debug("%s: tcp write len not equal to compressed packet, comp:%d, len:%d",
|
||||
G_STRLOC, (int)compress_packet->len, (int)len);
|
||||
con->last_compressed_packet = compress_packet;
|
||||
con->compressed_unsend_offset = len;
|
||||
return NETWORK_SOCKET_WAIT_FOR_EVENT;
|
||||
} else {
|
||||
g_string_free(compress_packet, TRUE);
|
||||
con->last_compressed_packet = NULL;
|
||||
con->compressed_unsend_offset = 0;
|
||||
if (need_more_write) {
|
||||
return NETWORK_SOCKET_WAIT_FOR_EVENT;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
con->last_compressed_packet = compress_packet;
|
||||
con->compressed_unsend_offset = 0;
|
||||
}
|
||||
|
||||
if (-1 == len) {
|
||||
switch (os_errno) {
|
||||
case E_NET_WOULDBLOCK:
|
||||
case EAGAIN:
|
||||
return NETWORK_SOCKET_WAIT_FOR_EVENT;
|
||||
case EPIPE:
|
||||
case E_NET_CONNRESET:
|
||||
case E_NET_CONNABORTED:
|
||||
/** remote side closed the connection */
|
||||
return NETWORK_SOCKET_ERROR;
|
||||
default:
|
||||
g_message("%s: writev(%s, ...) failed: %s", G_STRLOC, con->dst->name->str, g_strerror(errno));
|
||||
return NETWORK_SOCKET_ERROR;
|
||||
}
|
||||
} else if (len == 0) {
|
||||
return NETWORK_SOCKET_ERROR;
|
||||
}
|
||||
|
||||
return NETWORK_SOCKET_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* write data to the socket
|
||||
|
@ -490,10 +490,5 @@ network_socket_retval_t network_ssl_handshake(network_socket* sock)
|
||||
}
|
||||
}
|
||||
|
||||
gboolean network_ssl_is_init_finished(network_socket* sock)
|
||||
{
|
||||
return sock->ssl->ssl && SSL_is_init_finished(sock->ssl->ssl);
|
||||
}
|
||||
|
||||
|
||||
#endif /* HAVE_OPENSSL */
|
||||
|
@ -22,8 +22,6 @@ gboolean network_ssl_decrypt_packet(network_socket* sock);
|
||||
|
||||
network_socket_retval_t network_ssl_handshake(network_socket* sock);
|
||||
|
||||
gboolean network_ssl_is_init_finished(network_socket* sock);
|
||||
|
||||
#endif /* HAVE_OPENSSL */
|
||||
|
||||
#endif /* NETWORK_SSL_H */
|
||||
|
@ -1590,18 +1590,6 @@ cetus_result_retrieve_field_count(GQueue *input, guint64 *p_field_count)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
cetus_result_parse_field_count(cetus_result_t *res_merge, GQueue *input)
|
||||
{
|
||||
guint64 field_count = 0;
|
||||
if (cetus_result_retrieve_field_count(input, &field_count) == TRUE) {
|
||||
res_merge->field_count = field_count;
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get order_array.pos, order_array.type
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user