Skip to content

Commit

Permalink
base64 service
Browse files Browse the repository at this point in the history
  • Loading branch information
vuvova committed Mar 10, 2017
1 parent 70a2efd commit 051851b
Show file tree
Hide file tree
Showing 18 changed files with 193 additions and 69 deletions.
62 changes: 0 additions & 62 deletions include/base64.h

This file was deleted.

16 changes: 16 additions & 0 deletions include/mysql/plugin_audit.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@
void my_md5_init(void *context);
void my_md5_input(void *context, const unsigned char *buf, size_t len);
void my_md5_result(void *context, unsigned char *digest);
extern struct base64_service_st {
int (*base64_needed_encoded_length_ptr)(int length_of_data);
int (*base64_encode_max_arg_length_ptr)(void);
int (*base64_needed_decoded_length_ptr)(int length_of_encoded_data);
int (*base64_decode_max_arg_length_ptr)();
int (*base64_encode_ptr)(const void *src, size_t src_len, char *dst);
int (*base64_decode_ptr)(const char *src, size_t src_len,
void *dst, const char **end_ptr, int flags);
} *base64_service;
int base64_needed_encoded_length(int length_of_data);
int base64_encode_max_arg_length(void);
int base64_needed_decoded_length(int length_of_encoded_data);
int base64_decode_max_arg_length();
int base64_encode(const void *src, size_t src_len, char *dst);
int base64_decode(const char *src, size_t src_len,
void *dst, const char **end_ptr, int flags);
typedef struct logger_handle_st LOGGER_HANDLE;
extern struct logger_service_st {
void (*logger_init_mutexes)();
Expand Down
16 changes: 16 additions & 0 deletions include/mysql/plugin_auth.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@
void my_md5_init(void *context);
void my_md5_input(void *context, const unsigned char *buf, size_t len);
void my_md5_result(void *context, unsigned char *digest);
extern struct base64_service_st {
int (*base64_needed_encoded_length_ptr)(int length_of_data);
int (*base64_encode_max_arg_length_ptr)(void);
int (*base64_needed_decoded_length_ptr)(int length_of_encoded_data);
int (*base64_decode_max_arg_length_ptr)();
int (*base64_encode_ptr)(const void *src, size_t src_len, char *dst);
int (*base64_decode_ptr)(const char *src, size_t src_len,
void *dst, const char **end_ptr, int flags);
} *base64_service;
int base64_needed_encoded_length(int length_of_data);
int base64_encode_max_arg_length(void);
int base64_needed_decoded_length(int length_of_encoded_data);
int base64_decode_max_arg_length();
int base64_encode(const void *src, size_t src_len, char *dst);
int base64_decode(const char *src, size_t src_len,
void *dst, const char **end_ptr, int flags);
typedef struct logger_handle_st LOGGER_HANDLE;
extern struct logger_service_st {
void (*logger_init_mutexes)();
Expand Down
16 changes: 16 additions & 0 deletions include/mysql/plugin_encryption.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@
void my_md5_init(void *context);
void my_md5_input(void *context, const unsigned char *buf, size_t len);
void my_md5_result(void *context, unsigned char *digest);
extern struct base64_service_st {
int (*base64_needed_encoded_length_ptr)(int length_of_data);
int (*base64_encode_max_arg_length_ptr)(void);
int (*base64_needed_decoded_length_ptr)(int length_of_encoded_data);
int (*base64_decode_max_arg_length_ptr)();
int (*base64_encode_ptr)(const void *src, size_t src_len, char *dst);
int (*base64_decode_ptr)(const char *src, size_t src_len,
void *dst, const char **end_ptr, int flags);
} *base64_service;
int base64_needed_encoded_length(int length_of_data);
int base64_encode_max_arg_length(void);
int base64_needed_decoded_length(int length_of_encoded_data);
int base64_decode_max_arg_length();
int base64_encode(const void *src, size_t src_len, char *dst);
int base64_decode(const char *src, size_t src_len,
void *dst, const char **end_ptr, int flags);
typedef struct logger_handle_st LOGGER_HANDLE;
extern struct logger_service_st {
void (*logger_init_mutexes)();
Expand Down
16 changes: 16 additions & 0 deletions include/mysql/plugin_ftparser.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@
void my_md5_init(void *context);
void my_md5_input(void *context, const unsigned char *buf, size_t len);
void my_md5_result(void *context, unsigned char *digest);
extern struct base64_service_st {
int (*base64_needed_encoded_length_ptr)(int length_of_data);
int (*base64_encode_max_arg_length_ptr)(void);
int (*base64_needed_decoded_length_ptr)(int length_of_encoded_data);
int (*base64_decode_max_arg_length_ptr)();
int (*base64_encode_ptr)(const void *src, size_t src_len, char *dst);
int (*base64_decode_ptr)(const char *src, size_t src_len,
void *dst, const char **end_ptr, int flags);
} *base64_service;
int base64_needed_encoded_length(int length_of_data);
int base64_encode_max_arg_length(void);
int base64_needed_decoded_length(int length_of_encoded_data);
int base64_decode_max_arg_length();
int base64_encode(const void *src, size_t src_len, char *dst);
int base64_decode(const char *src, size_t src_len,
void *dst, const char **end_ptr, int flags);
typedef struct logger_handle_st LOGGER_HANDLE;
extern struct logger_service_st {
void (*logger_init_mutexes)();
Expand Down
16 changes: 16 additions & 0 deletions include/mysql/plugin_password_validation.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@
void my_md5_init(void *context);
void my_md5_input(void *context, const unsigned char *buf, size_t len);
void my_md5_result(void *context, unsigned char *digest);
extern struct base64_service_st {
int (*base64_needed_encoded_length_ptr)(int length_of_data);
int (*base64_encode_max_arg_length_ptr)(void);
int (*base64_needed_decoded_length_ptr)(int length_of_encoded_data);
int (*base64_decode_max_arg_length_ptr)();
int (*base64_encode_ptr)(const void *src, size_t src_len, char *dst);
int (*base64_decode_ptr)(const char *src, size_t src_len,
void *dst, const char **end_ptr, int flags);
} *base64_service;
int base64_needed_encoded_length(int length_of_data);
int base64_encode_max_arg_length(void);
int base64_needed_decoded_length(int length_of_encoded_data);
int base64_decode_max_arg_length();
int base64_encode(const void *src, size_t src_len, char *dst);
int base64_decode(const char *src, size_t src_len,
void *dst, const char **end_ptr, int flags);
typedef struct logger_handle_st LOGGER_HANDLE;
extern struct logger_service_st {
void (*logger_init_mutexes)();
Expand Down
82 changes: 82 additions & 0 deletions include/mysql/service_base64.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#ifndef MYSQL_SERVICE_BASE64_INCLUDED
/* Copyright (c) 2017, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */

/**
@file
my base64 service
Functions for base64 en- and decoding
*/

#ifdef __cplusplus
extern "C" {
#endif

#ifndef MYSQL_ABI_CHECK
#include <stdlib.h>
#endif

/* Allow multuple chunks 'AAA= AA== AA==', binlog uses this */
#define MY_BASE64_DECODE_ALLOW_MULTIPLE_CHUNKS 1

extern struct base64_service_st {
int (*base64_needed_encoded_length_ptr)(int length_of_data);
int (*base64_encode_max_arg_length_ptr)(void);
int (*base64_needed_decoded_length_ptr)(int length_of_encoded_data);
int (*base64_decode_max_arg_length_ptr)();
int (*base64_encode_ptr)(const void *src, size_t src_len, char *dst);
int (*base64_decode_ptr)(const char *src, size_t src_len,
void *dst, const char **end_ptr, int flags);
} *base64_service;

#ifdef MYSQL_DYNAMIC_PLUGIN

#define base64_needed_encoded_length(A) base64_service->base64_needed_encoded_length_ptr(A)
#define base64_encode_max_arg_length() base64_service->base64_encode_max_arg_length_ptr()
#define base64_needed_decoded_length(A) base64_service->base64_needed_decoded_length_ptr(A)
#define base64_decode_max_arg_length() base64_service->base64_decode_max_arg_length_ptr()
#define base64_encode(A,B,C) base64_service->base64_encode_ptr(A,B,C)
#define base64_decode(A,B,C,D,E) base64_service->base64_decode_ptr(A,B,C,D,E)

#else

/* Calculate how much memory needed for dst of base64_encode() */
int base64_needed_encoded_length(int length_of_data);

/* Maximum length base64_encode_needed_length() can accept with no overflow. */
int base64_encode_max_arg_length(void);

/* Calculate how much memory needed for dst of base64_decode() */
int base64_needed_decoded_length(int length_of_encoded_data);

/* Maximum length base64_decode_needed_length() can accept with no overflow. */
int base64_decode_max_arg_length();

/* Encode data as a base64 string */
int base64_encode(const void *src, size_t src_len, char *dst);

/* Decode a base64 string into data */
int base64_decode(const char *src, size_t src_len,
void *dst, const char **end_ptr, int flags);

#endif

#ifdef __cplusplus
}
#endif

#define MYSQL_SERVICE_BASE64_INCLUDED
#endif
1 change: 1 addition & 0 deletions include/mysql/services.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern "C" {
#include <mysql/service_sha2.h>
#include <mysql/service_sha1.h>
#include <mysql/service_md5.h>
#include <mysql/service_base64.h>
#include <mysql/service_logger.h>
#include <mysql/service_thd_autoinc.h>
#include <mysql/service_thd_error_context.h>
Expand Down
1 change: 1 addition & 0 deletions include/service_versions.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define VERSION_my_md5 0x0100
#define VERSION_wsrep 0x0201
#define VERSION_logger 0x0100
#define VERSION_base64 0x0100
#define VERSION_thd_autoinc 0x0100
#define VERSION_thd_error_context 0x0100
#define VERSION_thd_specifics 0x0100
Expand Down
1 change: 1 addition & 0 deletions libservices/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SET(MYSQLSERVICES_SOURCES
my_sha2_service.c
my_sha1_service.c
my_md5_service.c
base64_service.c
wsrep_service.c
encryption_service.c
encryption_scheme_service.c
Expand Down
18 changes: 18 additions & 0 deletions libservices/base64_service.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* Copyright (c) 2017 MariaDB
Use is subject to license terms.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */

#include <service_versions.h>
SERVICE_VERSION base64_service= (void*)VERSION_base64;
1 change: 0 additions & 1 deletion mysys/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <my_global.h>
#include <m_string.h> /* strchr() */
#include <m_ctype.h> /* my_isspace() */
#include <base64.h>

#ifndef MAIN

Expand Down
2 changes: 0 additions & 2 deletions plugin/feedback/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include <unistd.h>
#endif

#include <base64.h>

#if defined (_WIN32)
#define HAVE_SYS_UTSNAME_H

Expand Down
1 change: 0 additions & 1 deletion sql/item_strfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include "password.h" // my_make_scrambled_password,
// my_make_scrambled_password_323
#include <m_ctype.h>
#include <base64.h>
#include <my_md5.h>
#include <zlib.h>
C_MODE_START
Expand Down
1 change: 0 additions & 1 deletion sql/log_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#include "wsrep_mysqld.h"
#endif /* MYSQL_CLIENT */

#include <base64.h>
#include <my_bitmap.h>
#include "rpl_utility.h"
#include "rpl_constants.h"
Expand Down
1 change: 0 additions & 1 deletion sql/sql_binlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "sql_parse.h" // check_global_access
#include "sql_acl.h" // *_ACL
#include "rpl_rli.h"
#include "base64.h"
#include "slave.h" // apply_event_and_update_pos
#include "log_event.h" // Format_description_log_event,
// EVENT_LEN_OFFSET,
Expand Down
10 changes: 10 additions & 0 deletions sql/sql_plugin_services.ic
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ static struct thd_autoinc_service_st thd_autoinc_handler= {
thd_get_autoinc
};

static struct base64_service_st base64_handler= {
base64_needed_encoded_length,
base64_encode_max_arg_length,
base64_needed_decoded_length,
base64_decode_max_arg_length,
base64_encode,
base64_decode
};

static struct thd_error_context_service_st thd_error_conext_handler= {
thd_get_error_message,
thd_get_error_number,
Expand Down Expand Up @@ -195,6 +204,7 @@ static struct st_service_ref list_of_services[]=
{ "my_sha1_service", VERSION_my_sha1, &my_sha1_handler},
{ "my_md5_service", VERSION_my_md5, &my_md5_handler},
{ "logger_service", VERSION_logger, &logger_service_handler },
{ "base64_service", VERSION_base64, &base64_handler },
{ "thd_autoinc_service", VERSION_thd_autoinc, &thd_autoinc_handler },
{ "wsrep_service", VERSION_wsrep, &wsrep_handler },
{ "encryption_service", VERSION_encryption, &encryption_handler },
Expand Down
1 change: 0 additions & 1 deletion unittest/mysys/base64-t.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include <my_global.h>
#include <my_sys.h>
#include <base64.h>
#include <tap.h>
#include <string.h>

Expand Down

0 comments on commit 051851b

Please sign in to comment.